Version Description
- March 16th, 2015 =
- Security Update: We recommend all Pods 1.x/2.x installations be updated to the latest version of Pods
- or replace your plugin files with the download of your version from http://wordpress.org/plugins/pods/developers/
- Fixed: Pods UI orderby now strictly enforces Database column format
Download this release
Release Info
Developer | sc0ttkclark |
Plugin | Pods – Custom Content Types and Fields |
Version | 2.4.4 |
Comparing to | |
See all releases |
Version 2.4.4
- classes/Pods.php +3831 -0
- classes/PodsAPI.php +7849 -0
- classes/PodsAdmin.php +2395 -0
- classes/PodsArray.php +213 -0
- classes/PodsComponent.php +90 -0
- classes/PodsComponents.php +667 -0
- classes/PodsData.php +2988 -0
- classes/PodsField.php +384 -0
- classes/PodsForm.php +1449 -0
- classes/PodsInit.php +1281 -0
- classes/PodsMeta.php +2785 -0
- classes/PodsMigrate.php +1021 -0
- classes/PodsUI.php +3156 -0
classes/Pods.php
ADDED
@@ -0,0 +1,3831 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class Pods implements Iterator {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var bool
|
9 |
+
*/
|
10 |
+
private $iterator = false;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var PodsAPI
|
14 |
+
*/
|
15 |
+
public $api;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var PodsData
|
19 |
+
*/
|
20 |
+
public $data;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var PodsData
|
24 |
+
*/
|
25 |
+
public $alt_data;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var array Array of pod item arrays
|
29 |
+
*/
|
30 |
+
public $rows = array();
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var array Current pod item array
|
34 |
+
*/
|
35 |
+
public $row = array();
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @var int
|
39 |
+
*/
|
40 |
+
private $row_number = -1;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @var array Override pod item array
|
44 |
+
*/
|
45 |
+
public $row_override = array();
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var bool
|
49 |
+
*/
|
50 |
+
public $display_errors = false;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @var array|bool|mixed|null|void
|
54 |
+
*/
|
55 |
+
public $pod_data;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @var array
|
59 |
+
*/
|
60 |
+
public $params = array();
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @var string
|
64 |
+
*/
|
65 |
+
public $pod = '';
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @var int
|
69 |
+
*/
|
70 |
+
public $pod_id = 0;
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @var array
|
74 |
+
*/
|
75 |
+
public $fields = array();
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @var array
|
79 |
+
*/
|
80 |
+
public $filters = array();
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @var string
|
84 |
+
*/
|
85 |
+
public $detail_page;
|
86 |
+
|
87 |
+
/**
|
88 |
+
* @var int
|
89 |
+
*/
|
90 |
+
public $id = 0;
|
91 |
+
|
92 |
+
/**
|
93 |
+
* @var int
|
94 |
+
*/
|
95 |
+
public $limit = 15;
|
96 |
+
|
97 |
+
/**
|
98 |
+
* @var int
|
99 |
+
*/
|
100 |
+
public $offset = 0;
|
101 |
+
|
102 |
+
/**
|
103 |
+
* @var string
|
104 |
+
*/
|
105 |
+
public $page_var = 'pg';
|
106 |
+
|
107 |
+
/**
|
108 |
+
* @var int|mixed
|
109 |
+
*/
|
110 |
+
public $page = 1;
|
111 |
+
|
112 |
+
/**
|
113 |
+
* @var bool
|
114 |
+
*/
|
115 |
+
public $pagination = true;
|
116 |
+
|
117 |
+
/**
|
118 |
+
* @var bool
|
119 |
+
*/
|
120 |
+
public $search = true;
|
121 |
+
|
122 |
+
/**
|
123 |
+
* @var string
|
124 |
+
*/
|
125 |
+
public $search_var = 'search';
|
126 |
+
|
127 |
+
/**
|
128 |
+
* @var string
|
129 |
+
*/
|
130 |
+
public $search_mode = 'int'; // int | text | text_like
|
131 |
+
|
132 |
+
/**
|
133 |
+
* @var int
|
134 |
+
*/
|
135 |
+
public $total = 0;
|
136 |
+
|
137 |
+
/**
|
138 |
+
* @var int
|
139 |
+
*/
|
140 |
+
public $total_found = 0;
|
141 |
+
|
142 |
+
/**
|
143 |
+
* @var array
|
144 |
+
*/
|
145 |
+
public $ui = array();
|
146 |
+
|
147 |
+
/**
|
148 |
+
* @var mixed SEO related vars for Pod Pages
|
149 |
+
*/
|
150 |
+
public $page_template;
|
151 |
+
public $body_classes;
|
152 |
+
public $meta = array();
|
153 |
+
public $meta_properties = array();
|
154 |
+
public $meta_extra = '';
|
155 |
+
|
156 |
+
/**
|
157 |
+
* @var string Last SQL query used by a find()
|
158 |
+
*/
|
159 |
+
public $sql;
|
160 |
+
|
161 |
+
/**
|
162 |
+
* @var
|
163 |
+
*/
|
164 |
+
public $deprecated;
|
165 |
+
|
166 |
+
public $datatype;
|
167 |
+
|
168 |
+
public $datatype_id;
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Constructor - Pods Framework core
|
172 |
+
*
|
173 |
+
* @param string $pod The pod name
|
174 |
+
* @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
|
175 |
+
*
|
176 |
+
* @return \Pods
|
177 |
+
*
|
178 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
179 |
+
* @since 1.0.0
|
180 |
+
* @link http://pods.io/docs/pods/
|
181 |
+
*/
|
182 |
+
public function __construct ( $pod = null, $id = null ) {
|
183 |
+
if ( null === $pod ) {
|
184 |
+
$queried_object = get_queried_object();
|
185 |
+
|
186 |
+
if ( $queried_object ) {
|
187 |
+
$id_lookup = true;
|
188 |
+
|
189 |
+
// Post Type Singular
|
190 |
+
if ( isset( $queried_object->post_type ) ) {
|
191 |
+
$pod = $queried_object->post_type;
|
192 |
+
}
|
193 |
+
// Term Archive
|
194 |
+
elseif ( isset( $queried_object->taxonomy ) ) {
|
195 |
+
$pod = $queried_object->taxonomy;
|
196 |
+
}
|
197 |
+
// Author Archive
|
198 |
+
elseif ( isset( $queried_object->user_login ) ) {
|
199 |
+
$pod = 'user';
|
200 |
+
}
|
201 |
+
// Post Type Archive
|
202 |
+
elseif ( isset( $queried_object->public ) && isset( $queried_object->name ) ) {
|
203 |
+
$pod = $queried_object->name;
|
204 |
+
|
205 |
+
$id_lookup = false;
|
206 |
+
}
|
207 |
+
|
208 |
+
if ( null === $id && $id_lookup ) {
|
209 |
+
$id = get_queried_object_id();
|
210 |
+
}
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
$this->api = pods_api( $pod );
|
215 |
+
$this->api->display_errors =& $this->display_errors;
|
216 |
+
|
217 |
+
$this->data = pods_data( $this->api, $id, false );
|
218 |
+
PodsData::$display_errors =& $this->display_errors;
|
219 |
+
|
220 |
+
// Set up page variable
|
221 |
+
if ( pods_strict( false ) ) {
|
222 |
+
$this->page = 1;
|
223 |
+
$this->pagination = false;
|
224 |
+
$this->search = false;
|
225 |
+
}
|
226 |
+
else {
|
227 |
+
// Get the page variable
|
228 |
+
$this->page = pods_var( $this->page_var, 'get' );
|
229 |
+
$this->page = ( empty( $this->page ) ? 1 : max( pods_absint( $this->page ), 1 ) );
|
230 |
+
}
|
231 |
+
|
232 |
+
// Set default pagination handling to on/off
|
233 |
+
if ( defined( 'PODS_GLOBAL_POD_PAGINATION' ) ) {
|
234 |
+
if ( !PODS_GLOBAL_POD_PAGINATION ) {
|
235 |
+
$this->page = 1;
|
236 |
+
$this->pagination = false;
|
237 |
+
}
|
238 |
+
else
|
239 |
+
$this->pagination = true;
|
240 |
+
}
|
241 |
+
|
242 |
+
// Set default search to on/off
|
243 |
+
if ( defined( 'PODS_GLOBAL_POD_SEARCH' ) ) {
|
244 |
+
if ( PODS_GLOBAL_POD_SEARCH )
|
245 |
+
$this->search = true;
|
246 |
+
else
|
247 |
+
$this->search = false;
|
248 |
+
}
|
249 |
+
|
250 |
+
// Set default search mode
|
251 |
+
$allowed_search_modes = array( 'int', 'text', 'text_like' );
|
252 |
+
|
253 |
+
if ( defined( 'PODS_GLOBAL_POD_SEARCH_MODE' ) && in_array( PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes ) )
|
254 |
+
$this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE;
|
255 |
+
|
256 |
+
// Sync Settings
|
257 |
+
$this->data->page =& $this->page;
|
258 |
+
$this->data->limit =& $this->limit;
|
259 |
+
$this->data->pagination =& $this->pagination;
|
260 |
+
$this->data->search =& $this->search;
|
261 |
+
$this->data->search_mode =& $this->search_mode;
|
262 |
+
|
263 |
+
// Sync Pod Data
|
264 |
+
$this->api->pod_data =& $this->data->pod_data;
|
265 |
+
$this->pod_data =& $this->api->pod_data;
|
266 |
+
$this->api->pod_id =& $this->data->pod_id;
|
267 |
+
$this->pod_id =& $this->api->pod_id;
|
268 |
+
$this->datatype_id =& $this->pod_id;
|
269 |
+
$this->api->pod =& $this->data->pod;
|
270 |
+
$this->pod =& $this->api->pod;
|
271 |
+
$this->datatype =& $this->pod;
|
272 |
+
$this->api->fields =& $this->data->fields;
|
273 |
+
$this->fields =& $this->api->fields;
|
274 |
+
$this->detail_page =& $this->data->detail_page;
|
275 |
+
$this->id =& $this->data->id;
|
276 |
+
$this->row =& $this->data->row;
|
277 |
+
$this->rows =& $this->data->data;
|
278 |
+
$this->row_number =& $this->data->row_number;
|
279 |
+
$this->sql =& $this->data->sql;
|
280 |
+
|
281 |
+
if ( is_array( $id ) || is_object( $id ) )
|
282 |
+
$this->find( $id );
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Whether this Pod object is valid or not
|
287 |
+
*
|
288 |
+
* @return bool
|
289 |
+
*
|
290 |
+
* @since 2.0
|
291 |
+
*/
|
292 |
+
public function valid () {
|
293 |
+
if ( empty( $this->pod_id ) )
|
294 |
+
return false;
|
295 |
+
|
296 |
+
if ( $this->iterator )
|
297 |
+
return isset( $this->rows[ $this->row_number ] );
|
298 |
+
|
299 |
+
return true;
|
300 |
+
}
|
301 |
+
|
302 |
+
/**
|
303 |
+
* Check if in Iterator mode
|
304 |
+
*
|
305 |
+
* @return bool
|
306 |
+
*
|
307 |
+
* @since 2.3.4
|
308 |
+
*
|
309 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
310 |
+
*/
|
311 |
+
public function is_iterator () {
|
312 |
+
return $this->iterator;
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Turn off Iterator mode to off
|
317 |
+
*
|
318 |
+
* @return void
|
319 |
+
*
|
320 |
+
* @since 2.3.4
|
321 |
+
*
|
322 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
323 |
+
*/
|
324 |
+
public function stop_iterator () {
|
325 |
+
$this->iterator = false;
|
326 |
+
|
327 |
+
return;
|
328 |
+
}
|
329 |
+
|
330 |
+
/**
|
331 |
+
* Rewind Iterator
|
332 |
+
*
|
333 |
+
* @return void|boolean
|
334 |
+
*
|
335 |
+
* @since 2.3.4
|
336 |
+
*
|
337 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
338 |
+
*/
|
339 |
+
public function rewind () {
|
340 |
+
if ( $this->iterator ) {
|
341 |
+
$this->row_number = 0;
|
342 |
+
|
343 |
+
return;
|
344 |
+
}
|
345 |
+
|
346 |
+
return false;
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Get current Iterator row
|
351 |
+
*
|
352 |
+
* @return mixed|boolean
|
353 |
+
*
|
354 |
+
* @since 2.3.4
|
355 |
+
*
|
356 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
357 |
+
*/
|
358 |
+
public function current () {
|
359 |
+
if ( $this->iterator && $this->fetch() )
|
360 |
+
return $this;
|
361 |
+
|
362 |
+
return false;
|
363 |
+
}
|
364 |
+
|
365 |
+
/**
|
366 |
+
* Get current Iterator key
|
367 |
+
*
|
368 |
+
* @return int|boolean
|
369 |
+
*
|
370 |
+
* @since 2.3.4
|
371 |
+
*
|
372 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
373 |
+
*/
|
374 |
+
public function key () {
|
375 |
+
if ( $this->iterator )
|
376 |
+
return $this->row_number;
|
377 |
+
|
378 |
+
return false;
|
379 |
+
}
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Move onto the next Iterator row
|
383 |
+
*
|
384 |
+
* @return void|boolean
|
385 |
+
*
|
386 |
+
* @since 2.3.4
|
387 |
+
*
|
388 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
389 |
+
*/
|
390 |
+
public function next () {
|
391 |
+
if ( $this->iterator ) {
|
392 |
+
$this->row_number++;
|
393 |
+
|
394 |
+
return;
|
395 |
+
}
|
396 |
+
|
397 |
+
return false;
|
398 |
+
}
|
399 |
+
|
400 |
+
/**
|
401 |
+
* Whether a Pod item exists or not when using fetch() or construct with an ID or slug
|
402 |
+
*
|
403 |
+
* @return bool
|
404 |
+
*
|
405 |
+
* @since 2.0
|
406 |
+
*/
|
407 |
+
public function exists () {
|
408 |
+
if ( empty( $this->row ) )
|
409 |
+
return false;
|
410 |
+
|
411 |
+
return true;
|
412 |
+
}
|
413 |
+
|
414 |
+
/**
|
415 |
+
* Return an array of all rows returned from a find() call.
|
416 |
+
*
|
417 |
+
* Most of the time, you will want to loop through data using fetch()
|
418 |
+
* instead of using this function.
|
419 |
+
*
|
420 |
+
* @return array|bool An array of all rows returned from a find() call, or false if no items returned
|
421 |
+
*
|
422 |
+
* @since 2.0
|
423 |
+
* @link http://pods.io/docs/data/
|
424 |
+
*/
|
425 |
+
public function data () {
|
426 |
+
$this->do_hook( 'data' );
|
427 |
+
|
428 |
+
if ( empty( $this->rows ) )
|
429 |
+
return false;
|
430 |
+
|
431 |
+
return (array) $this->rows;
|
432 |
+
}
|
433 |
+
|
434 |
+
/**
|
435 |
+
* Return a field input for a specific field
|
436 |
+
*
|
437 |
+
* @param string|array $field Field name or Field data array
|
438 |
+
* @param string $field Input field name to use (overrides default name)
|
439 |
+
* @param mixed $value Current value to use
|
440 |
+
*
|
441 |
+
* @return string Field Input HTML
|
442 |
+
*
|
443 |
+
* @since 2.3.10
|
444 |
+
*/
|
445 |
+
public function input( $field, $input_name = null, $value = '__null' ) {
|
446 |
+
|
447 |
+
// Field data override
|
448 |
+
if ( is_array( $field ) ) {
|
449 |
+
$field_data = $field;
|
450 |
+
$field = pods_var_raw( 'name', $field );
|
451 |
+
}
|
452 |
+
// Get field data from field name
|
453 |
+
else {
|
454 |
+
$field_data = $this->fields( $field );
|
455 |
+
}
|
456 |
+
|
457 |
+
if ( !empty( $field_data ) ) {
|
458 |
+
$field_type = pods_var_raw( 'type', $field_data );
|
459 |
+
|
460 |
+
if ( empty( $input_name ) ) {
|
461 |
+
$input_name = $field;
|
462 |
+
}
|
463 |
+
|
464 |
+
if ( '__null' == $value ) {
|
465 |
+
$value = $this->field( array( 'name' => $field, 'in_form' => true ) );
|
466 |
+
}
|
467 |
+
|
468 |
+
return PodsForm::field( $input_name, $value, $field_type, $field_data, $this, $this->id() );
|
469 |
+
}
|
470 |
+
|
471 |
+
return '';
|
472 |
+
|
473 |
+
}
|
474 |
+
|
475 |
+
/**
|
476 |
+
* Return field array from a Pod, a field's data, or a field option
|
477 |
+
*
|
478 |
+
* @param null $field
|
479 |
+
* @param null $option
|
480 |
+
*
|
481 |
+
* @return bool|mixed
|
482 |
+
*
|
483 |
+
* @since 2.0
|
484 |
+
*/
|
485 |
+
public function fields ( $field = null, $option = null ) {
|
486 |
+
// No fields found
|
487 |
+
if ( empty( $this->fields ) )
|
488 |
+
$field_data = array();
|
489 |
+
// Return all fields
|
490 |
+
elseif ( empty( $field ) )
|
491 |
+
$field_data = (array) $this->fields;
|
492 |
+
// Field not found
|
493 |
+
elseif ( !isset( $this->fields[ $field ] ) )
|
494 |
+
$field_data = array();
|
495 |
+
// Return all field data
|
496 |
+
elseif ( empty( $option ) )
|
497 |
+
$field_data = $this->fields[ $field ];
|
498 |
+
else {
|
499 |
+
// Merge options
|
500 |
+
$options = array_merge( $this->fields[ $field ], $this->fields[ $field ][ 'options' ] );
|
501 |
+
|
502 |
+
$field_data = null;
|
503 |
+
|
504 |
+
// Get a list of available items from a relationship field
|
505 |
+
if ( 'data' == $option && in_array( pods_var_raw( 'type', $options ), PodsForm::tableless_field_types() ) ) {
|
506 |
+
$field_data = PodsForm::field_method( 'pick', 'get_field_data', $options );
|
507 |
+
}
|
508 |
+
// Return option
|
509 |
+
elseif ( isset( $options[ $option ] ) ) {
|
510 |
+
$field_data = $options[ $option ];
|
511 |
+
}
|
512 |
+
}
|
513 |
+
|
514 |
+
return $this->do_hook( 'fields', $field_data, $field, $option );
|
515 |
+
}
|
516 |
+
|
517 |
+
/**
|
518 |
+
* Return row array for an item
|
519 |
+
*
|
520 |
+
* @return array
|
521 |
+
*
|
522 |
+
* @since 2.0
|
523 |
+
*/
|
524 |
+
public function row () {
|
525 |
+
$this->do_hook( 'row' );
|
526 |
+
|
527 |
+
if ( !is_array( $this->row ) )
|
528 |
+
return false;
|
529 |
+
|
530 |
+
return (array) $this->row;
|
531 |
+
}
|
532 |
+
|
533 |
+
/**
|
534 |
+
* Return the output for a field. If you want the raw value for use in PHP for custom manipulation,
|
535 |
+
* you will want to use field() instead. This function will automatically convert arrays into a
|
536 |
+
* list of text such as "Rick, John, and Gary"
|
537 |
+
*
|
538 |
+
* @param string|array $name The field name, or an associative array of parameters
|
539 |
+
* @param boolean $single (optional) For tableless fields, to return an array or the first
|
540 |
+
*
|
541 |
+
* @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields
|
542 |
+
* @since 2.0
|
543 |
+
* @link http://pods.io/docs/display/
|
544 |
+
*/
|
545 |
+
public function display ( $name, $single = null ) {
|
546 |
+
$defaults = array(
|
547 |
+
'name' => $name,
|
548 |
+
'single' => $single,
|
549 |
+
'display' => true,
|
550 |
+
'serial_params' => null
|
551 |
+
);
|
552 |
+
|
553 |
+
if ( is_array( $name ) || is_object( $name ) ) {
|
554 |
+
$defaults[ 'name' ] = null;
|
555 |
+
$params = (object) array_merge( $defaults, (array) $name );
|
556 |
+
}
|
557 |
+
elseif ( is_array( $single ) || is_object( $single ) ) {
|
558 |
+
$defaults[ 'single' ] = null;
|
559 |
+
$params = (object) array_merge( $defaults, (array) $single );
|
560 |
+
}
|
561 |
+
else
|
562 |
+
$params = $defaults;
|
563 |
+
|
564 |
+
$params = (object) $params;
|
565 |
+
|
566 |
+
$value = $this->field( $params );
|
567 |
+
|
568 |
+
if ( is_array( $value ) ) {
|
569 |
+
$serial_params = array(
|
570 |
+
'field' => $params->name,
|
571 |
+
'fields' => $this->fields
|
572 |
+
);
|
573 |
+
|
574 |
+
if ( !empty( $params->serial_params ) && is_array( $params->serial_params ) )
|
575 |
+
$serial_params = array_merge( $serial_params, $params->serial_params );
|
576 |
+
|
577 |
+
$value = pods_serial_comma( $value, $serial_params );
|
578 |
+
}
|
579 |
+
|
580 |
+
return $value;
|
581 |
+
}
|
582 |
+
|
583 |
+
/**
|
584 |
+
* Return the raw output for a field If you want the raw value for use in PHP for custom manipulation,
|
585 |
+
* you will want to use field() instead. This function will automatically convert arrays into a
|
586 |
+
* list of text such as "Rick, John, and Gary"
|
587 |
+
*
|
588 |
+
* @param string|array $name The field name, or an associative array of parameters
|
589 |
+
* @param boolean $single (optional) For tableless fields, to return an array or the first
|
590 |
+
*
|
591 |
+
* @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields
|
592 |
+
* @since 2.0
|
593 |
+
* @link http://pods.io/docs/display/
|
594 |
+
*/
|
595 |
+
public function raw ( $name, $single = null ) {
|
596 |
+
$defaults = array(
|
597 |
+
'name' => $name,
|
598 |
+
'single' => $single,
|
599 |
+
'raw' => true
|
600 |
+
);
|
601 |
+
|
602 |
+
if ( is_array( $name ) || is_object( $name ) ) {
|
603 |
+
$defaults[ 'name' ] = null;
|
604 |
+
$params = (object) array_merge( $defaults, (array) $name );
|
605 |
+
}
|
606 |
+
elseif ( is_array( $single ) || is_object( $single ) ) {
|
607 |
+
$defaults[ 'single' ] = null;
|
608 |
+
$params = (object) array_merge( $defaults, (array) $single );
|
609 |
+
}
|
610 |
+
else
|
611 |
+
$params = (object) $defaults;
|
612 |
+
|
613 |
+
$value = $this->field( $params );
|
614 |
+
|
615 |
+
return $value;
|
616 |
+
}
|
617 |
+
|
618 |
+
/**
|
619 |
+
* Return the value for a field.
|
620 |
+
*
|
621 |
+
* If you are getting a field for output in a theme, most of the time you will want to use display() instead.
|
622 |
+
*
|
623 |
+
* This function will return arrays for relationship and file fields.
|
624 |
+
*
|
625 |
+
* @param string|array $name The field name, or an associative array of parameters
|
626 |
+
* @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item, or an associative array of parameters
|
627 |
+
* @param boolean $raw (optional) Whether to return the raw value, or to run through the field type's display method, or an associative array of parameters
|
628 |
+
*
|
629 |
+
* @return mixed|null Value returned depends on the field type, null if the field doesn't exist, false if no value returned for tableless fields
|
630 |
+
* @since 2.0
|
631 |
+
* @link http://pods.io/docs/field/
|
632 |
+
*/
|
633 |
+
public function field ( $name, $single = null, $raw = false ) {
|
634 |
+
global $sitepress;
|
635 |
+
|
636 |
+
$defaults = array(
|
637 |
+
'name' => $name,
|
638 |
+
'orderby' => null,
|
639 |
+
'single' => $single,
|
640 |
+
'params' => null,
|
641 |
+
'in_form' => false,
|
642 |
+
'raw' => $raw,
|
643 |
+
'raw_display' => false,
|
644 |
+
'display' => false,
|
645 |
+
'get_meta' => false,
|
646 |
+
'output' => null,
|
647 |
+
'deprecated' => false,
|
648 |
+
'args' => array() // extra data to send to field handlers
|
649 |
+
);
|
650 |
+
|
651 |
+
if ( is_array( $name ) || is_object( $name ) ) {
|
652 |
+
$defaults[ 'name' ] = null;
|
653 |
+
$params = (object) array_merge( $defaults, (array) $name );
|
654 |
+
}
|
655 |
+
elseif ( is_array( $single ) || is_object( $single ) ) {
|
656 |
+
$defaults[ 'single' ] = null;
|
657 |
+
$params = (object) array_merge( $defaults, (array) $single );
|
658 |
+
}
|
659 |
+
elseif ( is_array( $raw ) || is_object( $raw ) ) {
|
660 |
+
$defaults[ 'raw' ] = false;
|
661 |
+
$params = (object) array_merge( $defaults, (array) $raw );
|
662 |
+
}
|
663 |
+
else
|
664 |
+
$params = (object) $defaults;
|
665 |
+
|
666 |
+
if ( $params->in_form ) {
|
667 |
+
$params->output = 'ids';
|
668 |
+
}
|
669 |
+
elseif ( null === $params->output ) {
|
670 |
+
$params->output = $this->do_hook( 'field_related_output_type', 'arrays', $this->row, $params );
|
671 |
+
}
|
672 |
+
|
673 |
+
if ( in_array( $params->output, array( 'id', 'name', 'object', 'array', 'pod' ) ) )
|
674 |
+
$params->output .= 's';
|
675 |
+
|
676 |
+
// Support old $orderby variable
|
677 |
+
if ( null !== $params->single && is_string( $params->single ) && empty( $params->orderby ) ) {
|
678 |
+
pods_deprecated( 'Pods::field', '2.0', 'Use $params[ \'orderby\' ] instead' );
|
679 |
+
|
680 |
+
$params->orderby = $params->single;
|
681 |
+
$params->single = false;
|
682 |
+
}
|
683 |
+
|
684 |
+
if ( null !== $params->single )
|
685 |
+
$params->single = (boolean) $params->single;
|
686 |
+
|
687 |
+
if ( is_array( $params->name ) || strlen( trim( $params->name ) ) < 1 )
|
688 |
+
return null;
|
689 |
+
|
690 |
+
$params->name = trim( $params->name );
|
691 |
+
$params->full_name = $params->name;
|
692 |
+
|
693 |
+
$value = null;
|
694 |
+
|
695 |
+
if ( isset( $this->row_override[ $params->name ] ) )
|
696 |
+
$value = $this->row_override[ $params->name ];
|
697 |
+
|
698 |
+
if ( false === $this->row() ) {
|
699 |
+
if ( false !== $this->data() )
|
700 |
+
$this->fetch();
|
701 |
+
else
|
702 |
+
return $value;
|
703 |
+
}
|
704 |
+
|
705 |
+
if ( $this->data->field_id == $params->name ) {
|
706 |
+
if ( isset( $this->row[ $params->name ] ) )
|
707 |
+
return $this->row[ $params->name ];
|
708 |
+
elseif ( null !== $value )
|
709 |
+
return $value;
|
710 |
+
|
711 |
+
return 0;
|
712 |
+
}
|
713 |
+
|
714 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
715 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
716 |
+
|
717 |
+
$params->traverse = array();
|
718 |
+
|
719 |
+
if ( in_array( $params->name, array( '_link', 'detail_url' ) ) || ( in_array( $params->name, array( 'permalink', 'the_permalink' ) ) && in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) ) {
|
720 |
+
if ( 0 < strlen( $this->detail_page ) )
|
721 |
+
$value = get_home_url() . '/' . $this->do_magic_tags( $this->detail_page );
|
722 |
+
elseif ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) )
|
723 |
+
$value = get_permalink( $this->id() );
|
724 |
+
elseif ( 'taxonomy' == $this->pod_data[ 'type' ] )
|
725 |
+
$value = get_term_link( $this->id(), $this->pod_data[ 'name' ] );
|
726 |
+
elseif ( 'user' == $this->pod_data[ 'type' ] )
|
727 |
+
$value = get_author_posts_url( $this->id() );
|
728 |
+
elseif ( 'comment' == $this->pod_data[ 'type' ] )
|
729 |
+
$value = get_comment_link( $this->id() );
|
730 |
+
}
|
731 |
+
|
732 |
+
$field_data = false;
|
733 |
+
$field_type = false;
|
734 |
+
|
735 |
+
$first_field = explode( '.', $params->name );
|
736 |
+
$first_field = $first_field[ 0 ];
|
737 |
+
|
738 |
+
if ( isset( $this->fields[ $first_field ] ) ) {
|
739 |
+
$field_data = $this->fields[ $first_field ];
|
740 |
+
$field_type = 'field';
|
741 |
+
}
|
742 |
+
elseif ( isset( $this->pod_data[ 'object_fields' ] ) && !empty( $this->pod_data[ 'object_fields' ] ) ) {
|
743 |
+
if ( isset( $this->pod_data[ 'object_fields' ][ $first_field ] ) ) {
|
744 |
+
$field_data = $this->pod_data[ 'object_fields' ][ $first_field ];
|
745 |
+
$field_type = 'object_field';
|
746 |
+
}
|
747 |
+
else {
|
748 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
749 |
+
if ( in_array( $first_field, $object_field_opt[ 'alias' ] ) ) {
|
750 |
+
if ( $first_field == $params->name )
|
751 |
+
$params->name = $object_field;
|
752 |
+
|
753 |
+
$first_field = $object_field;
|
754 |
+
$field_data = $object_field_opt;
|
755 |
+
$field_type = 'object_field';
|
756 |
+
|
757 |
+
break;
|
758 |
+
}
|
759 |
+
}
|
760 |
+
}
|
761 |
+
}
|
762 |
+
|
763 |
+
// Simple fields have no other output options
|
764 |
+
if ( 'pick' == $field_data[ 'type' ] && in_array( $field_data[ 'pick_object' ], $simple_tableless_objects ) ) {
|
765 |
+
$params->output = 'arrays';
|
766 |
+
}
|
767 |
+
|
768 |
+
if ( empty( $value ) && in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
769 |
+
$params->raw = true;
|
770 |
+
|
771 |
+
$value = false;
|
772 |
+
|
773 |
+
if ( 'arrays' != $params->output && isset( $this->row[ '_' . $params->output . '_' . $params->name ] ) ) {
|
774 |
+
$value = $this->row[ '_' . $params->output . '_' . $params->name ];
|
775 |
+
}
|
776 |
+
elseif ( 'arrays' == $params->output && isset( $this->row[ $params->name ] ) ) {
|
777 |
+
$value = $this->row[ $params->name ];
|
778 |
+
}
|
779 |
+
|
780 |
+
if ( false !== $value && !is_array( $value ) && 'pick' == $field_data[ 'type' ] && in_array( $field_data[ 'pick_object' ], $simple_tableless_objects ) )
|
781 |
+
$value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $field_data, $this->pod_data, $this->id(), true );
|
782 |
+
}
|
783 |
+
|
784 |
+
if ( empty( $value ) && isset( $this->row[ $params->name ] ) && ( !in_array( $field_data[ 'type' ], $tableless_field_types ) || 'arrays' == $params->output ) ) {
|
785 |
+
if ( empty( $field_data ) || in_array( $field_data[ 'type' ], array( 'boolean', 'number', 'currency' ) ) )
|
786 |
+
$params->raw = true;
|
787 |
+
|
788 |
+
$value = $this->row[ $params->name ];
|
789 |
+
}
|
790 |
+
elseif ( empty( $value ) ) {
|
791 |
+
$object_field_found = false;
|
792 |
+
|
793 |
+
if ( 'object_field' == $field_type ) {
|
794 |
+
$object_field_found = true;
|
795 |
+
|
796 |
+
if ( isset( $this->row[ $first_field ] ) )
|
797 |
+
$value = $this->row[ $first_field ];
|
798 |
+
elseif ( in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
799 |
+
$this->fields[ $first_field ] = $field_data;
|
800 |
+
|
801 |
+
$object_field_found = false;
|
802 |
+
}
|
803 |
+
else
|
804 |
+
return null;
|
805 |
+
}
|
806 |
+
|
807 |
+
if ( 'post_type' == $this->pod_data[ 'type' ] && !isset( $this->fields[ $params->name ] ) ) {
|
808 |
+
if ( !isset( $this->fields[ 'post_thumbnail' ] ) && ( 'post_thumbnail' == $params->name || 0 === strpos( $params->name, 'post_thumbnail.' ) ) ) {
|
809 |
+
$size = 'thumbnail';
|
810 |
+
|
811 |
+
if ( 0 === strpos( $params->name, 'post_thumbnail.' ) ) {
|
812 |
+
$field_names = explode( '.', $params->name );
|
813 |
+
|
814 |
+
if ( isset( $field_names[ 1 ] ) )
|
815 |
+
$size = $field_names[ 1 ];
|
816 |
+
}
|
817 |
+
|
818 |
+
// Pods will auto-get the thumbnail ID if this isn't an attachment
|
819 |
+
$value = pods_image( $this->id(), $size, 0, null, true );
|
820 |
+
|
821 |
+
$object_field_found = true;
|
822 |
+
}
|
823 |
+
elseif ( !isset( $this->fields[ 'post_thumbnail_url' ] ) && ( 'post_thumbnail_url' == $params->name || 0 === strpos( $params->name, 'post_thumbnail_url.' ) ) ) {
|
824 |
+
$size = 'thumbnail';
|
825 |
+
|
826 |
+
if ( 0 === strpos( $params->name, 'post_thumbnail_url.' ) ) {
|
827 |
+
$field_names = explode( '.', $params->name );
|
828 |
+
|
829 |
+
if ( isset( $field_names[ 1 ] ) )
|
830 |
+
$size = $field_names[ 1 ];
|
831 |
+
}
|
832 |
+
|
833 |
+
// Pods will auto-get the thumbnail ID if this isn't an attachment
|
834 |
+
$value = pods_image_url( $this->id(), $size, 0, true );
|
835 |
+
|
836 |
+
$object_field_found = true;
|
837 |
+
}
|
838 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment.' ) ) {
|
839 |
+
$size = 'thumbnail';
|
840 |
+
|
841 |
+
$image_id = 0;
|
842 |
+
|
843 |
+
$field_names = explode( '.', $params->name );
|
844 |
+
|
845 |
+
if ( isset( $field_names[ 1 ] ) )
|
846 |
+
$image_id = $field_names[ 1 ];
|
847 |
+
|
848 |
+
if ( isset( $field_names[ 2 ] ) )
|
849 |
+
$size = $field_names[ 2 ];
|
850 |
+
|
851 |
+
if ( !empty( $image_id ) ) {
|
852 |
+
$value = pods_image( $image_id, $size, 0, null, true );
|
853 |
+
|
854 |
+
if ( !empty( $value ) )
|
855 |
+
$object_field_found = true;
|
856 |
+
}
|
857 |
+
}
|
858 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment_url.' ) ) {
|
859 |
+
$size = 'thumbnail';
|
860 |
+
|
861 |
+
$image_id = 0;
|
862 |
+
|
863 |
+
$field_names = explode( '.', $params->name );
|
864 |
+
|
865 |
+
if ( isset( $field_names[ 1 ] ) )
|
866 |
+
$image_id = $field_names[ 1 ];
|
867 |
+
|
868 |
+
if ( isset( $field_names[ 2 ] ) )
|
869 |
+
$size = $field_names[ 2 ];
|
870 |
+
|
871 |
+
if ( !empty( $image_id ) ) {
|
872 |
+
$value = pods_image_url( $image_id, $size, 0, true );
|
873 |
+
|
874 |
+
if ( !empty( $value ) )
|
875 |
+
$object_field_found = true;
|
876 |
+
}
|
877 |
+
}
|
878 |
+
}
|
879 |
+
elseif ( 'user' == $this->pod_data[ 'type' ] && !isset( $this->fields[ $params->name ] ) ) {
|
880 |
+
if ( !isset( $this->fields[ 'avatar' ] ) && ( 'avatar' == $params->name || 0 === strpos( $params->name, 'avatar.' ) ) ) {
|
881 |
+
$size = null;
|
882 |
+
|
883 |
+
if ( 0 === strpos( $params->name, 'avatar.' ) ) {
|
884 |
+
$field_names = explode( '.', $params->name );
|
885 |
+
|
886 |
+
if ( isset( $field_names[ 1 ] ) )
|
887 |
+
$size = (int) $field_names[ 1 ];
|
888 |
+
}
|
889 |
+
|
890 |
+
if ( !empty( $size ) )
|
891 |
+
$value = get_avatar( $this->id(), $size );
|
892 |
+
else
|
893 |
+
$value = get_avatar( $this->id() );
|
894 |
+
|
895 |
+
$object_field_found = true;
|
896 |
+
}
|
897 |
+
}
|
898 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment.' ) ) {
|
899 |
+
$size = 'thumbnail';
|
900 |
+
|
901 |
+
$image_id = 0;
|
902 |
+
|
903 |
+
$field_names = explode( '.', $params->name );
|
904 |
+
|
905 |
+
if ( isset( $field_names[ 1 ] ) )
|
906 |
+
$image_id = $field_names[ 1 ];
|
907 |
+
|
908 |
+
if ( isset( $field_names[ 2 ] ) )
|
909 |
+
$size = $field_names[ 2 ];
|
910 |
+
|
911 |
+
if ( !empty( $image_id ) ) {
|
912 |
+
$value = pods_image( $image_id, $size, 0, null, true );
|
913 |
+
|
914 |
+
if ( !empty( $value ) )
|
915 |
+
$object_field_found = true;
|
916 |
+
}
|
917 |
+
}
|
918 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment_url.' ) ) {
|
919 |
+
$size = 'thumbnail';
|
920 |
+
|
921 |
+
$image_id = 0;
|
922 |
+
|
923 |
+
$field_names = explode( '.', $params->name );
|
924 |
+
|
925 |
+
if ( isset( $field_names[ 1 ] ) )
|
926 |
+
$image_id = $field_names[ 1 ];
|
927 |
+
|
928 |
+
if ( isset( $field_names[ 2 ] ) )
|
929 |
+
$size = $field_names[ 2 ];
|
930 |
+
|
931 |
+
if ( !empty( $image_id ) ) {
|
932 |
+
$value = pods_image_url( $image_id, $size, 0, true );
|
933 |
+
|
934 |
+
if ( !empty( $value ) )
|
935 |
+
$object_field_found = true;
|
936 |
+
}
|
937 |
+
}
|
938 |
+
|
939 |
+
if ( false === $object_field_found ) {
|
940 |
+
$params->traverse = array( $params->name );
|
941 |
+
|
942 |
+
if ( false !== strpos( $params->name, '.' ) ) {
|
943 |
+
$params->traverse = explode( '.', $params->name );
|
944 |
+
|
945 |
+
$params->name = $params->traverse[ 0 ];
|
946 |
+
}
|
947 |
+
|
948 |
+
if ( isset( $this->fields[ $params->name ] ) && isset( $this->fields[ $params->name ][ 'type' ] ) ) {
|
949 |
+
$v = $this->do_hook( 'field_' . $this->fields[ $params->name ][ 'type' ], null, $this->fields[ $params->name ], $this->row, $params );
|
950 |
+
|
951 |
+
if ( null !== $v )
|
952 |
+
return $v;
|
953 |
+
}
|
954 |
+
|
955 |
+
$simple = false;
|
956 |
+
$simple_data = array();
|
957 |
+
|
958 |
+
if ( isset( $this->fields[ $params->name ] ) ) {
|
959 |
+
if ( 'meta' == $this->pod_data[ 'storage' ] ) {
|
960 |
+
if ( !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
|
961 |
+
$simple = true;
|
962 |
+
}
|
963 |
+
|
964 |
+
if ( in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) ) {
|
965 |
+
$params->raw = true;
|
966 |
+
|
967 |
+
if ( 'pick' == $this->fields[ $params->name ][ 'type' ] && in_array( $this->fields[ $params->name ][ 'pick_object' ], $simple_tableless_objects ) ) {
|
968 |
+
$simple = true;
|
969 |
+
$params->single = true;
|
970 |
+
}
|
971 |
+
}
|
972 |
+
elseif ( in_array( $this->fields[ $params->name ][ 'type' ], array( 'boolean', 'number', 'currency' ) ) )
|
973 |
+
$params->raw = true;
|
974 |
+
}
|
975 |
+
|
976 |
+
if ( !isset( $this->fields[ $params->name ] ) || !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) || $simple ) {
|
977 |
+
if ( null === $params->single ) {
|
978 |
+
if ( isset( $this->fields[ $params->name ] ) && !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
|
979 |
+
$params->single = true;
|
980 |
+
else
|
981 |
+
$params->single = false;
|
982 |
+
}
|
983 |
+
|
984 |
+
$no_conflict = pods_no_conflict_check( $this->pod_data[ 'type' ] );
|
985 |
+
|
986 |
+
if ( !$no_conflict )
|
987 |
+
pods_no_conflict_on( $this->pod_data[ 'type' ] );
|
988 |
+
|
989 |
+
if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) {
|
990 |
+
$id = $this->id();
|
991 |
+
|
992 |
+
// Support for WPML 'duplicated' translation handling
|
993 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $this->pod_data[ 'name' ] ) ) {
|
994 |
+
$master_post_id = (int) get_post_meta( $id, '_icl_lang_duplicate_of', true );
|
995 |
+
|
996 |
+
if ( 0 < $master_post_id )
|
997 |
+
$id = $master_post_id;
|
998 |
+
}
|
999 |
+
|
1000 |
+
$value = get_post_meta( $id, $params->name, $params->single );
|
1001 |
+
|
1002 |
+
$single_multi = pods_var( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
|
1003 |
+
|
1004 |
+
if ( $simple && !is_array( $value ) && 'single' != $single_multi ) {
|
1005 |
+
$value = get_post_meta( $id, $params->name );
|
1006 |
+
}
|
1007 |
+
}
|
1008 |
+
elseif ( in_array( $this->pod_data[ 'type' ], array( 'user', 'comment' ) ) ) {
|
1009 |
+
$value = get_metadata( $this->pod_data[ 'type' ], $this->id(), $params->name, $params->single );
|
1010 |
+
|
1011 |
+
$single_multi = pods_var( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
|
1012 |
+
|
1013 |
+
if ( $simple && !is_array( $value ) && 'single' != $single_multi ) {
|
1014 |
+
$value = get_metadata( $this->pod_data[ 'type' ], $this->id(), $params->name );
|
1015 |
+
}
|
1016 |
+
}
|
1017 |
+
elseif ( 'settings' == $this->pod_data[ 'type' ] )
|
1018 |
+
$value = get_option( $this->pod_data[ 'name' ] . '_' . $params->name, null );
|
1019 |
+
|
1020 |
+
// Handle Simple Relationships
|
1021 |
+
if ( $simple ) {
|
1022 |
+
if ( null === $params->single )
|
1023 |
+
$params->single = false;
|
1024 |
+
|
1025 |
+
$value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $this->fields[ $params->name ], $this->pod_data, $this->id(), true );
|
1026 |
+
}
|
1027 |
+
|
1028 |
+
if ( !$no_conflict )
|
1029 |
+
pods_no_conflict_off( $this->pod_data[ 'type' ] );
|
1030 |
+
}
|
1031 |
+
else {
|
1032 |
+
// Dot-traversal
|
1033 |
+
$pod = $this->pod;
|
1034 |
+
$ids = array( $this->id() );
|
1035 |
+
$all_fields = array();
|
1036 |
+
|
1037 |
+
$lookup = $params->traverse;
|
1038 |
+
|
1039 |
+
if ( !empty( $lookup ) ) {
|
1040 |
+
unset( $lookup[ 0 ] );
|
1041 |
+
|
1042 |
+
foreach ( $this->fields as $field ) {
|
1043 |
+
if ( !in_array( $field[ 'type' ], $tableless_field_types ) || in_array( $field[ 'name' ], $lookup ) )
|
1044 |
+
continue;
|
1045 |
+
|
1046 |
+
$lookup[] = $field[ 'name' ];
|
1047 |
+
}
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
// Get fields matching traversal names
|
1051 |
+
if ( !empty( $lookup ) ) {
|
1052 |
+
$fields = $this->api->load_fields( array(
|
1053 |
+
'name' => $lookup,
|
1054 |
+
'type' => $tableless_field_types,
|
1055 |
+
'object_fields' => true // @todo support object fields too
|
1056 |
+
) );
|
1057 |
+
|
1058 |
+
if ( !empty( $fields ) ) {
|
1059 |
+
foreach ( $fields as $field ) {
|
1060 |
+
if ( !empty( $field ) ) {
|
1061 |
+
if ( !isset( $all_fields[ $field[ 'pod' ] ] ) )
|
1062 |
+
$all_fields[ $field[ 'pod' ] ] = array();
|
1063 |
+
|
1064 |
+
$all_fields[ $field[ 'pod' ] ][ $field[ 'name' ] ] = $field;
|
1065 |
+
}
|
1066 |
+
}
|
1067 |
+
}
|
1068 |
+
|
1069 |
+
if ( isset( $this->pod_data[ 'object_fields' ] ) && !empty( $this->pod_data[ 'object_fields' ] ) ) {
|
1070 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
1071 |
+
if ( in_array( $object_field_opt[ 'type' ], $tableless_field_types ) ) {
|
1072 |
+
$all_fields[ $this->pod ][ $object_field ] = $object_field_opt;
|
1073 |
+
}
|
1074 |
+
}
|
1075 |
+
}
|
1076 |
+
}
|
1077 |
+
|
1078 |
+
$last_type = $last_object = $last_pick_val = '';
|
1079 |
+
$last_options = array();
|
1080 |
+
|
1081 |
+
$single_multi = pods_var( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
|
1082 |
+
|
1083 |
+
if ( 'multi' == $single_multi )
|
1084 |
+
$limit = (int) pods_var( $this->fields[ $params->name ][ 'type' ] . '_limit', $this->fields[ $params->name ][ 'options' ], 0 );
|
1085 |
+
else
|
1086 |
+
$limit = 1;
|
1087 |
+
|
1088 |
+
$last_limit = 0;
|
1089 |
+
|
1090 |
+
// Loop through each traversal level
|
1091 |
+
foreach ( $params->traverse as $key => $field ) {
|
1092 |
+
$last_loop = false;
|
1093 |
+
|
1094 |
+
if ( count( $params->traverse ) <= ( $key + 1 ) )
|
1095 |
+
$last_loop = true;
|
1096 |
+
|
1097 |
+
$field_exists = isset( $all_fields[ $pod ][ $field ] );
|
1098 |
+
|
1099 |
+
$simple = false;
|
1100 |
+
$last_options = array();
|
1101 |
+
|
1102 |
+
if ( $field_exists && 'pick' == $all_fields[ $pod ][ $field ][ 'type' ] && in_array( $all_fields[ $pod ][ $field ][ 'pick_object' ], $simple_tableless_objects ) ) {
|
1103 |
+
$simple = true;
|
1104 |
+
$last_options = $all_fields[ $pod ][ $field ];
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
// Tableless handler
|
1108 |
+
if ( $field_exists && ( !in_array( $all_fields[ $pod ][ $field ][ 'type' ], array( 'pick', 'taxonomy' ) ) || !$simple ) ) {
|
1109 |
+
|
1110 |
+
$type = $all_fields[ $pod ][ $field ][ 'type' ];
|
1111 |
+
$pick_object = $all_fields[ $pod ][ $field ][ 'pick_object' ];
|
1112 |
+
$pick_val = $all_fields[ $pod ][ $field ][ 'pick_val' ];
|
1113 |
+
|
1114 |
+
if ( 'table' == $pick_object ) {
|
1115 |
+
|
1116 |
+
$pick_val = pods_var( 'pick_table', $all_fields[ $pod ][ $field ][ 'options' ], $pick_val, null, true );
|
1117 |
+
}
|
1118 |
+
elseif ( '__current__' == $pick_val ) {
|
1119 |
+
|
1120 |
+
$pick_val = $pod;
|
1121 |
+
}
|
1122 |
+
|
1123 |
+
$last_limit = 0;
|
1124 |
+
|
1125 |
+
if ( in_array( $type, $tableless_field_types ) ) {
|
1126 |
+
|
1127 |
+
$single_multi = pods_var( "{$type}_format_type", $all_fields[ $pod ][ $field ][ 'options' ], 'single' );
|
1128 |
+
|
1129 |
+
if ( 'multi' == $single_multi ) {
|
1130 |
+
|
1131 |
+
$last_limit = (int) pods_var( "{$type}_limit", $all_fields[ $pod ][ $field ][ 'options' ], 0 );
|
1132 |
+
}
|
1133 |
+
else {
|
1134 |
+
|
1135 |
+
$last_limit = 1;
|
1136 |
+
}
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
$last_type = $type;
|
1140 |
+
$last_object = $pick_object;
|
1141 |
+
$last_pick_val = $pick_val;
|
1142 |
+
$last_options = $all_fields[ $pod ][ $field ];
|
1143 |
+
|
1144 |
+
// Temporary hack until there's some better handling here
|
1145 |
+
$last_limit = $last_limit * count( $ids );
|
1146 |
+
|
1147 |
+
// Get related IDs
|
1148 |
+
if ( !isset( $all_fields[ $pod ][ $field ][ 'pod_id' ] ) ) {
|
1149 |
+
|
1150 |
+
$all_fields[ $pod ][ $field ][ 'pod_id' ] = 0;
|
1151 |
+
}
|
1152 |
+
if ( isset( $all_fields[ $pod ][ $field ][ 'id' ] ) ) {
|
1153 |
+
|
1154 |
+
$ids = $this->api->lookup_related_items(
|
1155 |
+
$all_fields[ $pod ][ $field ][ 'id' ],
|
1156 |
+
$all_fields[ $pod ][ $field ][ 'pod_id' ],
|
1157 |
+
$ids,
|
1158 |
+
$all_fields[ $pod ][ $field ]
|
1159 |
+
);
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
// No items found
|
1163 |
+
if ( empty( $ids ) ) {
|
1164 |
+
|
1165 |
+
return false;
|
1166 |
+
} // @todo This should return array() if not $params->single
|
1167 |
+
elseif ( 0 < $last_limit ) {
|
1168 |
+
|
1169 |
+
$ids = array_slice( $ids, 0, $last_limit );
|
1170 |
+
}
|
1171 |
+
|
1172 |
+
// Get $pod if related to a Pod
|
1173 |
+
if ( !empty( $pick_object ) && !empty( $pick_val ) ) {
|
1174 |
+
|
1175 |
+
if ( 'pod' == $pick_object ) {
|
1176 |
+
|
1177 |
+
$pod = $pick_val;
|
1178 |
+
}
|
1179 |
+
else {
|
1180 |
+
|
1181 |
+
$check = $this->api->get_table_info( $pick_object, $pick_val );
|
1182 |
+
|
1183 |
+
if ( !empty( $check ) && !empty( $check[ 'pod' ] ) ) {
|
1184 |
+
|
1185 |
+
$pod = $check[ 'pod' ][ 'name' ];
|
1186 |
+
}
|
1187 |
+
}
|
1188 |
+
}
|
1189 |
+
}
|
1190 |
+
// Assume last iteration
|
1191 |
+
else {
|
1192 |
+
// Invalid field
|
1193 |
+
if ( 0 == $key ) {
|
1194 |
+
return false;
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
$last_loop = true;
|
1198 |
+
}
|
1199 |
+
|
1200 |
+
if ( $last_loop ) {
|
1201 |
+
$object_type = $last_object;
|
1202 |
+
$object = $last_pick_val;
|
1203 |
+
|
1204 |
+
if ( in_array( $last_type, PodsForm::file_field_types() ) ) {
|
1205 |
+
$object_type = 'media';
|
1206 |
+
$object = 'attachment';
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
$data = array();
|
1210 |
+
|
1211 |
+
$table = $this->api->get_table_info( $object_type, $object, null, null, $last_options );
|
1212 |
+
|
1213 |
+
$join = $where = array();
|
1214 |
+
|
1215 |
+
if ( !empty( $table[ 'join' ] ) )
|
1216 |
+
$join = (array) $table[ 'join' ];
|
1217 |
+
|
1218 |
+
if ( !empty( $table[ 'where' ] ) || !empty( $ids ) ) {
|
1219 |
+
foreach ( $ids as $id ) {
|
1220 |
+
$where[ $id ] = '`t`.`' . $table[ 'field_id' ] . '` = ' . (int) $id;
|
1221 |
+
}
|
1222 |
+
|
1223 |
+
if ( !empty( $where ) ) {
|
1224 |
+
$where = array( implode( ' OR ', $where ) );
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
if ( !empty( $table[ 'where' ] ) ) {
|
1228 |
+
$where = array_merge( $where, array_values( (array) $table[ 'where' ] ) );
|
1229 |
+
}
|
1230 |
+
}
|
1231 |
+
|
1232 |
+
/**
|
1233 |
+
* @var $related_obj Pods
|
1234 |
+
*/
|
1235 |
+
$related_obj = false;
|
1236 |
+
|
1237 |
+
if ( 'pod' == $object_type )
|
1238 |
+
$related_obj = pods( $object, null, false );
|
1239 |
+
elseif ( isset( $table[ 'pod' ] ) && !empty( $table[ 'pod' ] ) )
|
1240 |
+
$related_obj = pods( $table[ 'pod' ][ 'name' ], null, false );
|
1241 |
+
|
1242 |
+
if ( !empty( $table[ 'table' ] ) || !empty( $related_obj ) ) {
|
1243 |
+
$sql = array(
|
1244 |
+
'select' => '*, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`',
|
1245 |
+
'table' => $table[ 'table' ],
|
1246 |
+
'join' => $join,
|
1247 |
+
'where' => $where,
|
1248 |
+
'orderby' => $params->orderby,
|
1249 |
+
'pagination' => false,
|
1250 |
+
'search' => false,
|
1251 |
+
'limit' => -1
|
1252 |
+
);
|
1253 |
+
|
1254 |
+
// Output types
|
1255 |
+
if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ) ) )
|
1256 |
+
$sql[ 'select' ] = '`t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
|
1257 |
+
elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
|
1258 |
+
$sql[ 'select' ] = '`t`.`' . $table[ 'field_index' ] . '` AS `pod_item_index`, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
|
1259 |
+
|
1260 |
+
if ( is_array( $params->params ) && !empty( $params->params ) ) {
|
1261 |
+
$where = $sql[ 'where' ];
|
1262 |
+
|
1263 |
+
$sql = array_merge( $sql, $params->params );
|
1264 |
+
|
1265 |
+
if ( isset( $params->params[ 'where' ] ) )
|
1266 |
+
$sql[ 'where' ] = array_merge( (array) $where, (array) $params->params['where' ] );
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
if ( empty( $related_obj ) ) {
|
1270 |
+
if ( !is_object( $this->alt_data ) )
|
1271 |
+
$this->alt_data = pods_data( null, 0, true, true );
|
1272 |
+
|
1273 |
+
$item_data = $this->alt_data->select( $sql );
|
1274 |
+
}
|
1275 |
+
else
|
1276 |
+
$item_data = $related_obj->find( $sql )->data();
|
1277 |
+
|
1278 |
+
$items = array();
|
1279 |
+
|
1280 |
+
if ( !empty( $item_data ) ) {
|
1281 |
+
foreach ( $item_data as $item ) {
|
1282 |
+
if ( is_array( $item ) )
|
1283 |
+
$item = (object) $item;
|
1284 |
+
|
1285 |
+
if ( empty( $item->pod_item_id ) )
|
1286 |
+
continue;
|
1287 |
+
|
1288 |
+
// Bypass pass field
|
1289 |
+
if ( isset( $item->user_pass ) )
|
1290 |
+
unset( $item->user_pass );
|
1291 |
+
|
1292 |
+
// Get Item ID
|
1293 |
+
$item_id = $item->pod_item_id;
|
1294 |
+
|
1295 |
+
// Cleanup
|
1296 |
+
unset( $item->pod_item_id );
|
1297 |
+
|
1298 |
+
// Output types
|
1299 |
+
if ( 'ids' == $params->output )
|
1300 |
+
$item = (int) $item_id;
|
1301 |
+
elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
|
1302 |
+
$item = $item->pod_item_index;
|
1303 |
+
elseif ( 'objects' == $params->output ) {
|
1304 |
+
if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
|
1305 |
+
$item = get_post( $item_id );
|
1306 |
+
elseif ( 'taxonomy' == $object_type )
|
1307 |
+
$item = get_term( $item_id, $object );
|
1308 |
+
elseif ( 'user' == $object_type ) {
|
1309 |
+
$item = get_userdata( $item_id );
|
1310 |
+
|
1311 |
+
if ( !empty( $item ) ) {
|
1312 |
+
// Get other vars
|
1313 |
+
$roles = $item->roles;
|
1314 |
+
$caps = $item->caps;
|
1315 |
+
$allcaps = $item->allcaps;
|
1316 |
+
|
1317 |
+
$item = $item->data;
|
1318 |
+
|
1319 |
+
// Set other vars
|
1320 |
+
$item->roles = $roles;
|
1321 |
+
$item->caps = $caps;
|
1322 |
+
$item->allcaps = $allcaps;
|
1323 |
+
|
1324 |
+
unset( $item->user_pass );
|
1325 |
+
}
|
1326 |
+
}
|
1327 |
+
elseif ( 'comment' == $object_type )
|
1328 |
+
$item = get_comment( $item_id );
|
1329 |
+
else
|
1330 |
+
$item = (object) $item;
|
1331 |
+
}
|
1332 |
+
elseif ( 'pods' == $params->output ) {
|
1333 |
+
$item = pods( $object, (int) $item_id );
|
1334 |
+
}
|
1335 |
+
else // arrays
|
1336 |
+
$item = get_object_vars( (object) $item );
|
1337 |
+
|
1338 |
+
// Pass item data into $data
|
1339 |
+
$items[ $item_id ] = $item;
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
// Cleanup
|
1343 |
+
unset( $item_data );
|
1344 |
+
|
1345 |
+
// Return all of the data in the order expected
|
1346 |
+
if ( empty( $params->orderby ) ) {
|
1347 |
+
foreach ( $ids as $id ) {
|
1348 |
+
if ( isset( $items[ $id ] ) )
|
1349 |
+
$data[ $id ] = $items[ $id ];
|
1350 |
+
}
|
1351 |
+
}
|
1352 |
+
}
|
1353 |
+
}
|
1354 |
+
|
1355 |
+
if ( in_array( $last_type, $tableless_field_types ) || in_array( $last_type, array( 'boolean', 'number', 'currency' ) ) )
|
1356 |
+
$params->raw = true;
|
1357 |
+
|
1358 |
+
if ( empty( $data ) )
|
1359 |
+
$value = false;
|
1360 |
+
else {
|
1361 |
+
$object_type = $table[ 'type' ];
|
1362 |
+
|
1363 |
+
if ( in_array( $table[ 'type' ], array( 'post_type', 'attachment', 'media' ) ) )
|
1364 |
+
$object_type = 'post';
|
1365 |
+
|
1366 |
+
$no_conflict = true;
|
1367 |
+
|
1368 |
+
if ( in_array( $object_type, array( 'post', 'user', 'comment', 'settings' ) ) ) {
|
1369 |
+
$no_conflict = pods_no_conflict_check( $object_type );
|
1370 |
+
|
1371 |
+
if ( !$no_conflict )
|
1372 |
+
pods_no_conflict_on( $object_type );
|
1373 |
+
}
|
1374 |
+
|
1375 |
+
// Return entire array
|
1376 |
+
if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types ) && !$simple ) )
|
1377 |
+
$value = $data;
|
1378 |
+
// Return an array of single column values
|
1379 |
+
else {
|
1380 |
+
$value = array();
|
1381 |
+
|
1382 |
+
foreach ( $data as $item_id => $item ) {
|
1383 |
+
// $field is 123x123, needs to be _src.123x123
|
1384 |
+
$full_field = implode( '.', array_splice( $params->traverse, $key ) );
|
1385 |
+
|
1386 |
+
if ( ( ( false !== strpos( $full_field, '_src' ) || 'guid' == $field ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) || ( in_array( $field, array( '_link', 'detail_url' ) ) || in_array( $field, array( 'permalink', 'the_permalink' ) ) && in_array( $last_type, PodsForm::file_field_types() ) ) ) {
|
1387 |
+
$size = 'full';
|
1388 |
+
|
1389 |
+
if ( false !== strpos( $full_field, '_src.' ) && 5 < strlen( $full_field ) )
|
1390 |
+
$size = substr( $full_field, 5 );
|
1391 |
+
elseif ( false !== strpos( $full_field, '_src_relative.' ) && 14 < strlen( $full_field ) )
|
1392 |
+
$size = substr( $full_field, 14 );
|
1393 |
+
elseif ( false !== strpos( $full_field, '_src_schemeless.' ) && 16 < strlen( $full_field ) )
|
1394 |
+
$size = substr( $full_field, 16 );
|
1395 |
+
|
1396 |
+
$value_url = pods_image_url( $item_id, $size );
|
1397 |
+
|
1398 |
+
if ( false !== strpos( $full_field, '_src_relative' ) && !empty( $value_url ) ) {
|
1399 |
+
$value_url_parsed = parse_url( $value_url );
|
1400 |
+
$value_url = $value_url_parsed[ 'path' ];
|
1401 |
+
}
|
1402 |
+
elseif ( false !== strpos( $full_field, '_src_schemeless' ) && !empty( $value_url ) )
|
1403 |
+
$value_url = str_replace( array( 'http://', 'https://' ), '//', $value_url );
|
1404 |
+
|
1405 |
+
if ( !empty( $value_url ) )
|
1406 |
+
$value[] = $value_url;
|
1407 |
+
|
1408 |
+
$params->raw_display = true;
|
1409 |
+
}
|
1410 |
+
elseif ( false !== strpos( $full_field, '_img' ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) {
|
1411 |
+
$size = 'full';
|
1412 |
+
|
1413 |
+
if ( false !== strpos( $full_field, '_img.' ) && 5 < strlen( $full_field ) )
|
1414 |
+
$size = substr( $full_field, 5 );
|
1415 |
+
|
1416 |
+
$value[] = pods_image( $item_id, $size );
|
1417 |
+
|
1418 |
+
$params->raw_display = true;
|
1419 |
+
}
|
1420 |
+
elseif ( in_array( $field, array( '_link', 'detail_url' ) ) || ( in_array( $field, array( 'permalink', 'the_permalink' ) ) && 'post' == $object_type ) ) {
|
1421 |
+
if ( 'pod' == $object_type ) {
|
1422 |
+
if ( is_object( $related_obj ) ) {
|
1423 |
+
$related_obj->fetch( $item_id );
|
1424 |
+
|
1425 |
+
$value[] = $related_obj->field( 'detail_url' );
|
1426 |
+
}
|
1427 |
+
else
|
1428 |
+
$value[] = '';
|
1429 |
+
}
|
1430 |
+
elseif ( 'post' == $object_type )
|
1431 |
+
$value[] = get_permalink( $item_id );
|
1432 |
+
elseif ( 'taxonomy' == $object_type )
|
1433 |
+
$value[] = get_term_link( $item_id, $object );
|
1434 |
+
elseif ( 'user' == $object_type )
|
1435 |
+
$value[] = get_author_posts_url( $item_id );
|
1436 |
+
elseif ( 'comment' == $object_type )
|
1437 |
+
$value[] = get_comment_link( $item_id );
|
1438 |
+
else
|
1439 |
+
$value[] = '';
|
1440 |
+
|
1441 |
+
$params->raw_display = true;
|
1442 |
+
}
|
1443 |
+
elseif ( is_array( $item ) && isset( $item[ $field ] ) ) {
|
1444 |
+
if ( $table[ 'field_id' ] == $field )
|
1445 |
+
$value[] = (int) $item[ $field ];
|
1446 |
+
else
|
1447 |
+
$value[] = $item[ $field ];
|
1448 |
+
}
|
1449 |
+
elseif ( is_object( $item ) && isset( $item->{$field} ) ) {
|
1450 |
+
if ( $table[ 'field_id' ] == $field )
|
1451 |
+
$value[] = (int) $item->{$field};
|
1452 |
+
else
|
1453 |
+
$value[] = $item->{$field};
|
1454 |
+
}
|
1455 |
+
elseif ( 'post' == $object_type ) {
|
1456 |
+
// Support for WPML 'duplicated' translation handling
|
1457 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $object ) ) {
|
1458 |
+
$master_post_id = (int) get_post_meta( $item_id, '_icl_lang_duplicate_of', true );
|
1459 |
+
|
1460 |
+
if ( 0 < $master_post_id )
|
1461 |
+
$item_id = $master_post_id;
|
1462 |
+
}
|
1463 |
+
|
1464 |
+
$value[] = get_post_meta( $item_id, $field, true );
|
1465 |
+
}
|
1466 |
+
elseif ( in_array( $object_type, array( 'post', 'user', 'comment' ) ) )
|
1467 |
+
$value[] = get_metadata( $object_type, $item_id, $field, true );
|
1468 |
+
elseif ( 'settings' == $object_type )
|
1469 |
+
$value[] = get_option( $object . '_' . $field );
|
1470 |
+
}
|
1471 |
+
}
|
1472 |
+
|
1473 |
+
if ( in_array( $object_type, array( 'post', 'user', 'comment', 'settings' ) ) && !$no_conflict )
|
1474 |
+
pods_no_conflict_off( $object_type );
|
1475 |
+
|
1476 |
+
// Handle Simple Relationships
|
1477 |
+
if ( $simple ) {
|
1478 |
+
if ( null === $params->single )
|
1479 |
+
$params->single = false;
|
1480 |
+
|
1481 |
+
$value = PodsForm::field_method( 'pick', 'simple_value', $field, $value, $last_options, $all_fields[ $pod ], 0, true );
|
1482 |
+
}
|
1483 |
+
elseif ( false === $params->in_form && !empty( $value ) )
|
1484 |
+
$value = array_values( $value );
|
1485 |
+
|
1486 |
+
// Return a single column value
|
1487 |
+
if ( false === $params->in_form && 1 == $limit && !empty( $value ) && is_array( $value ) && 1 == count( $value ) )
|
1488 |
+
$value = current( $value );
|
1489 |
+
}
|
1490 |
+
|
1491 |
+
break;
|
1492 |
+
}
|
1493 |
+
}
|
1494 |
+
}
|
1495 |
+
}
|
1496 |
+
}
|
1497 |
+
|
1498 |
+
if ( !empty( $params->traverse ) && 1 < count( $params->traverse ) ) {
|
1499 |
+
$field_names = implode( '.', $params->traverse );
|
1500 |
+
|
1501 |
+
$this->row[ $field_names ] = $value;
|
1502 |
+
}
|
1503 |
+
elseif ( 'arrays' != $params->output && in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
1504 |
+
$this->row[ '_' . $params->output . '_' . $params->full_name ] = $value;
|
1505 |
+
}
|
1506 |
+
elseif ( 'arrays' == $params->output || !in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
1507 |
+
$this->row[ $params->full_name ] = $value;
|
1508 |
+
}
|
1509 |
+
|
1510 |
+
if ( $params->single && is_array( $value ) && 1 == count( $value ) )
|
1511 |
+
$value = current( $value );
|
1512 |
+
|
1513 |
+
// @todo Expand this into traversed fields too
|
1514 |
+
if ( !empty( $field_data ) && ( $params->display || !$params->raw ) && !$params->in_form && !$params->raw_display ) {
|
1515 |
+
if ( $params->display || ( ( $params->get_meta || $params->deprecated ) && !in_array( $field_data[ 'type' ], $tableless_field_types ) ) ) {
|
1516 |
+
$field_data[ 'options' ] = pods_var_raw( 'options', $field_data, array(), null, true );
|
1517 |
+
|
1518 |
+
$post_temp = false;
|
1519 |
+
|
1520 |
+
if ( 'post_type' == pods_var( 'type', $this->pod_data ) && 0 < $this->id() && ( !isset( $GLOBALS[ 'post' ] ) || empty( $GLOBALS[ 'post' ] ) ) ) {
|
1521 |
+
global $post_ID, $post;
|
1522 |
+
|
1523 |
+
$post_temp = true;
|
1524 |
+
|
1525 |
+
$old_post = $GLOBALS[ 'post' ];
|
1526 |
+
$old_ID = $GLOBALS[ 'post_ID' ];
|
1527 |
+
|
1528 |
+
$post = get_post( $this->id() );
|
1529 |
+
$post_ID = $this->id();
|
1530 |
+
}
|
1531 |
+
|
1532 |
+
$filter = pods_var_raw( 'display_filter', $field_data[ 'options' ] );
|
1533 |
+
|
1534 |
+
if ( 0 < strlen( $filter ) ) {
|
1535 |
+
$args = array(
|
1536 |
+
$filter,
|
1537 |
+
$value
|
1538 |
+
);
|
1539 |
+
|
1540 |
+
$filter_args = pods_var_raw( 'display_filter_args', $field_data[ 'options' ] );
|
1541 |
+
|
1542 |
+
if ( !empty( $filter_args ) )
|
1543 |
+
$args = array_merge( $args, compact( $filter_args ) );
|
1544 |
+
|
1545 |
+
$value = call_user_func_array( 'apply_filters', $args );
|
1546 |
+
}
|
1547 |
+
elseif ( 1 == pods_var( 'display_process', $field_data[ 'options' ], 1 ) ) {
|
1548 |
+
$value = PodsForm::display(
|
1549 |
+
$field_data[ 'type' ],
|
1550 |
+
$value,
|
1551 |
+
$params->name,
|
1552 |
+
array_merge( $field_data, $field_data[ 'options' ] ),
|
1553 |
+
$this->pod_data,
|
1554 |
+
$this->id()
|
1555 |
+
);
|
1556 |
+
}
|
1557 |
+
|
1558 |
+
if ( $post_temp ) {
|
1559 |
+
$post = $old_post;
|
1560 |
+
$post_ID = $old_ID;
|
1561 |
+
}
|
1562 |
+
}
|
1563 |
+
else {
|
1564 |
+
$value = PodsForm::value(
|
1565 |
+
$field_data[ 'type' ],
|
1566 |
+
$value,
|
1567 |
+
$params->name,
|
1568 |
+
array_merge( $field_data, $field_data[ 'options' ] ),
|
1569 |
+
$this->pod_data,
|
1570 |
+
$this->id()
|
1571 |
+
);
|
1572 |
+
}
|
1573 |
+
}
|
1574 |
+
|
1575 |
+
$value = $this->do_hook( 'field', $value, $this->row, $params );
|
1576 |
+
|
1577 |
+
return $value;
|
1578 |
+
}
|
1579 |
+
|
1580 |
+
/**
|
1581 |
+
* Check if an item field has a specific value in it
|
1582 |
+
*
|
1583 |
+
* @param string $field Field name
|
1584 |
+
* @param mixed $value Value to check
|
1585 |
+
* @param int $id (optional) ID of the pod item to check
|
1586 |
+
*
|
1587 |
+
* @return bool Whether the value was found
|
1588 |
+
*
|
1589 |
+
* @since 2.3.3
|
1590 |
+
*/
|
1591 |
+
public function has ( $field, $value, $id = null ) {
|
1592 |
+
$pod =& $this;
|
1593 |
+
|
1594 |
+
if ( null === $id )
|
1595 |
+
$id = $this->id();
|
1596 |
+
elseif ( $id != $this->id() )
|
1597 |
+
$pod = pods( $this->pod, $id );
|
1598 |
+
|
1599 |
+
$this->do_hook( 'has', $field, $value, $id );
|
1600 |
+
|
1601 |
+
if ( !isset( $this->fields[ $field ] ) )
|
1602 |
+
return false;
|
1603 |
+
|
1604 |
+
// Tableless fields
|
1605 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
1606 |
+
if ( !is_array( $value ) )
|
1607 |
+
$value = explode( ',', $value );
|
1608 |
+
|
1609 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::field_method( 'pick', 'simple_objects' ) ) ) {
|
1610 |
+
$current_value = $pod->raw( $field );
|
1611 |
+
|
1612 |
+
if ( !empty( $current_value ) )
|
1613 |
+
$current_value = (array) $current_value;
|
1614 |
+
|
1615 |
+
foreach ( $current_value as $v ) {
|
1616 |
+
if ( in_array( $v, $value ) )
|
1617 |
+
return true;
|
1618 |
+
}
|
1619 |
+
}
|
1620 |
+
else {
|
1621 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
1622 |
+
|
1623 |
+
foreach ( $value as $k => $v ) {
|
1624 |
+
if ( !preg_match( '/[^0-9]/', $v ) )
|
1625 |
+
$value[ $k ] = (int) $v;
|
1626 |
+
// @todo Convert slugs into IDs
|
1627 |
+
else {
|
1628 |
+
|
1629 |
+
}
|
1630 |
+
}
|
1631 |
+
|
1632 |
+
foreach ( $related_ids as $v ) {
|
1633 |
+
if ( in_array( $v, $value ) )
|
1634 |
+
return true;
|
1635 |
+
}
|
1636 |
+
}
|
1637 |
+
}
|
1638 |
+
// Text fields
|
1639 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
|
1640 |
+
$current_value = $pod->raw( $field );
|
1641 |
+
|
1642 |
+
if ( 0 < strlen( $current_value ) )
|
1643 |
+
return stripos( $current_value, $value );
|
1644 |
+
}
|
1645 |
+
// All other fields
|
1646 |
+
else
|
1647 |
+
return $this->is( $field, $value, $id );
|
1648 |
+
|
1649 |
+
return false;
|
1650 |
+
}
|
1651 |
+
|
1652 |
+
/**
|
1653 |
+
* Check if an item field is a specific value
|
1654 |
+
*
|
1655 |
+
* @param string $field Field name
|
1656 |
+
* @param mixed $value Value to check
|
1657 |
+
* @param int $id (optional) ID of the pod item to check
|
1658 |
+
*
|
1659 |
+
* @return bool Whether the value was found
|
1660 |
+
*
|
1661 |
+
* @since 2.3.3
|
1662 |
+
*/
|
1663 |
+
public function is ( $field, $value, $id = null ) {
|
1664 |
+
$pod =& $this;
|
1665 |
+
|
1666 |
+
if ( null === $id )
|
1667 |
+
$id = $this->id();
|
1668 |
+
elseif ( $id != $this->id() )
|
1669 |
+
$pod = pods( $this->pod, $id );
|
1670 |
+
|
1671 |
+
$this->do_hook( 'is', $field, $value, $id );
|
1672 |
+
|
1673 |
+
if ( !isset( $this->fields[ $field ] ) )
|
1674 |
+
return false;
|
1675 |
+
|
1676 |
+
// Tableless fields
|
1677 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
1678 |
+
if ( !is_array( $value ) )
|
1679 |
+
$value = explode( ',', $value );
|
1680 |
+
|
1681 |
+
$current_value = array();
|
1682 |
+
|
1683 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::field_method( 'pick', 'simple_objects' ) ) ) {
|
1684 |
+
$current_value = $pod->raw( $field );
|
1685 |
+
|
1686 |
+
if ( !empty( $current_value ) )
|
1687 |
+
$current_value = (array) $current_value;
|
1688 |
+
|
1689 |
+
foreach ( $current_value as $v ) {
|
1690 |
+
if ( in_array( $v, $value ) )
|
1691 |
+
return true;
|
1692 |
+
}
|
1693 |
+
}
|
1694 |
+
else {
|
1695 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
1696 |
+
|
1697 |
+
foreach ( $value as $k => $v ) {
|
1698 |
+
if ( !preg_match( '/[^0-9]/', $v ) )
|
1699 |
+
$value[ $k ] = (int) $v;
|
1700 |
+
// @todo Convert slugs into IDs
|
1701 |
+
else {
|
1702 |
+
|
1703 |
+
}
|
1704 |
+
}
|
1705 |
+
|
1706 |
+
foreach ( $related_ids as $v ) {
|
1707 |
+
if ( in_array( $v, $value ) )
|
1708 |
+
return true;
|
1709 |
+
}
|
1710 |
+
}
|
1711 |
+
|
1712 |
+
if ( !empty( $current_value ) )
|
1713 |
+
$current_value = array_filter( array_unique( $current_value ) );
|
1714 |
+
else
|
1715 |
+
$current_value = array();
|
1716 |
+
|
1717 |
+
if ( !empty( $value ) )
|
1718 |
+
$value = array_filter( array_unique( $value ) );
|
1719 |
+
else
|
1720 |
+
$value = array();
|
1721 |
+
|
1722 |
+
sort( $current_value );
|
1723 |
+
sort( $value );
|
1724 |
+
|
1725 |
+
if ( $value === $current_value )
|
1726 |
+
return true;
|
1727 |
+
}
|
1728 |
+
// Number fields
|
1729 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
|
1730 |
+
$current_value = $pod->raw( $field );
|
1731 |
+
|
1732 |
+
if ( (float) $current_value === (float) $value )
|
1733 |
+
return true;
|
1734 |
+
}
|
1735 |
+
// Date fields
|
1736 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
|
1737 |
+
$current_value = $pod->raw( $field );
|
1738 |
+
|
1739 |
+
if ( 0 < strlen( $current_value ) ) {
|
1740 |
+
if ( strtotime( $current_value ) == strtotime( $value ) )
|
1741 |
+
return true;
|
1742 |
+
}
|
1743 |
+
elseif ( empty( $value ) )
|
1744 |
+
return true;
|
1745 |
+
}
|
1746 |
+
// Text fields
|
1747 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
|
1748 |
+
$current_value = $pod->raw( $field );
|
1749 |
+
|
1750 |
+
if ( (string) $current_value === (string) $value )
|
1751 |
+
return true;
|
1752 |
+
}
|
1753 |
+
// All other fields
|
1754 |
+
else {
|
1755 |
+
$current_value = $pod->raw( $field );
|
1756 |
+
|
1757 |
+
if ( $current_value === $value )
|
1758 |
+
return true;
|
1759 |
+
}
|
1760 |
+
|
1761 |
+
return false;
|
1762 |
+
}
|
1763 |
+
|
1764 |
+
/**
|
1765 |
+
* Return the item ID
|
1766 |
+
*
|
1767 |
+
* @return int
|
1768 |
+
* @since 2.0
|
1769 |
+
*/
|
1770 |
+
public function id () {
|
1771 |
+
return $this->field( $this->data->field_id );
|
1772 |
+
}
|
1773 |
+
|
1774 |
+
/**
|
1775 |
+
* Return the previous item ID, loops at the last id to return the first
|
1776 |
+
*
|
1777 |
+
* @param int $id
|
1778 |
+
* @param array $params_override
|
1779 |
+
*
|
1780 |
+
* @return int
|
1781 |
+
* @since 2.0
|
1782 |
+
*/
|
1783 |
+
public function prev_id ( $id = null, $params_override = null ) {
|
1784 |
+
if ( null === $id )
|
1785 |
+
$id = $this->id();
|
1786 |
+
|
1787 |
+
$id = (int) $id;
|
1788 |
+
|
1789 |
+
$params = array(
|
1790 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
1791 |
+
'where' => "`t`.`{$this->data->field_id}` < {$id}",
|
1792 |
+
'orderby' => "`t`.`{$this->data->field_id}` DESC",
|
1793 |
+
'limit' => 1
|
1794 |
+
);
|
1795 |
+
|
1796 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
1797 |
+
if ( !empty( $params_override ) )
|
1798 |
+
$params = $params_override;
|
1799 |
+
elseif ( !empty( $this->params ) )
|
1800 |
+
$params = $this->params;
|
1801 |
+
|
1802 |
+
if ( is_object( $params ) ) {
|
1803 |
+
$params = get_object_vars( $params );
|
1804 |
+
}
|
1805 |
+
|
1806 |
+
if ( 0 < $id ) {
|
1807 |
+
if ( isset( $params[ 'where' ] ) && !empty( $params[ 'where' ] ) ) {
|
1808 |
+
$params[ 'where' ] = (array) $params[ 'where' ];
|
1809 |
+
$params[ 'where' ][] = "`t`.`{$this->data->field_id}` < {$id}";
|
1810 |
+
}
|
1811 |
+
else {
|
1812 |
+
$params[ 'where' ] = "`t`.`{$this->data->field_id}` < {$id}";
|
1813 |
+
}
|
1814 |
+
}
|
1815 |
+
elseif ( isset( $params[ 'offset' ] ) && 0 < $params[ 'offset' ] )
|
1816 |
+
$params[ 'offset' ] -= 1;
|
1817 |
+
elseif ( !isset( $params[ 'offset' ] ) && !empty( $this->params ) && 0 < $this->row_number )
|
1818 |
+
$params[ 'offset' ] = $this->row_number - 1;
|
1819 |
+
else
|
1820 |
+
return 0;
|
1821 |
+
|
1822 |
+
if ( isset( $params[ 'orderby' ] ) && !empty( $params[ 'orderby' ] ) ) {
|
1823 |
+
if ( is_array( $params[ 'orderby' ] ) ) {
|
1824 |
+
foreach ( $params[ 'orderby' ] as $orderby => $dir ) {
|
1825 |
+
$dir = strtoupper( $dir );
|
1826 |
+
|
1827 |
+
if ( !in_array( $dir, array( 'ASC', 'DESC' ) ) ) {
|
1828 |
+
continue;
|
1829 |
+
}
|
1830 |
+
|
1831 |
+
if ( 'ASC' == $dir ) {
|
1832 |
+
$params[ 'orderby' ][ $orderby ] = 'DESC';
|
1833 |
+
}
|
1834 |
+
else {
|
1835 |
+
$params[ 'orderby' ][ $orderby ] = 'ASC';
|
1836 |
+
}
|
1837 |
+
}
|
1838 |
+
|
1839 |
+
$params[ 'orderby' ][ $this->data->field_id ] = 'DESC';
|
1840 |
+
}
|
1841 |
+
elseif ( "`t`.`{$this->data->field_id}` DESC" != $params[ 'orderby' ] ) {
|
1842 |
+
$params[ 'orderby' ] .= ", `t`.`{$this->data->field_id}` DESC";
|
1843 |
+
}
|
1844 |
+
}
|
1845 |
+
|
1846 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
1847 |
+
$params[ 'limit' ] = 1;
|
1848 |
+
}
|
1849 |
+
|
1850 |
+
$pod = pods( $this->pod, $params );
|
1851 |
+
|
1852 |
+
$new_id = 0;
|
1853 |
+
|
1854 |
+
if ( $pod->fetch() )
|
1855 |
+
$new_id = $pod->id();
|
1856 |
+
|
1857 |
+
$new_id = $this->do_hook( 'prev_id', $new_id, $id, $pod, $params_override );
|
1858 |
+
|
1859 |
+
return $new_id;
|
1860 |
+
}
|
1861 |
+
|
1862 |
+
/**
|
1863 |
+
* Return the next item ID, loops at the first id to return the last
|
1864 |
+
*
|
1865 |
+
* @param int $id
|
1866 |
+
* @param array $find_params
|
1867 |
+
*
|
1868 |
+
* @return int
|
1869 |
+
* @since 2.0
|
1870 |
+
*/
|
1871 |
+
public function next_id ( $id = null, $params_override = null ) {
|
1872 |
+
if ( null === $id )
|
1873 |
+
$id = $this->id();
|
1874 |
+
|
1875 |
+
$id = (int) $id;
|
1876 |
+
|
1877 |
+
$params = array(
|
1878 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
1879 |
+
'where' => "{$id} < `t`.`{$this->data->field_id}`",
|
1880 |
+
'orderby' => "`t`.`{$this->data->field_id}` ASC",
|
1881 |
+
'limit' => 1
|
1882 |
+
);
|
1883 |
+
|
1884 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
1885 |
+
if ( !empty( $params_override ) )
|
1886 |
+
$params = $params_override;
|
1887 |
+
elseif ( !empty( $this->params ) )
|
1888 |
+
$params = $this->params;
|
1889 |
+
|
1890 |
+
if ( is_object( $params ) ) {
|
1891 |
+
$params = get_object_vars( $params );
|
1892 |
+
}
|
1893 |
+
|
1894 |
+
if ( 0 < $id ) {
|
1895 |
+
if ( isset( $params[ 'where' ] ) && !empty( $params[ 'where' ] ) ) {
|
1896 |
+
$params[ 'where' ] = (array) $params[ 'where' ];
|
1897 |
+
$params[ 'where' ][] = "{$id} < `t`.`{$this->data->field_id}`";
|
1898 |
+
}
|
1899 |
+
else {
|
1900 |
+
$params[ 'where' ] = "{$id} < `t`.`{$this->data->field_id}`";
|
1901 |
+
}
|
1902 |
+
}
|
1903 |
+
elseif ( !isset( $params[ 'offset' ] ) ) {
|
1904 |
+
if ( !empty( $this->params ) && -1 < $this->row_number )
|
1905 |
+
$params[ 'offset' ] = $this->row_number + 1;
|
1906 |
+
else
|
1907 |
+
$params[ 'offset' ] = 1;
|
1908 |
+
}
|
1909 |
+
else
|
1910 |
+
$params[ 'offset' ] += 1;
|
1911 |
+
|
1912 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
1913 |
+
$params[ 'limit' ] = 1;
|
1914 |
+
}
|
1915 |
+
|
1916 |
+
$pod = pods( $this->pod, $params );
|
1917 |
+
|
1918 |
+
$new_id = 0;
|
1919 |
+
|
1920 |
+
if ( $pod->fetch() )
|
1921 |
+
$new_id = $pod->id();
|
1922 |
+
|
1923 |
+
$new_id = $this->do_hook( 'next_id', $new_id, $id, $pod, $params_override );
|
1924 |
+
|
1925 |
+
return $new_id;
|
1926 |
+
}
|
1927 |
+
|
1928 |
+
/**
|
1929 |
+
* Return the first item ID
|
1930 |
+
*
|
1931 |
+
* @param array $params_override
|
1932 |
+
*
|
1933 |
+
* @return int
|
1934 |
+
* @since 2.3
|
1935 |
+
*/
|
1936 |
+
public function first_id ( $params_override = null ) {
|
1937 |
+
$params = array(
|
1938 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
1939 |
+
'orderby' => "`t`.`{$this->data->field_id}` ASC",
|
1940 |
+
'limit' => 1
|
1941 |
+
);
|
1942 |
+
|
1943 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
1944 |
+
if ( !empty( $params_override ) )
|
1945 |
+
$params = $params_override;
|
1946 |
+
elseif ( !empty( $this->params ) )
|
1947 |
+
$params = $this->params;
|
1948 |
+
|
1949 |
+
if ( is_object( $params ) ) {
|
1950 |
+
$params = get_object_vars( $params );
|
1951 |
+
}
|
1952 |
+
|
1953 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
1954 |
+
$params[ 'offset' ] = 0;
|
1955 |
+
$params[ 'limit' ] = 1;
|
1956 |
+
}
|
1957 |
+
|
1958 |
+
$pod = pods( $this->pod, $params );
|
1959 |
+
|
1960 |
+
$new_id = 0;
|
1961 |
+
|
1962 |
+
if ( $pod->fetch() )
|
1963 |
+
$new_id = $pod->id();
|
1964 |
+
|
1965 |
+
$new_id = $this->do_hook( 'first_id', $new_id, $pod, $params_override );
|
1966 |
+
|
1967 |
+
return $new_id;
|
1968 |
+
}
|
1969 |
+
|
1970 |
+
/**
|
1971 |
+
* Return the last item ID
|
1972 |
+
*
|
1973 |
+
* @param array $params_override
|
1974 |
+
*
|
1975 |
+
* @return int
|
1976 |
+
* @since 2.3
|
1977 |
+
*/
|
1978 |
+
public function last_id ( $params_override = null ) {
|
1979 |
+
$params = array(
|
1980 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
1981 |
+
'orderby' => "`t`.`{$this->data->field_id}` DESC",
|
1982 |
+
'limit' => 1
|
1983 |
+
);
|
1984 |
+
|
1985 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
1986 |
+
if ( !empty( $params_override ) )
|
1987 |
+
$params = $params_override;
|
1988 |
+
elseif ( !empty( $this->params ) )
|
1989 |
+
$params = $this->params;
|
1990 |
+
|
1991 |
+
if ( is_object( $params ) ) {
|
1992 |
+
$params = get_object_vars( $params );
|
1993 |
+
}
|
1994 |
+
|
1995 |
+
if ( isset( $params[ 'total_found' ] ) )
|
1996 |
+
$params[ 'offset' ] = $params[ 'total_found' ] - 1;
|
1997 |
+
else
|
1998 |
+
$params[ 'offset' ] = $this->total_found() - 1;
|
1999 |
+
|
2000 |
+
if ( isset( $params[ 'orderby' ] ) && !empty( $params[ 'orderby' ] ) ) {
|
2001 |
+
if ( is_array( $params[ 'orderby' ] ) ) {
|
2002 |
+
foreach ( $params[ 'orderby' ] as $orderby => $dir ) {
|
2003 |
+
$dir = strtoupper( $dir );
|
2004 |
+
|
2005 |
+
if ( !in_array( $dir, array( 'ASC', 'DESC' ) ) ) {
|
2006 |
+
continue;
|
2007 |
+
}
|
2008 |
+
|
2009 |
+
if ( 'ASC' == $dir ) {
|
2010 |
+
$params[ 'orderby' ][ $orderby ] = 'DESC';
|
2011 |
+
}
|
2012 |
+
else {
|
2013 |
+
$params[ 'orderby' ][ $orderby ] = 'ASC';
|
2014 |
+
}
|
2015 |
+
}
|
2016 |
+
|
2017 |
+
$params[ 'orderby' ][ $this->data->field_id ] = 'DESC';
|
2018 |
+
}
|
2019 |
+
elseif ( "`t`.`{$this->data->field_id}` DESC" != $params[ 'orderby' ] ) {
|
2020 |
+
$params[ 'orderby' ] .= ", `t`.`{$this->data->field_id}` DESC";
|
2021 |
+
}
|
2022 |
+
}
|
2023 |
+
|
2024 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
2025 |
+
$params[ 'limit' ] = 1;
|
2026 |
+
}
|
2027 |
+
|
2028 |
+
$pod = pods( $this->pod, $params );
|
2029 |
+
|
2030 |
+
$new_id = 0;
|
2031 |
+
|
2032 |
+
if ( $pod->fetch() )
|
2033 |
+
$new_id = $pod->id();
|
2034 |
+
|
2035 |
+
$new_id = $this->do_hook( 'last_id', $new_id, $pod, $params_override );
|
2036 |
+
}
|
2037 |
+
|
2038 |
+
/**
|
2039 |
+
* Return the item name
|
2040 |
+
*
|
2041 |
+
* @return string
|
2042 |
+
* @since 2.0
|
2043 |
+
*/
|
2044 |
+
public function index () {
|
2045 |
+
return $this->field( $this->data->field_index );
|
2046 |
+
}
|
2047 |
+
|
2048 |
+
/**
|
2049 |
+
* Find items of a pod, much like WP_Query, but with advanced table handling.
|
2050 |
+
*
|
2051 |
+
* @param array $params An associative array of parameters
|
2052 |
+
* @param int $limit (optional) (deprecated) Limit the number of items to find, use -1 to return all items with no limit
|
2053 |
+
* @param string $where (optional) (deprecated) SQL WHERE declaration to use
|
2054 |
+
* @param string $sql (optional) (deprecated) For advanced use, a custom SQL query to run
|
2055 |
+
*
|
2056 |
+
* @return \Pods The pod object
|
2057 |
+
* @since 2.0
|
2058 |
+
* @link http://pods.io/docs/find/
|
2059 |
+
*/
|
2060 |
+
public function find ( $params = null, $limit = 15, $where = null, $sql = null ) {
|
2061 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
2062 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
2063 |
+
|
2064 |
+
$this->params = $params;
|
2065 |
+
|
2066 |
+
$select = '`t`.*';
|
2067 |
+
|
2068 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) && 'table' == $this->pod_data[ 'storage' ] )
|
2069 |
+
$select .= ', `d`.*';
|
2070 |
+
|
2071 |
+
if ( empty( $this->data->table ) )
|
2072 |
+
return $this;
|
2073 |
+
|
2074 |
+
$defaults = array(
|
2075 |
+
'table' => $this->data->table,
|
2076 |
+
'select' => $select,
|
2077 |
+
'join' => null,
|
2078 |
+
|
2079 |
+
'where' => $where,
|
2080 |
+
'groupby' => null,
|
2081 |
+
'having' => null,
|
2082 |
+
'orderby' => null,
|
2083 |
+
|
2084 |
+
'limit' => (int) $limit,
|
2085 |
+
'offset' => null,
|
2086 |
+
'page' => (int) $this->page,
|
2087 |
+
'page_var' => $this->page_var,
|
2088 |
+
'pagination' => (boolean) $this->pagination,
|
2089 |
+
|
2090 |
+
'search' => (boolean) $this->search,
|
2091 |
+
'search_var' => $this->search_var,
|
2092 |
+
'search_query' => null,
|
2093 |
+
'search_mode' => $this->search_mode,
|
2094 |
+
'search_across' => false,
|
2095 |
+
'search_across_picks' => false,
|
2096 |
+
'search_across_files' => false,
|
2097 |
+
|
2098 |
+
'filters' => $this->filters,
|
2099 |
+
'sql' => $sql,
|
2100 |
+
|
2101 |
+
'expires' => null,
|
2102 |
+
'cache_mode' => 'cache'
|
2103 |
+
);
|
2104 |
+
|
2105 |
+
if ( is_array( $params ) )
|
2106 |
+
$params = (object) array_merge( $defaults, $params );
|
2107 |
+
if ( is_object( $params ) )
|
2108 |
+
$params = (object) array_merge( $defaults, get_object_vars( $params ) );
|
2109 |
+
else {
|
2110 |
+
$defaults[ 'orderby' ] = $params;
|
2111 |
+
$params = (object) $defaults;
|
2112 |
+
}
|
2113 |
+
|
2114 |
+
$params = $this->do_hook( 'find', $params );
|
2115 |
+
|
2116 |
+
$params->limit = (int) $params->limit;
|
2117 |
+
|
2118 |
+
if ( 0 == $params->limit )
|
2119 |
+
$params->limit = -1;
|
2120 |
+
|
2121 |
+
$this->limit = (int) $params->limit;
|
2122 |
+
$this->offset = (int) $params->offset;
|
2123 |
+
$this->page = (int) $params->page;
|
2124 |
+
$this->page_var = $params->page_var;
|
2125 |
+
$this->pagination = (boolean) $params->pagination;
|
2126 |
+
$this->search = (boolean) $params->search;
|
2127 |
+
$this->search_var = $params->search_var;
|
2128 |
+
$params->join = (array) $params->join;
|
2129 |
+
|
2130 |
+
if ( empty( $params->search_query ) )
|
2131 |
+
$params->search_query = pods_var( $this->search_var, 'get', '' );
|
2132 |
+
|
2133 |
+
// Allow orderby array ( 'field' => 'asc|desc' )
|
2134 |
+
if ( !empty( $params->orderby ) && is_array( $params->orderby ) ) {
|
2135 |
+
foreach ( $params->orderby as $k => &$orderby ) {
|
2136 |
+
if ( !is_numeric( $k ) ) {
|
2137 |
+
$key = '';
|
2138 |
+
|
2139 |
+
$order = 'ASC';
|
2140 |
+
|
2141 |
+
if ( 'DESC' == strtoupper( $orderby ) )
|
2142 |
+
$order = 'DESC';
|
2143 |
+
|
2144 |
+
if ( isset( $this->fields[ $k ] ) && in_array( $this->fields[ $k ][ 'type' ], $tableless_field_types ) ) {
|
2145 |
+
if ( in_array( $this->fields[ $k ][ 'pick_object' ], $simple_tableless_objects ) ) {
|
2146 |
+
if ( 'table' == $this->pod_data[ 'storage' ] ) {
|
2147 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) )
|
2148 |
+
$key = "`d`.`{$k}`";
|
2149 |
+
else
|
2150 |
+
$key = "`t`.`{$k}`";
|
2151 |
+
}
|
2152 |
+
else
|
2153 |
+
$key = "`{$k}`.`meta_value`";
|
2154 |
+
}
|
2155 |
+
else {
|
2156 |
+
$pick_val = $this->fields[ $k ][ 'pick_val' ];
|
2157 |
+
|
2158 |
+
if ( '__current__' == $pick_val )
|
2159 |
+
$pick_val = $this->pod;
|
2160 |
+
|
2161 |
+
$table = $this->api->get_table_info( $this->fields[ $k ][ 'pick_object' ], $pick_val );
|
2162 |
+
|
2163 |
+
if ( !empty( $table ) )
|
2164 |
+
$key = "`{$k}`.`" . $table[ 'field_index' ] . '`';
|
2165 |
+
}
|
2166 |
+
}
|
2167 |
+
|
2168 |
+
if ( empty( $key ) ) {
|
2169 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
|
2170 |
+
if ( isset( $this->pod_data[ 'object_fields' ][ $k ] ) )
|
2171 |
+
$key = "`t`.`{$k}`";
|
2172 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
2173 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
2174 |
+
$key = "`d`.`{$k}`";
|
2175 |
+
else
|
2176 |
+
$key = "`{$k}`.`meta_value`";
|
2177 |
+
}
|
2178 |
+
else {
|
2179 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
2180 |
+
if ( $object_field == $k || in_array( $k, $object_field_opt[ 'alias' ] ) )
|
2181 |
+
$key = "`t`.`{$object_field}`";
|
2182 |
+
}
|
2183 |
+
}
|
2184 |
+
}
|
2185 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
2186 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
2187 |
+
$key = "`t`.`{$k}`";
|
2188 |
+
else
|
2189 |
+
$key = "`{$k}`.`meta_value`";
|
2190 |
+
}
|
2191 |
+
|
2192 |
+
if ( empty( $key ) ) {
|
2193 |
+
$key = $k;
|
2194 |
+
|
2195 |
+
if ( false === strpos( $key, ' ' ) && false === strpos( $key, '`' ) )
|
2196 |
+
$key = '`' . str_replace( '.', '`.`', $key ) . '`';
|
2197 |
+
}
|
2198 |
+
}
|
2199 |
+
|
2200 |
+
$orderby = $key;
|
2201 |
+
|
2202 |
+
if ( false === strpos( $orderby, ' ' ) )
|
2203 |
+
$orderby .= ' ' . $order;
|
2204 |
+
}
|
2205 |
+
}
|
2206 |
+
}
|
2207 |
+
|
2208 |
+
// Add prefix to $params->orderby if needed
|
2209 |
+
if ( !empty( $params->orderby ) ) {
|
2210 |
+
if ( !is_array( $params->orderby ) )
|
2211 |
+
$params->orderby = array( $params->orderby );
|
2212 |
+
|
2213 |
+
foreach ( $params->orderby as &$prefix_orderby ) {
|
2214 |
+
if ( false === strpos( $prefix_orderby, ',' ) && false === strpos( $prefix_orderby, '(' ) && false === stripos( $prefix_orderby, ' AS ' ) && false === strpos( $prefix_orderby, '`' ) && false === strpos( $prefix_orderby, '.' ) ) {
|
2215 |
+
if ( false !== stripos( $prefix_orderby, ' DESC' ) ) {
|
2216 |
+
$k = trim( str_ireplace( array( '`', ' DESC' ), '', $prefix_orderby ) );
|
2217 |
+
$dir = 'DESC';
|
2218 |
+
}
|
2219 |
+
else {
|
2220 |
+
$k = trim( str_ireplace( array( '`', ' ASC' ), '', $prefix_orderby ) );
|
2221 |
+
$dir = 'ASC';
|
2222 |
+
}
|
2223 |
+
|
2224 |
+
$key = $k;
|
2225 |
+
|
2226 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
|
2227 |
+
if ( isset( $this->pod_data[ 'object_fields' ][ $k ] ) )
|
2228 |
+
$key = "`t`.`{$k}`";
|
2229 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
2230 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
2231 |
+
$key = "`d`.`{$k}`";
|
2232 |
+
else
|
2233 |
+
$key = "`{$k}`.`meta_value`";
|
2234 |
+
}
|
2235 |
+
else {
|
2236 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
2237 |
+
if ( $object_field == $k || in_array( $k, $object_field_opt[ 'alias' ] ) )
|
2238 |
+
$key = "`t`.`{$object_field}`";
|
2239 |
+
}
|
2240 |
+
}
|
2241 |
+
}
|
2242 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
2243 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
2244 |
+
$key = "`t`.`{$k}`";
|
2245 |
+
else
|
2246 |
+
$key = "`{$k}`.`meta_value`";
|
2247 |
+
}
|
2248 |
+
|
2249 |
+
$prefix_orderby = "{$key} {$dir}";
|
2250 |
+
}
|
2251 |
+
}
|
2252 |
+
}
|
2253 |
+
|
2254 |
+
$this->data->select( $params );
|
2255 |
+
|
2256 |
+
return $this;
|
2257 |
+
}
|
2258 |
+
|
2259 |
+
/**
|
2260 |
+
* Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
|
2261 |
+
* You can rewind the list back to the start by using reset().
|
2262 |
+
*
|
2263 |
+
* Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id or slug.
|
2264 |
+
*
|
2265 |
+
* @see PodsData::fetch
|
2266 |
+
*
|
2267 |
+
* @param int $id ID or slug of the item to fetch
|
2268 |
+
* @param bool $explicit_set Whether to set explicitly (use false when in loop)
|
2269 |
+
*
|
2270 |
+
* @return array An array of fields from the row
|
2271 |
+
*
|
2272 |
+
* @since 2.0
|
2273 |
+
* @link http://pods.io/docs/fetch/
|
2274 |
+
*/
|
2275 |
+
public function fetch ( $id = null, $explicit_set = true ) {
|
2276 |
+
$this->do_hook( 'fetch', $id );
|
2277 |
+
|
2278 |
+
if ( !empty( $id ) )
|
2279 |
+
$this->params = array();
|
2280 |
+
|
2281 |
+
$this->data->fetch( $id, $explicit_set );
|
2282 |
+
|
2283 |
+
return $this->row;
|
2284 |
+
}
|
2285 |
+
|
2286 |
+
/**
|
2287 |
+
* (Re)set the MySQL result pointer
|
2288 |
+
*
|
2289 |
+
* @see PodsData::reset
|
2290 |
+
*
|
2291 |
+
* @param int $row ID of the row to reset to
|
2292 |
+
*
|
2293 |
+
* @return \Pods The pod object
|
2294 |
+
*
|
2295 |
+
* @since 2.0
|
2296 |
+
* @link http://pods.io/docs/reset/
|
2297 |
+
*/
|
2298 |
+
public function reset ( $row = null ) {
|
2299 |
+
$this->do_hook( 'reset', $row );
|
2300 |
+
|
2301 |
+
$this->data->reset( $row );
|
2302 |
+
|
2303 |
+
return $this;
|
2304 |
+
}
|
2305 |
+
|
2306 |
+
/**
|
2307 |
+
* Fetch the total row count returned by the last call to find(), based on the 'limit' parameter set.
|
2308 |
+
*
|
2309 |
+
* This is different than the total number of rows found in the database, which you can get with total_found().
|
2310 |
+
*
|
2311 |
+
* @see PodsData::total
|
2312 |
+
*
|
2313 |
+
* @return int Number of rows returned by find(), based on the 'limit' parameter set
|
2314 |
+
* @since 2.0
|
2315 |
+
* @link http://pods.io/docs/total/
|
2316 |
+
*/
|
2317 |
+
public function total () {
|
2318 |
+
$this->do_hook( 'total' );
|
2319 |
+
|
2320 |
+
$this->data->total();
|
2321 |
+
|
2322 |
+
$this->total =& $this->data->total;
|
2323 |
+
|
2324 |
+
return $this->total;
|
2325 |
+
}
|
2326 |
+
|
2327 |
+
/**
|
2328 |
+
* Fetch the total amount of rows found by the last call to find(), regardless of the 'limit' parameter set.
|
2329 |
+
*
|
2330 |
+
* This is different than the total number of rows limited by the current call, which you can get with total().
|
2331 |
+
*
|
2332 |
+
* @see PodsData::total_found
|
2333 |
+
*
|
2334 |
+
* @return int Number of rows returned by find(), regardless of the 'limit' parameter
|
2335 |
+
* @since 2.0
|
2336 |
+
* @link http://pods.io/docs/total-found/
|
2337 |
+
*/
|
2338 |
+
public function total_found () {
|
2339 |
+
$this->do_hook( 'total_found' );
|
2340 |
+
|
2341 |
+
$this->data->total_found();
|
2342 |
+
|
2343 |
+
$this->total_found =& $this->data->total_found;
|
2344 |
+
|
2345 |
+
return $this->total_found;
|
2346 |
+
}
|
2347 |
+
|
2348 |
+
/**
|
2349 |
+
* Fetch the total number of pages, based on total rows found and the last find() limit
|
2350 |
+
*
|
2351 |
+
* @param null|int $limit Rows per page
|
2352 |
+
* @param null|int $offset Offset of rows
|
2353 |
+
* @param null|int $total Total rows
|
2354 |
+
*
|
2355 |
+
* @return int Number of pages
|
2356 |
+
* @since 2.3.10
|
2357 |
+
*/
|
2358 |
+
public function total_pages( $limit = null, $offset = null, $total = null ) {
|
2359 |
+
|
2360 |
+
$this->do_hook( 'total_pages' );
|
2361 |
+
|
2362 |
+
if ( null === $limit ) {
|
2363 |
+
$limit = $this->limit;
|
2364 |
+
}
|
2365 |
+
|
2366 |
+
if ( null === $offset ) {
|
2367 |
+
$offset = $this->offset;
|
2368 |
+
}
|
2369 |
+
|
2370 |
+
if ( null === $total ) {
|
2371 |
+
$total = $this->total_found();
|
2372 |
+
}
|
2373 |
+
|
2374 |
+
$total_pages = ceil( ( $total - $offset ) / $limit );
|
2375 |
+
|
2376 |
+
return $total_pages;
|
2377 |
+
|
2378 |
+
}
|
2379 |
+
|
2380 |
+
/**
|
2381 |
+
* Fetch the zebra switch
|
2382 |
+
*
|
2383 |
+
* @see PodsData::zebra
|
2384 |
+
*
|
2385 |
+
* @return bool Zebra state
|
2386 |
+
* @since 1.12
|
2387 |
+
*/
|
2388 |
+
public function zebra () {
|
2389 |
+
$this->do_hook( 'zebra' );
|
2390 |
+
|
2391 |
+
return $this->data->zebra();
|
2392 |
+
}
|
2393 |
+
|
2394 |
+
/**
|
2395 |
+
* Fetch the nth state
|
2396 |
+
*
|
2397 |
+
* @see PodsData::nth
|
2398 |
+
*
|
2399 |
+
* @param int|string $nth The $nth to match on the PodsData::row_number
|
2400 |
+
*
|
2401 |
+
* @return bool Whether $nth matches
|
2402 |
+
* @since 2.3
|
2403 |
+
*/
|
2404 |
+
public function nth ( $nth = null ) {
|
2405 |
+
$this->do_hook( 'nth', $nth );
|
2406 |
+
|
2407 |
+
return $this->data->nth( $nth );
|
2408 |
+
}
|
2409 |
+
|
2410 |
+
/**
|
2411 |
+
* Fetch the current position in the loop (starting at 1)
|
2412 |
+
*
|
2413 |
+
* @see PodsData::position
|
2414 |
+
*
|
2415 |
+
* @return int Current row number (+1)
|
2416 |
+
* @since 2.3
|
2417 |
+
*/
|
2418 |
+
public function position () {
|
2419 |
+
$this->do_hook( 'position' );
|
2420 |
+
|
2421 |
+
return $this->data->position();
|
2422 |
+
}
|
2423 |
+
|
2424 |
+
/**
|
2425 |
+
* Add an item to a Pod by giving an array of field data or set a specific field to
|
2426 |
+
* a specific value if you're just wanting to add a new item but only set one field.
|
2427 |
+
*
|
2428 |
+
* You may be looking for save() in most cases where you're setting a specific field.
|
2429 |
+
*
|
2430 |
+
* @see PodsAPI::save_pod_item
|
2431 |
+
*
|
2432 |
+
* @param array|string $data Either an associative array of field information or a field name
|
2433 |
+
* @param mixed $value (optional) Value of the field, if $data is a field name
|
2434 |
+
*
|
2435 |
+
* @return int The item ID
|
2436 |
+
*
|
2437 |
+
* @since 2.0
|
2438 |
+
* @link http://pods.io/docs/add/
|
2439 |
+
*/
|
2440 |
+
public function add ( $data = null, $value = null ) {
|
2441 |
+
if ( null !== $value )
|
2442 |
+
$data = array( $data => $value );
|
2443 |
+
|
2444 |
+
$data = (array) $this->do_hook( 'add', $data );
|
2445 |
+
|
2446 |
+
if ( empty( $data ) )
|
2447 |
+
return 0;
|
2448 |
+
|
2449 |
+
$params = array(
|
2450 |
+
'pod' => $this->pod,
|
2451 |
+
'data' => $data,
|
2452 |
+
'allow_custom_fields' => true
|
2453 |
+
);
|
2454 |
+
|
2455 |
+
return $this->api->save_pod_item( $params );
|
2456 |
+
}
|
2457 |
+
|
2458 |
+
/**
|
2459 |
+
* Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date field, or add text to a text field
|
2460 |
+
*
|
2461 |
+
* @see PodsAPI::save_pod_item
|
2462 |
+
*
|
2463 |
+
* @param string $field Field name
|
2464 |
+
* @param mixed $value ID(s) to add, int|float to add to number field, string for dates (+1 week), or string for text
|
2465 |
+
* @param int $id (optional) ID of the pod item to update
|
2466 |
+
*
|
2467 |
+
* @return int The item ID
|
2468 |
+
*
|
2469 |
+
* @since 2.3
|
2470 |
+
*/
|
2471 |
+
public function add_to ( $field, $value, $id = null ) {
|
2472 |
+
$pod =& $this;
|
2473 |
+
|
2474 |
+
$fetch = false;
|
2475 |
+
|
2476 |
+
if ( null === $id ) {
|
2477 |
+
$fetch = true;
|
2478 |
+
|
2479 |
+
$id = $this->id();
|
2480 |
+
}
|
2481 |
+
elseif ( $id != $this->id() )
|
2482 |
+
$pod = pods( $this->pod, $id );
|
2483 |
+
|
2484 |
+
$this->do_hook( 'add_to', $field, $value, $id );
|
2485 |
+
|
2486 |
+
if ( !isset( $this->fields[ $field ] ) )
|
2487 |
+
return $id;
|
2488 |
+
|
2489 |
+
// Tableless fields
|
2490 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
2491 |
+
if ( !is_array( $value ) )
|
2492 |
+
$value = explode( ',', $value );
|
2493 |
+
|
2494 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::field_method( 'pick', 'simple_objects' ) ) ) {
|
2495 |
+
$current_value = $pod->raw( $field );
|
2496 |
+
|
2497 |
+
if ( !empty( $current_value ) || ( !is_array( $current_value ) && 0 < strlen( $current_value ) ) )
|
2498 |
+
$current_value = (array) $current_value;
|
2499 |
+
else
|
2500 |
+
$current_value = array();
|
2501 |
+
|
2502 |
+
$value = array_merge( $current_value, $value );
|
2503 |
+
}
|
2504 |
+
else {
|
2505 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
2506 |
+
|
2507 |
+
foreach ( $value as $k => $v ) {
|
2508 |
+
if ( !preg_match( '/[^0-9]/', $v ) )
|
2509 |
+
$value[ $k ] = (int) $v;
|
2510 |
+
}
|
2511 |
+
|
2512 |
+
$value = array_merge( $related_ids, $value );
|
2513 |
+
}
|
2514 |
+
|
2515 |
+
if ( !empty( $value ) )
|
2516 |
+
$value = array_filter( array_unique( $value ) );
|
2517 |
+
else
|
2518 |
+
$value = array();
|
2519 |
+
|
2520 |
+
if ( empty( $value ) )
|
2521 |
+
return $id;
|
2522 |
+
}
|
2523 |
+
// Number fields
|
2524 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
|
2525 |
+
$current_value = (float) $pod->raw( $field );
|
2526 |
+
|
2527 |
+
$value = ( $current_value + (float) $value );
|
2528 |
+
}
|
2529 |
+
// Date fields
|
2530 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
|
2531 |
+
$current_value = $pod->raw( $field );
|
2532 |
+
|
2533 |
+
if ( 0 < strlen( $current_value ) )
|
2534 |
+
$value = strtotime( $value, strtotime( $current_value ) );
|
2535 |
+
else
|
2536 |
+
$value = strtotime( $value );
|
2537 |
+
}
|
2538 |
+
// Text fields
|
2539 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
|
2540 |
+
$current_value = $pod->raw( $field );
|
2541 |
+
|
2542 |
+
if ( 0 < strlen( $current_value ) )
|
2543 |
+
$value = $current_value . $value;
|
2544 |
+
}
|
2545 |
+
|
2546 |
+
// @todo handle object fields and taxonomies
|
2547 |
+
|
2548 |
+
$params = array(
|
2549 |
+
'pod' => $this->pod,
|
2550 |
+
'id' => $id,
|
2551 |
+
'data' => array(
|
2552 |
+
$field => $value
|
2553 |
+
)
|
2554 |
+
);
|
2555 |
+
|
2556 |
+
$id = $this->api->save_pod_item( $params );
|
2557 |
+
|
2558 |
+
if ( 0 < $id && $fetch )
|
2559 |
+
$pod->fetch( $id, false );
|
2560 |
+
|
2561 |
+
return $id;
|
2562 |
+
}
|
2563 |
+
|
2564 |
+
/**
|
2565 |
+
* Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove time to a date field
|
2566 |
+
*
|
2567 |
+
* @see PodsAPI::save_pod_item
|
2568 |
+
*
|
2569 |
+
* @param string $field Field name
|
2570 |
+
* @param mixed $value ID(s) to add, int|float to add to number field, string for dates (-1 week), or string for text
|
2571 |
+
* @param int $id (optional) ID of the pod item to update
|
2572 |
+
*
|
2573 |
+
* @return int The item ID
|
2574 |
+
*
|
2575 |
+
* @since 2.3.3
|
2576 |
+
*/
|
2577 |
+
public function remove_from( $field, $value = null, $id = null ) {
|
2578 |
+
|
2579 |
+
$pod =& $this;
|
2580 |
+
|
2581 |
+
$fetch = false;
|
2582 |
+
|
2583 |
+
if ( null === $id ) {
|
2584 |
+
$fetch = true;
|
2585 |
+
|
2586 |
+
$id = $this->id();
|
2587 |
+
}
|
2588 |
+
elseif ( $id != $this->id() ) {
|
2589 |
+
$pod = pods( $this->pod, $id );
|
2590 |
+
}
|
2591 |
+
|
2592 |
+
$this->do_hook( 'remove_from', $field, $value, $id );
|
2593 |
+
|
2594 |
+
if ( !isset( $this->fields[ $field ] ) ) {
|
2595 |
+
return $id;
|
2596 |
+
}
|
2597 |
+
|
2598 |
+
// Tableless fields
|
2599 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
2600 |
+
if ( empty( $value ) ) {
|
2601 |
+
$value = array();
|
2602 |
+
}
|
2603 |
+
|
2604 |
+
if ( !empty( $value ) ) {
|
2605 |
+
if ( !is_array( $value ) ) {
|
2606 |
+
$value = explode( ',', $value );
|
2607 |
+
}
|
2608 |
+
|
2609 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::field_method( 'pick', 'simple_objects' ) ) ) {
|
2610 |
+
$current_value = $pod->raw( $field );
|
2611 |
+
|
2612 |
+
if ( !empty( $current_value ) ) {
|
2613 |
+
$current_value = (array) $current_value;
|
2614 |
+
}
|
2615 |
+
|
2616 |
+
foreach ( $current_value as $k => $v ) {
|
2617 |
+
if ( in_array( $v, $value ) ) {
|
2618 |
+
unset( $current_value[ $k ] );
|
2619 |
+
}
|
2620 |
+
}
|
2621 |
+
|
2622 |
+
$value = $current_value;
|
2623 |
+
}
|
2624 |
+
else {
|
2625 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
2626 |
+
|
2627 |
+
foreach ( $value as $k => $v ) {
|
2628 |
+
if ( !preg_match( '/[^0-9]/', $v ) ) {
|
2629 |
+
$value[ $k ] = (int) $v;
|
2630 |
+
}
|
2631 |
+
// @todo Convert slugs into IDs
|
2632 |
+
else {
|
2633 |
+
|
2634 |
+
}
|
2635 |
+
}
|
2636 |
+
|
2637 |
+
foreach ( $related_ids as $k => $v ) {
|
2638 |
+
if ( in_array( $v, $value ) ) {
|
2639 |
+
unset( $related_ids[ $k ] );
|
2640 |
+
}
|
2641 |
+
}
|
2642 |
+
|
2643 |
+
$value = $related_ids;
|
2644 |
+
}
|
2645 |
+
|
2646 |
+
if ( !empty( $value ) ) {
|
2647 |
+
$value = array_filter( array_unique( $value ) );
|
2648 |
+
}
|
2649 |
+
else {
|
2650 |
+
$value = array();
|
2651 |
+
}
|
2652 |
+
}
|
2653 |
+
}
|
2654 |
+
// Number fields
|
2655 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
|
2656 |
+
// Date fields don't support empty for removing
|
2657 |
+
if ( empty( $value ) ) {
|
2658 |
+
return $id;
|
2659 |
+
}
|
2660 |
+
|
2661 |
+
$current_value = (float) $pod->raw( $field );
|
2662 |
+
|
2663 |
+
$value = ( $current_value - (float) $value );
|
2664 |
+
}
|
2665 |
+
// Date fields
|
2666 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
|
2667 |
+
// Date fields don't support empty for removing
|
2668 |
+
if ( empty( $value ) ) {
|
2669 |
+
return $id;
|
2670 |
+
}
|
2671 |
+
|
2672 |
+
$current_value = $pod->raw( $field );
|
2673 |
+
|
2674 |
+
if ( 0 < strlen( $current_value ) ) {
|
2675 |
+
$value = strtotime( $value, strtotime( $current_value ) );
|
2676 |
+
}
|
2677 |
+
else {
|
2678 |
+
$value = strtotime( $value );
|
2679 |
+
}
|
2680 |
+
|
2681 |
+
$value = date_i18n( 'Y-m-d h:i:s', $value );
|
2682 |
+
}
|
2683 |
+
|
2684 |
+
// @todo handle object fields and taxonomies
|
2685 |
+
|
2686 |
+
$params = array(
|
2687 |
+
'pod' => $this->pod,
|
2688 |
+
'id' => $id,
|
2689 |
+
'data' => array(
|
2690 |
+
$field => $value
|
2691 |
+
)
|
2692 |
+
);
|
2693 |
+
|
2694 |
+
$id = $this->api->save_pod_item( $params );
|
2695 |
+
|
2696 |
+
if ( 0 < $id && $fetch ) {
|
2697 |
+
$pod->fetch( $id, false );
|
2698 |
+
}
|
2699 |
+
|
2700 |
+
return $id;
|
2701 |
+
|
2702 |
+
}
|
2703 |
+
|
2704 |
+
/**
|
2705 |
+
* Save an item by giving an array of field data or set a specific field to a specific value.
|
2706 |
+
*
|
2707 |
+
* Though this function has the capacity to add new items, best practice should direct you
|
2708 |
+
* to use add() for that instead.
|
2709 |
+
*
|
2710 |
+
* @see PodsAPI::save_pod_item
|
2711 |
+
*
|
2712 |
+
* @param array|string $data Either an associative array of field information or a field name
|
2713 |
+
* @param mixed $value (optional) Value of the field, if $data is a field name
|
2714 |
+
* @param int $id (optional) ID of the pod item to update
|
2715 |
+
* @param array $params (optional) Additional params to send to save_pod_item
|
2716 |
+
*
|
2717 |
+
* @return int The item ID
|
2718 |
+
*
|
2719 |
+
* @since 2.0
|
2720 |
+
* @link http://pods.io/docs/save/
|
2721 |
+
*/
|
2722 |
+
public function save ( $data = null, $value = null, $id = null, $params = null ) {
|
2723 |
+
if ( null !== $value )
|
2724 |
+
$data = array( $data => $value );
|
2725 |
+
|
2726 |
+
$fetch = false;
|
2727 |
+
|
2728 |
+
if ( null === $id ) {
|
2729 |
+
$fetch = true;
|
2730 |
+
|
2731 |
+
$id = $this->id();
|
2732 |
+
}
|
2733 |
+
|
2734 |
+
$data = (array) $this->do_hook( 'save', $data, $id );
|
2735 |
+
|
2736 |
+
if ( empty( $data ) )
|
2737 |
+
return $id;
|
2738 |
+
|
2739 |
+
$default = array();
|
2740 |
+
|
2741 |
+
if ( !empty( $params ) && is_array( $params ) )
|
2742 |
+
$default = $params;
|
2743 |
+
|
2744 |
+
$params = array(
|
2745 |
+
'pod' => $this->pod,
|
2746 |
+
'id' => $id,
|
2747 |
+
'data' => $data,
|
2748 |
+
'allow_custom_fields' => true,
|
2749 |
+
'clear_slug_cache' => false
|
2750 |
+
);
|
2751 |
+
|
2752 |
+
if ( !empty( $default ) )
|
2753 |
+
$params = array_merge( $params, $default );
|
2754 |
+
|
2755 |
+
$id = $this->api->save_pod_item( $params );
|
2756 |
+
|
2757 |
+
if ( 0 < $id && $fetch )
|
2758 |
+
$this->fetch( $id, false );
|
2759 |
+
|
2760 |
+
if ( !empty( $this->pod_data[ 'field_slug' ] ) ) {
|
2761 |
+
if ( 0 < $id && $fetch ) {
|
2762 |
+
$slug = $this->field( $this->pod_data[ 'field_slug' ] );
|
2763 |
+
}
|
2764 |
+
else {
|
2765 |
+
$slug = pods( $this->pod, $id )->field( $this->pod_data[ 'field_slug' ] );
|
2766 |
+
}
|
2767 |
+
|
2768 |
+
if ( 0 < strlen( $slug ) ) {
|
2769 |
+
pods_cache_clear( $slug, 'pods_items_' . $this->pod );
|
2770 |
+
}
|
2771 |
+
}
|
2772 |
+
|
2773 |
+
return $id;
|
2774 |
+
}
|
2775 |
+
|
2776 |
+
/**
|
2777 |
+
* Delete an item
|
2778 |
+
*
|
2779 |
+
* @see PodsAPI::delete_pod_item
|
2780 |
+
*
|
2781 |
+
* @param int $id ID of the Pod item to delete
|
2782 |
+
*
|
2783 |
+
* @return bool Whether the item was successfully deleted
|
2784 |
+
*
|
2785 |
+
* @since 2.0
|
2786 |
+
* @link http://pods.io/docs/delete/
|
2787 |
+
*/
|
2788 |
+
public function delete ( $id = null ) {
|
2789 |
+
if ( null === $id )
|
2790 |
+
$id = $this->id();
|
2791 |
+
|
2792 |
+
$id = (int) $this->do_hook( 'delete', $id );
|
2793 |
+
|
2794 |
+
if ( empty( $id ) )
|
2795 |
+
return false;
|
2796 |
+
|
2797 |
+
$params = array(
|
2798 |
+
'pod' => $this->pod,
|
2799 |
+
'id' => $id
|
2800 |
+
);
|
2801 |
+
|
2802 |
+
return $this->api->delete_pod_item( $params );
|
2803 |
+
}
|
2804 |
+
|
2805 |
+
/**
|
2806 |
+
* Reset Pod
|
2807 |
+
*
|
2808 |
+
* @see PodsAPI::reset_pod
|
2809 |
+
*
|
2810 |
+
* @return bool Whether the Pod was successfully reset
|
2811 |
+
*
|
2812 |
+
* @since 2.1.1
|
2813 |
+
*/
|
2814 |
+
public function reset_pod () {
|
2815 |
+
$params = array( 'id' => $this->pod_id );
|
2816 |
+
|
2817 |
+
$this->data->id = null;
|
2818 |
+
$this->data->row = array();
|
2819 |
+
$this->data->data = array();
|
2820 |
+
|
2821 |
+
$this->data->total = 0;
|
2822 |
+
$this->data->total_found = 0;
|
2823 |
+
|
2824 |
+
return $this->api->reset_pod( $params );
|
2825 |
+
}
|
2826 |
+
|
2827 |
+
/**
|
2828 |
+
* Duplicate an item
|
2829 |
+
*
|
2830 |
+
* @see PodsAPI::duplicate_pod_item
|
2831 |
+
*
|
2832 |
+
* @param int $id ID of the pod item to duplicate
|
2833 |
+
*
|
2834 |
+
* @return int|bool ID of the new pod item
|
2835 |
+
*
|
2836 |
+
* @since 2.0
|
2837 |
+
* @link http://pods.io/docs/duplicate/
|
2838 |
+
*/
|
2839 |
+
public function duplicate ( $id = null ) {
|
2840 |
+
if ( null === $id )
|
2841 |
+
$id = $this->id();
|
2842 |
+
|
2843 |
+
$id = (int) $this->do_hook( 'duplicate', $id );
|
2844 |
+
|
2845 |
+
if ( empty( $id ) )
|
2846 |
+
return false;
|
2847 |
+
|
2848 |
+
$params = array(
|
2849 |
+
'pod' => $this->pod,
|
2850 |
+
'id' => $id
|
2851 |
+
);
|
2852 |
+
|
2853 |
+
return $this->api->duplicate_pod_item( $params );
|
2854 |
+
}
|
2855 |
+
|
2856 |
+
/**
|
2857 |
+
* Import data / Save multiple rows of data at once
|
2858 |
+
*
|
2859 |
+
* @see PodsAPI::import
|
2860 |
+
*
|
2861 |
+
* @param mixed $import_data PHP associative array or CSV input
|
2862 |
+
* @param bool $numeric_mode Use IDs instead of the name field when matching
|
2863 |
+
* @param string $format Format of import data, options are php or csv
|
2864 |
+
*
|
2865 |
+
* @return array IDs of imported items
|
2866 |
+
*
|
2867 |
+
* @since 2.3
|
2868 |
+
*/
|
2869 |
+
public function import ( $import_data, $numeric_mode = false, $format = null ) {
|
2870 |
+
return $this->api->import( $import_data, $numeric_mode, $format );
|
2871 |
+
}
|
2872 |
+
|
2873 |
+
/**
|
2874 |
+
* Export an item's data
|
2875 |
+
*
|
2876 |
+
* @see PodsAPI::export_pod_item
|
2877 |
+
*
|
2878 |
+
* @param array $fields (optional) Fields to export
|
2879 |
+
* @param int $id (optional) ID of the pod item to export
|
2880 |
+
*
|
2881 |
+
* @return array|bool Data array of the exported pod item
|
2882 |
+
*
|
2883 |
+
* @since 2.0
|
2884 |
+
* @link http://pods.io/docs/export/
|
2885 |
+
*/
|
2886 |
+
public function export ( $fields = null, $id = null, $format = null ) {
|
2887 |
+
$params = array(
|
2888 |
+
'pod' => $this->pod,
|
2889 |
+
'id' => $id,
|
2890 |
+
'fields' => null,
|
2891 |
+
'depth' => 2,
|
2892 |
+
'flatten' => false
|
2893 |
+
);
|
2894 |
+
|
2895 |
+
if ( is_array( $fields ) && ( isset( $fields[ 'fields' ] ) || isset( $fields[ 'depth' ] ) ) )
|
2896 |
+
$params = array_merge( $params, $fields );
|
2897 |
+
else
|
2898 |
+
$params[ 'fields' ] = $fields;
|
2899 |
+
|
2900 |
+
if ( isset( $params[ 'fields' ] ) && is_array( $params[ 'fields' ] ) && !in_array( $this->pod_data[ 'field_id' ], $params[ 'fields' ] ) )
|
2901 |
+
$params[ 'fields' ] = array_merge( array( $this->pod_data[ 'field_id' ] ), $params[ 'fields' ] );
|
2902 |
+
|
2903 |
+
if ( null === $params[ 'id' ] )
|
2904 |
+
$params[ 'id' ] = $this->id();
|
2905 |
+
|
2906 |
+
$params = (array) $this->do_hook( 'export', $params );
|
2907 |
+
|
2908 |
+
if ( empty( $params[ 'id' ] ) )
|
2909 |
+
return false;
|
2910 |
+
|
2911 |
+
$data = $this->api->export_pod_item( $params );
|
2912 |
+
|
2913 |
+
if ( !empty( $format ) ) {
|
2914 |
+
if ( 'json' == $format )
|
2915 |
+
$data = json_encode( (array) $data );
|
2916 |
+
// @todo more formats
|
2917 |
+
}
|
2918 |
+
|
2919 |
+
return $data;
|
2920 |
+
}
|
2921 |
+
|
2922 |
+
/**
|
2923 |
+
* Export data from all items
|
2924 |
+
*
|
2925 |
+
* @see PodsAPI::export
|
2926 |
+
*
|
2927 |
+
* @param array $params An associative array of parameters
|
2928 |
+
*
|
2929 |
+
* @return array Data arrays of all exported pod items
|
2930 |
+
*
|
2931 |
+
* @since 2.3
|
2932 |
+
*/
|
2933 |
+
public function export_data ( $params = null ) {
|
2934 |
+
$defaults = array(
|
2935 |
+
'fields' => null,
|
2936 |
+
'depth' => 2,
|
2937 |
+
'params' => null
|
2938 |
+
);
|
2939 |
+
|
2940 |
+
if ( empty( $params ) )
|
2941 |
+
$params = $defaults;
|
2942 |
+
else
|
2943 |
+
$params = array_merge( $defaults, (array) $params );
|
2944 |
+
|
2945 |
+
return $this->api->export( $this, $params );
|
2946 |
+
}
|
2947 |
+
|
2948 |
+
/**
|
2949 |
+
* Display the pagination controls, types supported by default
|
2950 |
+
* are simple, paginate and advanced. The base and format parameters
|
2951 |
+
* are used only for the paginate view.
|
2952 |
+
*
|
2953 |
+
* @var array $params Associative array of parameters
|
2954 |
+
*
|
2955 |
+
* @return string Pagination HTML
|
2956 |
+
* @since 2.0
|
2957 |
+
* @link http://pods.io/docs/pagination/
|
2958 |
+
*/
|
2959 |
+
public function pagination( $params = null ) {
|
2960 |
+
|
2961 |
+
if ( empty( $params ) ) {
|
2962 |
+
$params = array();
|
2963 |
+
}
|
2964 |
+
elseif ( !is_array( $params ) ) {
|
2965 |
+
$params = array( 'label' => $params );
|
2966 |
+
}
|
2967 |
+
|
2968 |
+
$this->page_var = pods_var_raw( 'page_var', $params, $this->page_var );
|
2969 |
+
|
2970 |
+
$url = pods_var_update( null, null, $this->page_var );
|
2971 |
+
|
2972 |
+
$append = '?';
|
2973 |
+
|
2974 |
+
if ( false !== strpos( $url, '?' ) ) {
|
2975 |
+
$append = '&';
|
2976 |
+
}
|
2977 |
+
|
2978 |
+
$defaults = array(
|
2979 |
+
'type' => 'advanced',
|
2980 |
+
'label' => __( 'Go to page:', 'pods' ),
|
2981 |
+
'show_label' => true,
|
2982 |
+
'first_text' => __( '« First', 'pods' ),
|
2983 |
+
'prev_text' => __( '‹ Previous', 'pods' ),
|
2984 |
+
'next_text' => __( 'Next ›', 'pods' ),
|
2985 |
+
'last_text' => __( 'Last »', 'pods' ),
|
2986 |
+
'prev_next' => true,
|
2987 |
+
'first_last' => true,
|
2988 |
+
'limit' => (int) $this->limit,
|
2989 |
+
'offset' => (int) $this->offset,
|
2990 |
+
'page' => max( 1, (int) $this->page ),
|
2991 |
+
'mid_size' => 2,
|
2992 |
+
'end_size' => 1,
|
2993 |
+
'total_found' => $this->total_found(),
|
2994 |
+
'page_var' => $this->page_var,
|
2995 |
+
'base' => "{$url}{$append}%_%",
|
2996 |
+
'format' => "{$this->page_var}=%#%",
|
2997 |
+
'class' => '',
|
2998 |
+
'link_class' => ''
|
2999 |
+
);
|
3000 |
+
|
3001 |
+
$params = (object) array_merge( $defaults, $params );
|
3002 |
+
|
3003 |
+
$params->total = $this->total_pages( $params->limit, $params->offset, $params->total_found );
|
3004 |
+
|
3005 |
+
if ( $params->limit < 1 || $params->total_found < 1 || 1 == $params->total || $params->total_found <= $params->offset ) {
|
3006 |
+
return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, '', $params ), $params );
|
3007 |
+
}
|
3008 |
+
|
3009 |
+
$pagination = $params->type;
|
3010 |
+
|
3011 |
+
if ( !in_array( $params->type, array( 'simple', 'advanced', 'paginate', 'list' ) ) ) {
|
3012 |
+
$pagination = 'advanced';
|
3013 |
+
}
|
3014 |
+
|
3015 |
+
ob_start();
|
3016 |
+
|
3017 |
+
pods_view( PODS_DIR . 'ui/front/pagination/' . $pagination . '.php', compact( array_keys( get_defined_vars() ) ) );
|
3018 |
+
|
3019 |
+
$output = ob_get_clean();
|
3020 |
+
|
3021 |
+
return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, $output, $params ), $params );
|
3022 |
+
|
3023 |
+
}
|
3024 |
+
|
3025 |
+
/**
|
3026 |
+
* Return a filter form for searching a Pod
|
3027 |
+
*
|
3028 |
+
* @var array|string $params Comma-separated list of fields or array of parameters
|
3029 |
+
*
|
3030 |
+
* @return string Filters HTML
|
3031 |
+
*
|
3032 |
+
* @since 2.0
|
3033 |
+
* @link http://pods.io/docs/filters/
|
3034 |
+
*/
|
3035 |
+
public function filters ( $params = null ) {
|
3036 |
+
$defaults = array(
|
3037 |
+
'fields' => $params,
|
3038 |
+
'label' => '',
|
3039 |
+
'action' => '',
|
3040 |
+
'search' => ''
|
3041 |
+
);
|
3042 |
+
|
3043 |
+
if ( is_array( $params ) )
|
3044 |
+
$params = array_merge( $defaults, $params );
|
3045 |
+
else
|
3046 |
+
$params = $defaults;
|
3047 |
+
|
3048 |
+
$pod =& $this;
|
3049 |
+
|
3050 |
+
$params = apply_filters( 'pods_filters_params', $params, $pod );
|
3051 |
+
|
3052 |
+
$fields = $params[ 'fields' ];
|
3053 |
+
|
3054 |
+
if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) )
|
3055 |
+
$fields = explode( ',', $fields );
|
3056 |
+
|
3057 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $this->pod_data, array(), null, true );
|
3058 |
+
|
3059 |
+
// Force array
|
3060 |
+
if ( empty( $fields ) )
|
3061 |
+
$fields = array();
|
3062 |
+
else {
|
3063 |
+
$filter_fields = $fields; // Temporary
|
3064 |
+
|
3065 |
+
$fields = array();
|
3066 |
+
|
3067 |
+
foreach ( $filter_fields as $k => $field ) {
|
3068 |
+
$name = $k;
|
3069 |
+
|
3070 |
+
$defaults = array(
|
3071 |
+
'name' => $name
|
3072 |
+
);
|
3073 |
+
|
3074 |
+
if ( !is_array( $field ) ) {
|
3075 |
+
$name = $field;
|
3076 |
+
|
3077 |
+
$field = array(
|
3078 |
+
'name' => $name
|
3079 |
+
);
|
3080 |
+
}
|
3081 |
+
|
3082 |
+
$field = array_merge( $defaults, $field );
|
3083 |
+
|
3084 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
3085 |
+
|
3086 |
+
if ( pods_var_raw( 'hidden', $field, false, null, true ) )
|
3087 |
+
$field[ 'type' ] = 'hidden';
|
3088 |
+
|
3089 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) )
|
3090 |
+
$fields[ $field[ 'name' ] ] = array_merge( $object_fields[ $field[ 'name' ] ], $field );
|
3091 |
+
elseif ( isset( $this->fields[ $field[ 'name' ] ] ) )
|
3092 |
+
$fields[ $field[ 'name' ] ] = array_merge( $this->fields[ $field[ 'name' ] ], $field );
|
3093 |
+
}
|
3094 |
+
|
3095 |
+
unset( $filter_fields ); // Cleanup
|
3096 |
+
}
|
3097 |
+
|
3098 |
+
$this->filters = array_keys( $fields );
|
3099 |
+
|
3100 |
+
$label = $params[ 'label' ];
|
3101 |
+
|
3102 |
+
if ( strlen( $label ) < 1 )
|
3103 |
+
$label = __( 'Search', 'pods' );
|
3104 |
+
|
3105 |
+
$action = $params[ 'action' ];
|
3106 |
+
|
3107 |
+
$search = trim( $params[ 'search' ] );
|
3108 |
+
|
3109 |
+
if ( strlen( $search ) < 1 )
|
3110 |
+
$search = pods_var_raw( $pod->search_var, 'get', '' );
|
3111 |
+
|
3112 |
+
ob_start();
|
3113 |
+
|
3114 |
+
pods_view( PODS_DIR . 'ui/front/filters.php', compact( array_keys( get_defined_vars() ) ) );
|
3115 |
+
|
3116 |
+
$output = ob_get_clean();
|
3117 |
+
|
3118 |
+
return $this->do_hook( 'filters', $output, $params );
|
3119 |
+
}
|
3120 |
+
|
3121 |
+
/**
|
3122 |
+
* Run a helper within a Pod Page or WP Template
|
3123 |
+
*
|
3124 |
+
* @see Pods_Helpers::helper
|
3125 |
+
*
|
3126 |
+
* @param string $helper Helper name
|
3127 |
+
* @param string $value Value to run the helper on
|
3128 |
+
* @param string $name Field name
|
3129 |
+
* @internal param array $params An associative array of parameters
|
3130 |
+
*
|
3131 |
+
* @return mixed Anything returned by the helper
|
3132 |
+
* @since 2.0
|
3133 |
+
*/
|
3134 |
+
public function helper ( $helper, $value = null, $name = null ) {
|
3135 |
+
$params = array(
|
3136 |
+
'helper' => $helper,
|
3137 |
+
'value' => $value,
|
3138 |
+
'name' => $name,
|
3139 |
+
'deprecated' => false
|
3140 |
+
);
|
3141 |
+
|
3142 |
+
if ( class_exists( 'Pods_Templates' ) )
|
3143 |
+
$params[ 'deprecated' ] = Pods_Templates::$deprecated;
|
3144 |
+
|
3145 |
+
if ( is_array( $helper ) )
|
3146 |
+
$params = array_merge( $params, $helper );
|
3147 |
+
|
3148 |
+
if ( class_exists( 'Pods_Helpers' ) )
|
3149 |
+
$value = Pods_Helpers::helper( $params, $this );
|
3150 |
+
elseif ( function_exists( $params[ 'helper' ] ) )
|
3151 |
+
$value = call_user_func( $params[ 'helper' ], $value );
|
3152 |
+
else
|
3153 |
+
$value = apply_filters( $params[ 'helper' ], $value );
|
3154 |
+
|
3155 |
+
return $value;
|
3156 |
+
}
|
3157 |
+
|
3158 |
+
/**
|
3159 |
+
* Display the page template
|
3160 |
+
*
|
3161 |
+
* @see Pods_Templates::template
|
3162 |
+
*
|
3163 |
+
* @param string $template The template name
|
3164 |
+
* @param string $code Custom template code to use instead
|
3165 |
+
* @param bool $deprecated Whether to use deprecated functionality based on old function usage
|
3166 |
+
*
|
3167 |
+
* @return mixed Template output
|
3168 |
+
*
|
3169 |
+
* @since 2.0
|
3170 |
+
* @link http://pods.io/docs/template/
|
3171 |
+
*/
|
3172 |
+
public function template ( $template_name, $code = null, $deprecated = false ) {
|
3173 |
+
$out = null;
|
3174 |
+
|
3175 |
+
$obj =& $this;
|
3176 |
+
|
3177 |
+
if ( !empty( $code ) ) {
|
3178 |
+
$code = str_replace( '$this->', '$obj->', $code ); // backwards compatibility
|
3179 |
+
|
3180 |
+
$code = apply_filters( 'pods_templates_pre_template', $code, $template_name, $this );
|
3181 |
+
$code = apply_filters( "pods_templates_pre_template_{$template_name}", $code, $template_name, $this );
|
3182 |
+
|
3183 |
+
ob_start();
|
3184 |
+
|
3185 |
+
if ( !empty( $code ) ) {
|
3186 |
+
// Only detail templates need $this->id
|
3187 |
+
if ( empty( $this->id ) ) {
|
3188 |
+
while ( $this->fetch() ) {
|
3189 |
+
echo $this->do_magic_tags( $code );
|
3190 |
+
}
|
3191 |
+
}
|
3192 |
+
else
|
3193 |
+
echo $this->do_magic_tags( $code );
|
3194 |
+
}
|
3195 |
+
|
3196 |
+
$out = ob_get_clean();
|
3197 |
+
|
3198 |
+
$out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
|
3199 |
+
$out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
|
3200 |
+
}
|
3201 |
+
elseif ( class_exists( 'Pods_Templates' ) )
|
3202 |
+
$out = Pods_Templates::template( $template_name, $code, $this, $deprecated );
|
3203 |
+
elseif ( $template_name == trim( preg_replace( '/[^a-zA-Z0-9_\-\/]/', '', $template_name ), ' /-' ) ) {
|
3204 |
+
ob_start();
|
3205 |
+
|
3206 |
+
$default_templates = array(
|
3207 |
+
'pods/' . $template_name,
|
3208 |
+
'pods-' . $template_name,
|
3209 |
+
$template_name
|
3210 |
+
);
|
3211 |
+
|
3212 |
+
$default_templates = apply_filters( 'pods_template_default_templates', $default_templates );
|
3213 |
+
|
3214 |
+
// Only detail templates need $this->id
|
3215 |
+
if ( empty( $this->id ) ) {
|
3216 |
+
while ( $this->fetch() ) {
|
3217 |
+
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
|
3218 |
+
}
|
3219 |
+
}
|
3220 |
+
else
|
3221 |
+
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
|
3222 |
+
|
3223 |
+
$out = ob_get_clean();
|
3224 |
+
|
3225 |
+
$out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
|
3226 |
+
$out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
|
3227 |
+
}
|
3228 |
+
|
3229 |
+
return $out;
|
3230 |
+
}
|
3231 |
+
|
3232 |
+
/**
|
3233 |
+
* Embed a form to add / edit a pod item from within your theme. Provide an array of $fields to include
|
3234 |
+
* and override options where needed. For WP object based Pods, you can pass through the WP object
|
3235 |
+
* field names too, such as "post_title" or "post_content" for example.
|
3236 |
+
*
|
3237 |
+
* @param array $params (optional) Fields to show on the form, defaults to all fields
|
3238 |
+
* @param string $label (optional) Save button label, defaults to "Save Changes"
|
3239 |
+
* @param string $thank_you (optional) Thank you URL to send to upon success
|
3240 |
+
*
|
3241 |
+
* @return bool|mixed
|
3242 |
+
* @since 2.0
|
3243 |
+
* @link http://pods.io/docs/form/
|
3244 |
+
*/
|
3245 |
+
public function form ( $params = null, $label = null, $thank_you = null ) {
|
3246 |
+
$defaults = array(
|
3247 |
+
'fields' => $params,
|
3248 |
+
'label' => $label,
|
3249 |
+
'thank_you' => $thank_you,
|
3250 |
+
'fields_only' => false
|
3251 |
+
);
|
3252 |
+
|
3253 |
+
if ( is_array( $params ) )
|
3254 |
+
$params = array_merge( $defaults, $params );
|
3255 |
+
else
|
3256 |
+
$params = $defaults;
|
3257 |
+
|
3258 |
+
$pod =& $this;
|
3259 |
+
|
3260 |
+
$params = $this->do_hook( 'form_params', $params );
|
3261 |
+
|
3262 |
+
$fields = $params[ 'fields' ];
|
3263 |
+
|
3264 |
+
if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) )
|
3265 |
+
$fields = explode( ',', $fields );
|
3266 |
+
|
3267 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $this->pod_data, array(), null, true );
|
3268 |
+
|
3269 |
+
if ( empty( $fields ) ) {
|
3270 |
+
// Add core object fields if $fields is empty
|
3271 |
+
$fields = array_merge( $object_fields, $this->fields );
|
3272 |
+
}
|
3273 |
+
|
3274 |
+
$form_fields = $fields; // Temporary
|
3275 |
+
|
3276 |
+
$fields = array();
|
3277 |
+
|
3278 |
+
foreach ( $form_fields as $k => $field ) {
|
3279 |
+
$name = $k;
|
3280 |
+
|
3281 |
+
$defaults = array(
|
3282 |
+
'name' => $name
|
3283 |
+
);
|
3284 |
+
|
3285 |
+
if ( !is_array( $field ) ) {
|
3286 |
+
$name = $field;
|
3287 |
+
|
3288 |
+
$field = array(
|
3289 |
+
'name' => $name
|
3290 |
+
);
|
3291 |
+
}
|
3292 |
+
|
3293 |
+
$field = array_merge( $defaults, $field );
|
3294 |
+
|
3295 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
3296 |
+
|
3297 |
+
$default_value = pods_var_raw( 'default', $field );
|
3298 |
+
$value = pods_var_raw( 'value', $field );
|
3299 |
+
|
3300 |
+
if ( empty( $field[ 'name' ] ) )
|
3301 |
+
$field[ 'name' ] = trim( $name );
|
3302 |
+
|
3303 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
|
3304 |
+
$field = array_merge( $object_fields[ $field[ 'name' ] ], $field );
|
3305 |
+
}
|
3306 |
+
elseif ( isset( $this->fields[ $field[ 'name' ] ] ) ) {
|
3307 |
+
$field = array_merge( $this->fields[ $field[ 'name' ] ], $field );
|
3308 |
+
}
|
3309 |
+
|
3310 |
+
if ( pods_var_raw( 'hidden', $field, false, null, true ) )
|
3311 |
+
$field[ 'type' ] = 'hidden';
|
3312 |
+
|
3313 |
+
$fields[ $field[ 'name' ] ] = $field;
|
3314 |
+
|
3315 |
+
if ( empty( $this->id ) && null !== $default_value ) {
|
3316 |
+
$this->row_override[ $field[ 'name' ] ] = $default_value;
|
3317 |
+
}
|
3318 |
+
elseif ( !empty( $this->id ) && null !== $value ) {
|
3319 |
+
$this->row[ $field[ 'name' ] ] = $value;
|
3320 |
+
}
|
3321 |
+
}
|
3322 |
+
|
3323 |
+
unset( $form_fields ); // Cleanup
|
3324 |
+
|
3325 |
+
$fields = $this->do_hook( 'form_fields', $fields, $params );
|
3326 |
+
|
3327 |
+
$label = $params[ 'label' ];
|
3328 |
+
|
3329 |
+
if ( empty( $label ) )
|
3330 |
+
$label = __( 'Save Changes', 'pods' );
|
3331 |
+
|
3332 |
+
$thank_you = $params[ 'thank_you' ];
|
3333 |
+
$fields_only = $params[ 'fields_only' ];
|
3334 |
+
|
3335 |
+
PodsForm::$form_counter++;
|
3336 |
+
|
3337 |
+
ob_start();
|
3338 |
+
|
3339 |
+
if ( empty( $thank_you ) ) {
|
3340 |
+
$success = 'success';
|
3341 |
+
|
3342 |
+
if ( 1 < PodsForm::$form_counter )
|
3343 |
+
$success .= PodsForm::$form_counter;
|
3344 |
+
|
3345 |
+
$thank_you = pods_var_update( array( 'success*' => null, $success => 1 ) );
|
3346 |
+
|
3347 |
+
if ( 1 == pods_var( $success, 'get', 0 ) ) {
|
3348 |
+
$message = __( 'Form submitted successfully', 'pods' );
|
3349 |
+
/**
|
3350 |
+
* Change the text of the message that appears on succesful form submission.
|
3351 |
+
*
|
3352 |
+
* @param string $message
|
3353 |
+
*
|
3354 |
+
* @returns string the message
|
3355 |
+
*
|
3356 |
+
* @since 3.0.0
|
3357 |
+
*/
|
3358 |
+
$message = apply_filters( 'pods_pod_form_success_message', $message );
|
3359 |
+
|
3360 |
+
echo '<div id="message" class="pods-form-front-success">' . $message . '</div>';
|
3361 |
+
}
|
3362 |
+
}
|
3363 |
+
|
3364 |
+
pods_view( PODS_DIR . 'ui/front/form.php', compact( array_keys( get_defined_vars() ) ) );
|
3365 |
+
|
3366 |
+
$output = ob_get_clean();
|
3367 |
+
|
3368 |
+
if ( empty( $this->id ) )
|
3369 |
+
$this->row_override = array();
|
3370 |
+
|
3371 |
+
return $this->do_hook( 'form', $output, $fields, $label, $thank_you, $this, $this->id() );
|
3372 |
+
}
|
3373 |
+
|
3374 |
+
/**
|
3375 |
+
* @param array $fields (optional) Fields to show in the view, defaults to all fields
|
3376 |
+
*
|
3377 |
+
* @return mixed
|
3378 |
+
* @since 2.3.10
|
3379 |
+
*/
|
3380 |
+
public function view( $fields = null ) {
|
3381 |
+
|
3382 |
+
$pod =& $this;
|
3383 |
+
|
3384 |
+
// Convert comma separated list of fields to an array
|
3385 |
+
if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) ) {
|
3386 |
+
$fields = explode( ',', $fields );
|
3387 |
+
}
|
3388 |
+
|
3389 |
+
$object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true );
|
3390 |
+
|
3391 |
+
if ( empty( $fields ) ) {
|
3392 |
+
// Add core object fields if $fields is empty
|
3393 |
+
$fields = array_merge( $object_fields, $this->fields );
|
3394 |
+
}
|
3395 |
+
|
3396 |
+
$view_fields = $fields; // Temporary
|
3397 |
+
|
3398 |
+
$fields = array();
|
3399 |
+
|
3400 |
+
foreach ( $view_fields as $name => $field ) {
|
3401 |
+
|
3402 |
+
$defaults = array(
|
3403 |
+
'name' => $name
|
3404 |
+
);
|
3405 |
+
|
3406 |
+
if ( !is_array( $field ) ) {
|
3407 |
+
$name = $field;
|
3408 |
+
|
3409 |
+
$field = array(
|
3410 |
+
'name' => $name
|
3411 |
+
);
|
3412 |
+
}
|
3413 |
+
|
3414 |
+
$field = array_merge( $defaults, $field );
|
3415 |
+
|
3416 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
3417 |
+
|
3418 |
+
if ( empty( $field[ 'name' ] ) ) {
|
3419 |
+
$field[ 'name' ] = trim( $name );
|
3420 |
+
}
|
3421 |
+
|
3422 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) )
|
3423 |
+
$field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
|
3424 |
+
elseif ( isset( $this->fields[ $field[ 'name' ] ] ) )
|
3425 |
+
$field = array_merge( $this->fields[ $field[ 'name' ] ], $field );
|
3426 |
+
|
3427 |
+
if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' == $field[ 'type' ] ) {
|
3428 |
+
continue;
|
3429 |
+
}
|
3430 |
+
elseif ( !PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
|
3431 |
+
continue;
|
3432 |
+
}
|
3433 |
+
|
3434 |
+
$fields[ $field[ 'name' ] ] = $field;
|
3435 |
+
}
|
3436 |
+
|
3437 |
+
unset( $view_fields ); // Cleanup
|
3438 |
+
|
3439 |
+
$output = pods_view( PODS_DIR . 'ui/front/view.php', compact( array_keys( get_defined_vars() ) ), false, 'cache', true );
|
3440 |
+
|
3441 |
+
return $this->do_hook( 'view', $output, $fields, $this->id() );
|
3442 |
+
|
3443 |
+
}
|
3444 |
+
|
3445 |
+
/**
|
3446 |
+
* Replace magic tags with their values
|
3447 |
+
*
|
3448 |
+
* @param string $code The content to evaluate
|
3449 |
+
* @param object $obj The Pods object
|
3450 |
+
*
|
3451 |
+
* @return string Code with Magic Tags evaluated
|
3452 |
+
*
|
3453 |
+
* @since 2.0
|
3454 |
+
*/
|
3455 |
+
public function do_magic_tags ( $code ) {
|
3456 |
+
return preg_replace_callback( '/({@(.*?)})/m', array( $this, 'process_magic_tags' ), $code );
|
3457 |
+
}
|
3458 |
+
|
3459 |
+
/**
|
3460 |
+
* Replace magic tags with their values
|
3461 |
+
*
|
3462 |
+
* @param string $tag The magic tag to process
|
3463 |
+
* @param object $obj The Pods object
|
3464 |
+
*
|
3465 |
+
* @return string Code with Magic Tags evaluated
|
3466 |
+
*
|
3467 |
+
* @since 2.0.2
|
3468 |
+
*/
|
3469 |
+
private function process_magic_tags ( $tag ) {
|
3470 |
+
|
3471 |
+
if ( is_array( $tag ) ) {
|
3472 |
+
if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 )
|
3473 |
+
return '';
|
3474 |
+
|
3475 |
+
$tag = $tag[ 2 ];
|
3476 |
+
}
|
3477 |
+
|
3478 |
+
$tag = trim( $tag, ' {@}' );
|
3479 |
+
$tag = explode( ',', $tag );
|
3480 |
+
|
3481 |
+
if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 )
|
3482 |
+
return '';
|
3483 |
+
|
3484 |
+
foreach ( $tag as $k => $v ) {
|
3485 |
+
$tag[ $k ] = trim( $v );
|
3486 |
+
}
|
3487 |
+
|
3488 |
+
$field_name = $tag[ 0 ];
|
3489 |
+
|
3490 |
+
$helper_name = $before = $after = '';
|
3491 |
+
|
3492 |
+
if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) ) {
|
3493 |
+
$value = $this->field( $field_name );
|
3494 |
+
|
3495 |
+
$helper_name = $tag[ 1 ];
|
3496 |
+
|
3497 |
+
$value = $this->helper( $helper_name, $value, $field_name );
|
3498 |
+
}
|
3499 |
+
else
|
3500 |
+
$value = $this->display( $field_name );
|
3501 |
+
|
3502 |
+
if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) )
|
3503 |
+
$before = $tag[ 2 ];
|
3504 |
+
|
3505 |
+
if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) )
|
3506 |
+
$after = $tag[ 3 ];
|
3507 |
+
|
3508 |
+
$value = apply_filters( 'pods_do_magic_tags', $value, $field_name, $helper_name, $before, $after );
|
3509 |
+
|
3510 |
+
if ( is_array( $value ) )
|
3511 |
+
$value = pods_serial_comma( $value, array( 'field' => $field_name, 'fields' => $this->fields ) );
|
3512 |
+
|
3513 |
+
if ( null !== $value && false !== $value )
|
3514 |
+
return $before . $value . $after;
|
3515 |
+
|
3516 |
+
return '';
|
3517 |
+
}
|
3518 |
+
|
3519 |
+
/**
|
3520 |
+
*
|
3521 |
+
* Generate UI for Data Management
|
3522 |
+
*
|
3523 |
+
* @param mixed $options Array or String containing Pod or Options to be used
|
3524 |
+
* @param bool $amend Whether to amend the default UI options or replace entirely
|
3525 |
+
*
|
3526 |
+
* @return PodsUI|void UI object or void if custom UI used
|
3527 |
+
*
|
3528 |
+
* @since 2.3.10
|
3529 |
+
*/
|
3530 |
+
public function ui ( $options = null, $amend = false ) {
|
3531 |
+
$num = '';
|
3532 |
+
|
3533 |
+
if ( empty( $options ) )
|
3534 |
+
$options = array();
|
3535 |
+
else {
|
3536 |
+
$num = pods_var( 'num', $options, '' );
|
3537 |
+
|
3538 |
+
if ( empty( $num ) ) {
|
3539 |
+
$num = '';
|
3540 |
+
}
|
3541 |
+
}
|
3542 |
+
|
3543 |
+
if ( $this->id() != pods_var( 'id' . $num, 'get', null, null, true ) )
|
3544 |
+
$this->fetch( pods_var( 'id' . $num, 'get', null, null, true ) );
|
3545 |
+
|
3546 |
+
if ( !empty( $options ) && !$amend ) {
|
3547 |
+
$this->ui = $options;
|
3548 |
+
|
3549 |
+
return pods_ui( $this );
|
3550 |
+
}
|
3551 |
+
elseif ( !empty( $options ) || 'custom' != pods_var( 'ui_style', $this->pod_data[ 'options' ], 'post_type', null, true ) ) {
|
3552 |
+
$actions_enabled = pods_var_raw( 'ui_actions_enabled', $this->pod_data[ 'options' ] );
|
3553 |
+
|
3554 |
+
if ( !empty( $actions_enabled ) )
|
3555 |
+
$actions_enabled = (array) $actions_enabled;
|
3556 |
+
else
|
3557 |
+
$actions_enabled = array();
|
3558 |
+
|
3559 |
+
$available_actions = array(
|
3560 |
+
'add',
|
3561 |
+
'edit',
|
3562 |
+
'duplicate',
|
3563 |
+
'delete',
|
3564 |
+
'reorder',
|
3565 |
+
'export'
|
3566 |
+
);
|
3567 |
+
|
3568 |
+
if ( !empty( $actions_enabled ) ) {
|
3569 |
+
$actions_disabled = array(
|
3570 |
+
'view' => 'view'
|
3571 |
+
);
|
3572 |
+
|
3573 |
+
foreach ( $available_actions as $action ) {
|
3574 |
+
if ( !in_array( $action, $actions_enabled ) )
|
3575 |
+
$actions_disabled[ $action ] = $action;
|
3576 |
+
}
|
3577 |
+
}
|
3578 |
+
else {
|
3579 |
+
$actions_disabled = array(
|
3580 |
+
'duplicate' => 'duplicate',
|
3581 |
+
'view' => 'view',
|
3582 |
+
'export' => 'export'
|
3583 |
+
);
|
3584 |
+
|
3585 |
+
if ( 1 == pods_var( 'ui_export', $this->pod_data[ 'options' ], 0 ) )
|
3586 |
+
unset( $actions_disabled[ 'export' ] );
|
3587 |
+
}
|
3588 |
+
|
3589 |
+
if ( empty( $options ) ) {
|
3590 |
+
$author_restrict = false;
|
3591 |
+
|
3592 |
+
if ( isset( $this->fields[ 'author' ] ) && 'pick' == $this->fields[ 'author' ][ 'type' ] && 'user' == $this->fields[ 'author' ][ 'pick_object' ] )
|
3593 |
+
$author_restrict = 'author.ID';
|
3594 |
+
|
3595 |
+
if ( !pods_is_admin( array( 'pods', 'pods_content' ) ) ) {
|
3596 |
+
if ( !current_user_can( 'pods_add_' . $this->pod ) ) {
|
3597 |
+
$actions_disabled[ 'add' ] = 'add';
|
3598 |
+
|
3599 |
+
if ( 'add' == pods_var( 'action' . $num, 'get' ) )
|
3600 |
+
$_GET[ 'action' . $num ] = 'manage';
|
3601 |
+
}
|
3602 |
+
|
3603 |
+
if ( !$author_restrict && !current_user_can( 'pods_edit_' . $this->pod ) && !current_user_can( 'pods_edit_others_' . $this->pod ) )
|
3604 |
+
$actions_disabled[ 'edit' ] = 'edit';
|
3605 |
+
|
3606 |
+
if ( !$author_restrict && !current_user_can( 'pods_delete_' . $this->pod ) && !current_user_can( 'pods_delete_others_' . $this->pod ) )
|
3607 |
+
$actions_disabled[ 'delete' ] = 'delete';
|
3608 |
+
|
3609 |
+
if ( !current_user_can( 'pods_reorder_' . $this->pod ) )
|
3610 |
+
$actions_disabled[ 'reorder' ] = 'reorder';
|
3611 |
+
|
3612 |
+
if ( !current_user_can( 'pods_export_' . $this->pod ) )
|
3613 |
+
$actions_disabled[ 'export' ] = 'export';
|
3614 |
+
}
|
3615 |
+
}
|
3616 |
+
|
3617 |
+
$_GET[ 'action' . $num ] = pods_var( 'action' . $num, 'get', pods_var( 'action', $options, 'manage' ) );
|
3618 |
+
|
3619 |
+
$index = $this->pod_data[ 'field_id' ];
|
3620 |
+
$label = __( 'ID', 'pods' );
|
3621 |
+
|
3622 |
+
if ( isset( $this->pod_data[ 'fields' ][ $this->pod_data[ 'field_index' ] ] ) ) {
|
3623 |
+
$index = $this->pod_data[ 'field_index' ];
|
3624 |
+
$label = $this->pod_data[ 'fields' ][ $this->pod_data[ 'field_index' ] ];
|
3625 |
+
}
|
3626 |
+
|
3627 |
+
$manage = array(
|
3628 |
+
$index => $label
|
3629 |
+
);
|
3630 |
+
|
3631 |
+
if ( isset( $this->pod_data[ 'fields' ][ 'modified' ] ) )
|
3632 |
+
$manage[ 'modified' ] = $this->pod_data[ 'fields' ][ 'modified' ][ 'label' ];
|
3633 |
+
|
3634 |
+
$manage_fields = pods_var_raw( 'ui_fields_manage', $this->pod_data[ 'options' ] );
|
3635 |
+
|
3636 |
+
if ( !empty( $manage_fields ) ) {
|
3637 |
+
$manage_new = array();
|
3638 |
+
|
3639 |
+
foreach ( $manage_fields as $manage_field ) {
|
3640 |
+
if ( isset( $this->pod_data[ 'fields' ][ $manage_field ] ) )
|
3641 |
+
$manage_new[ $manage_field ] = $this->pod_data[ 'fields' ][ $manage_field ];
|
3642 |
+
elseif ( isset( $this->pod_data[ 'object_fields' ][ $manage_field ] ) )
|
3643 |
+
$manage_new[ $manage_field ] = $this->pod_data[ 'object_fields' ][ $manage_field ];
|
3644 |
+
elseif ( $manage_field == $this->pod_data[ 'field_id' ] ) {
|
3645 |
+
$field = array(
|
3646 |
+
'name' => $manage_field,
|
3647 |
+
'label' => 'ID',
|
3648 |
+
'type' => 'number',
|
3649 |
+
'width' => '8%'
|
3650 |
+
);
|
3651 |
+
|
3652 |
+
$manage_new[ $manage_field ] = PodsForm::field_setup( $field, null, $field[ 'type' ] );
|
3653 |
+
}
|
3654 |
+
}
|
3655 |
+
|
3656 |
+
if ( !empty( $manage_new ) )
|
3657 |
+
$manage = $manage_new;
|
3658 |
+
}
|
3659 |
+
|
3660 |
+
$manage = apply_filters( 'pods_admin_ui_fields_' . $this->pod, apply_filters( 'pods_admin_ui_fields', $manage, $this->pod, $this ), $this->pod, $this );
|
3661 |
+
|
3662 |
+
$icon = pods_var_raw( 'ui_icon', $this->pod_data[ 'options' ] );
|
3663 |
+
|
3664 |
+
if ( !empty( $icon ) )
|
3665 |
+
$icon = pods_image_url( $icon, '32x32' );
|
3666 |
+
|
3667 |
+
$filters = pods_var_raw( 'ui_filters', $this->pod_data[ 'options' ] );
|
3668 |
+
|
3669 |
+
if ( !empty( $filters ) ) {
|
3670 |
+
$filters_new = array();
|
3671 |
+
|
3672 |
+
foreach ( $filters as $filter_field ) {
|
3673 |
+
if ( isset( $this->pod_data[ 'fields' ][ $filter_field ] ) )
|
3674 |
+
$filters_new[ $filter_field ] = $this->pod_data[ 'fields' ][ $filter_field ];
|
3675 |
+
elseif ( isset( $this->pod_data[ 'object_fields' ][ $filter_field ] ) )
|
3676 |
+
$filters_new[ $filter_field ] = $this->pod_data[ 'object_fields' ][ $filter_field ];
|
3677 |
+
}
|
3678 |
+
|
3679 |
+
$filters = $filters_new;
|
3680 |
+
}
|
3681 |
+
|
3682 |
+
$ui = array(
|
3683 |
+
'fields' => array(
|
3684 |
+
'manage' => $manage,
|
3685 |
+
'add' => $this->pod_data[ 'fields' ],
|
3686 |
+
'edit' => $this->pod_data[ 'fields' ],
|
3687 |
+
'duplicate' => $this->pod_data[ 'fields' ]
|
3688 |
+
),
|
3689 |
+
'icon' => $icon,
|
3690 |
+
'actions_disabled' => $actions_disabled
|
3691 |
+
);
|
3692 |
+
|
3693 |
+
if ( !empty( $filters ) ) {
|
3694 |
+
$ui[ 'fields' ][ 'search' ] = $filters;
|
3695 |
+
$ui[ 'filters' ] = array_keys( $filters );
|
3696 |
+
$ui[ 'filters_enhanced' ] = true;
|
3697 |
+
}
|
3698 |
+
|
3699 |
+
$reorder_field = pods_var_raw( 'ui_reorder_field', $this->pod_data[ 'options' ] );
|
3700 |
+
|
3701 |
+
if ( in_array( 'reorder', $actions_enabled ) && !in_array( 'reorder', $actions_disabled ) && !empty( $reorder_field ) && ( ( !empty( $this->pod_data[ 'object_fields' ] ) && isset( $this->pod_data[ 'object_fields' ][ $reorder_field ] ) ) || isset( $this->pod_data[ 'fields' ][ $reorder_field ] ) ) ) {
|
3702 |
+
$ui[ 'reorder' ] = array( 'on' => $reorder_field );
|
3703 |
+
$ui[ 'orderby' ] = $reorder_field;
|
3704 |
+
$ui[ 'orderby_dir' ] = 'ASC';
|
3705 |
+
}
|
3706 |
+
|
3707 |
+
if ( !empty( $author_restrict ) )
|
3708 |
+
$ui[ 'restrict' ] = array( 'author_restrict' => $author_restrict );
|
3709 |
+
|
3710 |
+
if ( !in_array( 'delete', $ui[ 'actions_disabled' ] ) ) {
|
3711 |
+
$ui[ 'actions_bulk' ] = array(
|
3712 |
+
'delete' => array(
|
3713 |
+
'label' => __( 'Delete', 'pods' )
|
3714 |
+
// callback not needed, Pods has this built-in for delete
|
3715 |
+
)
|
3716 |
+
);
|
3717 |
+
}
|
3718 |
+
|
3719 |
+
$detail_url = pods_var( 'detail_url', $this->pod_data[ 'options' ] );
|
3720 |
+
|
3721 |
+
if ( 0 < strlen( $detail_url ) ) {
|
3722 |
+
$ui[ 'actions_custom' ] = array(
|
3723 |
+
'view_url' => array(
|
3724 |
+
'label' => 'View',
|
3725 |
+
'link' => get_site_url() . '/' . $detail_url
|
3726 |
+
)
|
3727 |
+
);
|
3728 |
+
}
|
3729 |
+
|
3730 |
+
// @todo Customize the Add New / Manage links to point to their correct menu items
|
3731 |
+
|
3732 |
+
$ui = apply_filters( 'pods_admin_ui_' . $this->pod, apply_filters( 'pods_admin_ui', $ui, $this->pod, $this ), $this->pod, $this );
|
3733 |
+
|
3734 |
+
// Override UI options
|
3735 |
+
foreach ( $options as $option => $value ) {
|
3736 |
+
$ui[ $option ] = $value;
|
3737 |
+
}
|
3738 |
+
|
3739 |
+
$this->ui = $ui;
|
3740 |
+
|
3741 |
+
return pods_ui( $this );
|
3742 |
+
}
|
3743 |
+
|
3744 |
+
do_action( 'pods_admin_ui_custom', $this );
|
3745 |
+
do_action( 'pods_admin_ui_custom_' . $this->pod, $this );
|
3746 |
+
}
|
3747 |
+
|
3748 |
+
/**
|
3749 |
+
* Handle filters / actions for the class
|
3750 |
+
*
|
3751 |
+
* @see pods_do_hook
|
3752 |
+
*
|
3753 |
+
* @return mixed Value filtered
|
3754 |
+
*
|
3755 |
+
* @since 2.0
|
3756 |
+
*/
|
3757 |
+
private function do_hook () {
|
3758 |
+
$args = func_get_args();
|
3759 |
+
|
3760 |
+
if ( empty( $args ) )
|
3761 |
+
return false;
|
3762 |
+
|
3763 |
+
$name = array_shift( $args );
|
3764 |
+
|
3765 |
+
return pods_do_hook( 'pods', $name, $args, $this );
|
3766 |
+
}
|
3767 |
+
|
3768 |
+
/**
|
3769 |
+
* Handle variables that have been deprecated and PodsData vars
|
3770 |
+
*
|
3771 |
+
* @var $name
|
3772 |
+
*
|
3773 |
+
* @return mixed
|
3774 |
+
*
|
3775 |
+
* @since 2.0
|
3776 |
+
*/
|
3777 |
+
public function __get ( $name ) {
|
3778 |
+
$name = (string) $name;
|
3779 |
+
|
3780 |
+
// PodsData vars
|
3781 |
+
if ( 0 === strpos( $name, 'field_' ) && isset( $this->data->{$name} ) ) {
|
3782 |
+
return $this->data->{$name};
|
3783 |
+
}
|
3784 |
+
|
3785 |
+
if ( !isset( $this->deprecated ) ) {
|
3786 |
+
require_once( PODS_DIR . 'deprecated/classes/Pods.php' );
|
3787 |
+
$this->deprecated = new Pods_Deprecated( $this );
|
3788 |
+
}
|
3789 |
+
|
3790 |
+
$var = null;
|
3791 |
+
|
3792 |
+
if ( isset( $this->deprecated->{$name} ) ) {
|
3793 |
+
pods_deprecated( "Pods->{$name}", '2.0' );
|
3794 |
+
|
3795 |
+
$var = $this->deprecated->{$name};
|
3796 |
+
}
|
3797 |
+
else
|
3798 |
+
pods_deprecated( "Pods->{$name}", '2.0' );
|
3799 |
+
|
3800 |
+
return $var;
|
3801 |
+
}
|
3802 |
+
|
3803 |
+
/**
|
3804 |
+
* Handle methods that have been deprecated and any aliasing
|
3805 |
+
*
|
3806 |
+
* @var $name
|
3807 |
+
* @var $args
|
3808 |
+
*
|
3809 |
+
* @return mixed
|
3810 |
+
*
|
3811 |
+
* @since 2.0
|
3812 |
+
*/
|
3813 |
+
public function __call ( $name, $args ) {
|
3814 |
+
$name = (string) $name;
|
3815 |
+
|
3816 |
+
// select > find alias
|
3817 |
+
if ( 'select' == $name ) {
|
3818 |
+
return call_user_func_array( array( $this, 'find' ), $args );
|
3819 |
+
}
|
3820 |
+
|
3821 |
+
if ( !isset( $this->deprecated ) ) {
|
3822 |
+
require_once( PODS_DIR . 'deprecated/classes/Pods.php' );
|
3823 |
+
$this->deprecated = new Pods_Deprecated( $this );
|
3824 |
+
}
|
3825 |
+
|
3826 |
+
if ( method_exists( $this->deprecated, $name ) )
|
3827 |
+
return call_user_func_array( array( $this->deprecated, $name ), $args );
|
3828 |
+
else
|
3829 |
+
pods_deprecated( "Pods::{$name}", '2.0' );
|
3830 |
+
}
|
3831 |
+
}
|
classes/PodsAPI.php
ADDED
@@ -0,0 +1,7849 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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@var bool
|
14 |
+
*/
|
15 |
+
public $display_errors = false;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var array|bool|mixed|null|void
|
19 |
+
*/
|
20 |
+
public $pod_data;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var
|
24 |
+
*/
|
25 |
+
public $pod;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var
|
29 |
+
*/
|
30 |
+
public $pod_id;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var
|
34 |
+
*/
|
35 |
+
public $fields;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @var
|
39 |
+
* @deprecated 2.0
|
40 |
+
*/
|
41 |
+
public $format = null;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var
|
45 |
+
*/
|
46 |
+
private $deprecated;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Singleton handling for a basic pods_api() request
|
50 |
+
*
|
51 |
+
* @param string $pod (optional) The pod name
|
52 |
+
* @param string $format (deprecated) Format for import/export, "php" or "csv"
|
53 |
+
*
|
54 |
+
* @return \PodsAPI
|
55 |
+
*
|
56 |
+
* @since 2.3.5
|
57 |
+
*/
|
58 |
+
public static function init ( $pod = null, $format = null ) {
|
59 |
+
if ( null !== $pod || null !== $format ) {
|
60 |
+
return new PodsAPI( $pod, $format );
|
61 |
+
}
|
62 |
+
elseif ( !is_object( self::$instance ) ) {
|
63 |
+
self::$instance = new PodsAPI();
|
64 |
+
}
|
65 |
+
|
66 |
+
return self::$instance;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Store and retrieve data programatically
|
71 |
+
*
|
72 |
+
* @param string $pod (optional) The pod name
|
73 |
+
* @param string $format (deprecated) Format for import/export, "php" or "csv"
|
74 |
+
*
|
75 |
+
* @return \PodsAPI
|
76 |
+
*
|
77 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
78 |
+
* @since 1.7.1
|
79 |
+
*/
|
80 |
+
public function __construct ( $pod = null, $format = null ) {
|
81 |
+
if ( null !== $pod && 0 < strlen( (string) $pod ) ) {
|
82 |
+
if ( null !== $format ) {
|
83 |
+
$this->format = $format;
|
84 |
+
|
85 |
+
pods_deprecated( 'pods_api( $pod, $format )', '2.0', 'pods_api( $pod )' );
|
86 |
+
}
|
87 |
+
|
88 |
+
$pod = pods_clean_name( $pod );
|
89 |
+
|
90 |
+
$pod = $this->load_pod( array( 'name' => $pod, 'table_info' => true ), false );
|
91 |
+
|
92 |
+
if ( !empty( $pod ) ) {
|
93 |
+
$this->pod_data = $pod;
|
94 |
+
$this->pod = $pod[ 'name' ];
|
95 |
+
$this->pod_id = $pod[ 'id' ];
|
96 |
+
$this->fields = $pod[ 'fields' ];
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Save a WP object and its meta
|
103 |
+
*
|
104 |
+
* @param string $object_type Object type: post|user|comment|setting
|
105 |
+
* @param array $data All post data to be saved
|
106 |
+
* @param array $meta (optional) Associative array of meta keys and values
|
107 |
+
* @param bool $strict (optional) Decides whether the previous saved meta should be deleted or not
|
108 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
109 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
110 |
+
*
|
111 |
+
* @return bool|mixed
|
112 |
+
*
|
113 |
+
* @since 2.0
|
114 |
+
*/
|
115 |
+
public function save_wp_object ( $object_type, $data, $meta = array(), $strict = false, $sanitized = false, $fields = array() ) {
|
116 |
+
if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
|
117 |
+
$object_type = 'post';
|
118 |
+
|
119 |
+
if ( $sanitized ) {
|
120 |
+
$data = pods_unsanitize( $data );
|
121 |
+
$meta = pods_unsanitize( $meta );
|
122 |
+
}
|
123 |
+
|
124 |
+
if ( in_array( $object_type, array( 'post', 'user', 'comment' ) ) )
|
125 |
+
return call_user_func( array( $this, 'save_' . $object_type ), $data, $meta, $strict, false, $fields );
|
126 |
+
elseif ( 'settings' == $object_type ) {
|
127 |
+
// Nothing to save
|
128 |
+
if ( empty( $meta ) )
|
129 |
+
return true;
|
130 |
+
|
131 |
+
return $this->save_setting( pods_var( 'option_id', $data ), $meta, false );
|
132 |
+
}
|
133 |
+
|
134 |
+
return false;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Delete a WP object
|
139 |
+
*
|
140 |
+
* @param string $object_type Object type: post|user|comment
|
141 |
+
* @param int $id Object ID
|
142 |
+
* @param bool $force_delete (optional) Force deletion instead of trashing (post types only)
|
143 |
+
*
|
144 |
+
* @return bool|mixed
|
145 |
+
*
|
146 |
+
* @since 2.0
|
147 |
+
*/
|
148 |
+
public function delete_wp_object ( $object_type, $id, $force_delete = true ) {
|
149 |
+
if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
|
150 |
+
$object_type = 'post';
|
151 |
+
|
152 |
+
if ( empty( $id ) )
|
153 |
+
return false;
|
154 |
+
|
155 |
+
if ( in_array( $object_type, array( 'post' ) ) )
|
156 |
+
return wp_delete_post( $id, $force_delete );
|
157 |
+
|
158 |
+
if ( function_exists( 'wp_delete_' . $object_type ) )
|
159 |
+
return call_user_func( 'wp_delete_' . $object_type, $id );
|
160 |
+
|
161 |
+
return false;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Save a post and it's meta
|
166 |
+
*
|
167 |
+
* @param array $post_data All post data to be saved (using wp_insert_post / wp_update_post)
|
168 |
+
* @param array $post_meta (optional) All meta to be saved (set value to null to delete)
|
169 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
|
170 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
171 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
172 |
+
*
|
173 |
+
* @return mixed|void
|
174 |
+
*
|
175 |
+
* @since 2.0
|
176 |
+
*/
|
177 |
+
public function save_post ( $post_data, $post_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
178 |
+
$conflicted = pods_no_conflict_check( 'post' );
|
179 |
+
|
180 |
+
if ( !$conflicted )
|
181 |
+
pods_no_conflict_on( 'post' );
|
182 |
+
|
183 |
+
if ( !is_array( $post_data ) || empty( $post_data ) )
|
184 |
+
$post_data = array( 'post_title' => '' );
|
185 |
+
|
186 |
+
if ( !is_array( $post_meta ) )
|
187 |
+
$post_meta = array();
|
188 |
+
|
189 |
+
if ( $sanitized ) {
|
190 |
+
$post_data = pods_unsanitize( $post_data );
|
191 |
+
$post_meta = pods_unsanitize( $post_meta );
|
192 |
+
}
|
193 |
+
|
194 |
+
if ( !isset( $post_data[ 'ID' ] ) || empty( $post_data[ 'ID' ] ) )
|
195 |
+
$post_data[ 'ID' ] = wp_insert_post( $post_data, true );
|
196 |
+
elseif ( 2 < count( $post_data ) || !isset( $post_data[ 'post_type' ] ) )
|
197 |
+
wp_update_post( $post_data );
|
198 |
+
|
199 |
+
if ( is_wp_error( $post_data[ 'ID' ] ) ) {
|
200 |
+
if ( !$conflicted )
|
201 |
+
pods_no_conflict_off( 'post' );
|
202 |
+
|
203 |
+
/**
|
204 |
+
* @var $post_error WP_Error
|
205 |
+
*/
|
206 |
+
$post_error = $post_data[ 'ID' ];
|
207 |
+
|
208 |
+
return pods_error( $post_error->get_error_message(), $this );
|
209 |
+
}
|
210 |
+
|
211 |
+
$this->save_post_meta( $post_data[ 'ID' ], $post_meta, $strict, $fields );
|
212 |
+
|
213 |
+
if ( !$conflicted )
|
214 |
+
pods_no_conflict_off( 'post' );
|
215 |
+
|
216 |
+
return $post_data[ 'ID' ];
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Save a post's meta
|
221 |
+
*
|
222 |
+
* @param int $id Post ID
|
223 |
+
* @param array $post_meta All meta to be saved (set value to null to delete)
|
224 |
+
* @param bool $strict Whether to delete previously saved meta not in $post_meta
|
225 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
226 |
+
*
|
227 |
+
* @return int Id of the post with the meta
|
228 |
+
*
|
229 |
+
* @since 2.0
|
230 |
+
*/
|
231 |
+
public function save_post_meta ( $id, $post_meta = null, $strict = false, $fields = array() ) {
|
232 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
233 |
+
|
234 |
+
$conflicted = pods_no_conflict_check( 'post' );
|
235 |
+
|
236 |
+
if ( !$conflicted )
|
237 |
+
pods_no_conflict_on( 'post' );
|
238 |
+
|
239 |
+
if ( !is_array( $post_meta ) )
|
240 |
+
$post_meta = array();
|
241 |
+
|
242 |
+
$id = (int) $id;
|
243 |
+
|
244 |
+
$meta = get_post_meta( $id );
|
245 |
+
|
246 |
+
foreach ( $meta as $k => $value ) {
|
247 |
+
if ( is_array( $value ) && 1 == count( $value ) )
|
248 |
+
$meta[ $k ] = current( $value );
|
249 |
+
}
|
250 |
+
|
251 |
+
foreach ( $post_meta as $meta_key => $meta_value ) {
|
252 |
+
if ( null === $meta_value || ( $strict && '' === $post_meta[ $meta_key ] ) ) {
|
253 |
+
$old_meta_value = '';
|
254 |
+
|
255 |
+
if ( isset( $meta[ $meta_key ] ) )
|
256 |
+
$old_meta_value = $meta[ $meta_key ];
|
257 |
+
|
258 |
+
delete_post_meta( $id, $meta_key, $old_meta_value );
|
259 |
+
}
|
260 |
+
else {
|
261 |
+
$simple = false;
|
262 |
+
|
263 |
+
if ( isset( $fields[ $meta_key ] ) && is_array( $meta_value ) ) {
|
264 |
+
$field_data = $fields[ $meta_key ];
|
265 |
+
|
266 |
+
$simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
267 |
+
}
|
268 |
+
|
269 |
+
if ( $simple ) {
|
270 |
+
delete_post_meta( $id, $meta_key );
|
271 |
+
|
272 |
+
update_post_meta( $id, '_pods_' . $meta_key, $meta_value );
|
273 |
+
|
274 |
+
foreach ( $meta_value as $value ) {
|
275 |
+
add_post_meta( $id, $meta_key, $value );
|
276 |
+
}
|
277 |
+
}
|
278 |
+
else {
|
279 |
+
update_post_meta( $id, $meta_key, $meta_value );
|
280 |
+
}
|
281 |
+
}
|
282 |
+
}
|
283 |
+
|
284 |
+
if ( $strict ) {
|
285 |
+
foreach ( $meta as $meta_key => $meta_value ) {
|
286 |
+
if ( !isset( $post_meta[ $meta_key ] ) )
|
287 |
+
delete_post_meta( $id, $meta_key, $meta_value );
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
if ( !$conflicted )
|
292 |
+
pods_no_conflict_off( 'post' );
|
293 |
+
|
294 |
+
return $id;
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Save a user and it's meta
|
299 |
+
*
|
300 |
+
* @param array $user_data All user data to be saved (using wp_insert_user / wp_update_user)
|
301 |
+
* @param array $user_meta (optional) All meta to be saved (set value to null to delete)
|
302 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
|
303 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
304 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
305 |
+
*
|
306 |
+
* @return int Returns user id on success
|
307 |
+
*
|
308 |
+
* @since 2.0
|
309 |
+
*/
|
310 |
+
public function save_user ( $user_data, $user_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
311 |
+
if ( !is_array( $user_data ) || empty( $user_data ) )
|
312 |
+
return pods_error( __( 'User data is required but is either invalid or empty', 'pods' ), $this );
|
313 |
+
|
314 |
+
$conflicted = pods_no_conflict_check( 'user' );
|
315 |
+
|
316 |
+
if ( !$conflicted )
|
317 |
+
pods_no_conflict_on( 'user' );
|
318 |
+
|
319 |
+
if ( !is_array( $user_meta ) )
|
320 |
+
$user_meta = array();
|
321 |
+
|
322 |
+
if ( $sanitized ) {
|
323 |
+
$user_data = pods_unsanitize( $user_data );
|
324 |
+
$user_meta = pods_unsanitize( $user_meta );
|
325 |
+
}
|
326 |
+
|
327 |
+
// Set role
|
328 |
+
if ( isset( $user_meta[ 'role' ] ) ) {
|
329 |
+
$user_data[ 'role' ] = $user_meta[ 'role' ];
|
330 |
+
|
331 |
+
unset( $user_meta[ 'role' ] );
|
332 |
+
}
|
333 |
+
|
334 |
+
if ( !isset( $user_data[ 'ID' ] ) || empty( $user_data[ 'ID' ] ) )
|
335 |
+
$user_data[ 'ID' ] = wp_insert_user( $user_data );
|
336 |
+
elseif ( 1 < count( $user_data ) )
|
337 |
+
wp_update_user( $user_data );
|
338 |
+
|
339 |
+
if ( is_wp_error( $user_data[ 'ID' ] ) ) {
|
340 |
+
if ( !$conflicted )
|
341 |
+
pods_no_conflict_off( 'user' );
|
342 |
+
|
343 |
+
/**
|
344 |
+
* @var $user_error WP_Error
|
345 |
+
*/
|
346 |
+
$user_error = $user_data[ 'ID' ];
|
347 |
+
|
348 |
+
return pods_error( $user_error->get_error_message(), $this );
|
349 |
+
}
|
350 |
+
|
351 |
+
$this->save_user_meta( $user_data[ 'ID' ], $user_meta, $strict, $fields );
|
352 |
+
|
353 |
+
if ( !$conflicted )
|
354 |
+
pods_no_conflict_off( 'user' );
|
355 |
+
|
356 |
+
return $user_data[ 'ID' ];
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* Save a user meta
|
361 |
+
*
|
362 |
+
* @param int $id User ID
|
363 |
+
* @param array $user_meta (optional) All meta to be saved (set value to null to delete)
|
364 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
|
365 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
366 |
+
*
|
367 |
+
* @return int User ID
|
368 |
+
*
|
369 |
+
* @since 2.0
|
370 |
+
*
|
371 |
+
*/
|
372 |
+
public function save_user_meta ( $id, $user_meta = null, $strict = false, $fields = array() ) {
|
373 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
374 |
+
|
375 |
+
$conflicted = pods_no_conflict_check( 'user' );
|
376 |
+
|
377 |
+
if ( !$conflicted )
|
378 |
+
pods_no_conflict_on( 'user' );
|
379 |
+
|
380 |
+
if ( !is_array( $user_meta ) )
|
381 |
+
$user_meta = array();
|
382 |
+
|
383 |
+
$id = (int) $id;
|
384 |
+
|
385 |
+
$meta = get_user_meta( $id );
|
386 |
+
|
387 |
+
foreach ( $user_meta as $meta_key => $meta_value ) {
|
388 |
+
if ( null === $meta_value ) {
|
389 |
+
$old_meta_value = '';
|
390 |
+
|
391 |
+
if ( isset( $meta[ $meta_key ] ) )
|
392 |
+
$old_meta_value = $meta[ $meta_key ];
|
393 |
+
|
394 |
+
delete_user_meta( $id, $meta_key, $old_meta_value );
|
395 |
+
}
|
396 |
+
else {
|
397 |
+
$simple = false;
|
398 |
+
|
399 |
+
if ( isset( $fields[ $meta_key ] ) && is_array( $meta_value ) ) {
|
400 |
+
$field_data = $fields[ $meta_key ];
|
401 |
+
|
402 |
+
$simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
403 |
+
}
|
404 |
+
|
405 |
+
if ( $simple ) {
|
406 |
+
delete_user_meta( $id, $meta_key );
|
407 |
+
|
408 |
+
foreach ( $meta_value as $value ) {
|
409 |
+
add_user_meta( $id, $meta_key, $value );
|
410 |
+
}
|
411 |
+
}
|
412 |
+
else {
|
413 |
+
update_user_meta( $id, $meta_key, $meta_value );
|
414 |
+
}
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
if ( $strict ) {
|
419 |
+
foreach ( $meta as $meta_key => $meta_value ) {
|
420 |
+
if ( !isset( $user_meta[ $meta_key ] ) )
|
421 |
+
delete_user_meta( $id, $meta_key, $user_meta[ $meta_key ] );
|
422 |
+
}
|
423 |
+
}
|
424 |
+
|
425 |
+
if ( !$conflicted )
|
426 |
+
pods_no_conflict_off( 'user' );
|
427 |
+
|
428 |
+
return $id;
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* Save a comment and it's meta
|
433 |
+
*
|
434 |
+
* @param array $comment_data All comment data to be saved (using wp_insert_comment / wp_update_comment)
|
435 |
+
* @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
|
436 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
|
437 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
438 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
439 |
+
*
|
440 |
+
* @return int Comment ID
|
441 |
+
*
|
442 |
+
* @since 2.0
|
443 |
+
*/
|
444 |
+
public function save_comment ( $comment_data, $comment_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
445 |
+
if ( !is_array( $comment_data ) || empty( $comment_data ) )
|
446 |
+
return pods_error( __( 'Comment data is required but is either invalid or empty', 'pods' ), $this );
|
447 |
+
|
448 |
+
$conflicted = pods_no_conflict_check( 'comment' );
|
449 |
+
|
450 |
+
if ( !$conflicted )
|
451 |
+
pods_no_conflict_on( 'comment' );
|
452 |
+
|
453 |
+
if ( !is_array( $comment_meta ) )
|
454 |
+
$comment_meta = array();
|
455 |
+
|
456 |
+
if ( $sanitized ) {
|
457 |
+
$comment_data = pods_unsanitize( $comment_data );
|
458 |
+
$comment_meta = pods_unsanitize( $comment_meta );
|
459 |
+
}
|
460 |
+
|
461 |
+
if ( !isset( $comment_data[ 'comment_ID' ] ) || empty( $comment_data[ 'comment_ID' ] ) )
|
462 |
+
$comment_data[ 'comment_ID' ] = wp_insert_comment( $comment_data );
|
463 |
+
elseif ( 1 < count( $comment_data ) )
|
464 |
+
wp_update_comment( $comment_data );
|
465 |
+
|
466 |
+
if ( is_wp_error( $comment_data[ 'comment_ID' ] ) ) {
|
467 |
+
if ( !$conflicted )
|
468 |
+
pods_no_conflict_off( 'comment' );
|
469 |
+
|
470 |
+
/**
|
471 |
+
* @var $comment_error WP_Error
|
472 |
+
*/
|
473 |
+
$comment_error = $comment_data[ 'comment_ID' ];
|
474 |
+
|
475 |
+
return pods_error( $comment_error->get_error_message(), $this );
|
476 |
+
}
|
477 |
+
|
478 |
+
$this->save_comment_meta( $comment_data[ 'comment_ID' ], $comment_meta, $strict, $fields );
|
479 |
+
|
480 |
+
if ( !$conflicted )
|
481 |
+
pods_no_conflict_off( 'comment' );
|
482 |
+
|
483 |
+
return $comment_data[ 'comment_ID' ];
|
484 |
+
}
|
485 |
+
|
486 |
+
/**
|
487 |
+
* Save a comment meta
|
488 |
+
*
|
489 |
+
* @param int $id Comment ID
|
490 |
+
* @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
|
491 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
|
492 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
493 |
+
*
|
494 |
+
* @return int Comment ID
|
495 |
+
*
|
496 |
+
* @since 2.0
|
497 |
+
*/
|
498 |
+
public function save_comment_meta ( $id, $comment_meta = null, $strict = false, $fields = array() ) {
|
499 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
500 |
+
|
501 |
+
$conflicted = pods_no_conflict_check( 'comment' );
|
502 |
+
|
503 |
+
if ( !$conflicted )
|
504 |
+
pods_no_conflict_on( 'comment' );
|
505 |
+
|
506 |
+
if ( !is_array( $comment_meta ) )
|
507 |
+
$comment_meta = array();
|
508 |
+
|
509 |
+
$id = (int) $id;
|
510 |
+
|
511 |
+
$meta = get_comment_meta( $id );
|
512 |
+
|
513 |
+
foreach ( $comment_meta as $meta_key => $meta_value ) {
|
514 |
+
if ( null === $meta_value ) {
|
515 |
+
$old_meta_value = '';
|
516 |
+
|
517 |
+
if ( isset( $meta[ $meta_key ] ) )
|
518 |
+
$old_meta_value = $meta[ $meta_key ];
|
519 |
+
|
520 |
+
delete_comment_meta( $id, $meta_key, $old_meta_value );
|
521 |
+
}
|
522 |
+
else {
|
523 |
+
$simple = false;
|
524 |
+
|
525 |
+
if ( isset( $fields[ $meta_key ] ) && is_array( $meta_value ) ) {
|
526 |
+
$field_data = $fields[ $meta_key ];
|
527 |
+
|
528 |
+
$simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
529 |
+
}
|
530 |
+
|
531 |
+
if ( $simple ) {
|
532 |
+
delete_comment_meta( $id, $meta_key );
|
533 |
+
|
534 |
+
foreach ( $meta_value as $value ) {
|
535 |
+
add_comment_meta( $id, $meta_key, $value );
|
536 |
+
}
|
537 |
+
}
|
538 |
+
else {
|
539 |
+
update_comment_meta( $id, $meta_key, $meta_value );
|
540 |
+
}
|
541 |
+
}
|
542 |
+
}
|
543 |
+
|
544 |
+
if ( $strict ) {
|
545 |
+
foreach ( $meta as $meta_key => $meta_value ) {
|
546 |
+
if ( !isset( $comment_meta[ $meta_key ] ) )
|
547 |
+
delete_comment_meta( (int) $id, $meta_key, $comment_meta[ $meta_key ] );
|
548 |
+
}
|
549 |
+
}
|
550 |
+
|
551 |
+
if ( !$conflicted )
|
552 |
+
pods_no_conflict_off( 'comment' );
|
553 |
+
|
554 |
+
return $id;
|
555 |
+
}
|
556 |
+
|
557 |
+
/**
|
558 |
+
* Save a taxonomy's term
|
559 |
+
*
|
560 |
+
* @param int $term_ID Term ID, leave empty to add
|
561 |
+
* @param string $term Term name
|
562 |
+
* @param string $taxonomy Taxonomy name
|
563 |
+
* @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
|
564 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
565 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
566 |
+
*
|
567 |
+
* @return int Term ID
|
568 |
+
*
|
569 |
+
* @since 2.0
|
570 |
+
*/
|
571 |
+
public function save_term ( $term_ID, $term, $taxonomy, $term_data, $sanitized = false, $fields = array() ) {
|
572 |
+
$conflicted = pods_no_conflict_check( 'taxonomy' );
|
573 |
+
|
574 |
+
if ( !$conflicted )
|
575 |
+
pods_no_conflict_on( 'taxonomy' );
|
576 |
+
|
577 |
+
if ( !is_array( $term_data ) )
|
578 |
+
$term_data = array();
|
579 |
+
|
580 |
+
$term_ID = (int) $term_ID;
|
581 |
+
|
582 |
+
if ( $sanitized ) {
|
583 |
+
$term = pods_unsanitize( $term );
|
584 |
+
$taxonomy = pods_unsanitize( $taxonomy );
|
585 |
+
$term_data = pods_unsanitize( $term_data );
|
586 |
+
}
|
587 |
+
|
588 |
+
if ( empty( $term_ID ) )
|
589 |
+
$term_ID = wp_insert_term( $term, $taxonomy, $term_data );
|
590 |
+
else {
|
591 |
+
if ( 0 < strlen( $term ) )
|
592 |
+
$term_data[ 'term' ] = $term;
|
593 |
+
|
594 |
+
if ( empty( $term_data ) ) {
|
595 |
+
if ( !$conflicted )
|
596 |
+
pods_no_conflict_off( 'taxonomy' );
|
597 |
+
|
598 |
+
return pods_error( __( 'Taxonomy term data is required but is either invalid or empty', 'pods' ), $this );
|
599 |
+
}
|
600 |
+
|
601 |
+
wp_update_term( $term_ID, $taxonomy, $term_data );
|
602 |
+
}
|
603 |
+
|
604 |
+
if ( is_wp_error( $term_ID ) ) {
|
605 |
+
if ( !$conflicted )
|
606 |
+
pods_no_conflict_off( 'taxonomy' );
|
607 |
+
|
608 |
+
return pods_error( $term_ID->get_error_message(), $this );
|
609 |
+
}
|
610 |
+
elseif ( is_array( $term_ID ) )
|
611 |
+
$term_ID = $term_ID[ 'term_id' ];
|
612 |
+
|
613 |
+
if ( !$conflicted )
|
614 |
+
pods_no_conflict_off( 'taxonomy' );
|
615 |
+
|
616 |
+
return $term_ID;
|
617 |
+
}
|
618 |
+
|
619 |
+
/**
|
620 |
+
* Save a set of options
|
621 |
+
*
|
622 |
+
* @param string $setting Setting group name
|
623 |
+
* @param array $option_data All option data to be saved
|
624 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
625 |
+
*
|
626 |
+
* @return bool
|
627 |
+
*
|
628 |
+
* @since 2.3
|
629 |
+
*/
|
630 |
+
public function save_setting ( $setting, $option_data, $sanitized = false ) {
|
631 |
+
if ( !is_array( $option_data ) || empty( $option_data ) )
|
632 |
+
return pods_error( __( 'Setting data is required but is either invalid or empty', 'pods' ), $this );
|
633 |
+
|
634 |
+
$conflicted = pods_no_conflict_check( 'settings' );
|
635 |
+
|
636 |
+
if ( !$conflicted )
|
637 |
+
pods_no_conflict_on( 'settings' );
|
638 |
+
|
639 |
+
if ( $sanitized )
|
640 |
+
$option_data = pods_unsanitize( $option_data );
|
641 |
+
|
642 |
+
foreach ( $option_data as $option => $value ) {
|
643 |
+
if ( !empty( $setting ) )
|
644 |
+
$option = $setting . '_' . $option;
|
645 |
+
|
646 |
+
update_option( $option, $value );
|
647 |
+
}
|
648 |
+
|
649 |
+
if ( !$conflicted )
|
650 |
+
pods_no_conflict_off( 'settings' );
|
651 |
+
|
652 |
+
return true;
|
653 |
+
}
|
654 |
+
|
655 |
+
/**
|
656 |
+
* Rename a WP object's type
|
657 |
+
*
|
658 |
+
* @param string $object_type Object type: post|taxonomy|comment|setting
|
659 |
+
* @param string $old_name The old name
|
660 |
+
* @param string $new_name The new name
|
661 |
+
*
|
662 |
+
* @return bool
|
663 |
+
*
|
664 |
+
* @since 2.0
|
665 |
+
*/
|
666 |
+
public function rename_wp_object_type ( $object_type, $old_name, $new_name ) {
|
667 |
+
/**
|
668 |
+
* @var $wpdb wpdb
|
669 |
+
*/
|
670 |
+
global $wpdb;
|
671 |
+
|
672 |
+
if ( 'post_type' == $object_type )
|
673 |
+
$object_type = 'post';
|
674 |
+
|
675 |
+
if ( 'post' == $object_type ) {
|
676 |
+
pods_query( "UPDATE `{$wpdb->posts}` SET `post_type` = %s WHERE `post_type` = %s", array(
|
677 |
+
$new_name,
|
678 |
+
$old_name
|
679 |
+
) );
|
680 |
+
}
|
681 |
+
elseif ( 'taxonomy' == $object_type ) {
|
682 |
+
pods_query( "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s", array(
|
683 |
+
$new_name,
|
684 |
+
$old_name
|
685 |
+
) );
|
686 |
+
}
|
687 |
+
elseif ( 'comment' == $object_type ) {
|
688 |
+
pods_query( "UPDATE `{$wpdb->comments}` SET `comment_type` = %s WHERE `comment_type` = %s", array(
|
689 |
+
$new_name,
|
690 |
+
$old_name
|
691 |
+
) );
|
692 |
+
}
|
693 |
+
elseif ( 'settings' == $object_type ) {
|
694 |
+
pods_query( "UPDATE `{$wpdb->options}` SET `option_name` = REPLACE( `option_name`, %s, %s ) WHERE `option_name` LIKE '" . pods_sanitize_like( $old_name ) . "_%'", array(
|
695 |
+
$new_name . '_',
|
696 |
+
$old_name . '_'
|
697 |
+
) );
|
698 |
+
}
|
699 |
+
|
700 |
+
return true;
|
701 |
+
}
|
702 |
+
|
703 |
+
/**
|
704 |
+
* Get a list of core WP object fields for a specific object
|
705 |
+
*
|
706 |
+
* @param string $object The pod type to look for, possible values: post_type, user, comment, taxonomy
|
707 |
+
* @param array $pod Array of Pod data
|
708 |
+
* @param boolean $refresh Whether to force refresh the information
|
709 |
+
*
|
710 |
+
* @return array Array of fields
|
711 |
+
*
|
712 |
+
* @since 2.0
|
713 |
+
*/
|
714 |
+
public function get_wp_object_fields ( $object = 'post_type', $pod = null, $refresh = false ) {
|
715 |
+
$pod_name = pods_var_raw( 'name', $pod, $object, null, true );
|
716 |
+
|
717 |
+
if ( 'media' == $pod_name ) {
|
718 |
+
$object = 'post_type';
|
719 |
+
$pod_name = 'attachment';
|
720 |
+
}
|
721 |
+
|
722 |
+
$fields = false;
|
723 |
+
|
724 |
+
if ( pods_api_cache() )
|
725 |
+
$fields = pods_transient_get( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ) );
|
726 |
+
|
727 |
+
if ( false !== $fields && !$refresh )
|
728 |
+
return $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
|
729 |
+
|
730 |
+
$fields = array();
|
731 |
+
|
732 |
+
if ( 'post_type' == $object ) {
|
733 |
+
$fields = array(
|
734 |
+
'post_title' => array(
|
735 |
+
'name' => 'post_title',
|
736 |
+
'label' => 'Title',
|
737 |
+
'type' => 'text',
|
738 |
+
'alias' => array( 'title', 'name' ),
|
739 |
+
'options' => array(
|
740 |
+
'display_filter' => 'the_title',
|
741 |
+
'display_filter_args' => array( 'post_ID' )
|
742 |
+
)
|
743 |
+
),
|
744 |
+
'post_content' => array(
|
745 |
+
'name' => 'post_content',
|
746 |
+
'label' => 'Content',
|
747 |
+
'type' => 'wysiwyg',
|
748 |
+
'alias' => array( 'content' ),
|
749 |
+
'options' => array(
|
750 |
+
'wysiwyg_allowed_html_tags' => '',
|
751 |
+
'display_filter' => 'the_content',
|
752 |
+
'pre_save' => 0
|
753 |
+
)
|
754 |
+
),
|
755 |
+
'post_excerpt' => array(
|
756 |
+
'name' => 'post_excerpt',
|
757 |
+
'label' => 'Excerpt',
|
758 |
+
'type' => 'paragraph',
|
759 |
+
'alias' => array( 'excerpt' ),
|
760 |
+
'options' => array(
|
761 |
+
'paragraph_allow_html' => 1,
|
762 |
+
'paragraph_allowed_html_tags' => '',
|
763 |
+
'display_filter' => 'the_excerpt',
|
764 |
+
'pre_save' => 0
|
765 |
+
)
|
766 |
+
),
|
767 |
+
'post_author' => array(
|
768 |
+
'name' => 'post_author',
|
769 |
+
'label' => 'Author',
|
770 |
+
'type' => 'pick',
|
771 |
+
'alias' => array( 'author' ),
|
772 |
+
'pick_object' => 'user',
|
773 |
+
'options' => array(
|
774 |
+
'pick_format_type' => 'single',
|
775 |
+
'pick_format_single' => 'autocomplete',
|
776 |
+
'default_value' => '{@user.ID}'
|
777 |
+
)
|
778 |
+
),
|
779 |
+
'post_date' => array(
|
780 |
+
'name' => 'post_date',
|
781 |
+
'label' => 'Publish Date',
|
782 |
+
'type' => 'datetime',
|
783 |
+
'alias' => array( 'created', 'date' )
|
784 |
+
),
|
785 |
+
'post_date_gmt' => array(
|
786 |
+
'name' => 'post_date_gmt',
|
787 |
+
'label' => 'Publish Date (GMT)',
|
788 |
+
'type' => 'datetime',
|
789 |
+
'alias' => array(),
|
790 |
+
'hidden' => true
|
791 |
+
),
|
792 |
+
'post_status' => array(
|
793 |
+
'name' => 'post_status',
|
794 |
+
'label' => 'Status',
|
795 |
+
'type' => 'pick',
|
796 |
+
'pick_object' => 'post-status',
|
797 |
+
'default' => $this->do_hook( 'default_status_' . $pod_name, pods_var( 'default_status', pods_var_raw( 'options', $pod ), 'draft', null, true ), $pod ),
|
798 |
+
'alias' => array( 'status' )
|
799 |
+
),
|
800 |
+
'comment_status' => array(
|
801 |
+
'name' => 'comment_status',
|
802 |
+
'label' => 'Comment Status',
|
803 |
+
'type' => 'text',
|
804 |
+
'default' => get_option( 'default_comment_status', 'open' ),
|
805 |
+
'alias' => array(),
|
806 |
+
'data' => array(
|
807 |
+
'open' => __( 'Open', 'pods' ),
|
808 |
+
'closed' => __( 'Closed', 'pods' )
|
809 |
+
)
|
810 |
+
),
|
811 |
+
'ping_status' => array(
|
812 |
+
'name' => 'ping_status',
|
813 |
+
'label' => 'Ping Status',
|
814 |
+
'default' => get_option( 'default_ping_status', 'open' ),
|
815 |
+
'type' => 'text',
|
816 |
+
'alias' => array(),
|
817 |
+
'data' => array(
|
818 |
+
'open' => __( 'Open', 'pods' ),
|
819 |
+
'closed' => __( 'Closed', 'pods' )
|
820 |
+
)
|
821 |
+
),
|
822 |
+
'post_password' => array(
|
823 |
+
'name' => 'post_password',
|
824 |
+
'label' => 'Password',
|
825 |
+
'type' => 'text',
|
826 |
+
'alias' => array()
|
827 |
+
),
|
828 |
+
'post_name' => array(
|
829 |
+
'name' => 'post_name',
|
830 |
+
'label' => 'Permalink',
|
831 |
+
'type' => 'slug',
|
832 |
+
'alias' => array( 'slug', 'permalink' )
|
833 |
+
),
|
834 |
+
'to_ping' => array(
|
835 |
+
'name' => 'to_ping',
|
836 |
+
'label' => 'To Ping',
|
837 |
+
'type' => 'text',
|
838 |
+
'alias' => array(),
|
839 |
+
'hidden' => true
|
840 |
+
),
|
841 |
+
'pinged' => array(
|
842 |
+
'name' => 'pinged',
|
843 |
+
'label' => 'Pinged',
|
844 |
+
'type' => 'text',
|
845 |
+
'alias' => array(),
|
846 |
+
'hidden' => true
|
847 |
+
),
|
848 |
+
'post_modified' => array(
|
849 |
+
'name' => 'post_modified',
|
850 |
+
'label' => 'Last Modified Date',
|
851 |
+
'type' => 'datetime',
|
852 |
+
'alias' => array( 'modified' ),
|
853 |
+
'hidden' => true
|
854 |
+
),
|
855 |
+
'post_modified_gmt' => array(
|
856 |
+
'name' => 'post_modified_gmt',
|
857 |
+
'label' => 'Last Modified Date (GMT)',
|
858 |
+
'type' => 'datetime',
|
859 |
+
'alias' => array(),
|
860 |
+
'hidden' => true
|
861 |
+
),
|
862 |
+
'post_content_filtered' => array(
|
863 |
+
'name' => 'post_content_filtered',
|
864 |
+
'label' => 'Content (filtered)',
|
865 |
+
'type' => 'paragraph',
|
866 |
+
'alias' => array(),
|
867 |
+
'hidden' => true,
|
868 |
+
'options' => array(
|
869 |
+
'paragraph_allow_html' => 1,
|
870 |
+
'paragraph_oembed' => 1,
|
871 |
+
'paragraph_wptexturize' => 1,
|
872 |
+
'paragraph_convert_chars' => 1,
|
873 |
+
'paragraph_wpautop' => 1,
|
874 |
+
'paragraph_allow_shortcode' => 1,
|
875 |
+
'paragraph_allowed_html_tags' => ''
|
876 |
+
)
|
877 |
+
),
|
878 |
+
'post_parent' => array(
|
879 |
+
'name' => 'post_parent',
|
880 |
+
'label' => 'Parent',
|
881 |
+
'type' => 'pick',
|
882 |
+
'pick_object' => 'post_type',
|
883 |
+
'pick_val' => '__current__',
|
884 |
+
'alias' => array( 'parent' ),
|
885 |
+
'data' => array(),
|
886 |
+
'hidden' => true
|
887 |
+
),
|
888 |
+
'guid' => array(
|
889 |
+
'name' => 'guid',
|
890 |
+
'label' => 'GUID',
|
891 |
+
'type' => 'text',
|
892 |
+
'alias' => array(),
|
893 |
+
'hidden' => true
|
894 |
+
),
|
895 |
+
'menu_order' => array(
|
896 |
+
'name' => 'menu_order',
|
897 |
+
'label' => 'Menu Order',
|
898 |
+
'type' => 'number',
|
899 |
+
'alias' => array()
|
900 |
+
),
|
901 |
+
'post_type' => array(
|
902 |
+
'name' => 'post_type',
|
903 |
+
'label' => 'Type',
|
904 |
+
'type' => 'text',
|
905 |
+
'alias' => array( 'type' ),
|
906 |
+
'hidden' => true
|
907 |
+
),
|
908 |
+
'post_mime_type' => array(
|
909 |
+
'name' => 'post_mime_type',
|
910 |
+
'label' => 'Mime Type',
|
911 |
+
'type' => 'text',
|
912 |
+
'alias' => array(),
|
913 |
+
'hidden' => true
|
914 |
+
),
|
915 |
+
'comment_count' => array(
|
916 |
+
'name' => 'comment_count',
|
917 |
+
'label' => 'Comment Count',
|
918 |
+
'type' => 'number',
|
919 |
+
'alias' => array(),
|
920 |
+
'hidden' => true
|
921 |
+
)
|
922 |
+
);
|
923 |
+
|
924 |
+
if ( !empty( $pod ) ) {
|
925 |
+
$taxonomies = get_object_taxonomies( $pod_name, 'objects' );
|
926 |
+
|
927 |
+
foreach ( $taxonomies as $taxonomy ) {
|
928 |
+
$fields[ $taxonomy->name ] = array(
|
929 |
+
'name' => $taxonomy->name,
|
930 |
+
'label' => $taxonomy->labels->name,
|
931 |
+
'type' => 'taxonomy',
|
932 |
+
'pick_object' => 'taxonomy',
|
933 |
+
'pick_val' => $taxonomy->name,
|
934 |
+
'alias' => array(),
|
935 |
+
'hidden' => true,
|
936 |
+
'options' => array(
|
937 |
+
'taxonomy_format_type' => 'multi'
|
938 |
+
)
|
939 |
+
);
|
940 |
+
}
|
941 |
+
}
|
942 |
+
}
|
943 |
+
elseif ( 'user' == $object ) {
|
944 |
+
$fields = array(
|
945 |
+
'user_login' => array(
|
946 |
+
'name' => 'user_login',
|
947 |
+
'label' => 'Title',
|
948 |
+
'type' => 'text',
|
949 |
+
'alias' => array( 'login' ),
|
950 |
+
'options' => array(
|
951 |
+
'required' => 1
|
952 |
+
)
|
953 |
+
),
|
954 |
+
'user_nicename' => array(
|
955 |
+
'name' => 'user_nicename',
|
956 |
+
'label' => 'Permalink',
|
957 |
+
'type' => 'slug',
|
958 |
+
'alias' => array( 'nicename', 'slug', 'permalink' )
|
959 |
+
),
|
960 |
+
'display_name' => array(
|
961 |
+
'name' => 'display_name',
|
962 |
+
'label' => 'Display Name',
|
963 |
+
'type' => 'text',
|
964 |
+
'alias' => array( 'title', 'name' )
|
965 |
+
),
|
966 |
+
'user_pass' => array(
|
967 |
+
'name' => 'user_pass',
|
968 |
+
'label' => 'Password',
|
969 |
+
'type' => 'text',
|
970 |
+
'alias' => array( 'password', 'pass' ),
|
971 |
+
'options' => array(
|
972 |
+
'required' => 1,
|
973 |
+
'text_format_type' => 'password'
|
974 |
+
)
|
975 |
+
),
|
976 |
+
'user_email' => array(
|
977 |
+
'name' => 'user_email',
|
978 |
+
'label' => 'E-mail',
|
979 |
+
'type' => 'text',
|
980 |
+
'alias' => array( 'email' ),
|
981 |
+
'options' => array(
|
982 |
+
'required' => 1,
|
983 |
+
'text_format_type' => 'email'
|
984 |
+
)
|
985 |
+
),
|
986 |
+
'user_url' => array(
|
987 |
+
'name' => 'user_url',
|
988 |
+
'label' => 'URL',
|
989 |
+
'type' => 'text',
|
990 |
+
'alias' => array( 'url', 'website' ),
|
991 |
+
'options' => array(
|
992 |
+
'required' => 1,
|
993 |
+
'text_format_type' => 'website',
|
994 |
+
'text_format_website' => 'normal'
|
995 |
+
)
|
996 |
+
),
|
997 |
+
'user_registered' => array(
|
998 |
+
'name' => 'user_registered',
|
999 |
+
'label' => 'Registration Date',
|
1000 |
+
'type' => 'date',
|
1001 |
+
'alias' => array( 'created', 'date', 'registered' ),
|
1002 |
+
'options' => array(
|
1003 |
+
'date_format_type' => 'datetime'
|
1004 |
+
)
|
1005 |
+
)
|
1006 |
+
);
|
1007 |
+
}
|
1008 |
+
elseif ( 'comment' == $object ) {
|
1009 |
+
$fields = array(
|
1010 |
+
'comment_content' => array(
|
1011 |
+
'name' => 'comment_content',
|
1012 |
+
'label' => 'Content',
|
1013 |
+
'type' => 'wysiwyg',
|
1014 |
+
'alias' => array( 'content' )
|
1015 |
+
),
|
1016 |
+
'comment_approved' => array(
|
1017 |
+
'name' => 'comment_approved',
|
1018 |
+
'label' => 'Approved',
|
1019 |
+
'type' => 'number',
|
1020 |
+
'alias' => array( 'approved' )
|
1021 |
+
),
|
1022 |
+
'comment_post_ID' => array(
|
1023 |
+
'name' => 'comment_post_ID',
|
1024 |
+
'label' => 'Post',
|
1025 |
+
'type' => 'pick',
|
1026 |
+
'alias' => array( 'post', 'post_id' ),
|
1027 |
+
'data' => array()
|
1028 |
+
),
|
1029 |
+
'user_id' => array(
|
1030 |
+
'name' => 'user_id',
|
1031 |
+
'label' => 'Author',
|
1032 |
+
'type' => 'pick',
|
1033 |
+
'alias' => array( 'author' ),
|
1034 |
+
'pick_object' => 'user',
|
1035 |
+
'data' => array()
|
1036 |
+
),
|
1037 |
+
'comment_date' => array(
|
1038 |
+
'name' => 'comment_date',
|
1039 |
+
'label' => 'Date',
|
1040 |
+
'type' => 'date',
|
1041 |
+
'alias' => array( 'created', 'date' ),
|
1042 |
+
'options' => array(
|
1043 |
+
'date_format_type' => 'datetime'
|
1044 |
+
)
|
1045 |
+
)
|
1046 |
+
);
|
1047 |
+
}
|
1048 |
+
elseif ( 'taxonomy' == $object ) {
|
1049 |
+
$fields = array(
|
1050 |
+
'name' => array(
|
1051 |
+
'name' => 'name',
|
1052 |
+
'label' => 'Title',
|
1053 |
+
'type' => 'text',
|
1054 |
+
'alias' => array( 'title' )
|
1055 |
+
),
|
1056 |
+
'slug' => array(
|
1057 |
+
'name' => 'slug',
|
1058 |
+
'label' => 'Permalink',
|
1059 |
+
'type' => 'slug',
|
1060 |
+
'alias' => array( 'permalink' )
|
1061 |
+
),
|
1062 |
+
'description' => array(
|
1063 |
+
'name' => 'description',
|
1064 |
+
'label' => 'Description',
|
1065 |
+
'type' => 'wysiwyg',
|
1066 |
+
'alias' => array( 'content' )
|
1067 |
+
),
|
1068 |
+
'taxonomy' => array(
|
1069 |
+
'name' => 'taxonomy',
|
1070 |
+
'label' => 'Taxonomy',
|
1071 |
+
'type' => 'pick',
|
1072 |
+
'alias' => array()
|
1073 |
+
),
|
1074 |
+
'parent' => array(
|
1075 |
+
'name' => 'parent',
|
1076 |
+
'label' => 'Parent',
|
1077 |
+
'type' => 'pick',
|
1078 |
+
'pick_object' => 'taxonomy',
|
1079 |
+
'pick_val' => '__current__',
|
1080 |
+
'alias' => array( 'parent' ),
|
1081 |
+
'data' => array(),
|
1082 |
+
'hidden' => true
|
1083 |
+
),
|
1084 |
+
'term_taxonomy_id' => array(
|
1085 |
+
'name' => 'term_taxonomy_id',
|
1086 |
+
'label' => 'Term Taxonomy ID',
|
1087 |
+
'type' => 'number',
|
1088 |
+
'alias' => array( 'term_taxonomy_id' ),
|
1089 |
+
'hidden' => true
|
1090 |
+
),
|
1091 |
+
'term_group' => array(
|
1092 |
+
'name' => 'term_group',
|
1093 |
+
'label' => 'Term Group',
|
1094 |
+
'type' => 'number',
|
1095 |
+
'alias' => array( 'term_group' ),
|
1096 |
+
'hidden' => true
|
1097 |
+
),
|
1098 |
+
'count' => array(
|
1099 |
+
'name' => 'count',
|
1100 |
+
'label' => 'Count',
|
1101 |
+
'type' => 'number',
|
1102 |
+
'alias' => array( 'count' ),
|
1103 |
+
'hidden' => true
|
1104 |
+
)
|
1105 |
+
);
|
1106 |
+
}
|
1107 |
+
|
1108 |
+
$fields = $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
|
1109 |
+
|
1110 |
+
foreach ( $fields as $field => $options ) {
|
1111 |
+
if ( !isset( $options[ 'alias' ] ) )
|
1112 |
+
$options[ 'alias' ] = array();
|
1113 |
+
else
|
1114 |
+
$options[ 'alias' ] = (array) $options[ 'alias' ];
|
1115 |
+
|
1116 |
+
if ( !isset( $options[ 'name' ] ) )
|
1117 |
+
$options[ 'name' ] = $field;
|
1118 |
+
|
1119 |
+
$fields[ $field ] = $options;
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
$fields = PodsForm::fields_setup( $fields );
|
1123 |
+
|
1124 |
+
if ( did_action( 'init' ) && pods_api_cache() )
|
1125 |
+
pods_transient_set( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ), $fields );
|
1126 |
+
|
1127 |
+
return $fields;
|
1128 |
+
}
|
1129 |
+
|
1130 |
+
/**
|
1131 |
+
*
|
1132 |
+
* @see PodsAPI::save_pod
|
1133 |
+
*
|
1134 |
+
* Add a Pod via the Wizard
|
1135 |
+
*
|
1136 |
+
* $params['create_extend'] string Create or Extend a Content Type
|
1137 |
+
* $params['create_pod_type'] string Pod Type (for Creating)
|
1138 |
+
* $params['create_name'] string Pod Name (for Creating)
|
1139 |
+
* $params['create_label_plural'] string Plural Label (for Creating)
|
1140 |
+
* $params['create_label_singular'] string Singular Label (for Creating)
|
1141 |
+
* $params['create_storage'] string Storage Type (for Creating Post Types)
|
1142 |
+
* $params['create_storage_taxonomy'] string Storage Type (for Creating Taxonomies)
|
1143 |
+
* $params['extend_pod_type'] string Pod Type (for Extending)
|
1144 |
+
* $params['extend_post_type'] string Post Type (for Extending Post Types)
|
1145 |
+
* $params['extend_taxonomy'] string Taxonomy (for Extending Taxonomies)
|
1146 |
+
* $params['extend_storage'] string Storage Type (for Extending Post Types / Users / Comments)
|
1147 |
+
*
|
1148 |
+
* @param array $params An associative array of parameters
|
1149 |
+
*
|
1150 |
+
* @return bool|int Pod ID
|
1151 |
+
* @since 2.0
|
1152 |
+
*/
|
1153 |
+
public function add_pod ( $params ) {
|
1154 |
+
$defaults = array(
|
1155 |
+
'create_extend' => 'create',
|
1156 |
+
'create_pod_type' => 'post_type',
|
1157 |
+
|
1158 |
+
'create_name' => '',
|
1159 |
+
'create_label_singular' => '',
|
1160 |
+
'create_label_plural' => '',
|
1161 |
+
'create_storage' => 'meta',
|
1162 |
+
'create_storage_taxonomy' => 'none',
|
1163 |
+
|
1164 |
+
'create_setting_name' => '',
|
1165 |
+
'create_label_title' => '',
|
1166 |
+
'create_label_menu' => '',
|
1167 |
+
'create_menu_location' => 'settings',
|
1168 |
+
|
1169 |
+
'extend_pod_type' => 'post_type',
|
1170 |
+
'extend_post_type' => 'post',
|
1171 |
+
'extend_taxonomy' => 'category',
|
1172 |
+
'extend_table' => '',
|
1173 |
+
'extend_storage_taxonomy' => 'table',
|
1174 |
+
'extend_storage' => 'meta'
|
1175 |
+
);
|
1176 |
+
|
1177 |
+
$params = (object) array_merge( $defaults, (array) $params );
|
1178 |
+
|
1179 |
+
if ( empty( $params->create_extend ) || !in_array( $params->create_extend, array( 'create', 'extend' ) ) )
|
1180 |
+
return pods_error( __( 'Please choose whether to Create or Extend a Content Type', 'pods' ), $this );
|
1181 |
+
|
1182 |
+
$pod_params = array(
|
1183 |
+
'name' => '',
|
1184 |
+
'label' => '',
|
1185 |
+
'type' => '',
|
1186 |
+
'storage' => 'table',
|
1187 |
+
'object' => '',
|
1188 |
+
'options' => array()
|
1189 |
+
);
|
1190 |
+
|
1191 |
+
if ( 'create' == $params->create_extend ) {
|
1192 |
+
$label = ucwords( str_replace( '_', ' ', $params->create_name ) );
|
1193 |
+
|
1194 |
+
if ( !empty( $params->create_label_singular ) )
|
1195 |
+
$label = $params->create_label_singular;
|
1196 |
+
|
1197 |
+
$pod_params[ 'name' ] = $params->create_name;
|
1198 |
+
$pod_params[ 'label' ] = ( !empty( $params->create_label_plural ) ? $params->create_label_plural : $label );
|
1199 |
+
$pod_params[ 'type' ] = $params->create_pod_type;
|
1200 |
+
$pod_params[ 'options' ] = array(
|
1201 |
+
'label_singular' => ( !empty( $params->create_label_singular ) ? $params->create_label_singular : $pod_params[ 'label' ] ),
|
1202 |
+
'public' => 1,
|
1203 |
+
'show_ui' => 1
|
1204 |
+
);
|
1205 |
+
|
1206 |
+
// Auto-generate name if not provided
|
1207 |
+
if ( empty( $pod_params[ 'name' ] ) && !empty( $pod_params[ 'options' ][ 'label_singular' ] ) )
|
1208 |
+
$pod_params[ 'name' ] = pods_clean_name( $pod_params[ 'options' ][ 'label_singular' ] );
|
1209 |
+
|
1210 |
+
if ( 'post_type' == $pod_params[ 'type' ] ) {
|
1211 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
1212 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
1213 |
+
|
1214 |
+
$pod_params[ 'storage' ] = $params->create_storage;
|
1215 |
+
|
1216 |
+
if ( pods_tableless() )
|
1217 |
+
$pod_params[ 'storage' ] = 'meta';
|
1218 |
+
}
|
1219 |
+
elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
|
1220 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
1221 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
1222 |
+
|
1223 |
+
$pod_params[ 'storage' ] = $params->create_storage_taxonomy;
|
1224 |
+
|
1225 |
+
if ( pods_tableless() )
|
1226 |
+
$pod_params[ 'storage' ] = 'none';
|
1227 |
+
}
|
1228 |
+
elseif ( 'pod' == $pod_params[ 'type' ] ) {
|
1229 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
1230 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
1231 |
+
|
1232 |
+
if ( pods_tableless() ) {
|
1233 |
+
$pod_params[ 'type' ] = 'post_type';
|
1234 |
+
$pod_params[ 'storage' ] = 'meta';
|
1235 |
+
}
|
1236 |
+
}
|
1237 |
+
elseif ( 'settings' == $pod_params[ 'type' ] ) {
|
1238 |
+
$pod_params[ 'name' ] = $params->create_setting_name;
|
1239 |
+
$pod_params[ 'label' ] = ( !empty( $params->create_label_title ) ? $params->create_label_title : ucwords( str_replace( '_', ' ', $params->create_setting_name ) ) );
|
1240 |
+
$pod_params[ 'options' ] = array(
|
1241 |
+
'menu_name' => ( !empty( $params->create_label_menu ) ? $params->create_label_menu : $pod_params[ 'label' ] ),
|
1242 |
+
'menu_location' => $params->create_menu_location
|
1243 |
+
);
|
1244 |
+
$pod_params[ 'storage' ] = 'none';
|
1245 |
+
|
1246 |
+
// Auto-generate name if not provided
|
1247 |
+
if ( empty( $pod_params[ 'name' ] ) && !empty( $pod_params[ 'label' ] ) )
|
1248 |
+
$pod_params[ 'name' ] = pods_clean_name( $pod_params[ 'label' ] );
|
1249 |
+
|
1250 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
1251 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
1252 |
+
}
|
1253 |
+
}
|
1254 |
+
elseif ( 'extend' == $params->create_extend ) {
|
1255 |
+
$pod_params[ 'type' ] = $params->extend_pod_type;
|
1256 |
+
|
1257 |
+
if ( 'post_type' == $pod_params[ 'type' ] ) {
|
1258 |
+
$pod_params[ 'storage' ] = $params->extend_storage;
|
1259 |
+
|
1260 |
+
if ( pods_tableless() )
|
1261 |
+
$pod_params[ 'storage' ] = 'meta';
|
1262 |
+
|
1263 |
+
$pod_params[ 'name' ] = $params->extend_post_type;
|
1264 |
+
}
|
1265 |
+
elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
|
1266 |
+
$pod_params[ 'storage' ] = $params->extend_storage_taxonomy;
|
1267 |
+
|
1268 |
+
if ( pods_tableless() )
|
1269 |
+
$pod_params[ 'storage' ] = 'none';
|
1270 |
+
|
1271 |
+
$pod_params[ 'name' ] = $params->extend_taxonomy;
|
1272 |
+
}
|
1273 |
+
elseif ( 'table' == $pod_params[ 'type' ] ) {
|
1274 |
+
$pod_params[ 'storage' ] = 'table';
|
1275 |
+
$pod_params[ 'name' ] = $params->extend_table;
|
1276 |
+
}
|
1277 |
+
else {
|
1278 |
+
$pod_params[ 'storage' ] = $params->extend_storage;
|
1279 |
+
|
1280 |
+
if ( pods_tableless() )
|
1281 |
+
$pod_params[ 'storage' ] = 'meta';
|
1282 |
+
|
1283 |
+
$pod_params[ 'name' ] = $params->extend_pod_type;
|
1284 |
+
}
|
1285 |
+
|
1286 |
+
$pod_params[ 'label' ] = ucwords( str_replace( '_', ' ', $pod_params[ 'name' ] ) );
|
1287 |
+
$pod_params[ 'object' ] = $pod_params[ 'name' ];
|
1288 |
+
}
|
1289 |
+
|
1290 |
+
if ( empty( $pod_params[ 'object' ] ) ) {
|
1291 |
+
if ( 'post_type' == $pod_params[ 'type' ] ) {
|
1292 |
+
$check = get_post_type_object( $pod_params[ 'name' ] );
|
1293 |
+
|
1294 |
+
if ( !empty( $check ) )
|
1295 |
+
return pods_error( sprintf( __( 'Post Type %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
|
1296 |
+
|
1297 |
+
$pod_params[ 'options' ][ 'supports_title' ] = 1;
|
1298 |
+
$pod_params[ 'options' ][ 'supports_editor' ] = 1;
|
1299 |
+
}
|
1300 |
+
elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
|
1301 |
+
$check = get_taxonomy( $pod_params[ 'name' ] );
|
1302 |
+
|
1303 |
+
if ( !empty( $check ) )
|
1304 |
+
return pods_error( sprintf( __( 'Taxonomy %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
|
1305 |
+
}
|
1306 |
+
}
|
1307 |
+
|
1308 |
+
if ( !empty( $pod_params ) )
|
1309 |
+
return $this->save_pod( $pod_params );
|
1310 |
+
|
1311 |
+
return false;
|
1312 |
+
}
|
1313 |
+
|
1314 |
+
/**
|
1315 |
+
* Add or edit a Pod
|
1316 |
+
*
|
1317 |
+
* $params['id'] int The Pod ID
|
1318 |
+
* $params['name'] string The Pod name
|
1319 |
+
* $params['label'] string The Pod label
|
1320 |
+
* $params['type'] string The Pod type
|
1321 |
+
* $params['object'] string The object being extended (if any)
|
1322 |
+
* $params['storage'] string The Pod storage
|
1323 |
+
* $params['options'] array Options
|
1324 |
+
*
|
1325 |
+
* @param array $params An associative array of parameters
|
1326 |
+
* @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will sanitize them if false.
|
1327 |
+
* @param bool|int $db (optional) Whether to save into the DB or just return Pod array.
|
1328 |
+
*
|
1329 |
+
* @return int Pod ID
|
1330 |
+
* @since 1.7.9
|
1331 |
+
*/
|
1332 |
+
public function save_pod ( $params, $sanitized = false, $db = true ) {
|
1333 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
1334 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
1335 |
+
|
1336 |
+
$load_params = (object) $params;
|
1337 |
+
|
1338 |
+
if ( isset( $load_params->id ) && isset( $load_params->name ) )
|
1339 |
+
unset( $load_params->name );
|
1340 |
+
|
1341 |
+
if ( isset( $load_params->old_name ) )
|
1342 |
+
$load_params->name = $load_params->old_name;
|
1343 |
+
|
1344 |
+
$load_params->table_info = true;
|
1345 |
+
|
1346 |
+
$pod = $this->load_pod( $load_params, false );
|
1347 |
+
|
1348 |
+
$params = (object) $params;
|
1349 |
+
|
1350 |
+
if ( false === $sanitized )
|
1351 |
+
$params = pods_sanitize( $params );
|
1352 |
+
|
1353 |
+
$old_id = $old_name = $old_storage = null;
|
1354 |
+
|
1355 |
+
$old_fields = $old_options = array();
|
1356 |
+
|
1357 |
+
if ( isset( $params->name ) && ! isset( $params->object ) ) {
|
1358 |
+
$params->name = pods_clean_name( $params->name );
|
1359 |
+
}
|
1360 |
+
|
1361 |
+
if ( !empty( $pod ) ) {
|
1362 |
+
if ( isset( $params->id ) && 0 < $params->id )
|
1363 |
+
$old_id = $params->id;
|
1364 |
+
|
1365 |
+
$params->id = $pod[ 'id' ];
|
1366 |
+
|
1367 |
+
$old_name = $pod[ 'name' ];
|
1368 |
+
$old_storage = $pod[ 'storage' ];
|
1369 |
+
$old_fields = $pod[ 'fields' ];
|
1370 |
+
$old_options = $pod[ 'options' ];
|
1371 |
+
|
1372 |
+
if ( !isset( $params->name ) && empty( $params->name ) )
|
1373 |
+
$params->name = $pod[ 'name' ];
|
1374 |
+
|
1375 |
+
if ( $old_name != $params->name && false !== $this->pod_exists( array( 'name' => $params->name ) ) )
|
1376 |
+
return pods_error( sprintf( __( 'Pod %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
|
1377 |
+
|
1378 |
+
if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'user', 'comment', 'media' ) ) && in_array( $pod[ 'object' ], array( 'user', 'comment', 'media' ) ) )
|
1379 |
+
return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
|
1380 |
+
|
1381 |
+
if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && !empty( $pod[ 'object' ] ) && $pod[ 'object' ] == $old_name )
|
1382 |
+
return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
|
1383 |
+
|
1384 |
+
if ( $old_id != $params->id ) {
|
1385 |
+
if ( $params->type == $pod[ 'type' ] && isset( $params->object ) && $params->object == $pod[ 'object' ] )
|
1386 |
+
return pods_error( sprintf( __( 'Pod using %s already exists, you can not reuse an object across multiple pods', 'pods' ), $params->object ), $this );
|
1387 |
+
else
|
1388 |
+
return pods_error( sprintf( __( 'Pod %s already exists', 'pods' ), $params->name ), $this );
|
1389 |
+
}
|
1390 |
+
}
|
1391 |
+
elseif ( in_array( $params->name, array( 'order','orderby','post_type' ) ) && 'post_type' == pods_var( 'type', $params ) ) {
|
1392 |
+
return pods_error( sprintf( 'There are certain names that a Custom Post Types cannot be named and unfortunately, %s is one of them.', $params->name ), $this );
|
1393 |
+
}
|
1394 |
+
else {
|
1395 |
+
$pod = array(
|
1396 |
+
'id' => 0,
|
1397 |
+
'name' => $params->name,
|
1398 |
+
'label' => $params->name,
|
1399 |
+
'description' => '',
|
1400 |
+
'type' => 'pod',
|
1401 |
+
'storage' => 'table',
|
1402 |
+
'object' => '',
|
1403 |
+
'alias' => '',
|
1404 |
+
'options' => array(),
|
1405 |
+
'fields' => array()
|
1406 |
+
);
|
1407 |
+
}
|
1408 |
+
|
1409 |
+
// Blank out fields and options for AJAX calls (everything should be sent to it for a full overwrite)
|
1410 |
+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
1411 |
+
$pod[ 'fields' ] = array();
|
1412 |
+
$pod[ 'options' ] = array();
|
1413 |
+
}
|
1414 |
+
|
1415 |
+
// Setup options
|
1416 |
+
$options = get_object_vars( $params );
|
1417 |
+
|
1418 |
+
if ( isset( $options[ 'method' ] ) )
|
1419 |
+
unset( $options[ 'method' ] );
|
1420 |
+
|
1421 |
+
$options_ignore = array(
|
1422 |
+
'object_type',
|
1423 |
+
'object_name',
|
1424 |
+
'table',
|
1425 |
+
'meta_table',
|
1426 |
+
'pod_table',
|
1427 |
+
'field_id',
|
1428 |
+
'field_index',
|
1429 |
+
'field_slug',
|
1430 |
+
'field_type',
|
1431 |
+
'field_parent',
|
1432 |
+
'field_parent_select',
|
1433 |
+
'meta_field_id',
|
1434 |
+
'meta_field_index',
|
1435 |
+
'meta_field_value',
|
1436 |
+
'pod_field_id',
|
1437 |
+
'pod_field_index',
|
1438 |
+
'object_fields',
|
1439 |
+
'join',
|
1440 |
+
'where',
|
1441 |
+
'where_default',
|
1442 |
+
'orderby',
|
1443 |
+
'pod',
|
1444 |
+
'recurse',
|
1445 |
+
'table_info',
|
1446 |
+
'attributes',
|
1447 |
+
'group',
|
1448 |
+
'grouped',
|
1449 |
+
'developer_mode',
|
1450 |
+
'dependency',
|
1451 |
+
'depends-on',
|
1452 |
+
'excludes-on'
|
1453 |
+
);
|
1454 |
+
|
1455 |
+
foreach ( $options_ignore as $ignore ) {
|
1456 |
+
if ( isset( $options[ $ignore ] ) )
|
1457 |
+
unset( $options[ $ignore ] );
|
1458 |
+
}
|
1459 |
+
|
1460 |
+
$exclude = array(
|
1461 |
+
'id',
|
1462 |
+
'name',
|
1463 |
+
'label',
|
1464 |
+
'description',
|
1465 |
+
'type',
|
1466 |
+
'storage',
|
1467 |
+
'object',
|
1468 |
+
'alias',
|
1469 |
+
'options',
|
1470 |
+
'fields'
|
1471 |
+
);
|
1472 |
+
|
1473 |
+
foreach ( $exclude as $k => $exclude_field ) {
|
1474 |
+
$aliases = array( $exclude_field );
|
1475 |
+
|
1476 |
+
if ( is_array( $exclude_field ) ) {
|
1477 |
+
$aliases = array_merge( array( $k ), $exclude_field );
|
1478 |
+
$exclude_field = $k;
|
1479 |
+
}
|
1480 |
+
|
1481 |
+
foreach ( $aliases as $alias ) {
|
1482 |
+
if ( isset( $options[ $alias ] ) ) {
|
1483 |
+
$pod[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
1484 |
+
|
1485 |
+
unset( $options[ $alias ] );
|
1486 |
+
}
|
1487 |
+
}
|
1488 |
+
}
|
1489 |
+
|
1490 |
+
if ( pods_tableless() && !in_array( $pod[ 'type' ], array( 'settings', 'table' ) ) ) {
|
1491 |
+
if ( 'pod' == $pod[ 'type' ] )
|
1492 |
+
$pod[ 'type' ] = 'post_type';
|
1493 |
+
|
1494 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
1495 |
+
if ( 'taxonomy' == $pod[ 'type' ] )
|
1496 |
+
$pod[ 'storage' ] = 'none';
|
1497 |
+
else
|
1498 |
+
$pod[ 'storage' ] = 'meta';
|
1499 |
+
}
|
1500 |
+
}
|
1501 |
+
|
1502 |
+
$pod[ 'options' ][ 'type' ] = $pod[ 'type' ];
|
1503 |
+
$pod[ 'options' ][ 'storage' ] = $pod[ 'storage' ];
|
1504 |
+
$pod[ 'options' ][ 'object' ] = $pod[ 'object' ];
|
1505 |
+
$pod[ 'options' ][ 'alias' ] = $pod[ 'alias' ];
|
1506 |
+
|
1507 |
+
$pod[ 'options' ] = array_merge( $pod[ 'options' ], $options );
|
1508 |
+
|
1509 |
+
/**
|
1510 |
+
* @var WP_Query
|
1511 |
+
*/
|
1512 |
+
global $wp_query;
|
1513 |
+
|
1514 |
+
$reserved_query_vars = array(
|
1515 |
+
'post_type',
|
1516 |
+
'taxonomy',
|
1517 |
+
'output'
|
1518 |
+
);
|
1519 |
+
|
1520 |
+
if ( is_object( $wp_query ) ) {
|
1521 |
+
$reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
|
1522 |
+
}
|
1523 |
+
|
1524 |
+
if ( isset( $pod[ 'options' ][ 'query_var_string' ] ) ) {
|
1525 |
+
if ( in_array( $pod[ 'options' ][ 'query_var_string' ], $reserved_query_vars ) ) {
|
1526 |
+
$pod[ 'options' ][ 'query_var_string' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var_string' ];
|
1527 |
+
}
|
1528 |
+
}
|
1529 |
+
|
1530 |
+
if ( isset( $pod[ 'options' ][ 'query_var' ] ) ) {
|
1531 |
+
if ( in_array( $pod[ 'options' ][ 'query_var' ], $reserved_query_vars ) ) {
|
1532 |
+
$pod[ 'options' ][ 'query_var' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var' ];
|
1533 |
+
}
|
1534 |
+
}
|
1535 |
+
|
1536 |
+
if ( strlen( $pod[ 'label' ] ) < 1 )
|
1537 |
+
$pod[ 'label' ] = $pod[ 'name' ];
|
1538 |
+
|
1539 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
1540 |
+
// Max length for post types are 20 characters
|
1541 |
+
$pod[ 'name' ] = substr( $pod[ 'name' ], 0, 20 );
|
1542 |
+
}
|
1543 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
1544 |
+
// Max length for taxonomies are 32 characters
|
1545 |
+
$pod[ 'name' ] = substr( $pod[ 'name' ], 0, 32 );
|
1546 |
+
}
|
1547 |
+
|
1548 |
+
$params->id = $pod[ 'id' ];
|
1549 |
+
$params->name = $pod[ 'name' ];
|
1550 |
+
|
1551 |
+
if ( null !== $old_name && $old_name != $params->name && empty( $pod[ 'object' ] ) ) {
|
1552 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
1553 |
+
$check = get_post_type_object( $params->name );
|
1554 |
+
|
1555 |
+
if ( !empty( $check ) )
|
1556 |
+
return pods_error( sprintf( __( 'Post Type %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
|
1557 |
+
}
|
1558 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
1559 |
+
$check = get_taxonomy( $params->name );
|
1560 |
+
|
1561 |
+
if ( !empty( $check ) )
|
1562 |
+
return pods_error( sprintf( __( 'Taxonomy %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
|
1563 |
+
}
|
1564 |
+
}
|
1565 |
+
|
1566 |
+
$field_table_operation = true;
|
1567 |
+
|
1568 |
+
// Add new pod
|
1569 |
+
if ( empty( $params->id ) ) {
|
1570 |
+
if ( strlen( $params->name ) < 1 )
|
1571 |
+
return pods_error( __( 'Pod name cannot be empty', 'pods' ), $this );
|
1572 |
+
|
1573 |
+
$post_data = array(
|
1574 |
+
'post_name' => $pod[ 'name' ],
|
1575 |
+
'post_title' => $pod[ 'label' ],
|
1576 |
+
'post_content' => $pod[ 'description' ],
|
1577 |
+
'post_type' => '_pods_pod',
|
1578 |
+
'post_status' => 'publish'
|
1579 |
+
);
|
1580 |
+
|
1581 |
+
if ( 'pod' == $pod[ 'type' ] && ( !is_array( $pod[ 'fields' ] ) || empty( $pod[ 'fields' ] ) ) ) {
|
1582 |
+
$pod[ 'fields' ] = array();
|
1583 |
+
|
1584 |
+
$pod[ 'fields' ][ 'name' ] = array(
|
1585 |
+
'name' => 'name',
|
1586 |
+
'label' => 'Name',
|
1587 |
+
'type' => 'text',
|
1588 |
+
'options' => array(
|
1589 |
+
'required' => '1'
|
1590 |
+
)
|
1591 |
+
);
|
1592 |
+
|
1593 |
+
$pod[ 'fields' ][ 'created' ] = array(
|
1594 |
+
'name' => 'created',
|
1595 |
+
'label' => 'Date Created',
|
1596 |
+
'type' => 'datetime',
|
1597 |
+
'options' => array(
|
1598 |
+
'datetime_format' => 'ymd_slash',
|
1599 |
+
'datetime_time_type' => '12',
|
1600 |
+
'datetime_time_format' => 'h_mm_ss_A'
|
1601 |
+
)
|
1602 |
+
);
|
1603 |
+
|
1604 |
+
$pod[ 'fields' ][ 'modified' ] = array(
|
1605 |
+
'name' => 'modified',
|
1606 |
+
'label' => 'Date Modified',
|
1607 |
+
'type' => 'datetime',
|
1608 |
+
'options' => array(
|
1609 |
+
'datetime_format' => 'ymd_slash',
|
1610 |
+
'datetime_time_type' => '12',
|
1611 |
+
'datetime_time_format' => 'h_mm_ss_A'
|
1612 |
+
)
|
1613 |
+
);
|
1614 |
+
|
1615 |
+
$pod[ 'fields' ][ 'author' ] = array(
|
1616 |
+
'name' => 'author',
|
1617 |
+
'label' => 'Author',
|
1618 |
+
'type' => 'pick',
|
1619 |
+
'pick_object' => 'user',
|
1620 |
+
'options' => array(
|
1621 |
+
'pick_format_type' => 'single',
|
1622 |
+
'pick_format_single' => 'autocomplete',
|
1623 |
+
'default_value' => '{@user.ID}'
|
1624 |
+
)
|
1625 |
+
);
|
1626 |
+
|
1627 |
+
$pod[ 'fields' ][ 'permalink' ] = array(
|
1628 |
+
'name' => 'permalink',
|
1629 |
+
'label' => 'Permalink',
|
1630 |
+
'type' => 'slug',
|
1631 |
+
'description' => 'Leave blank to auto-generate from Name'
|
1632 |
+
);
|
1633 |
+
|
1634 |
+
if ( !isset( $pod[ 'options' ][ 'pod_index' ] ) )
|
1635 |
+
$pod[ 'options' ][ 'pod_index' ] = 'name';
|
1636 |
+
}
|
1637 |
+
|
1638 |
+
$pod = $this->do_hook( 'save_pod_default_pod', $pod, $params, $sanitized, $db );
|
1639 |
+
|
1640 |
+
$field_table_operation = false;
|
1641 |
+
}
|
1642 |
+
else {
|
1643 |
+
$post_data = array(
|
1644 |
+
'ID' => $pod[ 'id' ],
|
1645 |
+
'post_name' => $pod[ 'name' ],
|
1646 |
+
'post_title' => $pod[ 'label' ],
|
1647 |
+
'post_content' => $pod[ 'description' ],
|
1648 |
+
'post_status' => 'publish'
|
1649 |
+
);
|
1650 |
+
}
|
1651 |
+
|
1652 |
+
if ( true === $db ) {
|
1653 |
+
if ( !has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) )
|
1654 |
+
add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
|
1655 |
+
|
1656 |
+
$conflicted = false;
|
1657 |
+
|
1658 |
+
// Headway compatibility fix
|
1659 |
+
if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
|
1660 |
+
remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
1661 |
+
|
1662 |
+
$conflicted = true;
|
1663 |
+
}
|
1664 |
+
|
1665 |
+
$params->id = $this->save_wp_object( 'post', $post_data, $pod[ 'options' ], true, true );
|
1666 |
+
|
1667 |
+
if ( $conflicted )
|
1668 |
+
add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
1669 |
+
|
1670 |
+
if ( false === $params->id )
|
1671 |
+
return pods_error( __( 'Cannot save Pod', 'pods' ), $this );
|
1672 |
+
}
|
1673 |
+
elseif ( empty( $params->id ) )
|
1674 |
+
$params->id = (int) $db;
|
1675 |
+
|
1676 |
+
$pod[ 'id' ] = $params->id;
|
1677 |
+
|
1678 |
+
// Setup / update tables
|
1679 |
+
if ( 'table' != $pod[ 'type' ] && 'table' == $pod[ 'storage' ] && $old_storage != $pod[ 'storage' ] && $db ) {
|
1680 |
+
$definitions = array( "`id` BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY" );
|
1681 |
+
|
1682 |
+
$defined_fields = array();
|
1683 |
+
|
1684 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
1685 |
+
if ( !is_array( $field ) || !isset( $field[ 'name' ] ) || in_array( $field[ 'name' ], $defined_fields ) )
|
1686 |
+
continue;
|
1687 |
+
|
1688 |
+
$defined_fields[] = $field[ 'name' ];
|
1689 |
+
|
1690 |
+
if ( !in_array( $field[ 'type' ], $tableless_field_types ) || ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) ) {
|
1691 |
+
$definition = $this->get_field_definition( $field[ 'type' ], array_merge( $field, pods_var_raw( 'options', $field, array() ) ) );
|
1692 |
+
|
1693 |
+
if ( 0 < strlen( $definition ) )
|
1694 |
+
$definitions[] = "`{$field['name']}` " . $definition;
|
1695 |
+
}
|
1696 |
+
}
|
1697 |
+
|
1698 |
+
pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`" );
|
1699 |
+
|
1700 |
+
$result = pods_query( "CREATE TABLE `@wp_pods_{$params->name}` (" . implode( ', ', $definitions ) . ") DEFAULT CHARSET utf8", $this );
|
1701 |
+
|
1702 |
+
if ( empty( $result ) )
|
1703 |
+
return pods_error( __( 'Cannot add Database Table for Pod', 'pods' ), $this );
|
1704 |
+
|
1705 |
+
}
|
1706 |
+
elseif ( 'table' != $pod[ 'type' ] && 'table' == $pod[ 'storage' ] && $pod[ 'storage' ] == $old_storage && null !== $old_name && $old_name != $params->name && $db ) {
|
1707 |
+
$result = pods_query( "ALTER TABLE `@wp_pods_{$old_name}` RENAME `@wp_pods_{$params->name}`", $this );
|
1708 |
+
|
1709 |
+
if ( empty( $result ) )
|
1710 |
+
return pods_error( __( 'Cannot update Database Table for Pod', 'pods' ), $this );
|
1711 |
+
}
|
1712 |
+
|
1713 |
+
/**
|
1714 |
+
* @var $wpdb wpdb
|
1715 |
+
*/
|
1716 |
+
global $wpdb;
|
1717 |
+
|
1718 |
+
if ( null !== $old_name && $old_name != $params->name && $db ) {
|
1719 |
+
// Rename items in the DB pointed at the old WP Object names
|
1720 |
+
if ( 'post_type' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
|
1721 |
+
$this->rename_wp_object_type( 'post', $old_name, $params->name );
|
1722 |
+
}
|
1723 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
|
1724 |
+
$this->rename_wp_object_type( 'taxonomy', $old_name, $params->name );
|
1725 |
+
}
|
1726 |
+
elseif ( 'comment' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
|
1727 |
+
$this->rename_wp_object_type( 'comment', $old_name, $params->name );
|
1728 |
+
}
|
1729 |
+
elseif ( 'settings' == $pod[ 'type' ] ) {
|
1730 |
+
$this->rename_wp_object_type( 'settings', $old_name, $params->name );
|
1731 |
+
}
|
1732 |
+
|
1733 |
+
// Sync any related fields if the name has changed
|
1734 |
+
$fields = pods_query( "
|
1735 |
+
SELECT `p`.`ID`
|
1736 |
+
FROM `{$wpdb->posts}` AS `p`
|
1737 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
|
1738 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm2` ON `pm2`.`post_id` = `p`.`ID`
|
1739 |
+
WHERE
|
1740 |
+
`p`.`post_type` = '_pods_field'
|
1741 |
+
AND `pm`.`meta_key` = 'pick_object'
|
1742 |
+
AND (
|
1743 |
+
`pm`.`meta_value` = 'pod'
|
1744 |
+
OR `pm`.`meta_value` = '" . $pod[ 'type' ] . "'
|
1745 |
+
)
|
1746 |
+
AND `pm2`.`meta_key` = 'pick_val'
|
1747 |
+
AND `pm2`.`meta_value` = '{$old_name}'
|
1748 |
+
" );
|
1749 |
+
|
1750 |
+
if ( !empty( $fields ) ) {
|
1751 |
+
foreach ( $fields as $field ) {
|
1752 |
+
update_post_meta( $field->ID, 'pick_object', $pod[ 'type' ] );
|
1753 |
+
update_post_meta( $field->ID, 'pick_val', $params->name );
|
1754 |
+
}
|
1755 |
+
}
|
1756 |
+
|
1757 |
+
$fields = pods_query( "
|
1758 |
+
SELECT `p`.`ID`
|
1759 |
+
FROM `{$wpdb->posts}` AS `p`
|
1760 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
|
1761 |
+
WHERE
|
1762 |
+
`p`.`post_type` = '_pods_field'
|
1763 |
+
AND `pm`.`meta_key` = 'pick_object'
|
1764 |
+
AND (
|
1765 |
+
`pm`.`meta_value` = 'pod-{$old_name}'
|
1766 |
+
OR `pm`.`meta_value` = '" . $pod[ 'type' ] . "-{$old_name}'
|
1767 |
+
)
|
1768 |
+
" );
|
1769 |
+
|
1770 |
+
if ( !empty( $fields ) ) {
|
1771 |
+
foreach ( $fields as $field ) {
|
1772 |
+
update_post_meta( $field->ID, 'pick_object', $pod[ 'type' ] );
|
1773 |
+
update_post_meta( $field->ID, 'pick_val', $params->name );
|
1774 |
+
}
|
1775 |
+
}
|
1776 |
+
}
|
1777 |
+
|
1778 |
+
// Sync built-in options for post types and taxonomies
|
1779 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && empty( $pod[ 'object' ] ) && $db ) {
|
1780 |
+
// Build list of 'built_in' for later
|
1781 |
+
$built_in = array();
|
1782 |
+
|
1783 |
+
foreach ( $pod[ 'options' ] as $key => $val ) {
|
1784 |
+
if ( false === strpos( $key, 'built_in_' ) )
|
1785 |
+
continue;
|
1786 |
+
elseif ( false !== strpos( $key, 'built_in_post_types_' ) )
|
1787 |
+
$built_in_type = 'post_type';
|
1788 |
+
elseif ( false !== strpos( $key, 'built_in_taxonomies_' ) )
|
1789 |
+
$built_in_type = 'taxonomy';
|
1790 |
+
else
|
1791 |
+
continue;
|
1792 |
+
|
1793 |
+
if ( $built_in_type == $pod[ 'type' ] )
|
1794 |
+
continue;
|
1795 |
+
|
1796 |
+
if ( !isset( $built_in[ $built_in_type ] ) )
|
1797 |
+
$built_in[ $built_in_type ] = array();
|
1798 |
+
|
1799 |
+
$built_in_object = str_replace( array( 'built_in_post_types_', 'built_in_taxonomies_' ), '', $key );
|
1800 |
+
|
1801 |
+
$built_in[ $built_in_type ][ $built_in_object ] = (int) $val;
|
1802 |
+
}
|
1803 |
+
|
1804 |
+
$lookup_option = $lookup_built_in = false;
|
1805 |
+
|
1806 |
+
$lookup_name = $pod[ 'name' ];
|
1807 |
+
|
1808 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
1809 |
+
$lookup_option = 'built_in_post_types_' . $lookup_name;
|
1810 |
+
$lookup_built_in = 'taxonomy';
|
1811 |
+
}
|
1812 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
1813 |
+
$lookup_option = 'built_in_taxonomies_' . $lookup_name;
|
1814 |
+
$lookup_built_in = 'post_type';
|
1815 |
+
}
|
1816 |
+
|
1817 |
+
if ( !empty( $lookup_option ) && !empty( $lookup_built_in ) && isset( $built_in[ $lookup_built_in ] ) ) {
|
1818 |
+
foreach ( $built_in[ $lookup_built_in ] as $built_in_object => $val ) {
|
1819 |
+
$search_val = 1;
|
1820 |
+
|
1821 |
+
if ( 1 == $val )
|
1822 |
+
$search_val = 0;
|
1823 |
+
|
1824 |
+
$query = "SELECT p.ID FROM {$wpdb->posts} AS p
|
1825 |
+
LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.ID AND pm.meta_key = '{$lookup_option}'
|
1826 |
+
LEFT JOIN {$wpdb->postmeta} AS pm2 ON pm2.post_id = p.ID AND pm2.meta_key = 'type' AND pm2.meta_value = '{$lookup_built_in}'
|
1827 |
+
LEFT JOIN {$wpdb->postmeta} AS pm3 ON pm3.post_id = p.ID AND pm3.meta_key = 'object' AND pm3.meta_value = ''
|
1828 |
+
WHERE p.post_type = '_pods_pod' AND p.post_name = '{$built_in_object}'
|
1829 |
+
AND pm2.meta_id IS NOT NULL
|
1830 |
+
AND ( pm.meta_id IS NULL OR pm.meta_value = {$search_val} )";
|
1831 |
+
|
1832 |
+
$results = pods_query( $query );
|
1833 |
+
|
1834 |
+
if ( !empty( $results ) ) {
|
1835 |
+
foreach ( $results as $the_pod ) {
|
1836 |
+
delete_post_meta( $the_pod->ID, $lookup_option );
|
1837 |
+
|
1838 |
+
add_post_meta( $the_pod->ID, $lookup_option, $val );
|
1839 |
+
}
|
1840 |
+
}
|
1841 |
+
}
|
1842 |
+
}
|
1843 |
+
}
|
1844 |
+
|
1845 |
+
$saved = array();
|
1846 |
+
$errors = array();
|
1847 |
+
|
1848 |
+
$field_index_change = false;
|
1849 |
+
$field_index_id = 0;
|
1850 |
+
|
1851 |
+
$id_required = false;
|
1852 |
+
|
1853 |
+
$field_index = pods_var( 'pod_index', $pod[ 'options' ], 'id', null, true );
|
1854 |
+
|
1855 |
+
if ( 'pod' == $pod[ 'type' ] && !empty( $pod[ 'fields' ] ) && isset( $pod[ 'fields' ][ $field_index ] ) )
|
1856 |
+
$field_index_id = $pod[ 'fields' ][ $field_index ];
|
1857 |
+
|
1858 |
+
if ( isset( $params->fields ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
1859 |
+
$fields = array();
|
1860 |
+
|
1861 |
+
if ( isset( $params->fields ) ) {
|
1862 |
+
$params->fields = (array) $params->fields;
|
1863 |
+
|
1864 |
+
$weight = 0;
|
1865 |
+
|
1866 |
+
foreach ( $params->fields as $field ) {
|
1867 |
+
if ( !is_array( $field ) || !isset( $field[ 'name' ] ) )
|
1868 |
+
continue;
|
1869 |
+
|
1870 |
+
if ( !isset( $field[ 'weight' ] ) ) {
|
1871 |
+
$field[ 'weight' ] = $weight;
|
1872 |
+
|
1873 |
+
$weight++;
|
1874 |
+
}
|
1875 |
+
|
1876 |
+
$fields[ $field[ 'name' ] ] = $field;
|
1877 |
+
}
|
1878 |
+
}
|
1879 |
+
|
1880 |
+
$weight = 0;
|
1881 |
+
|
1882 |
+
$saved_field_ids = array();
|
1883 |
+
|
1884 |
+
foreach ( $pod[ 'fields' ] as $k => $field ) {
|
1885 |
+
if ( !empty( $old_id ) && ( !is_array( $field ) || !isset( $field[ 'name' ] ) || !isset( $fields[ $field[ 'name' ] ] ) ) ) {
|
1886 |
+
// Iterative change handling for setup-edit.php
|
1887 |
+
if ( !is_array( $field ) && isset( $old_fields[ $k ] ) )
|
1888 |
+
$saved[ $old_fields[ $k ][ 'name' ] ] = true;
|
1889 |
+
|
1890 |
+
continue;
|
1891 |
+
}
|
1892 |
+
|
1893 |
+
if ( !empty( $old_id ) )
|
1894 |
+
$field = array_merge( $field, $fields[ $field[ 'name' ] ] );
|
1895 |
+
|
1896 |
+
$field[ 'pod' ] = $pod;
|
1897 |
+
|
1898 |
+
if ( !isset( $field[ 'weight' ] ) ) {
|
1899 |
+
$field[ 'weight' ] = $weight;
|
1900 |
+
|
1901 |
+
$weight++;
|
1902 |
+
}
|
1903 |
+
|
1904 |
+
if ( 0 < $field_index_id && pods_var( 'id', $field ) == $field_index_id )
|
1905 |
+
$field_index_change = $field[ 'name' ];
|
1906 |
+
|
1907 |
+
if ( 0 < pods_var( 'id', $field ) )
|
1908 |
+
$id_required = true;
|
1909 |
+
|
1910 |
+
if ( $id_required )
|
1911 |
+
$field[ 'id_required' ] = true;
|
1912 |
+
|
1913 |
+
$field_data = $field;
|
1914 |
+
|
1915 |
+
$field = $this->save_field( $field_data, $field_table_operation, true, $db );
|
1916 |
+
|
1917 |
+
if ( true !== $db ) {
|
1918 |
+
$pod[ 'fields' ][ $k ] = $field;
|
1919 |
+
$saved_field_ids[] = $field[ 'id' ];
|
1920 |
+
}
|
1921 |
+
else {
|
1922 |
+
if ( !empty( $field ) && 0 < $field ) {
|
1923 |
+
$saved[ $field_data[ 'name' ] ] = true;
|
1924 |
+
$saved_field_ids[] = $field;
|
1925 |
+
}
|
1926 |
+
else
|
1927 |
+
$errors[] = sprintf( __( 'Cannot save the %s field', 'pods' ), $field_data[ 'name' ] );
|
1928 |
+
}
|
1929 |
+
}
|
1930 |
+
|
1931 |
+
if ( true === $db ) {
|
1932 |
+
foreach ( $old_fields as $field ) {
|
1933 |
+
if ( isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) || isset( $saved[ $field[ 'name' ] ] ) || in_array( $field[ 'id' ], $saved_field_ids ) )
|
1934 |
+
continue;
|
1935 |
+
|
1936 |
+
if ( $field[ 'id' ] == $field_index_id )
|
1937 |
+
$field_index_change = 'id';
|
1938 |
+
elseif ( $field[ 'name' ] == $field_index )
|
1939 |
+
$field_index_change = 'id';
|
1940 |
+
|
1941 |
+
$this->delete_field( array(
|
1942 |
+
'id' => (int) $field[ 'id' ],
|
1943 |
+
'name' => $field[ 'name' ],
|
1944 |
+
'pod' => $pod
|
1945 |
+
), $field_table_operation );
|
1946 |
+
}
|
1947 |
+
}
|
1948 |
+
|
1949 |
+
// Update field index if the name has changed or the field has been removed
|
1950 |
+
if ( false !== $field_index_change && true === $db )
|
1951 |
+
update_post_meta( $pod[ 'id' ], 'pod_index', $field_index_change );
|
1952 |
+
}
|
1953 |
+
|
1954 |
+
if ( !empty( $errors ) )
|
1955 |
+
return pods_error( $errors, $this );
|
1956 |
+
|
1957 |
+
$this->cache_flush_pods( $pod );
|
1958 |
+
|
1959 |
+
if ( 'post_type' == $pod[ 'type' ] )
|
1960 |
+
PodsMeta::$post_types[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
1961 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] )
|
1962 |
+
PodsMeta::$taxonomies[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
1963 |
+
elseif ( 'media' == $pod[ 'type' ] )
|
1964 |
+
PodsMeta::$media[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
1965 |
+
elseif ( 'user' == $pod[ 'type' ] )
|
1966 |
+
PodsMeta::$user[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
1967 |
+
elseif ( 'comment' == $pod[ 'type' ] )
|
1968 |
+
PodsMeta::$comment[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
1969 |
+
|
1970 |
+
// Register Post Types / Taxonomies post-registration from PodsInit
|
1971 |
+
if ( !empty( PodsInit::$content_types_registered ) && in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && empty( $pod[ 'object' ] ) ) {
|
1972 |
+
global $pods_init;
|
1973 |
+
|
1974 |
+
$pods_init->setup_content_types( true );
|
1975 |
+
}
|
1976 |
+
|
1977 |
+
if ( true === $db )
|
1978 |
+
return $pod[ 'id' ];
|
1979 |
+
else
|
1980 |
+
return $pod;
|
1981 |
+
}
|
1982 |
+
|
1983 |
+
/**
|
1984 |
+
* Add or edit a field within a Pod
|
1985 |
+
*
|
1986 |
+
* $params['id'] int Field ID (id OR pod_id+pod+name required)
|
1987 |
+
* $params['pod_id'] int Pod ID (id OR pod_id+pod+name required)
|
1988 |
+
* $params['pod'] string Pod name (id OR pod_id+pod+name required)
|
1989 |
+
* $params['name'] string Field name (id OR pod_id+pod+name required)
|
1990 |
+
* $params['label'] string (optional) Field label
|
1991 |
+
* $params['type'] string (optional) Field type (avatar, boolean, code, color, currency, date, datetime, email, file, number, paragraph, password, phone, pick, slug, text, time, website, wysiwyg)
|
1992 |
+
* $params['pick_object'] string (optional) Related Object (for relationships)
|
1993 |
+
* $params['pick_val'] string (optional) Related Object name (for relationships)
|
1994 |
+
* $params['sister_id'] int (optional) Related Field ID (for bidirectional relationships)
|
1995 |
+
* $params['weight'] int (optional) Order in which the field appears
|
1996 |
+
* $params['options'] array (optional) Options
|
1997 |
+
*
|
1998 |
+
* @param array $params An associative array of parameters
|
1999 |
+
* @param bool $table_operation (optional) Whether or not to handle table operations
|
2000 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
2001 |
+
* @param bool|int $db (optional) Whether to save into the DB or just return field array.
|
2002 |
+
*
|
2003 |
+
* @return int|array The field ID or field array (if !$db)
|
2004 |
+
* @since 1.7.9
|
2005 |
+
*/
|
2006 |
+
public function save_field ( $params, $table_operation = true, $sanitized = false, $db = true ) {
|
2007 |
+
/**
|
2008 |
+
* @var $wpdb wpdb
|
2009 |
+
*/
|
2010 |
+
global $wpdb;
|
2011 |
+
|
2012 |
+
if ( true !== $db )
|
2013 |
+
$table_operation = false;
|
2014 |
+
|
2015 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
2016 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
2017 |
+
|
2018 |
+
$params = (object) $params;
|
2019 |
+
|
2020 |
+
if ( false === $sanitized )
|
2021 |
+
$params = pods_sanitize( $params );
|
2022 |
+
|
2023 |
+
if ( isset( $params->pod_id ) )
|
2024 |
+
$params->pod_id = pods_absint( $params->pod_id );
|
2025 |
+
|
2026 |
+
if ( true !== $db )
|
2027 |
+
$params->pod_id = (int) $db;
|
2028 |
+
|
2029 |
+
$pod = null;
|
2030 |
+
$save_pod = false;
|
2031 |
+
$id_required = false;
|
2032 |
+
|
2033 |
+
if ( isset( $params->id_required ) ) {
|
2034 |
+
unset( $params->id_required );
|
2035 |
+
|
2036 |
+
$id_required = true;
|
2037 |
+
}
|
2038 |
+
|
2039 |
+
if ( ( !isset( $params->pod ) || empty( $params->pod ) ) && ( !isset( $params->pod_id ) || empty( $params->pod_id ) ) )
|
2040 |
+
return pods_error( __( 'Pod ID or name is required', 'pods' ), $this );
|
2041 |
+
|
2042 |
+
if ( isset( $params->pod ) && is_array( $params->pod ) ) {
|
2043 |
+
$pod = $params->pod;
|
2044 |
+
|
2045 |
+
$save_pod = true;
|
2046 |
+
}
|
2047 |
+
elseif ( ( !isset( $params->pod_id ) || empty( $params->pod_id ) ) && ( true === $db || 0 < $db ) )
|
2048 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
|
2049 |
+
elseif ( !isset( $params->pod ) && ( true === $db || 0 < $db ) )
|
2050 |
+
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'table_info' => true ) );
|
2051 |
+
elseif ( true === $db || 0 < $db )
|
2052 |
+
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
|
2053 |
+
|
2054 |
+
if ( empty( $pod ) && true === $db )
|
2055 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
2056 |
+
|
2057 |
+
$params->pod_id = $pod[ 'id' ];
|
2058 |
+
$params->pod = $pod[ 'name' ];
|
2059 |
+
$params->pod_data = $pod;
|
2060 |
+
|
2061 |
+
$params->name = pods_clean_name( $params->name, true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
|
2062 |
+
|
2063 |
+
if ( !isset( $params->id ) )
|
2064 |
+
$params->id = 0;
|
2065 |
+
|
2066 |
+
if ( empty( $params->name ) )
|
2067 |
+
return pods_error( 'Pod field name is required', $this );
|
2068 |
+
|
2069 |
+
$field = $this->load_field( $params );
|
2070 |
+
|
2071 |
+
unset( $params->pod_data );
|
2072 |
+
|
2073 |
+
$old_id = $old_name = $old_type = $old_definition = $old_simple = $old_options = $old_sister_id = null;
|
2074 |
+
|
2075 |
+
if ( !empty( $field ) ) {
|
2076 |
+
$old_id = pods_var( 'id', $field );
|
2077 |
+
$old_name = pods_clean_name( $field[ 'name' ], true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
|
2078 |
+
$old_type = $field[ 'type' ];
|
2079 |
+
$old_options = $field[ 'options' ];
|
2080 |
+
$old_sister_id = (int) pods_var( 'sister_id', $old_options, 0 );
|
2081 |
+
|
2082 |
+
$old_simple = ( 'pick' == $old_type && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
|
2083 |
+
|
2084 |
+
if ( isset( $params->name ) && !empty( $params->name ) )
|
2085 |
+
$field[ 'name' ] = $params->name;
|
2086 |
+
|
2087 |
+
if ( $old_name != $field[ 'name' ] && false !== $this->field_exists( $params ) )
|
2088 |
+
return pods_error( sprintf( __( 'Field %s already exists, you cannot rename %s to that', 'pods' ), $field[ 'name' ], $old_name ), $this );
|
2089 |
+
|
2090 |
+
if ( ( $id_required || !empty( $params->id ) ) && ( empty( $old_id ) || $old_id != $params->id ) )
|
2091 |
+
return pods_error( sprintf( __( 'Field %s already exists', 'pods' ), $field[ 'name' ] ), $this );
|
2092 |
+
|
2093 |
+
if ( empty( $params->id ) )
|
2094 |
+
$params->id = $old_id;
|
2095 |
+
|
2096 |
+
if ( !in_array( $old_type, $tableless_field_types ) || $old_simple ) {
|
2097 |
+
$definition = $this->get_field_definition( $old_type, array_merge( $field, $old_options ) );
|
2098 |
+
|
2099 |
+
if ( 0 < strlen( $definition ) )
|
2100 |
+
$old_definition = "`{$old_name}` " . $definition;
|
2101 |
+
}
|
2102 |
+
}
|
2103 |
+
else {
|
2104 |
+
$field = array(
|
2105 |
+
'id' => 0,
|
2106 |
+
'pod_id' => $params->pod_id,
|
2107 |
+
'name' => $params->name,
|
2108 |
+
'label' => $params->name,
|
2109 |
+
'description' => '',
|
2110 |
+
'type' => 'text',
|
2111 |
+
'pick_object' => '',
|
2112 |
+
'pick_val' => '',
|
2113 |
+
'sister_id' => '',
|
2114 |
+
'weight' => null,
|
2115 |
+
'options' => array()
|
2116 |
+
);
|
2117 |
+
}
|
2118 |
+
|
2119 |
+
// Setup options
|
2120 |
+
$options = get_object_vars( $params );
|
2121 |
+
|
2122 |
+
$options_ignore = array(
|
2123 |
+
'method',
|
2124 |
+
'table_info',
|
2125 |
+
'attributes',
|
2126 |
+
'group',
|
2127 |
+
'grouped',
|
2128 |
+
'developer_mode',
|
2129 |
+
'dependency',
|
2130 |
+
'depends-on',
|
2131 |
+
'excludes-on'
|
2132 |
+
);
|
2133 |
+
|
2134 |
+
foreach ( $options_ignore as $ignore ) {
|
2135 |
+
if ( isset( $options[ $ignore ] ) )
|
2136 |
+
unset( $options[ $ignore ] );
|
2137 |
+
}
|
2138 |
+
|
2139 |
+
if ( isset( $options[ 'method' ] ) )
|
2140 |
+
unset( $options[ 'method' ] );
|
2141 |
+
elseif ( isset( $options[ 'table_info' ] ) )
|
2142 |
+
unset( $options[ 'table_info' ] );
|
2143 |
+
|
2144 |
+
$exclude = array(
|
2145 |
+
'id',
|
2146 |
+
'pod_id',
|
2147 |
+
'pod',
|
2148 |
+
'name',
|
2149 |
+
'label',
|
2150 |
+
'description',
|
2151 |
+
'type',
|
2152 |
+
'pick_object',
|
2153 |
+
'pick_val',
|
2154 |
+
'sister_id',
|
2155 |
+
'weight',
|
2156 |
+
'options'
|
2157 |
+
);
|
2158 |
+
|
2159 |
+
foreach ( $exclude as $k => $exclude_field ) {
|
2160 |
+
$aliases = array( $exclude_field );
|
2161 |
+
|
2162 |
+
if ( is_array( $exclude_field ) ) {
|
2163 |
+
$aliases = array_merge( array( $k ), $exclude_field );
|
2164 |
+
$exclude_field = $k;
|
2165 |
+
}
|
2166 |
+
|
2167 |
+
foreach ( $aliases as $alias ) {
|
2168 |
+
if ( isset( $options[ $alias ] ) ) {
|
2169 |
+
$field[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
2170 |
+
|
2171 |
+
unset( $options[ $alias ] );
|
2172 |
+
}
|
2173 |
+
}
|
2174 |
+
}
|
2175 |
+
|
2176 |
+
if ( strlen( $field[ 'label' ] ) < 1 )
|
2177 |
+
$field[ 'label' ] = $field[ 'name' ];
|
2178 |
+
|
2179 |
+
$field[ 'options' ][ 'type' ] = $field[ 'type' ];
|
2180 |
+
|
2181 |
+
if ( in_array( $field[ 'options' ][ 'type' ], $tableless_field_types ) ) {
|
2182 |
+
// Clean up special drop-down in field editor and save out pick_val
|
2183 |
+
$field[ 'pick_object' ] = pods_var( 'pick_object', $field, '', null, true );
|
2184 |
+
|
2185 |
+
if ( 0 === strpos( $field[ 'pick_object' ], 'pod-' ) ) {
|
2186 |
+
$field[ 'pick_val' ] = pods_str_replace( 'pod-', '', $field[ 'pick_object' ], 1 );
|
2187 |
+
$field[ 'pick_object' ] = 'pod';
|
2188 |
+
}
|
2189 |
+
elseif ( 0 === strpos( $field[ 'pick_object' ], 'post_type-' ) ) {
|
2190 |
+
$field[ 'pick_val' ] = pods_str_replace( 'post_type-', '', $field[ 'pick_object' ], 1 );
|
2191 |
+
$field[ 'pick_object' ] = 'post_type';
|
2192 |
+
}
|
2193 |
+
elseif ( 0 === strpos( $field[ 'pick_object' ], 'taxonomy-' ) ) {
|
2194 |
+
$field[ 'pick_val' ] = pods_str_replace( 'taxonomy-', '', $field[ 'pick_object' ], 1 );
|
2195 |
+
$field[ 'pick_object' ] = 'taxonomy';
|
2196 |
+
}
|
2197 |
+
elseif ( 'table' == $field[ 'pick_object' ] && 0 < strlen( pods_var_raw( 'pick_table', $field[ 'options' ] ) ) ) {
|
2198 |
+
$field[ 'pick_val' ] = $field[ 'options' ][ 'pick_table' ];
|
2199 |
+
$field[ 'pick_object' ] = 'table';
|
2200 |
+
}
|
2201 |
+
elseif ( false === strpos( $field[ 'pick_object' ], '-' ) && !in_array( $field[ 'pick_object' ], array( 'pod', 'post_type', 'taxonomy' ) ) ) {
|
2202 |
+
$field[ 'pick_val' ] = '';
|
2203 |
+
}
|
2204 |
+
elseif ( 'custom-simple' == $field[ 'pick_object' ] ) {
|
2205 |
+
$field[ 'pick_val' ] = '';
|
2206 |
+
}
|
2207 |
+
|
2208 |
+
$field[ 'options' ][ 'pick_object' ] = $field[ 'pick_object' ];
|
2209 |
+
$field[ 'options' ][ 'pick_val' ] = $field[ 'pick_val' ];
|
2210 |
+
$field[ 'options' ][ 'sister_id' ] = pods_var( 'sister_id', $field );
|
2211 |
+
|
2212 |
+
unset( $field[ 'pick_object' ] );
|
2213 |
+
unset( $field[ 'pick_val' ] );
|
2214 |
+
|
2215 |
+
if ( isset( $field[ 'sister_id' ] ) )
|
2216 |
+
unset( $field[ 'sister_id' ] );
|
2217 |
+
}
|
2218 |
+
|
2219 |
+
$field[ 'options' ] = array_merge( $field[ 'options' ], $options );
|
2220 |
+
|
2221 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
|
2222 |
+
|
2223 |
+
if ( 0 < $old_id && defined( 'PODS_FIELD_STRICT' ) && !PODS_FIELD_STRICT )
|
2224 |
+
$params->id = $field[ 'id' ] = $old_id;
|
2225 |
+
|
2226 |
+
// Add new field
|
2227 |
+
if ( !isset( $params->id ) || empty( $params->id ) || empty( $field ) ) {
|
2228 |
+
if ( $table_operation && in_array( $field[ 'name' ], array( 'created', 'modified' ) ) && !in_array( $field[ 'type' ], array( 'date', 'datetime' ) ) && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
2229 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
2230 |
+
|
2231 |
+
if ( $table_operation && 'author' == $field[ 'name' ] && 'pick' != $field[ 'type' ] && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
2232 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
2233 |
+
|
2234 |
+
if ( in_array( $field[ 'name' ], array( 'id', 'ID' ) ) )
|
2235 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
2236 |
+
|
2237 |
+
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
2238 |
+
if ( $object_field == $field[ 'name' ] || in_array( $field[ 'name' ], $object_field_opt[ 'alias' ] ) )
|
2239 |
+
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name. Also consider what WordPress and Pods provide you built-in.', 'pods' ), $field[ 'name' ] ), $this );
|
2240 |
+
}
|
2241 |
+
|
2242 |
+
if ( in_array( $field[ 'name' ], array( 'rss' ) ) ) // Reserved post_name values that can't be used as field names
|
2243 |
+
$field[ 'name' ] .= '2';
|
2244 |
+
|
2245 |
+
if ( 'slug' == $field[ 'type' ] && true === $db ) {
|
2246 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy', 'user' ) ) )
|
2247 |
+
return pods_error( __( 'This pod already has an internal WordPress permalink field', 'pods' ), $this );
|
2248 |
+
|
2249 |
+
$slug_field = get_posts( array(
|
2250 |
+
'post_type' => '_pods_field',
|
2251 |
+
'orderby' => 'menu_order',
|
2252 |
+
'order' => 'ASC',
|
2253 |
+
'posts_per_page' => 1,
|
2254 |
+
'post_parent' => $field[ 'pod_id' ],
|
2255 |
+
'meta_query' => array(
|
2256 |
+
array(
|
2257 |
+
'key' => 'type',
|
2258 |
+
'value' => 'slug'
|
2259 |
+
)
|
2260 |
+
)
|
2261 |
+
) );
|
2262 |
+
|
2263 |
+
if ( !empty( $slug_field ) )
|
2264 |
+
return pods_error( __( 'This pod already has a permalink field', 'pods' ), $this );
|
2265 |
+
}
|
2266 |
+
|
2267 |
+
// Sink the new field to the bottom of the list
|
2268 |
+
if ( null === $field[ 'weight' ] ) {
|
2269 |
+
$field[ 'weight' ] = 0;
|
2270 |
+
|
2271 |
+
$bottom_most_field = get_posts( array(
|
2272 |
+
'post_type' => '_pods_field',
|
2273 |
+
'orderby' => 'menu_order',
|
2274 |
+
'order' => 'DESC',
|
2275 |
+
'posts_per_page' => 1,
|
2276 |
+
'post_parent' => $field[ 'pod_id' ]
|
2277 |
+
) );
|
2278 |
+
|
2279 |
+
if ( !empty( $bottom_most_field ) )
|
2280 |
+
$field[ 'weight' ] = pods_absint( $bottom_most_field[ 0 ]->menu_order ) + 1;
|
2281 |
+
}
|
2282 |
+
|
2283 |
+
$field[ 'weight' ] = pods_absint( $field[ 'weight' ] );
|
2284 |
+
|
2285 |
+
$post_data = array(
|
2286 |
+
'post_name' => $field[ 'name' ],
|
2287 |
+
'post_title' => $field[ 'label' ],
|
2288 |
+
'post_content' => $field[ 'description' ],
|
2289 |
+
'post_type' => '_pods_field',
|
2290 |
+
'post_parent' => $field[ 'pod_id' ],
|
2291 |
+
'post_status' => 'publish',
|
2292 |
+
'menu_order' => $field[ 'weight' ]
|
2293 |
+
);
|
2294 |
+
}
|
2295 |
+
else {
|
2296 |
+
if ( in_array( $field[ 'name' ], array( 'id', 'ID' ) ) ) {
|
2297 |
+
if ( null !== $old_name )
|
2298 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
2299 |
+
else
|
2300 |
+
return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field[ 'name' ] ), $this );
|
2301 |
+
}
|
2302 |
+
|
2303 |
+
if ( null !== $old_name && $field[ 'name' ] != $old_name && in_array( $field[ 'name' ], array( 'created', 'modified' ) ) && !in_array( $field[ 'type' ], array( 'date', 'datetime' ) ) && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
2304 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
2305 |
+
|
2306 |
+
if ( null !== $old_name && $field[ 'name' ] != $old_name && 'author' == $field[ 'name' ] && 'pick' != $field[ 'type' ] && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
2307 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
2308 |
+
|
2309 |
+
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
2310 |
+
if ( $object_field != $field[ 'name' ] && !in_array( $field[ 'name' ], $object_field_opt[ 'alias' ] ) )
|
2311 |
+
continue;
|
2312 |
+
|
2313 |
+
if ( null !== $old_name )
|
2314 |
+
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
2315 |
+
else
|
2316 |
+
return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field[ 'name' ] ), $this );
|
2317 |
+
}
|
2318 |
+
|
2319 |
+
$post_data = array(
|
2320 |
+
'ID' => $field[ 'id' ],
|
2321 |
+
'post_name' => $field[ 'name' ],
|
2322 |
+
'post_title' => $field[ 'label' ],
|
2323 |
+
'post_content' => $field[ 'description' ]
|
2324 |
+
);
|
2325 |
+
|
2326 |
+
if ( null !== $field[ 'weight' ] ) {
|
2327 |
+
$field[ 'weight' ] = pods_absint( $field[ 'weight' ] );
|
2328 |
+
|
2329 |
+
$post_data[ 'menu_order' ] = $field[ 'weight' ];
|
2330 |
+
}
|
2331 |
+
}
|
2332 |
+
|
2333 |
+
if ( true === $db ) {
|
2334 |
+
if ( !has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) )
|
2335 |
+
add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
|
2336 |
+
|
2337 |
+
$conflicted = false;
|
2338 |
+
|
2339 |
+
// Headway compatibility fix
|
2340 |
+
if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
|
2341 |
+
remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
2342 |
+
|
2343 |
+
$conflicted = true;
|
2344 |
+
}
|
2345 |
+
|
2346 |
+
$params->id = $this->save_wp_object( 'post', $post_data, $field[ 'options' ], true, true );
|
2347 |
+
|
2348 |
+
if ( $conflicted )
|
2349 |
+
add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
2350 |
+
|
2351 |
+
if ( false === $params->id )
|
2352 |
+
return pods_error( __( 'Cannot save Field', 'pods' ), $this );
|
2353 |
+
}
|
2354 |
+
else
|
2355 |
+
$params->id = $field[ 'name' ];
|
2356 |
+
|
2357 |
+
$field[ 'id' ] = $params->id;
|
2358 |
+
|
2359 |
+
$simple = ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field[ 'options' ] ), $simple_tableless_objects ) );
|
2360 |
+
|
2361 |
+
$definition = false;
|
2362 |
+
|
2363 |
+
if ( !in_array( $field[ 'type' ], $tableless_field_types ) || $simple ) {
|
2364 |
+
$field_definition = $this->get_field_definition( $field[ 'type' ], array_merge( $field, $field[ 'options' ] ) );
|
2365 |
+
|
2366 |
+
if ( 0 < strlen( $field_definition ) )
|
2367 |
+
$definition = '`' . $field[ 'name' ] . '` ' . $field_definition;
|
2368 |
+
}
|
2369 |
+
|
2370 |
+
$sister_id = (int) pods_var( 'sister_id', $field[ 'options' ], 0 );
|
2371 |
+
|
2372 |
+
if ( $table_operation && 'table' == $pod[ 'storage' ] && !pods_tableless() ) {
|
2373 |
+
if ( !empty( $old_id ) ) {
|
2374 |
+
if ( ( $field[ 'type' ] != $old_type || $old_simple != $simple ) && empty( $definition ) )
|
2375 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$old_name}`", false );
|
2376 |
+
elseif ( 0 < strlen( $definition ) ) {
|
2377 |
+
if ( $old_name != $field[ 'name' ] || $old_simple != $simple ) {
|
2378 |
+
$test = false;
|
2379 |
+
|
2380 |
+
if ( 0 < strlen( $old_definition ) )
|
2381 |
+
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
|
2382 |
+
|
2383 |
+
// If the old field doesn't exist, continue to add a new field
|
2384 |
+
if ( false === $test )
|
2385 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
|
2386 |
+
}
|
2387 |
+
elseif ( null !== $old_definition && $definition != $old_definition ) {
|
2388 |
+
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
|
2389 |
+
|
2390 |
+
// If the old field doesn't exist, continue to add a new field
|
2391 |
+
if ( false === $test )
|
2392 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
|
2393 |
+
}
|
2394 |
+
}
|
2395 |
+
}
|
2396 |
+
elseif ( 0 < strlen( $definition ) ) {
|
2397 |
+
$test = false;
|
2398 |
+
|
2399 |
+
if ( 0 < strlen( $old_definition ) )
|
2400 |
+
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `" . $field[ 'name' ] . "` {$definition}", false );
|
2401 |
+
|
2402 |
+
// If the old field doesn't exist, continue to add a new field
|
2403 |
+
if ( false === $test )
|
2404 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
|
2405 |
+
}
|
2406 |
+
}
|
2407 |
+
|
2408 |
+
if ( !empty( $old_id ) && 'meta' == $pod[ 'storage' ] && $old_name != $field[ 'name' ] && $pod[ 'meta_table' ] != $pod[ 'table' ] ) {
|
2409 |
+
$prepare = array(
|
2410 |
+
$field[ 'name' ],
|
2411 |
+
$old_name
|
2412 |
+
);
|
2413 |
+
|
2414 |
+
// Users don't have a type
|
2415 |
+
if ( !empty( $pod[ 'field_type' ] ) )
|
2416 |
+
$prepare[] = $pod[ 'name' ];
|
2417 |
+
|
2418 |
+
pods_query( "
|
2419 |
+
UPDATE `{$pod[ 'meta_table' ]}` AS `m`
|
2420 |
+
LEFT JOIN `{$pod[ 'table' ]}` AS `t`
|
2421 |
+
ON `t`.`{$pod[ 'field_id' ]}` = `m`.`{$pod[ 'meta_field_id' ]}`
|
2422 |
+
SET
|
2423 |
+
`m`.`{$pod[ 'meta_field_index' ]}` = %s
|
2424 |
+
WHERE
|
2425 |
+
`m`.`{$pod[ 'meta_field_index' ]}` = %s
|
2426 |
+
" . ( !empty( $pod[ 'field_type' ] ) ? " AND `t`.`{$pod[ 'field_type' ]}` = %s" : "" ),
|
2427 |
+
$prepare
|
2428 |
+
);
|
2429 |
+
}
|
2430 |
+
|
2431 |
+
if ( $field[ 'type' ] != $old_type && in_array( $old_type, $tableless_field_types ) ) {
|
2432 |
+
delete_post_meta( $old_sister_id, 'sister_id' );
|
2433 |
+
|
2434 |
+
if ( true === $db ) {
|
2435 |
+
pods_query( "
|
2436 |
+
DELETE pm
|
2437 |
+
FROM {$wpdb->postmeta} AS pm
|
2438 |
+
LEFT JOIN {$wpdb->posts} AS p
|
2439 |
+
ON p.post_type = '_pods_field'
|
2440 |
+
AND p.ID = pm.post_id
|
2441 |
+
WHERE
|
2442 |
+
p.ID IS NOT NULL
|
2443 |
+
AND pm.meta_key = 'sister_id'
|
2444 |
+
AND pm.meta_value = %d
|
2445 |
+
", array(
|
2446 |
+
$params->id
|
2447 |
+
)
|
2448 |
+
);
|
2449 |
+
|
2450 |
+
if ( !pods_tableless() ) {
|
2451 |
+
pods_query( "DELETE FROM @wp_podsrel WHERE `field_id` = {$params->id}", false );
|
2452 |
+
|
2453 |
+
pods_query( "
|
2454 |
+
UPDATE `@wp_podsrel`
|
2455 |
+
SET `related_field_id` = 0
|
2456 |
+
WHERE `field_id` = %d
|
2457 |
+
", array(
|
2458 |
+
$old_sister_id
|
2459 |
+
)
|
2460 |
+
);
|
2461 |
+
}
|
2462 |
+
}
|
2463 |
+
}
|
2464 |
+
elseif ( 0 < $sister_id ) {
|
2465 |
+
update_post_meta( $sister_id, 'sister_id', $params->id );
|
2466 |
+
|
2467 |
+
if ( true === $db && ( !pods_tableless() ) ) {
|
2468 |
+
pods_query( "
|
2469 |
+
UPDATE `@wp_podsrel`
|
2470 |
+
SET `related_field_id` = %d
|
2471 |
+
WHERE `field_id` = %d
|
2472 |
+
",
|
2473 |
+
array(
|
2474 |
+
$params->id,
|
2475 |
+
$sister_id
|
2476 |
+
)
|
2477 |
+
);
|
2478 |
+
}
|
2479 |
+
}
|
2480 |
+
elseif ( 0 < $old_sister_id ) {
|
2481 |
+
delete_post_meta( $old_sister_id, 'sister_id' );
|
2482 |
+
|
2483 |
+
if ( true === $db && ( !pods_tableless() ) ) {
|
2484 |
+
pods_query( "
|
2485 |
+
UPDATE `@wp_podsrel`
|
2486 |
+
SET `related_field_id` = 0
|
2487 |
+
WHERE `field_id` = %d
|
2488 |
+
", array(
|
2489 |
+
$old_sister_id
|
2490 |
+
)
|
2491 |
+
);
|
2492 |
+
}
|
2493 |
+
}
|
2494 |
+
|
2495 |
+
if ( !empty( $old_id ) && $old_name != $field[ 'name' ] && true === $db ) {
|
2496 |
+
pods_query( "
|
2497 |
+
UPDATE `@wp_postmeta`
|
2498 |
+
SET `meta_value` = %s
|
2499 |
+
WHERE
|
2500 |
+
`post_id` = %d
|
2501 |
+
AND `meta_key` = 'pod_index'
|
2502 |
+
AND `meta_value` = %s
|
2503 |
+
", array(
|
2504 |
+
$field[ 'name' ],
|
2505 |
+
$pod[ 'id' ],
|
2506 |
+
$old_name
|
2507 |
+
)
|
2508 |
+
);
|
2509 |
+
}
|
2510 |
+
|
2511 |
+
if ( !$save_pod )
|
2512 |
+
$this->cache_flush_pods( $pod );
|
2513 |
+
else {
|
2514 |
+
pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
2515 |
+
|
2516 |
+
if ( !empty( $old_id ) && $old_name != $field[ 'name' ] )
|
2517 |
+
pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $old_name );
|
2518 |
+
}
|
2519 |
+
|
2520 |
+
if ( true === $db )
|
2521 |
+
return $params->id;
|
2522 |
+
else
|
2523 |
+
return $field;
|
2524 |
+
}
|
2525 |
+
|
2526 |
+
/**
|
2527 |
+
* Fix Pod / Field post_name to ensure they are exactly as saved (allow multiple posts w/ same post_name)
|
2528 |
+
*
|
2529 |
+
* @param string $slug Unique slug value
|
2530 |
+
* @param int $post_ID Post ID
|
2531 |
+
* @param string $post_status Post Status
|
2532 |
+
* @param string $post_type Post Type
|
2533 |
+
* @param int $post_parent Post Parent ID
|
2534 |
+
* @param string $original_slug Original slug value
|
2535 |
+
*
|
2536 |
+
* @return string Final slug value
|
2537 |
+
*
|
2538 |
+
* @since 2.3.3
|
2539 |
+
*/
|
2540 |
+
public function save_slug_fix ( $slug, $post_ID, $post_status, $post_type, $post_parent = 0, $original_slug = null ) {
|
2541 |
+
if ( in_array( $post_type, array( '_pods_field', '_pods_pod' ) ) && false !== strpos( $slug, '-' ) )
|
2542 |
+
$slug = $original_slug;
|
2543 |
+
|
2544 |
+
return $slug;
|
2545 |
+
}
|
2546 |
+
|
2547 |
+
/**
|
2548 |
+
* Add or Edit a Pods Object
|
2549 |
+
*
|
2550 |
+
* $params['id'] int The Object ID
|
2551 |
+
* $params['name'] string The Object name
|
2552 |
+
* $params['type'] string The Object type
|
2553 |
+
* $params['options'] Associative array of Object options
|
2554 |
+
*
|
2555 |
+
* @param array|object $params An associative array of parameters
|
2556 |
+
* @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will sanitize them if false.
|
2557 |
+
*
|
2558 |
+
* @return int The Object ID
|
2559 |
+
* @since 2.0
|
2560 |
+
*/
|
2561 |
+
public function save_object ( $params, $sanitized = false ) {
|
2562 |
+
$params = (object) $params;
|
2563 |
+
|
2564 |
+
if ( false === $sanitized )
|
2565 |
+
$params = pods_sanitize( $params );
|
2566 |
+
|
2567 |
+
if ( !isset( $params->name ) || empty( $params->name ) )
|
2568 |
+
return pods_error( __( 'Name must be given to save an Object', 'pods' ), $this );
|
2569 |
+
|
2570 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
2571 |
+
return pods_error( __( 'Type must be given to save an Object', 'pods' ), $this );
|
2572 |
+
|
2573 |
+
$object = array(
|
2574 |
+
'id' => 0,
|
2575 |
+
'name' => $params->name,
|
2576 |
+
'type' => $params->type,
|
2577 |
+
'code' => '',
|
2578 |
+
'options' => array()
|
2579 |
+
);
|
2580 |
+
|
2581 |
+
// Setup options
|
2582 |
+
$options = get_object_vars( $params );
|
2583 |
+
|
2584 |
+
if ( isset( $options[ 'method' ] ) )
|
2585 |
+
unset( $options[ 'method' ] );
|
2586 |
+
|
2587 |
+
$exclude = array(
|
2588 |
+
'id',
|
2589 |
+
'name',
|
2590 |
+
'helper_type',
|
2591 |
+
'code',
|
2592 |
+
'options',
|
2593 |
+
'status'
|
2594 |
+
);
|
2595 |
+
|
2596 |
+
foreach ( $exclude as $k => $exclude_field ) {
|
2597 |
+
$aliases = array( $exclude_field );
|
2598 |
+
|
2599 |
+
if ( is_array( $exclude_field ) ) {
|
2600 |
+
$aliases = array_merge( array( $k ), $exclude_field );
|
2601 |
+
$exclude_field = $k;
|
2602 |
+
}
|
2603 |
+
|
2604 |
+
foreach ( $aliases as $alias ) {
|
2605 |
+
if ( isset( $options[ $alias ] ) ) {
|
2606 |
+
$object[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
2607 |
+
|
2608 |
+
unset( $options[ $alias ] );
|
2609 |
+
}
|
2610 |
+
}
|
2611 |
+
}
|
2612 |
+
|
2613 |
+
if ( 'helper' == $object[ 'type' ] )
|
2614 |
+
$object[ 'options' ][ 'helper_type' ] = $object[ 'helper_type' ];
|
2615 |
+
|
2616 |
+
if ( isset( $object[ 'options' ][ 'code' ] ) )
|
2617 |
+
unset( $object[ 'options' ][ 'code' ] );
|
2618 |
+
|
2619 |
+
$object[ 'options' ] = array_merge( $object[ 'options' ], $options );
|
2620 |
+
|
2621 |
+
$post_data = array(
|
2622 |
+
'post_name' => pods_clean_name( $object[ 'name' ], true),
|
2623 |
+
'post_title' => $object[ 'name' ],
|
2624 |
+
'post_content' => $object[ 'code' ],
|
2625 |
+
'post_type' => '_pods_' . $object[ 'type' ],
|
2626 |
+
'post_status' => 'publish'
|
2627 |
+
);
|
2628 |
+
|
2629 |
+
if ( !empty( $object[ 'id' ] ) )
|
2630 |
+
$post_data[ 'ID' ] = $object[ 'id' ];
|
2631 |
+
|
2632 |
+
if ( null !== pods_var( 'status', $object, null, null, true ) )
|
2633 |
+
$post_data[ 'post_status' ] = pods_var( 'status', $object, null, null, true );
|
2634 |
+
|
2635 |
+
remove_filter( 'content_save_pre', 'balanceTags', 50 );
|
2636 |
+
|
2637 |
+
$post_data = pods_sanitize( $post_data );
|
2638 |
+
|
2639 |
+
$params->id = $this->save_post( $post_data, $object[ 'options' ], true, true );
|
2640 |
+
|
2641 |
+
pods_transient_clear( 'pods_objects_' . $params->type );
|
2642 |
+
pods_transient_clear( 'pods_objects_' . $params->type . '_get' );
|
2643 |
+
|
2644 |
+
return $params->id;
|
2645 |
+
}
|
2646 |
+
|
2647 |
+
/**
|
2648 |
+
* @see PodsAPI::save_object
|
2649 |
+
*
|
2650 |
+
* Add or edit a Pod Template
|
2651 |
+
*
|
2652 |
+
* $params['id'] int The template ID
|
2653 |
+
* $params['name'] string The template name
|
2654 |
+
* $params['code'] string The template code
|
2655 |
+
*
|
2656 |
+
* @param array|object $params An associative array of parameters
|
2657 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
2658 |
+
*
|
2659 |
+
* @return int The Template ID
|
2660 |
+
*
|
2661 |
+
* @since 1.7.9
|
2662 |
+
*/
|
2663 |
+
public function save_template ( $params, $sanitized = false ) {
|
2664 |
+
$params = (object) $params;
|
2665 |
+
|
2666 |
+
$params->type = 'template';
|
2667 |
+
|
2668 |
+
return $this->save_object( $params, $sanitized );
|
2669 |
+
}
|
2670 |
+
|
2671 |
+
/**
|
2672 |
+
* @see PodsAPI::save_object
|
2673 |
+
*
|
2674 |
+
* Add or edit a Pod Page
|
2675 |
+
*
|
2676 |
+
* $params['id'] int The page ID
|
2677 |
+
* $params['name'] string The page URI
|
2678 |
+
* $params['code'] string The page code
|
2679 |
+
*
|
2680 |
+
* @param array|object $params An associative array of parameters
|
2681 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
2682 |
+
*
|
2683 |
+
* @return int The page ID
|
2684 |
+
* @since 1.7.9
|
2685 |
+
*/
|
2686 |
+
public function save_page ( $params, $sanitized = false ) {
|
2687 |
+
$params = (object) $params;
|
2688 |
+
|
2689 |
+
if ( !isset( $params->name ) ) {
|
2690 |
+
$params->name = $params->uri;
|
2691 |
+
unset( $params->uri );
|
2692 |
+
}
|
2693 |
+
|
2694 |
+
if ( isset( $params->phpcode ) ) {
|
2695 |
+
$params->code = $params->phpcode;
|
2696 |
+
unset( $params->phpcode );
|
2697 |
+
}
|
2698 |
+
|
2699 |
+
$params->name = trim( $params->name, '/' );
|
2700 |
+
$params->type = 'page';
|
2701 |
+
|
2702 |
+
return $this->save_object( $params, $sanitized );
|
2703 |
+
}
|
2704 |
+
|
2705 |
+
/**
|
2706 |
+
* @see PodsAPI::save_object
|
2707 |
+
*
|
2708 |
+
* Add or edit a Pod Helper
|
2709 |
+
*
|
2710 |
+
* $params['id'] int The helper ID
|
2711 |
+
* $params['name'] string The helper name
|
2712 |
+
* $params['helper_type'] string The helper type ("pre_save", "display", etc)
|
2713 |
+
* $params['code'] string The helper code
|
2714 |
+
*
|
2715 |
+
* @param array $params An associative array of parameters
|
2716 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
2717 |
+
*
|
2718 |
+
* @return int The helper ID
|
2719 |
+
* @since 1.7.9
|
2720 |
+
*/
|
2721 |
+
public function save_helper ( $params, $sanitized = false ) {
|
2722 |
+
$params = (object) $params;
|
2723 |
+
|
2724 |
+
if ( isset( $params->phpcode ) ) {
|
2725 |
+
$params->code = $params->phpcode;
|
2726 |
+
unset( $params->phpcode );
|
2727 |
+
}
|
2728 |
+
|
2729 |
+
if ( isset( $params->type ) ) {
|
2730 |
+
$params->helper_type = $params->type;
|
2731 |
+
unset( $params->type );
|
2732 |
+
}
|
2733 |
+
|
2734 |
+
$params->type = 'helper';
|
2735 |
+
|
2736 |
+
return $this->save_object( $params, $sanitized );
|
2737 |
+
}
|
2738 |
+
|
2739 |
+
/**
|
2740 |
+
* Add or edit a single pod item
|
2741 |
+
*
|
2742 |
+
* $params['pod'] string The Pod name (pod or pod_id is required)
|
2743 |
+
* $params['pod_id'] string The Pod ID (pod or pod_id is required)
|
2744 |
+
* $params['id'] int The item ID
|
2745 |
+
* $params['data'] array (optional) Associative array of field names + values
|
2746 |
+
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
2747 |
+
* $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via PodsAPI::get_changed_fields()
|
2748 |
+
*
|
2749 |
+
* @param array|object $params An associative array of parameters
|
2750 |
+
*
|
2751 |
+
* @return int The item ID
|
2752 |
+
*
|
2753 |
+
* @since 1.7.9
|
2754 |
+
*/
|
2755 |
+
public function save_pod_item ( $params ) {
|
2756 |
+
|
2757 |
+
global $wpdb;
|
2758 |
+
|
2759 |
+
$params = (object) pods_str_replace( '@wp_', '{prefix}', $params );
|
2760 |
+
|
2761 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
2762 |
+
$repeatable_field_types = PodsForm::repeatable_field_types();
|
2763 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
2764 |
+
|
2765 |
+
// @deprecated 2.0
|
2766 |
+
if ( isset( $params->datatype ) ) {
|
2767 |
+
pods_deprecated( '$params->pod instead of $params->datatype', '2.0' );
|
2768 |
+
|
2769 |
+
$params->pod = $params->datatype;
|
2770 |
+
|
2771 |
+
unset( $params->datatype );
|
2772 |
+
|
2773 |
+
if ( isset( $params->pod_id ) ) {
|
2774 |
+
pods_deprecated( '$params->id instead of $params->pod_id', '2.0' );
|
2775 |
+
|
2776 |
+
$params->id = $params->pod_id;
|
2777 |
+
|
2778 |
+
unset( $params->pod_id );
|
2779 |
+
}
|
2780 |
+
|
2781 |
+
if ( isset( $params->data ) && !empty( $params->data ) && is_array( $params->data ) ) {
|
2782 |
+
$check = current( $params->data );
|
2783 |
+
|
2784 |
+
if ( is_array( $check ) ) {
|
2785 |
+
pods_deprecated( 'PodsAPI::save_pod_items', '2.0' );
|
2786 |
+
|
2787 |
+
return $this->save_pod_items( $params, $params->data );
|
2788 |
+
}
|
2789 |
+
}
|
2790 |
+
}
|
2791 |
+
|
2792 |
+
// @deprecated 2.0
|
2793 |
+
if ( isset( $params->tbl_row_id ) ) {
|
2794 |
+
pods_deprecated( '$params->id instead of $params->tbl_row_id', '2.0' );
|
2795 |
+
|
2796 |
+
$params->id = $params->tbl_row_id;
|
2797 |
+
|
2798 |
+
unset( $params->tbl_row_id );
|
2799 |
+
}
|
2800 |
+
|
2801 |
+
// @deprecated 2.0
|
2802 |
+
if ( isset( $params->columns ) ) {
|
2803 |
+
pods_deprecated( '$params->data instead of $params->columns', '2.0' );
|
2804 |
+
|
2805 |
+
$params->data = $params->columns;
|
2806 |
+
|
2807 |
+
unset( $params->columns );
|
2808 |
+
}
|
2809 |
+
|
2810 |
+
if ( !isset( $params->pod ) )
|
2811 |
+
$params->pod = false;
|
2812 |
+
if ( isset( $params->pod_id ) )
|
2813 |
+
$params->pod_id = pods_absint( $params->pod_id );
|
2814 |
+
else
|
2815 |
+
$params->pod_id = 0;
|
2816 |
+
|
2817 |
+
if ( isset( $params->id ) )
|
2818 |
+
$params->id = pods_absint( $params->id );
|
2819 |
+
else
|
2820 |
+
$params->id = 0;
|
2821 |
+
|
2822 |
+
if ( !isset( $params->from ) )
|
2823 |
+
$params->from = 'save';
|
2824 |
+
|
2825 |
+
if ( !isset( $params->location ) )
|
2826 |
+
$params->location = null;
|
2827 |
+
|
2828 |
+
if ( !isset( $params->track_changed_fields ) )
|
2829 |
+
$params->track_changed_fields = false;
|
2830 |
+
|
2831 |
+
/**
|
2832 |
+
* Override $params['track_changed_fields']
|
2833 |
+
*
|
2834 |
+
* Use for globally setting field change tracking.
|
2835 |
+
*
|
2836 |
+
* @param bool
|
2837 |
+
*
|
2838 |
+
* @since 2.3.19
|
2839 |
+
*/
|
2840 |
+
$track_changed_fields = apply_filters( 'pods_api_save_pod_item_track_changed_fields_' . $params->pod, (boolean) $params->track_changed_fields, $params );
|
2841 |
+
$changed_fields = array();
|
2842 |
+
|
2843 |
+
if ( !isset( $params->clear_slug_cache ) ) {
|
2844 |
+
$params->clear_slug_cache = true;
|
2845 |
+
}
|
2846 |
+
|
2847 |
+
// Support for bulk edit
|
2848 |
+
if ( isset( $params->id ) && !empty( $params->id ) && is_array( $params->id ) ) {
|
2849 |
+
$ids = array();
|
2850 |
+
$new_params = $params;
|
2851 |
+
|
2852 |
+
foreach ( $params->id as $id ) {
|
2853 |
+
$new_params->id = $id;
|
2854 |
+
|
2855 |
+
$ids[] = $this->save_pod_item( $new_params );
|
2856 |
+
}
|
2857 |
+
|
2858 |
+
return $ids;
|
2859 |
+
}
|
2860 |
+
|
2861 |
+
// Allow Helpers to know what's going on, are we adding or saving?
|
2862 |
+
$is_new_item = false;
|
2863 |
+
|
2864 |
+
if ( empty( $params->id ) )
|
2865 |
+
$is_new_item = true;
|
2866 |
+
|
2867 |
+
if ( isset( $params->is_new_item ) )
|
2868 |
+
$is_new_item = (boolean) $params->is_new_item;
|
2869 |
+
|
2870 |
+
// Allow Helpers to bypass subsequent helpers in recursive save_pod_item calls
|
2871 |
+
$bypass_helpers = false;
|
2872 |
+
|
2873 |
+
if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers )
|
2874 |
+
$bypass_helpers = true;
|
2875 |
+
|
2876 |
+
// Allow Custom Fields not defined by Pods to be saved
|
2877 |
+
$allow_custom_fields = false;
|
2878 |
+
|
2879 |
+
if ( isset( $params->allow_custom_fields ) && false !== $params->allow_custom_fields )
|
2880 |
+
$allow_custom_fields = true;
|
2881 |
+
|
2882 |
+
// Get array of Pods
|
2883 |
+
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
|
2884 |
+
|
2885 |
+
if ( false === $pod )
|
2886 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
2887 |
+
|
2888 |
+
$params->pod = $pod[ 'name' ];
|
2889 |
+
$params->pod_id = $pod[ 'id' ];
|
2890 |
+
|
2891 |
+
if ( 'settings' == $pod[ 'type' ] )
|
2892 |
+
$params->id = $pod[ 'id' ];
|
2893 |
+
|
2894 |
+
$fields = $pod[ 'fields' ];
|
2895 |
+
|
2896 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
|
2897 |
+
|
2898 |
+
$fields_active = array();
|
2899 |
+
$custom_data = array();
|
2900 |
+
|
2901 |
+
// Find the active fields (loop through $params->data to retain order)
|
2902 |
+
if ( !empty( $params->data ) && is_array( $params->data ) ) {
|
2903 |
+
$custom_fields = array();
|
2904 |
+
|
2905 |
+
foreach ( $params->data as $field => $value ) {
|
2906 |
+
if ( isset( $object_fields[ $field ] ) ) {
|
2907 |
+
$object_fields[ $field ][ 'value' ] = $value;
|
2908 |
+
$fields_active[] = $field;
|
2909 |
+
}
|
2910 |
+
elseif ( isset( $fields[ $field ] ) ) {
|
2911 |
+
if ( 'save' == $params->from || true === PodsForm::permission( $fields[ $field ][ 'type' ], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
|
2912 |
+
$fields[ $field ][ 'value' ] = $value;
|
2913 |
+
$fields_active[] = $field;
|
2914 |
+
}
|
2915 |
+
elseif ( !pods_has_permissions( $fields[ $field ][ 'options' ] ) && pods_var( 'hidden', $fields[ $field ][ 'options' ], false ) ) {
|
2916 |
+
$fields[ $field ][ 'value' ] = $value;
|
2917 |
+
$fields_active[] = $field;
|
2918 |
+
}
|
2919 |
+
}
|
2920 |
+
else {
|
2921 |
+
$found = false;
|
2922 |
+
|
2923 |
+
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
2924 |
+
if ( in_array( $field, $object_field_opt[ 'alias' ] ) ) {
|
2925 |
+
$object_fields[ $object_field ][ 'value' ] = $value;
|
2926 |
+
$fields_active[] = $object_field;
|
2927 |
+
|
2928 |
+
$found = true;
|
2929 |
+
|
2930 |
+
break;
|
2931 |
+
}
|
2932 |
+
}
|
2933 |
+
|
2934 |
+
if ( $allow_custom_fields && !$found )
|
2935 |
+
$custom_fields[] = $field;
|
2936 |
+
}
|
2937 |
+
}
|
2938 |
+
|
2939 |
+
if ( $allow_custom_fields && !empty( $custom_fields ) ) {
|
2940 |
+
foreach ( $custom_fields as $field ) {
|
2941 |
+
$custom_data[ $field ] = $params->data[ $field ];
|
2942 |
+
}
|
2943 |
+
}
|
2944 |
+
|
2945 |
+
if ( $pod[ 'type' ] === 'taxonomy' && isset( $params->data ) && !empty( $params->data ) ) {
|
2946 |
+
$term_data = $params->data;
|
2947 |
+
}
|
2948 |
+
|
2949 |
+
unset( $params->data );
|
2950 |
+
}
|
2951 |
+
|
2952 |
+
if ( empty( $params->id ) && !in_array( 'created', $fields_active ) && isset( $fields[ 'created' ] ) && in_array( $fields[ 'created' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
|
2953 |
+
$fields[ 'created' ][ 'value' ] = current_time( 'mysql' );
|
2954 |
+
$fields_active[] = 'created';
|
2955 |
+
}
|
2956 |
+
|
2957 |
+
if ( !in_array( 'modified', $fields_active ) && isset( $fields[ 'modified' ] ) && in_array( $fields[ 'modified' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
|
2958 |
+
$fields[ 'modified' ][ 'value' ] = current_time( 'mysql' );
|
2959 |
+
$fields_active[] = 'modified';
|
2960 |
+
}
|
2961 |
+
|
2962 |
+
if ( in_array( $pod[ 'type' ], array( 'pod', 'table' ) ) && empty( $params->id ) && !empty( $pod[ 'pod_field_index' ] ) && in_array( $pod[ 'pod_field_index' ], $fields_active ) && !in_array( $pod[ 'pod_field_slug' ], $fields_active ) && isset( $fields[ $pod[ 'pod_field_slug' ] ] ) ) {
|
2963 |
+
$fields[ $pod[ 'pod_field_slug' ] ][ 'value' ] = ''; // this will get picked up by slug pre_save method
|
2964 |
+
$fields_active[] = $pod[ 'pod_field_slug' ];
|
2965 |
+
}
|
2966 |
+
|
2967 |
+
// Handle hidden fields
|
2968 |
+
if ( empty( $params->id ) ) {
|
2969 |
+
foreach ( $fields as $field => $field_data ) {
|
2970 |
+
if ( in_array( $field, $fields_active ) )
|
2971 |
+
continue;
|
2972 |
+
|
2973 |
+
if ( in_array( $params->from, array( 'save', 'process_form' ) ) || true === PodsForm::permission( $fields[ $field ][ 'type' ], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
|
2974 |
+
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
2975 |
+
|
2976 |
+
if ( null !== $value && '' !== $value && false !== $value ) {
|
2977 |
+
$fields[ $field ][ 'value' ] = $value;
|
2978 |
+
$fields_active[] = $field;
|
2979 |
+
}
|
2980 |
+
}
|
2981 |
+
}
|
2982 |
+
|
2983 |
+
// Set default field values for object fields
|
2984 |
+
if ( !empty( $object_fields ) ) {
|
2985 |
+
foreach ( $object_fields as $field => $field_data ) {
|
2986 |
+
if ( in_array( $field, $fields_active ) ) {
|
2987 |
+
continue;
|
2988 |
+
}
|
2989 |
+
elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
|
2990 |
+
continue;
|
2991 |
+
}
|
2992 |
+
|
2993 |
+
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
2994 |
+
|
2995 |
+
if ( null !== $value && '' !== $value && false !== $value ) {
|
2996 |
+
$object_fields[ $field ][ 'value' ] = $value;
|
2997 |
+
$fields_active[] = $field;
|
2998 |
+
}
|
2999 |
+
}
|
3000 |
+
}
|
3001 |
+
|
3002 |
+
// Set default field values for Pod fields
|
3003 |
+
foreach ( $fields as $field => $field_data ) {
|
3004 |
+
if ( in_array( $field, $fields_active ) ) {
|
3005 |
+
continue;
|
3006 |
+
}
|
3007 |
+
elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
|
3008 |
+
continue;
|
3009 |
+
}
|
3010 |
+
|
3011 |
+
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
3012 |
+
|
3013 |
+
if ( null !== $value && '' !== $value && false !== $value ) {
|
3014 |
+
$fields[ $field ][ 'value' ] = $value;
|
3015 |
+
$fields_active[] = $field;
|
3016 |
+
}
|
3017 |
+
}
|
3018 |
+
}
|
3019 |
+
|
3020 |
+
$columns =& $fields; // @deprecated 2.0
|
3021 |
+
$active_columns =& $fields_active; // @deprecated 2.0
|
3022 |
+
$params->tbl_row_id =& $params->id; // @deprecated 2.0
|
3023 |
+
|
3024 |
+
$pre_save_helpers = $post_save_helpers = array();
|
3025 |
+
|
3026 |
+
$pieces = array(
|
3027 |
+
'fields',
|
3028 |
+
'params',
|
3029 |
+
'pod',
|
3030 |
+
'fields_active',
|
3031 |
+
'object_fields',
|
3032 |
+
'custom_fields',
|
3033 |
+
'custom_data',
|
3034 |
+
'track_changed_fields',
|
3035 |
+
'changed_fields'
|
3036 |
+
);
|
3037 |
+
|
3038 |
+
if ( false === $bypass_helpers ) {
|
3039 |
+
// Plugin hooks
|
3040 |
+
$hooked = $this->do_hook( 'pre_save_pod_item', compact( $pieces ), $is_new_item, $params->id );
|
3041 |
+
|
3042 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
3043 |
+
extract( $hooked );
|
3044 |
+
|
3045 |
+
$hooked = $this->do_hook( "pre_save_pod_item_{$params->pod}", compact( $pieces ), $is_new_item, $params->id );
|
3046 |
+
|
3047 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
3048 |
+
extract( $hooked );
|
3049 |
+
|
3050 |
+
if ( $is_new_item ) {
|
3051 |
+
$hooked = $this->do_hook( 'pre_create_pod_item', compact( $pieces ) );
|
3052 |
+
|
3053 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
3054 |
+
extract( $hooked );
|
3055 |
+
|
3056 |
+
$hooked = $this->do_hook( "pre_create_pod_item_{$params->pod}", compact( $pieces ) );
|
3057 |
+
|
3058 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
3059 |
+
extract( $hooked );
|
3060 |
+
}
|
3061 |
+
else {
|
3062 |
+
$hooked = $this->do_hook( 'pre_edit_pod_item', compact( $pieces ), $params->id );
|
3063 |
+
|
3064 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
3065 |
+
extract( $hooked );
|
3066 |
+
|
3067 |
+
$hooked = $this->do_hook( "pre_edit_pod_item_{$params->pod}", compact( $pieces ), $params->id );
|
3068 |
+
|
3069 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
3070 |
+
extract( $hooked );
|
3071 |
+
}
|
3072 |
+
|
3073 |
+
// Call any pre-save helpers (if not bypassed)
|
3074 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
3075 |
+
if ( !empty( $pod[ 'options' ] ) && is_array( $pod[ 'options' ] ) ) {
|
3076 |
+
$helpers = array( 'pre_save_helpers', 'post_save_helpers' );
|
3077 |
+
|
3078 |
+
foreach ( $helpers as $helper ) {
|
3079 |
+
if ( isset( $pod[ 'options' ][ $helper ] ) && !empty( $pod[ 'options' ][ $helper ] ) )
|
3080 |
+
${$helper} = explode( ',', $pod[ 'options' ][ $helper ] );
|
3081 |
+
}
|
3082 |
+
}
|
3083 |
+
|
3084 |
+
if ( !empty( $pre_save_helpers ) ) {
|
3085 |
+
pods_deprecated( sprintf( __( 'Pre-save helpers are deprecated, use the action pods_pre_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
3086 |
+
|
3087 |
+
foreach ( $pre_save_helpers as $helper ) {
|
3088 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
3089 |
+
|
3090 |
+
if ( false !== $helper )
|
3091 |
+
eval( '?>' . $helper[ 'code' ] );
|
3092 |
+
}
|
3093 |
+
}
|
3094 |
+
}
|
3095 |
+
}
|
3096 |
+
|
3097 |
+
if ( $track_changed_fields ) {
|
3098 |
+
$changed_fields = $this->get_changed_fields( compact( $pieces ) );
|
3099 |
+
}
|
3100 |
+
|
3101 |
+
$table_data = $table_formats = $update_values = $rel_fields = $rel_field_ids = array();
|
3102 |
+
|
3103 |
+
$object_type = $pod[ 'type' ];
|
3104 |
+
|
3105 |
+
$object_ID = 'ID';
|
3106 |
+
|
3107 |
+
if ( 'comment' == $object_type )
|
3108 |
+
$object_ID = 'comment_ID';
|
3109 |
+
|
3110 |
+
$object_data = $object_meta = $post_term_data = array();
|
3111 |
+
|
3112 |
+
if ( 'settings' == $object_type )
|
3113 |
+
$object_data[ 'option_id' ] = $pod[ 'name' ];
|
3114 |
+
elseif ( !empty( $params->id ) )
|
3115 |
+
$object_data[ $object_ID ] = $params->id;
|
3116 |
+
|
3117 |
+
$fields_active = array_unique( $fields_active );
|
3118 |
+
|
3119 |
+
// Loop through each active field, validating and preparing the table data
|
3120 |
+
foreach ( $fields_active as $field ) {
|
3121 |
+
if ( isset( $object_fields[ $field ] ) )
|
3122 |
+
$field_data = $object_fields[ $field ];
|
3123 |
+
elseif ( isset( $fields[ $field ] ) )
|
3124 |
+
$field_data = $fields[ $field ];
|
3125 |
+
else
|
3126 |
+
continue;
|
3127 |
+
|
3128 |
+
$value = $field_data[ 'value' ];
|
3129 |
+
$type = $field_data[ 'type' ];
|
3130 |
+
$options = pods_var( 'options', $field_data, array() );
|
3131 |
+
|
3132 |
+
// WPML AJAX compatibility
|
3133 |
+
if ( is_admin() && isset( $_GET[ 'page' ] ) && false !== strpos( $_GET[ 'page' ], '/menu/languages.php' ) && isset( $_POST[ 'icl_ajx_action' ] ) && isset( $_POST[ '_icl_nonce' ] ) && wp_verify_nonce( $_POST[ '_icl_nonce' ], $_POST[ 'icl_ajx_action' ] . '_nonce' ) )
|
3134 |
+
$options[ 'unique' ] = $fields[ $field ][ 'options' ][ 'unique' ] = $options[ 'required' ] = $fields[ $field ][ 'options' ][ 'required' ] = 0;
|
3135 |
+
else {
|
3136 |
+
// Validate value
|
3137 |
+
$validate = $this->handle_field_validation( $value, $field, $object_fields, $fields, $pod, $params );
|
3138 |
+
|
3139 |
+
if ( false === $validate )
|
3140 |
+
$validate = sprintf( __( 'There was an issue validating the field %s', 'pods' ), $field_data[ 'label' ] );
|
3141 |
+
elseif ( true !== $validate )
|
3142 |
+
$validate = (array) $validate;
|
3143 |
+
|
3144 |
+
if ( !is_bool( $validate ) && !empty( $validate ) )
|
3145 |
+
return pods_error( $validate, $this );
|
3146 |
+
}
|
3147 |
+
|
3148 |
+
$value = PodsForm::pre_save( $field_data[ 'type' ], $value, $params->id, $field, array_merge( $field_data, $options ), array_merge( $fields, $object_fields ), $pod, $params );
|
3149 |
+
|
3150 |
+
$field_data[ 'value' ] = $value;
|
3151 |
+
|
3152 |
+
if ( isset( $object_fields[ $field ] ) ) {
|
3153 |
+
if ( 'taxonomy' == $object_fields[ $field ][ 'type' ] ) {
|
3154 |
+
$post_term_data[ $field ] = $value;
|
3155 |
+
}
|
3156 |
+
else {
|
3157 |
+
$object_data[ $field ] = $value;
|
3158 |
+
}
|
3159 |
+
}
|
3160 |
+
else {
|
3161 |
+
$simple = ( 'pick' == $type && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
3162 |
+
$simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field_data, $field, $fields, $pod, $params );
|
3163 |
+
|
3164 |
+
// Handle Simple Relationships
|
3165 |
+
if ( $simple ) {
|
3166 |
+
if ( !is_array( $value ) )
|
3167 |
+
$value = explode( ',', $value );
|
3168 |
+
|
3169 |
+
$pick_limit = (int) pods_var_raw( 'pick_limit', $options, 0 );
|
3170 |
+
|
3171 |
+
if ( 'single' == pods_var_raw( 'pick_format_type', $options ) )
|
3172 |
+
$pick_limit = 1;
|
3173 |
+
|
3174 |
+
if ( 'custom-simple' == pods_var( 'pick_object', $field_data ) ) {
|
3175 |
+
$custom = pods_var_raw( 'pick_custom', $options, '' );
|
3176 |
+
|
3177 |
+
$custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $field_data[ 'name' ], $value, array_merge( $field_data, $options ), $pod, $params->id );
|
3178 |
+
|
3179 |
+
if ( empty( $value ) || empty( $custom ) )
|
3180 |
+
$value = '';
|
3181 |
+
elseif ( !empty( $custom ) ) {
|
3182 |
+
if ( !is_array( $custom ) ) {
|
3183 |
+
$custom = explode( "\n", $custom );
|
3184 |
+
|
3185 |
+
$custom_values = array();
|
3186 |
+
|
3187 |
+
foreach ( $custom as $c => $cv ) {
|
3188 |
+
if ( 0 < strlen( $cv ) ) {
|
3189 |
+
$custom_label = explode( '|', $cv );
|
3190 |
+
|
3191 |
+
if ( !isset( $custom_label[ 1 ] ) )
|
3192 |
+
$custom_label[ 1 ] = $custom_label[ 0 ];
|
3193 |
+
|
3194 |
+
$custom_values[ $custom_label[ 0 ] ] = $custom_label[ 1 ];
|
3195 |
+
}
|
3196 |
+
}
|
3197 |
+
}
|
3198 |
+
else
|
3199 |
+
$custom_values = $custom;
|
3200 |
+
|
3201 |
+
$values = array();
|
3202 |
+
|
3203 |
+
foreach ( $value as $k => $v ) {
|
3204 |
+
$v = pods_unsanitize( $v );
|
3205 |
+
|
3206 |
+
if ( isset( $custom_values[ $v ] ) )
|
3207 |
+
$values[ $k ] = $v;
|
3208 |
+
}
|
3209 |
+
|
3210 |
+
$value = $values;
|
3211 |
+
}
|
3212 |
+
}
|
3213 |
+
|
3214 |
+
if ( 0 < $pick_limit && !empty( $value ) )
|
3215 |
+
$value = array_slice( $value, 0, $pick_limit );
|
3216 |
+
|
3217 |
+
// Don't save an empty array, just make it an empty string
|
3218 |
+
if ( empty( $value ) )
|
3219 |
+
$value = '';
|
3220 |
+
elseif ( is_array( $value ) ) {
|
3221 |
+
// If there's just one item, don't save as an array, save the string
|
3222 |
+
if ( 1 == $pick_limit || 1 == count( $value ) )
|
3223 |
+
$value = implode( '', $value );
|
3224 |
+
// If storage is set to table, json encode, otherwise WP will serialize automatically
|
3225 |
+
elseif ( 'table' == pods_var( 'storage', $pod ) )
|
3226 |
+
$value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
|
3227 |
+
}
|
3228 |
+
}
|
3229 |
+
|
3230 |
+
// Prepare all table / meta data
|
3231 |
+
if ( !in_array( $type, $tableless_field_types ) || $simple ) {
|
3232 |
+
if ( in_array( $type, $repeatable_field_types ) && 1 == pods_var( $type . '_repeatable', $field_data, 0 ) ) {
|
3233 |
+
// Don't save an empty array, just make it an empty string
|
3234 |
+
if ( empty( $value ) )
|
3235 |
+
$value = '';
|
3236 |
+
elseif ( is_array( $value ) ) {
|
3237 |
+
// If there's just one item, don't save as an array, save the string
|
3238 |
+
if ( 1 == count( $value ) )
|
3239 |
+
$value = implode( '', $value );
|
3240 |
+
// If storage is set to table, json encode, otherwise WP will serialize automatically
|
3241 |
+
elseif ( 'table' == pods_var( 'storage', $pod ) )
|
3242 |
+
$value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
|
3243 |
+
}
|
3244 |
+
}
|
3245 |
+
|
3246 |
+
$table_data[ $field ] = str_replace( array( '{prefix}', '@wp_' ), array( '{/prefix/}', '{prefix}' ), $value ); // Fix for pods_query
|
3247 |
+
$table_formats[] = PodsForm::prepare( $type, $options );
|
3248 |
+
|
3249 |
+
$object_meta[ $field ] = $value;
|
3250 |
+
}
|
3251 |
+
// Store relational field data to be looped through later
|
3252 |
+
else {
|
3253 |
+
// Convert values from a comma-separated string into an array
|
3254 |
+
if ( !is_array( $value ) )
|
3255 |
+
$value = explode( ',', $value );
|
3256 |
+
|
3257 |
+
$rel_fields[ $type ][ $field ] = $value;
|
3258 |
+
$rel_field_ids[] = $field_data[ 'id' ];
|
3259 |
+
}
|
3260 |
+
}
|
3261 |
+
}
|
3262 |
+
|
3263 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
3264 |
+
$post_type = $pod[ 'name' ];
|
3265 |
+
|
3266 |
+
if ( !empty( $pod[ 'object' ] ) )
|
3267 |
+
$post_type = $pod[ 'object' ];
|
3268 |
+
|
3269 |
+
$object_data[ 'post_type' ] = $post_type;
|
3270 |
+
}
|
3271 |
+
|
3272 |
+
if ( ( 'meta' == $pod[ 'storage' ] || 'settings' == $pod[ 'type' ] ) && !in_array( $pod[ 'type' ], array( 'taxonomy', 'pod', 'table', '' ) ) ) {
|
3273 |
+
if ( $allow_custom_fields && !empty( $custom_data ) )
|
3274 |
+
$object_meta = array_merge( $custom_data, $object_meta );
|
3275 |
+
|
3276 |
+
$fields_to_send = array_flip( array_keys( $object_meta ) );
|
3277 |
+
|
3278 |
+
foreach ( $fields_to_send as $field => $field_data ) {
|
3279 |
+
if ( isset( $object_fields[ $field ] ) ) {
|
3280 |
+
$field_data = $object_fields[ $field ];
|
3281 |
+
}
|
3282 |
+
elseif ( isset( $fields[ $field ] ) ) {
|
3283 |
+
$field_data = $fields[ $field ];
|
3284 |
+
}
|
3285 |
+
else {
|
3286 |
+
unset( $fields_to_send[ $field ] );
|
3287 |
+
}
|
3288 |
+
|
3289 |
+
$fields_to_send[ $field ] = $field_data;
|
3290 |
+
}
|
3291 |
+
|
3292 |
+
$params->id = $this->save_wp_object( $object_type, $object_data, $object_meta, false, true, $fields_to_send );
|
3293 |
+
|
3294 |
+
if ( !empty( $params->id ) && 'settings' == $object_type )
|
3295 |
+
$params->id = $pod[ 'id' ];
|
3296 |
+
}
|
3297 |
+
else {
|
3298 |
+
if ( !in_array( $pod[ 'type' ], array( 'taxonomy', 'pod', 'table', '' ) ) )
|
3299 |
+
$params->id = $this->save_wp_object( $object_type, $object_data, array(), false, true );
|
3300 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
3301 |
+
$term = pods_v( $object_fields[ 'name' ][ 'name' ], $object_data, '', null, true );
|
3302 |
+
if ( !isset( $term_data ) ) {
|
3303 |
+
$term_data = array ();
|
3304 |
+
}
|
3305 |
+
|
3306 |
+
if ( empty( $params->id ) || !empty( $term_data ) ) {
|
3307 |
+
$taxonomy = $pod[ 'name' ];
|
3308 |
+
|
3309 |
+
if ( !empty( $pod[ 'object' ] ) )
|
3310 |
+
$taxonomy = $pod[ 'object' ];
|
3311 |
+
|
3312 |
+
$params->id = $this->save_term( $params->id, $term, $taxonomy, $term_data, true );
|
3313 |
+
}
|
3314 |
+
}
|
3315 |
+
|
3316 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
3317 |
+
// Every row should have an id set here, otherwise Pods with nothing
|
3318 |
+
// but relationship fields won't get properly ID'd
|
3319 |
+
if ( empty( $params->id ) )
|
3320 |
+
$params->id = 0;
|
3321 |
+
|
3322 |
+
$table_data = array( 'id' => $params->id ) + $table_data;
|
3323 |
+
array_unshift( $table_formats, '%d' );
|
3324 |
+
|
3325 |
+
if ( !empty( $table_data ) ) {
|
3326 |
+
$sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );
|
3327 |
+
|
3328 |
+
$id = pods_query( $sql, 'Cannot add/save table row' );
|
3329 |
+
|
3330 |
+
if ( empty( $params->id ) )
|
3331 |
+
$params->id = $id;
|
3332 |
+
}
|
3333 |
+
}
|
3334 |
+
}
|
3335 |
+
|
3336 |
+
$params->id = (int) $params->id;
|
3337 |
+
|
3338 |
+
// Save terms for taxonomies associated to a post type
|
3339 |
+
if ( 0 < $params->id && 'post_type' == $pod[ 'type' ] && !empty( $post_term_data ) ) {
|
3340 |
+
foreach ( $post_term_data as $post_taxonomy => $post_terms ) {
|
3341 |
+
wp_set_object_terms( $params->id, $post_terms, $post_taxonomy );
|
3342 |
+
}
|
3343 |
+
}
|
3344 |
+
|
3345 |
+
$no_conflict = pods_no_conflict_check( $pod[ 'type' ] );
|
3346 |
+
|
3347 |
+
if ( !$no_conflict )
|
3348 |
+
pods_no_conflict_on( $pod[ 'type' ] );
|
3349 |
+
|
3350 |
+
// Save relationship / file data
|
3351 |
+
if ( !empty( $rel_fields ) ) {
|
3352 |
+
foreach ( $rel_fields as $type => $data ) {
|
3353 |
+
// Only handle tableless fields
|
3354 |
+
if ( !in_array( $type, $tableless_field_types ) ) {
|
3355 |
+
continue;
|
3356 |
+
}
|
3357 |
+
|
3358 |
+
foreach ( $data as $field => $values ) {
|
3359 |
+
$pick_val = pods_var( 'pick_val', $fields[ $field ] );
|
3360 |
+
|
3361 |
+
if ( 'table' == pods_var( 'pick_object', $fields[ $field ] ) ) {
|
3362 |
+
$pick_val = pods_var( 'pick_table', $fields[ $field ][ 'options' ], $pick_val, null, true );
|
3363 |
+
}
|
3364 |
+
|
3365 |
+
if ( '__current__' == $pick_val ) {
|
3366 |
+
if ( is_object( $pod ) ) {
|
3367 |
+
$pick_val = $pod->pod;
|
3368 |
+
}
|
3369 |
+
elseif ( is_array( $pod ) ) {
|
3370 |
+
$pick_val = $pod[ 'name' ];
|
3371 |
+
}
|
3372 |
+
elseif ( 0 < strlen( $pod ) ) {
|
3373 |
+
$pick_val = $pod;
|
3374 |
+
}
|
3375 |
+
}
|
3376 |
+
|
3377 |
+
$fields[ $field ][ 'options' ][ 'table_info' ] = pods_api()->get_table_info( pods_var( 'pick_object', $fields[ $field ] ), $pick_val, null, null, $fields[ $field ][ 'options' ] );
|
3378 |
+
|
3379 |
+
if ( isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && !empty( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
|
3380 |
+
$search_data = pods( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] );
|
3381 |
+
|
3382 |
+
$data_mode = 'pods';
|
3383 |
+
}
|
3384 |
+
else {
|
3385 |
+
$search_data = pods_data();
|
3386 |
+
$search_data->table( $fields[ $field ][ 'options' ][ 'table_info' ] );
|
3387 |
+
|
3388 |
+
$data_mode = 'data';
|
3389 |
+
}
|
3390 |
+
|
3391 |
+
$find_rel_params = array(
|
3392 |
+
'select' => "`t`.`{$search_data->field_id}`",
|
3393 |
+
'where' => "`t`.`{$search_data->field_slug}` = %s OR `t`.`{$search_data->field_index}` = %s",
|
3394 |
+
'limit' => 1,
|
3395 |
+
'pagination' => false,
|
3396 |
+
'search' => false
|
3397 |
+
);
|
3398 |
+
|
3399 |
+
if ( empty( $search_data->field_slug ) && !empty( $search_data->field_index ) ) {
|
3400 |
+
$find_rel_params[ 'where' ] = "`t`.`{$search_data->field_index}` = %s";
|
3401 |
+
}
|
3402 |
+
elseif ( empty( $search_data->field_slug ) && empty( $search_data->field_index ) ) {
|
3403 |
+
$find_rel_params = false;
|
3404 |
+
}
|
3405 |
+
|
3406 |
+
$related_limit = (int) pods_var_raw( $type . '_limit', $fields[ $field ][ 'options' ], 0 );
|
3407 |
+
|
3408 |
+
if ( 'single' == pods_var_raw( $type . '_format_type', $fields[ $field ][ 'options' ] ) ) {
|
3409 |
+
$related_limit = 1;
|
3410 |
+
}
|
3411 |
+
|
3412 |
+
// Enforce integers / unique values for IDs
|
3413 |
+
$value_ids = array();
|
3414 |
+
|
3415 |
+
$is_file_field = in_array( $type, PodsForm::file_field_types() );
|
3416 |
+
$is_taggable = ( in_array( $type, PodsForm::tableless_field_types() ) && 1 == pods_v( $type . '_taggable', $fields[ $field ][ 'options' ] ) );
|
3417 |
+
|
3418 |
+
// @todo Handle simple relationships eventually
|
3419 |
+
foreach ( $values as $v ) {
|
3420 |
+
if ( !empty( $v ) ) {
|
3421 |
+
if ( !is_array( $v ) ) {
|
3422 |
+
if ( !preg_match( '/[^0-9]/', $v ) ) {
|
3423 |
+
$v = (int) $v;
|
3424 |
+
}
|
3425 |
+
// File handling
|
3426 |
+
elseif ( $is_file_field ) {
|
3427 |
+
// Get ID from GUID
|
3428 |
+
$v = pods_image_id_from_field( $v );
|
3429 |
+
|
3430 |
+
// If file not found, add it
|
3431 |
+
if ( empty( $v ) ) {
|
3432 |
+
$v = pods_attachment_import( $v );
|
3433 |
+
}
|
3434 |
+
}
|
3435 |
+
// Reference by slug
|
3436 |
+
else {
|
3437 |
+
$v_data = false;
|
3438 |
+
|
3439 |
+
if ( false !== $find_rel_params ) {
|
3440 |
+
$rel_params = $find_rel_params;
|
3441 |
+
$rel_params[ 'where' ] = $wpdb->prepare( $rel_params[ 'where' ], array( $v, $v ) );
|
3442 |
+
|
3443 |
+
$search_data->select( $rel_params );
|
3444 |
+
|
3445 |
+
$v_data = $search_data->fetch( $v );
|
3446 |
+
}
|
3447 |
+
|
3448 |
+
if ( !empty( $v_data ) && isset( $v_data[ $search_data->field_id ] ) ) {
|
3449 |
+
$v = (int) $v_data[ $search_data->field_id ];
|
3450 |
+
}
|
3451 |
+
// Allow tagging for Pods objects
|
3452 |
+
elseif ( $is_taggable && 'pods' == $data_mode ) {
|
3453 |
+
$tag_data = array(
|
3454 |
+
$search_data->field_index => $v
|
3455 |
+
);
|
3456 |
+
|
3457 |
+
if ( 'post_type' == $search_data->pod_data[ 'type' ] ) {
|
3458 |
+
$tag_data[ 'post_status' ] = 'publish';
|
3459 |
+
}
|
3460 |
+
|
3461 |
+
/**
|
3462 |
+
* Filter for changing tag before adding new item.
|
3463 |
+
*
|
3464 |
+
* @param array $tag_data Fields for creating new item.
|
3465 |
+
* @param int $v Field ID of tag.
|
3466 |
+
* @param obj $search_data Search object for tag.
|
3467 |
+
* @param string $field Table info for field.
|
3468 |
+
* @param array $pieces Field array.
|
3469 |
+
*
|
3470 |
+
* @since 2.3.19
|
3471 |
+
*/
|
3472 |
+
$tag_data = apply_filters( 'pods_api_save_pod_item_taggable_data', $tag_data, $v, $search_data, $field, compact( $pieces ) );
|
3473 |
+
|
3474 |
+
// Save $v to a new item on related object
|
3475 |
+
$v = $search_data->add( $tag_data );
|
3476 |
+
|
3477 |
+
// @todo Support non-Pods for tagging
|
3478 |
+
}
|
3479 |
+
}
|
3480 |
+
}
|
3481 |
+
elseif ( $is_file_field && isset( $v[ 'id' ] ) ) {
|
3482 |
+
$v = (int) $v[ 'id' ];
|
3483 |
+
}
|
3484 |
+
else {
|
3485 |
+
continue;
|
3486 |
+
}
|
3487 |
+
|
3488 |
+
if ( !empty( $v ) && !in_array( $v, $value_ids ) ) {
|
3489 |
+
$value_ids[] = $v;
|
3490 |
+
}
|
3491 |
+
}
|
3492 |
+
}
|
3493 |
+
|
3494 |
+
$value_ids = array_unique( array_filter( $value_ids ) );
|
3495 |
+
|
3496 |
+
// Limit values
|
3497 |
+
if ( 0 < $related_limit && !empty( $value_ids ) )
|
3498 |
+
$value_ids = array_slice( $value_ids, 0, $related_limit );
|
3499 |
+
|
3500 |
+
// Get current values
|
3501 |
+
if ( 'pick' == $type && isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] ) && isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'current_ids' ] ) )
|
3502 |
+
$related_ids = PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'current_ids' ];
|
3503 |
+
else
|
3504 |
+
$related_ids = $this->lookup_related_items( $fields[ $field ][ 'id' ], $pod[ 'id' ], $params->id, $fields[ $field ], $pod );
|
3505 |
+
|
3506 |
+
// Get ids to remove
|
3507 |
+
$remove_ids = array_diff( $related_ids, $value_ids );
|
3508 |
+
|
3509 |
+
// Delete relationships
|
3510 |
+
if ( !empty( $remove_ids ) )
|
3511 |
+
$this->delete_relationships( $params->id, $remove_ids, $pod, $fields[ $field ] );
|
3512 |
+
|
3513 |
+
// Save relationships
|
3514 |
+
if ( !empty( $value_ids ) )
|
3515 |
+
$this->save_relationships( $params->id, $value_ids, $pod, $fields[ $field ] );
|
3516 |
+
|
3517 |
+
// Run save function for field type (where needed)
|
3518 |
+
PodsForm::save( $type, $values, $params->id, $field, array_merge( $fields[ $field ], $fields[ $field ][ 'options' ] ), array_merge( $fields, $object_fields ), $pod, $params );
|
3519 |
+
}
|
3520 |
+
|
3521 |
+
// Unset data no longer needed
|
3522 |
+
if ( 'pick' == $type ) {
|
3523 |
+
foreach ( $data as $field => $values ) {
|
3524 |
+
if ( isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] ) ) {
|
3525 |
+
unset( PodsField_Pick::$related_data[ PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'related_field' ][ 'id' ] ] );
|
3526 |
+
unset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] );
|
3527 |
+
}
|
3528 |
+
}
|
3529 |
+
}
|
3530 |
+
}
|
3531 |
+
}
|
3532 |
+
|
3533 |
+
if ( !$no_conflict )
|
3534 |
+
pods_no_conflict_off( $pod[ 'type' ] );
|
3535 |
+
|
3536 |
+
if ( false === $bypass_helpers ) {
|
3537 |
+
$pieces = compact( $pieces );
|
3538 |
+
|
3539 |
+
// Plugin hooks
|
3540 |
+
$this->do_hook( 'post_save_pod_item', $pieces, $is_new_item, $params->id );
|
3541 |
+
$this->do_hook( "post_save_pod_item_{$params->pod}", $pieces, $is_new_item, $params->id );
|
3542 |
+
|
3543 |
+
if ( $is_new_item ) {
|
3544 |
+
$this->do_hook( 'post_create_pod_item', $pieces, $params->id );
|
3545 |
+
$this->do_hook( "post_create_pod_item_{$params->pod}", $pieces, $params->id );
|
3546 |
+
}
|
3547 |
+
else {
|
3548 |
+
$this->do_hook( 'post_edit_pod_item', $pieces, $params->id );
|
3549 |
+
$this->do_hook( "post_edit_pod_item_{$params->pod}", $pieces, $params->id );
|
3550 |
+
}
|
3551 |
+
|
3552 |
+
// Call any post-save helpers (if not bypassed)
|
3553 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
3554 |
+
if ( !empty( $post_save_helpers ) ) {
|
3555 |
+
pods_deprecated( sprintf( __( 'Post-save helpers are deprecated, use the action pods_post_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
3556 |
+
|
3557 |
+
foreach ( $post_save_helpers as $helper ) {
|
3558 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
3559 |
+
|
3560 |
+
if ( false !== $helper && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) )
|
3561 |
+
eval( '?>' . $helper[ 'code' ] );
|
3562 |
+
}
|
3563 |
+
}
|
3564 |
+
}
|
3565 |
+
}
|
3566 |
+
|
3567 |
+
// Clear cache
|
3568 |
+
pods_cache_clear( $params->id, 'pods_items_' . $pod[ 'name' ] );
|
3569 |
+
|
3570 |
+
if ( $params->clear_slug_cache && !empty( $pod[ 'field_slug' ] ) ) {
|
3571 |
+
$slug = pods( $pod[ 'name' ], $params->id )->field( $pod[ 'field_slug' ] );
|
3572 |
+
|
3573 |
+
if ( 0 < strlen( $slug ) ) {
|
3574 |
+
pods_cache_clear( $slug, 'pods_items_' . $pod[ 'name' ] );
|
3575 |
+
}
|
3576 |
+
}
|
3577 |
+
|
3578 |
+
// Clear WP meta cache
|
3579 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy', 'user', 'comment' ) ) ) {
|
3580 |
+
$meta_type = $pod[ 'type' ];
|
3581 |
+
|
3582 |
+
if ( 'post_type' == $meta_type )
|
3583 |
+
$meta_type = 'post';
|
3584 |
+
|
3585 |
+
wp_cache_delete( $params->id, $meta_type . '_meta' );
|
3586 |
+
wp_cache_delete( $params->id, 'pods_' . $meta_type . '_meta' );
|
3587 |
+
}
|
3588 |
+
|
3589 |
+
// Success! Return the id
|
3590 |
+
return $params->id;
|
3591 |
+
|
3592 |
+
}
|
3593 |
+
|
3594 |
+
/**
|
3595 |
+
* @see PodsAPI::save_pod_item
|
3596 |
+
* Add multiple pod items
|
3597 |
+
*
|
3598 |
+
* $params['pod'] string The Pod name (pod or pod_id is required)
|
3599 |
+
* $params['pod_id'] string The Pod ID (pod or pod_id is required)
|
3600 |
+
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
3601 |
+
*
|
3602 |
+
* $data['id'] int The item ID (optional)
|
3603 |
+
* $data['data'] array An associative array of field names + values
|
3604 |
+
*
|
3605 |
+
* @param array|object $params An associative array of parameters, data excluded
|
3606 |
+
* @param array $data An associative array of pod ids and field names + values (arrays of field data)
|
3607 |
+
*
|
3608 |
+
* @return int The item ID
|
3609 |
+
* @since 2.0
|
3610 |
+
*/
|
3611 |
+
public function save_pod_items ( $params, $data ) {
|
3612 |
+
$params = (object) $params;
|
3613 |
+
|
3614 |
+
$ids = array();
|
3615 |
+
|
3616 |
+
foreach ( $data as $fields ) {
|
3617 |
+
$params->data = $fields;
|
3618 |
+
|
3619 |
+
if ( isset( $fields[ 'id' ] ) && isset( $fields[ 'data' ] ) ) {
|
3620 |
+
$params->id = $fields[ 'id' ];
|
3621 |
+
$params->data = $fields[ 'data' ];
|
3622 |
+
}
|
3623 |
+
|
3624 |
+
$ids[] = $this->save_pod_item( $params );
|
3625 |
+
}
|
3626 |
+
|
3627 |
+
return $ids;
|
3628 |
+
}
|
3629 |
+
|
3630 |
+
/**
|
3631 |
+
* Get the fields that have changed during a save
|
3632 |
+
*
|
3633 |
+
* @param array $pieces Pieces array from save_pod_item
|
3634 |
+
*
|
3635 |
+
* @return array Array of fields and values that have changed
|
3636 |
+
*/
|
3637 |
+
public function get_changed_fields( $pieces ) {
|
3638 |
+
|
3639 |
+
$fields = $pieces[ 'fields' ];
|
3640 |
+
$fields_active = $pieces[ 'fields_active' ];
|
3641 |
+
|
3642 |
+
$fields_changed = array();
|
3643 |
+
|
3644 |
+
if ( 0 < $pieces[ 'params' ]->id ) {
|
3645 |
+
$pod = pods( $pieces[ 'params' ]->pod, $pieces[ 'params' ]->id );
|
3646 |
+
|
3647 |
+
foreach ( $fields_active as $field ) {
|
3648 |
+
if ( isset( $fields[ $field ] ) && $pod->raw( $field ) != $fields[ $field ][ 'value' ] ) {
|
3649 |
+
$fields_changed[ $field ] = $fields[ $field ][ 'value' ];
|
3650 |
+
}
|
3651 |
+
}
|
3652 |
+
}
|
3653 |
+
|
3654 |
+
return $fields_changed;
|
3655 |
+
|
3656 |
+
}
|
3657 |
+
|
3658 |
+
/**
|
3659 |
+
* Save relationships
|
3660 |
+
*
|
3661 |
+
* @param int $id ID of item
|
3662 |
+
* @param int|array $related_id ID or IDs to save
|
3663 |
+
* @param array $pod Pod data
|
3664 |
+
* @param array $field Field data
|
3665 |
+
*/
|
3666 |
+
public function save_relationships ( $id, $related_ids, $pod, $field ) {
|
3667 |
+
// Get current values
|
3668 |
+
if ( 'pick' == $field[ 'type' ] && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ] ) && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'current_ids' ] ) )
|
3669 |
+
$current_ids = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'current_ids' ];
|
3670 |
+
else
|
3671 |
+
$current_ids = $this->lookup_related_items( $field[ 'id' ], $pod[ 'id' ], $id, $field, $pod );
|
3672 |
+
|
3673 |
+
if ( !is_array( $related_ids ) )
|
3674 |
+
$related_ids = implode( ',', $related_ids );
|
3675 |
+
|
3676 |
+
foreach ( $related_ids as $k => $related_id ) {
|
3677 |
+
$related_ids[ $k ] = (int) $related_id;
|
3678 |
+
}
|
3679 |
+
|
3680 |
+
$related_ids = array_unique( array_filter( $related_ids ) );
|
3681 |
+
|
3682 |
+
$related_limit = (int) pods_var_raw( $field[ 'type' ] . '_limit', $field[ 'options' ], 0 );
|
3683 |
+
|
3684 |
+
if ( 'single' == pods_var_raw( $field[ 'type' ] . '_format_type', $field[ 'options' ] ) )
|
3685 |
+
$related_limit = 1;
|
3686 |
+
|
3687 |
+
// Limit values
|
3688 |
+
if ( 0 < $related_limit && !empty( $related_ids ) )
|
3689 |
+
$related_ids = array_slice( $related_ids, 0, $related_limit );
|
3690 |
+
|
3691 |
+
// Post Types, Media, Users, and Comments (meta-based)
|
3692 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment' ) ) ) {
|
3693 |
+
$object_type = $pod[ 'type' ];
|
3694 |
+
|
3695 |
+
if ( 'post_type' == $object_type || 'media' == $object_type )
|
3696 |
+
$object_type = 'post';
|
3697 |
+
|
3698 |
+
delete_metadata( $object_type, $id, $field[ 'name' ] );
|
3699 |
+
|
3700 |
+
if ( !empty( $related_ids ) ) {
|
3701 |
+
update_metadata( $object_type, $id, '_pods_' . $field[ 'name' ], $related_ids );
|
3702 |
+
|
3703 |
+
foreach ( $related_ids as $related_id ) {
|
3704 |
+
add_metadata( $object_type, $id, $field[ 'name' ], $related_id );
|
3705 |
+
}
|
3706 |
+
}
|
3707 |
+
else
|
3708 |
+
delete_metadata( $object_type, $id, '_pods_' . $field[ 'name' ] );
|
3709 |
+
}
|
3710 |
+
// Custom Settings Pages (options-based)
|
3711 |
+
elseif ( 'settings' == $pod[ 'type' ] ) {
|
3712 |
+
if ( !empty( $related_ids ) )
|
3713 |
+
update_option( $pod[ 'name' ] . '_' . $field[ 'name' ], $related_ids );
|
3714 |
+
else
|
3715 |
+
delete_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
3716 |
+
}
|
3717 |
+
|
3718 |
+
$related_pod_id = $related_field_id = 0;
|
3719 |
+
|
3720 |
+
if ( 'pick' == $field[ 'type' ] && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ] ) && !empty( PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_field' ] ) ) {
|
3721 |
+
$related_pod_id = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_pod' ][ 'id' ];
|
3722 |
+
$related_field_id = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_field' ][ 'id' ];
|
3723 |
+
}
|
3724 |
+
|
3725 |
+
// Relationships table
|
3726 |
+
if ( !pods_tableless() ) {
|
3727 |
+
$related_weight = 0;
|
3728 |
+
|
3729 |
+
foreach ( $related_ids as $related_id ) {
|
3730 |
+
if ( in_array( $related_id, $current_ids ) ) {
|
3731 |
+
pods_query( "
|
3732 |
+
UPDATE `@wp_podsrel`
|
3733 |
+
SET
|
3734 |
+
`pod_id` = %d,
|
3735 |
+
`field_id` = %d,
|
3736 |
+
`item_id` = %d,
|
3737 |
+
`related_pod_id` = %d,
|
3738 |
+
`related_field_id` = %d,
|
3739 |
+
`related_item_id` = %d,
|
3740 |
+
`weight` = %d
|
3741 |
+
WHERE
|
3742 |
+
`pod_id` = %d
|
3743 |
+
AND `field_id` = %d
|
3744 |
+
AND `item_id` = %d
|
3745 |
+
AND `related_item_id` = %d
|
3746 |
+
", array(
|
3747 |
+
$pod[ 'id' ],
|
3748 |
+
$field[ 'id' ],
|
3749 |
+
$id,
|
3750 |
+
$related_pod_id,
|
3751 |
+
$related_field_id,
|
3752 |
+
$related_id,
|
3753 |
+
$related_weight,
|
3754 |
+
|
3755 |
+
$pod[ 'id' ],
|
3756 |
+
$field[ 'id' ],
|
3757 |
+
$id,
|
3758 |
+
$related_id,
|
3759 |
+
) );
|
3760 |
+
}
|
3761 |
+
else {
|
3762 |
+
pods_query( "
|
3763 |
+
INSERT INTO `@wp_podsrel`
|
3764 |
+
(
|
3765 |
+
`pod_id`,
|
3766 |
+
`field_id`,
|
3767 |
+
`item_id`,
|
3768 |
+
`related_pod_id`,
|
3769 |
+
`related_field_id`,
|
3770 |
+
`related_item_id`,
|
3771 |
+
`weight`
|
3772 |
+
)
|
3773 |
+
VALUES ( %d, %d, %d, %d, %d, %d, %d )
|
3774 |
+
", array(
|
3775 |
+
$pod[ 'id' ],
|
3776 |
+
$field[ 'id' ],
|
3777 |
+
$id,
|
3778 |
+
$related_pod_id,
|
3779 |
+
$related_field_id,
|
3780 |
+
$related_id,
|
3781 |
+
$related_weight
|
3782 |
+
) );
|
3783 |
+
}
|
3784 |
+
|
3785 |
+
$related_weight++;
|
3786 |
+
}
|
3787 |
+
}
|
3788 |
+
}
|
3789 |
+
|
3790 |
+
/**
|
3791 |
+
* Duplicate a Pod
|
3792 |
+
*
|
3793 |
+
* $params['id'] int The Pod ID
|
3794 |
+
* $params['name'] string The Pod name
|
3795 |
+
* $params['new_name'] string The new Pod name
|
3796 |
+
*
|
3797 |
+
* @param array $params An associative array of parameters
|
3798 |
+
* @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
|
3799 |
+
*
|
3800 |
+
* @return int New Pod ID
|
3801 |
+
* @since 2.3
|
3802 |
+
*/
|
3803 |
+
public function duplicate_pod ( $params, $strict = false ) {
|
3804 |
+
if ( !is_object( $params ) && !is_array( $params ) ) {
|
3805 |
+
if ( is_numeric( $params ) )
|
3806 |
+
$params = array( 'id' => $params );
|
3807 |
+
else
|
3808 |
+
$params = array( 'name' => $params );
|
3809 |
+
|
3810 |
+
$params = (object) pods_sanitize( $params );
|
3811 |
+
}
|
3812 |
+
else
|
3813 |
+
$params = (object) pods_sanitize( $params );
|
3814 |
+
|
3815 |
+
$params->table_info = false;
|
3816 |
+
|
3817 |
+
$pod = $this->load_pod( $params, $strict );
|
3818 |
+
|
3819 |
+
if ( empty( $pod ) ) {
|
3820 |
+
if ( false !== $strict )
|
3821 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
3822 |
+
|
3823 |
+
return false;
|
3824 |
+
}
|
3825 |
+
elseif ( in_array( $pod[ 'type' ], array( 'media', 'user', 'comment' ) ) ) {
|
3826 |
+
if ( false !== $strict )
|
3827 |
+
return pods_error( __( 'Pod not allowed to be duplicated', 'pods' ), $this );
|
3828 |
+
|
3829 |
+
return false;
|
3830 |
+
}
|
3831 |
+
elseif ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && 0 < strlen( $pod[ 'object' ] ) ) {
|
3832 |
+
$pod[ 'object' ] = '';
|
3833 |
+
}
|
3834 |
+
|
3835 |
+
unset( $pod[ 'id' ] );
|
3836 |
+
|
3837 |
+
if ( isset( $params->new_name ) )
|
3838 |
+
$pod[ 'name' ] = $params->new_name;
|
3839 |
+
|
3840 |
+
$try = 1;
|
3841 |
+
|
3842 |
+
$check_name = $pod[ 'name' ];
|
3843 |
+
$new_label = $pod[ 'label' ];
|
3844 |
+
|
3845 |
+
while ( $this->load_pod( array( 'name' => $check_name, 'table_info' => false ), false ) ) {
|
3846 |
+
$try++;
|
3847 |
+
|
3848 |
+
$check_name = $pod[ 'name' ] . $try;
|
3849 |
+
$new_label = $pod[ 'label' ] . $try;
|
3850 |
+
}
|
3851 |
+
|
3852 |
+
$pod[ 'name' ] = $check_name;
|
3853 |
+
$pod[ 'label' ] = $new_label;
|
3854 |
+
|
3855 |
+
foreach ( $pod[ 'fields' ] as $field => $field_data ) {
|
3856 |
+
unset( $pod[ 'fields' ][ $field ][ 'id' ] );
|
3857 |
+
}
|
3858 |
+
|
3859 |
+
return $this->save_pod( $pod );
|
3860 |
+
}
|
3861 |
+
|
3862 |
+
/**
|
3863 |
+
* Duplicate a Field
|
3864 |
+
*
|
3865 |
+
* $params['pod_id'] int The Pod ID
|
3866 |
+
* $params['pod'] string The Pod name
|
3867 |
+
* $params['id'] int The Field ID
|
3868 |
+
* $params['name'] string The Field name
|
3869 |
+
* $params['new_name'] string The new Field name
|
3870 |
+
*
|
3871 |
+
* @param array $params An associative array of parameters
|
3872 |
+
* @param bool $strict (optional) Makes sure a field exists, if it doesn't throws an error
|
3873 |
+
*
|
3874 |
+
* @return int New Field ID
|
3875 |
+
* @since 2.3.10
|
3876 |
+
*/
|
3877 |
+
public function duplicate_field( $params, $strict = false ) {
|
3878 |
+
|
3879 |
+
if ( !is_object( $params ) && !is_array( $params ) ) {
|
3880 |
+
if ( is_numeric( $params ) ) {
|
3881 |
+
$params = array( 'id' => $params );
|
3882 |
+
}
|
3883 |
+
else {
|
3884 |
+
$params = array( 'name' => $params );
|
3885 |
+
}
|
3886 |
+
}
|
3887 |
+
|
3888 |
+
$params = (object) pods_sanitize( $params );
|
3889 |
+
|
3890 |
+
$params->table_info = false;
|
3891 |
+
|
3892 |
+
$field = $this->load_field( $params, $strict );
|
3893 |
+
|
3894 |
+
if ( empty( $field ) ) {
|
3895 |
+
if ( false !== $strict ) {
|
3896 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
3897 |
+
}
|
3898 |
+
|
3899 |
+
return false;
|
3900 |
+
}
|
3901 |
+
|
3902 |
+
unset( $field[ 'id' ] );
|
3903 |
+
|
3904 |
+
if ( isset( $params->new_name ) ) {
|
3905 |
+
$field[ 'name' ] = $params->new_name;
|
3906 |
+
}
|
3907 |
+
|
3908 |
+
$try = 1;
|
3909 |
+
|
3910 |
+
$check_name = $field[ 'name' ];
|
3911 |
+
$new_label = $field[ 'label' ];
|
3912 |
+
|
3913 |
+
while ( $this->load_field( array( 'pod_id' => $field[ 'pod_id' ], 'name' => $check_name, 'table_info' => false ), false ) ) {
|
3914 |
+
$try++;
|
3915 |
+
|
3916 |
+
$check_name = $field[ 'name' ] . $try;
|
3917 |
+
$new_label = $field[ 'label' ] . $try;
|
3918 |
+
}
|
3919 |
+
|
3920 |
+
$field[ 'name' ] = $check_name;
|
3921 |
+
$field[ 'label' ] = $new_label;
|
3922 |
+
|
3923 |
+
return $this->save_field( $field );
|
3924 |
+
|
3925 |
+
}
|
3926 |
+
|
3927 |
+
/**
|
3928 |
+
* @see PodsAPI::save_pod_item
|
3929 |
+
*
|
3930 |
+
* Duplicate a pod item
|
3931 |
+
*
|
3932 |
+
* $params['pod'] string The Pod name
|
3933 |
+
* $params['id'] int The item's ID from the wp_pods_* table
|
3934 |
+
*
|
3935 |
+
* @param array $params An associative array of parameters
|
3936 |
+
*
|
3937 |
+
* @return int The table row ID
|
3938 |
+
* @since 1.12
|
3939 |
+
*/
|
3940 |
+
public function duplicate_pod_item ( $params ) {
|
3941 |
+
$params = (object) pods_sanitize( $params );
|
3942 |
+
|
3943 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => false ) );
|
3944 |
+
|
3945 |
+
if ( false === $pod )
|
3946 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
3947 |
+
|
3948 |
+
$pod = pods( $params->pod, $params->id );
|
3949 |
+
|
3950 |
+
$params->pod = $pod->pod;
|
3951 |
+
$params->pod_id = $pod->pod_id;
|
3952 |
+
|
3953 |
+
$fields = (array) pods_var_raw( 'fields', $pod->pod_data, array(), null, true );
|
3954 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
|
3955 |
+
|
3956 |
+
if ( !empty( $object_fields ) )
|
3957 |
+
$fields = array_merge( $object_fields, $fields );
|
3958 |
+
|
3959 |
+
$save_params = array(
|
3960 |
+
'pod' => $params->pod,
|
3961 |
+
'data' => array()
|
3962 |
+
);
|
3963 |
+
|
3964 |
+
foreach ( $fields as $field ) {
|
3965 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'ids' ) );
|
3966 |
+
|
3967 |
+
if ( !empty( $value ) || ( !is_array( $value ) && 0 < strlen( $value ) ) )
|
3968 |
+
$save_params[ 'data' ][ $field[ 'name' ] ] = $value;
|
3969 |
+
}
|
3970 |
+
|
3971 |
+
$save_params = $this->do_hook( 'duplicate_pod_item', $save_params, $pod->pod, $pod->id(), $params );
|
3972 |
+
|
3973 |
+
$id = $this->save_pod_item( $save_params );
|
3974 |
+
|
3975 |
+
return $id;
|
3976 |
+
}
|
3977 |
+
|
3978 |
+
/**
|
3979 |
+
* @see pods()
|
3980 |
+
*
|
3981 |
+
* Export a pod item
|
3982 |
+
*
|
3983 |
+
* $params['pod'] string The Pod name
|
3984 |
+
* $params['id'] int The item's ID from the wp_pods_* table
|
3985 |
+
* $params['fields'] array The fields to export
|
3986 |
+
* $params['depth'] int How many levels deep to export data
|
3987 |
+
*
|
3988 |
+
* @param array $params An associative array of parameters
|
3989 |
+
* @param object $pod (optional) Pods object
|
3990 |
+
*
|
3991 |
+
* @return int The table row ID
|
3992 |
+
* @since 1.12
|
3993 |
+
*/
|
3994 |
+
public function export_pod_item ( $params, $pod = null ) {
|
3995 |
+
if ( !is_object( $pod ) || 'Pods' != get_class( $pod ) ) {
|
3996 |
+
if ( empty( $params ) )
|
3997 |
+
return false;
|
3998 |
+
|
3999 |
+
$params = (object) pods_sanitize( $params );
|
4000 |
+
|
4001 |
+
$pod = pods( $params->pod, $params->id, false );
|
4002 |
+
|
4003 |
+
if ( empty( $pod ) )
|
4004 |
+
return false;
|
4005 |
+
}
|
4006 |
+
|
4007 |
+
$fields = (array) pods_var_raw( 'fields', $params, array(), null, true );
|
4008 |
+
$depth = (int) pods_var_raw( 'depth', $params, 2, null, true );
|
4009 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
|
4010 |
+
$flatten = (boolean) pods_var( 'flatten', $params, false, null, true );
|
4011 |
+
|
4012 |
+
if ( empty( $fields ) ) {
|
4013 |
+
$fields = $pod->fields;
|
4014 |
+
$fields = array_merge( $fields, $object_fields );
|
4015 |
+
}
|
4016 |
+
|
4017 |
+
$data = $this->export_pod_item_level( $pod, $fields, $depth, $flatten );
|
4018 |
+
|
4019 |
+
$data = $this->do_hook( 'export_pod_item', $data, $pod->pod, $pod->id(), $pod, $fields, $depth, $flatten );
|
4020 |
+
|
4021 |
+
return $data;
|
4022 |
+
}
|
4023 |
+
|
4024 |
+
/**
|
4025 |
+
* Export a pod item by depth level
|
4026 |
+
*
|
4027 |
+
* @param Pods $pod Pods object
|
4028 |
+
* @param array $fields Fields to export
|
4029 |
+
* @param int $depth Depth limit
|
4030 |
+
* @param boolean $flatten Whether to flatten arrays for display
|
4031 |
+
* @param int $current_depth Current depth level
|
4032 |
+
*
|
4033 |
+
* @return array Data array
|
4034 |
+
*
|
4035 |
+
* @since 2.3
|
4036 |
+
*/
|
4037 |
+
private function export_pod_item_level ( $pod, $fields, $depth, $flatten = false, $current_depth = 1 ) {
|
4038 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
4039 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
4040 |
+
|
4041 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
|
4042 |
+
|
4043 |
+
$export_fields = array();
|
4044 |
+
|
4045 |
+
foreach ( $fields as $k => $field ) {
|
4046 |
+
if ( !is_array( $field ) ) {
|
4047 |
+
$field = array(
|
4048 |
+
'id' => 0,
|
4049 |
+
'name' => $field
|
4050 |
+
);
|
4051 |
+
}
|
4052 |
+
|
4053 |
+
if ( isset( $pod->fields[ $field[ 'name' ] ] ) ) {
|
4054 |
+
$field = $pod->fields[ $field[ 'name' ] ];
|
4055 |
+
$field[ 'lookup_name' ] = $field[ 'name' ];
|
4056 |
+
|
4057 |
+
if ( in_array( $field[ 'type' ], $tableless_field_types ) && !in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
|
4058 |
+
if ( 'pick' == $field[ 'type' ] ) {
|
4059 |
+
if ( empty( $field[ 'table_info' ] ) )
|
4060 |
+
$field[ 'table_info' ] = $this->get_table_info( pods_var_raw( 'pick_object', $field ), pods_var_raw( 'pick_val', $field ), null, null, $field );
|
4061 |
+
|
4062 |
+
if ( !empty( $field[ 'table_info' ] ) )
|
4063 |
+
$field[ 'lookup_name' ] .= '.' . $field[ 'table_info' ][ 'field_id' ];
|
4064 |
+
}
|
4065 |
+
elseif ( in_array( $field[ 'type' ], PodsForm::file_field_types() ) )
|
4066 |
+
$field[ 'lookup_name' ] .= '.guid';
|
4067 |
+
}
|
4068 |
+
|
4069 |
+
$export_fields[ $field[ 'name' ] ] = $field;
|
4070 |
+
}
|
4071 |
+
elseif ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
|
4072 |
+
$field = $object_fields[ $field[ 'name' ] ];
|
4073 |
+
$field[ 'lookup_name' ] = $field[ 'name' ];
|
4074 |
+
|
4075 |
+
$export_fields[ $field[ 'name' ] ] = $field;
|
4076 |
+
}
|
4077 |
+
elseif ( $field[ 'name' ] == $pod->pod_data[ 'field_id' ] ) {
|
4078 |
+
$field[ 'type' ] = 'number';
|
4079 |
+
$field[ 'lookup_name' ] = $field[ 'name' ];
|
4080 |
+
|
4081 |
+
$export_fields[ $field[ 'name' ] ] = $field;
|
4082 |
+
}
|
4083 |
+
}
|
4084 |
+
|
4085 |
+
$data = array();
|
4086 |
+
|
4087 |
+
foreach ( $export_fields as $field ) {
|
4088 |
+
// Return IDs (or guid for files) if only one level deep
|
4089 |
+
if ( 1 == $depth )
|
4090 |
+
$data[ $field[ 'name' ] ] = $pod->field( array( 'name' => $field[ 'lookup_name' ], 'output' => 'arrays' ) );
|
4091 |
+
// Recurse depth levels for pick fields if $depth allows
|
4092 |
+
elseif ( ( -1 == $depth || $current_depth < $depth ) && 'pick' == $field[ 'type' ] && !in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
|
4093 |
+
$related_data = array();
|
4094 |
+
|
4095 |
+
$related_ids = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'ids' ) );
|
4096 |
+
|
4097 |
+
if ( !empty( $related_ids ) ) {
|
4098 |
+
$related_ids = (array) $related_ids;
|
4099 |
+
|
4100 |
+
$pick_object = pods_var_raw( 'pick_object', $field );
|
4101 |
+
|
4102 |
+
$related_pod = pods( pods_var_raw( 'pick_val', $field ), null, false );
|
4103 |
+
|
4104 |
+
// If this isn't a Pod, return data exactly as Pods does normally
|
4105 |
+
if ( empty( $related_pod ) || ( 'pod' != $pick_object && $pick_object != $related_pod->pod_data[ 'type' ] ) || $related_pod->pod == $pod->pod )
|
4106 |
+
$related_data = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'arrays' ) );
|
4107 |
+
else {
|
4108 |
+
$related_object_fields = (array) pods_var_raw( 'object_fields', $related_pod->pod_data, array(), null, true );
|
4109 |
+
|
4110 |
+
$related_fields = array_merge( $related_pod->fields, $related_object_fields );
|
4111 |
+
|
4112 |
+
foreach ( $related_ids as $related_id ) {
|
4113 |
+
if ( $related_pod->fetch( $related_id ) ) {
|
4114 |
+
$related_item = $this->export_pod_item_level( $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ) );
|
4115 |
+
|
4116 |
+
$related_data[ $related_id ] = $this->do_hook( 'export_pod_item_level', $related_item, $related_pod->pod, $related_pod->id(), $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ) );
|
4117 |
+
}
|
4118 |
+
}
|
4119 |
+
|
4120 |
+
if ( $flatten && !empty( $related_data ) )
|
4121 |
+
$related_data = pods_serial_comma( array_values( $related_data ), array( 'and' => '', 'field_index' => $related_pod->pod_data[ 'field_index' ] ) );
|
4122 |
+
}
|
4123 |
+
}
|
4124 |
+
|
4125 |
+
$data[ $field[ 'name' ] ] = $related_data;
|
4126 |
+
}
|
4127 |
+
// Return data exactly as Pods does normally
|
4128 |
+
else
|
4129 |
+
$data[ $field[ 'name' ] ] = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'arrays' ) );
|
4130 |
+
|
4131 |
+
if ( $flatten && is_array( $data[ $field[ 'name' ] ] ) )
|
4132 |
+
$data[ $field[ 'name' ] ] = pods_serial_comma( $data[ $field[ 'name' ] ], array( 'field' => $field[ 'name' ], 'fields' => $export_fields, 'and' => '' ) );
|
4133 |
+
}
|
4134 |
+
|
4135 |
+
return $data;
|
4136 |
+
}
|
4137 |
+
|
4138 |
+
/**
|
4139 |
+
* Reorder a Pod
|
4140 |
+
*
|
4141 |
+
* $params['pod'] string The Pod name
|
4142 |
+
* $params['field'] string The field name of the field to reorder
|
4143 |
+
* $params['order'] array The key => value array of items to reorder (key should be an integer)
|
4144 |
+
*
|
4145 |
+
* @param array $params An associative array of parameters
|
4146 |
+
*
|
4147 |
+
* @return bool
|
4148 |
+
*
|
4149 |
+
* @since 1.9.0
|
4150 |
+
*/
|
4151 |
+
public function reorder_pod_item ( $params ) {
|
4152 |
+
$params = (object) pods_sanitize( $params );
|
4153 |
+
|
4154 |
+
// @deprecated 2.0
|
4155 |
+
if ( isset( $params->datatype ) ) {
|
4156 |
+
pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
|
4157 |
+
|
4158 |
+
$params->pod = $params->datatype;
|
4159 |
+
|
4160 |
+
unset( $params->datatype );
|
4161 |
+
}
|
4162 |
+
|
4163 |
+
if ( null === pods_var_raw( 'pod', $params, null, null, true ) )
|
4164 |
+
return pods_error( __( '$params->pod is required', 'pods' ), $this );
|
4165 |
+
|
4166 |
+
if ( !is_array( $params->order ) )
|
4167 |
+
$params->order = explode( ',', $params->order );
|
4168 |
+
|
4169 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
|
4170 |
+
|
4171 |
+
$params->name = $pod[ 'name' ];
|
4172 |
+
|
4173 |
+
if ( false === $pod )
|
4174 |
+
return pods_error( __( 'Pod is required', 'pods' ), $this );
|
4175 |
+
|
4176 |
+
foreach ( $params->order as $order => $id ) {
|
4177 |
+
if ( isset( $pod[ 'fields' ][ $params->field ] ) || isset( $pod[ 'object_fields' ][ $params->field ] ) ) {
|
4178 |
+
if ( 'table' == $pod[ 'storage' ] && ( !pods_tableless() ) ) {
|
4179 |
+
if ( isset( $pod[ 'fields' ][ $params->field ] ) )
|
4180 |
+
pods_query( "UPDATE `@wp_pods_{$params->name}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `id` = " . pods_absint( $id ) . " LIMIT 1" );
|
4181 |
+
else
|
4182 |
+
pods_query( "UPDATE `{$pod['table']}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `{$pod['field_id']}` = " . pods_absint( $id ) . " LIMIT 1" );
|
4183 |
+
}
|
4184 |
+
else
|
4185 |
+
$this->save_pod_item( array( 'pod' => $params->pod, 'pod_id' => $params->pod_id, 'id' => $id, 'data' => array( $params->field => pods_absint( $order ) ) ) );
|
4186 |
+
}
|
4187 |
+
}
|
4188 |
+
|
4189 |
+
return true;
|
4190 |
+
}
|
4191 |
+
|
4192 |
+
/**
|
4193 |
+
*
|
4194 |
+
* Delete all content for a Pod
|
4195 |
+
*
|
4196 |
+
* $params['id'] int The Pod ID
|
4197 |
+
* $params['name'] string The Pod name
|
4198 |
+
*
|
4199 |
+
* @param array $params An associative array of parameters
|
4200 |
+
* @param array $pod Pod data
|
4201 |
+
*
|
4202 |
+
* @return bool
|
4203 |
+
*
|
4204 |
+
* @uses pods_query
|
4205 |
+
* @uses pods_cache_clear
|
4206 |
+
*
|
4207 |
+
* @since 1.9.0
|
4208 |
+
*/
|
4209 |
+
public function reset_pod ( $params, $pod = false ) {
|
4210 |
+
$params = (object) pods_sanitize( $params );
|
4211 |
+
|
4212 |
+
$params->table_info = true;
|
4213 |
+
|
4214 |
+
if ( empty( $pod ) )
|
4215 |
+
$pod = $this->load_pod( $params );
|
4216 |
+
|
4217 |
+
if ( false === $pod )
|
4218 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
4219 |
+
|
4220 |
+
$params->id = $pod[ 'id' ];
|
4221 |
+
$params->name = $pod[ 'name' ];
|
4222 |
+
|
4223 |
+
if ( !pods_tableless() ) {
|
4224 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
4225 |
+
try {
|
4226 |
+
pods_query( "TRUNCATE `@wp_pods_{$params->name}`", false );
|
4227 |
+
}
|
4228 |
+
catch ( Exception $e ) {
|
4229 |
+
// Allow pod to be reset if the table doesn't exist
|
4230 |
+
if ( false === strpos( $e->getMessage(), 'Unknown table' ) )
|
4231 |
+
return pods_error( $e->getMessage(), $this );
|
4232 |
+
}
|
4233 |
+
}
|
4234 |
+
|
4235 |
+
pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
|
4236 |
+
}
|
4237 |
+
|
4238 |
+
// @todo Delete relationships from tableless relationships
|
4239 |
+
|
4240 |
+
// Delete all posts/revisions from this post type
|
4241 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media' ) ) ) {
|
4242 |
+
$type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
|
4243 |
+
|
4244 |
+
$sql = "
|
4245 |
+
DELETE `t`, `r`, `m`
|
4246 |
+
FROM `{$pod['table']}` AS `t`
|
4247 |
+
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
4248 |
+
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
4249 |
+
LEFT JOIN `{$pod['table']}` AS `r`
|
4250 |
+
ON `r`.`post_parent` = `t`.`{$pod['field_id']}` AND `r`.`post_status` = 'inherit'
|
4251 |
+
WHERE `t`.`{$pod['field_type']}` = '{$type}'
|
4252 |
+
";
|
4253 |
+
|
4254 |
+
pods_query( $sql, false );
|
4255 |
+
}
|
4256 |
+
// Delete all terms from this taxonomy
|
4257 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
4258 |
+
$type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
|
4259 |
+
|
4260 |
+
$sql = "
|
4261 |
+
DELETE FROM `{$pod['table']}` AS `t`
|
4262 |
+
" . $pod['join']['tt'] . "
|
4263 |
+
WHERE " . implode( ' AND ', $pod['where'] ) . "
|
4264 |
+
";
|
4265 |
+
|
4266 |
+
pods_query( $sql, false );
|
4267 |
+
}
|
4268 |
+
// Delete all users except the current one
|
4269 |
+
elseif ( 'user' == $pod[ 'type' ] ) {
|
4270 |
+
$sql = "
|
4271 |
+
DELETE `t`, `m`
|
4272 |
+
FROM `{$pod['table']}` AS `t`
|
4273 |
+
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
4274 |
+
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
4275 |
+
WHERE `t`.`{$pod['field_id']}` != " . (int) get_current_user_id() . "
|
4276 |
+
";
|
4277 |
+
|
4278 |
+
pods_query( $sql, false );
|
4279 |
+
}
|
4280 |
+
// Delete all comments
|
4281 |
+
elseif ( 'comment' == $pod[ 'type' ] ) {
|
4282 |
+
$type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
|
4283 |
+
|
4284 |
+
$sql = "
|
4285 |
+
DELETE `t`, `m`
|
4286 |
+
FROM `{$pod['table']}` AS `t`
|
4287 |
+
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
4288 |
+
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
4289 |
+
WHERE `t`.`{$pod['field_type']}` = '{$type}'
|
4290 |
+
";
|
4291 |
+
|
4292 |
+
pods_query( $sql, false );
|
4293 |
+
}
|
4294 |
+
|
4295 |
+
pods_cache_clear( true ); // only way to reliably clear out cached data across an entire group
|
4296 |
+
|
4297 |
+
return true;
|
4298 |
+
}
|
4299 |
+
|
4300 |
+
/**
|
4301 |
+
* Delete a Pod and all its content
|
4302 |
+
*
|
4303 |
+
* $params['id'] int The Pod ID
|
4304 |
+
* $params['name'] string The Pod name
|
4305 |
+
*
|
4306 |
+
* @param array $params An associative array of parameters
|
4307 |
+
* @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
|
4308 |
+
* @param bool $delete_all (optional) Whether to delete all content from a WP object
|
4309 |
+
*
|
4310 |
+
* @uses PodsAPI::load_pod
|
4311 |
+
* @uses wp_delete_post
|
4312 |
+
* @uses pods_query
|
4313 |
+
*
|
4314 |
+
* @return bool
|
4315 |
+
* @since 1.7.9
|
4316 |
+
*/
|
4317 |
+
public function delete_pod ( $params, $strict = false, $delete_all = false ) {
|
4318 |
+
/**
|
4319 |
+
* @var $wpdb wpdb
|
4320 |
+
*/
|
4321 |
+
global $wpdb;
|
4322 |
+
|
4323 |
+
if ( !is_object( $params ) && !is_array( $params ) ) {
|
4324 |
+
if ( is_numeric( $params ) )
|
4325 |
+
$params = array( 'id' => $params );
|
4326 |
+
else
|
4327 |
+
$params = array( 'name' => $params );
|
4328 |
+
|
4329 |
+
$params = (object) pods_sanitize( $params );
|
4330 |
+
}
|
4331 |
+
else
|
4332 |
+
$params = (object) pods_sanitize( $params );
|
4333 |
+
|
4334 |
+
$params->table_info = false;
|
4335 |
+
|
4336 |
+
$pod = $this->load_pod( $params, $strict );
|
4337 |
+
|
4338 |
+
if ( empty( $pod ) ) {
|
4339 |
+
if ( false !== $strict )
|
4340 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
4341 |
+
|
4342 |
+
return false;
|
4343 |
+
}
|
4344 |
+
|
4345 |
+
$params->id = (int) $pod[ 'id' ];
|
4346 |
+
$params->name = $pod[ 'name' ];
|
4347 |
+
|
4348 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
4349 |
+
$field[ 'pod' ] = $pod;
|
4350 |
+
|
4351 |
+
$this->delete_field( $field, false );
|
4352 |
+
}
|
4353 |
+
|
4354 |
+
// Only delete the post once the fields are taken care of, it's not required anymore
|
4355 |
+
$success = wp_delete_post( $params->id );
|
4356 |
+
|
4357 |
+
if ( !$success )
|
4358 |
+
return pods_error( __( 'Pod unable to be deleted', 'pods' ), $this );
|
4359 |
+
|
4360 |
+
// Reset content
|
4361 |
+
if ( $delete_all )
|
4362 |
+
$this->reset_pod( $params, $pod );
|
4363 |
+
|
4364 |
+
if ( !pods_tableless() ) {
|
4365 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
4366 |
+
try {
|
4367 |
+
pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`", false );
|
4368 |
+
}
|
4369 |
+
catch ( Exception $e ) {
|
4370 |
+
// Allow pod to be deleted if the table doesn't exist
|
4371 |
+
if ( false === strpos( $e->getMessage(), 'Unknown table' ) )
|
4372 |
+
return pods_error( $e->getMessage(), $this );
|
4373 |
+
}
|
4374 |
+
}
|
4375 |
+
|
4376 |
+
pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
|
4377 |
+
}
|
4378 |
+
|
4379 |
+
// @todo Delete relationships from tableless relationships
|
4380 |
+
|
4381 |
+
// Delete any relationship references
|
4382 |
+
$sql = "
|
4383 |
+
DELETE `pm`
|
4384 |
+
FROM `{$wpdb->postmeta}` AS `pm`
|
4385 |
+
LEFT JOIN `{$wpdb->posts}` AS `p`
|
4386 |
+
ON `p`.`post_type` = '_pods_field'
|
4387 |
+
AND `p`.`ID` = `pm`.`post_id`
|
4388 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm2`
|
4389 |
+
ON `pm2`.`meta_key` = 'pick_object'
|
4390 |
+
AND `pm2`.`meta_value` = 'pod'
|
4391 |
+
AND `pm2`.`post_id` = `pm`.`post_id`
|
4392 |
+
WHERE
|
4393 |
+
`p`.`ID` IS NOT NULL
|
4394 |
+
AND `pm2`.`meta_id` IS NOT NULL
|
4395 |
+
AND `pm`.`meta_key` = 'pick_val'
|
4396 |
+
AND `pm`.`meta_value` = '{$params->name}'
|
4397 |
+
";
|
4398 |
+
|
4399 |
+
pods_query( $sql );
|
4400 |
+
|
4401 |
+
$this->cache_flush_pods( $pod );
|
4402 |
+
|
4403 |
+
return true;
|
4404 |
+
}
|
4405 |
+
|
4406 |
+
/**
|
4407 |
+
* Drop a field within a Pod
|
4408 |
+
*
|
4409 |
+
* $params['id'] int The field ID
|
4410 |
+
* $params['name'] int The field name
|
4411 |
+
* $params['pod'] string The Pod name
|
4412 |
+
* $params['pod_id'] string The Pod name
|
4413 |
+
*
|
4414 |
+
* @param array $params An associative array of parameters
|
4415 |
+
* @param bool $table_operation Whether or not to handle table operations
|
4416 |
+
*
|
4417 |
+
* @uses PodsAPI::load_field
|
4418 |
+
* @uses wp_delete_post
|
4419 |
+
* @uses pods_query
|
4420 |
+
*
|
4421 |
+
* @return bool
|
4422 |
+
* @since 1.7.9
|
4423 |
+
*/
|
4424 |
+
public function delete_field ( $params, $table_operation = true ) {
|
4425 |
+
/**
|
4426 |
+
* @var $wpdb wpdb
|
4427 |
+
*/
|
4428 |
+
global $wpdb;
|
4429 |
+
|
4430 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
4431 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
4432 |
+
|
4433 |
+
$params = (object) pods_sanitize( $params );
|
4434 |
+
|
4435 |
+
if ( !isset( $params->pod ) )
|
4436 |
+
$params->pod = '';
|
4437 |
+
|
4438 |
+
if ( !isset( $params->pod_id ) )
|
4439 |
+
$params->pod_id = 0;
|
4440 |
+
|
4441 |
+
$pod = $params->pod;
|
4442 |
+
|
4443 |
+
$save_pod = false;
|
4444 |
+
|
4445 |
+
if ( !is_array( $pod ) )
|
4446 |
+
$pod = $this->load_pod( array( 'name' => $pod, 'id' => $params->pod_id, 'table_info' => false ) );
|
4447 |
+
else
|
4448 |
+
$save_pod = true;
|
4449 |
+
|
4450 |
+
if ( empty( $pod ) )
|
4451 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
4452 |
+
|
4453 |
+
$params->pod_id = $pod[ 'id' ];
|
4454 |
+
$params->pod = $pod[ 'name' ];
|
4455 |
+
|
4456 |
+
if ( !isset( $params->name ) )
|
4457 |
+
$params->name = '';
|
4458 |
+
|
4459 |
+
if ( !isset( $params->id ) )
|
4460 |
+
$params->id = 0;
|
4461 |
+
|
4462 |
+
$field = $this->load_field( array( 'name' => $params->name, 'id' => $params->id ) );
|
4463 |
+
|
4464 |
+
if ( false === $field )
|
4465 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
4466 |
+
|
4467 |
+
$params->id = $field[ 'id' ];
|
4468 |
+
$params->name = $field[ 'name' ];
|
4469 |
+
|
4470 |
+
$simple = ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
|
4471 |
+
$simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field, $pod, $params );
|
4472 |
+
|
4473 |
+
if ( $table_operation && 'table' == $pod[ 'storage' ] && ( !in_array( $field[ 'type' ], $tableless_field_types ) || $simple ) )
|
4474 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$params->name}`", false );
|
4475 |
+
|
4476 |
+
$success = wp_delete_post( $params->id );
|
4477 |
+
|
4478 |
+
if ( !$success )
|
4479 |
+
return pods_error( __( 'Field unable to be deleted', 'pods' ), $this );
|
4480 |
+
|
4481 |
+
$wpdb->query( $wpdb->prepare( "DELETE pm FROM {$wpdb->postmeta} AS pm
|
4482 |
+
LEFT JOIN {$wpdb->posts} AS p
|
4483 |
+
ON p.post_type = '_pods_field' AND p.ID = pm.post_id
|
4484 |
+
WHERE p.ID IS NOT NULL AND pm.meta_key = 'sister_id' AND pm.meta_value = %d", $params->id ) );
|
4485 |
+
|
4486 |
+
if ( ( !pods_tableless() ) && $table_operation ) {
|
4487 |
+
pods_query( "DELETE FROM `@wp_podsrel` WHERE (`pod_id` = {$params->pod_id} AND `field_id` = {$params->id}) OR (`related_pod_id` = {$params->pod_id} AND `related_field_id` = {$params->id})", false );
|
4488 |
+
}
|
4489 |
+
|
4490 |
+
// @todo Delete tableless relationship meta
|
4491 |
+
|
4492 |
+
if ( true === $save_pod )
|
4493 |
+
$this->cache_flush_pods( $pod );
|
4494 |
+
|
4495 |
+
return true;
|
4496 |
+
}
|
4497 |
+
|
4498 |
+
/**
|
4499 |
+
* Drop a Pod Object
|
4500 |
+
*
|
4501 |
+
* $params['id'] int The object ID
|
4502 |
+
* $params['name'] string The object name
|
4503 |
+
* $params['type'] string The object type
|
4504 |
+
*
|
4505 |
+
* @param array|object $params An associative array of parameters
|
4506 |
+
*
|
4507 |
+
* @uses wp_delete_post
|
4508 |
+
*
|
4509 |
+
* @return bool
|
4510 |
+
* @since 2.0
|
4511 |
+
*/
|
4512 |
+
public function delete_object ( $params ) {
|
4513 |
+
$params = (object) $params;
|
4514 |
+
$object = $this->load_object( $params );
|
4515 |
+
|
4516 |
+
if ( empty( $object ) )
|
4517 |
+
return pods_error( sprintf( __( "%s Object not found", 'pods' ), ucwords( $params->type ) ), $this );
|
4518 |
+
|
4519 |
+
$success = wp_delete_post( $params->id );
|
4520 |
+
|
4521 |
+
if ( !$success )
|
4522 |
+
return pods_error( sprintf( __( "%s Object not deleted", 'pods' ), ucwords( $params->type ) ), $this );
|
4523 |
+
|
4524 |
+
pods_transient_clear( 'pods_objects_' . $params->type );
|
4525 |
+
|
4526 |
+
return true;
|
4527 |
+
}
|
4528 |
+
|
4529 |
+
/**
|
4530 |
+
* @see PodsAPI::delete_object
|
4531 |
+
*
|
4532 |
+
* Drop a Pod Template
|
4533 |
+
*
|
4534 |
+
* $params['id'] int The template ID
|
4535 |
+
* $params['name'] string The template name
|
4536 |
+
*
|
4537 |
+
* @param array $params An associative array of parameters
|
4538 |
+
*
|
4539 |
+
* @return bool
|
4540 |
+
* @since 1.7.9
|
4541 |
+
*/
|
4542 |
+
public function delete_template ( $params ) {
|
4543 |
+
$params = (object) $params;
|
4544 |
+
$params->type = 'template';
|
4545 |
+
return $this->delete_object( $params );
|
4546 |
+
}
|
4547 |
+
|
4548 |
+
/**
|
4549 |
+
* @see PodsAPI::delete_object
|
4550 |
+
*
|
4551 |
+
* Drop a Pod Page
|
4552 |
+
*
|
4553 |
+
* $params['id'] int The page ID
|
4554 |
+
* $params['uri'] string The page URI
|
4555 |
+
*
|
4556 |
+
* @param array $params An associative array of parameters
|
4557 |
+
*
|
4558 |
+
* @return bool
|
4559 |
+
* @since 1.7.9
|
4560 |
+
*/
|
4561 |
+
public function delete_page ( $params ) {
|
4562 |
+
$params = (object) $params;
|
4563 |
+
if ( isset( $params->uri ) ) {
|
4564 |
+
$params->name = $params->uri;
|
4565 |
+
unset( $params->uri );
|
4566 |
+
}
|
4567 |
+
if ( isset( $params->name ) )
|
4568 |
+
$params->name = trim( $params->name, '/' );
|
4569 |
+
$params->type = 'page';
|
4570 |
+
return $this->delete_object( $params );
|
4571 |
+
}
|
4572 |
+
|
4573 |
+
/**
|
4574 |
+
* @see PodsAPI::delete_object
|
4575 |
+
*
|
4576 |
+
* Drop a Pod Helper
|
4577 |
+
*
|
4578 |
+
* $params['id'] int The helper ID
|
4579 |
+
* $params['name'] string The helper name
|
4580 |
+
*
|
4581 |
+
* @param array $params An associative array of parameters
|
4582 |
+
*
|
4583 |
+
* @return bool
|
4584 |
+
* @since 1.7.9
|
4585 |
+
*/
|
4586 |
+
public function delete_helper ( $params ) {
|
4587 |
+
$params = (object) $params;
|
4588 |
+
$params->type = 'helper';
|
4589 |
+
return $this->delete_object( $params );
|
4590 |
+
}
|
4591 |
+
|
4592 |
+
/**
|
4593 |
+
* Drop a single pod item
|
4594 |
+
*
|
4595 |
+
* $params['id'] int (optional) The item's ID from the wp_pod_* table (used with datatype parameter)
|
4596 |
+
* $params['pod'] string (optional) The Pod name (used with id parameter)
|
4597 |
+
* $params['pod_id'] int (optional) The Pod ID (used with id parameter)
|
4598 |
+
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
4599 |
+
*
|
4600 |
+
* @param array $params An associative array of parameters
|
4601 |
+
* @param bool $wp Whether to run WP object delete action
|
4602 |
+
*
|
4603 |
+
* @return bool
|
4604 |
+
* @since 1.7.9
|
4605 |
+
*/
|
4606 |
+
public function delete_pod_item ( $params, $wp = true ) {
|
4607 |
+
$params = (object) pods_sanitize( $params );
|
4608 |
+
|
4609 |
+
// @deprecated 2.0
|
4610 |
+
if ( isset( $params->datatype_id ) || isset( $params->datatype ) || isset( $params->tbl_row_id ) ) {
|
4611 |
+
if ( isset( $params->tbl_row_id ) ) {
|
4612 |
+
pods_deprecated( __( '$params->id instead of $params->tbl_row_id', 'pods' ), '2.0' );
|
4613 |
+
$params->id = $params->tbl_row_id;
|
4614 |
+
unset( $params->tbl_row_id );
|
4615 |
+
}
|
4616 |
+
|
4617 |
+
if ( isset( $params->pod_id ) ) {
|
4618 |
+
pods_deprecated( __( '$params->id instead of $params->pod_id', 'pods' ), '2.0' );
|
4619 |
+
$params->id = $params->pod_id;
|
4620 |
+
unset( $params->pod_id );
|
4621 |
+
}
|
4622 |
+
|
4623 |
+
if ( isset( $params->dataype_id ) ) {
|
4624 |
+
pods_deprecated( __( '$params->pod_id instead of $params->datatype_id', 'pods' ), '2.0' );
|
4625 |
+
$params->pod_id = $params->dataype_id;
|
4626 |
+
unset( $params->dataype_id );
|
4627 |
+
}
|
4628 |
+
|
4629 |
+
if ( isset( $params->datatype ) ) {
|
4630 |
+
pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
|
4631 |
+
$params->pod = $params->datatype;
|
4632 |
+
unset( $params->datatype );
|
4633 |
+
}
|
4634 |
+
}
|
4635 |
+
|
4636 |
+
if ( !isset( $params->id ) )
|
4637 |
+
return pods_error( __( 'Pod Item not found', 'pods' ), $this );
|
4638 |
+
|
4639 |
+
$params->id = pods_absint( $params->id );
|
4640 |
+
|
4641 |
+
if ( !isset( $params->pod ) )
|
4642 |
+
$params->pod = '';
|
4643 |
+
|
4644 |
+
if ( !isset( $params->pod_id ) )
|
4645 |
+
$params->pod_id = 0;
|
4646 |
+
|
4647 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false ) );
|
4648 |
+
|
4649 |
+
if ( false === $pod )
|
4650 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
4651 |
+
|
4652 |
+
$params->pod_id = $pod[ 'id' ];
|
4653 |
+
$params->pod = $pod[ 'name' ];
|
4654 |
+
|
4655 |
+
// Allow Helpers to bypass subsequent helpers in recursive delete_pod_item calls
|
4656 |
+
$bypass_helpers = false;
|
4657 |
+
|
4658 |
+
if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers )
|
4659 |
+
$bypass_helpers = true;
|
4660 |
+
|
4661 |
+
$pre_delete_helpers = $post_delete_helpers = array();
|
4662 |
+
|
4663 |
+
if ( false === $bypass_helpers ) {
|
4664 |
+
// Plugin hook
|
4665 |
+
$this->do_hook( 'pre_delete_pod_item', $params, $pod );
|
4666 |
+
$this->do_hook( "pre_delete_pod_item_{$params->pod}", $params, $pod );
|
4667 |
+
|
4668 |
+
// Call any pre-save helpers (if not bypassed)
|
4669 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
4670 |
+
if ( !empty( $pod[ 'options' ] ) && is_array( $pod[ 'options' ] ) ) {
|
4671 |
+
$helpers = array( 'pre_delete_helpers', 'post_delete_helpers' );
|
4672 |
+
|
4673 |
+
foreach ( $helpers as $helper ) {
|
4674 |
+
if ( isset( $pod[ 'options' ][ $helper ] ) && !empty( $pod[ 'options' ][ $helper ] ) )
|
4675 |
+
${$helper} = explode( ',', $pod[ 'options' ][ $helper ] );
|
4676 |
+
}
|
4677 |
+
}
|
4678 |
+
|
4679 |
+
if ( !empty( $pre_delete_helpers ) ) {
|
4680 |
+
pods_deprecated( sprintf( __( 'Pre-delete helpers are deprecated, use the action pods_pre_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
4681 |
+
|
4682 |
+
foreach ( $pre_delete_helpers as $helper ) {
|
4683 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
4684 |
+
|
4685 |
+
if ( false !== $helper )
|
4686 |
+
eval( '?>' . $helper[ 'code' ] );
|
4687 |
+
}
|
4688 |
+
}
|
4689 |
+
}
|
4690 |
+
}
|
4691 |
+
|
4692 |
+
// Delete object from relationship fields
|
4693 |
+
$this->delete_object_from_relationships( $params->id, $pod );
|
4694 |
+
|
4695 |
+
if ( 'table' == $pod[ 'storage' ] )
|
4696 |
+
pods_query( "DELETE FROM `@wp_pods_{$params->pod}` WHERE `id` = {$params->id} LIMIT 1" );
|
4697 |
+
|
4698 |
+
if ( $wp && 'taxonomy' == $pod[ 'type' ] ) {
|
4699 |
+
$taxonomy = $pod[ 'name' ];
|
4700 |
+
|
4701 |
+
if ( !empty( $pod[ 'object' ] ) )
|
4702 |
+
$taxonomy = $pod[ 'object' ];
|
4703 |
+
|
4704 |
+
wp_delete_term( $params->id, $taxonomy );
|
4705 |
+
}
|
4706 |
+
elseif ( $wp && !in_array( $pod[ 'type' ], array( 'pod', 'table', '', 'taxonomy' ) ) )
|
4707 |
+
$this->delete_wp_object( $pod[ 'type' ], $params->id );
|
4708 |
+
|
4709 |
+
if ( false === $bypass_helpers ) {
|
4710 |
+
// Plugin hook
|
4711 |
+
$this->do_hook( 'post_delete_pod_item', $params, $pod );
|
4712 |
+
$this->do_hook( "post_delete_pod_item_{$params->pod}", $params, $pod );
|
4713 |
+
|
4714 |
+
// Call any post-save helpers (if not bypassed)
|
4715 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
4716 |
+
if ( !empty( $post_delete_helpers ) ) {
|
4717 |
+
pods_deprecated( sprintf( __( 'Post-delete helpers are deprecated, use the action pods_post_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
4718 |
+
|
4719 |
+
foreach ( $post_delete_helpers as $helper ) {
|
4720 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
4721 |
+
|
4722 |
+
if ( false !== $helper )
|
4723 |
+
eval( '?>' . $helper[ 'code' ] );
|
4724 |
+
}
|
4725 |
+
}
|
4726 |
+
}
|
4727 |
+
}
|
4728 |
+
|
4729 |
+
pods_cache_clear( $params->id, 'pods_items_' . $params->pod );
|
4730 |
+
|
4731 |
+
return true;
|
4732 |
+
}
|
4733 |
+
|
4734 |
+
/**
|
4735 |
+
* Delete an object from tableless fields
|
4736 |
+
*
|
4737 |
+
* @param int $id
|
4738 |
+
* @param string $type
|
4739 |
+
* @param string $name
|
4740 |
+
*
|
4741 |
+
* @return bool
|
4742 |
+
*
|
4743 |
+
* @since 2.3
|
4744 |
+
*/
|
4745 |
+
public function delete_object_from_relationships ( $id, $object, $name = null ) {
|
4746 |
+
/**
|
4747 |
+
* @var $pods_init \PodsInit
|
4748 |
+
*/
|
4749 |
+
global $pods_init;
|
4750 |
+
|
4751 |
+
$pod = false;
|
4752 |
+
|
4753 |
+
// Run any bidirectional delete operations
|
4754 |
+
if ( is_array( $object ) )
|
4755 |
+
$pod = $object;
|
4756 |
+
elseif ( is_object( $pods_init ) )
|
4757 |
+
$pod = PodsInit::$meta->get_object( $object, $name );
|
4758 |
+
|
4759 |
+
if ( !empty( $pod ) ) {
|
4760 |
+
$object = $pod[ 'type' ];
|
4761 |
+
$name = $pod[ 'name' ];
|
4762 |
+
|
4763 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
4764 |
+
PodsForm::delete( $field[ 'type' ], $id, $field[ 'name' ], array_merge( $field, $field[ 'options' ] ), $pod );
|
4765 |
+
}
|
4766 |
+
}
|
4767 |
+
|
4768 |
+
// Lookup related fields (non-bidirectional)
|
4769 |
+
$params = array(
|
4770 |
+
'where' => array(
|
4771 |
+
array(
|
4772 |
+
'key' => 'type',
|
4773 |
+
'value' => 'pick'
|
4774 |
+
),
|
4775 |
+
array(
|
4776 |
+
'key' => 'pick_object',
|
4777 |
+
'value' => $object
|
4778 |
+
)
|
4779 |
+
)
|
4780 |
+
);
|
4781 |
+
|
4782 |
+
if ( !empty( $name ) && $name != $object ) {
|
4783 |
+
$params[ 'where' ][] = array(
|
4784 |
+
'key' => 'pick_val',
|
4785 |
+
'value' => $name
|
4786 |
+
);
|
4787 |
+
}
|
4788 |
+
|
4789 |
+
$fields = $this->load_fields( $params, false );
|
4790 |
+
|
4791 |
+
if ( !empty( $pod ) && 'media' == $pod[ 'type' ] ) {
|
4792 |
+
$params[ 'where' ] = array(
|
4793 |
+
array(
|
4794 |
+
'key' => 'type',
|
4795 |
+
'value' => 'file'
|
4796 |
+
)
|
4797 |
+
);
|
4798 |
+
|
4799 |
+
$fields = array_merge( $fields, $this->load_fields( $params, false ) );
|
4800 |
+
}
|
4801 |
+
|
4802 |
+
if ( is_array( $fields ) && !empty( $fields ) ) {
|
4803 |
+
foreach ( $fields as $related_field ) {
|
4804 |
+
$related_pod = $this->load_pod( array( 'id' => $related_field[ 'pod_id' ], 'fields' => false ), false );
|
4805 |
+
|
4806 |
+
if ( empty( $related_pod ) )
|
4807 |
+
continue;
|
4808 |
+
|
4809 |
+
$related_from = $this->lookup_related_items_from( $related_field[ 'id' ], $related_pod[ 'id' ], $id, $related_field, $related_pod );
|
4810 |
+
|
4811 |
+
$this->delete_relationships( $related_from, $id, $related_pod, $related_field );
|
4812 |
+
}
|
4813 |
+
}
|
4814 |
+
|
4815 |
+
if ( !empty( $pod ) && !pods_tableless() ) {
|
4816 |
+
pods_query( "
|
4817 |
+
DELETE FROM `@wp_podsrel`
|
4818 |
+
WHERE
|
4819 |
+
(
|
4820 |
+
`pod_id` = %d
|
4821 |
+
AND `item_id` = %d
|
4822 |
+
)
|
4823 |
+
OR (
|
4824 |
+
`related_pod_id` = %d
|
4825 |
+
AND `related_item_id` = %d
|
4826 |
+
)
|
4827 |
+
", array(
|
4828 |
+
$pod[ 'id' ],
|
4829 |
+
$id,
|
4830 |
+
|
4831 |
+
$pod[ 'id' ],
|
4832 |
+
$id
|
4833 |
+
) );
|
4834 |
+
}
|
4835 |
+
|
4836 |
+
return true;
|
4837 |
+
}
|
4838 |
+
|
4839 |
+
/**
|
4840 |
+
* Delete relationships
|
4841 |
+
*
|
4842 |
+
* @param int|array $related_id IDs for items to save
|
4843 |
+
* @param int|array $id ID or IDs to remove
|
4844 |
+
* @param array $related_pod Pod data
|
4845 |
+
* @param array $related_field Field data
|
4846 |
+
*
|
4847 |
+
* @return void
|
4848 |
+
*
|
4849 |
+
* @since 2.3
|
4850 |
+
*/
|
4851 |
+
public function delete_relationships ( $related_id, $id, $related_pod, $related_field ) {
|
4852 |
+
if ( is_array( $related_id ) ) {
|
4853 |
+
foreach ( $related_id as $rid ) {
|
4854 |
+
$this->delete_relationships( $rid, $id, $related_pod, $related_field );
|
4855 |
+
}
|
4856 |
+
|
4857 |
+
return;
|
4858 |
+
}
|
4859 |
+
|
4860 |
+
if ( is_array( $id ) ) {
|
4861 |
+
foreach ( $id as $rid ) {
|
4862 |
+
$this->delete_relationships( $related_id, $rid, $related_pod, $related_field );
|
4863 |
+
}
|
4864 |
+
|
4865 |
+
return;
|
4866 |
+
}
|
4867 |
+
|
4868 |
+
$id = (int) $id;
|
4869 |
+
|
4870 |
+
if ( empty( $id ) )
|
4871 |
+
return;
|
4872 |
+
|
4873 |
+
$related_ids = $this->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod );
|
4874 |
+
|
4875 |
+
if ( empty( $related_ids ) )
|
4876 |
+
return;
|
4877 |
+
elseif ( !in_array( $id, $related_ids ) )
|
4878 |
+
return;
|
4879 |
+
|
4880 |
+
unset( $related_ids[ array_search( $id, $related_ids ) ] );
|
4881 |
+
|
4882 |
+
$no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] );
|
4883 |
+
|
4884 |
+
if ( !$no_conflict )
|
4885 |
+
pods_no_conflict_on( $related_pod[ 'type' ] );
|
4886 |
+
|
4887 |
+
// Post Types, Media, Users, and Comments (meta-based)
|
4888 |
+
if ( in_array( $related_pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment' ) ) ) {
|
4889 |
+
$object_type = $related_pod[ 'type' ];
|
4890 |
+
|
4891 |
+
if ( 'post_type' == $object_type || 'media' == $object_type )
|
4892 |
+
$object_type = 'post';
|
4893 |
+
|
4894 |
+
delete_metadata( $object_type, $related_id, $related_field[ 'name' ] );
|
4895 |
+
|
4896 |
+
if ( !empty( $related_ids ) ) {
|
4897 |
+
update_metadata( $object_type, $related_id, '_pods_' . $related_field[ 'name' ], $related_ids );
|
4898 |
+
|
4899 |
+
foreach ( $related_ids as $rel_id ) {
|
4900 |
+
add_metadata( $object_type, $related_id, $related_field[ 'name' ], $rel_id );
|
4901 |
+
}
|
4902 |
+
}
|
4903 |
+
else
|
4904 |
+
delete_metadata( $object_type, $related_id, '_pods_' . $related_field[ 'name' ] );
|
4905 |
+
}
|
4906 |
+
// Custom Settings Pages (options-based)
|
4907 |
+
elseif ( 'settings' == $related_pod[ 'type' ] ) {
|
4908 |
+
if ( !empty( $related_ids ) )
|
4909 |
+
update_option( $related_pod[ 'name' ] . '_' . $related_field[ 'name' ], $related_ids );
|
4910 |
+
else
|
4911 |
+
delete_option( $related_pod[ 'name' ] . '_' . $related_field[ 'name' ] );
|
4912 |
+
}
|
4913 |
+
|
4914 |
+
// Relationships table
|
4915 |
+
if ( !pods_tableless() ) {
|
4916 |
+
pods_query( "
|
4917 |
+
DELETE FROM `@wp_podsrel`
|
4918 |
+
WHERE
|
4919 |
+
(
|
4920 |
+
`pod_id` = %d
|
4921 |
+
AND `field_id` = %d
|
4922 |
+
AND `item_id` = %d
|
4923 |
+
AND `related_item_id` = %d
|
4924 |
+
)
|
4925 |
+
OR (
|
4926 |
+
`related_pod_id` = %d
|
4927 |
+
AND `related_field_id` = %d
|
4928 |
+
AND `related_item_id` = %d
|
4929 |
+
AND `item_id` = %d
|
4930 |
+
)
|
4931 |
+
", array(
|
4932 |
+
$related_pod[ 'id' ],
|
4933 |
+
$related_field[ 'id' ],
|
4934 |
+
$related_id,
|
4935 |
+
$id,
|
4936 |
+
|
4937 |
+
$related_pod[ 'id' ],
|
4938 |
+
$related_field[ 'id' ],
|
4939 |
+
$related_id,
|
4940 |
+
$id
|
4941 |
+
) );
|
4942 |
+
}
|
4943 |
+
|
4944 |
+
if ( !$no_conflict )
|
4945 |
+
pods_no_conflict_off( $related_pod[ 'type' ] );
|
4946 |
+
}
|
4947 |
+
|
4948 |
+
/**
|
4949 |
+
* Check if a Pod exists
|
4950 |
+
*
|
4951 |
+
* $params['id'] int Pod ID
|
4952 |
+
* $params['name'] string Pod name
|
4953 |
+
*
|
4954 |
+
* @param array $params An associative array of parameters
|
4955 |
+
*
|
4956 |
+
* @return bool True if exists
|
4957 |
+
*
|
4958 |
+
* @since 1.12
|
4959 |
+
*/
|
4960 |
+
public function pod_exists ( $params, $type = null ) {
|
4961 |
+
if ( is_string( $params ) )
|
4962 |
+
$params = array( 'name' => $params );
|
4963 |
+
|
4964 |
+
$params = (object) pods_sanitize( $params );
|
4965 |
+
|
4966 |
+
if ( !empty( $params->id ) || !empty( $params->name ) ) {
|
4967 |
+
if ( !isset( $params->name ) )
|
4968 |
+
$pod = get_post( $dummy = (int) $params->id );
|
4969 |
+
else {
|
4970 |
+
$pod = get_posts( array(
|
4971 |
+
'name' => $params->name,
|
4972 |
+
'post_type' => '_pods_pod',
|
4973 |
+
'posts_per_page' => 1
|
4974 |
+
) );
|
4975 |
+
}
|
4976 |
+
|
4977 |
+
if ( !empty( $pod ) && ( empty( $type ) || $type == get_post_meta( $pod->ID, 'type', true ) ) )
|
4978 |
+
return true;
|
4979 |
+
}
|
4980 |
+
|
4981 |
+
return false;
|
4982 |
+
}
|
4983 |
+
|
4984 |
+
/**
|
4985 |
+
* Load a Pod and all of its fields
|
4986 |
+
*
|
4987 |
+
* $params['id'] int The Pod ID
|
4988 |
+
* $params['name'] string The Pod name
|
4989 |
+
* $params['fields'] bool Whether to load fields (default is true)
|
4990 |
+
*
|
4991 |
+
* @param array|object $params An associative array of parameters or pod name as a string
|
4992 |
+
* @param bool $strict Makes sure the pod exists, throws an error if it doesn't work
|
4993 |
+
*
|
4994 |
+
* @return array|bool|mixed|void
|
4995 |
+
* @since 1.7.9
|
4996 |
+
*/
|
4997 |
+
public function load_pod ( $params, $strict = true ) {
|
4998 |
+
|
4999 |
+
/**
|
5000 |
+
* @var $sitepress SitePress
|
5001 |
+
* @var $wpdb wpdb
|
5002 |
+
*/
|
5003 |
+
global $sitepress, $icl_adjust_id_url_filter_off, $wpdb;
|
5004 |
+
|
5005 |
+
$current_language = false;
|
5006 |
+
$load_fields = true;
|
5007 |
+
|
5008 |
+
// WPML support
|
5009 |
+
if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
5010 |
+
$current_language = pods_sanitize( ICL_LANGUAGE_CODE );
|
5011 |
+
// Polylang support
|
5012 |
+
elseif ( function_exists( 'pll_current_language' ) )
|
5013 |
+
$current_language = pll_current_language( 'slug' );
|
5014 |
+
|
5015 |
+
if ( !is_array( $params ) && !is_object( $params ) )
|
5016 |
+
$params = array( 'name' => $params, 'table_info' => false, 'fields' => true );
|
5017 |
+
|
5018 |
+
if ( is_object( $params ) && isset( $params->fields ) && !$params->fields )
|
5019 |
+
$load_fields = false;
|
5020 |
+
elseif ( is_array( $params ) && isset( $params[ 'fields' ] ) && !$params[ 'fields' ] )
|
5021 |
+
$load_fields = false;
|
5022 |
+
|
5023 |
+
$transient = 'pods_' . $wpdb->prefix . '_pod';
|
5024 |
+
|
5025 |
+
if ( !empty( $current_language ) )
|
5026 |
+
$transient .= '_' . $current_language;
|
5027 |
+
|
5028 |
+
if ( !$load_fields )
|
5029 |
+
$transient .= '_nofields';
|
5030 |
+
|
5031 |
+
if ( pods_var_raw( 'table_info', $params, false ) )
|
5032 |
+
$transient .= '_tableinfo';
|
5033 |
+
|
5034 |
+
if ( is_object( $params ) && isset( $params->post_name ) ) {
|
5035 |
+
$pod = false;
|
5036 |
+
|
5037 |
+
if ( pods_api_cache() )
|
5038 |
+
$pod = pods_transient_get( $transient . '_' . $params->post_name );
|
5039 |
+
|
5040 |
+
if ( false !== $pod && ( pods_var_raw( 'table_info', $params, false ) || isset( $pod[ 'table' ] ) ) ) {
|
5041 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
5042 |
+
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
|
5043 |
+
|
5044 |
+
return $pod;
|
5045 |
+
}
|
5046 |
+
|
5047 |
+
$_pod = get_object_vars( $params );
|
5048 |
+
}
|
5049 |
+
else {
|
5050 |
+
$params = (object) pods_sanitize( $params );
|
5051 |
+
|
5052 |
+
if ( ( !isset( $params->id ) || empty( $params->id ) ) && ( !isset( $params->name ) || empty( $params->name ) ) ) {
|
5053 |
+
if ( $strict )
|
5054 |
+
return pods_error( 'Either Pod ID or Name are required', $this );
|
5055 |
+
|
5056 |
+
return false;
|
5057 |
+
}
|
5058 |
+
|
5059 |
+
if ( isset( $params->name ) ) {
|
5060 |
+
$pod = false;
|
5061 |
+
|
5062 |
+
if ( '_pods_pod' == $params->name ) {
|
5063 |
+
$pod = array(
|
5064 |
+
'id' => 0,
|
5065 |
+
'name' => $params->name,
|
5066 |
+
'label' => __( 'Pods', 'pods' ),
|
5067 |
+
'type' => 'post_type',
|
5068 |
+
'storage' => 'meta',
|
5069 |
+
'options' => array(
|
5070 |
+
'label_singular' => __( 'Pod', 'pods' )
|
5071 |
+
),
|
5072 |
+
'fields' => array()
|
5073 |
+
);
|
5074 |
+
}
|
5075 |
+
elseif ( '_pods_field' == $params->name ) {
|
5076 |
+
$pod = array(
|
5077 |
+
'id' => 0,
|
5078 |
+
'name' => $params->name,
|
5079 |
+
'label' => __( 'Pod Fields', 'pods' ),
|
5080 |
+
'type' => 'post_type',
|
5081 |
+
'storage' => 'meta',
|
5082 |
+
'options' => array(
|
5083 |
+
'label_singular' => __( 'Pod Field', 'pods' )
|
5084 |
+
),
|
5085 |
+
'fields' => array()
|
5086 |
+
);
|
5087 |
+
}
|
5088 |
+
elseif ( pods_api_cache() )
|
5089 |
+
$pod = pods_transient_get( $transient . '_' . $params->name );
|
5090 |
+
|
5091 |
+
if ( false !== $pod && ( pods_var_raw( 'table_info', $params, false ) || isset( $pod[ 'table' ] ) ) ) {
|
5092 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
5093 |
+
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
|
5094 |
+
|
5095 |
+
return $pod;
|
5096 |
+
}
|
5097 |
+
}
|
5098 |
+
|
5099 |
+
if ( !isset( $params->name ) )
|
5100 |
+
$pod = get_post( $dummy = (int) $params->id );
|
5101 |
+
else {
|
5102 |
+
$pod = get_posts( array(
|
5103 |
+
'name' => $params->name,
|
5104 |
+
'post_type' => '_pods_pod',
|
5105 |
+
'posts_per_page' => 1
|
5106 |
+
) );
|
5107 |
+
}
|
5108 |
+
|
5109 |
+
if ( empty( $pod ) ) {
|
5110 |
+
if ( $strict )
|
5111 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
5112 |
+
|
5113 |
+
return false;
|
5114 |
+
}
|
5115 |
+
|
5116 |
+
if ( is_array( $pod ) )
|
5117 |
+
$pod = $pod[ 0 ];
|
5118 |
+
|
5119 |
+
$_pod = get_object_vars( $pod );
|
5120 |
+
}
|
5121 |
+
|
5122 |
+
$pod = false;
|
5123 |
+
|
5124 |
+
if ( pods_api_cache() )
|
5125 |
+
$pod = pods_transient_get( $transient . '_' . $_pod[ 'post_name' ] );
|
5126 |
+
|
5127 |
+
if ( false !== $pod && ( pods_var_raw( 'table_info', $params, false ) || isset( $pod[ 'table' ] ) ) ) {
|
5128 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
5129 |
+
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
|
5130 |
+
|
5131 |
+
return $pod;
|
5132 |
+
}
|
5133 |
+
|
5134 |
+
$pod = array(
|
5135 |
+
'id' => $_pod[ 'ID' ],
|
5136 |
+
'name' => $_pod[ 'post_name' ],
|
5137 |
+
'label' => $_pod[ 'post_title' ],
|
5138 |
+
'description' => $_pod[ 'post_content' ]
|
5139 |
+
);
|
5140 |
+
|
5141 |
+
if ( strlen( $pod[ 'label' ] ) < 1 )
|
5142 |
+
$pod[ 'label' ] = $pod[ 'name' ];
|
5143 |
+
|
5144 |
+
// @todo update with a method to put all options in
|
5145 |
+
$defaults = array(
|
5146 |
+
'show_in_menu' => 1,
|
5147 |
+
'type' => 'post_type',
|
5148 |
+
'storage' => 'meta',
|
5149 |
+
'object' => '',
|
5150 |
+
'alias' => ''
|
5151 |
+
);
|
5152 |
+
|
5153 |
+
$pod[ 'options' ] = get_post_meta( $pod[ 'id' ] );
|
5154 |
+
|
5155 |
+
foreach ( $pod[ 'options' ] as $option => $value ) {
|
5156 |
+
if ( is_array( $value ) ) {
|
5157 |
+
foreach ( $value as $k => $v ) {
|
5158 |
+
if ( !is_array( $v ) )
|
5159 |
+
$value[ $k ] = maybe_unserialize( $v );
|
5160 |
+
}
|
5161 |
+
|
5162 |
+
if ( 1 == count( $value ) )
|
5163 |
+
$value = current( $value );
|
5164 |
+
}
|
5165 |
+
else
|
5166 |
+
$value = maybe_unserialize( $value );
|
5167 |
+
|
5168 |
+
$pod[ 'options' ][ $option ] = $value;
|
5169 |
+
}
|
5170 |
+
|
5171 |
+
$pod[ 'options' ] = array_merge( $defaults, $pod[ 'options' ] );
|
5172 |
+
|
5173 |
+
$pod[ 'type' ] = $pod[ 'options' ][ 'type' ];
|
5174 |
+
$pod[ 'storage' ] = $pod[ 'options' ][ 'storage' ];
|
5175 |
+
$pod[ 'object' ] = $pod[ 'options' ][ 'object' ];
|
5176 |
+
$pod[ 'alias' ] = $pod[ 'options' ][ 'alias' ];
|
5177 |
+
|
5178 |
+
unset( $pod[ 'options' ][ 'type' ] );
|
5179 |
+
unset( $pod[ 'options' ][ 'storage' ] );
|
5180 |
+
unset( $pod[ 'options' ][ 'object' ] );
|
5181 |
+
unset( $pod[ 'options' ][ 'alias' ] );
|
5182 |
+
|
5183 |
+
if ( pods_var_raw( 'table_info', $params, false ) )
|
5184 |
+
$pod = array_merge( $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ), $pod );
|
5185 |
+
|
5186 |
+
if ( isset( $pod[ 'pod' ] ) )
|
5187 |
+
unset( $pod[ 'pod' ] );
|
5188 |
+
|
5189 |
+
$pod[ 'fields' ] = array();
|
5190 |
+
|
5191 |
+
$pod[ 'object_fields' ] = array();
|
5192 |
+
|
5193 |
+
if ( 'pod' != $pod[ 'type' ] )
|
5194 |
+
$pod[ 'object_fields' ] = $this->get_wp_object_fields( $pod[ 'type' ], $pod );
|
5195 |
+
|
5196 |
+
$fields = get_posts( array(
|
5197 |
+
'post_type' => '_pods_field',
|
5198 |
+
'posts_per_page' => -1,
|
5199 |
+
'nopaging' => true,
|
5200 |
+
'post_parent' => $pod[ 'id' ],
|
5201 |
+
'orderby' => 'menu_order',
|
5202 |
+
'order' => 'ASC'
|
5203 |
+
) );
|
5204 |
+
|
5205 |
+
if ( !empty( $fields ) ) {
|
5206 |
+
foreach ( $fields as $field ) {
|
5207 |
+
$field->pod = $pod[ 'name' ];
|
5208 |
+
$field->table_info = (boolean) pods_var_raw( 'table_info', $params, false );
|
5209 |
+
|
5210 |
+
if ( $load_fields ) {
|
5211 |
+
$field = $this->load_field( $field );
|
5212 |
+
|
5213 |
+
$field = PodsForm::field_setup( $field, null, $field[ 'type' ] );
|
5214 |
+
}
|
5215 |
+
else {
|
5216 |
+
$field = array(
|
5217 |
+
'id' => $field->ID,
|
5218 |
+
'name' => $field->post_name,
|
5219 |
+
'label' => $field->post_title,
|
5220 |
+
'type' => get_post_meta( $field->ID, 'type', true )
|
5221 |
+
);
|
5222 |
+
}
|
5223 |
+
|
5224 |
+
$pod[ 'fields' ][ $field[ 'name' ] ] = $field;
|
5225 |
+
}
|
5226 |
+
}
|
5227 |
+
|
5228 |
+
if ( did_action( 'init' ) && pods_api_cache() )
|
5229 |
+
pods_transient_set( $transient . '_' . $pod[ 'name' ], $pod );
|
5230 |
+
|
5231 |
+
return $pod;
|
5232 |
+
}
|
5233 |
+
|
5234 |
+
/**
|
5235 |
+
* Load a list of Pods based on filters specified.
|
5236 |
+
*
|
5237 |
+
* $params['type'] string/array Pod Type(s) to filter by
|
5238 |
+
* $params['object'] string/array Pod Object(s) to filter by
|
5239 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
5240 |
+
* $params['orderby'] string ORDER BY clause of query
|
5241 |
+
* $params['limit'] string Number of Pods to return
|
5242 |
+
* $params['where'] string WHERE clause of query
|
5243 |
+
* $params['ids'] string|array IDs of Objects
|
5244 |
+
* $params['count'] boolean Return only a count of Pods
|
5245 |
+
* $params['names'] boolean Return only an array of name => label
|
5246 |
+
* $params['ids'] boolean Return only an array of ID => label
|
5247 |
+
* $params['fields'] boolean Return pod fields with Pods (default is true)
|
5248 |
+
* $params['key_names'] boolean Return pods keyed by name
|
5249 |
+
*
|
5250 |
+
* @param array $params An associative array of parameters
|
5251 |
+
*
|
5252 |
+
* @return array|mixed
|
5253 |
+
*
|
5254 |
+
* @uses PodsAPI::load_pod
|
5255 |
+
*
|
5256 |
+
* @since 2.0
|
5257 |
+
*/
|
5258 |
+
public function load_pods ( $params = null ) {
|
5259 |
+
|
5260 |
+
/**
|
5261 |
+
* @var $sitepress SitePress
|
5262 |
+
*/
|
5263 |
+
global $sitepress, $icl_adjust_id_url_filter_off;
|
5264 |
+
|
5265 |
+
$current_language = false;
|
5266 |
+
|
5267 |
+
// WPML support
|
5268 |
+
if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
5269 |
+
$current_language = pods_sanitize( ICL_LANGUAGE_CODE );
|
5270 |
+
// Polylang support
|
5271 |
+
elseif ( function_exists( 'pll_current_language' ) )
|
5272 |
+
$current_language = pll_current_language( 'slug' );
|
5273 |
+
|
5274 |
+
$params = (object) pods_sanitize( $params );
|
5275 |
+
|
5276 |
+
$order = 'ASC';
|
5277 |
+
$orderby = 'menu_order title';
|
5278 |
+
$limit = -1;
|
5279 |
+
$ids = false;
|
5280 |
+
|
5281 |
+
$meta_query = array();
|
5282 |
+
$cache_key = '';
|
5283 |
+
|
5284 |
+
if ( isset( $params->type ) && !empty( $params->type ) ) {
|
5285 |
+
if ( !is_array( $params->type ) )
|
5286 |
+
$params->type = array( trim( $params->type ) );
|
5287 |
+
|
5288 |
+
sort( $params->type );
|
5289 |
+
|
5290 |
+
$meta_query[] = array(
|
5291 |
+
'key' => 'type',
|
5292 |
+
'value' => $params->type,
|
5293 |
+
'compare' => 'IN'
|
5294 |
+
);
|
5295 |
+
|
5296 |
+
if ( 1 == count( $params->type ) )
|
5297 |
+
$cache_key .= '_type_' . trim( implode( '', $params->type ) );
|
5298 |
+
}
|
5299 |
+
|
5300 |
+
if ( isset( $params->object ) && !empty( $params->object ) ) {
|
5301 |
+
if ( !is_array( $params->object ) )
|
5302 |
+
$params->object = array( $params->object );
|
5303 |
+
|
5304 |
+
$params->object = pods_trim( $params->object );
|
5305 |
+
|
5306 |
+
sort( $params->object );
|
5307 |
+
|
5308 |
+
$meta_query[] = array(
|
5309 |
+
'key' => 'object',
|
5310 |
+
'value' => $params->object,
|
5311 |
+
'compare' => 'IN'
|
5312 |
+
);
|
5313 |
+
|
5314 |
+
if ( 1 == count( $params->object ) )
|
5315 |
+
$cache_key .= '_object_' . trim( implode( '', $params->object ) );
|
5316 |
+
}
|
5317 |
+
|
5318 |
+
if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
|
5319 |
+
foreach ( $params->options as $option => $value ) {
|
5320 |
+
if ( !is_array( $value ) )
|
5321 |
+
$value = array( $value );
|
5322 |
+
|
5323 |
+
$value = pods_trim( $value );
|
5324 |
+
|
5325 |
+
sort( $value );
|
5326 |
+
|
5327 |
+
$meta_query[] = array(
|
5328 |
+
'key' => $option,
|
5329 |
+
'value' => pods_sanitize( $value ),
|
5330 |
+
'compare' => 'IN'
|
5331 |
+
);
|
5332 |
+
}
|
5333 |
+
|
5334 |
+
$cache_key = '';
|
5335 |
+
}
|
5336 |
+
|
5337 |
+
if ( isset( $params->where ) && is_array( $params->where ) )
|
5338 |
+
$meta_query = array_merge( $meta_query, (array) $params->where );
|
5339 |
+
|
5340 |
+
if ( isset( $params->order ) && !empty( $params->order ) && in_array( strtoupper( $params->order ), array( 'ASC', 'DESC' ) ) )
|
5341 |
+
$order = strtoupper( $params->order );
|
5342 |
+
|
5343 |
+
if ( isset( $params->orderby ) && !empty( $params->orderby ) )
|
5344 |
+
$orderby = strtoupper( $params->orderby );
|
5345 |
+
|
5346 |
+
if ( isset( $params->limit ) && !empty( $params->limit ) )
|
5347 |
+
$limit = pods_absint( $params->limit );
|
5348 |
+
|
5349 |
+
if ( isset( $params->ids ) && !empty( $params->ids ) ) {
|
5350 |
+
$ids = $params->ids;
|
5351 |
+
|
5352 |
+
if ( !is_array( $ids ) )
|
5353 |
+
$ids = explode( ',', $ids );
|
5354 |
+
}
|
5355 |
+
|
5356 |
+
if ( empty( $ids ) )
|
5357 |
+
$ids = false;
|
5358 |
+
|
5359 |
+
$pre_key = '';
|
5360 |
+
|
5361 |
+
if ( !empty( $current_language ) )
|
5362 |
+
$pre_key .= '_' . $current_language;
|
5363 |
+
|
5364 |
+
if ( isset( $params->count ) && $params->count )
|
5365 |
+
$pre_key .= '_count';
|
5366 |
+
|
5367 |
+
if ( isset( $params->ids ) && $params->ids && !empty( $ids ) )
|
5368 |
+
$pre_key .= '_ids_' . implode( '_', $ids );
|
5369 |
+
|
5370 |
+
if ( isset( $params->names ) && $params->names )
|
5371 |
+
$pre_key .= '_names';
|
5372 |
+
elseif ( isset( $params->names_ids ) && $params->names_ids )
|
5373 |
+
$pre_key .= '_names_ids';
|
5374 |
+
|
5375 |
+
if ( isset( $params->key_names ) && $params->key_names )
|
5376 |
+
$pre_key .= '_namekeys';
|
5377 |
+
|
5378 |
+
if ( isset( $params->fields ) && !$params->fields )
|
5379 |
+
$pre_key .= '_nofields';
|
5380 |
+
|
5381 |
+
if ( isset( $params->table_info ) && $params->table_info )
|
5382 |
+
$pre_key .= '_tableinfo';
|
5383 |
+
|
5384 |
+
|
5385 |
+
$pre_key .= '_get';
|
5386 |
+
|
5387 |
+
if ( empty( $cache_key ) )
|
5388 |
+
$cache_key = 'pods' . $pre_key . '_all';
|
5389 |
+
else
|
5390 |
+
$cache_key = 'pods' . $pre_key . $cache_key;
|
5391 |
+
|
5392 |
+
if ( pods_api_cache() && !empty( $cache_key ) && ( 'pods' . ( !empty( $current_language ) ? '_' . $current_language : '' ) . '_get_all' != $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' == $orderby ) && empty( $ids ) ) {
|
5393 |
+
$the_pods = pods_transient_get( $cache_key );
|
5394 |
+
|
5395 |
+
if ( false === $the_pods )
|
5396 |
+
$the_pods = pods_cache_get( $cache_key, 'pods' );
|
5397 |
+
|
5398 |
+
if ( !is_array( $the_pods ) && 'none' == $the_pods )
|
5399 |
+
return array();
|
5400 |
+
elseif ( false !== $the_pods )
|
5401 |
+
return $the_pods;
|
5402 |
+
}
|
5403 |
+
|
5404 |
+
$the_pods = array();
|
5405 |
+
|
5406 |
+
$args = array(
|
5407 |
+
'post_type' => '_pods_pod',
|
5408 |
+
'nopaging' => true,
|
5409 |
+
'posts_per_page' => $limit,
|
5410 |
+
'order' => $order,
|
5411 |
+
'orderby' => $orderby,
|
5412 |
+
'meta_query' => $meta_query,
|
5413 |
+
);
|
5414 |
+
|
5415 |
+
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
5416 |
+
if ( false != $ids ) {
|
5417 |
+
$args[ 'post__in' ] = $ids;
|
5418 |
+
}
|
5419 |
+
|
5420 |
+
$_pods = get_posts( $args );
|
5421 |
+
|
5422 |
+
$export_ignore = array(
|
5423 |
+
'object_type',
|
5424 |
+
'object_name',
|
5425 |
+
'table',
|
5426 |
+
'meta_table',
|
5427 |
+
'pod_table',
|
5428 |
+
'field_id',
|
5429 |
+
'field_index',
|
5430 |
+
'field_slug',
|
5431 |
+
'field_type',
|
5432 |
+
'field_parent',
|
5433 |
+
'field_parent_select',
|
5434 |
+
'meta_field_id',
|
5435 |
+
'meta_field_index',
|
5436 |
+
'meta_field_value',
|
5437 |
+
'pod_field_id',
|
5438 |
+
'pod_field_index',
|
5439 |
+
'object_fields',
|
5440 |
+
'join',
|
5441 |
+
'where',
|
5442 |
+
'where_default',
|
5443 |
+
'orderby',
|
5444 |
+
'pod',
|
5445 |
+
'recurse',
|
5446 |
+
'table_info',
|
5447 |
+
'attributes',
|
5448 |
+
'group',
|
5449 |
+
'grouped',
|
5450 |
+
'developer_mode',
|
5451 |
+
'dependency',
|
5452 |
+
'depends-on',
|
5453 |
+
'excludes-on'
|
5454 |
+
);
|
5455 |
+
|
5456 |
+
$total_fields = 0;
|
5457 |
+
|
5458 |
+
if ( isset( $params->count ) && $params->count )
|
5459 |
+
$the_pods = count( $_pods );
|
5460 |
+
else {
|
5461 |
+
foreach ( $_pods as $pod ) {
|
5462 |
+
if ( isset( $params->names ) && $params->names )
|
5463 |
+
$the_pods[ $pod->post_name ] = $pod->post_title;
|
5464 |
+
elseif ( isset( $params->names_ids ) && $params->names_ids )
|
5465 |
+
$the_pods[ $pod->ID ] = $pod->post_name;
|
5466 |
+
else {
|
5467 |
+
if ( isset( $params->fields ) && !$params->fields )
|
5468 |
+
$pod->fields = false;
|
5469 |
+
|
5470 |
+
$pod = $this->load_pod( $pod );
|
5471 |
+
|
5472 |
+
// Remove extra data not needed
|
5473 |
+
if ( pods_var( 'export', $params, false ) && ( !isset( $params->fields ) || $params->fields ) ) {
|
5474 |
+
foreach ( $export_ignore as $ignore ) {
|
5475 |
+
if ( isset( $pod[ $ignore ] ) )
|
5476 |
+
unset( $pod[ $ignore ] );
|
5477 |
+
}
|
5478 |
+
|
5479 |
+
foreach ( $pod[ 'fields' ] as $field => $field_data ) {
|
5480 |
+
if ( isset( $pod[ 'fields' ][ $field ][ 'table_info' ] ) )
|
5481 |
+
unset( $pod[ 'fields' ][ $field ][ 'table_info' ] );
|
5482 |
+
}
|
5483 |
+
}
|
5484 |
+
|
5485 |
+
$total_fields += count( $pod[ 'fields' ] );
|
5486 |
+
|
5487 |
+
if ( isset( $params->key_names ) && $params->key_names )
|
5488 |
+
$the_pods[ $pod[ 'name' ] ] = $pod;
|
5489 |
+
else
|
5490 |
+
$the_pods[ $pod[ 'id' ] ] = $pod;
|
5491 |
+
}
|
5492 |
+
}
|
5493 |
+
}
|
5494 |
+
|
5495 |
+
if ( ( !function_exists( 'pll_current_language' ) || ( isset( $params->refresh ) && $params->refresh ) ) && !empty( $cache_key ) && ( 'pods' != $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' == $orderby ) && empty( $ids ) ) {
|
5496 |
+
// Too many Pods can cause issues with the DB when caching is not enabled
|
5497 |
+
if ( 15 < count( $the_pods ) || 75 < count( $total_fields ) ) {
|
5498 |
+
pods_transient_clear( $cache_key );
|
5499 |
+
|
5500 |
+
if ( pods_api_cache() ) {
|
5501 |
+
if ( empty( $the_pods ) && ( !isset( $params->count ) || !$params->count ) )
|
5502 |
+
pods_cache_set( $cache_key, 'none', 'pods' );
|
5503 |
+
else
|
5504 |
+
pods_cache_set( $cache_key, $the_pods, 'pods' );
|
5505 |
+
}
|
5506 |
+
}
|
5507 |
+
else {
|
5508 |
+
pods_cache_clear( $cache_key, 'pods' );
|
5509 |
+
|
5510 |
+
if ( pods_api_cache() ) {
|
5511 |
+
if ( empty( $the_pods ) && ( !isset( $params->count ) || !$params->count ) )
|
5512 |
+
pods_transient_set( $cache_key, 'none' );
|
5513 |
+
else
|
5514 |
+
pods_transient_set( $cache_key, $the_pods );
|
5515 |
+
}
|
5516 |
+
}
|
5517 |
+
}
|
5518 |
+
|
5519 |
+
return $the_pods;
|
5520 |
+
}
|
5521 |
+
|
5522 |
+
/**
|
5523 |
+
* Check if a Pod's field exists
|
5524 |
+
*
|
5525 |
+
* $params['pod_id'] int The Pod ID
|
5526 |
+
* $params['id'] int The field ID
|
5527 |
+
* $params['name'] string The field name
|
5528 |
+
*
|
5529 |
+
* @param array $params An associative array of parameters
|
5530 |
+
*
|
5531 |
+
* @return bool
|
5532 |
+
*
|
5533 |
+
* @since 1.12
|
5534 |
+
*/
|
5535 |
+
public function field_exists ( $params ) {
|
5536 |
+
$params = (object) pods_sanitize( $params );
|
5537 |
+
|
5538 |
+
if ( ( !empty( $params->id ) || !empty( $params->name ) ) && isset( $params->pod_id ) && !empty( $params->pod_id ) ) {
|
5539 |
+
if ( !isset( $params->name ) )
|
5540 |
+
$field = get_post( $dummy = (int) $params->id );
|
5541 |
+
else {
|
5542 |
+
$field = get_posts( array(
|
5543 |
+
'name' => $params->name,
|
5544 |
+
'post_type' => '_pods_field',
|
5545 |
+
'posts_per_page' => 1,
|
5546 |
+
'post_parent' => $params->pod_id
|
5547 |
+
) );
|
5548 |
+
}
|
5549 |
+
|
5550 |
+
if ( !empty( $field ) )
|
5551 |
+
return true;
|
5552 |
+
}
|
5553 |
+
|
5554 |
+
return false;
|
5555 |
+
}
|
5556 |
+
|
5557 |
+
/**
|
5558 |
+
* Load a field
|
5559 |
+
*
|
5560 |
+
* $params['pod_id'] int The Pod ID
|
5561 |
+
* $params['pod'] string The Pod name
|
5562 |
+
* $params['id'] int The field ID
|
5563 |
+
* $params['name'] string The field name
|
5564 |
+
* $params['table_info'] boolean Whether to lookup a pick field's table info
|
5565 |
+
*
|
5566 |
+
* @param array $params An associative array of parameters
|
5567 |
+
* @param boolean $strict Whether to require a field exist or not when loading the info
|
5568 |
+
*
|
5569 |
+
* @return array|bool Array with field data, false if field not found
|
5570 |
+
* @since 1.7.9
|
5571 |
+
*/
|
5572 |
+
public function load_field ( $params, $strict = false ) {
|
5573 |
+
$params = (object) $params;
|
5574 |
+
|
5575 |
+
if ( !isset( $params->table_info ) )
|
5576 |
+
$params->table_info = false;
|
5577 |
+
|
5578 |
+
$pod = array();
|
5579 |
+
$field = array();
|
5580 |
+
|
5581 |
+
if ( isset( $params->post_title ) )
|
5582 |
+
$_field = $params;
|
5583 |
+
elseif ( isset( $params->id ) && !empty( $params->id ) )
|
5584 |
+
$_field = get_post( $dumb = (int) $params->id );
|
5585 |
+
else {
|
5586 |
+
if ( !isset( $params->pod ) )
|
5587 |
+
$params->pod = '';
|
5588 |
+
|
5589 |
+
if ( !isset( $params->pod_id ) )
|
5590 |
+
$params->pod_id = 0;
|
5591 |
+
|
5592 |
+
if ( isset( $params->pod_data ) )
|
5593 |
+
$pod = $params->pod_data;
|
5594 |
+
else {
|
5595 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false ), false );
|
5596 |
+
|
5597 |
+
if ( false === $pod ) {
|
5598 |
+
if ( $strict )
|
5599 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
5600 |
+
|
5601 |
+
return false;
|
5602 |
+
}
|
5603 |
+
}
|
5604 |
+
|
5605 |
+
$params->pod_id = $pod[ 'id' ];
|
5606 |
+
$params->pod = $pod[ 'name' ];
|
5607 |
+
|
5608 |
+
if ( empty( $params->name ) && empty( $params->pod ) && empty( $params->pod_id ) )
|
5609 |
+
return pods_error( __( 'Either Field Name or Field ID / Pod ID are required', 'pods' ), $this );
|
5610 |
+
|
5611 |
+
$params->name = pods_clean_name( $params->name, true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
|
5612 |
+
|
5613 |
+
if ( isset( $pod[ 'fields' ][ $params->name ] ) && isset( $pod[ 'fields' ][ $params->name ][ 'id' ] ) )
|
5614 |
+
return $pod[ 'fields' ][ $params->name ];
|
5615 |
+
|
5616 |
+
$field = false;
|
5617 |
+
|
5618 |
+
if ( pods_api_cache() )
|
5619 |
+
$field = pods_transient_get( 'pods_field_' . $params->pod . '_' . $params->name );
|
5620 |
+
|
5621 |
+
if ( empty( $field ) ) {
|
5622 |
+
$field = get_posts( array(
|
5623 |
+
'name' => $params->name,
|
5624 |
+
'post_type' => '_pods_field',
|
5625 |
+
'posts_per_page' => 1,
|
5626 |
+
'post_parent' => $params->pod_id
|
5627 |
+
) );
|
5628 |
+
|
5629 |
+
if ( empty( $field ) ) {
|
5630 |
+
if ( $strict )
|
5631 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
5632 |
+
|
5633 |
+
return false;
|
5634 |
+
}
|
5635 |
+
|
5636 |
+
$_field = $field[ 0 ];
|
5637 |
+
|
5638 |
+
$field = array();
|
5639 |
+
}
|
5640 |
+
}
|
5641 |
+
|
5642 |
+
if ( empty( $_field ) ) {
|
5643 |
+
if ( $strict )
|
5644 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
5645 |
+
|
5646 |
+
return false;
|
5647 |
+
}
|
5648 |
+
|
5649 |
+
$_field = get_object_vars( $_field );
|
5650 |
+
|
5651 |
+
if ( !isset( $pod[ 'name' ] ) && !isset( $_field[ 'pod' ] ) ) {
|
5652 |
+
if ( 0 < $_field[ 'post_parent' ] )
|
5653 |
+
$pod = $this->load_pod( array( 'id' => $_field[ 'post_parent' ], 'table_info' => false ), false );
|
5654 |
+
|
5655 |
+
if ( empty( $pod ) ) {
|
5656 |
+
if ( $strict )
|
5657 |
+
return pods_error( __( 'Pod for field not found', 'pods' ), $this );
|
5658 |
+
|
5659 |
+
return false;
|
5660 |
+
}
|
5661 |
+
}
|
5662 |
+
|
5663 |
+
if ( empty( $field ) ) {
|
5664 |
+
if ( pods_api_cache() && ( isset( $pod[ 'name' ] ) || isset( $_field[ 'pod' ] ) ) )
|
5665 |
+
$field = pods_transient_get( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $_field[ 'post_name' ] );
|
5666 |
+
|
5667 |
+
if ( empty( $field ) ) {
|
5668 |
+
$defaults = array(
|
5669 |
+
'type' => 'text'
|
5670 |
+
);
|
5671 |
+
|
5672 |
+
$field = array(
|
5673 |
+
'id' => $_field[ 'ID' ],
|
5674 |
+
'name' => $_field[ 'post_name' ],
|
5675 |
+
'label' => $_field[ 'post_title' ],
|
5676 |
+
'description' => $_field[ 'post_content' ],
|
5677 |
+
'weight' => $_field[ 'menu_order' ],
|
5678 |
+
'pod_id' => $_field[ 'post_parent' ],
|
5679 |
+
'pick_object' => '',
|
5680 |
+
'pick_val' => '',
|
5681 |
+
'sister_id' => '',
|
5682 |
+
'table_info' => array()
|
5683 |
+
);
|
5684 |
+
|
5685 |
+
if ( isset( $pod[ 'name' ] ) )
|
5686 |
+
$field[ 'pod' ] = $pod[ 'name' ];
|
5687 |
+
elseif ( isset( $_field[ 'pod' ] ) )
|
5688 |
+
$field[ 'pod' ] = $_field[ 'pod' ];
|
5689 |
+
|
5690 |
+
$field[ 'options' ] = get_post_meta( $field[ 'id' ] );
|
5691 |
+
|
5692 |
+
$options_ignore = array(
|
5693 |
+
'method',
|
5694 |
+
'table_info',
|
5695 |
+
'attributes',
|
5696 |
+
'group',
|
5697 |
+
'grouped',
|
5698 |
+
'developer_mode',
|
5699 |
+
'dependency',
|
5700 |
+
'depends-on',
|
5701 |
+
'excludes-on'
|
5702 |
+
);
|
5703 |
+
|
5704 |
+
foreach ( $options_ignore as $ignore ) {
|
5705 |
+
if ( isset( $field[ 'options' ][ $ignore ] ) )
|
5706 |
+
unset( $field[ 'options' ][ $ignore ] );
|
5707 |
+
}
|
5708 |
+
|
5709 |
+
foreach ( $field[ 'options' ] as $option => $value ) {
|
5710 |
+
if ( is_array( $value ) ) {
|
5711 |
+
foreach ( $value as $k => $v ) {
|
5712 |
+
if ( !is_array( $v ) )
|
5713 |
+
$value[ $k ] = maybe_unserialize( $v );
|
5714 |
+
}
|
5715 |
+
|
5716 |
+
if ( 1 == count( $value ) )
|
5717 |
+
$value = current( $value );
|
5718 |
+
}
|
5719 |
+
else
|
5720 |
+
$value = maybe_unserialize( $value );
|
5721 |
+
|
5722 |
+
$field[ 'options' ][ $option ] = $value;
|
5723 |
+
}
|
5724 |
+
|
5725 |
+
$field[ 'options' ] = array_merge( $defaults, $field[ 'options' ] );
|
5726 |
+
|
5727 |
+
$field[ 'type' ] = $field[ 'options' ][ 'type' ];
|
5728 |
+
|
5729 |
+
unset( $field[ 'options' ][ 'type' ] );
|
5730 |
+
|
5731 |
+
if ( isset( $field[ 'options' ][ 'pick_object' ] ) ) {
|
5732 |
+
$field[ 'pick_object' ] = $field[ 'options' ][ 'pick_object' ];
|
5733 |
+
|
5734 |
+
unset( $field[ 'options' ][ 'pick_object' ] );
|
5735 |
+
}
|
5736 |
+
|
5737 |
+
if ( isset( $field[ 'options' ][ 'pick_val' ] ) ) {
|
5738 |
+
$field[ 'pick_val' ] = $field[ 'options' ][ 'pick_val' ];
|
5739 |
+
|
5740 |
+
unset( $field[ 'options' ][ 'pick_val' ] );
|
5741 |
+
}
|
5742 |
+
|
5743 |
+
if ( isset( $field[ 'options' ][ 'sister_id' ] ) ) {
|
5744 |
+
$field[ 'sister_id' ] = $field[ 'options' ][ 'sister_id' ];
|
5745 |
+
|
5746 |
+
unset( $field[ 'options' ][ 'sister_id' ] );
|
5747 |
+
}
|
5748 |
+
|
5749 |
+
if ( isset( $field[ 'options' ][ 'sister_field_id' ] ) )
|
5750 |
+
unset( $field[ 'options' ][ 'sister_field_id' ] );
|
5751 |
+
|
5752 |
+
if ( pods_api_cache() && ( isset( $pod[ 'name' ] ) || isset( $_field[ 'pod' ] ) ) )
|
5753 |
+
pods_transient_set( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $field[ 'name' ], $field );
|
5754 |
+
}
|
5755 |
+
}
|
5756 |
+
|
5757 |
+
$field[ 'table_info' ] = array();
|
5758 |
+
|
5759 |
+
if ( 'pick' == $field[ 'type' ] && $params->table_info )
|
5760 |
+
$field[ 'table_info' ] = $this->get_table_info( $field[ 'pick_object' ], $field[ 'pick_val' ], null, null, $field );
|
5761 |
+
|
5762 |
+
return $field;
|
5763 |
+
}
|
5764 |
+
|
5765 |
+
/**
|
5766 |
+
* Load fields by Pod, ID, Name, and/or Type
|
5767 |
+
*
|
5768 |
+
* $params['pod_id'] int The Pod ID
|
5769 |
+
* $params['pod'] string The Pod name
|
5770 |
+
* $params['id'] array The field IDs
|
5771 |
+
* $params['name'] array The field names
|
5772 |
+
* $params['type'] array The field types
|
5773 |
+
* $params['options'] array Field Option(s) key=>value array to filter by
|
5774 |
+
* $params['where'] string WHERE clause of query
|
5775 |
+
*
|
5776 |
+
* @param array $params An associative array of parameters
|
5777 |
+
* @param bool $strict Whether to require a field exist or not when loading the info
|
5778 |
+
*
|
5779 |
+
* @return array Array of field data.
|
5780 |
+
*
|
5781 |
+
* @since 1.7.9
|
5782 |
+
*/
|
5783 |
+
public function load_fields ( $params, $strict = false ) {
|
5784 |
+
$params = (object) pods_sanitize( $params );
|
5785 |
+
|
5786 |
+
if ( !isset( $params->pod ) || empty( $params->pod ) )
|
5787 |
+
$params->pod = '';
|
5788 |
+
|
5789 |
+
if ( !isset( $params->pod_id ) || empty( $params->pod_id ) )
|
5790 |
+
$params->pod_id = 0;
|
5791 |
+
|
5792 |
+
if ( !isset( $params->name ) || empty( $params->name ) )
|
5793 |
+
$params->name = array();
|
5794 |
+
else
|
5795 |
+
$params->name = (array) $params->name;
|
5796 |
+
|
5797 |
+
if ( !isset( $params->id ) || empty( $params->id ) )
|
5798 |
+
$params->id = array();
|
5799 |
+
else {
|
5800 |
+
$params->id = (array) $params->id;
|
5801 |
+
|
5802 |
+
foreach ( $params->id as &$id ) {
|
5803 |
+
$id = pods_absint( $id );
|
5804 |
+
}
|
5805 |
+
}
|
5806 |
+
|
5807 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
5808 |
+
$params->type = array();
|
5809 |
+
else
|
5810 |
+
$params->type = (array) $params->type;
|
5811 |
+
|
5812 |
+
$fields = array();
|
5813 |
+
|
5814 |
+
if ( !empty( $params->pod ) || !empty( $params->pod_id ) ) {
|
5815 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => true ), false );
|
5816 |
+
|
5817 |
+
if ( false === $pod ) {
|
5818 |
+
if ( $strict )
|
5819 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
5820 |
+
|
5821 |
+
return $fields;
|
5822 |
+
}
|
5823 |
+
|
5824 |
+
$pod[ 'fields' ] = array_merge( pods_var_raw( 'object_fields', $pod, array() ), $pod[ 'fields' ] );
|
5825 |
+
|
5826 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
5827 |
+
if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
|
5828 |
+
$fields[ $field[ 'name' ] ] = $field;
|
5829 |
+
elseif ( in_array( $fields[ 'name' ], $params->name ) || in_array( $fields[ 'id' ], $params->id ) || in_array( $fields[ 'type' ], $params->type ) )
|
5830 |
+
$fields[ $field[ 'name' ] ] = $field;
|
5831 |
+
}
|
5832 |
+
}
|
5833 |
+
elseif ( ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) || ( isset( $params->where ) && !empty( $params->where ) && is_array( $params->where ) ) ) {
|
5834 |
+
$order = 'ASC';
|
5835 |
+
$orderby = 'menu_order title';
|
5836 |
+
$limit = -1;
|
5837 |
+
$ids = false;
|
5838 |
+
|
5839 |
+
$meta_query = array();
|
5840 |
+
|
5841 |
+
if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
|
5842 |
+
foreach ( $params->options as $option => $value ) {
|
5843 |
+
if ( !is_array( $value ) )
|
5844 |
+
$value = array( $value );
|
5845 |
+
|
5846 |
+
$value = pods_trim( $value );
|
5847 |
+
|
5848 |
+
sort( $value );
|
5849 |
+
|
5850 |
+
$meta_query[] = array(
|
5851 |
+
'key' => $option,
|
5852 |
+
'value' => pods_sanitize( $value ),
|
5853 |
+
'compare' => 'IN'
|
5854 |
+
);
|
5855 |
+
}
|
5856 |
+
}
|
5857 |
+
|
5858 |
+
if ( isset( $params->where ) && !empty( $params->where ) && is_array( $params->where ) )
|
5859 |
+
$meta_query = array_merge( $meta_query, (array) $params->where );
|
5860 |
+
|
5861 |
+
$args = array(
|
5862 |
+
'post_type' => '_pods_field',
|
5863 |
+
'nopaging' => true,
|
5864 |
+
'posts_per_page' => $limit,
|
5865 |
+
'order' => $order,
|
5866 |
+
'orderby' => $orderby,
|
5867 |
+
'meta_query' => $meta_query,
|
5868 |
+
);
|
5869 |
+
|
5870 |
+
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
5871 |
+
if ( false != $ids ) {
|
5872 |
+
$args[ 'post__in' ] = $ids;
|
5873 |
+
}
|
5874 |
+
|
5875 |
+
$fields = false;
|
5876 |
+
|
5877 |
+
if ( pods_api_cache() )
|
5878 |
+
$fields = pods_cache_get( md5( json_encode( $args ) ), 'pods_load_fields' );
|
5879 |
+
|
5880 |
+
if ( false !== $fields )
|
5881 |
+
return $fields;
|
5882 |
+
|
5883 |
+
$fields = array();
|
5884 |
+
|
5885 |
+
$_fields = get_posts( $args );
|
5886 |
+
|
5887 |
+
foreach ( $_fields as $field ) {
|
5888 |
+
$field = $this->load_field( $field, false );
|
5889 |
+
|
5890 |
+
if ( !empty( $field ) )
|
5891 |
+
$fields[ $field[ 'id' ] ] = $field;
|
5892 |
+
}
|
5893 |
+
|
5894 |
+
if ( pods_api_cache() )
|
5895 |
+
pods_cache_set( md5( json_encode( $args ) ), $fields, 'pods_load_fields' );
|
5896 |
+
}
|
5897 |
+
else {
|
5898 |
+
if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
|
5899 |
+
return pods_error( __( 'Either Field Name / Field ID / Field Type, or Pod Name / Pod ID are required', 'pods' ), $this );
|
5900 |
+
|
5901 |
+
$lookup = array();
|
5902 |
+
|
5903 |
+
if ( !empty( $params->name ) ) {
|
5904 |
+
$fields = implode( "', '", $params->name );
|
5905 |
+
|
5906 |
+
$lookup[] = "`post_name` IN ( '{$fields}' )";
|
5907 |
+
}
|
5908 |
+
|
5909 |
+
if ( !empty( $params->id ) ) {
|
5910 |
+
$fields = implode( ", ", $params->id );
|
5911 |
+
|
5912 |
+
$lookup[] = "`ID` IN ( {$fields} )";
|
5913 |
+
}
|
5914 |
+
|
5915 |
+
$lookup = implode( ' AND ', $lookup );
|
5916 |
+
|
5917 |
+
$fields = false;
|
5918 |
+
|
5919 |
+
if ( pods_api_cache() )
|
5920 |
+
$fields = pods_cache_get( md5( $lookup ), 'pods_load_fields' );
|
5921 |
+
|
5922 |
+
if ( false !== $fields )
|
5923 |
+
return $fields;
|
5924 |
+
|
5925 |
+
$result = pods_query( "SELECT `ID`, `post_name`, `post_parent` FROM `@wp_posts` WHERE `post_type` = '_pods_field' AND ( {$lookup} )" );
|
5926 |
+
|
5927 |
+
$fields = array();
|
5928 |
+
|
5929 |
+
if ( !empty( $result ) ) {
|
5930 |
+
foreach ( $result as $field ) {
|
5931 |
+
$field = $this->load_field( array(
|
5932 |
+
'id' => $field->ID,
|
5933 |
+
'name' => $field->post_name,
|
5934 |
+
'pod_id' => $field->post_parent
|
5935 |
+
), false );
|
5936 |
+
|
5937 |
+
if ( !empty( $field ) && ( empty( $params->type ) || in_array( $field[ 'type' ], $params->type ) ) )
|
5938 |
+
$fields[ $field[ 'id' ] ] = $field;
|
5939 |
+
}
|
5940 |
+
}
|
5941 |
+
|
5942 |
+
if ( pods_api_cache() )
|
5943 |
+
pods_cache_set( md5( $lookup ), $fields, 'pods_load_fields' );
|
5944 |
+
}
|
5945 |
+
|
5946 |
+
return $fields;
|
5947 |
+
}
|
5948 |
+
|
5949 |
+
/**
|
5950 |
+
* Load a Pods Object
|
5951 |
+
*
|
5952 |
+
* $params['id'] int The Object ID
|
5953 |
+
* $params['name'] string The Object name
|
5954 |
+
* $params['type'] string The Object type
|
5955 |
+
*
|
5956 |
+
* @param array|object $params An associative array of parameters
|
5957 |
+
* @param bool $strict
|
5958 |
+
*
|
5959 |
+
* @return array|bool
|
5960 |
+
* @since 2.0
|
5961 |
+
*/
|
5962 |
+
public function load_object ( $params, $strict = false ) {
|
5963 |
+
if ( is_object( $params ) && isset( $params->post_title ) )
|
5964 |
+
$_object = get_object_vars( $params );
|
5965 |
+
else {
|
5966 |
+
$params = (object) pods_sanitize( $params );
|
5967 |
+
|
5968 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
5969 |
+
return pods_error( __( 'Object type is required', 'pods' ), $this );
|
5970 |
+
|
5971 |
+
if ( ( !isset( $params->id ) || empty( $params->id ) ) && ( !isset( $params->name ) || empty( $params->name ) ) )
|
5972 |
+
return pods_error( __( 'Either Object ID or Name are required', 'pods' ), $this );
|
5973 |
+
|
5974 |
+
/**
|
5975 |
+
* @var $wpdb wpdb
|
5976 |
+
*/
|
5977 |
+
global $wpdb;
|
5978 |
+
|
5979 |
+
if ( isset( $params->name ) )
|
5980 |
+
$_object = pods_by_title( $params->name, ARRAY_A, '_pods_' . $params->type, 'publish' );
|
5981 |
+
else {
|
5982 |
+
$object = $params->id;
|
5983 |
+
|
5984 |
+
$_object = get_post( $object, ARRAY_A );
|
5985 |
+
}
|
5986 |
+
|
5987 |
+
if ( empty( $_object ) ) {
|
5988 |
+
if ( $strict )
|
5989 |
+
return pods_error( __( 'Object not found', 'pods' ), $this );
|
5990 |
+
|
5991 |
+
return false;
|
5992 |
+
}
|
5993 |
+
}
|
5994 |
+
|
5995 |
+
$object = array(
|
5996 |
+
'id' => $_object[ 'ID' ],
|
5997 |
+
'name' => $_object[ 'post_title' ],
|
5998 |
+
'code' => $_object[ 'post_content' ],
|
5999 |
+
'type' => str_replace( '_pods_', '', $_object[ 'post_type' ] ),
|
6000 |
+
'slug' => $_object[ 'post_name' ]
|
6001 |
+
);
|
6002 |
+
|
6003 |
+
$object[ 'options' ] = get_post_meta( $object[ 'id' ] );
|
6004 |
+
|
6005 |
+
foreach ( $object[ 'options' ] as $option => &$value ) {
|
6006 |
+
if ( is_array( $value ) && 1 == count( $value ) )
|
6007 |
+
$value = current( $value );
|
6008 |
+
}
|
6009 |
+
|
6010 |
+
return $object;
|
6011 |
+
}
|
6012 |
+
|
6013 |
+
/**
|
6014 |
+
* Load Multiple Pods Objects
|
6015 |
+
*
|
6016 |
+
* $params['type'] string The Object type
|
6017 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
6018 |
+
* $params['orderby'] string ORDER BY clause of query
|
6019 |
+
* $params['limit'] string Number of objects to return
|
6020 |
+
* $params['where'] string WHERE clause of query
|
6021 |
+
* $params['ids'] string|array IDs of Objects
|
6022 |
+
*
|
6023 |
+
* @param array|object $params An associative array of parameters
|
6024 |
+
*
|
6025 |
+
* @return array
|
6026 |
+
* @since 2.0
|
6027 |
+
*/
|
6028 |
+
public function load_objects ( $params ) {
|
6029 |
+
$params = (object) pods_sanitize( $params );
|
6030 |
+
|
6031 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
6032 |
+
return pods_error( __( 'Pods Object type is required', 'pods' ), $this );
|
6033 |
+
|
6034 |
+
$order = 'ASC';
|
6035 |
+
$orderby = 'menu_order';
|
6036 |
+
$limit = -1;
|
6037 |
+
$ids = false;
|
6038 |
+
|
6039 |
+
$meta_query = array();
|
6040 |
+
$cache_key = '';
|
6041 |
+
|
6042 |
+
if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
|
6043 |
+
foreach ( $params->options as $option => $value ) {
|
6044 |
+
if ( !is_array( $value ) )
|
6045 |
+
$value = array( $value );
|
6046 |
+
|
6047 |
+
$value = pods_trim( $value );
|
6048 |
+
|
6049 |
+
sort( $value );
|
6050 |
+
|
6051 |
+
$meta_query[] = array(
|
6052 |
+
'key' => $option,
|
6053 |
+
'value' => pods_sanitize( $value ),
|
6054 |
+
'compare' => 'IN'
|
6055 |
+
);
|
6056 |
+
}
|
6057 |
+
}
|
6058 |
+
|
6059 |
+
if ( isset( $params->where ) && is_array( $params->where ) )
|
6060 |
+
$meta_query = array_merge( $meta_query, (array) $params->where );
|
6061 |
+
|
6062 |
+
if ( isset( $params->order ) && !empty( $params->order ) && in_array( strtoupper( $params->order ), array( 'ASC', 'DESC' ) ) )
|
6063 |
+
$order = strtoupper( $params->order );
|
6064 |
+
|
6065 |
+
if ( isset( $params->orderby ) && !empty( $params->orderby ) )
|
6066 |
+
$orderby = strtoupper( $params->orderby );
|
6067 |
+
|
6068 |
+
if ( isset( $params->limit ) && !empty( $params->limit ) )
|
6069 |
+
$limit = pods_absint( $params->limit );
|
6070 |
+
|
6071 |
+
if ( isset( $params->ids ) && !empty( $params->ids ) ) {
|
6072 |
+
$ids = $params->ids;
|
6073 |
+
|
6074 |
+
if ( !is_array( $ids ) )
|
6075 |
+
$ids = explode( ',', $ids );
|
6076 |
+
}
|
6077 |
+
|
6078 |
+
if ( empty( $ids ) )
|
6079 |
+
$ids = false;
|
6080 |
+
|
6081 |
+
if ( pods_api_cache() && empty( $meta_query ) && empty( $limit ) && ( empty( $orderby ) || 'menu_order' == $orderby ) && empty( $ids ) ) {
|
6082 |
+
$cache_key = 'pods_objects_' . $params->type;
|
6083 |
+
|
6084 |
+
$the_objects = pods_transient_get( $cache_key );
|
6085 |
+
|
6086 |
+
if ( false !== $the_objects )
|
6087 |
+
return $the_objects;
|
6088 |
+
}
|
6089 |
+
|
6090 |
+
$the_objects = array();
|
6091 |
+
|
6092 |
+
$args = array(
|
6093 |
+
'post_type' => '_pods_' . $params->type,
|
6094 |
+
'nopaging' => true,
|
6095 |
+
'posts_per_page' => $limit,
|
6096 |
+
'order' => $order,
|
6097 |
+
'orderby' => $orderby,
|
6098 |
+
'meta_query' => $meta_query,
|
6099 |
+
);
|
6100 |
+
|
6101 |
+
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
6102 |
+
if ( false != $ids ) {
|
6103 |
+
$args[ 'post__in' ] = $ids;
|
6104 |
+
}
|
6105 |
+
|
6106 |
+
$objects = get_posts( $args );
|
6107 |
+
|
6108 |
+
foreach ( $objects as $object ) {
|
6109 |
+
$object = $this->load_object( $object );
|
6110 |
+
|
6111 |
+
$the_objects[ $object[ 'name' ] ] = $object;
|
6112 |
+
}
|
6113 |
+
|
6114 |
+
if ( pods_api_cache() && !empty( $cache_key ) )
|
6115 |
+
pods_transient_set( $cache_key, $the_objects );
|
6116 |
+
|
6117 |
+
return $the_objects;
|
6118 |
+
}
|
6119 |
+
|
6120 |
+
/**
|
6121 |
+
* @see PodsAPI::load_object
|
6122 |
+
*
|
6123 |
+
* Load a Pod Template
|
6124 |
+
*
|
6125 |
+
* $params['id'] int The template ID
|
6126 |
+
* $params['name'] string The template name
|
6127 |
+
*
|
6128 |
+
* @param array $params An associative array of parameters
|
6129 |
+
*
|
6130 |
+
* @return array|bool
|
6131 |
+
* @since 1.7.9
|
6132 |
+
*/
|
6133 |
+
public function load_template ( $params ) {
|
6134 |
+
if ( !class_exists( 'Pods_Templates' ) )
|
6135 |
+
return false;
|
6136 |
+
|
6137 |
+
$params = (object) $params;
|
6138 |
+
$params->type = 'template';
|
6139 |
+
return $this->load_object( $params );
|
6140 |
+
}
|
6141 |
+
|
6142 |
+
/**
|
6143 |
+
* @see PodsAPI::load_objects
|
6144 |
+
*
|
6145 |
+
* Load Multiple Pod Templates
|
6146 |
+
*
|
6147 |
+
* $params['where'] string The WHERE clause of query
|
6148 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
6149 |
+
* $params['orderby'] string ORDER BY clause of query
|
6150 |
+
* $params['limit'] string Number of templates to return
|
6151 |
+
*
|
6152 |
+
* @param array $params (optional) An associative array of parameters
|
6153 |
+
*
|
6154 |
+
* @return array
|
6155 |
+
*
|
6156 |
+
* @since 2.0
|
6157 |
+
*/
|
6158 |
+
public function load_templates ( $params = null ) {
|
6159 |
+
if ( !class_exists( 'Pods_Templates' ) )
|
6160 |
+
return array();
|
6161 |
+
|
6162 |
+
$params = (object) $params;
|
6163 |
+
$params->type = 'template';
|
6164 |
+
return $this->load_objects( $params );
|
6165 |
+
}
|
6166 |
+
|
6167 |
+
/**
|
6168 |
+
* @see PodsAPI::load_object
|
6169 |
+
*
|
6170 |
+
* Load a Pod Page
|
6171 |
+
*
|
6172 |
+
* $params['id'] int The page ID
|
6173 |
+
* $params['name'] string The page URI
|
6174 |
+
*
|
6175 |
+
* @param array $params An associative array of parameters
|
6176 |
+
*
|
6177 |
+
* @return array|bool
|
6178 |
+
*
|
6179 |
+
* @since 1.7.9
|
6180 |
+
*/
|
6181 |
+
public function load_page ( $params ) {
|
6182 |
+
if ( !class_exists( 'Pods_Pages' ) )
|
6183 |
+
return false;
|
6184 |
+
|
6185 |
+
$params = (object) $params;
|
6186 |
+
if ( !isset( $params->name ) && isset( $params->uri ) ) {
|
6187 |
+
$params->name = $params->uri;
|
6188 |
+
unset( $params->uri );
|
6189 |
+
}
|
6190 |
+
$params->type = 'page';
|
6191 |
+
return $this->load_object( $params );
|
6192 |
+
}
|
6193 |
+
|
6194 |
+
/**
|
6195 |
+
* @see PodsAPI::load_objects
|
6196 |
+
*
|
6197 |
+
* Load Multiple Pod Pages
|
6198 |
+
*
|
6199 |
+
* $params['where'] string The WHERE clause of query
|
6200 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
6201 |
+
* $params['orderby'] string ORDER BY clause of query
|
6202 |
+
* $params['limit'] string Number of pages to return
|
6203 |
+
*
|
6204 |
+
* @param array $params (optional) An associative array of parameters
|
6205 |
+
*
|
6206 |
+
* @return array
|
6207 |
+
*
|
6208 |
+
* @since 2.0
|
6209 |
+
*/
|
6210 |
+
public function load_pages ( $params = null ) {
|
6211 |
+
if ( !class_exists( 'Pods_Pages' ) )
|
6212 |
+
return array();
|
6213 |
+
|
6214 |
+
$params = (object) $params;
|
6215 |
+
$params->type = 'page';
|
6216 |
+
return $this->load_objects( $params );
|
6217 |
+
}
|
6218 |
+
|
6219 |
+
/**
|
6220 |
+
* @see PodsAPI::load_object
|
6221 |
+
*
|
6222 |
+
* Load a Pod Helper
|
6223 |
+
*
|
6224 |
+
* $params['id'] int The helper ID
|
6225 |
+
* $params['name'] string The helper name
|
6226 |
+
*
|
6227 |
+
* @param array $params An associative array of parameters
|
6228 |
+
*
|
6229 |
+
* @return array|bool
|
6230 |
+
*
|
6231 |
+
* @since 1.7.9
|
6232 |
+
*/
|
6233 |
+
public function load_helper ( $params ) {
|
6234 |
+
if ( !class_exists( 'Pods_Helpers' ) )
|
6235 |
+
return false;
|
6236 |
+
|
6237 |
+
$params = (object) $params;
|
6238 |
+
$params->type = 'helper';
|
6239 |
+
return $this->load_object( $params );
|
6240 |
+
}
|
6241 |
+
|
6242 |
+
/**
|
6243 |
+
* @see PodsAPI::load_objects
|
6244 |
+
*
|
6245 |
+
* Load Multiple Pod Helpers
|
6246 |
+
*
|
6247 |
+
* $params['where'] string The WHERE clause of query
|
6248 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
6249 |
+
* $params['orderby'] string ORDER BY clause of query
|
6250 |
+
* $params['limit'] string Number of pages to return
|
6251 |
+
*
|
6252 |
+
* @param array $params (optional) An associative array of parameters
|
6253 |
+
*
|
6254 |
+
* @return array
|
6255 |
+
*
|
6256 |
+
* @since 2.0
|
6257 |
+
*/
|
6258 |
+
public function load_helpers ( $params = null ) {
|
6259 |
+
if ( !class_exists( 'Pods_Helpers' ) )
|
6260 |
+
return array();
|
6261 |
+
|
6262 |
+
$params = (object) $params;
|
6263 |
+
$params->type = 'helper';
|
6264 |
+
return $this->load_objects( $params );
|
6265 |
+
}
|
6266 |
+
|
6267 |
+
/**
|
6268 |
+
* Load the pod item object
|
6269 |
+
*
|
6270 |
+
* $params['pod'] string The datatype name
|
6271 |
+
* $params['id'] int (optional) The item's ID
|
6272 |
+
*
|
6273 |
+
* @param array $params An associative array of parameters
|
6274 |
+
*
|
6275 |
+
* @return bool|\Pods
|
6276 |
+
*
|
6277 |
+
* @uses pods()
|
6278 |
+
*
|
6279 |
+
* @since 2.0
|
6280 |
+
*/
|
6281 |
+
public function load_pod_item ( $params ) {
|
6282 |
+
$params = (object) pods_sanitize( $params );
|
6283 |
+
|
6284 |
+
if ( !isset( $params->pod ) || empty( $params->pod ) )
|
6285 |
+
return pods_error( __( 'Pod name required', 'pods' ), $this );
|
6286 |
+
if ( !isset( $params->id ) || empty( $params->id ) )
|
6287 |
+
return pods_error( __( 'Item ID required', 'pods' ), $this );
|
6288 |
+
|
6289 |
+
$pod = false;
|
6290 |
+
|
6291 |
+
if ( pods_api_cache() )
|
6292 |
+
$pod = pods_cache_get( $params->id, 'pods_item_object_' . $params->pod );
|
6293 |
+
|
6294 |
+
if ( false !== $pod )
|
6295 |
+
return $pod;
|
6296 |
+
|
6297 |
+
$pod = pods( $params->pod, $params->id );
|
6298 |
+
|
6299 |
+
if ( pods_api_cache() )
|
6300 |
+
pods_cache_set( $params->id, $pod, 'pods_item_object_' . $params->pod );
|
6301 |
+
|
6302 |
+
return $pod;
|
6303 |
+
}
|
6304 |
+
|
6305 |
+
/**
|
6306 |
+
* Load potential sister fields for a specific field
|
6307 |
+
*
|
6308 |
+
* $params['pod'] int The Pod name
|
6309 |
+
* $params['related_pod'] string The related Pod name
|
6310 |
+
*
|
6311 |
+
* @param array $params An associative array of parameters
|
6312 |
+
* @param array $pod (optional) Array of Pod data to use (to avoid lookup)
|
6313 |
+
*
|
6314 |
+
* @return array|bool
|
6315 |
+
*
|
6316 |
+
* @since 1.7.9
|
6317 |
+
*
|
6318 |
+
* @uses PodsAPI::load_pod
|
6319 |
+
*/
|
6320 |
+
public function load_sister_fields ( $params, $pod = null ) {
|
6321 |
+
$params = (object) pods_sanitize( $params );
|
6322 |
+
|
6323 |
+
if ( empty( $pod ) ) {
|
6324 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => false ), false );
|
6325 |
+
|
6326 |
+
if ( false === $pod )
|
6327 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
6328 |
+
}
|
6329 |
+
|
6330 |
+
$params->pod_id = $pod[ 'id' ];
|
6331 |
+
$params->pod = $pod[ 'name' ];
|
6332 |
+
|
6333 |
+
$type = false;
|
6334 |
+
|
6335 |
+
if ( 0 === strpos( $params->related_pod, 'pod-' ) ) {
|
6336 |
+
$params->related_pod = pods_str_replace( 'pod-', '', $params->related_pod, 1 );
|
6337 |
+
$type = 'pod';
|
6338 |
+
}
|
6339 |
+
elseif ( 0 === strpos( $params->related_pod, 'post_type-' ) ) {
|
6340 |
+
$params->related_pod = pods_str_replace( 'post_type-', '', $params->related_pod, 1 );
|
6341 |
+
$type = 'post_type';
|
6342 |
+
}
|
6343 |
+
elseif ( 0 === strpos( $params->related_pod, 'taxonomy-' ) ) {
|
6344 |
+
$params->related_pod = pods_str_replace( 'taxonomy-', '', $params->related_pod, 1 );
|
6345 |
+
$type = 'taxonomy';
|
6346 |
+
}
|
6347 |
+
|
6348 |
+
$related_pod = $this->load_pod( array( 'name' => $params->related_pod, 'table_info' => false ), false );
|
6349 |
+
|
6350 |
+
if ( false === $related_pod || ( false !== $type && 'pod' != $type && $type != $related_pod[ 'type' ] ) )
|
6351 |
+
return pods_error( __( 'Related Pod not found', 'pods' ), $this );
|
6352 |
+
|
6353 |
+
$params->related_pod_id = $related_pod[ 'id' ];
|
6354 |
+
$params->related_pod = $related_pod[ 'name' ];
|
6355 |
+
|
6356 |
+
$sister_fields = array();
|
6357 |
+
|
6358 |
+
foreach ( $related_pod[ 'fields' ] as $field ) {
|
6359 |
+
if ( 'pick' == $field[ 'type' ] && in_array( $field[ 'pick_object' ], array( $pod[ 'type' ], 'pod' ) ) && ( $params->pod == $field[ 'pick_object' ] || $params->pod == $field[ 'pick_val' ] ) )
|
6360 |
+
$sister_fields[ $field[ 'id' ] ] = esc_html( $field[ 'label' ] . ' (' . $field[ 'name' ] . ')' );
|
6361 |
+
}
|
6362 |
+
|
6363 |
+
return $sister_fields;
|
6364 |
+
}
|
6365 |
+
|
6366 |
+
/**
|
6367 |
+
* Takes a sql field such as tinyint and returns the pods field type, such as num.
|
6368 |
+
*
|
6369 |
+
* @param string $sql_field The SQL field to look for
|
6370 |
+
*
|
6371 |
+
* @return string The field type
|
6372 |
+
*
|
6373 |
+
* @since 2.0
|
6374 |
+
*/
|
6375 |
+
public static function detect_pod_field_from_sql_data_type ( $sql_field ) {
|
6376 |
+
$sql_field = strtolower( $sql_field );
|
6377 |
+
|
6378 |
+
$field_to_field_map = array(
|
6379 |
+
'tinyint' => 'number',
|
6380 |
+
'smallint' => 'number',
|
6381 |
+
'mediumint' => 'number',
|
6382 |
+
'int' => 'number',
|
6383 |
+
'bigint' => 'number',
|
6384 |
+
'float' => 'number',
|
6385 |
+
'double' => 'number',
|
6386 |
+
'decimal' => 'number',
|
6387 |
+
'date' => 'date',
|
6388 |
+
'datetime' => 'datetime',
|
6389 |
+
'timestamp' => 'datetime',
|
6390 |
+
'time' => 'time',
|
6391 |
+
'year' => 'date',
|
6392 |
+
'varchar' => 'text',
|
6393 |
+
'text' => 'paragraph',
|
6394 |
+
'mediumtext' => 'paragraph',
|
6395 |
+
'longtext' => 'paragraph'
|
6396 |
+
);
|
6397 |
+
|
6398 |
+
return ( array_key_exists( $sql_field, $field_to_field_map ) ) ? $field_to_field_map[ $sql_field ] : 'paragraph';
|
6399 |
+
}
|
6400 |
+
|
6401 |
+
/**
|
6402 |
+
* Gets all field types
|
6403 |
+
*
|
6404 |
+
* @return array Array of field types
|
6405 |
+
*
|
6406 |
+
* @uses PodsForm::field_loader
|
6407 |
+
*
|
6408 |
+
* @since 2.0
|
6409 |
+
* @deprecated
|
6410 |
+
*/
|
6411 |
+
public function get_field_types () {
|
6412 |
+
return PodsForm::field_types();
|
6413 |
+
}
|
6414 |
+
|
6415 |
+
/**
|
6416 |
+
* Gets the schema definition of a field.
|
6417 |
+
*
|
6418 |
+
* @param string $type Field type to look for
|
6419 |
+
* @param array $options (optional) Options of the field to pass to the schema function.
|
6420 |
+
*
|
6421 |
+
* @return array|bool|mixed|null
|
6422 |
+
*
|
6423 |
+
* @since 2.0
|
6424 |
+
*/
|
6425 |
+
private function get_field_definition ( $type, $options = null ) {
|
6426 |
+
$definition = PodsForm::field_method( $type, 'schema', $options );
|
6427 |
+
|
6428 |
+
return $this->do_hook( 'field_definition', $definition, $type, $options );
|
6429 |
+
}
|
6430 |
+
|
6431 |
+
/**
|
6432 |
+
* @see PodsForm:validate
|
6433 |
+
*
|
6434 |
+
* Validates the value of a field.
|
6435 |
+
*
|
6436 |
+
* @param mixed $value The value to validate
|
6437 |
+
* @param string $field Field to use for validation
|
6438 |
+
* @param array $object_fields Fields of the object we're validating
|
6439 |
+
* @param array $fields Array of all fields data
|
6440 |
+
* @param array|Pods $pod Array of pod data (or Pods object)
|
6441 |
+
* @param array|object $params Extra parameters to pass to the validation function of the field.
|
6442 |
+
*
|
6443 |
+
* @return array|bool
|
6444 |
+
*
|
6445 |
+
* @uses PodsForm::validate
|
6446 |
+
*
|
6447 |
+
* @since 2.0
|
6448 |
+
*/
|
6449 |
+
public function handle_field_validation ( &$value, $field, $object_fields, $fields, $pod, $params ) {
|
6450 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
6451 |
+
|
6452 |
+
$fields = array_merge( $fields, $object_fields );
|
6453 |
+
|
6454 |
+
$options = $fields[ $field ];
|
6455 |
+
|
6456 |
+
$id = ( is_object( $params ) ? $params->id : ( is_object( $pod ) ? $pod->id() : 0 ) );
|
6457 |
+
|
6458 |
+
if ( is_object( $pod ) )
|
6459 |
+
$pod = $pod->pod_data;
|
6460 |
+
|
6461 |
+
$type = $options[ 'type' ];
|
6462 |
+
$label = $options[ 'label' ];
|
6463 |
+
$label = empty( $label ) ? $field : $label;
|
6464 |
+
|
6465 |
+
// Verify required fields
|
6466 |
+
if ( 1 == pods_var( 'required', $options[ 'options' ], 0 ) && 'slug' != $type ) {
|
6467 |
+
if ( '' == $value || null === $value || array() === $value || 0 === $value || '0' === $value || 0.00 === $value || '0.00' === $value )
|
6468 |
+
return pods_error( sprintf( __( '%s is empty', 'pods' ), $label ), $this );
|
6469 |
+
|
6470 |
+
if ( 'multi' == pods_var( 'pick_format_type', $options[ 'options' ] ) && 'autocomplete' != pods_var( 'pick_format_multi', $options[ 'options' ] ) ) {
|
6471 |
+
$has_value = false;
|
6472 |
+
|
6473 |
+
$check_value = (array) $value;
|
6474 |
+
|
6475 |
+
foreach ( $check_value as $val ) {
|
6476 |
+
if ( '' != $val && null !== $val && 0 !== $val && '0' !== $val ) {
|
6477 |
+
$has_value = true;
|
6478 |
+
|
6479 |
+
continue;
|
6480 |
+
}
|
6481 |
+
}
|
6482 |
+
|
6483 |
+
if ( !$has_value )
|
6484 |
+
return pods_error( sprintf( __( '%s is required', 'pods' ), $label ), $this );
|
6485 |
+
}
|
6486 |
+
|
6487 |
+
}
|
6488 |
+
|
6489 |
+
// @todo move this to after pre-save preparations
|
6490 |
+
// Verify unique fields
|
6491 |
+
if ( 1 == pods_var( 'unique', $options[ 'options' ], 0 ) && '' !== $value && null !== $value && array() !== $value && 0 !== $value && '0' !== $value && 0.00 !== $value && '0.00' !== $value ) {
|
6492 |
+
if ( empty( $pod ) )
|
6493 |
+
return false;
|
6494 |
+
|
6495 |
+
if ( !in_array( $type, $tableless_field_types ) ) {
|
6496 |
+
$exclude = '';
|
6497 |
+
|
6498 |
+
if ( !empty( $id ) )
|
6499 |
+
$exclude = "AND `id` != {$id}";
|
6500 |
+
|
6501 |
+
$check = false;
|
6502 |
+
|
6503 |
+
$check_value = pods_sanitize( $value );
|
6504 |
+
|
6505 |
+
// @todo handle meta-based fields
|
6506 |
+
// Trigger an error if not unique
|
6507 |
+
if ( 'table' == $pod[ 'storage' ] )
|
6508 |
+
$check = pods_query( "SELECT `id` FROM `@wp_pods_" . $pod[ 'name' ] . "` WHERE `{$field}` = '{$check_value}' {$exclude} LIMIT 1", $this );
|
6509 |
+
|
6510 |
+
if ( !empty( $check ) )
|
6511 |
+
return pods_error( sprintf( __( '%s needs to be unique', 'pods' ), $label ), $this );
|
6512 |
+
}
|
6513 |
+
else {
|
6514 |
+
// @todo handle tableless check
|
6515 |
+
}
|
6516 |
+
}
|
6517 |
+
|
6518 |
+
$validate = PodsForm::validate( $options[ 'type' ], $value, $field, array_merge( $options, pods_var( 'options', $options, array() ) ), $fields, $pod, $id, $params );
|
6519 |
+
|
6520 |
+
$validate = $this->do_hook( 'field_validation', $validate, $value, $field, $object_fields, $fields, $pod, $params );
|
6521 |
+
|
6522 |
+
return $validate;
|
6523 |
+
}
|
6524 |
+
|
6525 |
+
/**
|
6526 |
+
* Find items related to a parent field
|
6527 |
+
*
|
6528 |
+
* @param int $field_id The Field ID
|
6529 |
+
* @param int $pod_id The Pod ID
|
6530 |
+
* @param mixed $ids A comma-separated string (or array) of item IDs
|
6531 |
+
* @param array $field Field data array
|
6532 |
+
* @param array $pod Pod data array
|
6533 |
+
*
|
6534 |
+
* @return array
|
6535 |
+
*
|
6536 |
+
* @since 2.0
|
6537 |
+
*
|
6538 |
+
* @uses pods_query()
|
6539 |
+
*/
|
6540 |
+
public function lookup_related_items ( $field_id, $pod_id, $ids, $field = null, $pod = null ) {
|
6541 |
+
$related_ids = array();
|
6542 |
+
|
6543 |
+
if ( !is_array( $ids ) )
|
6544 |
+
$ids = explode( ',', $ids );
|
6545 |
+
|
6546 |
+
foreach ( $ids as $k => $id ) {
|
6547 |
+
$ids[ $k ] = (int) $id;
|
6548 |
+
}
|
6549 |
+
|
6550 |
+
$ids = array_unique( array_filter( $ids ) );
|
6551 |
+
|
6552 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
6553 |
+
|
6554 |
+
$field_type = pods_var( 'type', $field );
|
6555 |
+
|
6556 |
+
if ( empty( $ids ) || !in_array( $field_type, $tableless_field_types ) )
|
6557 |
+
return array();
|
6558 |
+
|
6559 |
+
$related_pick_limit = 0;
|
6560 |
+
|
6561 |
+
if ( empty( $field ) ) {
|
6562 |
+
$field = $this->load_field( array( 'id' => $field_id ) );
|
6563 |
+
}
|
6564 |
+
|
6565 |
+
if ( !empty( $field ) ) {
|
6566 |
+
$options = (array) pods_var_raw( 'options', $field, $field, null, true );
|
6567 |
+
|
6568 |
+
$related_pick_limit = (int) pods_var( pods_var( 'type', $field ) . '_limit', $options, 0 );
|
6569 |
+
|
6570 |
+
if ( 'single' == pods_var_raw( pods_var( 'type', $field ) . '_format_type', $options ) )
|
6571 |
+
$related_pick_limit = 1;
|
6572 |
+
|
6573 |
+
// Temporary hack until there's some better handling here
|
6574 |
+
$related_pick_limit = $related_pick_limit * count( $ids );
|
6575 |
+
}
|
6576 |
+
|
6577 |
+
if ( 'taxonomy' == $field_type ) {
|
6578 |
+
$related = wp_get_object_terms( $ids, pods_var( 'name', $field ), array( 'fields' => 'ids' ) );
|
6579 |
+
|
6580 |
+
if ( !is_wp_error( $related ) ) {
|
6581 |
+
$related_ids = $related;
|
6582 |
+
}
|
6583 |
+
}
|
6584 |
+
elseif ( !pods_tableless() ) {
|
6585 |
+
$ids = implode( ', ', $ids );
|
6586 |
+
|
6587 |
+
$field_id = (int) $field_id;
|
6588 |
+
$sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
|
6589 |
+
|
6590 |
+
$related_where = "
|
6591 |
+
`field_id` = {$field_id}
|
6592 |
+
AND `item_id` IN ( {$ids} )
|
6593 |
+
";
|
6594 |
+
|
6595 |
+
$sql = "
|
6596 |
+
SELECT *
|
6597 |
+
FROM `@wp_podsrel`
|
6598 |
+
WHERE
|
6599 |
+
{$related_where}
|
6600 |
+
ORDER BY `weight`
|
6601 |
+
";
|
6602 |
+
|
6603 |
+
$relationships = pods_query( $sql );
|
6604 |
+
|
6605 |
+
if ( !empty( $relationships ) ) {
|
6606 |
+
foreach ( $relationships as $relation ) {
|
6607 |
+
if ( $field_id == $relation->field_id && !in_array( $relation->related_item_id, $related_ids ) )
|
6608 |
+
$related_ids[] = (int) $relation->related_item_id;
|
6609 |
+
elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && !in_array( $relation->item_id, $related_ids ) )
|
6610 |
+
$related_ids[] = (int) $relation->item_id;
|
6611 |
+
}
|
6612 |
+
}
|
6613 |
+
}
|
6614 |
+
else {
|
6615 |
+
if ( !is_array( $pod ) )
|
6616 |
+
$pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
|
6617 |
+
|
6618 |
+
if ( !empty( $pod ) && in_array( $pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment', 'settings' ) ) ) {
|
6619 |
+
$meta_type = $pod[ 'type' ];
|
6620 |
+
|
6621 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media' ) ) )
|
6622 |
+
$meta_type = 'post';
|
6623 |
+
|
6624 |
+
$no_conflict = pods_no_conflict_check( $meta_type );
|
6625 |
+
|
6626 |
+
if ( !$no_conflict )
|
6627 |
+
pods_no_conflict_on( $meta_type );
|
6628 |
+
|
6629 |
+
foreach ( $ids as $id ) {
|
6630 |
+
if ( 'settings' == $meta_type ) {
|
6631 |
+
$related_id = get_option( '_pods_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
6632 |
+
|
6633 |
+
if ( empty( $related_id ) )
|
6634 |
+
$related_id = get_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
6635 |
+
|
6636 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
6637 |
+
foreach ( $related_id as $related ) {
|
6638 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
6639 |
+
if ( isset( $related[ 'id' ] ) )
|
6640 |
+
$related_ids[] = (int) $related[ 'id' ];
|
6641 |
+
else {
|
6642 |
+
foreach ( $related as $r ) {
|
6643 |
+
$related_ids[] = (int) $r;
|
6644 |
+
}
|
6645 |
+
}
|
6646 |
+
}
|
6647 |
+
else
|
6648 |
+
$related_ids[] = (int) $related;
|
6649 |
+
}
|
6650 |
+
}
|
6651 |
+
}
|
6652 |
+
else {
|
6653 |
+
$related_id = get_metadata( $meta_type, $id, '_pods_' . $field[ 'name' ], true );
|
6654 |
+
|
6655 |
+
if ( empty( $related_id ) )
|
6656 |
+
$related_id = get_metadata( $meta_type, $id, $field[ 'name' ] );
|
6657 |
+
|
6658 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
6659 |
+
foreach ( $related_id as $related ) {
|
6660 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
6661 |
+
if ( isset( $related[ 'id' ] ) )
|
6662 |
+
$related_ids[] = (int) $related[ 'id' ];
|
6663 |
+
else {
|
6664 |
+
foreach ( $related as $r ) {
|
6665 |
+
if ( isset( $related[ 'id' ] ) )
|
6666 |
+
$related_ids[] = (int) $r[ 'id' ];
|
6667 |
+
else
|
6668 |
+
$related_ids[] = (int) $r;
|
6669 |
+
}
|
6670 |
+
}
|
6671 |
+
}
|
6672 |
+
else
|
6673 |
+
$related_ids[] = (int) $related;
|
6674 |
+
}
|
6675 |
+
}
|
6676 |
+
}
|
6677 |
+
}
|
6678 |
+
|
6679 |
+
if ( !$no_conflict )
|
6680 |
+
pods_no_conflict_off( $meta_type );
|
6681 |
+
}
|
6682 |
+
}
|
6683 |
+
|
6684 |
+
if ( is_array( $related_ids ) ) {
|
6685 |
+
$related_ids = array_unique( array_filter( $related_ids ) );
|
6686 |
+
|
6687 |
+
if ( 0 < $related_pick_limit && !empty( $related_ids ) )
|
6688 |
+
$related_ids = array_slice( $related_ids, 0, $related_pick_limit );
|
6689 |
+
}
|
6690 |
+
|
6691 |
+
return $related_ids;
|
6692 |
+
}
|
6693 |
+
|
6694 |
+
/**
|
6695 |
+
* Find related items related to an item
|
6696 |
+
*
|
6697 |
+
* @param int $field_id The Field ID
|
6698 |
+
* @param int $pod_id The Pod ID
|
6699 |
+
* @param int $id Item ID to get related IDs from
|
6700 |
+
* @param array $field Field data array
|
6701 |
+
* @param array $pod Pod data array
|
6702 |
+
*
|
6703 |
+
* @return array|bool
|
6704 |
+
*
|
6705 |
+
* @since 2.3
|
6706 |
+
*
|
6707 |
+
* @uses pods_query()
|
6708 |
+
*/
|
6709 |
+
public function lookup_related_items_from ( $field_id, $pod_id, $id, $field = null, $pod = null ) {
|
6710 |
+
$related_ids = false;
|
6711 |
+
|
6712 |
+
$id = (int) $id;
|
6713 |
+
|
6714 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
6715 |
+
|
6716 |
+
if ( empty( $id ) || !in_array( pods_var( 'type', $field ), $tableless_field_types ) )
|
6717 |
+
return false;
|
6718 |
+
|
6719 |
+
$related_pick_limit = 0;
|
6720 |
+
|
6721 |
+
if ( !empty( $field ) ) {
|
6722 |
+
$options = (array) pods_var_raw( 'options', $field, $field, null, true );
|
6723 |
+
|
6724 |
+
$related_pick_limit = (int) pods_var( 'pick_limit', $options, 0 );
|
6725 |
+
|
6726 |
+
if ( 'single' == pods_var_raw( 'pick_format_type', $options ) )
|
6727 |
+
$related_pick_limit = 1;
|
6728 |
+
}
|
6729 |
+
|
6730 |
+
if ( !pods_tableless() ) {
|
6731 |
+
$field_id = (int) $field_id;
|
6732 |
+
$sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
|
6733 |
+
|
6734 |
+
$related_where = "
|
6735 |
+
`field_id` = {$field_id}
|
6736 |
+
AND `related_item_id` = {$id}
|
6737 |
+
";
|
6738 |
+
|
6739 |
+
$sql = "
|
6740 |
+
SELECT *
|
6741 |
+
FROM `@wp_podsrel`
|
6742 |
+
WHERE
|
6743 |
+
{$related_where}
|
6744 |
+
ORDER BY `weight`
|
6745 |
+
";
|
6746 |
+
|
6747 |
+
$relationships = pods_query( $sql );
|
6748 |
+
|
6749 |
+
if ( !empty( $relationships ) ) {
|
6750 |
+
$related_ids = array();
|
6751 |
+
|
6752 |
+
foreach ( $relationships as $relation ) {
|
6753 |
+
if ( $field_id == $relation->field_id && !in_array( $relation->item_id, $related_ids ) )
|
6754 |
+
$related_ids[] = (int) $relation->item_id;
|
6755 |
+
elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && !in_array( $relation->related_item_id, $related_ids ) )
|
6756 |
+
$related_ids[] = (int) $relation->related_item_id;
|
6757 |
+
}
|
6758 |
+
}
|
6759 |
+
}
|
6760 |
+
else {
|
6761 |
+
// @todo handle meta-based lookups
|
6762 |
+
return false;
|
6763 |
+
|
6764 |
+
if ( !is_array( $pod ) )
|
6765 |
+
$pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
|
6766 |
+
|
6767 |
+
if ( !empty( $pod ) && in_array( $pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment', 'settings' ) ) ) {
|
6768 |
+
$related_ids = array();
|
6769 |
+
|
6770 |
+
$meta_type = $pod[ 'type' ];
|
6771 |
+
|
6772 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media' ) ) )
|
6773 |
+
$meta_type = 'post';
|
6774 |
+
|
6775 |
+
$no_conflict = pods_no_conflict_check( $meta_type );
|
6776 |
+
|
6777 |
+
if ( !$no_conflict )
|
6778 |
+
pods_no_conflict_on( $meta_type );
|
6779 |
+
|
6780 |
+
if ( 'settings' == $meta_type ) {
|
6781 |
+
$related_id = get_option( '_pods_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
6782 |
+
|
6783 |
+
if ( empty( $related_id ) )
|
6784 |
+
$related_id = get_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
6785 |
+
|
6786 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
6787 |
+
foreach ( $related_id as $related ) {
|
6788 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
6789 |
+
if ( isset( $related[ 'id' ] ) )
|
6790 |
+
$related_ids[] = (int) $related[ 'id' ];
|
6791 |
+
else {
|
6792 |
+
foreach ( $related as $r ) {
|
6793 |
+
$related_ids[] = (int) $r;
|
6794 |
+
}
|
6795 |
+
}
|
6796 |
+
}
|
6797 |
+
else
|
6798 |
+
$related_ids[] = (int) $related;
|
6799 |
+
}
|
6800 |
+
}
|
6801 |
+
}
|
6802 |
+
else {
|
6803 |
+
$related_id = get_metadata( $meta_type, $id, '_pods_' . $field[ 'name' ], true );
|
6804 |
+
|
6805 |
+
if ( empty( $related_id ) )
|
6806 |
+
$related_id = get_metadata( $meta_type, $id, $field[ 'name' ] );
|
6807 |
+
|
6808 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
6809 |
+
foreach ( $related_id as $related ) {
|
6810 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
6811 |
+
if ( isset( $related[ 'id' ] ) )
|
6812 |
+
$related_ids[] = (int) $related[ 'id' ];
|
6813 |
+
else {
|
6814 |
+
foreach ( $related as $r ) {
|
6815 |
+
if ( isset( $related[ 'id' ] ) )
|
6816 |
+
$related_ids[] = (int) $r[ 'id' ];
|
6817 |
+
else
|
6818 |
+
$related_ids[] = (int) $r;
|
6819 |
+
}
|
6820 |
+
}
|
6821 |
+
}
|
6822 |
+
else
|
6823 |
+
$related_ids[] = (int) $related;
|
6824 |
+
}
|
6825 |
+
}
|
6826 |
+
}
|
6827 |
+
|
6828 |
+
if ( !$no_conflict )
|
6829 |
+
pods_no_conflict_off( $meta_type );
|
6830 |
+
}
|
6831 |
+
}
|
6832 |
+
|
6833 |
+
if ( is_array( $related_ids ) )
|
6834 |
+
$related_ids = array_unique( array_filter( $related_ids ) );
|
6835 |
+
|
6836 |
+
return $related_ids;
|
6837 |
+
}
|
6838 |
+
|
6839 |
+
/**
|
6840 |
+
* Get information about an objects MySQL table
|
6841 |
+
*
|
6842 |
+
* @param string $object_type
|
6843 |
+
* @param string $object The object to look for
|
6844 |
+
* @param null $name (optional) Name of the pod to load
|
6845 |
+
* @param array $pod (optional) Array with pod information
|
6846 |
+
* @param array $field (optional) Array with field information
|
6847 |
+
*
|
6848 |
+
* @return array|bool
|
6849 |
+
*
|
6850 |
+
* @since 2.0
|
6851 |
+
*/
|
6852 |
+
public function get_table_info ( $object_type, $object, $name = null, $pod = null, $field = null ) {
|
6853 |
+
/**
|
6854 |
+
* @var $wpdb wpdb
|
6855 |
+
* @var $sitepress SitePress
|
6856 |
+
* @var $icl_adjust_id_url_filter_off boolean
|
6857 |
+
*/
|
6858 |
+
global $wpdb, $sitepress, $icl_adjust_id_url_filter_off, $polylang;
|
6859 |
+
|
6860 |
+
// @todo Handle $object arrays for Post Types, Taxonomies, Comments (table pulled from first object in array)
|
6861 |
+
|
6862 |
+
$info = array(
|
6863 |
+
//'select' => '`t`.*',
|
6864 |
+
'object_type' => $object_type,
|
6865 |
+
'type' => null,
|
6866 |
+
'object_name' => $object,
|
6867 |
+
'object_hierarchical' => false,
|
6868 |
+
|
6869 |
+
'table' => $object,
|
6870 |
+
'meta_table' => $object,
|
6871 |
+
'pod_table' => $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object ),
|
6872 |
+
|
6873 |
+
'field_id' => 'id',
|
6874 |
+
'field_index' => 'name',
|
6875 |
+
'field_slug' => null,
|
6876 |
+
'field_type' => null,
|
6877 |
+
'field_parent' => null,
|
6878 |
+
'field_parent_select' => null,
|
6879 |
+
|
6880 |
+
'meta_field_id' => 'id',
|
6881 |
+
'meta_field_index' => 'name',
|
6882 |
+
'meta_field_value' => 'name',
|
6883 |
+
|
6884 |
+
'pod_field_id' => 'id',
|
6885 |
+
'pod_field_index' => 'name',
|
6886 |
+
'pod_field_slug' => null,
|
6887 |
+
'pod_field_parent' => null,
|
6888 |
+
|
6889 |
+
'join' => array(),
|
6890 |
+
|
6891 |
+
'where' => null,
|
6892 |
+
'where_default' => null,
|
6893 |
+
|
6894 |
+
'orderby' => null,
|
6895 |
+
|
6896 |
+
'pod' => null,
|
6897 |
+
'recurse' => false
|
6898 |
+
);
|
6899 |
+
|
6900 |
+
if ( empty( $object_type ) ) {
|
6901 |
+
$object_type = 'post_type';
|
6902 |
+
$object = 'post';
|
6903 |
+
}
|
6904 |
+
|
6905 |
+
$pod_name = $pod;
|
6906 |
+
|
6907 |
+
if ( is_array( $pod_name ) )
|
6908 |
+
$pod_name = pods_var_raw( 'name', $pod_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $pod_name ) ), null, true );
|
6909 |
+
|
6910 |
+
$field_name = $field;
|
6911 |
+
|
6912 |
+
if ( is_array( $field_name ) )
|
6913 |
+
$field_name = pods_var_raw( 'name', $field_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $field_name ) ), null, true );
|
6914 |
+
|
6915 |
+
$transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
|
6916 |
+
|
6917 |
+
$current_language = false;
|
6918 |
+
$current_language_t_id = $current_language_tt_id = 0;
|
6919 |
+
|
6920 |
+
// WPML support
|
6921 |
+
if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
6922 |
+
$current_language = pods_sanitize( ICL_LANGUAGE_CODE );
|
6923 |
+
// Polylang support
|
6924 |
+
elseif ( is_object( $polylang ) && function_exists( 'pll_current_language' ) ) {
|
6925 |
+
$current_language = pods_sanitize( pll_current_language( 'slug' ) );
|
6926 |
+
|
6927 |
+
if ( !empty( $current_language ) ) {
|
6928 |
+
$current_language_t_id = (int) $polylang->get_language( $current_language )->term_id;
|
6929 |
+
$current_language_tt_id = (int) $polylang->get_language( $current_language )->term_taxonomy_id;
|
6930 |
+
}
|
6931 |
+
}
|
6932 |
+
|
6933 |
+
if ( !empty( $current_language ) )
|
6934 |
+
$transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
|
6935 |
+
|
6936 |
+
$_info = false;
|
6937 |
+
|
6938 |
+
if ( pods_api_cache() )
|
6939 |
+
$_info = pods_transient_get( $transient );
|
6940 |
+
|
6941 |
+
if ( pods_api_cache() && false === $_info && !did_action( 'init' ) )
|
6942 |
+
$_info = pods_transient_get( $transient . '_pre_init' );
|
6943 |
+
|
6944 |
+
if ( false !== $_info )
|
6945 |
+
$info = $_info;
|
6946 |
+
else {
|
6947 |
+
if ( 'pod' == $object_type && null === $pod ) {
|
6948 |
+
if ( empty( $name ) ) {
|
6949 |
+
$prefix = 'pod-';
|
6950 |
+
|
6951 |
+
// Make sure we actually have the prefix before trying anything with the name
|
6952 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
6953 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
6954 |
+
}
|
6955 |
+
|
6956 |
+
if ( empty( $name ) && !empty( $object ) )
|
6957 |
+
$name = $object;
|
6958 |
+
|
6959 |
+
$pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
|
6960 |
+
|
6961 |
+
if ( !empty( $pod ) ) {
|
6962 |
+
$object_type = $pod[ 'type' ];
|
6963 |
+
$name = $pod[ 'name' ];
|
6964 |
+
$object = $pod[ 'object' ];
|
6965 |
+
|
6966 |
+
$info[ 'pod' ] = $pod;
|
6967 |
+
}
|
6968 |
+
}
|
6969 |
+
elseif ( null === $pod ) {
|
6970 |
+
if ( empty( $name ) ) {
|
6971 |
+
$prefix = $object_type . '-';
|
6972 |
+
|
6973 |
+
// Make sure we actually have the prefix before trying anything with the name
|
6974 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
6975 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
6976 |
+
}
|
6977 |
+
|
6978 |
+
if ( empty( $name ) && !empty( $object ) )
|
6979 |
+
$name = $object;
|
6980 |
+
|
6981 |
+
if ( !empty( $name ) ) {
|
6982 |
+
$pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
|
6983 |
+
|
6984 |
+
if ( !empty( $pod ) && ( null === $object_type || $object_type == $pod[ 'type' ] ) ) {
|
6985 |
+
$object_type = $pod[ 'type' ];
|
6986 |
+
$name = $pod[ 'name' ];
|
6987 |
+
$object = $pod[ 'object' ];
|
6988 |
+
|
6989 |
+
$info[ 'pod' ] = $pod;
|
6990 |
+
}
|
6991 |
+
}
|
6992 |
+
}
|
6993 |
+
elseif ( !empty( $pod ) )
|
6994 |
+
$info[ 'pod' ] = $pod;
|
6995 |
+
|
6996 |
+
if ( 0 === strpos( $object_type, 'pod' ) ) {
|
6997 |
+
if ( empty( $name ) ) {
|
6998 |
+
$prefix = 'pod-';
|
6999 |
+
|
7000 |
+
// Make sure we actually have the prefix before trying anything with the name
|
7001 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
7002 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
7003 |
+
}
|
7004 |
+
|
7005 |
+
$object_type = 'pod';
|
7006 |
+
|
7007 |
+
$info[ 'table' ] = $info[ 'meta_table' ] = $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object );
|
7008 |
+
|
7009 |
+
if ( is_array( $info[ 'pod' ] ) && 'pod' == pods_var( 'type', $info[ 'pod' ] ) ) {
|
7010 |
+
$info[ 'pod_field_index' ] = $info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = pods_var( 'pod_index', $info[ 'pod' ][ 'options' ], 'id', null, true );
|
7011 |
+
|
7012 |
+
$slug_field = get_posts( array(
|
7013 |
+
'post_type' => '_pods_field',
|
7014 |
+
'posts_per_page' => 1,
|
7015 |
+
'nopaging' => true,
|
7016 |
+
'post_parent' => $info[ 'pod' ][ 'id' ],
|
7017 |
+
'orderby' => 'menu_order',
|
7018 |
+
'order' => 'ASC',
|
7019 |
+
'meta_query' => array(
|
7020 |
+
array(
|
7021 |
+
'key' => 'type',
|
7022 |
+
'value' => 'slug',
|
7023 |
+
)
|
7024 |
+
)
|
7025 |
+
) );
|
7026 |
+
|
7027 |
+
if ( !empty( $slug_field ) ) {
|
7028 |
+
$slug_field = $slug_field[ 0 ];
|
7029 |
+
|
7030 |
+
$info[ 'field_slug' ] = $info[ 'pod_field_slug' ] = $slug_field->post_name;
|
7031 |
+
}
|
7032 |
+
|
7033 |
+
if ( 1 == pods_var( 'hierarchical', $info[ 'pod' ][ 'options' ], 0 ) ) {
|
7034 |
+
$parent_field = pods_var( 'pod_parent', $info[ 'pod' ][ 'options' ], 'id', null, true );
|
7035 |
+
|
7036 |
+
if ( !empty( $parent_field ) && isset( $info[ 'pod' ][ 'fields' ][ $parent_field ] ) ) {
|
7037 |
+
$info[ 'object_hierarchical' ] = true;
|
7038 |
+
|
7039 |
+
$info[ 'pod_field_parent' ] = $info[ 'field_parent' ] = $parent_field . '_select';
|
7040 |
+
$info[ 'field_parent_select' ] = '`' . $parent_field . '`.`id` AS `' . $info[ 'field_parent' ] . '`';
|
7041 |
+
}
|
7042 |
+
}
|
7043 |
+
}
|
7044 |
+
}
|
7045 |
+
|
7046 |
+
if ( 0 === strpos( $object_type, 'post_type' ) || 'media' == $object_type || in_array( pods_var_raw( 'type', $info[ 'pod' ] ), array( 'post_type', 'media' ) ) ) {
|
7047 |
+
$info[ 'table' ] = $wpdb->posts;
|
7048 |
+
$info[ 'meta_table' ] = $wpdb->postmeta;
|
7049 |
+
|
7050 |
+
$info[ 'field_id' ] = 'ID';
|
7051 |
+
$info[ 'field_index' ] = 'post_title';
|
7052 |
+
$info[ 'field_slug' ] = 'post_name';
|
7053 |
+
$info[ 'field_type' ] = 'post_type';
|
7054 |
+
$info[ 'field_parent' ] = 'post_parent';
|
7055 |
+
$info[ 'field_parent_select' ] = '`t`.`' . $info[ 'field_parent' ] . '`';
|
7056 |
+
|
7057 |
+
$info[ 'meta_field_id' ] = 'post_id';
|
7058 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
7059 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
7060 |
+
|
7061 |
+
if ( 'media' == $object_type )
|
7062 |
+
$object = 'attachment';
|
7063 |
+
|
7064 |
+
if ( empty( $name ) ) {
|
7065 |
+
$prefix = 'post_type-';
|
7066 |
+
|
7067 |
+
// Make sure we actually have the prefix before trying anything with the name
|
7068 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
7069 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
7070 |
+
}
|
7071 |
+
|
7072 |
+
if ( 'media' != $object_type )
|
7073 |
+
$object_type = 'post_type';
|
7074 |
+
|
7075 |
+
$post_type = pods_sanitize( ( empty( $object ) ? $name : $object ) );
|
7076 |
+
|
7077 |
+
if ( 'attachment' == $post_type || 'media' == $object_type )
|
7078 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_media';
|
7079 |
+
else
|
7080 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . pods_clean_name( $post_type, true, false );
|
7081 |
+
|
7082 |
+
$post_type_object = get_post_type_object( $post_type );
|
7083 |
+
|
7084 |
+
if ( is_object( $post_type_object ) && $post_type_object->hierarchical )
|
7085 |
+
$info[ 'object_hierarchical' ] = true;
|
7086 |
+
|
7087 |
+
/**
|
7088 |
+
* Default Post Stati to query for.
|
7089 |
+
*
|
7090 |
+
* Use to change "default" post status from publish to any other status or statuses.
|
7091 |
+
*
|
7092 |
+
* @param array $post_stati List of post statuses. Default is 'publish'
|
7093 |
+
* @param string $post_type Post type of current object
|
7094 |
+
* @param array $info Array of information about the object.
|
7095 |
+
* @param string $object Type of object
|
7096 |
+
* @param string $name Name of pod to load
|
7097 |
+
* @param array $pod Array with Pod information. Result of PodsAPI::load_pod()
|
7098 |
+
* @param array $field Array with field information
|
7099 |
+
*
|
7100 |
+
* @since unknown
|
7101 |
+
*/
|
7102 |
+
$post_stati = apply_filters( 'pods_api_get_table_info_default_post_status', array( 'publish' ), $post_type, $info, $object_type, $object, $name, $pod, $field );
|
7103 |
+
|
7104 |
+
$info[ 'where' ] = array(
|
7105 |
+
//'post_status' => '`t`.`post_status` IN ( "inherit", "publish" )', // @todo Figure out what statuses Attachments can be
|
7106 |
+
'post_type' => '`t`.`' . $info[ 'field_type' ] . '` = "' . $post_type . '"'
|
7107 |
+
);
|
7108 |
+
|
7109 |
+
if ( 'post_type' == $object_type )
|
7110 |
+
$info[ 'where_default' ] = '`t`.`post_status` IN ( "' . implode( '", "', $post_stati ) . '" )';
|
7111 |
+
|
7112 |
+
$info[ 'orderby' ] = '`t`.`menu_order`, `t`.`' . $info[ 'field_index' ] . '`, `t`.`post_date`';
|
7113 |
+
|
7114 |
+
// WPML support
|
7115 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $post_type ) && !$icl_adjust_id_url_filter_off ) {
|
7116 |
+
$info[ 'join' ][ 'wpml_translations' ] = "
|
7117 |
+
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
|
7118 |
+
ON `wpml_translations`.`element_id` = `t`.`ID`
|
7119 |
+
AND `wpml_translations`.`element_type` = 'post_{$post_type}'
|
7120 |
+
AND `wpml_translations`.`language_code` = '{$current_language}'
|
7121 |
+
";
|
7122 |
+
|
7123 |
+
$info[ 'join' ][ 'wpml_languages' ] = "
|
7124 |
+
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
|
7125 |
+
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
|
7126 |
+
";
|
7127 |
+
|
7128 |
+
$info[ 'where' ][ 'wpml_languages' ] = "`wpml_languages`.`code` IS NOT NULL";
|
7129 |
+
}
|
7130 |
+
// Polylang support
|
7131 |
+
elseif( is_object( $polylang ) && !empty( $current_language ) && function_exists( 'pll_is_translated_post_type' ) && pll_is_translated_post_type( $post_type ) ) {
|
7132 |
+
$info[ 'join' ][ 'polylang_languages' ] = "
|
7133 |
+
LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
|
7134 |
+
ON `polylang_languages`.`object_id` = `t`.`ID`
|
7135 |
+
AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tt_id}
|
7136 |
+
";
|
7137 |
+
|
7138 |
+
$info[ 'where' ][ 'polylang_languages' ] = "`polylang_languages`.`object_id` IS NOT NULL";
|
7139 |
+
}
|
7140 |
+
|
7141 |
+
$info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
|
7142 |
+
}
|
7143 |
+
elseif ( 0 === strpos( $object_type, 'taxonomy' ) || in_array( $object_type, array( 'nav_menu', 'post_format' ) ) || 'taxonomy' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
7144 |
+
$info[ 'table' ] = $info[ 'meta_table' ] = $wpdb->terms;
|
7145 |
+
|
7146 |
+
$info[ 'join' ][ 'tt' ] = "LEFT JOIN `{$wpdb->term_taxonomy}` AS `tt` ON `tt`.`term_id` = `t`.`term_id`";
|
7147 |
+
$info[ 'field_id' ] = $info[ 'meta_field_id' ] = 'term_id';
|
7148 |
+
$info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = 'name';
|
7149 |
+
$info[ 'field_slug' ] = 'slug';
|
7150 |
+
$info[ 'field_type' ] = 'taxonomy';
|
7151 |
+
$info[ 'field_parent' ] = 'parent';
|
7152 |
+
$info[ 'field_parent_select' ] = '`tt`.`' . $info[ 'field_parent' ] . '`';
|
7153 |
+
|
7154 |
+
if ( 'nav_menu' == $object_type )
|
7155 |
+
$object = 'nav_menu';
|
7156 |
+
elseif ( 'post_format' == $object_type )
|
7157 |
+
$object = 'post_format';
|
7158 |
+
|
7159 |
+
if ( empty( $name ) ) {
|
7160 |
+
$prefix = 'taxonomy-';
|
7161 |
+
|
7162 |
+
// Make sure we actually have the prefix before trying anything with the name
|
7163 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
7164 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
7165 |
+
}
|
7166 |
+
|
7167 |
+
if ( !in_array( $object_type, array( 'nav_menu', 'post_format' ) ) )
|
7168 |
+
$object_type = 'taxonomy';
|
7169 |
+
|
7170 |
+
$taxonomy = pods_sanitize( ( empty( $object ) ? $name : $object ) );
|
7171 |
+
|
7172 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . pods_clean_name( $taxonomy, true, false );
|
7173 |
+
|
7174 |
+
$taxonomy_object = get_taxonomy( $taxonomy );
|
7175 |
+
|
7176 |
+
if ( is_object( $taxonomy_object ) && $taxonomy_object->hierarchical )
|
7177 |
+
$info[ 'object_hierarchical' ] = true;
|
7178 |
+
|
7179 |
+
$info[ 'where' ] = array(
|
7180 |
+
'tt.taxonomy' => '`tt`.`' . $info[ 'field_type' ] . '` = "' . $taxonomy . '"'
|
7181 |
+
);
|
7182 |
+
|
7183 |
+
// WPML Support
|
7184 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_taxonomy( $taxonomy ) && !$icl_adjust_id_url_filter_off ) {
|
7185 |
+
$info[ 'join' ][ 'wpml_translations' ] = "
|
7186 |
+
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
|
7187 |
+
ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`
|
7188 |
+
AND `wpml_translations`.`element_type` = 'tax_{$taxonomy}'
|
7189 |
+
AND `wpml_translations`.`language_code` = '{$current_language}'
|
7190 |
+
";
|
7191 |
+
|
7192 |
+
$info[ 'join' ][ 'wpml_languages' ] = "
|
7193 |
+
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
|
7194 |
+
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
|
7195 |
+
";
|
7196 |
+
|
7197 |
+
$info[ 'where' ][ 'wpml_languages' ] = "`wpml_languages`.`code` IS NOT NULL";
|
7198 |
+
}
|
7199 |
+
// Polylang support
|
7200 |
+
elseif ( is_object( $polylang ) && !empty( $current_language ) && function_exists( 'pll_is_translated_taxonomy' ) && pll_is_translated_taxonomy( $taxonomy ) ) {
|
7201 |
+
$info[ 'join' ][ 'polylang_languages' ] = "
|
7202 |
+
LEFT JOIN `{$wpdb->termmeta}` AS `polylang_languages`
|
7203 |
+
ON `polylang_languages`.`term_id` = `t`.`term_id`
|
7204 |
+
AND `polylang_languages`.`meta_value` = {$current_language_t_id}
|
7205 |
+
";
|
7206 |
+
|
7207 |
+
$info[ 'where' ][ 'polylang_languages' ] = "`polylang_languages`.`term_id` IS NOT NULL";
|
7208 |
+
}
|
7209 |
+
|
7210 |
+
$info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
|
7211 |
+
}
|
7212 |
+
elseif ( 'user' == $object_type || 'user' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
7213 |
+
$info[ 'table' ] = $wpdb->users;
|
7214 |
+
$info[ 'meta_table' ] = $wpdb->usermeta;
|
7215 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_user';
|
7216 |
+
|
7217 |
+
$info[ 'field_id' ] = 'ID';
|
7218 |
+
$info[ 'field_index' ] = 'display_name';
|
7219 |
+
$info[ 'field_slug' ] = 'user_nicename';
|
7220 |
+
|
7221 |
+
$info[ 'meta_field_id' ] = 'user_id';
|
7222 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
7223 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
7224 |
+
|
7225 |
+
$info[ 'where' ] = array(
|
7226 |
+
'user_status' => '`t`.`user_status` = 0'
|
7227 |
+
);
|
7228 |
+
|
7229 |
+
$info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
|
7230 |
+
}
|
7231 |
+
elseif ( 'comment' == $object_type || 'comment' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
7232 |
+
//$info[ 'object_hierarchical' ] = true;
|
7233 |
+
|
7234 |
+
$info[ 'table' ] = $wpdb->comments;
|
7235 |
+
$info[ 'meta_table' ] = $wpdb->commentmeta;
|
7236 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_comment';
|
7237 |
+
|
7238 |
+
$info[ 'field_id' ] = 'comment_ID';
|
7239 |
+
$info[ 'field_index' ] = 'comment_date';
|
7240 |
+
$info[ 'field_type' ] = 'comment_type';
|
7241 |
+
$info[ 'field_parent' ] = 'comment_parent';
|
7242 |
+
$info[ 'field_parent_select' ] = '`t`.`' . $info[ 'field_parent' ] . '`';
|
7243 |
+
|
7244 |
+
$info[ 'meta_field_id' ] = 'comment_id';
|
7245 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
7246 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
7247 |
+
|
7248 |
+
$object = 'comment';
|
7249 |
+
|
7250 |
+
$comment_type = ( empty( $object ) ? $name : $object );
|
7251 |
+
|
7252 |
+
$comment_type_clause = '`t`.`' . $info[ 'field_type' ] . '` = "' . $comment_type . '"';
|
7253 |
+
|
7254 |
+
if ( 'comment' == $comment_type ) {
|
7255 |
+
$comment_type_clause = '( ' . $comment_type_clause . ' OR `t`.`' . $info[ 'field_type' ] . '` = "" )';
|
7256 |
+
}
|
7257 |
+
|
7258 |
+
$info[ 'where' ] = array(
|
7259 |
+
'comment_approved' => '`t`.`comment_approved` = 1',
|
7260 |
+
'comment_type' => $comment_type_clause
|
7261 |
+
);
|
7262 |
+
|
7263 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` DESC, `t`.`' . $info[ 'field_id' ] . '`';
|
7264 |
+
}
|
7265 |
+
elseif ( in_array( $object_type, array( 'option', 'settings' ) ) || 'settings' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
7266 |
+
$info[ 'table' ] = $wpdb->options;
|
7267 |
+
$info[ 'meta_table' ] = $wpdb->options;
|
7268 |
+
|
7269 |
+
$info[ 'field_id' ] = 'option_id';
|
7270 |
+
$info[ 'field_index' ] = 'option_name';
|
7271 |
+
|
7272 |
+
$info[ 'meta_field_id' ] = 'option_id';
|
7273 |
+
$info[ 'meta_field_index' ] = 'option_name';
|
7274 |
+
$info[ 'meta_field_value' ] = 'option_value';
|
7275 |
+
|
7276 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC';
|
7277 |
+
}
|
7278 |
+
elseif ( is_multisite() && ( in_array( $object_type, array( 'site_option', 'site_settings' ) ) || 'site_settings' == pods_var_raw( 'type', $info[ 'pod' ] ) ) ) {
|
7279 |
+
$info[ 'table' ] = $wpdb->sitemeta;
|
7280 |
+
$info[ 'meta_table' ] = $wpdb->sitemeta;
|
7281 |
+
|
7282 |
+
$info[ 'field_id' ] = 'site_id';
|
7283 |
+
$info[ 'field_index' ] = 'meta_key';
|
7284 |
+
|
7285 |
+
$info[ 'meta_field_id' ] = 'site_id';
|
7286 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
7287 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
7288 |
+
|
7289 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC';
|
7290 |
+
}
|
7291 |
+
elseif ( is_multisite() && 'network' == $object_type ) { // Network = Site
|
7292 |
+
$info[ 'table' ] = $wpdb->site;
|
7293 |
+
$info[ 'meta_table' ] = $wpdb->sitemeta;
|
7294 |
+
|
7295 |
+
$info[ 'field_id' ] = 'id';
|
7296 |
+
$info[ 'field_index' ] = 'domain';
|
7297 |
+
|
7298 |
+
$info[ 'meta_field_id' ] = 'site_id';
|
7299 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
7300 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
7301 |
+
|
7302 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC, `t`.`path` ASC, `t`.`' . $info[ 'field_id' ] . '`';
|
7303 |
+
}
|
7304 |
+
elseif ( is_multisite() && 'site' == $object_type ) { // Site = Blog
|
7305 |
+
$info[ 'table' ] = $wpdb->blogs;
|
7306 |
+
|
7307 |
+
$info[ 'field_id' ] = 'blog_id';
|
7308 |
+
$info[ 'field_index' ] = 'domain';
|
7309 |
+
$info[ 'field_type' ] = 'site_id';
|
7310 |
+
|
7311 |
+
$info[ 'where' ] = array(
|
7312 |
+
'archived' => '`t`.`archived` = 0',
|
7313 |
+
'spam' => '`t`.`spam` = 0',
|
7314 |
+
'deleted' => '`t`.`deleted` = 0',
|
7315 |
+
'site_id' => '`t`.`' . $info[ 'field_type' ] . '` = ' . (int) get_current_site()->id
|
7316 |
+
);
|
7317 |
+
|
7318 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC, `t`.`path` ASC, `t`.`' . $info[ 'field_id' ] . '`';
|
7319 |
+
}
|
7320 |
+
elseif ( 'table' == $object_type || 'table' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
7321 |
+
$info[ 'table' ] = ( empty( $object ) ? $name : $object );
|
7322 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . $info[ 'table' ];
|
7323 |
+
|
7324 |
+
if ( !empty( $field ) && is_array( $field ) ) {
|
7325 |
+
$info[ 'table' ] = pods_var_raw( 'pick_table', pods_var_raw( 'options', $field, $field ) );
|
7326 |
+
$info[ 'field_id' ] = pods_var_raw( 'pick_table_id', pods_var_raw( 'options', $field, $field ) );
|
7327 |
+
$info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = pods_var_raw( 'pick_table_index', pods_var_raw( 'options', $field, $field ) );
|
7328 |
+
}
|
7329 |
+
}
|
7330 |
+
|
7331 |
+
$info[ 'table' ] = pods_clean_name( $info[ 'table' ], false, false );
|
7332 |
+
$info[ 'meta_table' ] = pods_clean_name( $info[ 'meta_table' ], false, false );
|
7333 |
+
$info[ 'pod_table' ] = pods_clean_name( $info[ 'pod_table' ], false, false );
|
7334 |
+
|
7335 |
+
$info[ 'field_id' ] = pods_clean_name( $info[ 'field_id' ], false, false );
|
7336 |
+
$info[ 'field_index' ] = pods_clean_name( $info[ 'field_index' ], false, false );
|
7337 |
+
$info[ 'field_slug' ] = pods_clean_name( $info[ 'field_slug' ], false, false );
|
7338 |
+
|
7339 |
+
$info[ 'meta_field_id' ] = pods_clean_name( $info[ 'meta_field_id' ], false, false );
|
7340 |
+
$info[ 'meta_field_index' ] = pods_clean_name( $info[ 'meta_field_index' ], false, false );
|
7341 |
+
$info[ 'meta_field_value' ] = pods_clean_name( $info[ 'meta_field_value' ], false, false );
|
7342 |
+
|
7343 |
+
if ( empty( $info[ 'orderby' ] ) )
|
7344 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '`, `t`.`' . $info[ 'field_id' ] . '`';
|
7345 |
+
|
7346 |
+
if ( 'table' == pods_var_raw( 'storage', $info[ 'pod' ] ) && !in_array( $object_type, array( 'pod', 'table' ) ) ) {
|
7347 |
+
$info[ 'join' ][ 'd' ] = 'LEFT JOIN `' . $info[ 'pod_table' ] . '` AS `d` ON `d`.`id` = `t`.`' . $info[ 'field_id' ] . '`';
|
7348 |
+
//$info[ 'select' ] .= ', `d`.*';
|
7349 |
+
}
|
7350 |
+
|
7351 |
+
if ( !empty( $info[ 'pod' ] ) && is_array( $info[ 'pod' ] ) )
|
7352 |
+
$info[ 'recurse' ] = true;
|
7353 |
+
|
7354 |
+
$info[ 'type' ] = $object_type;
|
7355 |
+
$info[ 'object_name' ] = $object;
|
7356 |
+
|
7357 |
+
if ( pods_api_cache() ) {
|
7358 |
+
if ( did_action( 'init' ) )
|
7359 |
+
pods_transient_set( $transient, $info );
|
7360 |
+
else
|
7361 |
+
pods_transient_set( $transient . '_pre_init', $info );
|
7362 |
+
}
|
7363 |
+
}
|
7364 |
+
|
7365 |
+
$info = $this->do_hook( 'get_table_info', $info, $object_type, $object, $name, $pod, $field );
|
7366 |
+
|
7367 |
+
return $info;
|
7368 |
+
}
|
7369 |
+
|
7370 |
+
/**
|
7371 |
+
* Export a package
|
7372 |
+
*
|
7373 |
+
* $params['pod'] string Pod Type IDs to export
|
7374 |
+
* $params['template'] string Template IDs to export
|
7375 |
+
* $params['podpage'] string Pod Page IDs to export
|
7376 |
+
* $params['helper'] string Helper IDs to export
|
7377 |
+
*
|
7378 |
+
* @param array $params An associative array of parameters
|
7379 |
+
*
|
7380 |
+
* @return array|bool
|
7381 |
+
*
|
7382 |
+
* @since 1.9.0
|
7383 |
+
* @deprecated 2.0
|
7384 |
+
*/
|
7385 |
+
public function export_package ( $params ) {
|
7386 |
+
if ( class_exists( 'Pods_Migrate_Packages' ) )
|
7387 |
+
return Pods_Migrate_Packages::export( $params );
|
7388 |
+
|
7389 |
+
return false;
|
7390 |
+
}
|
7391 |
+
|
7392 |
+
/**
|
7393 |
+
* Replace an existing package
|
7394 |
+
*
|
7395 |
+
* @param mixed $data (optional) An associative array containing a package, or the json encoded package
|
7396 |
+
*
|
7397 |
+
* @return bool
|
7398 |
+
*
|
7399 |
+
* @since 1.9.8
|
7400 |
+
* @deprecated 2.0
|
7401 |
+
*/
|
7402 |
+
public function replace_package ( $data = false ) {
|
7403 |
+
return $this->import_package( $data, true );
|
7404 |
+
}
|
7405 |
+
|
7406 |
+
/**
|
7407 |
+
* Import a package
|
7408 |
+
*
|
7409 |
+
* @param mixed $data (optional) An associative array containing a package, or the json encoded package
|
7410 |
+
* @param bool $replace (optional) Replace existing items when found
|
7411 |
+
*
|
7412 |
+
* @return bool
|
7413 |
+
*
|
7414 |
+
* @since 1.9.0
|
7415 |
+
* @deprecated 2.0
|
7416 |
+
*/
|
7417 |
+
public function import_package ( $data = false, $replace = false ) {
|
7418 |
+
if ( class_exists( 'Pods_Migrate_Packages' ) )
|
7419 |
+
return Pods_Migrate_Packages::import( $data, $replace );
|
7420 |
+
|
7421 |
+
return false;
|
7422 |
+
}
|
7423 |
+
|
7424 |
+
/**
|
7425 |
+
* Validate a package
|
7426 |
+
*
|
7427 |
+
* @param array|string $data (optional) An associative array containing a package, or the json encoded package
|
7428 |
+
* @param bool $output (optional)
|
7429 |
+
*
|
7430 |
+
* @return array|bool
|
7431 |
+
*
|
7432 |
+
* @since 1.9.0
|
7433 |
+
* @deprecated 2.0
|
7434 |
+
*/
|
7435 |
+
public function validate_package ( $data = false, $output = false ) {
|
7436 |
+
return true;
|
7437 |
+
}
|
7438 |
+
|
7439 |
+
/**
|
7440 |
+
* Import data from an array or a CSV file.
|
7441 |
+
*
|
7442 |
+
* @param mixed $import_data PHP associative array or CSV input
|
7443 |
+
* @param bool $numeric_mode Use IDs instead of the name field when matching
|
7444 |
+
* @param string $format Format of import data, options are php or csv
|
7445 |
+
*
|
7446 |
+
* @return array IDs of imported items
|
7447 |
+
*
|
7448 |
+
* @since 1.7.1
|
7449 |
+
* @todo This needs some love and use of table_info etc for relationships
|
7450 |
+
*/
|
7451 |
+
public function import ( $import_data, $numeric_mode = false, $format = null ) {
|
7452 |
+
/**
|
7453 |
+
* @var $wpdb wpdb
|
7454 |
+
*/
|
7455 |
+
global $wpdb;
|
7456 |
+
|
7457 |
+
if ( null === $format && null !== $this->format )
|
7458 |
+
$format = $this->format;
|
7459 |
+
|
7460 |
+
if ( 'csv' == $format && !is_array( $import_data ) ) {
|
7461 |
+
$data = pods_migrate( 'sv', ',' )->parse( $import_data );
|
7462 |
+
|
7463 |
+
$import_data = $data[ 'items' ];
|
7464 |
+
}
|
7465 |
+
|
7466 |
+
pods_query( "SET NAMES utf8" );
|
7467 |
+
pods_query( "SET CHARACTER SET utf8" );
|
7468 |
+
|
7469 |
+
// Loop through the array of items
|
7470 |
+
$ids = array();
|
7471 |
+
|
7472 |
+
// Test to see if it's an array of arrays
|
7473 |
+
if ( !is_array( @current( $import_data ) ) )
|
7474 |
+
$import_data = array( $import_data );
|
7475 |
+
|
7476 |
+
$pod = $this->load_pod( array( 'name' => $this->pod ) );
|
7477 |
+
|
7478 |
+
if ( false === $pod )
|
7479 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
7480 |
+
|
7481 |
+
$fields = array_merge( $pod[ 'fields' ], $pod[ 'object_fields' ] );
|
7482 |
+
|
7483 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
7484 |
+
|
7485 |
+
foreach ( $import_data as $key => $data_row ) {
|
7486 |
+
$data = array();
|
7487 |
+
|
7488 |
+
// Loop through each field (use $fields so only valid fields get parsed)
|
7489 |
+
foreach ( $fields as $field_name => $field_data ) {
|
7490 |
+
if ( !isset( $data_row[ $field_name ] ) && !isset( $data_row[ $field_data[ 'label' ] ] ) )
|
7491 |
+
continue;
|
7492 |
+
|
7493 |
+
$field_id = $field_data[ 'id' ];
|
7494 |
+
$type = $field_data[ 'type' ];
|
7495 |
+
$pick_object = isset( $field_data[ 'pick_object' ] ) ? $field_data[ 'pick_object' ] : '';
|
7496 |
+
$pick_val = isset( $field_data[ 'pick_val' ] ) ? $field_data[ 'pick_val' ] : '';
|
7497 |
+
|
7498 |
+
if ( isset( $data_row[ $field_name] ) )
|
7499 |
+
$field_value = $data_row[ $field_name ];
|
7500 |
+
else
|
7501 |
+
$field_value = $data_row[ $field_data[ 'label' ] ];
|
7502 |
+
|
7503 |
+
if ( null !== $field_value && false !== $field_value && '' !== $field_value ) {
|
7504 |
+
if ( 'pick' == $type || in_array( $type, PodsForm::file_field_types() ) ) {
|
7505 |
+
$field_values = is_array( $field_value ) ? $field_value : array( $field_value );
|
7506 |
+
$pick_values = array();
|
7507 |
+
|
7508 |
+
foreach ( $field_values as $pick_value ) {
|
7509 |
+
if ( in_array( $type, PodsForm::file_field_types() ) || 'media' == $pick_object ) {
|
7510 |
+
$where = "`guid` = '" . pods_sanitize( $pick_value ) . "'";
|
7511 |
+
|
7512 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
7513 |
+
$where = "`ID` = " . pods_absint( $pick_value );
|
7514 |
+
|
7515 |
+
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this );
|
7516 |
+
|
7517 |
+
if ( !empty( $result ) )
|
7518 |
+
$pick_values[] = $result[ 0 ]->id;
|
7519 |
+
}
|
7520 |
+
// @todo This could and should be abstracted better and simplified
|
7521 |
+
elseif ( 'pick' == $type ) {
|
7522 |
+
$related_pod = false;
|
7523 |
+
|
7524 |
+
if ( 'pod' == $pick_object )
|
7525 |
+
$related_pod = $this->load_pod( array( 'name' => $pick_val, 'table_info' => true ), false );
|
7526 |
+
|
7527 |
+
if ( empty( $related_pod ) ) {
|
7528 |
+
$related_pod = array(
|
7529 |
+
'id' => 0,
|
7530 |
+
'type' => $pick_object
|
7531 |
+
);
|
7532 |
+
}
|
7533 |
+
|
7534 |
+
if ( in_array( 'taxonomy', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
7535 |
+
$where = "`t`.`name` = '" . pods_sanitize( $pick_value ) . "'";
|
7536 |
+
|
7537 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
7538 |
+
$where = "`tt`.`term_id` = " . pods_absint( $pick_value );
|
7539 |
+
|
7540 |
+
$result = pods_query( "SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id`", $this );
|
7541 |
+
|
7542 |
+
if ( !empty( $result ) )
|
7543 |
+
$pick_values[] = $result[ 0 ]->id;
|
7544 |
+
}
|
7545 |
+
elseif ( in_array( 'post_type', array( $pick_object, $related_pod[ 'type' ] ) ) || in_array( 'media', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
7546 |
+
$where = "`post_title` = '" . pods_sanitize( $pick_value ) . "'";
|
7547 |
+
|
7548 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
7549 |
+
$where = "`ID` = " . pods_absint( $pick_value );
|
7550 |
+
|
7551 |
+
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID`", $this );
|
7552 |
+
|
7553 |
+
if ( !empty( $result ) )
|
7554 |
+
$pick_values[] = $result[ 0 ]->id;
|
7555 |
+
}
|
7556 |
+
elseif ( in_array( 'user', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
7557 |
+
$where = "`user_login` = '" . pods_sanitize( $pick_value ) . "'";
|
7558 |
+
|
7559 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
7560 |
+
$where = "`ID` = " . pods_absint( $pick_value );
|
7561 |
+
|
7562 |
+
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID`", $this );
|
7563 |
+
|
7564 |
+
if ( !empty( $result ) )
|
7565 |
+
$pick_values[] = $result[ 0 ]->id;
|
7566 |
+
}
|
7567 |
+
elseif ( in_array( 'comment', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
7568 |
+
$where = "`comment_ID` = " . pods_absint( $pick_value );
|
7569 |
+
|
7570 |
+
$result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID`", $this );
|
7571 |
+
|
7572 |
+
if ( !empty( $result ) )
|
7573 |
+
$pick_values[] = $result[ 0 ]->id;
|
7574 |
+
}
|
7575 |
+
elseif ( in_array( $pick_object, $simple_tableless_objects ) )
|
7576 |
+
$pick_values[] = $pick_value;
|
7577 |
+
elseif ( !empty( $related_pod[ 'id' ] ) ) {
|
7578 |
+
$where = "`" . $related_pod[ 'field_index' ] . "` = '" . pods_sanitize( $pick_value ) . "'";
|
7579 |
+
|
7580 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
7581 |
+
$where = "`" . $related_pod[ 'field_id' ] . "` = " . pods_absint( $pick_value );
|
7582 |
+
|
7583 |
+
$result = pods_query( "SELECT `" . $related_pod[ 'field_id' ] . "` AS `id` FROM `" . $related_pod[ 'table' ] . "` WHERE {$where} ORDER BY `" . $related_pod[ 'field_id' ] . "`", $this );
|
7584 |
+
|
7585 |
+
if ( !empty( $result ) )
|
7586 |
+
$pick_values[] = $result[ 0 ]->id;
|
7587 |
+
}
|
7588 |
+
}
|
7589 |
+
}
|
7590 |
+
|
7591 |
+
$field_value = implode( ',', $pick_values );
|
7592 |
+
}
|
7593 |
+
|
7594 |
+
$data[ $field_name ] = $field_value;
|
7595 |
+
}
|
7596 |
+
}
|
7597 |
+
|
7598 |
+
if ( !empty( $data ) ) {
|
7599 |
+
$params = array(
|
7600 |
+
'pod' => $this->pod,
|
7601 |
+
'data' => $data
|
7602 |
+
);
|
7603 |
+
|
7604 |
+
$ids[] = $this->save_pod_item( $params );
|
7605 |
+
}
|
7606 |
+
}
|
7607 |
+
|
7608 |
+
return $ids;
|
7609 |
+
}
|
7610 |
+
|
7611 |
+
/**
|
7612 |
+
* Export data from a Pod
|
7613 |
+
*
|
7614 |
+
* @param string|object $pod The pod name or Pods object
|
7615 |
+
* @param array $params An associative array of parameters
|
7616 |
+
*
|
7617 |
+
* @return array Data arrays of all exported pod items
|
7618 |
+
* @since 1.7.1
|
7619 |
+
*/
|
7620 |
+
public function export ( $pod = null, $params = null ) {
|
7621 |
+
|
7622 |
+
if ( empty( $pod ) ) {
|
7623 |
+
$pod = $this->pod;
|
7624 |
+
}
|
7625 |
+
|
7626 |
+
$find = array(
|
7627 |
+
'limit' => -1,
|
7628 |
+
'search' => false,
|
7629 |
+
'pagination' => false
|
7630 |
+
);
|
7631 |
+
|
7632 |
+
if ( !empty( $params ) && isset( $params[ 'params' ] ) ) {
|
7633 |
+
$find = array_merge( $find, (array) $params[ 'params' ] );
|
7634 |
+
|
7635 |
+
unset( $params[ 'params' ] );
|
7636 |
+
|
7637 |
+
$pod = pods( $pod, $find );
|
7638 |
+
}
|
7639 |
+
elseif ( !is_object( $pod ) ) {
|
7640 |
+
$pod = pods( $pod, $find );
|
7641 |
+
}
|
7642 |
+
|
7643 |
+
$data = array();
|
7644 |
+
|
7645 |
+
while ( $pod->fetch() ) {
|
7646 |
+
$data[ $pod->id() ] = $this->export_pod_item( $params, $pod );
|
7647 |
+
$data[ $pod->id() ][ 'ID' ] = (int) $pod->id();
|
7648 |
+
}
|
7649 |
+
|
7650 |
+
$data = $this->do_hook( 'export', $data, $pod->pod, $pod );
|
7651 |
+
|
7652 |
+
return $data;
|
7653 |
+
}
|
7654 |
+
|
7655 |
+
/**
|
7656 |
+
* Convert CSV to a PHP array
|
7657 |
+
*
|
7658 |
+
* @param string $data The CSV input
|
7659 |
+
*
|
7660 |
+
* @return array
|
7661 |
+
* @since 1.7.1
|
7662 |
+
*
|
7663 |
+
* @deprecated 2.3.5
|
7664 |
+
*/
|
7665 |
+
public function csv_to_php ( $data, $delimiter = ',' ) {
|
7666 |
+
pods_deprecated( "PodsAPI->csv_to_php", '2.3.5' );
|
7667 |
+
|
7668 |
+
$data = pods_migrate( 'sv', $delimiter, $data )->parse();
|
7669 |
+
|
7670 |
+
return $data[ 'items' ];
|
7671 |
+
}
|
7672 |
+
|
7673 |
+
/**
|
7674 |
+
* Clear Pod-related cache
|
7675 |
+
*
|
7676 |
+
* @param array $pod
|
7677 |
+
*
|
7678 |
+
* @return void
|
7679 |
+
*
|
7680 |
+
* @since 2.0
|
7681 |
+
*/
|
7682 |
+
public function cache_flush_pods ( $pod = null ) {
|
7683 |
+
/**
|
7684 |
+
* @var $wpdb wpdb
|
7685 |
+
*/
|
7686 |
+
global $wpdb;
|
7687 |
+
|
7688 |
+
pods_transient_clear( 'pods' );
|
7689 |
+
pods_transient_clear( 'pods_components' );
|
7690 |
+
|
7691 |
+
if ( null !== $pod && is_array( $pod ) ) {
|
7692 |
+
pods_transient_clear( 'pods_pod_' . $pod[ 'name' ] );
|
7693 |
+
pods_cache_clear( $pod[ 'name' ], 'pods-class' );
|
7694 |
+
|
7695 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
7696 |
+
pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
7697 |
+
}
|
7698 |
+
|
7699 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) )
|
7700 |
+
pods_transient_clear( 'pods_wp_cpt_ct' );
|
7701 |
+
}
|
7702 |
+
else
|
7703 |
+
pods_transient_clear( 'pods_wp_cpt_ct' );
|
7704 |
+
|
7705 |
+
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_pods%'" );
|
7706 |
+
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_pods%'" );
|
7707 |
+
|
7708 |
+
pods_cache_clear( true );
|
7709 |
+
|
7710 |
+
pods_transient_set( 'pods_flush_rewrites', 1 );
|
7711 |
+
}
|
7712 |
+
|
7713 |
+
/**
|
7714 |
+
* Process a Pod-based form
|
7715 |
+
*
|
7716 |
+
* @param mixed $params
|
7717 |
+
* @param object $obj Pod object
|
7718 |
+
* @param array $fields Fields being submitted in form ( key => settings )
|
7719 |
+
* @param string $thank_you URL to send to upon success
|
7720 |
+
*
|
7721 |
+
* @return mixed
|
7722 |
+
*
|
7723 |
+
* @since 2.0
|
7724 |
+
*/
|
7725 |
+
public function process_form ( $params, $obj = null, $fields = null, $thank_you = null ) {
|
7726 |
+
$this->display_errors = false;
|
7727 |
+
|
7728 |
+
$form = null;
|
7729 |
+
|
7730 |
+
$nonce = pods_var( '_pods_nonce', $params );
|
7731 |
+
$pod = pods_var( '_pods_pod', $params );
|
7732 |
+
$id = pods_var( '_pods_id', $params );
|
7733 |
+
$uri = pods_var( '_pods_uri', $params );
|
7734 |
+
$form = pods_var( '_pods_form', $params );
|
7735 |
+
$location = pods_var( '_pods_location', $params );
|
7736 |
+
|
7737 |
+
if ( is_object( $obj ) ) {
|
7738 |
+
$pod = $obj->pod;
|
7739 |
+
$id = $obj->id();
|
7740 |
+
}
|
7741 |
+
|
7742 |
+
if ( !empty( $fields ) ) {
|
7743 |
+
$fields = array_keys( $fields );
|
7744 |
+
$form = implode( ',', $fields );
|
7745 |
+
}
|
7746 |
+
else
|
7747 |
+
$fields = explode( ',', $form );
|
7748 |
+
|
7749 |
+
if ( empty( $nonce ) || empty( $pod ) || empty( $uri ) || empty( $fields ) )
|
7750 |
+
return pods_error( __( 'Invalid submission', 'pods' ), $this );
|
7751 |
+
|
7752 |
+
$uid = @session_id();
|
7753 |
+
|
7754 |
+
if ( is_user_logged_in() )
|
7755 |
+
$uid = 'user_' . get_current_user_id();
|
7756 |
+
|
7757 |
+
$field_hash = wp_create_nonce( 'pods_fields_' . $form );
|
7758 |
+
|
7759 |
+
$action = 'pods_form_' . $pod . '_' . $uid . '_' . $id . '_' . $uri . '_' . $field_hash;
|
7760 |
+
|
7761 |
+
if ( empty( $uid ) )
|
7762 |
+
return pods_error( __( 'Access denied for your session, please refresh and try again.', 'pods' ), $this );
|
7763 |
+
|
7764 |
+
if ( false === wp_verify_nonce( $nonce, $action ) )
|
7765 |
+
return pods_error( __( 'Access denied, please refresh and try again.', 'pods' ), $this );
|
7766 |
+
|
7767 |
+
$data = array();
|
7768 |
+
|
7769 |
+
foreach ( $fields as $field ) {
|
7770 |
+
$data[ $field ] = pods_var_raw( 'pods_field_' . $field, $params, '' );
|
7771 |
+
}
|
7772 |
+
|
7773 |
+
$params = array(
|
7774 |
+
'pod' => $pod,
|
7775 |
+
'id' => $id,
|
7776 |
+
'data' => $data,
|
7777 |
+
'from' => 'process_form',
|
7778 |
+
'location' => $location
|
7779 |
+
);
|
7780 |
+
|
7781 |
+
$id = $this->save_pod_item( $params );
|
7782 |
+
|
7783 |
+
if ( 0 < $id && !empty( $thank_you ) ) {
|
7784 |
+
$thank_you = str_replace( 'X_ID_X', $id, $thank_you );
|
7785 |
+
|
7786 |
+
pods_redirect( $thank_you );
|
7787 |
+
}
|
7788 |
+
|
7789 |
+
return $id;
|
7790 |
+
}
|
7791 |
+
|
7792 |
+
/**
|
7793 |
+
* Handle filters / actions for the class
|
7794 |
+
*
|
7795 |
+
* @since 2.0
|
7796 |
+
*/
|
7797 |
+
private function do_hook () {
|
7798 |
+
$args = func_get_args();
|
7799 |
+
if ( empty( $args ) )
|
7800 |
+
return false;
|
7801 |
+
$name = array_shift( $args );
|
7802 |
+
return pods_do_hook( "api", $name, $args, $this );
|
7803 |
+
}
|
7804 |
+
|
7805 |
+
/**
|
7806 |
+
* Handle variables that have been deprecated
|
7807 |
+
*
|
7808 |
+
* @since 2.0
|
7809 |
+
*/
|
7810 |
+
public function __get ( $name ) {
|
7811 |
+
$name = (string) $name;
|
7812 |
+
|
7813 |
+
if ( !isset( $this->deprecated ) ) {
|
7814 |
+
require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
|
7815 |
+
$this->deprecated = new PodsAPI_Deprecated( $this );
|
7816 |
+
}
|
7817 |
+
|
7818 |
+
$var = null;
|
7819 |
+
|
7820 |
+
if ( isset( $this->deprecated->{$name} ) ) {
|
7821 |
+
pods_deprecated( "PodsAPI->{$name}", '2.0' );
|
7822 |
+
|
7823 |
+
$var = $this->deprecated->{$name};
|
7824 |
+
}
|
7825 |
+
else
|
7826 |
+
pods_deprecated( "PodsAPI->{$name}", '2.0' );
|
7827 |
+
|
7828 |
+
return $var;
|
7829 |
+
}
|
7830 |
+
|
7831 |
+
/**
|
7832 |
+
* Handle methods that have been deprecated
|
7833 |
+
*
|
7834 |
+
* @since 2.0
|
7835 |
+
*/
|
7836 |
+
public function __call ( $name, $args ) {
|
7837 |
+
$name = (string) $name;
|
7838 |
+
|
7839 |
+
if ( !isset( $this->deprecated ) ) {
|
7840 |
+
require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
|
7841 |
+
$this->deprecated = new PodsAPI_Deprecated( $this );
|
7842 |
+
}
|
7843 |
+
|
7844 |
+
if ( method_exists( $this->deprecated, $name ) )
|
7845 |
+
return call_user_func_array( array( $this->deprecated, $name ), $args );
|
7846 |
+
else
|
7847 |
+
pods_deprecated( "PodsAPI::{$name}", '2.0' );
|
7848 |
+
}
|
7849 |
+
}
|
classes/PodsAdmin.php
ADDED
@@ -0,0 +1,2395 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsAdmin {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var PodsAdmin
|
9 |
+
*/
|
10 |
+
static $instance = null;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Singleton handling for a basic pods_admin() request
|
14 |
+
*
|
15 |
+
* @return \PodsAdmin
|
16 |
+
*
|
17 |
+
* @since 2.3.5
|
18 |
+
*/
|
19 |
+
public static function init () {
|
20 |
+
if ( !is_object( self::$instance ) )
|
21 |
+
self::$instance = new PodsAdmin();
|
22 |
+
|
23 |
+
return self::$instance;
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Setup and Handle Admin functionality
|
28 |
+
*
|
29 |
+
* @return \PodsAdmin
|
30 |
+
*
|
31 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
32 |
+
* @since 2.0
|
33 |
+
*/
|
34 |
+
public function __construct () {
|
35 |
+
// Scripts / Stylesheets
|
36 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 );
|
37 |
+
|
38 |
+
// AJAX $_POST fix
|
39 |
+
add_action( 'admin_init', array( $this, 'admin_init' ), 9 );
|
40 |
+
|
41 |
+
// Menus
|
42 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 );
|
43 |
+
|
44 |
+
// AJAX for Admin
|
45 |
+
add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) );
|
46 |
+
add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) );
|
47 |
+
|
48 |
+
// Add Media Bar button for Shortcode
|
49 |
+
add_action( 'media_buttons', array( $this, 'media_button' ), 12 );
|
50 |
+
|
51 |
+
// Add the Pods capabilities
|
52 |
+
add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) );
|
53 |
+
|
54 |
+
add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) );
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Init the admin area
|
59 |
+
*
|
60 |
+
* @since 2.0
|
61 |
+
*/
|
62 |
+
public function admin_init () {
|
63 |
+
// Fix for plugins that *don't do it right* so we don't cause issues for users
|
64 |
+
if ( defined( 'DOING_AJAX' ) && !empty( $_POST ) ) {
|
65 |
+
$pods_admin_ajax_actions = array(
|
66 |
+
'pods_admin',
|
67 |
+
'pods_relationship',
|
68 |
+
'pods_upload',
|
69 |
+
'pods_admin_components'
|
70 |
+
);
|
71 |
+
|
72 |
+
$pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions );
|
73 |
+
|
74 |
+
if ( in_array( pods_var( 'action', 'get' ), $pods_admin_ajax_actions ) || in_array( pods_var( 'action', 'post' ), $pods_admin_ajax_actions ) ) {
|
75 |
+
foreach ( $_POST as $key => $value ) {
|
76 |
+
if ( 'action' == $key || 0 === strpos( $key, '_podsfix_' ) )
|
77 |
+
continue;
|
78 |
+
|
79 |
+
unset( $_POST[ $key ] );
|
80 |
+
|
81 |
+
$_POST[ '_podsfix_' . $key ] = $value;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Attach requirements to admin header
|
89 |
+
*
|
90 |
+
* @since 2.0
|
91 |
+
*/
|
92 |
+
public function admin_head () {
|
93 |
+
wp_register_style( 'pods-admin', PODS_URL . 'ui/css/pods-admin.css', array(), PODS_VERSION );
|
94 |
+
|
95 |
+
wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION );
|
96 |
+
|
97 |
+
wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION );
|
98 |
+
|
99 |
+
wp_register_style( 'pods-manage', PODS_URL . 'ui/css/pods-manage.css', array(), PODS_VERSION );
|
100 |
+
|
101 |
+
wp_register_style( 'pods-wizard', PODS_URL . 'ui/css/pods-wizard.css', array(), PODS_VERSION );
|
102 |
+
|
103 |
+
wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION );
|
104 |
+
|
105 |
+
wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION );
|
106 |
+
|
107 |
+
if ( isset( $_GET[ 'page' ] ) ) {
|
108 |
+
$page = $_GET[ 'page' ];
|
109 |
+
if ( 'pods' == $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) {
|
110 |
+
?>
|
111 |
+
<script type="text/javascript">
|
112 |
+
var PODS_URL = "<?php echo PODS_URL; ?>";
|
113 |
+
</script>
|
114 |
+
<?php
|
115 |
+
wp_enqueue_script( 'jquery' );
|
116 |
+
wp_enqueue_script( 'jquery-ui-core' );
|
117 |
+
wp_enqueue_script( 'jquery-ui-sortable' );
|
118 |
+
|
119 |
+
wp_enqueue_style( 'jquery-ui' );
|
120 |
+
|
121 |
+
wp_enqueue_script( 'pods-floatmenu' );
|
122 |
+
|
123 |
+
wp_enqueue_style( 'pods-qtip' );
|
124 |
+
wp_enqueue_script( 'jquery-qtip' );
|
125 |
+
wp_enqueue_script( 'pods-qtip-init' );
|
126 |
+
|
127 |
+
wp_enqueue_script( 'pods' );
|
128 |
+
|
129 |
+
if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) )
|
130 |
+
wp_enqueue_script( 'post' );
|
131 |
+
elseif ( 0 === strpos( $page, 'pods-settings-' ) ) {
|
132 |
+
wp_enqueue_script( 'post' );
|
133 |
+
wp_enqueue_style( 'pods-admin' );
|
134 |
+
}
|
135 |
+
else
|
136 |
+
wp_enqueue_style( 'pods-admin' );
|
137 |
+
|
138 |
+
if ( 'pods-advanced' == $page ) {
|
139 |
+
wp_register_style( 'pods-advanced', PODS_URL . 'ui/css/pods-advanced.css', array(), '1.0' );
|
140 |
+
wp_enqueue_style( 'pods-advanced' );
|
141 |
+
|
142 |
+
wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' );
|
143 |
+
wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' );
|
144 |
+
wp_enqueue_script( 'jquery-ui-dialog' );
|
145 |
+
|
146 |
+
wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION );
|
147 |
+
wp_enqueue_script( 'pods-advanced' );
|
148 |
+
}
|
149 |
+
elseif ( 'pods-packages' == $page )
|
150 |
+
wp_enqueue_style( 'pods-wizard' );
|
151 |
+
elseif ( 'pods-wizard' == $page || 'pods-upgrade' == $page || ( in_array( $page, array( 'pods', 'pods-add-new' ) ) && in_array( pods_var( 'action', 'get', 'manage' ), array( 'add', 'manage' ) ) ) ) {
|
152 |
+
wp_enqueue_style( 'pods-wizard' );
|
153 |
+
|
154 |
+
if ( 'pods-upgrade' == $page )
|
155 |
+
wp_enqueue_script( 'pods-upgrade' );
|
156 |
+
}
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Build the admin menus
|
163 |
+
*
|
164 |
+
* @since 2.0
|
165 |
+
*/
|
166 |
+
public function admin_menu () {
|
167 |
+
$advanced_content_types = PodsMeta::$advanced_content_types;
|
168 |
+
$taxonomies = PodsMeta::$taxonomies;
|
169 |
+
$settings = PodsMeta::$settings;
|
170 |
+
|
171 |
+
$all_pods = pods_api()->load_pods( array( 'count' => true ) );
|
172 |
+
|
173 |
+
if ( !PodsInit::$upgrade_needed || ( pods_is_admin() && 1 == pods_var( 'pods_upgrade_bypass' ) ) ) {
|
174 |
+
$submenu_items = array();
|
175 |
+
|
176 |
+
if ( !empty( $advanced_content_types ) ) {
|
177 |
+
$submenu = array();
|
178 |
+
|
179 |
+
$pods_pages = 0;
|
180 |
+
|
181 |
+
foreach ( (array) $advanced_content_types as $pod ) {
|
182 |
+
if ( !isset( $pod[ 'name' ] ) || !isset( $pod[ 'options' ] ) || empty( $pod[ 'fields' ] ) )
|
183 |
+
continue;
|
184 |
+
elseif ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ], 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) )
|
185 |
+
continue;
|
186 |
+
|
187 |
+
if ( 1 == pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) {
|
188 |
+
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
189 |
+
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
190 |
+
|
191 |
+
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
|
192 |
+
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
193 |
+
|
194 |
+
$singular_label = pods_var_raw( 'label_singular', $pod[ 'options' ], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ), null, true );
|
195 |
+
$plural_label = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
196 |
+
|
197 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'objects' );
|
198 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
199 |
+
|
200 |
+
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
|
201 |
+
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
|
202 |
+
|
203 |
+
if ( empty( $menu_position ) )
|
204 |
+
$menu_position = null;
|
205 |
+
|
206 |
+
$parent_page = null;
|
207 |
+
|
208 |
+
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) {
|
209 |
+
if ( !empty( $menu_location_custom ) ) {
|
210 |
+
if ( !isset( $submenu_items[ $menu_location_custom ] ) )
|
211 |
+
$submenu_items[ $menu_location_custom ] = array();
|
212 |
+
|
213 |
+
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', 'pods-manage-' . $pod[ 'name' ], array( $this, 'admin_content' ) );
|
214 |
+
|
215 |
+
continue;
|
216 |
+
}
|
217 |
+
else {
|
218 |
+
$pods_pages++;
|
219 |
+
|
220 |
+
$parent_page = $page = 'pods-manage-' . $pod[ 'name' ];
|
221 |
+
|
222 |
+
if ( empty( $menu_position ) )
|
223 |
+
add_object_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon );
|
224 |
+
else
|
225 |
+
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
|
226 |
+
|
227 |
+
$all_title = $plural_label;
|
228 |
+
$all_label = __( 'All', 'pods' ) . ' ' . $plural_label;
|
229 |
+
|
230 |
+
if ( $page == pods_var( 'page', 'get' ) ) {
|
231 |
+
if ( 'edit' == pods_var( 'action', 'get', 'manage' ) )
|
232 |
+
$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
|
233 |
+
elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) )
|
234 |
+
$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
235 |
+
}
|
236 |
+
|
237 |
+
add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) );
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ] ) ) ) {
|
242 |
+
$page = 'pods-add-new-' . $pod[ 'name' ];
|
243 |
+
|
244 |
+
if ( null === $parent_page ) {
|
245 |
+
$pods_pages++;
|
246 |
+
|
247 |
+
$parent_page = $page;
|
248 |
+
|
249 |
+
if ( empty( $menu_position ) )
|
250 |
+
add_object_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon );
|
251 |
+
else
|
252 |
+
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
|
253 |
+
}
|
254 |
+
|
255 |
+
$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
256 |
+
$add_label = __( 'Add New', 'pods' );
|
257 |
+
|
258 |
+
add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) );
|
259 |
+
}
|
260 |
+
}
|
261 |
+
else
|
262 |
+
$submenu[] = $pod;
|
263 |
+
}
|
264 |
+
|
265 |
+
$submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu );
|
266 |
+
|
267 |
+
if ( !empty( $submenu ) && ( !defined( 'PODS_DISABLE_CONTENT_MENU' ) || !PODS_DISABLE_CONTENT_MENU ) ) {
|
268 |
+
$parent_page = null;
|
269 |
+
|
270 |
+
foreach ( $submenu as $item ) {
|
271 |
+
$singular_label = pods_var_raw( 'label_singular', $item[ 'options' ], pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ), null, true );
|
272 |
+
$plural_label = pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true );
|
273 |
+
|
274 |
+
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $item[ 'name' ], 'pods_delete_' . $item[ 'name' ] ) ) ) {
|
275 |
+
$page = 'pods-manage-' . $item[ 'name' ];
|
276 |
+
|
277 |
+
if ( null === $parent_page ) {
|
278 |
+
$parent_page = $page;
|
279 |
+
|
280 |
+
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, PODS_URL . 'ui/images/icon16.png', '58.5' );
|
281 |
+
}
|
282 |
+
|
283 |
+
$all_title = $plural_label;
|
284 |
+
$all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
|
285 |
+
|
286 |
+
if ( $page == pods_var( 'page', 'get' ) ) {
|
287 |
+
if ( 'edit' == pods_var( 'action', 'get', 'manage' ) )
|
288 |
+
$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
|
289 |
+
elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) )
|
290 |
+
$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
291 |
+
}
|
292 |
+
|
293 |
+
add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) );
|
294 |
+
}
|
295 |
+
elseif ( current_user_can( 'pods_add_' . $item[ 'name' ] ) ) {
|
296 |
+
$page = 'pods-add-new-' . $item[ 'name' ];
|
297 |
+
|
298 |
+
if ( null === $parent_page ) {
|
299 |
+
$parent_page = $page;
|
300 |
+
|
301 |
+
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, PODS_URL . 'ui/images/icon16.png', '58.5' );
|
302 |
+
}
|
303 |
+
|
304 |
+
$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
305 |
+
$add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
|
306 |
+
|
307 |
+
add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) );
|
308 |
+
}
|
309 |
+
}
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
if ( !empty( $taxonomies ) ) {
|
314 |
+
foreach ( (array) $taxonomies as $pod ) {
|
315 |
+
if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) )
|
316 |
+
continue;
|
317 |
+
|
318 |
+
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
319 |
+
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
320 |
+
|
321 |
+
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
|
322 |
+
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
323 |
+
|
324 |
+
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
|
325 |
+
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
|
326 |
+
|
327 |
+
if ( empty( $menu_position ) )
|
328 |
+
$menu_position = null;
|
329 |
+
|
330 |
+
$menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ];
|
331 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' );
|
332 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
333 |
+
|
334 |
+
if ( 'default' == $menu_location )
|
335 |
+
continue;
|
336 |
+
|
337 |
+
$taxonomy_data = get_taxonomy( $pod[ 'name' ] );
|
338 |
+
|
339 |
+
foreach ( (array) $taxonomy_data->object_type as $post_type ) {
|
340 |
+
if ( 'post' == $post_type )
|
341 |
+
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] );
|
342 |
+
elseif ( 'attachment' == $post_type )
|
343 |
+
remove_submenu_page( 'upload.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type );
|
344 |
+
else
|
345 |
+
remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type );
|
346 |
+
}
|
347 |
+
|
348 |
+
if ( 'settings' == $menu_location )
|
349 |
+
add_options_page( $page_title, $menu_label, 'read', $menu_slug );
|
350 |
+
elseif ( 'appearances' == $menu_location )
|
351 |
+
add_theme_page( $page_title, $menu_label, 'read', $menu_slug );
|
352 |
+
elseif ( 'objects' == $menu_location ) {
|
353 |
+
if ( empty( $menu_position ) )
|
354 |
+
add_object_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon );
|
355 |
+
else
|
356 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
|
357 |
+
}
|
358 |
+
elseif ( 'top' == $menu_location )
|
359 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
|
360 |
+
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
|
361 |
+
if ( !isset( $submenu_items[ $menu_location_custom ] ) )
|
362 |
+
$submenu_items[ $menu_location_custom ] = array();
|
363 |
+
|
364 |
+
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, '' );
|
365 |
+
}
|
366 |
+
}
|
367 |
+
}
|
368 |
+
|
369 |
+
if ( !empty( $settings ) ) {
|
370 |
+
foreach ( (array) $settings as $pod ) {
|
371 |
+
if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) )
|
372 |
+
continue;
|
373 |
+
|
374 |
+
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
375 |
+
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
376 |
+
|
377 |
+
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
|
378 |
+
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
379 |
+
|
380 |
+
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
|
381 |
+
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
|
382 |
+
|
383 |
+
if ( empty( $menu_position ) )
|
384 |
+
$menu_position = null;
|
385 |
+
|
386 |
+
$menu_slug = 'pods-settings-' . $pod[ 'name' ];
|
387 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'settings' );
|
388 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
389 |
+
|
390 |
+
if ( 'settings' == $menu_location )
|
391 |
+
add_options_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
|
392 |
+
elseif ( 'appearances' == $menu_location )
|
393 |
+
add_theme_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
|
394 |
+
elseif ( 'objects' == $menu_location ) {
|
395 |
+
if ( empty( $menu_position ) )
|
396 |
+
add_object_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon );
|
397 |
+
else
|
398 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position );
|
399 |
+
}
|
400 |
+
elseif ( 'top' == $menu_location )
|
401 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position );
|
402 |
+
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
|
403 |
+
if ( !isset( $submenu_items[ $menu_location_custom ] ) )
|
404 |
+
$submenu_items[ $menu_location_custom ] = array();
|
405 |
+
|
406 |
+
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
|
407 |
+
}
|
408 |
+
}
|
409 |
+
}
|
410 |
+
|
411 |
+
foreach ( $submenu_items as $items ) {
|
412 |
+
foreach ( $items as $item ) {
|
413 |
+
call_user_func_array( 'add_submenu_page', $item );
|
414 |
+
}
|
415 |
+
}
|
416 |
+
|
417 |
+
$admin_menus = array(
|
418 |
+
'pods' => array(
|
419 |
+
'label' => __( 'Edit Pods', 'pods' ),
|
420 |
+
'function' => array( $this, 'admin_setup' ),
|
421 |
+
'access' => 'pods'
|
422 |
+
),
|
423 |
+
'pods-add-new' => array(
|
424 |
+
'label' => __( 'Add New', 'pods' ),
|
425 |
+
'function' => array( $this, 'admin_setup' ),
|
426 |
+
'access' => 'pods'
|
427 |
+
),
|
428 |
+
'pods-components' => array(
|
429 |
+
'label' => __( 'Components', 'pods' ),
|
430 |
+
'function' => array( $this, 'admin_components' ),
|
431 |
+
'access' => 'pods_components'
|
432 |
+
),
|
433 |
+
'pods-settings' => array(
|
434 |
+
'label' => __( 'Settings', 'pods' ),
|
435 |
+
'function' => array( $this, 'admin_settings' ),
|
436 |
+
'access' => 'pods_settings'
|
437 |
+
),
|
438 |
+
'pods-help' => array(
|
439 |
+
'label' => __( 'Help', 'pods' ),
|
440 |
+
'function' => array( $this, 'admin_help' )
|
441 |
+
)
|
442 |
+
);
|
443 |
+
|
444 |
+
if ( empty( $all_pods ) )
|
445 |
+
unset( $admin_menus[ 'pods' ] );
|
446 |
+
|
447 |
+
add_filter( 'parent_file' , array( $this, 'parent_file' ) );
|
448 |
+
}
|
449 |
+
else {
|
450 |
+
$admin_menus = array(
|
451 |
+
'pods-upgrade' => array(
|
452 |
+
'label' => __( 'Upgrade', 'pods' ),
|
453 |
+
'function' => array( $this, 'admin_upgrade' ),
|
454 |
+
'access' => 'manage_options'
|
455 |
+
),
|
456 |
+
'pods-settings' => array(
|
457 |
+
'label' => __( 'Settings', 'pods' ),
|
458 |
+
'function' => array( $this, 'admin_settings' ),
|
459 |
+
'access' => 'pods_settings'
|
460 |
+
),
|
461 |
+
'pods-help' => array(
|
462 |
+
'label' => __( 'Help', 'pods' ),
|
463 |
+
'function' => array( $this, 'admin_help' )
|
464 |
+
)
|
465 |
+
);
|
466 |
+
|
467 |
+
add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
|
468 |
+
}
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Add or change Pods Admin menu items
|
472 |
+
*
|
473 |
+
* @params array $admin_menus The submenu items in Pods Admin menu.
|
474 |
+
*
|
475 |
+
* @since unknown
|
476 |
+
*/
|
477 |
+
$admin_menus = apply_filters( 'pods_admin_menu', $admin_menus );
|
478 |
+
|
479 |
+
$parent = false;
|
480 |
+
|
481 |
+
if ( !empty( $admin_menus ) && ( !defined( 'PODS_DISABLE_ADMIN_MENU' ) || !PODS_DISABLE_ADMIN_MENU ) ) {
|
482 |
+
foreach ( $admin_menus as $page => $menu_item ) {
|
483 |
+
if ( !pods_is_admin( pods_var_raw( 'access', $menu_item ) ) )
|
484 |
+
continue;
|
485 |
+
|
486 |
+
// Don't just show the help page
|
487 |
+
if ( false === $parent && 'pods-help' == $page )
|
488 |
+
continue;
|
489 |
+
|
490 |
+
if ( !isset( $menu_item[ 'label' ] ) )
|
491 |
+
$menu_item[ 'label' ] = $page;
|
492 |
+
|
493 |
+
if ( false === $parent ) {
|
494 |
+
$parent = $page;
|
495 |
+
|
496 |
+
$menu = __( 'Pods Admin', 'pods' );
|
497 |
+
|
498 |
+
if ( 'pods-upgrade' == $parent )
|
499 |
+
$menu = __( 'Pods Upgrade', 'pods' );
|
500 |
+
|
501 |
+
add_menu_page( $menu, $menu, 'read', $parent, null, PODS_URL . 'ui/images/icon16.png' );
|
502 |
+
}
|
503 |
+
|
504 |
+
add_submenu_page( $parent, $menu_item[ 'label' ], $menu_item[ 'label' ], 'read', $page, $menu_item[ 'function' ] );
|
505 |
+
|
506 |
+
if ( 'pods-components' == $page )
|
507 |
+
PodsInit::$components->menu( $parent );
|
508 |
+
}
|
509 |
+
}
|
510 |
+
}
|
511 |
+
|
512 |
+
/**
|
513 |
+
* Set the correct parent_file to highlight the correct top level menu
|
514 |
+
*/
|
515 |
+
public function parent_file ( $parent_file ) {
|
516 |
+
global $current_screen;
|
517 |
+
|
518 |
+
if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) {
|
519 |
+
$taxonomies = PodsMeta::$taxonomies;
|
520 |
+
if ( !empty( $taxonomies ) ) {
|
521 |
+
foreach ( (array) $taxonomies as $pod ) {
|
522 |
+
if ( $current_screen->taxonomy !== $pod[ 'name' ] )
|
523 |
+
continue;
|
524 |
+
|
525 |
+
$menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ];
|
526 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' );
|
527 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
528 |
+
|
529 |
+
if ( 'settings' == $menu_location )
|
530 |
+
$parent_file = 'options-general.php';
|
531 |
+
elseif ( 'appearances' == $menu_location )
|
532 |
+
$parent_file = 'themes.php';
|
533 |
+
elseif ( 'objects' == $menu_location )
|
534 |
+
$parent_file = $menu_slug;
|
535 |
+
elseif ( 'top' == $menu_location )
|
536 |
+
$parent_file = $menu_slug;
|
537 |
+
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
|
538 |
+
$parent_file = $menu_location_custom;
|
539 |
+
}
|
540 |
+
|
541 |
+
break;
|
542 |
+
}
|
543 |
+
}
|
544 |
+
}
|
545 |
+
|
546 |
+
if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) ) {
|
547 |
+
global $submenu_file;
|
548 |
+
$components = PodsInit::$components->components;
|
549 |
+
foreach ( $components as $component => $component_data ) {
|
550 |
+
if ( ! empty( $component_data[ 'MenuPage' ] ) && $parent_file === $component_data[ 'MenuPage' ] ) {
|
551 |
+
$parent_file = 'pods';
|
552 |
+
$submenu_file = $component_data[ 'MenuPage' ];
|
553 |
+
}
|
554 |
+
}
|
555 |
+
}
|
556 |
+
|
557 |
+
return $parent_file;
|
558 |
+
}
|
559 |
+
|
560 |
+
public function upgrade_notice () {
|
561 |
+
echo '<div class="error fade"><p>';
|
562 |
+
echo sprintf(
|
563 |
+
__( '<strong>NOTICE:</strong> Pods %s requires your action to complete the upgrade. Please run the <a href="%s">Upgrade Wizard</a>.', 'pods' ),
|
564 |
+
PODS_VERSION,
|
565 |
+
admin_url( 'admin.php?page=pods-upgrade' )
|
566 |
+
);
|
567 |
+
echo '</p></div>';
|
568 |
+
}
|
569 |
+
|
570 |
+
/**
|
571 |
+
* Create PodsUI content for the administration pages
|
572 |
+
*/
|
573 |
+
public function admin_content () {
|
574 |
+
$pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET[ 'page' ] );
|
575 |
+
|
576 |
+
$pod = pods( $pod_name, pods_var( 'id', 'get', null, null, true ) );
|
577 |
+
|
578 |
+
if ( false !== strpos( $_GET[ 'page' ], 'pods-add-new-' ) )
|
579 |
+
$_GET[ 'action' ] = pods_var( 'action', 'get', 'add' );
|
580 |
+
|
581 |
+
$pod->ui();
|
582 |
+
}
|
583 |
+
|
584 |
+
/**
|
585 |
+
* Create PodsUI content for the settings administration pages
|
586 |
+
*/
|
587 |
+
public function admin_content_settings () {
|
588 |
+
$pod_name = str_replace( 'pods-settings-', '', $_GET[ 'page' ] );
|
589 |
+
|
590 |
+
$pod = pods( $pod_name );
|
591 |
+
|
592 |
+
if ( 'custom' != pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ) ) {
|
593 |
+
$actions_disabled = array(
|
594 |
+
'manage' => 'manage',
|
595 |
+
'add' => 'add',
|
596 |
+
'delete' => 'delete',
|
597 |
+
'duplicate' => 'duplicate',
|
598 |
+
'view' => 'view',
|
599 |
+
'export' => 'export'
|
600 |
+
);
|
601 |
+
|
602 |
+
$_GET[ 'action' ] = 'edit';
|
603 |
+
|
604 |
+
$page_title = pods_var_raw( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) ), null, true );
|
605 |
+
|
606 |
+
$ui = array(
|
607 |
+
'pod' => $pod,
|
608 |
+
'fields' => array(
|
609 |
+
'edit' => $pod->pod_data[ 'fields' ]
|
610 |
+
),
|
611 |
+
'header' => array(
|
612 |
+
'edit' => $page_title
|
613 |
+
),
|
614 |
+
'label' => array(
|
615 |
+
'edit' => __( 'Save Changes', 'pods' )
|
616 |
+
),
|
617 |
+
'style' => pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ),
|
618 |
+
'icon' => pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod->pod_data[ 'options' ] ), true ),
|
619 |
+
'actions_disabled' => $actions_disabled
|
620 |
+
);
|
621 |
+
|
622 |
+
$ui = apply_filters( 'pods_admin_ui_' . $pod->pod, apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod );
|
623 |
+
|
624 |
+
// Force disabled actions, do not pass go, do not collect $two_hundred
|
625 |
+
$ui[ 'actions_disabled' ] = $actions_disabled;
|
626 |
+
|
627 |
+
pods_ui( $ui );
|
628 |
+
}
|
629 |
+
else {
|
630 |
+
do_action( 'pods_admin_ui_custom', $pod );
|
631 |
+
do_action( 'pods_admin_ui_custom_' . $pod->pod, $pod );
|
632 |
+
}
|
633 |
+
}
|
634 |
+
|
635 |
+
/**
|
636 |
+
* Add media button for Pods shortcode
|
637 |
+
*
|
638 |
+
* @param $context
|
639 |
+
*
|
640 |
+
* @return string
|
641 |
+
*/
|
642 |
+
public function media_button ( $context = null ) {
|
643 |
+
|
644 |
+
/**
|
645 |
+
* Filter to remove Pods shortcode button from the post editor.
|
646 |
+
*
|
647 |
+
* @param bool. Set to false to block the shortcode button from appearing.
|
648 |
+
* @param string $context
|
649 |
+
*
|
650 |
+
* @since 2.3.19
|
651 |
+
*/
|
652 |
+
if ( !apply_filters( 'pods_admin_media_button', true, $context ) ) {
|
653 |
+
return '';
|
654 |
+
}
|
655 |
+
|
656 |
+
$current_page = basename( $_SERVER[ 'PHP_SELF' ] );
|
657 |
+
$current_page = explode( '?', $current_page );
|
658 |
+
$current_page = explode( '#', $current_page[ 0 ] );
|
659 |
+
$current_page = $current_page[ 0 ];
|
660 |
+
|
661 |
+
// Only show the button on post type pages
|
662 |
+
if ( !in_array( $current_page, array( 'post-new.php', 'post.php' ) ) )
|
663 |
+
return '';
|
664 |
+
|
665 |
+
add_action( 'admin_footer', array( $this, 'mce_popup' ) );
|
666 |
+
|
667 |
+
echo '<a href="#TB_inline?width=640&inlineId=pods_shortcode_form" class="thickbox" id="add_pod_button" title="Pods Shortcode"><img src="' . PODS_URL . 'ui/images/icon16.png" alt="Pods Shortcode" /></a>';
|
668 |
+
}
|
669 |
+
|
670 |
+
/**
|
671 |
+
* Enqueue assets for Media Library Popup
|
672 |
+
*/
|
673 |
+
public function register_media_assets () {
|
674 |
+
if ( 'pods_media_attachment' == pods_var( 'inlineId', 'get' ) )
|
675 |
+
wp_enqueue_style( 'pods-attach' );
|
676 |
+
}
|
677 |
+
|
678 |
+
/**
|
679 |
+
* Output Pods shortcode popup window
|
680 |
+
*/
|
681 |
+
public function mce_popup () {
|
682 |
+
pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) );
|
683 |
+
}
|
684 |
+
|
685 |
+
/**
|
686 |
+
* Handle main Pods Setup area for managing Pods and Fields
|
687 |
+
*/
|
688 |
+
public function admin_setup () {
|
689 |
+
$pods = pods_api()->load_pods( array( 'fields' => false ) );
|
690 |
+
|
691 |
+
$view = pods_var( 'view', 'get', 'all', null, true );
|
692 |
+
|
693 |
+
if ( empty( $pods ) && !isset( $_GET[ 'action' ] ) )
|
694 |
+
$_GET[ 'action' ] = 'add';
|
695 |
+
|
696 |
+
if ( 'pods-add-new' == $_GET[ 'page' ] ) {
|
697 |
+
if ( isset( $_GET[ 'action' ] ) && 'add' != $_GET[ 'action' ] )
|
698 |
+
pods_redirect( pods_var_update( array( 'page' => 'pods', 'action' => $_GET[ 'action' ] ) ) );
|
699 |
+
else
|
700 |
+
$_GET[ 'action' ] = 'add';
|
701 |
+
}
|
702 |
+
elseif ( isset( $_GET[ 'action' ] ) && 'add' == $_GET[ 'action' ] )
|
703 |
+
pods_redirect( pods_var_update( array( 'page' => 'pods-add-new', 'action' => '' ) ) );
|
704 |
+
|
705 |
+
$types = array(
|
706 |
+
'post_type' => __( 'Post Type (extended)', 'pods' ),
|
707 |
+
'taxonomy' => __( 'Taxonomy (extended)', 'pods' ),
|
708 |
+
'cpt' => __( 'Custom Post Type', 'pods' ),
|
709 |
+
'ct' => __( 'Custom Taxonomy', 'pods' ),
|
710 |
+
'user' => __( 'User (extended)', 'pods' ),
|
711 |
+
'media' => __( 'Media (extended)', 'pods' ),
|
712 |
+
'comment' => __( 'Comments (extended)', 'pods' ),
|
713 |
+
'pod' => __( 'Advanced Content Type', 'pods' ),
|
714 |
+
'settings' => __( 'Custom Settings Page', 'pods' )
|
715 |
+
);
|
716 |
+
|
717 |
+
$row = false;
|
718 |
+
|
719 |
+
$pod_types_found = array();
|
720 |
+
|
721 |
+
$fields = array(
|
722 |
+
'label' => array( 'label' => __( 'Label', 'pods' ) ),
|
723 |
+
'name' => array( 'label' => __( 'Name', 'pods' ) ),
|
724 |
+
'type' => array( 'label' => __( 'Type', 'pods' ) ),
|
725 |
+
'storage' => array(
|
726 |
+
'label' => __( 'Storage Type', 'pods' ),
|
727 |
+
'width' => '10%'
|
728 |
+
),
|
729 |
+
'field_count' => array(
|
730 |
+
'label' => __( 'Number of Fields', 'pods' ),
|
731 |
+
'width' => '8%'
|
732 |
+
)
|
733 |
+
);
|
734 |
+
|
735 |
+
$total_fields = 0;
|
736 |
+
|
737 |
+
foreach ( $pods as $k => $pod ) {
|
738 |
+
if ( isset( $types[ $pod[ 'type' ] ] ) ) {
|
739 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) ) {
|
740 |
+
if ( empty( $pod[ 'object' ] ) ) {
|
741 |
+
if ( 'post_type' == $pod[ 'type' ] )
|
742 |
+
$pod[ 'type' ] = 'cpt';
|
743 |
+
else
|
744 |
+
$pod[ 'type' ] = 'ct';
|
745 |
+
}
|
746 |
+
}
|
747 |
+
|
748 |
+
if ( !isset( $pod_types_found[ $pod[ 'type' ] ] ) )
|
749 |
+
$pod_types_found[ $pod[ 'type' ] ] = 1;
|
750 |
+
else
|
751 |
+
$pod_types_found[ $pod[ 'type' ] ]++;
|
752 |
+
|
753 |
+
if ( 'all' != $view && $view != $pod[ 'type' ] ) {
|
754 |
+
unset( $pods[ $k ] );
|
755 |
+
|
756 |
+
continue;
|
757 |
+
}
|
758 |
+
|
759 |
+
$pod[ 'real_type' ] = $pod[ 'type' ];
|
760 |
+
$pod[ 'type' ] = $types[ $pod[ 'type' ] ];
|
761 |
+
}
|
762 |
+
elseif ( 'all' != $view )
|
763 |
+
continue;
|
764 |
+
|
765 |
+
$pod[ 'storage' ] = ucwords( $pod[ 'storage' ] );
|
766 |
+
|
767 |
+
if ( $pod[ 'id' ] == pods_var( 'id' ) && 'delete' != pods_var( 'action' ) )
|
768 |
+
$row = $pod;
|
769 |
+
|
770 |
+
$pod = array(
|
771 |
+
'id' => $pod[ 'id' ],
|
772 |
+
'label' => pods_var_raw( 'label', $pod ),
|
773 |
+
'name' => pods_var_raw( 'name', $pod ),
|
774 |
+
'object' => pods_var_raw( 'object', $pod ),
|
775 |
+
'type' => pods_var_raw( 'type', $pod ),
|
776 |
+
'real_type' => pods_var_raw( 'real_type', $pod ),
|
777 |
+
'storage' => pods_var_raw( 'storage', $pod ),
|
778 |
+
'field_count' => count( $pod[ 'fields' ] )
|
779 |
+
);
|
780 |
+
|
781 |
+
$total_fields += $pod[ 'field_count' ];
|
782 |
+
|
783 |
+
$pods[ $k ] = $pod;
|
784 |
+
}
|
785 |
+
|
786 |
+
if ( false === $row && 0 < pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) {
|
787 |
+
pods_message( 'Pod not found', 'error' );
|
788 |
+
|
789 |
+
unset( $_GET[ 'id' ] );
|
790 |
+
unset( $_GET[ 'action' ] );
|
791 |
+
}
|
792 |
+
|
793 |
+
$ui = array(
|
794 |
+
'data' => $pods,
|
795 |
+
'row' => $row,
|
796 |
+
'total' => count( $pods ),
|
797 |
+
'total_found' => count( $pods ),
|
798 |
+
'icon' => PODS_URL . 'ui/images/icon32.png',
|
799 |
+
'items' => 'Pods',
|
800 |
+
'item' => 'Pod',
|
801 |
+
'fields' => array(
|
802 |
+
'manage' => $fields
|
803 |
+
),
|
804 |
+
'actions_disabled' => array( 'view', 'export' ),
|
805 |
+
'actions_custom' => array(
|
806 |
+
'add' => array( $this, 'admin_setup_add' ),
|
807 |
+
'edit' => array( $this, 'admin_setup_edit' ),
|
808 |
+
'duplicate' => array(
|
809 |
+
'callback' => array( $this, 'admin_setup_duplicate' ),
|
810 |
+
'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' )
|
811 |
+
),
|
812 |
+
'reset' => array(
|
813 |
+
'label' => __( 'Delete All Items', 'pods' ),
|
814 |
+
'confirm' => __( 'Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods' ),
|
815 |
+
'callback' => array( $this, 'admin_setup_reset' ),
|
816 |
+
'restrict_callback' => array( $this, 'admin_setup_reset_restrict' )
|
817 |
+
),
|
818 |
+
'delete' => array( $this, 'admin_setup_delete' )
|
819 |
+
),
|
820 |
+
'action_links' => array(
|
821 |
+
'add' => pods_var_update( array( 'page' => 'pods-add-new', 'action' => '', 'id' => '', 'do' => '' ) )
|
822 |
+
),
|
823 |
+
'search' => false,
|
824 |
+
'searchable' => false,
|
825 |
+
'sortable' => true,
|
826 |
+
'pagination' => false,
|
827 |
+
'extra' => array(
|
828 |
+
'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' )
|
829 |
+
)
|
830 |
+
);
|
831 |
+
|
832 |
+
if ( 1 < count( $pod_types_found ) ) {
|
833 |
+
$ui[ 'views' ] = array( 'all' => __( 'All', 'pods' ) );
|
834 |
+
$ui[ 'view' ] = $view;
|
835 |
+
$ui[ 'heading' ] = array( 'views' => __( 'Type', 'pods' ) );
|
836 |
+
$ui[ 'filters_enhanced' ] = true;
|
837 |
+
|
838 |
+
foreach ( $pod_types_found as $pod_type => $number_found ) {
|
839 |
+
$ui[ 'views' ][ $pod_type ] = $types[ $pod_type ];
|
840 |
+
}
|
841 |
+
}
|
842 |
+
|
843 |
+
pods_ui( $ui );
|
844 |
+
}
|
845 |
+
|
846 |
+
/**
|
847 |
+
* Get the add page of an object
|
848 |
+
*
|
849 |
+
* @param $obj
|
850 |
+
*/
|
851 |
+
public function admin_setup_add ( $obj ) {
|
852 |
+
pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) );
|
853 |
+
}
|
854 |
+
|
855 |
+
/**
|
856 |
+
* Get the edit page of an object
|
857 |
+
*
|
858 |
+
* @param $duplicate
|
859 |
+
* @param $obj
|
860 |
+
*/
|
861 |
+
public function admin_setup_edit ( $duplicate, $obj ) {
|
862 |
+
pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) );
|
863 |
+
}
|
864 |
+
|
865 |
+
/**
|
866 |
+
* Get list of Pod option tabs
|
867 |
+
*
|
868 |
+
* @return array
|
869 |
+
*/
|
870 |
+
public function admin_setup_edit_tabs ( $pod ) {
|
871 |
+
$fields = true;
|
872 |
+
$labels = false;
|
873 |
+
$admin_ui = false;
|
874 |
+
$advanced = false;
|
875 |
+
|
876 |
+
if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) {
|
877 |
+
$labels = true;
|
878 |
+
$admin_ui = true;
|
879 |
+
$advanced = true;
|
880 |
+
}
|
881 |
+
elseif ( 'taxonomy' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) {
|
882 |
+
$labels = true;
|
883 |
+
$admin_ui = true;
|
884 |
+
$advanced = true;
|
885 |
+
}
|
886 |
+
elseif ( 'pod' == pods_var( 'type', $pod ) ) {
|
887 |
+
$labels = true;
|
888 |
+
$admin_ui = true;
|
889 |
+
$advanced = true;
|
890 |
+
}
|
891 |
+
elseif ( 'settings' == pods_var( 'type', $pod ) ) {
|
892 |
+
$labels = true;
|
893 |
+
$admin_ui = true;
|
894 |
+
}
|
895 |
+
|
896 |
+
if ( 'none' == pods_var( 'storage', $pod, 'none', null, true ) && 'settings' != pods_var( 'type', $pod ) )
|
897 |
+
$fields = false;
|
898 |
+
|
899 |
+
$tabs = array();
|
900 |
+
|
901 |
+
if ( $fields )
|
902 |
+
$tabs[ 'manage-fields' ] = __( 'Manage Fields', 'pods' );
|
903 |
+
|
904 |
+
if ( $labels )
|
905 |
+
$tabs[ 'labels' ] = __( 'Labels', 'pods' );
|
906 |
+
|
907 |
+
if ( $admin_ui )
|
908 |
+
$tabs[ 'admin-ui' ] = __( 'Admin UI', 'pods' );
|
909 |
+
|
910 |
+
if ( $advanced )
|
911 |
+
$tabs[ 'advanced' ] = __( 'Advanced Options', 'pods' );
|
912 |
+
|
913 |
+
if ( 'taxonomy' == pods_var( 'type', $pod ) && !$fields )
|
914 |
+
$tabs[ 'extra-fields' ] = __( 'Extra Fields', 'pods' );
|
915 |
+
|
916 |
+
$addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) );
|
917 |
+
|
918 |
+
/**
|
919 |
+
* Add or modify tabs in Pods editor for a specific Pod
|
920 |
+
*
|
921 |
+
* @params array $tabs Tabs to set.
|
922 |
+
* @params object $pod Current Pods object
|
923 |
+
* @params array $addtl_args Additional args.
|
924 |
+
*
|
925 |
+
* @since unknown
|
926 |
+
*/
|
927 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $tabs, $pod, $addtl_args );
|
928 |
+
|
929 |
+
/**
|
930 |
+
* Add or modify tabs for any Pod in Pods editor of a specific post type.
|
931 |
+
*/
|
932 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ], $tabs, $pod, $addtl_args );
|
933 |
+
|
934 |
+
/**
|
935 |
+
* Add or modify tabs in Pods editor for all pods.
|
936 |
+
*/
|
937 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args );
|
938 |
+
|
939 |
+
return $tabs;
|
940 |
+
}
|
941 |
+
|
942 |
+
/**
|
943 |
+
* Get list of Pod options
|
944 |
+
*
|
945 |
+
* @return array
|
946 |
+
*/
|
947 |
+
public function admin_setup_edit_options ( $pod ) {
|
948 |
+
$options = array();
|
949 |
+
|
950 |
+
// @todo fill this in
|
951 |
+
$options[ 'labels' ] = array(
|
952 |
+
'temporary' => 'This has the fields hardcoded' // :(
|
953 |
+
);
|
954 |
+
|
955 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
956 |
+
$options[ 'admin-ui' ] = array(
|
957 |
+
'description' => array(
|
958 |
+
'label' => __( 'Post Type Description', 'pods' ),
|
959 |
+
'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ),
|
960 |
+
'type' => 'text',
|
961 |
+
'default' => ''
|
962 |
+
),
|
963 |
+
'show_ui' => array(
|
964 |
+
'label' => __( 'Show Admin UI', 'pods' ),
|
965 |
+
'help' => __( 'help', 'pods' ),
|
966 |
+
'type' => 'boolean',
|
967 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
968 |
+
'boolean_yes_label' => ''
|
969 |
+
),
|
970 |
+
'show_in_menu' => array(
|
971 |
+
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
|
972 |
+
'help' => __( 'help', 'pods' ),
|
973 |
+
'type' => 'boolean',
|
974 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
975 |
+
'dependency' => true,
|
976 |
+
'boolean_yes_label' => ''
|
977 |
+
),
|
978 |
+
'menu_location_custom' => array(
|
979 |
+
'label' => __( 'Parent Menu ID (optional)', 'pods' ),
|
980 |
+
'help' => __( 'help', 'pods' ),
|
981 |
+
'type' => 'text',
|
982 |
+
'depends-on' => array( 'show_in_menu' => true )
|
983 |
+
),
|
984 |
+
'menu_name' => array(
|
985 |
+
'label' => __( 'Menu Name', 'pods' ),
|
986 |
+
'help' => __( 'help', 'pods' ),
|
987 |
+
'type' => 'text',
|
988 |
+
'default' => '',
|
989 |
+
'depends-on' => array( 'show_in_menu' => true )
|
990 |
+
),
|
991 |
+
'menu_position' => array(
|
992 |
+
'label' => __( 'Menu Position', 'pods' ),
|
993 |
+
'help' => __( 'help', 'pods' ),
|
994 |
+
'type' => 'number',
|
995 |
+
'default' => 0,
|
996 |
+
'depends-on' => array( 'show_in_menu' => true )
|
997 |
+
),
|
998 |
+
'menu_icon' => array(
|
999 |
+
'label' => __( 'Menu Icon', 'pods' ),
|
1000 |
+
'help' => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="http://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank">site tag</a> type <a href="http://pods.io/docs/build/special-magic-tags/" target="_blank">special magic tags</a>. For example, for a file in your theme directory, use "{@template-url}/path/to/image.png". You may also use the name of a <a href="http://melchoyce.github.io/dashicons/" target="_blank">Dashicon</a>. For example, to use the empty star icon, use "dashicons-star-empty".', 'pods' ),
|
1001 |
+
'type' => 'text',
|
1002 |
+
'default' => '',
|
1003 |
+
'depends-on' => array( 'show_in_menu' => true )
|
1004 |
+
),
|
1005 |
+
'show_in_nav_menus' => array(
|
1006 |
+
'label' => __( 'Show in Navigation Menus', 'pods' ),
|
1007 |
+
'help' => __( 'help', 'pods' ),
|
1008 |
+
'type' => 'boolean',
|
1009 |
+
'default' => true,
|
1010 |
+
'boolean_yes_label' => ''
|
1011 |
+
),
|
1012 |
+
'show_in_admin_bar' => array(
|
1013 |
+
'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ),
|
1014 |
+
'help' => __( 'help', 'pods' ),
|
1015 |
+
'type' => 'boolean',
|
1016 |
+
'default' => true,
|
1017 |
+
'boolean_yes_label' => ''
|
1018 |
+
)
|
1019 |
+
);
|
1020 |
+
|
1021 |
+
$options[ 'advanced' ] = array(
|
1022 |
+
'public' => array(
|
1023 |
+
'label' => __( 'Public', 'pods' ),
|
1024 |
+
'help' => __( 'help', 'pods' ),
|
1025 |
+
'type' => 'boolean',
|
1026 |
+
'default' => true,
|
1027 |
+
'boolean_yes_label' => ''
|
1028 |
+
),
|
1029 |
+
'publicly_queryable' => array(
|
1030 |
+
'label' => __( 'Publicly Queryable', 'pods' ),
|
1031 |
+
'help' => __( 'help', 'pods' ),
|
1032 |
+
'type' => 'boolean',
|
1033 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
1034 |
+
'boolean_yes_label' => ''
|
1035 |
+
),
|
1036 |
+
'exclude_from_search' => array(
|
1037 |
+
'label' => __( 'Exclude from Search', 'pods' ),
|
1038 |
+
'help' => __( 'help', 'pods' ),
|
1039 |
+
'type' => 'boolean',
|
1040 |
+
'default' => !pods_var_raw( 'public', $pod, true ),
|
1041 |
+
'boolean_yes_label' => ''
|
1042 |
+
),
|
1043 |
+
'capability_type' => array(
|
1044 |
+
'label' => __( 'User Capability', 'pods' ),
|
1045 |
+
'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ),
|
1046 |
+
'type' => 'pick',
|
1047 |
+
'default' => 'post',
|
1048 |
+
'data' => array(
|
1049 |
+
'post' => 'post',
|
1050 |
+
'page' => 'page',
|
1051 |
+
'custom' => __( 'Custom Capability', 'pods' )
|
1052 |
+
),
|
1053 |
+
'dependency' => true
|
1054 |
+
),
|
1055 |
+
'capability_type_custom' => array(
|
1056 |
+
'label' => __( 'Custom User Capability', 'pods' ),
|
1057 |
+
'help' => __( 'help', 'pods' ),
|
1058 |
+
'type' => 'text',
|
1059 |
+
'default' => pods_var_raw( 'name', $pod ),
|
1060 |
+
'depends-on' => array( 'capability_type' => 'custom' )
|
1061 |
+
),
|
1062 |
+
'capability_type_extra' => array(
|
1063 |
+
'label' => __( 'Additional User Capabilities', 'pods' ),
|
1064 |
+
'help' => __( 'Enables additional capabilities for this Post Type including: delete_{capability}s, delete_private_{capability}s, delete_published_{capability}s, delete_others_{capability}s, edit_private_{capability}s, and edit_published_{capability}s', 'pods' ),
|
1065 |
+
'type' => 'boolean',
|
1066 |
+
'default' => true,
|
1067 |
+
'boolean_yes_label' => ''
|
1068 |
+
),
|
1069 |
+
'has_archive' => array(
|
1070 |
+
'label' => __( 'Enable Archive Page', 'pods' ),
|
1071 |
+
'help' => __( 'If enabled, creates an archive page with list of of items in this custom post type. Functions like a category page for posts. Can be controlled with a template in your theme called "archive-{$post-type}.php".', 'pods' ),
|
1072 |
+
'type' => 'boolean',
|
1073 |
+
'default' => false,
|
1074 |
+
'dependency' => true,
|
1075 |
+
'boolean_yes_label' => ''
|
1076 |
+
),
|
1077 |
+
'has_archive_slug' => array(
|
1078 |
+
'label' => __( 'Archive Page Slug Override', 'pods' ),
|
1079 |
+
'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ),
|
1080 |
+
'type' => 'text',
|
1081 |
+
'default' => '',
|
1082 |
+
'depends-on' => array( 'has_archive' => true )
|
1083 |
+
),
|
1084 |
+
'hierarchical' => array(
|
1085 |
+
'label' => __( 'Hierarchical', 'pods' ),
|
1086 |
+
'help' => __( 'Allows for parent/ child relationships between items, just like with Pages. Note: To edit relationships in the post editor, you must enable "Page Attributes" in the "Supports" section below.', 'pods' ),
|
1087 |
+
'type' => 'boolean',
|
1088 |
+
'default' => false,
|
1089 |
+
'dependency' => true,
|
1090 |
+
'boolean_yes_label' => ''
|
1091 |
+
),
|
1092 |
+
'label_parent_item_colon' => array(
|
1093 |
+
'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
1094 |
+
'help' => __( 'help', 'pods' ),
|
1095 |
+
'type' => 'text',
|
1096 |
+
'default' => '',
|
1097 |
+
'depends-on' => array( 'hierarchical' => true )
|
1098 |
+
),
|
1099 |
+
'label_parent' => array(
|
1100 |
+
'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
|
1101 |
+
'help' => __( 'help', 'pods' ),
|
1102 |
+
'type' => 'text',
|
1103 |
+
'default' => '',
|
1104 |
+
'depends-on' => array( 'hierarchical' => true )
|
1105 |
+
),
|
1106 |
+
'rewrite' => array(
|
1107 |
+
'label' => __( 'Rewrite', 'pods' ),
|
1108 |
+
'help' => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Reading. If not enbabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ),
|
1109 |
+
'type' => 'boolean',
|
1110 |
+
'default' => true,
|
1111 |
+
'dependency' => true,
|
1112 |
+
'boolean_yes_label' => ''
|
1113 |
+
),
|
1114 |
+
'rewrite_custom_slug' => array(
|
1115 |
+
'label' => __( 'Custom Rewrite Slug', 'pods' ),
|
1116 |
+
'help' => __( 'Changes the first segment of the URL, which by default is the name of the Pod. For example, if your Pod is called "foo", if this field is left blank, your link will be "example.com/foo/post_slug", but if you were to enter "bar" your link will be "example.com/bar/post_slug".', 'pods' ),
|
1117 |
+
'type' => 'text',
|
1118 |
+
'default' => '',
|
1119 |
+
'depends-on' => array( 'rewrite' => true )
|
1120 |
+
),
|
1121 |
+
'rewrite_with_front' => array(
|
1122 |
+
'label' => __( 'Rewrite with Front', 'pods' ),
|
1123 |
+
'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ),
|
1124 |
+
'type' => 'boolean',
|
1125 |
+
'default' => true,
|
1126 |
+
'depends-on' => array( 'rewrite' => true ),
|
1127 |
+
'boolean_yes_label' => ''
|
1128 |
+
),
|
1129 |
+
'rewrite_feeds' => array(
|
1130 |
+
'label' => __( 'Rewrite Feeds', 'pods' ),
|
1131 |
+
'help' => __( 'help', 'pods' ),
|
1132 |
+
'type' => 'boolean',
|
1133 |
+
'default' => false,
|
1134 |
+
'depends-on' => array( 'rewrite' => true ),
|
1135 |
+
'boolean_yes_label' => ''
|
1136 |
+
),
|
1137 |
+
'rewrite_pages' => array(
|
1138 |
+
'label' => __( 'Rewrite Pages', 'pods' ),
|
1139 |
+
'help' => __( 'help', 'pods' ),
|
1140 |
+
'type' => 'boolean',
|
1141 |
+
'default' => true,
|
1142 |
+
'depends-on' => array( 'rewrite' => true ),
|
1143 |
+
'boolean_yes_label' => ''
|
1144 |
+
),
|
1145 |
+
'query_var' => array(
|
1146 |
+
'label' => __( 'Query Var', 'pods' ),
|
1147 |
+
'help' => __( 'The Query Var is used in the URL and underneath the WordPress Rewrite API to tell WordPress what page or post type you are on. For a list of reserved Query Vars, read <a href="http://codex.wordpress.org/WordPress_Query_Vars">WordPress Query Vars</a> from the WordPress Codex.', 'pods' ),
|
1148 |
+
'type' => 'boolean',
|
1149 |
+
'default' => true,
|
1150 |
+
'boolean_yes_label' => ''
|
1151 |
+
),
|
1152 |
+
'can_export' => array(
|
1153 |
+
'label' => __( 'Exportable', 'pods' ),
|
1154 |
+
'help' => __( 'help', 'pods' ),
|
1155 |
+
'type' => 'boolean',
|
1156 |
+
'default' => true,
|
1157 |
+
'boolean_yes_label' => ''
|
1158 |
+
),
|
1159 |
+
'default_status' => array(
|
1160 |
+
'label' => __( 'Default Status', 'pods' ),
|
1161 |
+
'help' => __( 'help', 'pods' ),
|
1162 |
+
'type' => 'pick',
|
1163 |
+
'pick_object' => 'post-status',
|
1164 |
+
'default' => apply_filters( 'pods_api_default_status_' . pods_var_raw( 'name', $pod, 'post_type', null, true ), 'draft', $pod )
|
1165 |
+
)
|
1166 |
+
);
|
1167 |
+
}
|
1168 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
1169 |
+
$options[ 'admin-ui' ] = array(
|
1170 |
+
'show_ui' => array(
|
1171 |
+
'label' => __( 'Show Admin UI', 'pods' ),
|
1172 |
+
'help' => __( 'help', 'pods' ),
|
1173 |
+
'type' => 'boolean',
|
1174 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
1175 |
+
'dependency' => true,
|
1176 |
+
'boolean_yes_label' => ''
|
1177 |
+
),
|
1178 |
+
'menu_name' => array(
|
1179 |
+
'label' => __( 'Menu Name', 'pods' ),
|
1180 |
+
'help' => __( 'help', 'pods' ),
|
1181 |
+
'type' => 'text',
|
1182 |
+
'default' => '',
|
1183 |
+
'depends-on' => array( 'show_ui' => true )
|
1184 |
+
),
|
1185 |
+
'menu_location' => array(
|
1186 |
+
'label' => __( 'Menu Location', 'pods' ),
|
1187 |
+
'help' => __( 'help', 'pods' ),
|
1188 |
+
'type' => 'pick',
|
1189 |
+
'default' => 'default',
|
1190 |
+
'depends-on' => array( 'show_ui' => true ),
|
1191 |
+
'data' => array(
|
1192 |
+
'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),
|
1193 |
+
'settings' => __( 'Add to Settings menu', 'pods' ),
|
1194 |
+
'appearances' => __( 'Add to Appearances menu', 'pods' ),
|
1195 |
+
'objects' => __( 'Make a top-level menu item', 'pods' ),
|
1196 |
+
'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),
|
1197 |
+
'submenu' => __( 'Add a submenu item to another menu', 'pods' )
|
1198 |
+
),
|
1199 |
+
'dependency' => true
|
1200 |
+
),
|
1201 |
+
'menu_location_custom' => array(
|
1202 |
+
'label' => __( 'Custom Menu Location', 'pods' ),
|
1203 |
+
'help' => __( 'help', 'pods' ),
|
1204 |
+
'type' => 'text',
|
1205 |
+
'depends-on' => array( 'menu_location' => 'submenu' )
|
1206 |
+
),
|
1207 |
+
'menu_position' => array(
|
1208 |
+
'label' => __( 'Menu Position', 'pods' ),
|
1209 |
+
'help' => __( 'help', 'pods' ),
|
1210 |
+
'type' => 'number',
|
1211 |
+
'default' => 0,
|
1212 |
+
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) )
|
1213 |
+
),
|
1214 |
+
'menu_icon' => array(
|
1215 |
+
'label' => __( 'Menu Icon URL', 'pods' ),
|
1216 |
+
'help' => __( 'help', 'pods' ),
|
1217 |
+
'type' => 'text',
|
1218 |
+
'default' => '',
|
1219 |
+
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) )
|
1220 |
+
),
|
1221 |
+
'show_in_nav_menus' => array(
|
1222 |
+
'label' => __( 'Show in Navigation Menus', 'pods' ),
|
1223 |
+
'help' => __( 'help', 'pods' ),
|
1224 |
+
'type' => 'boolean',
|
1225 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
1226 |
+
'boolean_yes_label' => ''
|
1227 |
+
),
|
1228 |
+
'show_tagcloud' => array(
|
1229 |
+
'label' => __( 'Allow in Tagcloud Widget', 'pods' ),
|
1230 |
+
'help' => __( 'help', 'pods' ),
|
1231 |
+
'type' => 'boolean',
|
1232 |
+
'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ),
|
1233 |
+
'boolean_yes_label' => ''
|
1234 |
+
)
|
1235 |
+
);
|
1236 |
+
|
1237 |
+
if ( pods_version_check( 'wp', '3.5' ) ) {
|
1238 |
+
$options[ 'admin-ui' ][ 'show_admin_column' ] = array(
|
1239 |
+
'label' => __( 'Show Taxonomy column on Post Types', 'pods' ),
|
1240 |
+
'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),
|
1241 |
+
'type' => 'boolean',
|
1242 |
+
'default' => false,
|
1243 |
+
'boolean_yes_label' => ''
|
1244 |
+
);
|
1245 |
+
}
|
1246 |
+
|
1247 |
+
// Integration for Single Value Taxonomy UI
|
1248 |
+
if ( function_exists( 'tax_single_value_meta_box' ) ) {
|
1249 |
+
$options[ 'admin-ui' ][ 'single_value' ] = array(
|
1250 |
+
'label' => __( 'Single Value Taxonomy', 'pods' ),
|
1251 |
+
'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ),
|
1252 |
+
'type' => 'boolean',
|
1253 |
+
'default' => false,
|
1254 |
+
'boolean_yes_label' => ''
|
1255 |
+
);
|
1256 |
+
|
1257 |
+
$options[ 'admin-ui' ][ 'single_value_required' ] = array(
|
1258 |
+
'label' => __( 'Single Value Taxonomy - Required', 'pods' ),
|
1259 |
+
'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ),
|
1260 |
+
'type' => 'boolean',
|
1261 |
+
'default' => false,
|
1262 |
+
'boolean_yes_label' => ''
|
1263 |
+
);
|
1264 |
+
}
|
1265 |
+
|
1266 |
+
// @todo fill this in
|
1267 |
+
$options[ 'advanced' ] = array(
|
1268 |
+
'temporary' => 'This type has the fields hardcoded' // :(
|
1269 |
+
);
|
1270 |
+
}
|
1271 |
+
elseif ( 'settings' == $pod[ 'type' ] ) {
|
1272 |
+
$options[ 'admin-ui' ] = array(
|
1273 |
+
'ui_style' => array(
|
1274 |
+
'label' => __( 'Admin UI Style', 'pods' ),
|
1275 |
+
'help' => __( 'help', 'pods' ),
|
1276 |
+
'type' => 'pick',
|
1277 |
+
'default' => 'settings',
|
1278 |
+
'data' => array(
|
1279 |
+
'settings' => __( 'Normal Settings Form', 'pods' ),
|
1280 |
+
'post_type' => __( 'Post Type UI', 'pods' ),
|
1281 |
+
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' )
|
1282 |
+
),
|
1283 |
+
'dependency' => true
|
1284 |
+
),
|
1285 |
+
'menu_location' => array(
|
1286 |
+
'label' => __( 'Menu Location', 'pods' ),
|
1287 |
+
'help' => __( 'help', 'pods' ),
|
1288 |
+
'type' => 'pick',
|
1289 |
+
'default' => 'settings',
|
1290 |
+
'data' => array(
|
1291 |
+
'settings' => __( 'Add to Settings menu', 'pods' ),
|
1292 |
+
'appearances' => __( 'Add to Appearances menu', 'pods' ),
|
1293 |
+
'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),
|
1294 |
+
'submenu' => __( 'Add a submenu item to another menu', 'pods' )
|
1295 |
+
),
|
1296 |
+
'dependency' => true
|
1297 |
+
),
|
1298 |
+
'menu_location_custom' => array(
|
1299 |
+
'label' => __( 'Custom Menu Location', 'pods' ),
|
1300 |
+
'help' => __( 'help', 'pods' ),
|
1301 |
+
'type' => 'text',
|
1302 |
+
'depends-on' => array( 'menu_location' => 'submenu' )
|
1303 |
+
),
|
1304 |
+
'menu_position' => array(
|
1305 |
+
'label' => __( 'Menu Position', 'pods' ),
|
1306 |
+
'help' => __( 'help', 'pods' ),
|
1307 |
+
'type' => 'number',
|
1308 |
+
'default' => 0,
|
1309 |
+
'depends-on' => array( 'menu_location' => 'top' )
|
1310 |
+
),
|
1311 |
+
'menu_icon' => array(
|
1312 |
+
'label' => __( 'Menu Icon URL', 'pods' ),
|
1313 |
+
'help' => __( 'help', 'pods' ),
|
1314 |
+
'type' => 'text',
|
1315 |
+
'default' => '',
|
1316 |
+
'depends-on' => array( 'menu_location' => 'top' )
|
1317 |
+
)
|
1318 |
+
);
|
1319 |
+
|
1320 |
+
// @todo fill this in
|
1321 |
+
$options[ 'advanced' ] = array(
|
1322 |
+
'temporary' => 'This type has the fields hardcoded' // :(
|
1323 |
+
);
|
1324 |
+
}
|
1325 |
+
elseif ( 'pod' == $pod[ 'type' ] ) {
|
1326 |
+
$options[ 'admin-ui' ] = array(
|
1327 |
+
'ui_style' => array(
|
1328 |
+
'label' => __( 'Admin UI Style', 'pods' ),
|
1329 |
+
'help' => __( 'help', 'pods' ),
|
1330 |
+
'type' => 'pick',
|
1331 |
+
'default' => 'settings',
|
1332 |
+
'data' => array(
|
1333 |
+
'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ),
|
1334 |
+
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' )
|
1335 |
+
),
|
1336 |
+
'dependency' => true
|
1337 |
+
),
|
1338 |
+
'show_in_menu' => array(
|
1339 |
+
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
|
1340 |
+
'help' => __( 'help', 'pods' ),
|
1341 |
+
'type' => 'boolean',
|
1342 |
+
'default' => false,
|
1343 |
+
'boolean_yes_label' => '',
|
1344 |
+
'dependency' => true
|
1345 |
+
),
|
1346 |
+
'menu_location_custom' => array(
|
1347 |
+
'label' => __( 'Parent Menu ID (optional)', 'pods' ),
|
1348 |
+
'help' => __( 'help', 'pods' ),
|
1349 |
+
'type' => 'text',
|
1350 |
+
'depends-on' => array( 'show_in_menu' => true )
|
1351 |
+
),
|
1352 |
+
'menu_position' => array(
|
1353 |
+
'label' => __( 'Menu Position', 'pods' ),
|
1354 |
+
'help' => __( 'help', 'pods' ),
|
1355 |
+
'type' => 'number',
|
1356 |
+
'default' => 0,
|
1357 |
+
'depends-on' => array( 'show_in_menu' => true )
|
1358 |
+
),
|
1359 |
+
'menu_icon' => array(
|
1360 |
+
'label' => __( 'Menu Icon URL', 'pods' ),
|
1361 |
+
'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ),
|
1362 |
+
'type' => 'text',
|
1363 |
+
'default' => '',
|
1364 |
+
'depends-on' => array( 'show_in_menu' => true )
|
1365 |
+
),
|
1366 |
+
'ui_icon' => array(
|
1367 |
+
'label' => __( 'Header Icon', 'pods' ),
|
1368 |
+
'help' => __( 'This is the icon shown to the left of the heading text at the top of the manage pages for this content type.', 'pods' ),
|
1369 |
+
'type' => 'file',
|
1370 |
+
'default' => '',
|
1371 |
+
'file_edit_title' => 0,
|
1372 |
+
'depends-on' => array( 'show_in_menu' => true )
|
1373 |
+
),
|
1374 |
+
'ui_actions_enabled' => array(
|
1375 |
+
'label' => __( 'Actions Available', 'pods' ),
|
1376 |
+
'help' => __( 'help', 'pods' ),
|
1377 |
+
'type' => 'pick',
|
1378 |
+
'default' => ( 1 == pods_var( 'ui_export', $pod ) ? array( 'add', 'edit', 'duplicate', 'delete', 'export' ) : array( 'add', 'edit', 'duplicate', 'delete' ) ),
|
1379 |
+
'data' => array(
|
1380 |
+
'add' => __( 'Add New', 'pods' ),
|
1381 |
+
'edit' => __( 'Edit', 'pods' ),
|
1382 |
+
'duplicate' => __( 'Duplicate', 'pods' ),
|
1383 |
+
'delete' => __( 'Delete', 'pods' ),
|
1384 |
+
'reorder' => __( 'Reorder', 'pods' ),
|
1385 |
+
'export' => __( 'Export', 'pods' )
|
1386 |
+
),
|
1387 |
+
'pick_format_type' => 'multi',
|
1388 |
+
'dependency' => true
|
1389 |
+
),
|
1390 |
+
'ui_reorder_field' => array(
|
1391 |
+
'label' => __( 'Reorder Field', 'pods' ),
|
1392 |
+
'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ),
|
1393 |
+
'type' => 'text',
|
1394 |
+
'default' => 'menu_order',
|
1395 |
+
'depends-on' => array( 'ui_actions_enabled' => 'reorder' )
|
1396 |
+
),
|
1397 |
+
'ui_fields_manage' => array(
|
1398 |
+
'label' => __( 'Admin Table Columns', 'pods' ),
|
1399 |
+
'help' => __( 'help', 'pods' ),
|
1400 |
+
'type' => 'pick',
|
1401 |
+
'default' => array(),
|
1402 |
+
'data' => array(),
|
1403 |
+
'pick_format_type' => 'multi'
|
1404 |
+
),
|
1405 |
+
'ui_filters' => array(
|
1406 |
+
'label' => __( 'Search Filters', 'pods' ),
|
1407 |
+
'help' => __( 'help', 'pods' ),
|
1408 |
+
'type' => 'pick',
|
1409 |
+
'default' => array(),
|
1410 |
+
'data' => array(),
|
1411 |
+
'pick_format_type' => 'multi'
|
1412 |
+
)
|
1413 |
+
);
|
1414 |
+
|
1415 |
+
if ( !empty( $pod[ 'fields' ] ) ) {
|
1416 |
+
if ( isset( $pod[ 'fields' ][ pods_var_raw( 'pod_index', $pod, 'name' ) ] ) )
|
1417 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = pods_var_raw( 'pod_index', $pod, 'name' );
|
1418 |
+
|
1419 |
+
if ( isset( $pod[ 'fields' ][ 'modified' ] ) )
|
1420 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = 'modified';
|
1421 |
+
|
1422 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
1423 |
+
$type = '';
|
1424 |
+
|
1425 |
+
if ( isset( $field_types[ $field[ 'type' ] ] ) )
|
1426 |
+
$type = ' <small>(' . $field_types[ $field[ 'type' ] ][ 'label' ] . ')</small>';
|
1427 |
+
|
1428 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type;
|
1429 |
+
$options[ 'admin-ui' ][ 'ui_filters' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type;
|
1430 |
+
}
|
1431 |
+
|
1432 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ 'id' ] = 'ID';
|
1433 |
+
}
|
1434 |
+
else {
|
1435 |
+
unset( $options[ 'admin-ui' ][ 'ui_fields_manage' ] );
|
1436 |
+
unset( $options[ 'admin-ui' ][ 'ui_filters' ] );
|
1437 |
+
}
|
1438 |
+
|
1439 |
+
// @todo fill this in
|
1440 |
+
$options[ 'advanced' ] = array(
|
1441 |
+
'temporary' => 'This type has the fields hardcoded' // :(
|
1442 |
+
);
|
1443 |
+
}
|
1444 |
+
|
1445 |
+
/**
|
1446 |
+
* Add admin fields to the Pods editor for a specific Pod
|
1447 |
+
*
|
1448 |
+
* @params array $options The Options fields
|
1449 |
+
* @params object $pod Current Pods object
|
1450 |
+
*
|
1451 |
+
* @since unkown
|
1452 |
+
*/
|
1453 |
+
$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $options, $pod );
|
1454 |
+
|
1455 |
+
/**
|
1456 |
+
* Add admin fields to the Pods editor for any Pod of a specific content type.
|
1457 |
+
*/
|
1458 |
+
$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ], $options, $pod );
|
1459 |
+
|
1460 |
+
/**
|
1461 |
+
* Add admin fields to the Pods editor for all Pods
|
1462 |
+
*/
|
1463 |
+
$options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod );
|
1464 |
+
|
1465 |
+
return $options;
|
1466 |
+
}
|
1467 |
+
|
1468 |
+
/**
|
1469 |
+
* Get list of Pod field option tabs
|
1470 |
+
*
|
1471 |
+
* @return array
|
1472 |
+
*/
|
1473 |
+
public function admin_setup_edit_field_tabs ( $pod ) {
|
1474 |
+
$core_tabs = array(
|
1475 |
+
'basic' => __( 'Basic', 'pods' ),
|
1476 |
+
'additional-field' => __( 'Additional Field Options', 'pods' ),
|
1477 |
+
'advanced' => __( 'Advanced', 'pods' )
|
1478 |
+
);
|
1479 |
+
|
1480 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod );
|
1481 |
+
|
1482 |
+
$tabs = array_merge( $core_tabs, $tabs );
|
1483 |
+
|
1484 |
+
return $tabs;
|
1485 |
+
}
|
1486 |
+
|
1487 |
+
/**
|
1488 |
+
* Get list of Pod field options
|
1489 |
+
*
|
1490 |
+
* @return array
|
1491 |
+
*/
|
1492 |
+
public function admin_setup_edit_field_options ( $pod ) {
|
1493 |
+
$options = array();
|
1494 |
+
|
1495 |
+
$options[ 'additional-field' ] = array();
|
1496 |
+
|
1497 |
+
$field_types = PodsForm::field_types();
|
1498 |
+
|
1499 |
+
foreach ( $field_types as $type => $field_type_data ) {
|
1500 |
+
/**
|
1501 |
+
* @var $field_type PodsField
|
1502 |
+
*/
|
1503 |
+
$field_type = PodsForm::field_loader( $type, $field_type_data[ 'file' ] );
|
1504 |
+
|
1505 |
+
$field_type_vars = get_class_vars( get_class( $field_type ) );
|
1506 |
+
|
1507 |
+
if ( !isset( $field_type_vars[ 'pod_types' ] ) )
|
1508 |
+
$field_type_vars[ 'pod_types' ] = true;
|
1509 |
+
|
1510 |
+
$options[ 'additional-field' ][ $type ] = array();
|
1511 |
+
|
1512 |
+
// Only show supported field types
|
1513 |
+
if ( true !== $field_type_vars[ 'pod_types' ] ) {
|
1514 |
+
if ( empty( $field_type_vars[ 'pod_types' ] ) )
|
1515 |
+
continue;
|
1516 |
+
elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( pods_var( 'type', $pod ), $field_type_vars[ 'pod_types' ] ) )
|
1517 |
+
continue;
|
1518 |
+
elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && pods_var( 'type', $pod ) != $field_type_vars[ 'pod_types' ] )
|
1519 |
+
continue;
|
1520 |
+
}
|
1521 |
+
|
1522 |
+
$options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type );
|
1523 |
+
}
|
1524 |
+
|
1525 |
+
$input_helpers = array(
|
1526 |
+
'' => '-- Select --'
|
1527 |
+
);
|
1528 |
+
|
1529 |
+
if ( class_exists( 'Pods_Helpers' ) ) {
|
1530 |
+
$helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) );
|
1531 |
+
|
1532 |
+
foreach ( $helpers as $helper ) {
|
1533 |
+
$input_helpers[ $helper[ 'name' ] ] = $helper[ 'name' ];
|
1534 |
+
}
|
1535 |
+
}
|
1536 |
+
|
1537 |
+
$options[ 'advanced' ] = array(
|
1538 |
+
__( 'Visual', 'pods' ) => array(
|
1539 |
+
'class' => array(
|
1540 |
+
'name' => 'class',
|
1541 |
+
'label' => __( 'Additional CSS Classes', 'pods' ),
|
1542 |
+
'help' => __( 'help', 'pods' ),
|
1543 |
+
'type' => 'text',
|
1544 |
+
'default' => ''
|
1545 |
+
),
|
1546 |
+
'input_helper' => array(
|
1547 |
+
'name' => 'input_helper',
|
1548 |
+
'label' => __( 'Input Helper', 'pods' ),
|
1549 |
+
'help' => __( 'help', 'pods' ),
|
1550 |
+
'type' => 'pick',
|
1551 |
+
'default' => '',
|
1552 |
+
'data' => $input_helpers
|
1553 |
+
)
|
1554 |
+
),
|
1555 |
+
__( 'Values', 'pods' ) => array(
|
1556 |
+
'default_value' => array(
|
1557 |
+
'name' => 'default_value',
|
1558 |
+
'label' => __( 'Default Value', 'pods' ),
|
1559 |
+
'help' => __( 'help', 'pods' ),
|
1560 |
+
'type' => 'text',
|
1561 |
+
'default' => ''
|
1562 |
+
),
|
1563 |
+
'default_value_parameter' => array(
|
1564 |
+
'name' => 'default_value_parameter',
|
1565 |
+
'label' => __( 'Set Default Value via Parameter', 'pods' ),
|
1566 |
+
'help' => __( 'help', 'pods' ),
|
1567 |
+
'type' => 'text',
|
1568 |
+
'default' => ''
|
1569 |
+
)
|
1570 |
+
),
|
1571 |
+
__( 'Visibility', 'pods' ) => array(
|
1572 |
+
'restrict_access' => array(
|
1573 |
+
'name' => 'restrict_access',
|
1574 |
+
'label' => __( 'Restrict Access', 'pods' ),
|
1575 |
+
'group' => array(
|
1576 |
+
'admin_only' => array(
|
1577 |
+
'name' => 'admin_only',
|
1578 |
+
'label' => __( 'Restrict access to Admins?', 'pods' ),
|
1579 |
+
'default' => 0,
|
1580 |
+
'type' => 'boolean',
|
1581 |
+
'dependency' => true,
|
1582 |
+
'help' => __( 'This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' )
|
1583 |
+
),
|
1584 |
+
'restrict_role' => array(
|
1585 |
+
'name' => 'restrict_role',
|
1586 |
+
'label' => __( 'Restrict access by Role?', 'pods' ),
|
1587 |
+
'default' => 0,
|
1588 |
+
'type' => 'boolean',
|
1589 |
+
'dependency' => true
|
1590 |
+
),
|
1591 |
+
'restrict_capability' => array(
|
1592 |
+
'name' => 'restrict_capability',
|
1593 |
+
'label' => __( 'Restrict access by Capability?', 'pods' ),
|
1594 |
+
'default' => 0,
|
1595 |
+
'type' => 'boolean',
|
1596 |
+
'dependency' => true
|
1597 |
+
),
|
1598 |
+
'hidden' => array(
|
1599 |
+
'name' => 'hidden',
|
1600 |
+
'label' => __( 'Hide field from UI', 'pods' ),
|
1601 |
+
'default' => 0,
|
1602 |
+
'type' => 'boolean',
|
1603 |
+
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' )
|
1604 |
+
),
|
1605 |
+
'read_only' => array(
|
1606 |
+
'name' => 'read_only',
|
1607 |
+
'label' => __( 'Make field "Read Only" in UI', 'pods' ),
|
1608 |
+
'default' => 0,
|
1609 |
+
'type' => 'boolean',
|
1610 |
+
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods' ),
|
1611 |
+
'depends-on' => array(
|
1612 |
+
'type' => array(
|
1613 |
+
'boolean',
|
1614 |
+
'color',
|
1615 |
+
'currency',
|
1616 |
+
'date',
|
1617 |
+
'datetime',
|
1618 |
+
'email',
|
1619 |
+
'number',
|
1620 |
+
'paragraph',
|
1621 |
+
'password',
|
1622 |
+
'phone',
|
1623 |
+
'slug',
|
1624 |
+
'text',
|
1625 |
+
'time',
|
1626 |
+
'website'
|
1627 |
+
)
|
1628 |
+
)
|
1629 |
+
)
|
1630 |
+
)
|
1631 |
+
),
|
1632 |
+
'roles_allowed' => array(
|
1633 |
+
'name' => 'roles_allowed',
|
1634 |
+
'label' => __( 'Role(s) Allowed', 'pods' ),
|
1635 |
+
'help' => __( 'help', 'pods' ),
|
1636 |
+
'type' => 'pick',
|
1637 |
+
'pick_object' => 'role',
|
1638 |
+
'pick_format_type' => 'multi',
|
1639 |
+
'default' => 'administrator',
|
1640 |
+
'depends-on' => array(
|
1641 |
+
'restrict_role' => true
|
1642 |
+
)
|
1643 |
+
),
|
1644 |
+
'capability_allowed' => array(
|
1645 |
+
'name' => 'capability_allowed',
|
1646 |
+
'label' => __( 'Capability Allowed', 'pods' ),
|
1647 |
+
'help' => __( 'Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ),
|
1648 |
+
'type' => 'text',
|
1649 |
+
'default' => '',
|
1650 |
+
'depends-on' => array(
|
1651 |
+
'restrict_capability' => true
|
1652 |
+
)
|
1653 |
+
)
|
1654 |
+
/*,
|
1655 |
+
'search' => array(
|
1656 |
+
'label' => __( 'Include in searches', 'pods' ),
|
1657 |
+
'help' => __( 'help', 'pods' ),
|
1658 |
+
'default' => 1,
|
1659 |
+
'type' => 'boolean',
|
1660 |
+
)*/
|
1661 |
+
)
|
1662 |
+
/*,
|
1663 |
+
__( 'Validation', 'pods' ) => array(
|
1664 |
+
'regex_validation' => array(
|
1665 |
+
'label' => __( 'RegEx Validation', 'pods' ),
|
1666 |
+
'help' => __( 'help', 'pods' ),
|
1667 |
+
'type' => 'text',
|
1668 |
+
'default' => ''
|
1669 |
+
),
|
1670 |
+
'message_regex' => array(
|
1671 |
+
'label' => __( 'Message if field does not pass RegEx', 'pods' ),
|
1672 |
+
'help' => __( 'help', 'pods' ),
|
1673 |
+
'type' => 'text',
|
1674 |
+
'default' => ''
|
1675 |
+
),
|
1676 |
+
'message_required' => array(
|
1677 |
+
'label' => __( 'Message if field is blank', 'pods' ),
|
1678 |
+
'help' => __( 'help', 'pods' ),
|
1679 |
+
'type' => 'text',
|
1680 |
+
'default' => '',
|
1681 |
+
'depends-on' => array( 'required' => true )
|
1682 |
+
),
|
1683 |
+
'message_unique' => array(
|
1684 |
+
'label' => __( 'Message if field is not unique', 'pods' ),
|
1685 |
+
'help' => __( 'help', 'pods' ),
|
1686 |
+
'type' => 'text',
|
1687 |
+
'default' => '',
|
1688 |
+
'depends-on' => array( 'unique' => true )
|
1689 |
+
)
|
1690 |
+
)*/
|
1691 |
+
);
|
1692 |
+
|
1693 |
+
if ( !class_exists( 'Pods_Helpers' ) )
|
1694 |
+
unset( $options[ 'advanced-options' ][ 'input_helper' ] );
|
1695 |
+
|
1696 |
+
$options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod );
|
1697 |
+
|
1698 |
+
return $options;
|
1699 |
+
}
|
1700 |
+
|
1701 |
+
/**
|
1702 |
+
* Duplicate a pod
|
1703 |
+
*
|
1704 |
+
* @param $id
|
1705 |
+
* @param $obj
|
1706 |
+
*
|
1707 |
+
* @return mixed
|
1708 |
+
*/
|
1709 |
+
public function admin_setup_duplicate ( $obj ) {
|
1710 |
+
$new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) );
|
1711 |
+
|
1712 |
+
if ( 0 < $new_id )
|
1713 |
+
pods_redirect( pods_var_update( array( 'action' => 'edit', 'id' => $new_id, 'do' => 'duplicate' ) ) );
|
1714 |
+
}
|
1715 |
+
|
1716 |
+
/**
|
1717 |
+
* Restrict Duplicate action to custom types, not extended
|
1718 |
+
*
|
1719 |
+
* @param bool $restricted
|
1720 |
+
* @param array $restrict
|
1721 |
+
* @param string $action
|
1722 |
+
* @param array $row
|
1723 |
+
* @param PodsUI $obj
|
1724 |
+
*
|
1725 |
+
* @since 2.3.10
|
1726 |
+
*/
|
1727 |
+
public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) {
|
1728 |
+
|
1729 |
+
if ( in_array( $row[ 'real_type' ], array( 'user', 'media', 'comment' ) ) ) {
|
1730 |
+
$restricted = true;
|
1731 |
+
}
|
1732 |
+
|
1733 |
+
return $restricted;
|
1734 |
+
|
1735 |
+
}
|
1736 |
+
|
1737 |
+
/**
|
1738 |
+
* Reset a pod
|
1739 |
+
*
|
1740 |
+
* @param $obj
|
1741 |
+
*
|
1742 |
+
* @return mixed
|
1743 |
+
*/
|
1744 |
+
public function admin_setup_reset ( $obj, $id ) {
|
1745 |
+
$pod = pods_api()->load_pod( array( 'id' => $id ), false );
|
1746 |
+
|
1747 |
+
if ( empty( $pod ) )
|
1748 |
+
return $obj->error( __( 'Pod not found.', 'pods' ) );
|
1749 |
+
|
1750 |
+
pods_api()->reset_pod( array( 'id' => $id ) );
|
1751 |
+
|
1752 |
+
$obj->message( __( 'Pod reset successfully.', 'pods' ) );
|
1753 |
+
|
1754 |
+
$obj->manage();
|
1755 |
+
}
|
1756 |
+
|
1757 |
+
/**
|
1758 |
+
* Restrict Reset action from users and media
|
1759 |
+
*
|
1760 |
+
* @param bool $restricted
|
1761 |
+
* @param array $restrict
|
1762 |
+
* @param string $action
|
1763 |
+
* @param array $row
|
1764 |
+
* @param PodsUI $obj
|
1765 |
+
*
|
1766 |
+
* @since 2.3.10
|
1767 |
+
*/
|
1768 |
+
public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) {
|
1769 |
+
|
1770 |
+
if ( in_array( $row[ 'real_type' ], array( 'user', 'media' ) ) ) {
|
1771 |
+
$restricted = true;
|
1772 |
+
}
|
1773 |
+
|
1774 |
+
return $restricted;
|
1775 |
+
|
1776 |
+
}
|
1777 |
+
|
1778 |
+
/**
|
1779 |
+
* Delete a pod
|
1780 |
+
*
|
1781 |
+
* @param $id
|
1782 |
+
* @param $obj
|
1783 |
+
*
|
1784 |
+
* @return mixed
|
1785 |
+
*/
|
1786 |
+
public function admin_setup_delete ( $id, $obj ) {
|
1787 |
+
$pod = pods_api()->load_pod( array( 'id' => $id ), false );
|
1788 |
+
|
1789 |
+
if ( empty( $pod ) )
|
1790 |
+
return $obj->error( __( 'Pod not found.', 'pods' ) );
|
1791 |
+
|
1792 |
+
pods_api()->delete_pod( array( 'id' => $id ) );
|
1793 |
+
|
1794 |
+
unset( $obj->data[ $pod[ 'id' ] ] );
|
1795 |
+
|
1796 |
+
$obj->total = count( $obj->data );
|
1797 |
+
$obj->total_found = count( $obj->data );
|
1798 |
+
|
1799 |
+
$obj->message( __( 'Pod deleted successfully.', 'pods' ) );
|
1800 |
+
}
|
1801 |
+
|
1802 |
+
/**
|
1803 |
+
* Get advanced administration view.
|
1804 |
+
*/
|
1805 |
+
public function admin_advanced () {
|
1806 |
+
pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) );
|
1807 |
+
}
|
1808 |
+
|
1809 |
+
/**
|
1810 |
+
* Get settings administration view
|
1811 |
+
*/
|
1812 |
+
public function admin_settings () {
|
1813 |
+
pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) );
|
1814 |
+
}
|
1815 |
+
|
1816 |
+
/**
|
1817 |
+
* Get components administration UI
|
1818 |
+
*/
|
1819 |
+
public function admin_components () {
|
1820 |
+
$components = PodsInit::$components->components;
|
1821 |
+
|
1822 |
+
$view = pods_var( 'view', 'get', 'all', null, true );
|
1823 |
+
|
1824 |
+
$recommended = array(
|
1825 |
+
'advanced-relationships',
|
1826 |
+
'advanced-content-types',
|
1827 |
+
'migrate-packages',
|
1828 |
+
'roles-and-capabilities',
|
1829 |
+
'pages',
|
1830 |
+
'table-storage',
|
1831 |
+
'templates'
|
1832 |
+
);
|
1833 |
+
|
1834 |
+
foreach ( $components as $component => &$component_data ) {
|
1835 |
+
if ( !in_array( $view, array( 'all', 'recommended', 'dev' ) ) && ( !isset( $component_data[ 'Category' ] ) || $view != sanitize_title( $component_data[ 'Category' ] ) ) ) {
|
1836 |
+
unset( $components[ $component ] );
|
1837 |
+
|
1838 |
+
continue;
|
1839 |
+
}
|
1840 |
+
elseif ( 'recommended' == $view && !in_array( $component_data[ 'ID' ], $recommended ) ) {
|
1841 |
+
unset( $components[ $component ] );
|
1842 |
+
|
1843 |
+
continue;
|
1844 |
+
}
|
1845 |
+
elseif ( 'dev' == $view && pods_developer() && !pods_var_raw( 'DeveloperMode', $component_data, false ) ) {
|
1846 |
+
unset( $components[ $component ] );
|
1847 |
+
|
1848 |
+
continue;
|
1849 |
+
}
|
1850 |
+
elseif ( pods_var_raw( 'DeveloperMode', $component_data, false ) && !pods_developer() ) {
|
1851 |
+
unset( $components[ $component ] );
|
1852 |
+
|
1853 |
+
continue;
|
1854 |
+
}
|
1855 |
+
elseif ( !pods_var_raw( 'TablelessMode', $component_data, false ) && pods_tableless() ) {
|
1856 |
+
unset( $components[ $component ] );
|
1857 |
+
|
1858 |
+
continue;
|
1859 |
+
}
|
1860 |
+
|
1861 |
+
$component_data[ 'Name' ] = strip_tags( $component_data[ 'Name' ] );
|
1862 |
+
|
1863 |
+
if ( pods_var_raw( 'DeveloperMode', $component_data, false ) )
|
1864 |
+
$component_data[ 'Name' ] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>';
|
1865 |
+
|
1866 |
+
$meta = array();
|
1867 |
+
|
1868 |
+
if ( !empty( $component_data[ 'Version' ] ) )
|
1869 |
+
$meta[] = 'Version ' . $component_data[ 'Version' ];
|
1870 |
+
|
1871 |
+
if ( empty( $component_data[ 'Author' ] ) ) {
|
1872 |
+
$component_data[ 'Author' ] = 'Pods Framework Team';
|
1873 |
+
$component_data[ 'AuthorURI' ] = 'http://pods.io/';
|
1874 |
+
}
|
1875 |
+
|
1876 |
+
if ( !empty( $component_data[ 'AuthorURI' ] ) )
|
1877 |
+
$component_data[ 'Author' ] = '<a href="' . $component_data[ 'AuthorURI' ] . '">' . $component_data[ 'Author' ] . '</a>';
|
1878 |
+
|
1879 |
+
$meta[] = sprintf( __( 'by %s', 'pods' ), $component_data[ 'Author' ] );
|
1880 |
+
|
1881 |
+
if ( !empty( $component_data[ 'URI' ] ) )
|
1882 |
+
$meta[] = '<a href="' . $component_data[ 'URI' ] . '">' . __( 'Visit component site', 'pods' ) . '</a>';
|
1883 |
+
|
1884 |
+
$component_data[ 'Description' ] = wpautop( trim( make_clickable( strip_tags( $component_data[ 'Description' ], 'em,strong' ) ) ) );
|
1885 |
+
|
1886 |
+
if ( !empty( $meta ) )
|
1887 |
+
$component_data[ 'Description' ] .= '<div class="pods-component-meta" ' . ( !empty( $component_data[ 'Description' ] ) ? ' style="padding:8px 0 4px;"' : '' ) . '>' . implode( ' | ', $meta ) . '</div>';
|
1888 |
+
|
1889 |
+
$component_data = array(
|
1890 |
+
'id' => $component_data[ 'ID' ],
|
1891 |
+
'name' => $component_data[ 'Name' ],
|
1892 |
+
'category' => $component_data[ 'Category' ],
|
1893 |
+
'version' => '',
|
1894 |
+
'description' => $component_data[ 'Description' ],
|
1895 |
+
'mustuse' => pods_var_raw( 'MustUse', $component_data, false ),
|
1896 |
+
'toggle' => 0
|
1897 |
+
);
|
1898 |
+
|
1899 |
+
if ( !empty( $component_data[ 'category' ] ) ) {
|
1900 |
+
$category_url = pods_var_update( array( 'view' => sanitize_title( $component_data[ 'category' ] ), 'pg' => '', 'page' => $_GET[ 'page' ] ) );
|
1901 |
+
|
1902 |
+
$component_data[ 'category' ] = '<a href="' . $category_url . '">' . $component_data[ 'category' ] . '</a>';
|
1903 |
+
}
|
1904 |
+
|
1905 |
+
if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) && 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] )
|
1906 |
+
$component_data[ 'toggle' ] = 1;
|
1907 |
+
elseif ( $component_data[ 'mustuse' ] )
|
1908 |
+
$component_data[ 'toggle' ] = 1;
|
1909 |
+
}
|
1910 |
+
|
1911 |
+
$ui = array(
|
1912 |
+
'data' => $components,
|
1913 |
+
'total' => count( $components ),
|
1914 |
+
'total_found' => count( $components ),
|
1915 |
+
'icon' => PODS_URL . 'ui/images/icon32.png',
|
1916 |
+
'items' => 'Components',
|
1917 |
+
'item' => 'Component',
|
1918 |
+
'fields' => array(
|
1919 |
+
'manage' => array(
|
1920 |
+
'name' => array(
|
1921 |
+
'label' => __( 'Name', 'pods' ),
|
1922 |
+
'width' => '30%',
|
1923 |
+
'type' => 'text',
|
1924 |
+
'options' => array(
|
1925 |
+
'text_allow_html' => true
|
1926 |
+
)
|
1927 |
+
),
|
1928 |
+
'category' => array(
|
1929 |
+
'label' => __( 'Category', 'pods' ),
|
1930 |
+
'width' => '10%',
|
1931 |
+
'type' => 'text',
|
1932 |
+
'options' => array(
|
1933 |
+
'text_allow_html' => true
|
1934 |
+
)
|
1935 |
+
),
|
1936 |
+
'description' => array(
|
1937 |
+
'label' => __( 'Description', 'pods' ),
|
1938 |
+
'width' => '60%',
|
1939 |
+
'type' => 'text',
|
1940 |
+
'options' => array(
|
1941 |
+
'text_allow_html' => true,
|
1942 |
+
'text_allowed_html_tags' => 'strong em a ul ol li b i br div'
|
1943 |
+
)
|
1944 |
+
)
|
1945 |
+
)
|
1946 |
+
),
|
1947 |
+
'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ),
|
1948 |
+
'actions_custom' => array(
|
1949 |
+
'toggle' => array( 'callback' => array( $this, 'admin_components_toggle' ) )
|
1950 |
+
),
|
1951 |
+
'filters_enhanced' => true,
|
1952 |
+
'views' => array(
|
1953 |
+
'all' => __( 'All', 'pods' ),
|
1954 |
+
//'recommended' => __( 'Recommended', 'pods' ),
|
1955 |
+
'field-types' => __( 'Field Types', 'pods' ),
|
1956 |
+
'tools' => __( 'Tools', 'pods' ),
|
1957 |
+
'integration' => __( 'Integration', 'pods' ),
|
1958 |
+
'migration' => __( 'Migration', 'pods' ),
|
1959 |
+
'advanced' => __( 'Advanced', 'pods' )
|
1960 |
+
),
|
1961 |
+
'view' => $view,
|
1962 |
+
'heading' => array(
|
1963 |
+
'views' => __( 'Category', 'pods' )
|
1964 |
+
),
|
1965 |
+
'search' => false,
|
1966 |
+
'searchable' => false,
|
1967 |
+
'sortable' => false,
|
1968 |
+
'pagination' => false
|
1969 |
+
);
|
1970 |
+
|
1971 |
+
if ( pods_developer() )
|
1972 |
+
$ui[ 'views' ][ 'dev' ] = __( 'Developer Preview', 'pods' );
|
1973 |
+
|
1974 |
+
pods_ui( $ui );
|
1975 |
+
}
|
1976 |
+
|
1977 |
+
/**
|
1978 |
+
* Toggle a component on or off
|
1979 |
+
*
|
1980 |
+
* @param PodsUI $ui
|
1981 |
+
*
|
1982 |
+
* @return bool
|
1983 |
+
*/
|
1984 |
+
public function admin_components_toggle ( PodsUI $ui ) {
|
1985 |
+
$component = $_GET[ 'id' ];
|
1986 |
+
|
1987 |
+
if ( !empty( PodsInit::$components->components[ $component ][ 'PluginDependency' ] ) ) {
|
1988 |
+
$dependency = explode( '|', PodsInit::$components->components[ $component ][ 'PluginDependency' ] );
|
1989 |
+
|
1990 |
+
if ( !pods_is_plugin_active( $dependency[ 1 ] ) ) {
|
1991 |
+
$website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[ 1 ] ) . '/';
|
1992 |
+
|
1993 |
+
if ( isset( $dependency[ 2 ] ) )
|
1994 |
+
$website = $dependency[ 2 ];
|
1995 |
+
|
1996 |
+
if ( !empty( $website ) )
|
1997 |
+
$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank">' . $website . '</a>' );
|
1998 |
+
|
1999 |
+
$message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> plugin installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website;
|
2000 |
+
|
2001 |
+
$ui->error( $message );
|
2002 |
+
|
2003 |
+
$ui->manage();
|
2004 |
+
|
2005 |
+
return;
|
2006 |
+
}
|
2007 |
+
}
|
2008 |
+
|
2009 |
+
if ( !empty( PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ) ) {
|
2010 |
+
$dependency = explode( '|', PodsInit::$components->components[ $component ][ 'ThemeDependency' ] );
|
2011 |
+
|
2012 |
+
if ( strtolower( $dependency[ 1 ] ) != strtolower( get_template() ) && strtolower( $dependency[ 1 ] ) != strtolower( get_stylesheet() ) ) {
|
2013 |
+
$website = '';
|
2014 |
+
|
2015 |
+
if ( isset( $dependency[ 2 ] ) )
|
2016 |
+
$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[ 2 ] . '" target="_blank">' . $dependency[ 2 ] . '</a>' );
|
2017 |
+
|
2018 |
+
$message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> theme installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website;
|
2019 |
+
|
2020 |
+
$ui->error( $message );
|
2021 |
+
|
2022 |
+
$ui->manage();
|
2023 |
+
|
2024 |
+
return;
|
2025 |
+
}
|
2026 |
+
}
|
2027 |
+
|
2028 |
+
if ( !empty( PodsInit::$components->components[ $component ][ 'MustUse' ] ) ) {
|
2029 |
+
$message = sprintf( __( 'The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ] );
|
2030 |
+
|
2031 |
+
$ui->error( $message );
|
2032 |
+
|
2033 |
+
$ui->manage();
|
2034 |
+
|
2035 |
+
return;
|
2036 |
+
}
|
2037 |
+
|
2038 |
+
if ( 1 == pods_var( 'toggled' ) ) {
|
2039 |
+
$toggle = PodsInit::$components->toggle( $component );
|
2040 |
+
|
2041 |
+
if ( true === $toggle )
|
2042 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) );
|
2043 |
+
elseif ( false === $toggle )
|
2044 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) );
|
2045 |
+
|
2046 |
+
$components = PodsInit::$components->components;
|
2047 |
+
|
2048 |
+
foreach ( $components as $component => &$component_data ) {
|
2049 |
+
$toggle = 0;
|
2050 |
+
|
2051 |
+
if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) ) {
|
2052 |
+
if ( 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] )
|
2053 |
+
$toggle = 1;
|
2054 |
+
}
|
2055 |
+
if ( true === $component_data[ 'DeveloperMode' ] ) {
|
2056 |
+
if ( !pods_developer() ) {
|
2057 |
+
unset( $components[ $component ] );
|
2058 |
+
continue;
|
2059 |
+
}
|
2060 |
+
}
|
2061 |
+
|
2062 |
+
$component_data = array(
|
2063 |
+
'id' => $component_data[ 'ID' ],
|
2064 |
+
'name' => $component_data[ 'Name' ],
|
2065 |
+
'description' => make_clickable( $component_data[ 'Description' ] ),
|
2066 |
+
'version' => $component_data[ 'Version' ],
|
2067 |
+
'author' => $component_data[ 'Author' ],
|
2068 |
+
'toggle' => $toggle
|
2069 |
+
);
|
2070 |
+
}
|
2071 |
+
|
2072 |
+
$ui->data = $components;
|
2073 |
+
|
2074 |
+
pods_transient_clear( 'pods_components' );
|
2075 |
+
|
2076 |
+
$url = pods_var_update( array( 'toggled' => null ) );
|
2077 |
+
|
2078 |
+
pods_redirect( $url );
|
2079 |
+
}
|
2080 |
+
elseif ( 1 == pods_var( 'toggle' ) )
|
2081 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) );
|
2082 |
+
else
|
2083 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) );
|
2084 |
+
|
2085 |
+
$ui->manage();
|
2086 |
+
}
|
2087 |
+
|
2088 |
+
/**
|
2089 |
+
* Get the admin upgrade page
|
2090 |
+
*/
|
2091 |
+
public function admin_upgrade () {
|
2092 |
+
foreach ( PodsInit::$upgrades as $old_version => $new_version ) {
|
2093 |
+
if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) {
|
2094 |
+
$new_version = str_replace( '.', '_', $new_version );
|
2095 |
+
|
2096 |
+
pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) );
|
2097 |
+
|
2098 |
+
break;
|
2099 |
+
}
|
2100 |
+
}
|
2101 |
+
}
|
2102 |
+
|
2103 |
+
/**
|
2104 |
+
* Get the admin help page
|
2105 |
+
*/
|
2106 |
+
public function admin_help () {
|
2107 |
+
pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) );
|
2108 |
+
}
|
2109 |
+
|
2110 |
+
/**
|
2111 |
+
* Add pods specific capabilities.
|
2112 |
+
*
|
2113 |
+
* @param $capabilities List of extra capabilities to add
|
2114 |
+
*
|
2115 |
+
* @return array
|
2116 |
+
*/
|
2117 |
+
public function admin_capabilities ( $capabilities ) {
|
2118 |
+
$pods = pods_api()->load_pods( array( 'type' => array( 'pod', 'table', 'post_type', 'taxonomy', 'settings' ) ) );
|
2119 |
+
|
2120 |
+
$capabilities[] = 'pods';
|
2121 |
+
$capabilities[] = 'pods_content';
|
2122 |
+
$capabilities[] = 'pods_settings';
|
2123 |
+
$capabilities[] = 'pods_components';
|
2124 |
+
|
2125 |
+
foreach ( $pods as $pod ) {
|
2126 |
+
if ( 'settings' == $pod[ 'type' ] ) {
|
2127 |
+
$capabilities[] = 'pods_edit_' . $pod[ 'name' ];
|
2128 |
+
}
|
2129 |
+
elseif ( 'post_type' == $pod[ 'type' ] ) {
|
2130 |
+
$capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) );
|
2131 |
+
|
2132 |
+
if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ] ) && 0 < strlen( $capability_type ) ) {
|
2133 |
+
$capabilities[] = 'read_' . $capability_type;
|
2134 |
+
$capabilities[] = 'edit_' . $capability_type;
|
2135 |
+
$capabilities[] = 'delete_' . $capability_type;
|
2136 |
+
|
2137 |
+
if ( 1 == pods_var( 'capability_type_extra', $pod[ 'options' ], 1 ) ) {
|
2138 |
+
$capabilities[] = 'read_private_' . $capability_type . 's';
|
2139 |
+
$capabilities[] = 'edit_' . $capability_type . 's';
|
2140 |
+
$capabilities[] = 'edit_others_' . $capability_type . 's';
|
2141 |
+
$capabilities[] = 'edit_private_' . $capability_type . 's';
|
2142 |
+
$capabilities[] = 'edit_published_' . $capability_type . 's';
|
2143 |
+
$capabilities[] = 'publish_' . $capability_type . 's';
|
2144 |
+
$capabilities[] = 'delete_' . $capability_type . 's';
|
2145 |
+
$capabilities[] = 'delete_private_' . $capability_type . 's';
|
2146 |
+
$capabilities[] = 'delete_published_' . $capability_type . 's';
|
2147 |
+
$capabilities[] = 'delete_others_' . $capability_type . 's';
|
2148 |
+
}
|
2149 |
+
}
|
2150 |
+
}
|
2151 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
2152 |
+
if ( 1 == pods_var( 'capabilities', $pod[ 'options' ], 0 ) ) {
|
2153 |
+
$capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) . 's' );
|
2154 |
+
|
2155 |
+
$capabilities[] = 'manage_' . $capability_type;
|
2156 |
+
$capabilities[] = 'edit_' . $capability_type;
|
2157 |
+
$capabilities[] = 'delete_' . $capability_type;
|
2158 |
+
$capabilities[] = 'assign_' . $capability_type;
|
2159 |
+
}
|
2160 |
+
}
|
2161 |
+
else {
|
2162 |
+
$capabilities[] = 'pods_add_' . $pod[ 'name' ];
|
2163 |
+
$capabilities[] = 'pods_edit_' . $pod[ 'name' ];
|
2164 |
+
|
2165 |
+
if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] )
|
2166 |
+
$capabilities[] = 'pods_edit_others_' . $pod[ 'name' ];
|
2167 |
+
|
2168 |
+
$capabilities[] = 'pods_delete_' . $pod[ 'name' ];
|
2169 |
+
|
2170 |
+
if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] )
|
2171 |
+
$capabilities[] = 'pods_delete_others_' . $pod[ 'name' ];
|
2172 |
+
|
2173 |
+
$actions_enabled = pods_var_raw( 'ui_actions_enabled', $pod[ 'options' ] );
|
2174 |
+
|
2175 |
+
if ( !empty( $actions_enabled ) )
|
2176 |
+
$actions_enabled = (array) $actions_enabled;
|
2177 |
+
else
|
2178 |
+
$actions_enabled = array();
|
2179 |
+
|
2180 |
+
$available_actions = array(
|
2181 |
+
'add',
|
2182 |
+
'edit',
|
2183 |
+
'duplicate',
|
2184 |
+
'delete',
|
2185 |
+
'reorder',
|
2186 |
+
'export'
|
2187 |
+
);
|
2188 |
+
|
2189 |
+
if ( !empty( $actions_enabled ) ) {
|
2190 |
+
$actions_disabled = array(
|
2191 |
+
'view' => 'view'
|
2192 |
+
);
|
2193 |
+
|
2194 |
+
foreach ( $available_actions as $action ) {
|
2195 |
+
if ( !in_array( $action, $actions_enabled ) )
|
2196 |
+
$actions_disabled[ $action ] = $action;
|
2197 |
+
}
|
2198 |
+
|
2199 |
+
if ( !in_array( 'export', $actions_disabled ) )
|
2200 |
+
$capabilities[] = 'pods_export_' . $pod[ 'name' ];
|
2201 |
+
|
2202 |
+
if ( !in_array( 'reorder', $actions_disabled ) )
|
2203 |
+
$capabilities[] = 'pods_reorder_' . $pod[ 'name' ];
|
2204 |
+
}
|
2205 |
+
elseif ( 1 == pods_var( 'ui_export', $pod[ 'options' ], 0 ) )
|
2206 |
+
$capabilities[] = 'pods_export_' . $pod[ 'name' ];
|
2207 |
+
}
|
2208 |
+
}
|
2209 |
+
|
2210 |
+
return $capabilities;
|
2211 |
+
}
|
2212 |
+
|
2213 |
+
/**
|
2214 |
+
* Handle ajax calls for the administration
|
2215 |
+
*/
|
2216 |
+
public function admin_ajax () {
|
2217 |
+
if ( false === headers_sent() ) {
|
2218 |
+
pods_session_start();
|
2219 |
+
|
2220 |
+
header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
|
2221 |
+
}
|
2222 |
+
|
2223 |
+
// Sanitize input
|
2224 |
+
$params = pods_unslash( (array) $_POST );
|
2225 |
+
|
2226 |
+
foreach ( $params as $key => $value ) {
|
2227 |
+
if ( 'action' == $key )
|
2228 |
+
continue;
|
2229 |
+
|
2230 |
+
// Fixup $_POST data
|
2231 |
+
$_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ];
|
2232 |
+
|
2233 |
+
// Fixup $params with unslashed data
|
2234 |
+
$params[ str_replace( '_podsfix_', '', $key ) ] = $value;
|
2235 |
+
|
2236 |
+
// Unset the _podsfix_* keys
|
2237 |
+
unset( $params[ $key ] );
|
2238 |
+
}
|
2239 |
+
|
2240 |
+
$params = (object) $params;
|
2241 |
+
|
2242 |
+
$methods = array(
|
2243 |
+
'add_pod' => array( 'priv' => true ),
|
2244 |
+
'save_pod' => array( 'priv' => true ),
|
2245 |
+
'load_sister_fields' => array( 'priv' => true ),
|
2246 |
+
'process_form' => array( 'custom_nonce' => true ), // priv handled through nonce
|
2247 |
+
'upgrade' => array( 'priv' => true ),
|
2248 |
+
'migrate' => array( 'priv' => true )
|
2249 |
+
);
|
2250 |
+
|
2251 |
+
$methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this );
|
2252 |
+
|
2253 |
+
if ( !isset( $params->method ) || !isset( $methods[ $params->method ] ) )
|
2254 |
+
pods_error( 'Invalid AJAX request', $this );
|
2255 |
+
|
2256 |
+
$defaults = array(
|
2257 |
+
'priv' => null,
|
2258 |
+
'name' => $params->method,
|
2259 |
+
'custom_nonce' => null
|
2260 |
+
);
|
2261 |
+
|
2262 |
+
$method = (object) array_merge( $defaults, (array) $methods[ $params->method ] );
|
2263 |
+
|
2264 |
+
if ( true !== $method->custom_nonce && ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-' . $params->method ) ) )
|
2265 |
+
pods_error( __( 'Unauthorized request', 'pods' ), $this );
|
2266 |
+
|
2267 |
+
// Cleaning up $params
|
2268 |
+
unset( $params->action );
|
2269 |
+
unset( $params->method );
|
2270 |
+
|
2271 |
+
if ( true !== $method->custom_nonce )
|
2272 |
+
unset( $params->_wpnonce );
|
2273 |
+
|
2274 |
+
// Check permissions (convert to array to support multiple)
|
2275 |
+
if ( !empty( $method->priv ) && !pods_is_admin( array( 'pods' ) ) && true !== $method->priv && !pods_is_admin( $method->priv ) )
|
2276 |
+
pods_error( __( 'Access denied', 'pods' ), $this );
|
2277 |
+
|
2278 |
+
$params->method = $method->name;
|
2279 |
+
|
2280 |
+
$params = apply_filters( 'pods_api_' . $method->name, $params, $method );
|
2281 |
+
|
2282 |
+
$api = pods_api();
|
2283 |
+
|
2284 |
+
if ( 'upgrade' == $method->name )
|
2285 |
+
$output = (string) pods_upgrade( $params->version )->ajax( $params );
|
2286 |
+
elseif ( 'migrate' == $method->name )
|
2287 |
+
$output = (string) apply_filters( 'pods_api_migrate_run', $params );
|
2288 |
+
else {
|
2289 |
+
if ( !method_exists( $api, $method->name ) )
|
2290 |
+
pods_error( 'API method does not exist', $this );
|
2291 |
+
elseif ( 'save_pod' == $method->name ) {
|
2292 |
+
if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) {
|
2293 |
+
$params->fields = $params->field_data_json;
|
2294 |
+
|
2295 |
+
unset( $params->field_data_json );
|
2296 |
+
|
2297 |
+
foreach ( $params->fields as $k => $v ) {
|
2298 |
+
if ( empty( $v ) )
|
2299 |
+
unset( $params->fields[ $k ] );
|
2300 |
+
elseif ( !is_array( $v ) )
|
2301 |
+
$params->fields[ $k ] = (array) @json_decode( $v, true );
|
2302 |
+
}
|
2303 |
+
}
|
2304 |
+
}
|
2305 |
+
|
2306 |
+
// Dynamically call the API method
|
2307 |
+
$params = (array) $params;
|
2308 |
+
|
2309 |
+
$output = call_user_func( array( $api, $method->name ), $params );
|
2310 |
+
}
|
2311 |
+
|
2312 |
+
// Output in json format
|
2313 |
+
if ( false !== $output ) {
|
2314 |
+
if ( is_array( $output ) || is_object( $output ) )
|
2315 |
+
wp_send_json( $output );
|
2316 |
+
else
|
2317 |
+
echo $output;
|
2318 |
+
}
|
2319 |
+
else
|
2320 |
+
pods_error( 'There was a problem with your request.' );
|
2321 |
+
|
2322 |
+
die(); // KBAI!
|
2323 |
+
}
|
2324 |
+
|
2325 |
+
/**
|
2326 |
+
* Profiles the Pods configuration
|
2327 |
+
*
|
2328 |
+
* @param null|string|array $pod. Optional. Which Pod(s) to get configuration for. Can be a the name of one Pod, or an array of names of Pods, or null, which is the default, to profile all Pods.
|
2329 |
+
* @param bool $full_field_info Optional. If true all info about each field is returned. If false, which is the default only name and type, will be returned.
|
2330 |
+
*
|
2331 |
+
* @return array
|
2332 |
+
*
|
2333 |
+
* @since 3.0.0
|
2334 |
+
*/
|
2335 |
+
function configuration( $pod = null, $full_field_info = false ){
|
2336 |
+
$api = pods_api();
|
2337 |
+
|
2338 |
+
if ( is_null( $pod ) ) {
|
2339 |
+
$the_pods = $api->load_pods();
|
2340 |
+
}
|
2341 |
+
elseif( is_array( $pod ) ) {
|
2342 |
+
foreach ( $pod as $p ) {
|
2343 |
+
$the_pods[] = $api->load_pod( $p );
|
2344 |
+
}
|
2345 |
+
}
|
2346 |
+
else {
|
2347 |
+
$the_pods[] = $api->load_pod( $pod );
|
2348 |
+
}
|
2349 |
+
|
2350 |
+
foreach( $the_pods as $pod ) {
|
2351 |
+
$configuration[ $pod[ 'name' ] ] = array(
|
2352 |
+
'name' => $pod['name'],
|
2353 |
+
'ID' => $pod[ 'id' ],
|
2354 |
+
'storage' => $pod[ 'storage' ],
|
2355 |
+
'fields' => $pod[ 'fields' ],
|
2356 |
+
);
|
2357 |
+
}
|
2358 |
+
|
2359 |
+
if ( ! $full_field_info ) {
|
2360 |
+
foreach ( $the_pods as $pod ) {
|
2361 |
+
$fields = $configuration[ $pod['name'] ][ 'fields' ];
|
2362 |
+
unset( $configuration[ $pod['name'] ][ 'fields' ] );
|
2363 |
+
foreach ( $fields as $field ) {
|
2364 |
+
$info = array (
|
2365 |
+
'name' => $field[ 'name' ],
|
2366 |
+
'type' => $field[ 'type' ],
|
2367 |
+
);
|
2368 |
+
|
2369 |
+
if ( $info[ 'type' ] === 'pick' ) {
|
2370 |
+
$info[ 'pick_object' ] = $field[ 'pick_object' ];
|
2371 |
+
if ( isset ( $field[ 'pick_val' ] ) && $field[ 'pick_val' ] !== '' ) {
|
2372 |
+
$info[ 'pick_val' ] = $field[ 'pick_val' ];
|
2373 |
+
}
|
2374 |
+
}
|
2375 |
+
|
2376 |
+
if ( is_array( $info ) ) {
|
2377 |
+
$configuration[ $pod[ 'name' ] ][ 'fields' ][ $field[ 'name' ] ] = $info;
|
2378 |
+
}
|
2379 |
+
|
2380 |
+
unset( $info );
|
2381 |
+
|
2382 |
+
}
|
2383 |
+
|
2384 |
+
}
|
2385 |
+
|
2386 |
+
}
|
2387 |
+
|
2388 |
+
if ( is_array ( $configuration ) ) {
|
2389 |
+
return $configuration;
|
2390 |
+
|
2391 |
+
}
|
2392 |
+
|
2393 |
+
}
|
2394 |
+
|
2395 |
+
}
|
classes/PodsArray.php
ADDED
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsArray implements ArrayAccess {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var array|mixed
|
9 |
+
*/
|
10 |
+
private $__container = array();
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Alternative to get_object_vars to access an object as an array with simple functionality and accepts arrays to
|
14 |
+
* add additional functionality. Additional functionality includes validation and setting default data.
|
15 |
+
*
|
16 |
+
* @param mixed $container Object (or existing Array)
|
17 |
+
*
|
18 |
+
* @return \PodsArray
|
19 |
+
*
|
20 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
21 |
+
* @since 2.0
|
22 |
+
*/
|
23 |
+
public function __construct ( $container ) {
|
24 |
+
if ( is_array( $container ) || is_object( $container ) )
|
25 |
+
$this->__container = &$container;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Set value from array usage $object['offset'] = 'value';
|
30 |
+
*
|
31 |
+
* @param mixed $offset Used to set index of Array or Variable name on Object
|
32 |
+
* @param mixed $value Value to be set
|
33 |
+
*
|
34 |
+
* @return mixed|void
|
35 |
+
* @since 2.0
|
36 |
+
*/
|
37 |
+
public function offsetSet ( $offset, $value ) {
|
38 |
+
if ( is_array( $this->__container ) )
|
39 |
+
$this->__container[ $offset ] = $value;
|
40 |
+
else
|
41 |
+
$this->__container->$offset = $value;
|
42 |
+
return $value;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Get value from array usage $object['offset'];
|
47 |
+
*
|
48 |
+
* @param mixed $offset Used to get value of Array or Variable on Object
|
49 |
+
*
|
50 |
+
* @return mixed|null
|
51 |
+
* @since 2.0
|
52 |
+
*/
|
53 |
+
public function offsetGet ( $offset ) {
|
54 |
+
if ( is_array( $this->__container ) ) {
|
55 |
+
if ( isset( $this->__container[ $offset ] ) )
|
56 |
+
return $this->__container[ $offset ];
|
57 |
+
return null;
|
58 |
+
}
|
59 |
+
if ( isset( $this->__container->$offset ) )
|
60 |
+
return $this->__container->$offset;
|
61 |
+
return null;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Get value from array usage $object['offset'];
|
66 |
+
*
|
67 |
+
* @param mixed $offset Used to get value of Array or Variable on Object
|
68 |
+
*
|
69 |
+
* @return bool
|
70 |
+
* @since 2.0
|
71 |
+
*/
|
72 |
+
public function offsetExists ( $offset ) {
|
73 |
+
if ( is_array( $this->__container ) )
|
74 |
+
return isset( $this->__container[ $offset ] );
|
75 |
+
return isset( $this->__container->$offset );
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Get value from array usage $object['offset'];
|
80 |
+
*
|
81 |
+
* @param mixed $offset Used to unset index of Array or Variable on Object
|
82 |
+
*
|
83 |
+
* @since 2.0
|
84 |
+
*/
|
85 |
+
public function offsetUnset ( $offset ) {
|
86 |
+
if ( is_array( $this->__container ) )
|
87 |
+
unset( $this->__container[ $offset ] );
|
88 |
+
else
|
89 |
+
unset( $this->__container->$offset );
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Validate value on a specific type and set default (if empty)
|
94 |
+
*
|
95 |
+
* @param mixed $offset Used to get value of Array or Variable on Object
|
96 |
+
* @param mixed $default Used to set default value if it doesn't exist
|
97 |
+
* @param string $type Used to force a specific type of variable (allowed: array, object, integer, absint, boolean)
|
98 |
+
* @param mixed $extra Used in advanced types of variables
|
99 |
+
*
|
100 |
+
* @return array|bool|int|mixed|null|number|object
|
101 |
+
* @since 2.0
|
102 |
+
*/
|
103 |
+
public function validate ( $offset, $default = null, $type = null, $extra = null ) {
|
104 |
+
if ( !$this->offsetExists( $offset ) )
|
105 |
+
$this->offsetSet( $offset, $default );
|
106 |
+
|
107 |
+
$value = $this->offsetGet( $offset );
|
108 |
+
|
109 |
+
if ( empty( $value ) && null !== $default && false !== $value )
|
110 |
+
$value = $default;
|
111 |
+
if ( 'array' == $type || 'array_merge' == $type ) {
|
112 |
+
if ( !is_array( $value ) )
|
113 |
+
$value = explode( ',', $value );
|
114 |
+
|
115 |
+
if ( 'array_merge' == $type && $value !== $default )
|
116 |
+
$value = array_merge( $default, $value );
|
117 |
+
}
|
118 |
+
elseif ( 'object' == $type || 'object_merge' == $type ) {
|
119 |
+
if ( !is_object( $value ) ) {
|
120 |
+
if ( !is_array( $value ) )
|
121 |
+
$value = explode( ',', $value );
|
122 |
+
$value = (object) $value;
|
123 |
+
}
|
124 |
+
|
125 |
+
if ( 'object_merge' == $type && $value !== $default )
|
126 |
+
$value = (object) array_merge( (array) $default, (array) $value );
|
127 |
+
}
|
128 |
+
elseif ( 'integer' == $type || 'int' == $type || 'absint' == $type ) {
|
129 |
+
if ( !is_numeric( trim( $value ) ) )
|
130 |
+
$value = 0;
|
131 |
+
else
|
132 |
+
$value = intval( $value );
|
133 |
+
|
134 |
+
if ( 'absint' == $type )
|
135 |
+
$value = abs( $value );
|
136 |
+
}
|
137 |
+
elseif ( 'boolean' == $type || 'bool' == $type )
|
138 |
+
$value = (boolean) $value;
|
139 |
+
elseif ( 'in_array' == $type && is_array( $default ) ) {
|
140 |
+
if ( is_array( $value ) ) {
|
141 |
+
foreach ( $value as $k => $v ) {
|
142 |
+
if ( !in_array( $v, $extra ) )
|
143 |
+
unset( $value[ $k ] );
|
144 |
+
}
|
145 |
+
}
|
146 |
+
elseif ( !in_array( $value, $extra ) )
|
147 |
+
$value = $default;
|
148 |
+
}
|
149 |
+
elseif ( 'isset' == $type && is_array( $default ) ) {
|
150 |
+
if ( is_array( $value ) ) {
|
151 |
+
foreach ( $value as $k => $v ) {
|
152 |
+
if ( !isset( $extra[ $v ] ) )
|
153 |
+
unset( $value[ $k ] );
|
154 |
+
}
|
155 |
+
}
|
156 |
+
elseif ( !isset( $extra[ $value ] ) )
|
157 |
+
$value = $default;
|
158 |
+
}
|
159 |
+
|
160 |
+
$this->offsetSet( $offset, $value );
|
161 |
+
|
162 |
+
return $value;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Dump the PodsArray object to array
|
167 |
+
*
|
168 |
+
* @return array Array version of the object
|
169 |
+
*
|
170 |
+
* @since 2.0
|
171 |
+
*/
|
172 |
+
public function dump () {
|
173 |
+
if ( is_array( $this->__container ) )
|
174 |
+
return $this->__container;
|
175 |
+
return get_object_vars( $this->__container );
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Mapping >> offsetSet
|
180 |
+
*
|
181 |
+
* @since 2.0
|
182 |
+
*/
|
183 |
+
public function __set ( $offset, $value ) {
|
184 |
+
return $this->offsetSet( $offset, $value );
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Mapping >> offsetGet
|
189 |
+
*
|
190 |
+
* @since 2.0
|
191 |
+
*/
|
192 |
+
public function __get ( $offset ) {
|
193 |
+
return $this->offsetGet( $offset );
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Mapping >> offsetExists
|
198 |
+
*
|
199 |
+
* @since 2.0
|
200 |
+
*/
|
201 |
+
public function __isset ( $offset ) {
|
202 |
+
return $this->offsetExists( $offset );
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Mapping >> offsetUnset
|
207 |
+
*
|
208 |
+
* @since 2.0
|
209 |
+
*/
|
210 |
+
public function __unset ( $offset ) {
|
211 |
+
$this->offsetUnset( $offset );
|
212 |
+
}
|
213 |
+
}
|
classes/PodsComponent.php
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The base component class, all components should extend this.
|
4 |
+
*
|
5 |
+
* @package Pods
|
6 |
+
*/
|
7 |
+
class PodsComponent {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Do things like register/enqueue scripts and stylesheets
|
11 |
+
*
|
12 |
+
* @return \PodsComponent
|
13 |
+
*
|
14 |
+
* @since 2.0
|
15 |
+
*/
|
16 |
+
public function __construct () {
|
17 |
+
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Add options and set defaults for component settings, shows in admin area
|
22 |
+
*
|
23 |
+
* @return array $options
|
24 |
+
*
|
25 |
+
* @since 2.0
|
26 |
+
public function options () {
|
27 |
+
$options = array(
|
28 |
+
'option_name' => array(
|
29 |
+
'label' => 'Option Label',
|
30 |
+
'depends-on' => array( 'another_option' => 'specific-value' ),
|
31 |
+
'default' => 'default-value',
|
32 |
+
'type' => 'field_type',
|
33 |
+
'data' => array(
|
34 |
+
'value1' => 'Label 1',
|
35 |
+
|
36 |
+
// Group your options together
|
37 |
+
'Option Group' => array(
|
38 |
+
'gvalue1' => 'Option Label 1',
|
39 |
+
'gvalue2' => 'Option Label 2'
|
40 |
+
),
|
41 |
+
|
42 |
+
// below is only if the option_name above is the "{$fieldtype}_format_type"
|
43 |
+
'value2' => array(
|
44 |
+
'label' => 'Label 2',
|
45 |
+
'regex' => '[a-zA-Z]' // Uses JS regex validation for the value saved if this option selected
|
46 |
+
)
|
47 |
+
),
|
48 |
+
|
49 |
+
// below is only for a boolean group
|
50 |
+
'group' => array(
|
51 |
+
'option_boolean1' => array(
|
52 |
+
'label' => 'Option boolean 1?',
|
53 |
+
'default' => 1,
|
54 |
+
'type' => 'boolean'
|
55 |
+
),
|
56 |
+
'option_boolean2' => array(
|
57 |
+
'label' => 'Option boolean 2?',
|
58 |
+
'default' => 0,
|
59 |
+
'type' => 'boolean'
|
60 |
+
)
|
61 |
+
)
|
62 |
+
)
|
63 |
+
);
|
64 |
+
|
65 |
+
return $options;
|
66 |
+
}
|
67 |
+
*/
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Handler to run code based on $options
|
71 |
+
*
|
72 |
+
* @param $options
|
73 |
+
*
|
74 |
+
* @since 2.0
|
75 |
+
*/
|
76 |
+
public function handler ( $options ) {
|
77 |
+
// run code based on $options set
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Build admin area
|
82 |
+
*
|
83 |
+
* @param $options
|
84 |
+
*
|
85 |
+
* @since 2.0
|
86 |
+
public function admin ( $options ) {
|
87 |
+
// run code based on $options set
|
88 |
+
}
|
89 |
+
*/
|
90 |
+
}
|
classes/PodsComponents.php
ADDED
@@ -0,0 +1,667 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Component managing class
|
4 |
+
*
|
5 |
+
* @package Pods
|
6 |
+
*/
|
7 |
+
class PodsComponents {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @var PodsComponents
|
11 |
+
*/
|
12 |
+
static $instance = null;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Root of Components directory
|
16 |
+
*
|
17 |
+
* @var string
|
18 |
+
*
|
19 |
+
* @private
|
20 |
+
* @since 2.0
|
21 |
+
*/
|
22 |
+
private $components_dir = null;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Available components
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*
|
29 |
+
* @since 2.0
|
30 |
+
*/
|
31 |
+
public $components = array();
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Components settings
|
35 |
+
*
|
36 |
+
* @var string
|
37 |
+
*
|
38 |
+
* @since 2.0
|
39 |
+
*/
|
40 |
+
public $settings = array();
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Singleton handling for a basic pods_components() request
|
44 |
+
*
|
45 |
+
* @return \PodsComponents
|
46 |
+
*
|
47 |
+
* @since 2.3.5
|
48 |
+
*/
|
49 |
+
public static function init () {
|
50 |
+
if ( !is_object( self::$instance ) )
|
51 |
+
self::$instance = new PodsComponents();
|
52 |
+
|
53 |
+
return self::$instance;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Setup actions and get options
|
58 |
+
*
|
59 |
+
* @return \PodsComponents
|
60 |
+
*
|
61 |
+
* @since 2.0
|
62 |
+
*/
|
63 |
+
public function __construct () {
|
64 |
+
$this->components_dir = realpath( apply_filters( 'pods_components_dir', PODS_DIR . 'components' ) ) . '/';
|
65 |
+
|
66 |
+
$settings = get_option( 'pods_component_settings', '' );
|
67 |
+
|
68 |
+
if ( !empty( $settings ) )
|
69 |
+
$this->settings = (array) json_decode( $settings, true );
|
70 |
+
|
71 |
+
if ( !isset( $this->settings[ 'components' ] ) )
|
72 |
+
$this->settings[ 'components' ] = array();
|
73 |
+
|
74 |
+
// Get components (give it access to theme)
|
75 |
+
add_action( 'setup_theme', array( $this, 'get_components' ), 11 );
|
76 |
+
|
77 |
+
// Load in components
|
78 |
+
add_action( 'setup_theme', array( $this, 'load' ), 12 );
|
79 |
+
|
80 |
+
// AJAX handling
|
81 |
+
if ( is_admin() ) {
|
82 |
+
add_action( 'wp_ajax_pods_admin_components', array( $this, 'admin_ajax' ) );
|
83 |
+
add_action( 'wp_ajax_nopriv_pods_admin_components', array( $this, 'admin_ajax' ) );
|
84 |
+
|
85 |
+
// Add the Pods Components capabilities
|
86 |
+
add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) );
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Add menu item
|
92 |
+
*
|
93 |
+
* @param string $parent The parent slug.
|
94 |
+
*
|
95 |
+
* @since 2.0
|
96 |
+
*
|
97 |
+
* @uses add_submenu_page
|
98 |
+
*/
|
99 |
+
public function menu ( $parent ) {
|
100 |
+
global $submenu;
|
101 |
+
|
102 |
+
$custom_component_menus = array();
|
103 |
+
|
104 |
+
$pods_component_menu_items = array();
|
105 |
+
|
106 |
+
foreach ( $this->components as $component => $component_data ) {
|
107 |
+
$component_data[ 'MustUse' ] = apply_filters( 'pods_component_require_' . $component_data[ 'ID' ], $component_data[ 'MustUse' ], $component_data );
|
108 |
+
|
109 |
+
if ( empty( $component_data[ 'MustUse' ] ) && ( !isset( $this->settings[ 'components' ][ $component ] ) || 0 == $this->settings[ 'components' ][ $component ] ) )
|
110 |
+
continue;
|
111 |
+
|
112 |
+
if ( !empty( $component_data[ 'Hide' ] ) )
|
113 |
+
continue;
|
114 |
+
|
115 |
+
if ( !empty( $component_data[ 'DeveloperMode' ] ) && !pods_developer() )
|
116 |
+
continue;
|
117 |
+
|
118 |
+
if ( empty( $component_data[ 'TablelessMode' ] ) && pods_tableless() )
|
119 |
+
continue;
|
120 |
+
|
121 |
+
if ( empty( $component_data[ 'MenuPage' ] ) ) {
|
122 |
+
if ( !isset( $component_data[ 'object' ] ) )
|
123 |
+
continue;
|
124 |
+
elseif ( !method_exists( $component_data[ 'object' ], 'admin' ) && !method_exists( $component_data[ 'object' ], 'options' ) )
|
125 |
+
continue;
|
126 |
+
}
|
127 |
+
|
128 |
+
if ( false === $component_data[ 'External' ] )
|
129 |
+
$component_data[ 'File' ] = realpath( $this->components_dir . $component_data[ 'File' ] );
|
130 |
+
|
131 |
+
if ( !file_exists( $component_data[ 'File' ] ) ) {
|
132 |
+
pods_message( 'Pods Component not found: ' . $component_data[ 'File' ] );
|
133 |
+
|
134 |
+
pods_transient_clear( 'pods_components' );
|
135 |
+
|
136 |
+
continue;
|
137 |
+
}
|
138 |
+
|
139 |
+
$capability = 'pods_component_' . str_replace( '-', '_', sanitize_title( $component ) );
|
140 |
+
|
141 |
+
if ( 0 < strlen( $component_data[ 'Capability' ] ) )
|
142 |
+
$capability = $component_data[ 'Capability' ];
|
143 |
+
|
144 |
+
if ( !pods_is_admin( array( 'pods', 'pods_components', $capability ) ) )
|
145 |
+
continue;
|
146 |
+
|
147 |
+
$menu_page = 'pods-component-' . $component;
|
148 |
+
|
149 |
+
if ( !empty( $component_data[ 'MenuPage' ] ) )
|
150 |
+
$custom_component_menus[ $menu_page ] = $component_data;
|
151 |
+
|
152 |
+
$pods_component_menu_items[ $component_data[ 'MenuName' ] ] = array(
|
153 |
+
'menu_page' => $menu_page,
|
154 |
+
'page_title' => $component_data[ 'Name' ],
|
155 |
+
'capability' => 'read',
|
156 |
+
'callback' => array( $this, 'admin_handler' )
|
157 |
+
);
|
158 |
+
|
159 |
+
if ( isset( $component_data[ 'object' ] ) && method_exists( $component_data[ 'object' ], 'admin_assets' ) ) {
|
160 |
+
$pods_component_menu_items[ $component_data[ 'MenuName' ] ][ 'assets' ] = array( $component_data[ 'object' ], 'admin_assets' );
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Add or change the items in the Pods Components Submenu.
|
166 |
+
*
|
167 |
+
* Can also be used to change which menu components is a submenu of or change title of menu.
|
168 |
+
*
|
169 |
+
* @params array $pods_component_menu_items {
|
170 |
+
* An array of arguments for add_submenu_page
|
171 |
+
*
|
172 |
+
* @param string $parent_slug The slug name for the parent menu (or the file name of a standard WordPress admin page)
|
173 |
+
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
|
174 |
+
* @param $menu_title The text to be used for the menu
|
175 |
+
* @param $capability The capability required for this menu to be displayed to the user.
|
176 |
+
* @param $menu_slug The slug name to refer to this menu by (should be unique for this menu)
|
177 |
+
* @param $function The function to be called to output the content for this page.
|
178 |
+
* }
|
179 |
+
*
|
180 |
+
* @returns array Array of submenu pages to be passed to add_submenu_page()
|
181 |
+
*
|
182 |
+
* @since 2.4.1
|
183 |
+
*/
|
184 |
+
$pods_component_menu_items = apply_filters( 'pods_admin_components_menu', $pods_component_menu_items );
|
185 |
+
|
186 |
+
ksort( $pods_component_menu_items );
|
187 |
+
|
188 |
+
foreach ( $pods_component_menu_items as $menu_title => $menu_data ) {
|
189 |
+
if ( !is_callable( $menu_data[ 'callback' ] ) ) {
|
190 |
+
continue;
|
191 |
+
}
|
192 |
+
|
193 |
+
$page = add_submenu_page(
|
194 |
+
$parent,
|
195 |
+
strip_tags( $menu_data[ 'page_title' ] ),
|
196 |
+
'- ' . strip_tags( $menu_title ),
|
197 |
+
pods_v( 'capability', $menu_data, 'read', true ),
|
198 |
+
$menu_data[ 'menu_page' ],
|
199 |
+
$menu_data[ 'callback' ]
|
200 |
+
);
|
201 |
+
|
202 |
+
if ( isset( $menu_data[ 'assets' ] ) && is_callable( $menu_data[ 'assets' ] ) ) {
|
203 |
+
add_action( 'admin_print_styles-' . $page, $menu_data[ 'assets' ] );
|
204 |
+
}
|
205 |
+
}
|
206 |
+
|
207 |
+
if ( !empty( $custom_component_menus ) ) {
|
208 |
+
foreach ( $custom_component_menus as $menu_page => $component_data ) {
|
209 |
+
if ( isset( $submenu[ $parent ] ) ) {
|
210 |
+
foreach ( $submenu[ $parent ] as $sub => &$menu ) {
|
211 |
+
if ( $menu[ 2 ] == $menu_page ) {
|
212 |
+
$menu_page = $component_data[ 'MenuPage' ];
|
213 |
+
|
214 |
+
/*if ( !empty( $component_data[ 'MenuAddPage' ] ) ) {
|
215 |
+
if ( false !== strpos( $_SERVER[ 'REQUEST_URI' ], $component_data[ 'MenuAddPage' ] ) )
|
216 |
+
$menu_page = $component_data[ 'MenuAddPage' ];
|
217 |
+
}*/
|
218 |
+
|
219 |
+
$menu[ 2 ] = $menu_page;
|
220 |
+
|
221 |
+
$page = current( explode( '?', $menu[ 2 ] ) );
|
222 |
+
|
223 |
+
if ( isset( $component_data[ 'object' ] ) && method_exists( $component_data[ 'object' ], 'admin_assets' ) )
|
224 |
+
add_action( 'admin_print_styles-' . $page, array( $component_data[ 'object' ], 'admin_assets' ) );
|
225 |
+
|
226 |
+
break;
|
227 |
+
}
|
228 |
+
}
|
229 |
+
}
|
230 |
+
}
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Load activated components and init component
|
236 |
+
*
|
237 |
+
* @since 2.0
|
238 |
+
*/
|
239 |
+
public function load () {
|
240 |
+
do_action( 'pods_components_load' );
|
241 |
+
|
242 |
+
foreach ( (array) $this->components as $component => $component_data ) {
|
243 |
+
$component_data[ 'MustUse' ] = apply_filters( 'pods_component_require_' . $component_data[ 'ID' ], $component_data[ 'MustUse' ], $component_data );
|
244 |
+
|
245 |
+
if ( false === $component_data[ 'MustUse' ] && ( !isset( $this->settings[ 'components' ][ $component ] ) || 0 == $this->settings[ 'components' ][ $component ] ) )
|
246 |
+
continue;
|
247 |
+
|
248 |
+
if ( !empty( $component_data[ 'PluginDependency' ] ) ) {
|
249 |
+
$dependency = explode( '|', $component_data[ 'PluginDependency' ] );
|
250 |
+
|
251 |
+
if ( !pods_is_plugin_active( $dependency[ 1 ] ) )
|
252 |
+
continue;
|
253 |
+
}
|
254 |
+
|
255 |
+
if ( !empty( $component_data[ 'ThemeDependency' ] ) ) {
|
256 |
+
$dependency = explode( '|', $component_data[ 'ThemeDependency' ] );
|
257 |
+
|
258 |
+
if ( strtolower( $dependency[ 1 ] ) != strtolower( get_template() ) && strtolower( $dependency[ 1 ] ) != strtolower( get_stylesheet() ) )
|
259 |
+
continue;
|
260 |
+
}
|
261 |
+
|
262 |
+
if ( false === $component_data[ 'External' ] )
|
263 |
+
$component_data[ 'File' ] = realpath( $this->components_dir . $component_data[ 'File' ] );
|
264 |
+
|
265 |
+
if ( empty( $component_data[ 'File' ] ) ) {
|
266 |
+
pods_transient_clear( 'pods_components' );
|
267 |
+
|
268 |
+
continue;
|
269 |
+
}
|
270 |
+
|
271 |
+
if ( !file_exists( $component_data[ 'File' ] ) ) {
|
272 |
+
pods_message( 'Pods Component not found: ' . $component_data[ 'File' ] );
|
273 |
+
|
274 |
+
pods_transient_clear( 'pods_components' );
|
275 |
+
|
276 |
+
continue;
|
277 |
+
}
|
278 |
+
|
279 |
+
include_once $component_data[ 'File' ];
|
280 |
+
|
281 |
+
if ( ( !empty( $component_data[ 'Class' ] ) && class_exists( $component_data[ 'Class' ] ) ) || isset( $component_data[ 'object' ] ) ) {
|
282 |
+
if ( !isset( $this->components[ $component ][ 'object' ] ) )
|
283 |
+
$this->components[ $component ][ 'object' ] = new $component_data[ 'Class' ];
|
284 |
+
|
285 |
+
if ( method_exists( $this->components[ $component ][ 'object' ], 'options' ) ) {
|
286 |
+
if ( isset( $this->settings[ 'components' ][ $component ] ) )
|
287 |
+
$this->components[ $component ][ 'options' ] = $this->components[ $component ][ 'object' ]->options( $this->settings[ 'components' ][ $component ] );
|
288 |
+
else
|
289 |
+
$this->components[ $component ][ 'options' ] = $this->components[ $component ][ 'object' ]->options( array() );
|
290 |
+
|
291 |
+
$this->options( $component, $this->components[ $component ][ 'options' ] );
|
292 |
+
}
|
293 |
+
else
|
294 |
+
$this->options( $component, array() );
|
295 |
+
|
296 |
+
if ( method_exists( $this->components[ $component ][ 'object' ], 'handler' ) )
|
297 |
+
$this->components[ $component ][ 'object' ]->handler( $this->settings[ 'components' ][ $component ] );
|
298 |
+
}
|
299 |
+
}
|
300 |
+
}
|
301 |
+
|
302 |
+
/**
|
303 |
+
* Get list of components available
|
304 |
+
*
|
305 |
+
* @since 2.0
|
306 |
+
*/
|
307 |
+
public function get_components () {
|
308 |
+
$components = pods_transient_get( 'pods_components' );
|
309 |
+
|
310 |
+
if ( 1 == pods_var( 'pods_debug_components', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
311 |
+
$components = array();
|
312 |
+
|
313 |
+
if ( PodsInit::$version != PODS_VERSION || !is_array( $components ) || empty( $components ) || ( is_admin() && isset( $_GET[ 'page' ] ) && 'pods-components' == $_GET[ 'page' ] && 1 !== pods_transient_get( 'pods_components_refresh' ) ) ) {
|
314 |
+
do_action( 'pods_components_get' );
|
315 |
+
|
316 |
+
$component_dir = @opendir( untrailingslashit( $this->components_dir ) );
|
317 |
+
$component_files = array();
|
318 |
+
|
319 |
+
if ( false !== $component_dir ) {
|
320 |
+
while ( false !== ( $file = readdir( $component_dir ) ) ) {
|
321 |
+
if ( '.' == substr( $file, 0, 1 ) )
|
322 |
+
continue;
|
323 |
+
elseif ( is_dir( $this->components_dir . $file ) ) {
|
324 |
+
$component_subdir = @opendir( $this->components_dir . $file );
|
325 |
+
|
326 |
+
if ( $component_subdir ) {
|
327 |
+
while ( false !== ( $subfile = readdir( $component_subdir ) ) ) {
|
328 |
+
if ( '.' == substr( $subfile, 0, 1 ) )
|
329 |
+
continue;
|
330 |
+
elseif ( '.php' == substr( $subfile, -4 ) )
|
331 |
+
$component_files[] = str_replace( '\\', '/', $file . '/' . $subfile );
|
332 |
+
}
|
333 |
+
|
334 |
+
closedir( $component_subdir );
|
335 |
+
}
|
336 |
+
}
|
337 |
+
elseif ( '.php' == substr( $file, -4 ) )
|
338 |
+
$component_files[] = $file;
|
339 |
+
}
|
340 |
+
|
341 |
+
closedir( $component_dir );
|
342 |
+
}
|
343 |
+
|
344 |
+
$default_headers = array(
|
345 |
+
'ID' => 'ID',
|
346 |
+
'Name' => 'Name',
|
347 |
+
'ShortName' => 'Short Name',
|
348 |
+
'PluginName' => 'Plugin Name',
|
349 |
+
'ComponentName' => 'Component Name',
|
350 |
+
'URI' => 'URI',
|
351 |
+
'MenuName' => 'Menu Name',
|
352 |
+
'MenuPage' => 'Menu Page',
|
353 |
+
'MenuAddPage' => 'Menu Add Page',
|
354 |
+
'MustUse' => 'Must Use',
|
355 |
+
'Description' => 'Description',
|
356 |
+
'Version' => 'Version',
|
357 |
+
'Category' => 'Category',
|
358 |
+
'Author' => 'Author',
|
359 |
+
'AuthorURI' => 'Author URI',
|
360 |
+
'Class' => 'Class',
|
361 |
+
'Hide' => 'Hide',
|
362 |
+
'PluginDependency' => 'Plugin Dependency',
|
363 |
+
'ThemeDependency' => 'Theme Dependency',
|
364 |
+
'DeveloperMode' => 'Developer Mode',
|
365 |
+
'TablelessMode' => 'Tableless Mode',
|
366 |
+
'Capability' => 'Capability',
|
367 |
+
'Plugin' => 'Plugin'
|
368 |
+
);
|
369 |
+
|
370 |
+
$component_files = apply_filters( 'pods_components_register', $component_files );
|
371 |
+
|
372 |
+
$components = array();
|
373 |
+
|
374 |
+
foreach ( $component_files as $component_file ) {
|
375 |
+
$external = false;
|
376 |
+
|
377 |
+
if ( is_array( $component_file ) && isset( $component_file[ 'File' ] ) ) {
|
378 |
+
$component = $component_file = $component_file[ 'File' ];
|
379 |
+
|
380 |
+
$external = true;
|
381 |
+
}
|
382 |
+
else
|
383 |
+
$component = $this->components_dir . $component_file;
|
384 |
+
|
385 |
+
if ( !is_readable( $component ) )
|
386 |
+
continue;
|
387 |
+
|
388 |
+
$component_data = get_file_data( $component, $default_headers, 'pods_component' );
|
389 |
+
|
390 |
+
if ( ( empty( $component_data[ 'Name' ] ) && empty( $component_data[ 'ComponentName' ] ) && empty( $component_data[ 'PluginName' ] ) ) || 'yes' == $component_data[ 'Hide' ] )
|
391 |
+
continue;
|
392 |
+
|
393 |
+
if ( isset( $component_data[ 'Plugin' ] ) && pods_is_plugin_active( $component_data[ 'Plugin' ] ) )
|
394 |
+
continue;
|
395 |
+
|
396 |
+
if ( empty( $component_data[ 'Name' ] ) ) {
|
397 |
+
if ( !empty( $component_data[ 'ComponentName' ] ) )
|
398 |
+
$component_data[ 'Name' ] = $component_data[ 'ComponentName' ];
|
399 |
+
elseif ( !empty( $component_data[ 'PluginName' ] ) )
|
400 |
+
$component_data[ 'Name' ] = $component_data[ 'PluginName' ];
|
401 |
+
}
|
402 |
+
|
403 |
+
if ( empty( $component_data[ 'ShortName' ] ) )
|
404 |
+
$component_data[ 'ShortName' ] = $component_data[ 'Name' ];
|
405 |
+
|
406 |
+
if ( empty( $component_data[ 'MenuName' ] ) )
|
407 |
+
$component_data[ 'MenuName' ] = $component_data[ 'Name' ];
|
408 |
+
|
409 |
+
if ( empty( $component_data[ 'Class' ] ) )
|
410 |
+
$component_data[ 'Class' ] = 'Pods_' . pods_clean_name( basename( $component, '.php' ), false );
|
411 |
+
|
412 |
+
if ( empty( $component_data[ 'ID' ] ) )
|
413 |
+
$component_data[ 'ID' ] = $component_data[ 'Name' ];
|
414 |
+
|
415 |
+
$component_data[ 'ID' ] = sanitize_title( $component_data[ 'ID' ] );
|
416 |
+
|
417 |
+
if ( 'on' == strtolower( $component_data[ 'DeveloperMode' ] ) || 1 == $component_data[ 'DeveloperMode' ] )
|
418 |
+
$component_data[ 'DeveloperMode' ] = true;
|
419 |
+
else
|
420 |
+
$component_data[ 'DeveloperMode' ] = false;
|
421 |
+
|
422 |
+
if ( 'on' == strtolower( $component_data[ 'TablelessMode' ] ) || 1 == $component_data[ 'TablelessMode' ] )
|
423 |
+
$component_data[ 'TablelessMode' ] = true;
|
424 |
+
else
|
425 |
+
$component_data[ 'TablelessMode' ] = false;
|
426 |
+
|
427 |
+
$component_data[ 'External' ] = (boolean) $external;
|
428 |
+
|
429 |
+
if ( 'on' == strtolower($component_data[ 'MustUse' ] ) || '1' == $component_data[ 'MustUse' ] )
|
430 |
+
$component_data[ 'MustUse' ] = true;
|
431 |
+
elseif ( 'off' == strtolower($component_data[ 'MustUse' ] ) || '0' == $component_data[ 'MustUse' ] )
|
432 |
+
$component_data[ 'MustUse' ] = false;
|
433 |
+
else
|
434 |
+
$component_data[ 'MustUse' ] = $component_data[ 'External' ];
|
435 |
+
|
436 |
+
$component_data[ 'File' ] = $component_file;
|
437 |
+
|
438 |
+
$components[ $component_data[ 'ID' ] ] = $component_data;
|
439 |
+
}
|
440 |
+
|
441 |
+
ksort( $components );
|
442 |
+
|
443 |
+
pods_transient_set( 'pods_components_refresh', 1, ( 60 * 60 * 12 ) );
|
444 |
+
|
445 |
+
pods_transient_set( 'pods_components', $components );
|
446 |
+
}
|
447 |
+
|
448 |
+
if ( 1 == pods_var( 'pods_debug_components', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
449 |
+
pods_debug( $components );
|
450 |
+
|
451 |
+
$this->components = $components;
|
452 |
+
|
453 |
+
return $this->components;
|
454 |
+
}
|
455 |
+
|
456 |
+
/**
|
457 |
+
* Set component options
|
458 |
+
*
|
459 |
+
* @param $component
|
460 |
+
* @param $options
|
461 |
+
*
|
462 |
+
* @since 2.0
|
463 |
+
*/
|
464 |
+
public function options ( $component, $options ) {
|
465 |
+
if ( !isset( $this->settings[ 'components' ][ $component ] ) || !is_array( $this->settings[ 'components' ][ $component ] ) )
|
466 |
+
$this->settings[ 'components' ][ $component ] = array();
|
467 |
+
|
468 |
+
foreach ( $options as $option => $data ) {
|
469 |
+
if ( !isset( $this->settings[ 'components' ][ $component ][ $option ] ) && isset( $data[ 'default' ] ) )
|
470 |
+
$this->settings[ 'components' ][ $component ][ $option ] = $data[ 'default' ];
|
471 |
+
}
|
472 |
+
}
|
473 |
+
|
474 |
+
/**
|
475 |
+
* Call component specific admin functions
|
476 |
+
*
|
477 |
+
* @since 2.0
|
478 |
+
*/
|
479 |
+
public function admin_handler () {
|
480 |
+
$component = str_replace( 'pods-component-', '', $_GET[ 'page' ] );
|
481 |
+
|
482 |
+
if ( isset( $this->components[ $component ] ) && isset( $this->components[ $component ][ 'object' ] ) && is_object( $this->components[ $component ][ 'object' ] ) ) {
|
483 |
+
// Component init
|
484 |
+
if ( method_exists( $this->components[ $component ][ 'object' ], 'init' ) )
|
485 |
+
$this->components[ $component ][ 'object' ]->init( $this->settings[ 'components' ][ $component ], $component );
|
486 |
+
|
487 |
+
// Component Admin handler
|
488 |
+
if ( method_exists( $this->components[ $component ][ 'object' ], 'admin' ) )
|
489 |
+
$this->components[ $component ][ 'object' ]->admin( $this->settings[ 'components' ][ $component ], $component );
|
490 |
+
// Built-in Admin Handler
|
491 |
+
elseif ( method_exists( $this->components[ $component ][ 'object' ], 'options' ) )
|
492 |
+
$this->admin( $this->components[ $component ][ 'object' ]->options( $this->settings[ 'components' ][ $component ] ), $this->settings[ 'components' ][ $component ], $component );
|
493 |
+
}
|
494 |
+
}
|
495 |
+
|
496 |
+
public function admin ( $options, $settings, $component ) {
|
497 |
+
if ( !isset( $this->components[ $component ] ) )
|
498 |
+
wp_die( 'Invalid Component' );
|
499 |
+
|
500 |
+
$component_label = $this->components[ $component ][ 'Name' ];
|
501 |
+
|
502 |
+
include PODS_DIR . 'ui/admin/components-admin.php';
|
503 |
+
}
|
504 |
+
|
505 |
+
/**
|
506 |
+
* Toggle a component on or off
|
507 |
+
*
|
508 |
+
* @param string $component The component name to toggle
|
509 |
+
*
|
510 |
+
* @return bool
|
511 |
+
*
|
512 |
+
* @since 2.0
|
513 |
+
*/
|
514 |
+
public function toggle ( $component ) {
|
515 |
+
$toggle = null;
|
516 |
+
|
517 |
+
if ( isset( $this->components[ $component ] ) ) {
|
518 |
+
if ( 1 == pods_var( 'toggle', 'get' ) && ( !isset( $this->settings[ 'components' ][ $component ] ) || 0 == $this->settings[ 'components' ][ $component ] ) ) {
|
519 |
+
$this->settings[ 'components' ][ $component ] = array();
|
520 |
+
$toggle = true;
|
521 |
+
}
|
522 |
+
elseif ( 0 == pods_var( 'toggle', 'get' ) ) {
|
523 |
+
$this->settings[ 'components' ][ $component ] = 0;
|
524 |
+
$toggle = false;
|
525 |
+
}
|
526 |
+
}
|
527 |
+
|
528 |
+
$settings = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $this->settings, JSON_UNESCAPED_UNICODE ) : json_encode( $this->settings );
|
529 |
+
|
530 |
+
update_option( 'pods_component_settings', $settings );
|
531 |
+
|
532 |
+
return $toggle;
|
533 |
+
}
|
534 |
+
|
535 |
+
/**
|
536 |
+
* Add pods specific capabilities.
|
537 |
+
*
|
538 |
+
* @param $capabilities List of extra capabilities to add
|
539 |
+
*
|
540 |
+
* @return array
|
541 |
+
*/
|
542 |
+
public function admin_capabilities ( $capabilities ) {
|
543 |
+
foreach ( $this->components as $component => $component_data ) {
|
544 |
+
if ( !empty( $component_data[ 'Hide' ] ) )
|
545 |
+
continue;
|
546 |
+
|
547 |
+
if ( true === (boolean) pods_var( 'DeveloperMode', $component_data, false ) && !pods_developer() )
|
548 |
+
continue;
|
549 |
+
|
550 |
+
if ( true === (boolean) pods_var( 'TablelessMode', $component_data, false ) && !pods_developer() )
|
551 |
+
continue;
|
552 |
+
|
553 |
+
if ( empty( $component_data[ 'MenuPage' ] ) && ( !isset( $component_data[ 'object' ] ) || !method_exists( $component_data[ 'object' ], 'admin' ) ) )
|
554 |
+
continue;
|
555 |
+
|
556 |
+
$capability = 'pods_component_' . str_replace( '-', '_', sanitize_title( str_replace( ' and ', ' ', strip_tags( $component_data[ 'Name' ] ) ) ) );
|
557 |
+
|
558 |
+
if ( 0 < strlen ( $component_data[ 'Capability' ] ) )
|
559 |
+
$capability = $component_data[ 'Capability' ];
|
560 |
+
|
561 |
+
if ( !in_array( $capability, $capabilities ) )
|
562 |
+
$capabilities[] = $capability;
|
563 |
+
}
|
564 |
+
|
565 |
+
return $capabilities;
|
566 |
+
}
|
567 |
+
|
568 |
+
/**
|
569 |
+
* Handle admin ajax
|
570 |
+
*
|
571 |
+
* @since 2.0
|
572 |
+
*/
|
573 |
+
public function admin_ajax () {
|
574 |
+
if ( false === headers_sent() ) {
|
575 |
+
pods_session_start();
|
576 |
+
|
577 |
+
header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
|
578 |
+
}
|
579 |
+
|
580 |
+
// Sanitize input
|
581 |
+
$params = pods_unslash( (array) $_POST );
|
582 |
+
|
583 |
+
foreach ( $params as $key => $value ) {
|
584 |
+
if ( 'action' == $key )
|
585 |
+
continue;
|
586 |
+
|
587 |
+
unset( $params[ $key ] );
|
588 |
+
|
589 |
+
$params[ str_replace( '_podsfix_', '', $key ) ] = $value;
|
590 |
+
}
|
591 |
+
|
592 |
+
$params = (object) $params;
|
593 |
+
|
594 |
+
$component = $params->component;
|
595 |
+
$method = $params->method;
|
596 |
+
|
597 |
+
if ( !isset( $component ) || !isset( $this->components[ $component ] ) || !isset( $this->settings[ 'components' ][ $component ] ) )
|
598 |
+
pods_error( 'Invalid AJAX request', $this );
|
599 |
+
|
600 |
+
if ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-component-' . $component . '-' . $method ) )
|
601 |
+
pods_error( 'Unauthorized request', $this );
|
602 |
+
|
603 |
+
// Cleaning up $params
|
604 |
+
unset( $params->action );
|
605 |
+
unset( $params->component );
|
606 |
+
unset( $params->method );
|
607 |
+
unset( $params->_wpnonce );
|
608 |
+
|
609 |
+
$params = (object) apply_filters( 'pods_component_ajax_' . $component . '_' . $method, $params, $component, $method );
|
610 |
+
|
611 |
+
$output = false;
|
612 |
+
|
613 |
+
// Component init
|
614 |
+
if ( isset( $this->components[ $component ][ 'object' ] ) && method_exists( $this->components[ $component ][ 'object' ], 'init' ) )
|
615 |
+
$this->components[ $component ][ 'object' ]->init( $this->settings[ 'components' ][ $component ], $component );
|
616 |
+
|
617 |
+
// Handle internal methods
|
618 |
+
if ( isset( $this->components[ $component ][ 'object' ] ) && !method_exists( $this->components[ $component ][ 'object' ], 'ajax_' . $method ) && method_exists( $this, 'admin_ajax_' . $method ) )
|
619 |
+
$output = call_user_func( array( $this, 'admin_ajax_' . $method ), $component, $params );
|
620 |
+
// Make sure method exists
|
621 |
+
elseif ( !isset( $this->components[ $component ][ 'object' ] ) || !method_exists( $this->components[ $component ][ 'object' ], 'ajax_' . $method ) )
|
622 |
+
pods_error( 'API method does not exist', $this );
|
623 |
+
// Dynamically call the component method
|
624 |
+
else
|
625 |
+
$output = call_user_func( array( $this->components[ $component ][ 'object' ], 'ajax_' . $method ), $params );
|
626 |
+
|
627 |
+
if ( !is_bool( $output ) )
|
628 |
+
echo $output;
|
629 |
+
|
630 |
+
die(); // KBAI!
|
631 |
+
}
|
632 |
+
|
633 |
+
public function admin_ajax_settings ( $component, $params ) {
|
634 |
+
if ( !isset( $this->components[ $component ] ) )
|
635 |
+
wp_die( 'Invalid Component' );
|
636 |
+
elseif ( !method_exists( $this->components[ $component ][ 'object' ], 'options' ) )
|
637 |
+
pods_error( 'Component options method does not exist', $this );
|
638 |
+
|
639 |
+
$options = $this->components[ $component ][ 'object' ]->options( $this->settings[ 'components' ][ $component ] );
|
640 |
+
|
641 |
+
if ( empty( $this->settings[ 'components' ][ $component ] ) )
|
642 |
+
$this->settings[ 'components' ][ $component ] = array();
|
643 |
+
|
644 |
+
foreach ( $options as $field_name => $field_option ) {
|
645 |
+
$field_option = PodsForm::field_setup( $field_option, null, $field_option[ 'type' ] );
|
646 |
+
|
647 |
+
if ( !is_array( $field_option[ 'group' ] ) ) {
|
648 |
+
$field_value = pods_var_raw( 'pods_setting_' . $field_name, $params );
|
649 |
+
|
650 |
+
$this->settings[ 'components' ][ $component ][ $field_name ] = $field_value;
|
651 |
+
}
|
652 |
+
else {
|
653 |
+
foreach ( $field_option[ 'group' ] as $field_group_name => $field_group_option ) {
|
654 |
+
$field_value = pods_var_raw( 'pods_setting_' . $field_group_name, $params );
|
655 |
+
|
656 |
+
$this->settings[ 'components' ][ $component ][ $field_group_name ] = $field_value;
|
657 |
+
}
|
658 |
+
}
|
659 |
+
}
|
660 |
+
|
661 |
+
$settings = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $this->settings, JSON_UNESCAPED_UNICODE ) : json_encode( $this->settings );
|
662 |
+
|
663 |
+
update_option( 'pods_component_settings', $settings );
|
664 |
+
|
665 |
+
return '1';
|
666 |
+
}
|
667 |
+
}
|
classes/PodsData.php
ADDED
@@ -0,0 +1,2988 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsData {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var PodsData
|
9 |
+
*/
|
10 |
+
static $instance = null;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var string
|
14 |
+
*/
|
15 |
+
static protected $prefix = 'pods_';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var array
|
19 |
+
*/
|
20 |
+
static protected $field_types = array();
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var bool
|
24 |
+
*/
|
25 |
+
public static $display_errors = true;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var PodsAPI
|
29 |
+
*/
|
30 |
+
public $api = null;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var null
|
34 |
+
*/
|
35 |
+
public $select = null;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @var null
|
39 |
+
*/
|
40 |
+
public $table = null;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @var null
|
44 |
+
*/
|
45 |
+
public $pod = null;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var array|bool|mixed|null|void
|
49 |
+
*/
|
50 |
+
public $pod_data = null;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @var int
|
54 |
+
*/
|
55 |
+
public $id = 0;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @var string
|
59 |
+
*/
|
60 |
+
public $field_id = 'id';
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @var string
|
64 |
+
*/
|
65 |
+
public $field_index = 'name';
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @var string
|
69 |
+
*/
|
70 |
+
public $field_slug = '';
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @var string
|
74 |
+
*/
|
75 |
+
public $join = '';
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @var array
|
79 |
+
*/
|
80 |
+
public $where = array();
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @var array
|
84 |
+
*/
|
85 |
+
public $where_default = array();
|
86 |
+
|
87 |
+
/**
|
88 |
+
* @var string
|
89 |
+
*/
|
90 |
+
public $orderby = '';
|
91 |
+
|
92 |
+
/**
|
93 |
+
* @var array
|
94 |
+
*/
|
95 |
+
public $fields = array();
|
96 |
+
|
97 |
+
/**
|
98 |
+
* @var array
|
99 |
+
*/
|
100 |
+
public $aliases = array();
|
101 |
+
|
102 |
+
/**
|
103 |
+
* @var
|
104 |
+
*/
|
105 |
+
public $detail_page;
|
106 |
+
|
107 |
+
// data
|
108 |
+
/**
|
109 |
+
* @var int
|
110 |
+
*/
|
111 |
+
public $row_number = -1;
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @var
|
115 |
+
*/
|
116 |
+
public $data;
|
117 |
+
|
118 |
+
/**
|
119 |
+
* @var
|
120 |
+
*/
|
121 |
+
public $row;
|
122 |
+
|
123 |
+
/**
|
124 |
+
* @var
|
125 |
+
*/
|
126 |
+
public $insert_id;
|
127 |
+
|
128 |
+
/**
|
129 |
+
* @var
|
130 |
+
*/
|
131 |
+
public $total;
|
132 |
+
|
133 |
+
/**
|
134 |
+
* @var
|
135 |
+
*/
|
136 |
+
public $total_found;
|
137 |
+
|
138 |
+
/**
|
139 |
+
* @var bool
|
140 |
+
*/
|
141 |
+
public $total_found_calculated;
|
142 |
+
|
143 |
+
// pagination
|
144 |
+
/**
|
145 |
+
* @var string
|
146 |
+
*/
|
147 |
+
public $page_var = 'pg';
|
148 |
+
|
149 |
+
/**
|
150 |
+
* @var int
|
151 |
+
*/
|
152 |
+
public $page = 1;
|
153 |
+
|
154 |
+
/**
|
155 |
+
* @var int
|
156 |
+
*/
|
157 |
+
public $limit = 15;
|
158 |
+
|
159 |
+
/**
|
160 |
+
* @var bool
|
161 |
+
*/
|
162 |
+
public $pagination = true;
|
163 |
+
|
164 |
+
// search
|
165 |
+
/**
|
166 |
+
* @var bool
|
167 |
+
*/
|
168 |
+
public $search = true;
|
169 |
+
|
170 |
+
/**
|
171 |
+
* @var string
|
172 |
+
*/
|
173 |
+
public $search_var = 'search';
|
174 |
+
|
175 |
+
/**
|
176 |
+
* @var string
|
177 |
+
*/
|
178 |
+
public $search_mode = 'int'; // int | text | text_like
|
179 |
+
/**
|
180 |
+
* @var string
|
181 |
+
*/
|
182 |
+
public $search_query = '';
|
183 |
+
|
184 |
+
/**
|
185 |
+
* @var array
|
186 |
+
*/
|
187 |
+
public $search_fields = array();
|
188 |
+
|
189 |
+
/**
|
190 |
+
* @var string
|
191 |
+
*/
|
192 |
+
public $search_where = array();
|
193 |
+
|
194 |
+
/**
|
195 |
+
* @var array
|
196 |
+
*/
|
197 |
+
public $filters = array();
|
198 |
+
|
199 |
+
/**
|
200 |
+
* Holds Traversal information about Pods
|
201 |
+
*
|
202 |
+
* @var array
|
203 |
+
*/
|
204 |
+
public $traversal = array();
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Holds custom Traversals to be included
|
208 |
+
*
|
209 |
+
* @var array
|
210 |
+
*/
|
211 |
+
public $traverse = array();
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Last select() query SQL
|
215 |
+
*
|
216 |
+
* @var string
|
217 |
+
*/
|
218 |
+
public $sql = false;
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Last total sql
|
222 |
+
*
|
223 |
+
* @var string
|
224 |
+
*/
|
225 |
+
public $total_sql = false;
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Singleton handling for a basic pods_data() request
|
229 |
+
*
|
230 |
+
* @param string $pod Pod name
|
231 |
+
* @param integer $id Pod Item ID
|
232 |
+
* @param bool $strict If true throws an error if a pod is not found.
|
233 |
+
*
|
234 |
+
* @return \PodsData
|
235 |
+
*
|
236 |
+
* @since 2.3.5
|
237 |
+
*/
|
238 |
+
public static function init ( $pod = null, $id = 0, $strict = true ) {
|
239 |
+
if ( ( true !== $pod && null !== $pod ) || 0 != $id )
|
240 |
+
return new PodsData( $pod, $id, $strict );
|
241 |
+
elseif ( !is_object( self::$instance ) )
|
242 |
+
self::$instance = new PodsData();
|
243 |
+
else {
|
244 |
+
$vars = get_class_vars( __CLASS__ );
|
245 |
+
|
246 |
+
foreach ( $vars as $var => $default ) {
|
247 |
+
if ( 'api' == $var )
|
248 |
+
continue;
|
249 |
+
|
250 |
+
self::$instance->{$var} = $default;
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
return self::$instance;
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Data Abstraction Class for Pods
|
259 |
+
*
|
260 |
+
* @param string $pod Pod name
|
261 |
+
* @param integer $id Pod Item ID
|
262 |
+
* @param bool $strict If true throws an error if a pod is not found.
|
263 |
+
*
|
264 |
+
* @return \PodsData
|
265 |
+
*
|
266 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
267 |
+
* @since 2.0
|
268 |
+
*/
|
269 |
+
public function __construct ( $pod = null, $id = 0, $strict = true ) {
|
270 |
+
global $wpdb;
|
271 |
+
|
272 |
+
if ( is_object( $pod ) && 'PodsAPI' == get_class( $pod ) ) {
|
273 |
+
$this->api = $pod;
|
274 |
+
$pod = $this->api->pod;
|
275 |
+
}
|
276 |
+
else
|
277 |
+
$this->api = pods_api( $pod );
|
278 |
+
|
279 |
+
$this->api->display_errors =& self::$display_errors;
|
280 |
+
|
281 |
+
if ( !empty( $pod ) ) {
|
282 |
+
$this->pod_data =& $this->api->pod_data;
|
283 |
+
|
284 |
+
if ( false === $this->pod_data ) {
|
285 |
+
if ( true === $strict )
|
286 |
+
return pods_error( 'Pod not found', $this );
|
287 |
+
else
|
288 |
+
return $this;
|
289 |
+
}
|
290 |
+
|
291 |
+
$this->pod_id = $this->pod_data[ 'id' ];
|
292 |
+
$this->pod = $this->pod_data[ 'name' ];
|
293 |
+
$this->fields = $this->pod_data[ 'fields' ];
|
294 |
+
|
295 |
+
if ( isset( $this->pod_data[ 'options' ][ 'detail_url' ] ) )
|
296 |
+
$this->detail_page = $this->pod_data[ 'options' ][ 'detail_url' ];
|
297 |
+
|
298 |
+
if ( isset( $this->pod_data[ 'select' ] ) )
|
299 |
+
$this->select = $this->pod_data[ 'select' ];
|
300 |
+
|
301 |
+
if ( isset( $this->pod_data[ 'table' ] ) )
|
302 |
+
$this->table = $this->pod_data[ 'table' ];
|
303 |
+
|
304 |
+
if ( isset( $this->pod_data[ 'join' ] ) )
|
305 |
+
$this->join = $this->pod_data[ 'join' ];
|
306 |
+
|
307 |
+
if ( isset( $this->pod_data[ 'field_id' ] ) )
|
308 |
+
$this->field_id = $this->pod_data[ 'field_id' ];
|
309 |
+
|
310 |
+
if ( isset( $this->pod_data[ 'field_index' ] ) )
|
311 |
+
$this->field_index = $this->pod_data[ 'field_index' ];
|
312 |
+
|
313 |
+
if ( isset( $this->pod_data[ 'field_slug' ] ) )
|
314 |
+
$this->field_slug = $this->pod_data[ 'field_slug' ];
|
315 |
+
|
316 |
+
if ( isset( $this->pod_data[ 'where' ] ) )
|
317 |
+
$this->where = $this->pod_data[ 'where' ];
|
318 |
+
|
319 |
+
if ( isset( $this->pod_data[ 'where_default' ] ) )
|
320 |
+
$this->where_default = $this->pod_data[ 'where_default' ];
|
321 |
+
|
322 |
+
if ( isset( $this->pod_data[ 'orderby' ] ) )
|
323 |
+
$this->orderby = $this->pod_data[ 'orderby' ];
|
324 |
+
|
325 |
+
if ( 'settings' == $this->pod_data[ 'type' ] ) {
|
326 |
+
$this->id = $this->pod_data[ 'id' ];
|
327 |
+
|
328 |
+
$this->fetch( $this->id );
|
329 |
+
}
|
330 |
+
elseif ( null !== $id && !is_array( $id ) && !is_object( $id ) ) {
|
331 |
+
$this->id = $id;
|
332 |
+
|
333 |
+
$this->fetch( $this->id );
|
334 |
+
}
|
335 |
+
}
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* Handle tables like they are Pods (for traversal in select/build)
|
340 |
+
*
|
341 |
+
* @param array|string $table
|
342 |
+
* @param string $object
|
343 |
+
*/
|
344 |
+
public function table ( $table, $object = '' ) {
|
345 |
+
global $wpdb;
|
346 |
+
|
347 |
+
if ( !is_array( $table ) ) {
|
348 |
+
$object_type = '';
|
349 |
+
|
350 |
+
if ( $wpdb->users == $table )
|
351 |
+
$object_type = 'user';
|
352 |
+
elseif ( $wpdb->posts == $table )
|
353 |
+
$object_type = 'post_type';
|
354 |
+
elseif ( $wpdb->terms == $table )
|
355 |
+
$object_type = 'taxonomy';
|
356 |
+
elseif ( $wpdb->options == $table )
|
357 |
+
$object_type = 'settings';
|
358 |
+
}
|
359 |
+
|
360 |
+
if ( !empty( $object_type ) )
|
361 |
+
$table = $this->api->get_table_info( $object_type, $object );
|
362 |
+
|
363 |
+
if ( !empty( $table ) && is_array( $table ) ) {
|
364 |
+
$table[ 'id' ] = pods_var( 'id', $table[ 'pod' ], 0, null, true );
|
365 |
+
$table[ 'name' ] = pods_var( 'name', $table[ 'pod' ], $table[ 'object_type' ], null, true );
|
366 |
+
$table[ 'type' ] = pods_var_raw( 'type', $table[ 'pod' ], $table[ 'object_type' ], null, true );
|
367 |
+
$table[ 'storage' ] = pods_var_raw( 'storage', $table[ 'pod' ], ( 'taxonomy' == $table[ 'object_type' ] ? 'none' : 'meta' ), null, true );
|
368 |
+
$table[ 'fields' ] = pods_var_raw( 'fields', $table[ 'pod' ], array() );
|
369 |
+
$table[ 'object_fields' ] = pods_var_raw( 'object_fields', $table[ 'pod' ], $this->api->get_wp_object_fields( $table[ 'object_type' ] ), null, true );
|
370 |
+
|
371 |
+
$this->pod_data = $table;
|
372 |
+
$this->pod_id = $this->pod_data[ 'id' ];
|
373 |
+
$this->pod = $this->pod_data[ 'name' ];
|
374 |
+
$this->fields = $this->pod_data[ 'fields' ];
|
375 |
+
|
376 |
+
if ( isset( $this->pod_data[ 'select' ] ) )
|
377 |
+
$this->select = $this->pod_data[ 'select' ];
|
378 |
+
|
379 |
+
if ( isset( $this->pod_data[ 'table' ] ) )
|
380 |
+
$this->table = $this->pod_data[ 'table' ];
|
381 |
+
|
382 |
+
if ( isset( $this->pod_data[ 'join' ] ) )
|
383 |
+
$this->join = $this->pod_data[ 'join' ];
|
384 |
+
|
385 |
+
if ( isset( $this->pod_data[ 'field_id' ] ) )
|
386 |
+
$this->field_id = $this->pod_data[ 'field_id' ];
|
387 |
+
|
388 |
+
if ( isset( $this->pod_data[ 'field_index' ] ) )
|
389 |
+
$this->field_index = $this->pod_data[ 'field_index' ];
|
390 |
+
|
391 |
+
if ( isset( $this->pod_data[ 'field_slug' ] ) )
|
392 |
+
$this->field_slug = $this->pod_data[ 'field_slug' ];
|
393 |
+
|
394 |
+
if ( isset( $this->pod_data[ 'where' ] ) )
|
395 |
+
$this->where = $this->pod_data[ 'where' ];
|
396 |
+
|
397 |
+
if ( isset( $this->pod_data[ 'where_default' ] ) )
|
398 |
+
$this->where_default = $this->pod_data[ 'where_default' ];
|
399 |
+
|
400 |
+
if ( isset( $this->pod_data[ 'orderby' ] ) )
|
401 |
+
$this->orderby = $this->pod_data[ 'orderby' ];
|
402 |
+
}
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Insert an item, eventually mapping to WPDB::insert
|
407 |
+
*
|
408 |
+
* @param string $table Table name
|
409 |
+
* @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
|
410 |
+
* @param array $format (optional) An array of formats to be mapped to each of the value in $data.
|
411 |
+
*
|
412 |
+
* @return int|bool The ID of the item
|
413 |
+
*
|
414 |
+
* @uses wpdb::insert
|
415 |
+
*
|
416 |
+
* @since 2.0
|
417 |
+
*/
|
418 |
+
public function insert ( $table, $data, $format = null ) {
|
419 |
+
/**
|
420 |
+
* @var $wpdb wpdb
|
421 |
+
*/
|
422 |
+
global $wpdb;
|
423 |
+
|
424 |
+
if ( strlen( $table ) < 1 || empty( $data ) || !is_array( $data ) )
|
425 |
+
return false;
|
426 |
+
|
427 |
+
if ( empty( $format ) ) {
|
428 |
+
$format = array();
|
429 |
+
|
430 |
+
foreach ( $data as $field ) {
|
431 |
+
if ( isset( self::$field_types[ $field ] ) )
|
432 |
+
$format[] = self::$field_types[ $field ];
|
433 |
+
elseif ( isset( $wpdb->field_types[ $field ] ) )
|
434 |
+
$format[] = $wpdb->field_types[ $field ];
|
435 |
+
else
|
436 |
+
break;
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
list( $table, $data, $format ) = $this->do_hook( 'insert', array( $table, $data, $format ) );
|
441 |
+
|
442 |
+
$result = $wpdb->insert( $table, $data, $format );
|
443 |
+
$this->insert_id = $wpdb->insert_id;
|
444 |
+
|
445 |
+
if ( false !== $result )
|
446 |
+
return $this->insert_id;
|
447 |
+
|
448 |
+
return false;
|
449 |
+
}
|
450 |
+
|
451 |
+
/**
|
452 |
+
* @static
|
453 |
+
*
|
454 |
+
* Insert into a table, if unique key exists just update values.
|
455 |
+
*
|
456 |
+
* Data must be a key value pair array, keys act as table rows.
|
457 |
+
*
|
458 |
+
* Returns the prepared query from wpdb or false for errors
|
459 |
+
*
|
460 |
+
* @param string $table Name of the table to update
|
461 |
+
* @param array $data column => value pairs
|
462 |
+
* @param array $formats For $wpdb->prepare, uses sprintf formatting
|
463 |
+
*
|
464 |
+
* @return mixed Sanitized query string
|
465 |
+
*
|
466 |
+
* @uses wpdb::prepare
|
467 |
+
*
|
468 |
+
* @since 2.0
|
469 |
+
*/
|
470 |
+
public static function insert_on_duplicate ( $table, $data, $formats = array() ) {
|
471 |
+
/**
|
472 |
+
* @var $wpdb wpdb
|
473 |
+
*/
|
474 |
+
global $wpdb;
|
475 |
+
|
476 |
+
$columns = array_keys( $data );
|
477 |
+
|
478 |
+
$update = array();
|
479 |
+
$values = array();
|
480 |
+
|
481 |
+
foreach ( $columns as $column ) {
|
482 |
+
$update[] = "`{$column}` = VALUES( `{$column}` )";
|
483 |
+
$values[] = "%s";
|
484 |
+
}
|
485 |
+
|
486 |
+
if ( empty( $formats ) )
|
487 |
+
$formats = $values;
|
488 |
+
|
489 |
+
$columns_data = implode( '`, `', $columns );
|
490 |
+
$formats = implode( ", ", $formats );
|
491 |
+
$update = implode( ', ', $update );
|
492 |
+
|
493 |
+
$sql = "INSERT INTO `{$table}` ( `{$columns_data}` ) VALUES ( {$formats} ) ON DUPLICATE KEY UPDATE {$update}";
|
494 |
+
|
495 |
+
return $wpdb->prepare( $sql, $data );
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* Update an item, eventually mapping to WPDB::update
|
500 |
+
*
|
501 |
+
* @param string $table Table name
|
502 |
+
* @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
|
503 |
+
* @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
|
504 |
+
* @param array $format (optional) An array of formats to be mapped to each of the values in $data.
|
505 |
+
* @param array $where_format (optional) An array of formats to be mapped to each of the values in $where.
|
506 |
+
*
|
507 |
+
* @return bool
|
508 |
+
* @since 2.0
|
509 |
+
*/
|
510 |
+
public function update ( $table, $data, $where, $format = null, $where_format = null ) {
|
511 |
+
/**
|
512 |
+
* @var $wpdb wpdb
|
513 |
+
*/
|
514 |
+
global $wpdb;
|
515 |
+
|
516 |
+
if ( strlen( $table ) < 1 || empty( $data ) || !is_array( $data ) )
|
517 |
+
return false;
|
518 |
+
|
519 |
+
if ( empty( $format ) ) {
|
520 |
+
$format = array();
|
521 |
+
|
522 |
+
foreach ( $data as $field ) {
|
523 |
+
if ( isset( self::$field_types[ $field ] ) )
|
524 |
+
$form = self::$field_types[ $field ];
|
525 |
+
elseif ( isset( $wpdb->field_types[ $field ] ) )
|
526 |
+
$form = $wpdb->field_types[ $field ];
|
527 |
+
else
|
528 |
+
$form = '%s';
|
529 |
+
|
530 |
+
$format[] = $form;
|
531 |
+
}
|
532 |
+
}
|
533 |
+
|
534 |
+
if ( empty( $where_format ) ) {
|
535 |
+
$where_format = array();
|
536 |
+
|
537 |
+
foreach ( (array) array_keys( $where ) as $field ) {
|
538 |
+
if ( isset( self::$field_types[ $field ] ) )
|
539 |
+
$form = self::$field_types[ $field ];
|
540 |
+
elseif ( isset( $wpdb->field_types[ $field ] ) )
|
541 |
+
$form = $wpdb->field_types[ $field ];
|
542 |
+
else
|
543 |
+
$form = '%s';
|
544 |
+
|
545 |
+
$where_format[] = $form;
|
546 |
+
}
|
547 |
+
}
|
548 |
+
|
549 |
+
list( $table, $data, $where, $format, $where_format ) = $this->do_hook( 'update', array(
|
550 |
+
$table,
|
551 |
+
$data,
|
552 |
+
$where,
|
553 |
+
$format,
|
554 |
+
$where_format
|
555 |
+
) );
|
556 |
+
|
557 |
+
$result = $wpdb->update( $table, $data, $where, $format, $where_format );
|
558 |
+
|
559 |
+
if ( false !== $result )
|
560 |
+
return true;
|
561 |
+
|
562 |
+
return false;
|
563 |
+
}
|
564 |
+
|
565 |
+
/**
|
566 |
+
* Delete an item
|
567 |
+
*
|
568 |
+
* @param string $table Table name
|
569 |
+
* @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
|
570 |
+
* @param array $where_format (optional) An array of formats to be mapped to each of the values in $where.
|
571 |
+
*
|
572 |
+
* @return array|bool|mixed|null|void
|
573 |
+
*
|
574 |
+
* @uses PodsData::query
|
575 |
+
* @uses PodsData::prepare
|
576 |
+
*
|
577 |
+
* @since 2.0
|
578 |
+
*/
|
579 |
+
public function delete ( $table, $where, $where_format = null ) {
|
580 |
+
/**
|
581 |
+
* @var $wpdb wpdb
|
582 |
+
*/
|
583 |
+
global $wpdb;
|
584 |
+
|
585 |
+
if ( strlen( $table ) < 1 || empty( $where ) || !is_array( $where ) )
|
586 |
+
return false;
|
587 |
+
|
588 |
+
$wheres = array();
|
589 |
+
$where_formats = $where_format = (array) $where_format;
|
590 |
+
|
591 |
+
foreach ( (array) array_keys( $where ) as $field ) {
|
592 |
+
if ( !empty( $where_format ) )
|
593 |
+
$form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[ 0 ];
|
594 |
+
elseif ( isset( self::$field_types[ $field ] ) )
|
595 |
+
$form = self::$field_types[ $field ];
|
596 |
+
elseif ( isset( $wpdb->field_types[ $field ] ) )
|
597 |
+
$form = $wpdb->field_types[ $field ];
|
598 |
+
else
|
599 |
+
$form = '%s';
|
600 |
+
|
601 |
+
$wheres[] = "`{$field}` = {$form}";
|
602 |
+
}
|
603 |
+
|
604 |
+
$sql = "DELETE FROM `$table` WHERE " . implode( ' AND ', $wheres );
|
605 |
+
|
606 |
+
list( $sql, $where ) = $this->do_hook( 'delete', array(
|
607 |
+
$sql,
|
608 |
+
array_values( $where )
|
609 |
+
), $table, $where, $where_format, $wheres );
|
610 |
+
|
611 |
+
return $this->query( self::prepare( $sql, $where ) );
|
612 |
+
}
|
613 |
+
|
614 |
+
/**
|
615 |
+
* Select items, eventually building dynamic query
|
616 |
+
*
|
617 |
+
* @param array $params
|
618 |
+
*
|
619 |
+
* @return array|bool|mixed
|
620 |
+
* @since 2.0
|
621 |
+
*/
|
622 |
+
public function select ( $params ) {
|
623 |
+
global $wpdb;
|
624 |
+
|
625 |
+
$cache_key = $results = false;
|
626 |
+
|
627 |
+
// Debug purposes
|
628 |
+
if ( 1 == pods_var( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
629 |
+
pods_debug( $params );
|
630 |
+
|
631 |
+
// Get from cache if enabled
|
632 |
+
if ( null !== pods_var( 'expires', $params, null, null, true ) ) {
|
633 |
+
$cache_key = md5( serialize( get_object_vars( $params ) ) );
|
634 |
+
|
635 |
+
$results = pods_view_get( $cache_key, pods_var( 'cache_mode', $params, 'cache', null, true ), 'pods_data_select' );
|
636 |
+
|
637 |
+
if ( empty( $results ) )
|
638 |
+
$results = false;
|
639 |
+
}
|
640 |
+
|
641 |
+
if ( empty( $results ) ) {
|
642 |
+
// Build
|
643 |
+
$this->sql = $this->build( $params );
|
644 |
+
|
645 |
+
// Debug purposes
|
646 |
+
if ( ( 1 == pods_var( 'pods_debug_sql', 'get', 0 ) || 1 == pods_var( 'pods_debug_sql_all', 'get', 0 ) ) && pods_is_admin( array( 'pods' ) ) )
|
647 |
+
echo '<textarea cols="100" rows="24">' . str_replace( array( '@wp_users', '@wp_' ), array( $wpdb->users, $wpdb->prefix ), $this->sql ) . '</textarea>';
|
648 |
+
|
649 |
+
if ( empty( $this->sql ) )
|
650 |
+
return array();
|
651 |
+
|
652 |
+
// Get Data
|
653 |
+
$results = pods_query( $this->sql, $this );
|
654 |
+
|
655 |
+
// Cache if enabled
|
656 |
+
if ( false !== $cache_key )
|
657 |
+
pods_view_set( $cache_key, $results, pods_var( 'expires', $params, 0, null, true ), pods_var( 'cache_mode', $params, 'cache', null, true ), 'pods_data_select' );
|
658 |
+
}
|
659 |
+
|
660 |
+
$results = $this->do_hook( 'select', $results );
|
661 |
+
|
662 |
+
$this->data = $results;
|
663 |
+
|
664 |
+
$this->row_number = -1;
|
665 |
+
|
666 |
+
// Fill in empty field data (if none provided)
|
667 |
+
if ( ( !isset( $this->fields ) || empty( $this->fields ) ) && !empty( $this->data ) ) {
|
668 |
+
$this->fields = array();
|
669 |
+
$data = (array) @current( $this->data );
|
670 |
+
|
671 |
+
foreach ( $data as $data_key => $data_value ) {
|
672 |
+
$this->fields[ $data_key ] = array( 'label' => ucwords( str_replace( '-', ' ', str_replace( '_', ' ', $data_key ) ) ) );
|
673 |
+
}
|
674 |
+
|
675 |
+
$this->fields = PodsForm::fields_setup( $this->fields );
|
676 |
+
}
|
677 |
+
$this->total_found_calculated = false;
|
678 |
+
|
679 |
+
$this->total = count( (array) $this->data );
|
680 |
+
|
681 |
+
return $this->data;
|
682 |
+
}
|
683 |
+
|
684 |
+
public function calculate_totals () {
|
685 |
+
/**
|
686 |
+
* @var $wpdb wpdb
|
687 |
+
*/
|
688 |
+
global $wpdb;
|
689 |
+
|
690 |
+
// Set totals
|
691 |
+
if ( false !== $this->total_sql )
|
692 |
+
$total = @current( $wpdb->get_col( $this->get_sql( $this->total_sql ) ) );
|
693 |
+
else
|
694 |
+
$total = @current( $wpdb->get_col( "SELECT FOUND_ROWS()" ) );
|
695 |
+
|
696 |
+
$total = $this->do_hook( 'select_total', $total );
|
697 |
+
$this->total_found = 0;
|
698 |
+
$this->total_found_calculated = true;
|
699 |
+
|
700 |
+
if ( is_numeric( $total ) )
|
701 |
+
$this->total_found = $total;
|
702 |
+
}
|
703 |
+
|
704 |
+
/**
|
705 |
+
* Build/Rewrite dynamic SQL and handle search/filter/sort
|
706 |
+
*
|
707 |
+
* @param array $params
|
708 |
+
*
|
709 |
+
* @return bool|mixed|string
|
710 |
+
* @since 2.0
|
711 |
+
*/
|
712 |
+
public function build ( $params ) {
|
713 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
714 |
+
|
715 |
+
$defaults = array(
|
716 |
+
'select' => '*',
|
717 |
+
'calc_rows' => false,
|
718 |
+
'distinct' => true,
|
719 |
+
'table' => null,
|
720 |
+
'join' => null,
|
721 |
+
'where' => null,
|
722 |
+
'groupby' => null,
|
723 |
+
'having' => null,
|
724 |
+
'orderby' => null,
|
725 |
+
'limit' => -1,
|
726 |
+
'offset' => null,
|
727 |
+
|
728 |
+
'id' => null,
|
729 |
+
'index' => null,
|
730 |
+
|
731 |
+
'page' => 1,
|
732 |
+
'pagination' => $this->pagination,
|
733 |
+
'search' => $this->search,
|
734 |
+
'search_query' => null,
|
735 |
+
'search_mode' => null,
|
736 |
+
'search_across' => false,
|
737 |
+
'search_across_picks' => false,
|
738 |
+
'search_across_files' => false,
|
739 |
+
'filters' => array(),
|
740 |
+
|
741 |
+
'fields' => array(),
|
742 |
+
'object_fields' => array(),
|
743 |
+
'pod_table_prefix' => null,
|
744 |
+
|
745 |
+
'traverse' => array(),
|
746 |
+
|
747 |
+
'sql' => null,
|
748 |
+
|
749 |
+
'strict' => false
|
750 |
+
);
|
751 |
+
|
752 |
+
$params = (object) array_merge( $defaults, (array) $params );
|
753 |
+
|
754 |
+
if ( 0 < strlen( $params->sql ) )
|
755 |
+
return $params->sql;
|
756 |
+
|
757 |
+
$pod = false;
|
758 |
+
|
759 |
+
if ( is_array( $this->pod_data ) ) {
|
760 |
+
$pod = $this->pod_data;
|
761 |
+
}
|
762 |
+
|
763 |
+
// Validate
|
764 |
+
$params->page = pods_absint( $params->page );
|
765 |
+
|
766 |
+
$params->pagination = (boolean) $params->pagination;
|
767 |
+
|
768 |
+
if ( 0 == $params->page || !$params->pagination )
|
769 |
+
$params->page = 1;
|
770 |
+
|
771 |
+
$params->limit = (int) $params->limit;
|
772 |
+
|
773 |
+
if ( 0 == $params->limit )
|
774 |
+
$params->limit = -1;
|
775 |
+
|
776 |
+
$this->limit = $params->limit;
|
777 |
+
|
778 |
+
$offset = ( $params->limit * ( $params->page - 1 ) );
|
779 |
+
|
780 |
+
if ( 0 < (int) $params->offset )
|
781 |
+
$params->offset += $offset;
|
782 |
+
else
|
783 |
+
$params->offset = $offset;
|
784 |
+
|
785 |
+
if ( !$params->pagination || -1 == $params->limit ) {
|
786 |
+
$params->page = 1;
|
787 |
+
$params->offset = 0;
|
788 |
+
}
|
789 |
+
|
790 |
+
if ( ( empty( $params->fields ) || !is_array( $params->fields ) ) && !empty( $pod ) && isset( $this->fields ) && !empty( $this->fields ) )
|
791 |
+
$params->fields = $this->fields;
|
792 |
+
|
793 |
+
if ( ( empty( $params->object_fields ) || !is_array( $params->object_fields ) ) && !empty( $pod ) && isset( $pod[ 'object_fields' ] ) && !empty( $pod[ 'object_fields' ] ) )
|
794 |
+
$params->object_fields = $pod[ 'object_fields' ];
|
795 |
+
|
796 |
+
if ( empty( $params->filters ) && $params->search )
|
797 |
+
$params->filters = array_keys( $params->fields );
|
798 |
+
elseif ( empty( $params->filters ) )
|
799 |
+
$params->filters = array();
|
800 |
+
|
801 |
+
if ( empty( $params->index ) )
|
802 |
+
$params->index = $this->field_index;
|
803 |
+
|
804 |
+
if ( empty( $params->id ) )
|
805 |
+
$params->id = $this->field_id;
|
806 |
+
|
807 |
+
if ( empty( $params->table ) && !empty( $pod ) && isset( $this->table ) && !empty( $this->table ) )
|
808 |
+
$params->table = $this->table;
|
809 |
+
|
810 |
+
if ( empty( $params->pod_table_prefix ) )
|
811 |
+
$params->pod_table_prefix = 't';
|
812 |
+
|
813 |
+
if ( !empty( $pod ) && !in_array( $pod[ 'type' ], array( 'pod', 'table' ) ) && 'table' == $pod[ 'storage' ] )
|
814 |
+
$params->pod_table_prefix = 'd';
|
815 |
+
|
816 |
+
$params->meta_fields = false;
|
817 |
+
|
818 |
+
if ( !empty( $pod ) && !in_array( $pod[ 'type' ], array( 'pod', 'table', 'taxonomy' ) ) && 'meta' == $pod[ 'storage' ] )
|
819 |
+
$params->meta_fields = true;
|
820 |
+
|
821 |
+
if ( empty( $params->table ) )
|
822 |
+
return false;
|
823 |
+
|
824 |
+
if ( false === strpos( $params->table, '(' ) && false === strpos( $params->table, '`' ) )
|
825 |
+
$params->table = '`' . $params->table . '`';
|
826 |
+
|
827 |
+
if ( !empty( $params->join ) )
|
828 |
+
$params->join = array_merge( (array) $this->join, (array) $params->join );
|
829 |
+
elseif ( false === $params->strict )
|
830 |
+
$params->join = $this->join;
|
831 |
+
|
832 |
+
$params->where_defaulted = false;
|
833 |
+
$params->where_default = $this->where_default;
|
834 |
+
|
835 |
+
if ( false === $params->strict ) {
|
836 |
+
// Set default where
|
837 |
+
if ( !empty( $this->where_default ) && empty( $params->where ) ) {
|
838 |
+
$params->where = array_values( (array) $this->where_default );
|
839 |
+
|
840 |
+
$params->where_defaulted = true;
|
841 |
+
}
|
842 |
+
|
843 |
+
if ( !empty( $this->where ) ) {
|
844 |
+
if ( is_array( $params->where ) && isset( $params->where[ 'relation' ] ) && 'OR' == strtoupper( $params->where[ 'relation' ] ) ) {
|
845 |
+
$params->where = array_merge( array( $params->where ), array_values( (array) $this->where ) );
|
846 |
+
}
|
847 |
+
else {
|
848 |
+
$params->where = array_merge( (array) $params->where, array_values( (array) $this->where ) );
|
849 |
+
}
|
850 |
+
}
|
851 |
+
}
|
852 |
+
|
853 |
+
// Allow where array ( 'field' => 'value' ) and WP_Query meta_query syntax
|
854 |
+
$params->where = $this->query_fields( (array) $params->where, $pod, $params );
|
855 |
+
|
856 |
+
if ( empty( $params->where ) ) {
|
857 |
+
$params->where = array();
|
858 |
+
}
|
859 |
+
else {
|
860 |
+
$params->where = (array) $params->where;
|
861 |
+
}
|
862 |
+
|
863 |
+
// Allow having array ( 'field' => 'value' ) and WP_Query meta_query syntax
|
864 |
+
$params->having = $this->query_fields( (array) $params->having, $pod );
|
865 |
+
|
866 |
+
if ( empty( $params->having ) )
|
867 |
+
$params->having = array();
|
868 |
+
else
|
869 |
+
$params->having = (array) $params->having;
|
870 |
+
|
871 |
+
if ( !empty( $params->orderby ) )
|
872 |
+
$params->orderby = (array) $params->orderby;
|
873 |
+
else
|
874 |
+
$params->orderby = array();
|
875 |
+
|
876 |
+
if ( false === $params->strict && !empty( $this->orderby ) )
|
877 |
+
$params->orderby = array_merge( $params->orderby, (array) $this->orderby );
|
878 |
+
|
879 |
+
if ( !empty( $params->traverse ) )
|
880 |
+
$this->traverse = $params->traverse;
|
881 |
+
|
882 |
+
$allowed_search_modes = array( 'int', 'text', 'text_like' );
|
883 |
+
|
884 |
+
if ( !empty( $params->search_mode ) && in_array( $params->search_mode, $allowed_search_modes ) )
|
885 |
+
$this->search_mode = $params->search_mode;
|
886 |
+
|
887 |
+
$params->search = (boolean) $params->search;
|
888 |
+
|
889 |
+
if ( 1 == pods_var( 'pods_debug_params_all', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
890 |
+
pods_debug( $params );
|
891 |
+
|
892 |
+
$params->field_table_alias = 't';
|
893 |
+
|
894 |
+
// Get Aliases for future reference
|
895 |
+
$selectsfound = '';
|
896 |
+
|
897 |
+
if ( !empty( $params->select ) ) {
|
898 |
+
if ( is_array( $params->select ) )
|
899 |
+
$selectsfound = implode( ', ', $params->select );
|
900 |
+
else
|
901 |
+
$selectsfound = $params->select;
|
902 |
+
}
|
903 |
+
|
904 |
+
// Pull Aliases from SQL query too
|
905 |
+
if ( null !== $params->sql ) {
|
906 |
+
$temp_sql = ' ' . trim( str_replace( array( "\n", "\r" ), ' ', $params->sql ) );
|
907 |
+
$temp_sql = preg_replace( array(
|
908 |
+
'/\sSELECT\sSQL_CALC_FOUND_ROWS\s/i',
|
909 |
+
'/\sSELECT\s/i'
|
910 |
+
),
|
911 |
+
array(
|
912 |
+
' SELECT ',
|
913 |
+
' SELECT SQL_CALC_FOUND_ROWS '
|
914 |
+
),
|
915 |
+
$temp_sql );
|
916 |
+
preg_match( '/\sSELECT SQL_CALC_FOUND_ROWS\s(.*)\sFROM/i', $temp_sql, $selectmatches );
|
917 |
+
if ( isset( $selectmatches[ 1 ] ) && !empty( $selectmatches[ 1 ] ) && false !== stripos( $selectmatches[ 1 ], ' AS ' ) )
|
918 |
+
$selectsfound .= ( !empty( $selectsfound ) ? ', ' : '' ) . $selectmatches[ 1 ];
|
919 |
+
}
|
920 |
+
|
921 |
+
// Build Alias list
|
922 |
+
$this->aliases = array();
|
923 |
+
|
924 |
+
if ( !empty( $selectsfound ) && false !== stripos( $selectsfound, ' AS ' ) ) {
|
925 |
+
$theselects = array_filter( explode( ', ', $selectsfound ) );
|
926 |
+
|
927 |
+
if ( empty( $theselects ) )
|
928 |
+
$theselects = array_filter( explode( ',', $selectsfound ) );
|
929 |
+
|
930 |
+
foreach ( $theselects as $selected ) {
|
931 |
+
$selected = trim( $selected );
|
932 |
+
|
933 |
+
if ( strlen( $selected ) < 1 )
|
934 |
+
continue;
|
935 |
+
|
936 |
+
$selectfield = explode( ' AS ', str_replace( ' as ', ' AS ', $selected ) );
|
937 |
+
|
938 |
+
if ( 2 == count( $selectfield ) ) {
|
939 |
+
$field = trim( trim( $selectfield[ 1 ] ), '`' );
|
940 |
+
$real_field = trim( trim( $selectfield[ 0 ] ), '`' );
|
941 |
+
$this->aliases[ $field ] = $real_field;
|
942 |
+
}
|
943 |
+
}
|
944 |
+
}
|
945 |
+
|
946 |
+
// Search
|
947 |
+
if ( !empty( $params->search ) && !empty( $params->fields ) ) {
|
948 |
+
if ( false !== $params->search_query && 0 < strlen( $params->search_query ) ) {
|
949 |
+
$where = $having = array();
|
950 |
+
|
951 |
+
if ( false !== $params->search_across ) {
|
952 |
+
foreach ( $params->fields as $key => $field ) {
|
953 |
+
if ( is_array( $field ) ) {
|
954 |
+
$attributes = $field;
|
955 |
+
$field = pods_var( 'name', $field, $key, null, true );
|
956 |
+
}
|
957 |
+
else {
|
958 |
+
$attributes = array(
|
959 |
+
'type' => '',
|
960 |
+
'options' => array()
|
961 |
+
);
|
962 |
+
}
|
963 |
+
|
964 |
+
if ( isset( $attributes[ 'options' ][ 'search' ] ) && !$attributes[ 'options' ][ 'search' ] )
|
965 |
+
continue;
|
966 |
+
|
967 |
+
if ( in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime', 'number', 'decimal', 'currency', 'phone', 'password', 'boolean' ) ) )
|
968 |
+
continue;
|
969 |
+
|
970 |
+
$fieldfield = '`' . $field . '`';
|
971 |
+
|
972 |
+
if ( 'pick' == $attributes[ 'type' ] && !in_array( pods_var( 'pick_object', $attributes ), $simple_tableless_objects ) ) {
|
973 |
+
if ( false === $params->search_across_picks )
|
974 |
+
continue;
|
975 |
+
else {
|
976 |
+
if ( !isset( $attributes[ 'table_info' ] ) || empty( $attributes[ 'table_info' ] ) )
|
977 |
+
$attributes[ 'table_info' ] = $this->api->get_table_info( pods_var( 'pick_object', $attributes ), pods_var( 'pick_val', $attributes ) );
|
978 |
+
|
979 |
+
if ( empty( $attributes[ 'table_info' ][ 'field_index' ] ) )
|
980 |
+
continue;
|
981 |
+
|
982 |
+
$fieldfield = $fieldfield . '.`' . $attributes[ 'table_info' ][ 'field_index' ] . '`';
|
983 |
+
}
|
984 |
+
}
|
985 |
+
elseif ( in_array( $attributes[ 'type' ], PodsForm::file_field_types() ) ) {
|
986 |
+
if ( false === $params->search_across_files )
|
987 |
+
continue;
|
988 |
+
else
|
989 |
+
$fieldfield = $fieldfield . '.`post_title`';
|
990 |
+
}
|
991 |
+
elseif ( isset( $params->fields[ $field ] ) ) {
|
992 |
+
if ( $params->meta_fields )
|
993 |
+
$fieldfield = $fieldfield . '.`' . $params->pod_table_prefix . '`';
|
994 |
+
else
|
995 |
+
$fieldfield = '`' . $params->pod_table_prefix . '`.' . $fieldfield;
|
996 |
+
}
|
997 |
+
elseif ( !empty( $params->object_fields ) && !isset( $params->object_fields[ $field ] ) )
|
998 |
+
$fieldfield = $fieldfield . '.`meta_value`';
|
999 |
+
else
|
1000 |
+
$fieldfield = '`t`.' . $fieldfield;
|
1001 |
+
|
1002 |
+
if ( isset( $this->aliases[ $field ] ) )
|
1003 |
+
$fieldfield = '`' . $this->aliases[ $field ] . '`';
|
1004 |
+
|
1005 |
+
if ( isset( $attributes[ 'real_name' ] ) && !empty( $attributes[ 'real_name' ] ) )
|
1006 |
+
$fieldfield = $attributes[ 'real_name' ];
|
1007 |
+
|
1008 |
+
if ( isset( $attributes[ 'group_related' ] ) && false !== $attributes[ 'group_related' ] )
|
1009 |
+
$having[] = "{$fieldfield} LIKE '%" . pods_sanitize_like( $params->search_query ) . "%'";
|
1010 |
+
else
|
1011 |
+
$where[] = "{$fieldfield} LIKE '%" . pods_sanitize_like( $params->search_query ) . "%'";
|
1012 |
+
}
|
1013 |
+
}
|
1014 |
+
elseif ( !empty( $params->index ) ) {
|
1015 |
+
$attributes = array();
|
1016 |
+
|
1017 |
+
$fieldfield = '`t`.`' . $params->index . '`';
|
1018 |
+
|
1019 |
+
if ( isset( $params->fields[ $params->index ] ) ) {
|
1020 |
+
if ( $params->meta_fields )
|
1021 |
+
$fieldfield = '`' . $params->index . '`.`' . $params->pod_table_prefix . '`';
|
1022 |
+
else
|
1023 |
+
$fieldfield = '`' . $params->pod_table_prefix . '`.`' . $params->index . '`';
|
1024 |
+
}
|
1025 |
+
elseif ( !empty( $params->object_fields ) && !isset( $params->object_fields[ $params->index ] ) )
|
1026 |
+
$fieldfield = '`' . $params->index . '`.`meta_value`';
|
1027 |
+
|
1028 |
+
if ( isset( $attributes[ 'real_name' ] ) && false !== $attributes[ 'real_name' ] && !empty( $attributes[ 'real_name' ] ) )
|
1029 |
+
$fieldfield = $attributes[ 'real_name' ];
|
1030 |
+
|
1031 |
+
if ( isset( $attributes[ 'group_related' ] ) && false !== $attributes[ 'group_related' ] )
|
1032 |
+
$having[] = "{$fieldfield} LIKE '%" . pods_sanitize_like( $params->search_query ) . "%'";
|
1033 |
+
else
|
1034 |
+
$where[] = "{$fieldfield} LIKE '%" . pods_sanitize_like( $params->search_query ) . "%'";
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
if ( !empty( $where ) )
|
1038 |
+
$params->where[] = '( ' . implode( ' OR ', $where ) . ' )';
|
1039 |
+
|
1040 |
+
if ( !empty( $having ) )
|
1041 |
+
$params->having[] = '( ' . implode( ' OR ', $having ) . ' )';
|
1042 |
+
}
|
1043 |
+
|
1044 |
+
// Filter
|
1045 |
+
foreach ( $params->filters as $filter ) {
|
1046 |
+
$where = $having = array();
|
1047 |
+
|
1048 |
+
if ( !isset( $params->fields[ $filter ] ) )
|
1049 |
+
continue;
|
1050 |
+
|
1051 |
+
$attributes = $params->fields[ $filter ];
|
1052 |
+
$field = pods_var( 'name', $attributes, $filter, null, true );
|
1053 |
+
|
1054 |
+
$filterfield = '`' . $field . '`';
|
1055 |
+
|
1056 |
+
if ( 'pick' == $attributes[ 'type' ] && !in_array( pods_var( 'pick_object', $attributes ), $simple_tableless_objects ) ) {
|
1057 |
+
if ( !isset( $attributes[ 'table_info' ] ) || empty( $attributes[ 'table_info' ] ) )
|
1058 |
+
$attributes[ 'table_info' ] = $this->api->get_table_info( pods_var( 'pick_object', $attributes ), pods_var( 'pick_val', $attributes ) );
|
1059 |
+
|
1060 |
+
if ( empty( $attributes[ 'table_info' ][ 'field_index' ] ) )
|
1061 |
+
continue;
|
1062 |
+
|
1063 |
+
$filterfield = $filterfield . '.`' . $attributes[ 'table_info' ][ 'field_index' ] . '`';
|
1064 |
+
}
|
1065 |
+
elseif ( in_array( $attributes[ 'type' ], PodsForm::file_field_types() ) )
|
1066 |
+
$filterfield = $filterfield . '.`post_title`';
|
1067 |
+
elseif ( isset( $params->fields[ $field ] ) ) {
|
1068 |
+
if ( $params->meta_fields )
|
1069 |
+
$filterfield = $filterfield . '.`meta_value`';
|
1070 |
+
else
|
1071 |
+
$filterfield = '`' . $params->pod_table_prefix . '`.' . $filterfield;
|
1072 |
+
}
|
1073 |
+
elseif ( !empty( $params->object_fields ) && !isset( $params->object_fields[ $field ] ) )
|
1074 |
+
$filterfield = $filterfield . '.`meta_value`';
|
1075 |
+
else
|
1076 |
+
$filterfield = '`t`.' . $filterfield;
|
1077 |
+
|
1078 |
+
if ( isset( $this->aliases[ $field ] ) )
|
1079 |
+
$filterfield = '`' . $this->aliases[ $field ] . '`';
|
1080 |
+
|
1081 |
+
if ( isset( $attributes[ 'real_name' ] ) && false !== $attributes[ 'real_name' ] && !empty( $attributes[ 'real_name' ] ) )
|
1082 |
+
$filterfield = $attributes[ 'real_name' ];
|
1083 |
+
|
1084 |
+
if ( 'pick' == $attributes[ 'type' ] ) {
|
1085 |
+
$filter_value = pods_var_raw( 'filter_' . $field, 'get' );
|
1086 |
+
|
1087 |
+
if ( !is_array( $filter_value ) )
|
1088 |
+
$filter_value = (array) $filter_value;
|
1089 |
+
|
1090 |
+
foreach ( $filter_value as $filter_v ) {
|
1091 |
+
if ( in_array( pods_var( 'pick_object', $attributes ), $simple_tableless_objects ) ) {
|
1092 |
+
if ( strlen( $filter_v ) < 1 )
|
1093 |
+
continue;
|
1094 |
+
|
1095 |
+
if ( isset( $attributes[ 'group_related' ] ) && false !== $attributes[ 'group_related' ] ) {
|
1096 |
+
$having[] = "( {$filterfield} = '" . pods_sanitize( $filter_v ) . "'"
|
1097 |
+
. " OR {$filterfield} LIKE '%\"" . pods_sanitize_like( $filter_v ) . "\"%' )";
|
1098 |
+
}
|
1099 |
+
else {
|
1100 |
+
$where[] = "( {$filterfield} = '" . pods_sanitize( $filter_v ) . "'"
|
1101 |
+
. " OR {$filterfield} LIKE '%\"" . pods_sanitize_like( $filter_v ) . "\"%' )";
|
1102 |
+
}
|
1103 |
+
}
|
1104 |
+
else {
|
1105 |
+
$filter_v = (int) $filter_v;
|
1106 |
+
|
1107 |
+
if ( empty( $filter_v ) || empty( $attributes[ 'table_info' ] ) || empty( $attributes[ 'table_info' ][ 'field_id' ] ) )
|
1108 |
+
continue;
|
1109 |
+
|
1110 |
+
$filterfield = '`' . $field . '`.`' . $attributes[ 'table_info' ][ 'field_id' ] . '`';
|
1111 |
+
|
1112 |
+
if ( isset( $attributes[ 'group_related' ] ) && false !== $attributes[ 'group_related' ] )
|
1113 |
+
$having[] = "{$filterfield} = " . $filter_v;
|
1114 |
+
else
|
1115 |
+
$where[] = "{$filterfield} = " . $filter_v;
|
1116 |
+
}
|
1117 |
+
}
|
1118 |
+
}
|
1119 |
+
elseif ( in_array( $attributes[ 'type' ], array( 'date', 'datetime' ) ) ) {
|
1120 |
+
$start = date_i18n( 'Y-m-d' ) . ( 'datetime' == $attributes[ 'type' ] ) ? ' 00:00:00' : '';
|
1121 |
+
$end = date_i18n( 'Y-m-d' ) . ( 'datetime' == $attributes[ 'type' ] ) ? ' 23:59:59' : '';
|
1122 |
+
|
1123 |
+
$start_value = pods_var( 'filter_' . $field . '_start', 'get', false );
|
1124 |
+
$end_value = pods_var( 'filter_' . $field . '_end', 'get', false );
|
1125 |
+
|
1126 |
+
if ( empty( $start_value ) && empty( $end_value ) )
|
1127 |
+
continue;
|
1128 |
+
|
1129 |
+
if ( !empty( $start_value ) )
|
1130 |
+
$start = date_i18n( 'Y-m-d', strtotime( $start_value ) ) . ( 'datetime' == $attributes[ 'type' ] ? ' 00:00:00' : '' );
|
1131 |
+
|
1132 |
+
if ( !empty( $end_value ) )
|
1133 |
+
$end = date_i18n( 'Y-m-d', strtotime( $end_value ) ) . ( 'datetime' == $attributes[ 'type' ] ? ' 23:59:59' : '' );
|
1134 |
+
|
1135 |
+
if ( isset( $attributes[ 'date_ongoing' ] ) && true === $attributes[ 'date_ongoing' ] ) {
|
1136 |
+
$date_ongoing = '`' . $attributes[ 'date_ongoing' ] . '`';
|
1137 |
+
|
1138 |
+
if ( isset( $this->aliases[ $date_ongoing ] ) )
|
1139 |
+
$date_ongoing = '`' . $this->aliases[ $date_ongoing ] . '`';
|
1140 |
+
|
1141 |
+
if ( isset( $attributes[ 'group_related' ] ) && false !== $attributes[ 'group_related' ] )
|
1142 |
+
$having[] = "(({$filterfield} <= '$start' OR ({$filterfield} >= '$start' AND {$filterfield} <= '$end')) AND ({$date_ongoing} >= '$start' OR ({$date_ongoing} >= '$start' AND {$date_ongoing} <= '$end')))";
|
1143 |
+
else
|
1144 |
+
$where[] = "(({$filterfield} <= '$start' OR ({$filterfield} >= '$start' AND {$filterfield} <= '$end')) AND ({$date_ongoing} >= '$start' OR ({$date_ongoing} >= '$start' AND {$date_ongoing} <= '$end')))";
|
1145 |
+
}
|
1146 |
+
else {
|
1147 |
+
if ( isset( $attributes[ 'group_related' ] ) && false !== $attributes[ 'group_related' ] )
|
1148 |
+
$having[] = "({$filterfield} BETWEEN '$start' AND '$end')";
|
1149 |
+
else
|
1150 |
+
$where[] = "({$filterfield} BETWEEN '$start' AND '$end')";
|
1151 |
+
}
|
1152 |
+
}
|
1153 |
+
else {
|
1154 |
+
$filter_value = pods_var_raw( 'filter_' . $field, 'get', '' );
|
1155 |
+
|
1156 |
+
if ( strlen( $filter_value ) < 1 )
|
1157 |
+
continue;
|
1158 |
+
|
1159 |
+
if ( isset( $attributes[ 'group_related' ] ) && false !== $attributes[ 'group_related' ] )
|
1160 |
+
$having[] = "{$filterfield} LIKE '%" . pods_sanitize_like( $filter_value ) . "%'";
|
1161 |
+
else
|
1162 |
+
$where[] = "{$filterfield} LIKE '%" . pods_sanitize_like( $filter_value ) . "%'";
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
if ( !empty( $where ) )
|
1166 |
+
$params->where[] = implode( ' AND ', $where );
|
1167 |
+
|
1168 |
+
if ( !empty( $having ) )
|
1169 |
+
$params->having[] = implode( ' AND ', $having );
|
1170 |
+
}
|
1171 |
+
}
|
1172 |
+
|
1173 |
+
// Traverse the Rabbit Hole
|
1174 |
+
if ( !empty( $this->pod ) ) {
|
1175 |
+
$haystack = implode( ' ', (array) $params->select )
|
1176 |
+
. ' ' . implode( ' ', (array) $params->where )
|
1177 |
+
. ' ' . implode( ' ', (array) $params->groupby )
|
1178 |
+
. ' ' . implode( ' ', (array) $params->having )
|
1179 |
+
. ' ' . implode( ' ', (array) $params->orderby );
|
1180 |
+
$haystack = preg_replace( '/\s/', ' ', $haystack );
|
1181 |
+
$haystack = preg_replace( '/\w\(/', ' ', $haystack );
|
1182 |
+
$haystack = str_replace( array( '(', ')', ' ', '\\\'', "\\\"" ), ' ', $haystack );
|
1183 |
+
|
1184 |
+
preg_match_all( '/`?[\w]+`?(?:\\.`?[\w]+`?)+(?=[^"\']*(?:"[^"]*"[^"]*|\'[^\']*\'[^\']*)*$)/', $haystack, $found, PREG_PATTERN_ORDER );
|
1185 |
+
|
1186 |
+
$found = (array) @current( $found );
|
1187 |
+
$find = $replace = $traverse = array();
|
1188 |
+
|
1189 |
+
foreach ( $found as $key => $value ) {
|
1190 |
+
$value = str_replace( '`', '', $value );
|
1191 |
+
$value = explode( '.', $value );
|
1192 |
+
$dot = $last_value = array_pop( $value );
|
1193 |
+
|
1194 |
+
if ( 't' == $value[ 0 ] || in_array( '/\b' . trim( $found[ $key ], '`' ) . '\b(?=[^"\']*(?:"[^"]*"[^"]*|\'[^\']*\'[^\']*)*$)/', $find ) )
|
1195 |
+
continue;
|
1196 |
+
elseif ( 1 == count( $value ) && '' == preg_replace( '/[0-9]*/', '', $value[ 0 ] ) && '' == preg_replace( '/[0-9]*/', '', $last_value ) )
|
1197 |
+
continue;
|
1198 |
+
|
1199 |
+
$find[ $key ] = '/\b' . trim( $found[ $key ], '`' ) . '\b(?=[^"\']*(?:"[^"]*"[^"]*|\'[^\']*\'[^\']*)*$)/';
|
1200 |
+
|
1201 |
+
$esc_start = $esc_end = '`';
|
1202 |
+
|
1203 |
+
if ( strlen( ltrim( $found[ $key ], '`' ) ) < strlen( $found[ $key ] ) )
|
1204 |
+
$esc_start = '';
|
1205 |
+
|
1206 |
+
if ( strlen( rtrim( $found[ $key ], '`' ) ) < strlen( $found[ $key ] ) )
|
1207 |
+
$esc_end = '';
|
1208 |
+
|
1209 |
+
if ( '*' != $dot )
|
1210 |
+
$dot = '`' . $dot . $esc_end;
|
1211 |
+
|
1212 |
+
$replace[ $key ] = $esc_start . implode( '_', $value ) . '`.' . $dot;
|
1213 |
+
|
1214 |
+
$value[] = $last_value;
|
1215 |
+
|
1216 |
+
if ( !in_array( $value, $traverse ) )
|
1217 |
+
$traverse[ $key ] = $value;
|
1218 |
+
}
|
1219 |
+
|
1220 |
+
if ( !empty( $this->traverse ) ) {
|
1221 |
+
foreach ( (array) $this->traverse as $key => $traverse ) {
|
1222 |
+
$traverse = str_replace( '`', '', $traverse );
|
1223 |
+
$already_found = false;
|
1224 |
+
|
1225 |
+
foreach ( $traverse as $traversal ) {
|
1226 |
+
if ( is_array( $traversal ) )
|
1227 |
+
$traversal = implode( '.', $traversal );
|
1228 |
+
|
1229 |
+
if ( $traversal == $traverse ) {
|
1230 |
+
$already_found = true;
|
1231 |
+
break;
|
1232 |
+
}
|
1233 |
+
}
|
1234 |
+
|
1235 |
+
if ( !$already_found )
|
1236 |
+
$traverse[ 'traverse_' . $key ] = explode( '.', $traverse );
|
1237 |
+
}
|
1238 |
+
}
|
1239 |
+
|
1240 |
+
$joins = array();
|
1241 |
+
|
1242 |
+
if ( !empty( $find ) ) {
|
1243 |
+
$params->select = preg_replace( $find, $replace, $params->select );
|
1244 |
+
$params->where = preg_replace( $find, $replace, $params->where );
|
1245 |
+
$params->groupby = preg_replace( $find, $replace, $params->groupby );
|
1246 |
+
$params->having = preg_replace( $find, $replace, $params->having );
|
1247 |
+
$params->orderby = preg_replace( $find, $replace, $params->orderby );
|
1248 |
+
|
1249 |
+
if ( !empty( $traverse ) )
|
1250 |
+
$joins = $this->traverse( $traverse, $params->fields, $params );
|
1251 |
+
elseif ( false !== $params->search )
|
1252 |
+
$joins = $this->traverse( null, $params->fields, $params );
|
1253 |
+
}
|
1254 |
+
}
|
1255 |
+
|
1256 |
+
// Traversal Search
|
1257 |
+
if ( !empty( $params->search ) && !empty( $this->search_where ) )
|
1258 |
+
$params->where = array_merge( (array) $this->search_where, $params->where );
|
1259 |
+
|
1260 |
+
if ( !empty( $params->join ) && !empty( $joins ) )
|
1261 |
+
$params->join = array_merge( $joins, (array) $params->join );
|
1262 |
+
elseif ( !empty( $joins ) )
|
1263 |
+
$params->join = $joins;
|
1264 |
+
|
1265 |
+
// Build
|
1266 |
+
if ( null === $params->sql ) {
|
1267 |
+
$sql = "
|
1268 |
+
SELECT
|
1269 |
+
" . ( $params->calc_rows ? 'SQL_CALC_FOUND_ROWS' : '' ) . "
|
1270 |
+
" . ( $params->distinct ? 'DISTINCT' : '' ) . "
|
1271 |
+
" . ( !empty( $params->select ) ? ( is_array( $params->select ) ? implode( ', ', $params->select ) : $params->select ) : '*' ) . "
|
1272 |
+
FROM {$params->table} AS `t`
|
1273 |
+
" . ( !empty( $params->join ) ? ( is_array( $params->join ) ? implode( "\n ", $params->join ) : $params->join ) : '' ) . "
|
1274 |
+
" . ( !empty( $params->where ) ? 'WHERE ' . ( is_array( $params->where ) ? implode( ' AND ', $params->where ) : $params->where ) : '' ) . "
|
1275 |
+
" . ( !empty( $params->groupby ) ? 'GROUP BY ' . ( is_array( $params->groupby ) ? implode( ', ', $params->groupby ) : $params->groupby ) : '' ) . "
|
1276 |
+
" . ( !empty( $params->having ) ? 'HAVING ' . ( is_array( $params->having ) ? implode( ' AND ', $params->having ) : $params->having ) : '' ) . "
|
1277 |
+
" . ( !empty( $params->orderby ) ? 'ORDER BY ' . ( is_array( $params->orderby ) ? implode( ', ', $params->orderby ) : $params->orderby ) : '' ) . "
|
1278 |
+
" . ( ( 0 < $params->page && 0 < $params->limit ) ? 'LIMIT ' . $params->offset . ', ' . ( $params->limit ) : '' ) . "
|
1279 |
+
";
|
1280 |
+
|
1281 |
+
if ( !$params->calc_rows ) {
|
1282 |
+
$this->total_sql = "
|
1283 |
+
SELECT
|
1284 |
+
COUNT( " . ( $params->distinct ? 'DISTINCT `t`.`' . $params->id . '`' : '*' ) . " )
|
1285 |
+
FROM {$params->table} AS `t`
|
1286 |
+
" . ( !empty( $params->join ) ? ( is_array( $params->join ) ? implode( "\n ", $params->join ) : $params->join ) : '' ) . "
|
1287 |
+
" . ( !empty( $params->where ) ? 'WHERE ' . ( is_array( $params->where ) ? implode( ' AND ', $params->where ) : $params->where ) : '' ) . "
|
1288 |
+
" . ( !empty( $params->groupby ) ? 'GROUP BY ' . ( is_array( $params->groupby ) ? implode( ', ', $params->groupby ) : $params->groupby ) : '' ) . "
|
1289 |
+
" . ( !empty( $params->having ) ? 'HAVING ' . ( is_array( $params->having ) ? implode( ' AND ', $params->having ) : $params->having ) : '' ) . "
|
1290 |
+
";
|
1291 |
+
}
|
1292 |
+
}
|
1293 |
+
// Rewrite
|
1294 |
+
else {
|
1295 |
+
$sql = ' ' . trim( str_replace( array( "\n", "\r" ), ' ', $params->sql ) );
|
1296 |
+
$sql = preg_replace( array(
|
1297 |
+
'/\sSELECT\sSQL_CALC_FOUND_ROWS\s/i',
|
1298 |
+
'/\sSELECT\s/i'
|
1299 |
+
),
|
1300 |
+
array(
|
1301 |
+
' SELECT ',
|
1302 |
+
' SELECT SQL_CALC_FOUND_ROWS '
|
1303 |
+
),
|
1304 |
+
$sql );
|
1305 |
+
|
1306 |
+
// Insert variables based on existing statements
|
1307 |
+
if ( false === stripos( $sql, '%%SELECT%%' ) )
|
1308 |
+
$sql = preg_replace( '/\sSELECT\sSQL_CALC_FOUND_ROWS\s/i', ' SELECT SQL_CALC_FOUND_ROWS %%SELECT%% ', $sql );
|
1309 |
+
if ( false === stripos( $sql, '%%WHERE%%' ) )
|
1310 |
+
$sql = preg_replace( '/\sWHERE\s(?!.*\sWHERE\s)/i', ' WHERE %%WHERE%% ', $sql );
|
1311 |
+
if ( false === stripos( $sql, '%%GROUPBY%%' ) )
|
1312 |
+
$sql = preg_replace( '/\sGROUP BY\s(?!.*\sGROUP BY\s)/i', ' GROUP BY %%GROUPBY%% ', $sql );
|
1313 |
+
if ( false === stripos( $sql, '%%HAVING%%' ) )
|
1314 |
+
$sql = preg_replace( '/\sHAVING\s(?!.*\sHAVING\s)/i', ' HAVING %%HAVING%% ', $sql );
|
1315 |
+
if ( false === stripos( $sql, '%%ORDERBY%%' ) )
|
1316 |
+
$sql = preg_replace( '/\sORDER BY\s(?!.*\sORDER BY\s)/i', ' ORDER BY %%ORDERBY%% ', $sql );
|
1317 |
+
|
1318 |
+
// Insert variables based on other existing statements
|
1319 |
+
if ( false === stripos( $sql, '%%JOIN%%' ) ) {
|
1320 |
+
if ( false !== stripos( $sql, ' WHERE ' ) )
|
1321 |
+
$sql = preg_replace( '/\sWHERE\s(?!.*\sWHERE\s)/i', ' %%JOIN%% WHERE ', $sql );
|
1322 |
+
elseif ( false !== stripos( $sql, ' GROUP BY ' ) )
|
1323 |
+
$sql = preg_replace( '/\sGROUP BY\s(?!.*\sGROUP BY\s)/i', ' %%WHERE%% GROUP BY ', $sql );
|
1324 |
+
elseif ( false !== stripos( $sql, ' ORDER BY ' ) )
|
1325 |
+
$sql = preg_replace( '/\ORDER BY\s(?!.*\ORDER BY\s)/i', ' %%WHERE%% ORDER BY ', $sql );
|
1326 |
+
else
|
1327 |
+
$sql .= ' %%JOIN%% ';
|
1328 |
+
}
|
1329 |
+
if ( false === stripos( $sql, '%%WHERE%%' ) ) {
|
1330 |
+
if ( false !== stripos( $sql, ' GROUP BY ' ) )
|
1331 |
+
$sql = preg_replace( '/\sGROUP BY\s(?!.*\sGROUP BY\s)/i', ' %%WHERE%% GROUP BY ', $sql );
|
1332 |
+
elseif ( false !== stripos( $sql, ' ORDER BY ' ) )
|
1333 |
+
$sql = preg_replace( '/\ORDER BY\s(?!.*\ORDER BY\s)/i', ' %%WHERE%% ORDER BY ', $sql );
|
1334 |
+
else
|
1335 |
+
$sql .= ' %%WHERE%% ';
|
1336 |
+
}
|
1337 |
+
if ( false === stripos( $sql, '%%GROUPBY%%' ) ) {
|
1338 |
+
if ( false !== stripos( $sql, ' HAVING ' ) )
|
1339 |
+
$sql = preg_replace( '/\sHAVING\s(?!.*\sHAVING\s)/i', ' %%GROUPBY%% HAVING ', $sql );
|
1340 |
+
elseif ( false !== stripos( $sql, ' ORDER BY ' ) )
|
1341 |
+
$sql = preg_replace( '/\ORDER BY\s(?!.*\ORDER BY\s)/i', ' %%GROUPBY%% ORDER BY ', $sql );
|
1342 |
+
else
|
1343 |
+
$sql .= ' %%GROUPBY%% ';
|
1344 |
+
}
|
1345 |
+
if ( false === stripos( $sql, '%%HAVING%%' ) ) {
|
1346 |
+
if ( false !== stripos( $sql, ' ORDER BY ' ) )
|
1347 |
+
$sql = preg_replace( '/\ORDER BY\s(?!.*\ORDER BY\s)/i', ' %%HAVING%% ORDER BY ', $sql );
|
1348 |
+
else
|
1349 |
+
$sql .= ' %%HAVING%% ';
|
1350 |
+
}
|
1351 |
+
if ( false === stripos( $sql, '%%ORDERBY%%' ) )
|
1352 |
+
$sql .= ' %%ORDERBY%% ';
|
1353 |
+
if ( false === stripos( $sql, '%%LIMIT%%' ) )
|
1354 |
+
$sql .= ' %%LIMIT%% ';
|
1355 |
+
|
1356 |
+
// Replace variables
|
1357 |
+
if ( 0 < strlen( $params->select ) ) {
|
1358 |
+
if ( false === stripos( $sql, '%%SELECT%% FROM ' ) )
|
1359 |
+
$sql = str_ireplace( '%%SELECT%%', $params->select . ', ', $sql );
|
1360 |
+
else
|
1361 |
+
$sql = str_ireplace( '%%SELECT%%', $params->select, $sql );
|
1362 |
+
}
|
1363 |
+
if ( 0 < strlen( $params->join ) )
|
1364 |
+
$sql = str_ireplace( '%%JOIN%%', $params->join, $sql );
|
1365 |
+
if ( 0 < strlen( $params->where ) ) {
|
1366 |
+
if ( false !== stripos( $sql, ' WHERE ' ) ) {
|
1367 |
+
if ( false !== stripos( $sql, ' WHERE %%WHERE%% ' ) )
|
1368 |
+
$sql = str_ireplace( '%%WHERE%%', $params->where . ' AND ', $sql );
|
1369 |
+
else
|
1370 |
+
$sql = str_ireplace( '%%WHERE%%', ' AND ' . $params->where, $sql );
|
1371 |
+
}
|
1372 |
+
else
|
1373 |
+
$sql = str_ireplace( '%%WHERE%%', ' WHERE ' . $params->where, $sql );
|
1374 |
+
}
|
1375 |
+
if ( 0 < strlen( $params->groupby ) ) {
|
1376 |
+
if ( false !== stripos( $sql, ' GROUP BY ' ) ) {
|
1377 |
+
if ( false !== stripos( $sql, ' GROUP BY %%GROUPBY%% ' ) )
|
1378 |
+
$sql = str_ireplace( '%%GROUPBY%%', $params->groupby . ', ', $sql );
|
1379 |
+
else
|
1380 |
+
$sql = str_ireplace( '%%GROUPBY%%', ', ' . $params->groupby, $sql );
|
1381 |
+
}
|
1382 |
+
else
|
1383 |
+
$sql = str_ireplace( '%%GROUPBY%%', ' GROUP BY ' . $params->groupby, $sql );
|
1384 |
+
}
|
1385 |
+
if ( 0 < strlen( $params->having ) && false !== stripos( $sql, ' GROUP BY ' ) ) {
|
1386 |
+
if ( false !== stripos( $sql, ' HAVING ' ) ) {
|
1387 |
+
if ( false !== stripos( $sql, ' HAVING %%HAVING%% ' ) )
|
1388 |
+
$sql = str_ireplace( '%%HAVING%%', $params->having . ' AND ', $sql );
|
1389 |
+
else
|
1390 |
+
$sql = str_ireplace( '%%HAVING%%', ' AND ' . $params->having, $sql );
|
1391 |
+
}
|
1392 |
+
else
|
1393 |
+
$sql = str_ireplace( '%%HAVING%%', ' HAVING ' . $params->having, $sql );
|
1394 |
+
}
|
1395 |
+
if ( 0 < strlen( $params->orderby ) ) {
|
1396 |
+
if ( false !== stripos( $sql, ' ORDER BY ' ) ) {
|
1397 |
+
if ( false !== stripos( $sql, ' ORDER BY %%ORDERBY%% ' ) )
|
1398 |
+
$sql = str_ireplace( '%%ORDERBY%%', $params->groupby . ', ', $sql );
|
1399 |
+
else
|
1400 |
+
$sql = str_ireplace( '%%ORDERBY%%', ', ' . $params->groupby, $sql );
|
1401 |
+
}
|
1402 |
+
else
|
1403 |
+
$sql = str_ireplace( '%%ORDERBY%%', ' ORDER BY ' . $params->groupby, $sql );
|
1404 |
+
}
|
1405 |
+
if ( 0 < $params->page && 0 < $params->limit ) {
|
1406 |
+
$start = ( $params->page - 1 ) * $params->limit;
|
1407 |
+
$end = $start + $params->limit;
|
1408 |
+
$sql .= 'LIMIT ' . (int) $start . ', ' . (int) $end;
|
1409 |
+
}
|
1410 |
+
|
1411 |
+
// Clear any unused variables
|
1412 |
+
$sql = str_ireplace( array(
|
1413 |
+
'%%SELECT%%',
|
1414 |
+
'%%JOIN%%',
|
1415 |
+
'%%WHERE%%',
|
1416 |
+
'%%GROUPBY%%',
|
1417 |
+
'%%HAVING%%',
|
1418 |
+
'%%ORDERBY%%',
|
1419 |
+
'%%LIMIT%%'
|
1420 |
+
), '', $sql );
|
1421 |
+
$sql = str_replace( array( '``', '`' ), array( ' ', ' ' ), $sql );
|
1422 |
+
}
|
1423 |
+
|
1424 |
+
return $sql;
|
1425 |
+
}
|
1426 |
+
|
1427 |
+
/**
|
1428 |
+
* Fetch the total row count returned
|
1429 |
+
*
|
1430 |
+
* @return int Number of rows returned by select()
|
1431 |
+
* @since 2.0
|
1432 |
+
*/
|
1433 |
+
public function total () {
|
1434 |
+
return (int) $this->total;
|
1435 |
+
}
|
1436 |
+
|
1437 |
+
/**
|
1438 |
+
* Fetch the total row count total
|
1439 |
+
*
|
1440 |
+
* @return int Number of rows found by select()
|
1441 |
+
* @since 2.0
|
1442 |
+
*/
|
1443 |
+
public function total_found () {
|
1444 |
+
if(false === $this->total_found_calculated)
|
1445 |
+
$this->calculate_totals();
|
1446 |
+
|
1447 |
+
return (int) $this->total_found;
|
1448 |
+
}
|
1449 |
+
|
1450 |
+
/**
|
1451 |
+
* Fetch the zebra state
|
1452 |
+
*
|
1453 |
+
* @return bool Zebra state
|
1454 |
+
* @since 1.12
|
1455 |
+
* @see PodsData::nth
|
1456 |
+
*/
|
1457 |
+
public function zebra () {
|
1458 |
+
return $this->nth( 'odd' ); // Odd numbers
|
1459 |
+
}
|
1460 |
+
|
1461 |
+
/**
|
1462 |
+
* Fetch the nth state
|
1463 |
+
*
|
1464 |
+
* @param int|string $nth The $nth to match on the PodsData::row_number
|
1465 |
+
*
|
1466 |
+
* @return bool Whether $nth matches
|
1467 |
+
* @since 2.3
|
1468 |
+
*/
|
1469 |
+
public function nth ( $nth ) {
|
1470 |
+
if ( empty( $nth ) )
|
1471 |
+
$nth = 2;
|
1472 |
+
|
1473 |
+
$offset = 0;
|
1474 |
+
$negative = false;
|
1475 |
+
|
1476 |
+
if ( 'even' == $nth )
|
1477 |
+
$nth = 2;
|
1478 |
+
elseif ( 'odd' == $nth ) {
|
1479 |
+
$negative = true;
|
1480 |
+
$nth = 2;
|
1481 |
+
}
|
1482 |
+
elseif ( false !== strpos( $nth, '+' ) ) {
|
1483 |
+
$nth = explode( '+', $nth );
|
1484 |
+
|
1485 |
+
if ( isset( $nth[ 1 ] ) )
|
1486 |
+
$offset += (int) trim( $nth[ 1 ] );
|
1487 |
+
|
1488 |
+
$nth = (int) trim( $nth[ 0 ], ' n' );
|
1489 |
+
}
|
1490 |
+
elseif ( false !== strpos( $nth, '-' ) ) {
|
1491 |
+
$nth = explode( '-', $nth );
|
1492 |
+
|
1493 |
+
if ( isset( $nth[ 1 ] ) )
|
1494 |
+
$offset -= (int) trim( $nth[ 1 ] );
|
1495 |
+
|
1496 |
+
$nth = (int) trim( $nth[ 0 ], ' n' );
|
1497 |
+
}
|
1498 |
+
|
1499 |
+
$nth = (int) $nth;
|
1500 |
+
$offset = (int) $offset;
|
1501 |
+
|
1502 |
+
if ( 0 == ( ( $this->row_number % $nth ) + $offset ) )
|
1503 |
+
return ( $negative ? false: true );
|
1504 |
+
|
1505 |
+
return ( $negative ? true : false );
|
1506 |
+
}
|
1507 |
+
|
1508 |
+
/**
|
1509 |
+
* Fetch the current position in the loop (starting at 1)
|
1510 |
+
*
|
1511 |
+
* @return int Current row number (+1)
|
1512 |
+
* @since 2.3
|
1513 |
+
*/
|
1514 |
+
public function position () {
|
1515 |
+
return $this->row_number + 1;
|
1516 |
+
}
|
1517 |
+
|
1518 |
+
/**
|
1519 |
+
* Create a Table
|
1520 |
+
*
|
1521 |
+
* @param string $table Table name
|
1522 |
+
* @param string $fields
|
1523 |
+
* @param boolean $if_not_exists Check if the table exists.
|
1524 |
+
*
|
1525 |
+
* @return array|bool|mixed|null|void
|
1526 |
+
*
|
1527 |
+
* @uses PodsData::query
|
1528 |
+
*
|
1529 |
+
* @since 2.0
|
1530 |
+
*/
|
1531 |
+
public static function table_create ( $table, $fields, $if_not_exists = false ) {
|
1532 |
+
/**
|
1533 |
+
* @var $wpdb wpdb
|
1534 |
+
*/
|
1535 |
+
global $wpdb;
|
1536 |
+
|
1537 |
+
$sql = "CREATE TABLE";
|
1538 |
+
|
1539 |
+
if ( true === $if_not_exists )
|
1540 |
+
$sql .= " IF NOT EXISTS";
|
1541 |
+
|
1542 |
+
$sql .= " `{$wpdb->prefix}" . self::$prefix . "{$table}` ({$fields})";
|
1543 |
+
|
1544 |
+
if ( !empty( $wpdb->charset ) )
|
1545 |
+
$sql .= " DEFAULT CHARACTER SET {$wpdb->charset}";
|
1546 |
+
|
1547 |
+
if ( !empty( $wpdb->collate ) )
|
1548 |
+
$sql .= " COLLATE {$wpdb->collate}";
|
1549 |
+
|
1550 |
+
return self::query( $sql );
|
1551 |
+
}
|
1552 |
+
|
1553 |
+
/**
|
1554 |
+
* Alter a Table
|
1555 |
+
*
|
1556 |
+
* @param string $table Table name
|
1557 |
+
* @param string $changes
|
1558 |
+
*
|
1559 |
+
* @return array|bool|mixed|null|void
|
1560 |
+
*
|
1561 |
+
* @uses PodsData::query
|
1562 |
+
*
|
1563 |
+
* @since 2.0
|
1564 |
+
*/
|
1565 |
+
public static function table_alter ( $table, $changes ) {
|
1566 |
+
/**
|
1567 |
+
* @var $wpdb wpdb
|
1568 |
+
*/
|
1569 |
+
global $wpdb;
|
1570 |
+
|
1571 |
+
$sql = "ALTER TABLE `{$wpdb->prefix}" . self::$prefix . "{$table}` {$changes}";
|
1572 |
+
|
1573 |
+
return self::query( $sql );
|
1574 |
+
}
|
1575 |
+
|
1576 |
+
/**
|
1577 |
+
* Truncate a Table
|
1578 |
+
*
|
1579 |
+
* @param string $table Table name
|
1580 |
+
*
|
1581 |
+
* @return array|bool|mixed|null|void
|
1582 |
+
*
|
1583 |
+
* @uses PodsData::query
|
1584 |
+
*
|
1585 |
+
* @since 2.0
|
1586 |
+
*/
|
1587 |
+
public static function table_truncate ( $table ) {
|
1588 |
+
/**
|
1589 |
+
* @var $wpdb wpdb
|
1590 |
+
*/
|
1591 |
+
global $wpdb;
|
1592 |
+
|
1593 |
+
$sql = "TRUNCATE TABLE `{$wpdb->prefix}" . self::$prefix . "{$table}`";
|
1594 |
+
|
1595 |
+
return self::query( $sql );
|
1596 |
+
}
|
1597 |
+
|
1598 |
+
/**
|
1599 |
+
* Drop a Table
|
1600 |
+
*
|
1601 |
+
* @param string $table Table name
|
1602 |
+
*
|
1603 |
+
* @uses PodsData::query
|
1604 |
+
*
|
1605 |
+
* @return array|bool|mixed|null|void
|
1606 |
+
*
|
1607 |
+
* @uses PodsData::query
|
1608 |
+
*
|
1609 |
+
* @since 2.0
|
1610 |
+
*/
|
1611 |
+
public static function table_drop ( $table ) {
|
1612 |
+
/**
|
1613 |
+
* @var $wpdb wpdb
|
1614 |
+
*/
|
1615 |
+
global $wpdb;
|
1616 |
+
|
1617 |
+
$sql = "DROP TABLE `{$wpdb->prefix}" . self::$prefix . "{$table}`";
|
1618 |
+
|
1619 |
+
return self::query( $sql );
|
1620 |
+
}
|
1621 |
+
|
1622 |
+
/**
|
1623 |
+
* Reorder Items
|
1624 |
+
*
|
1625 |
+
* @param string $table Table name
|
1626 |
+
* @param string $weight_field
|
1627 |
+
* @param string $id_field
|
1628 |
+
* @param array $ids
|
1629 |
+
*
|
1630 |
+
* @return bool
|
1631 |
+
*
|
1632 |
+
* @uses PodsData::update
|
1633 |
+
*
|
1634 |
+
* @since 2.0
|
1635 |
+
*/
|
1636 |
+
public function reorder ( $table, $weight_field, $id_field, $ids ) {
|
1637 |
+
$success = false;
|
1638 |
+
$ids = (array) $ids;
|
1639 |
+
|
1640 |
+
list( $table, $weight_field, $id_field, $ids ) = $this->do_hook( 'reorder', array(
|
1641 |
+
$table,
|
1642 |
+
$weight_field,
|
1643 |
+
$id_field,
|
1644 |
+
$ids
|
1645 |
+
) );
|
1646 |
+
|
1647 |
+
if ( !empty( $ids ) ) {
|
1648 |
+
$success = true;
|
1649 |
+
|
1650 |
+
foreach ( $ids as $weight => $id ) {
|
1651 |
+
$updated = $this->update( $table, array( $weight_field => $weight ), array( $id_field => $id ), array( '%d' ), array( '%d' ) );
|
1652 |
+
|
1653 |
+
if ( false === $updated )
|
1654 |
+
$success = false;
|
1655 |
+
}
|
1656 |
+
}
|
1657 |
+
|
1658 |
+
return $success;
|
1659 |
+
}
|
1660 |
+
|
1661 |
+
/**
|
1662 |
+
* Fetch a new row for the current pod_data
|
1663 |
+
*
|
1664 |
+
* @param int $row Row number to fetch
|
1665 |
+
* @param bool $explicit_set Whether to set explicitly (use false when in loop)
|
1666 |
+
*
|
1667 |
+
* @return mixed
|
1668 |
+
*
|
1669 |
+
* @since 2.0
|
1670 |
+
*/
|
1671 |
+
public function fetch ( $row = null, $explicit_set = true ) {
|
1672 |
+
global $wpdb;
|
1673 |
+
|
1674 |
+
if ( null === $row )
|
1675 |
+
$explicit_set = false;
|
1676 |
+
|
1677 |
+
$id = $row;
|
1678 |
+
|
1679 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
1680 |
+
|
1681 |
+
if ( null === $row ) {
|
1682 |
+
$this->row_number++;
|
1683 |
+
|
1684 |
+
$this->row = false;
|
1685 |
+
|
1686 |
+
if ( isset( $this->data[ $this->row_number ] ) ) {
|
1687 |
+
$this->row = get_object_vars( $this->data[ $this->row_number ] );
|
1688 |
+
|
1689 |
+
$current_row_id = false;
|
1690 |
+
|
1691 |
+
if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) )
|
1692 |
+
$current_row_id = pods_var_raw( 'ID', $this->row );
|
1693 |
+
elseif ( 'taxonomy' == $this->pod_data[ 'type' ] )
|
1694 |
+
$current_row_id = pods_var_raw( 'term_id', $this->row );
|
1695 |
+
elseif ( 'user' == $this->pod_data[ 'type' ] )
|
1696 |
+
$current_row_id = pods_var_raw( 'ID', $this->row );
|
1697 |
+
elseif ( 'comment' == $this->pod_data[ 'type' ] )
|
1698 |
+
$current_row_id = pods_var_raw( 'comment_ID', $this->row );
|
1699 |
+
elseif ( 'settings' == $this->pod_data[ 'type' ] )
|
1700 |
+
$current_row_id = $this->pod_data[ 'id' ];
|
1701 |
+
|
1702 |
+
if ( 0 < $current_row_id )
|
1703 |
+
$row = $current_row_id;
|
1704 |
+
}
|
1705 |
+
}
|
1706 |
+
|
1707 |
+
if ( null !== $row || 'settings' == $this->pod_data[ 'type' ] ) {
|
1708 |
+
if ( $explicit_set )
|
1709 |
+
$this->row_number = -1;
|
1710 |
+
|
1711 |
+
$mode = 'id';
|
1712 |
+
$id = pods_absint( $row );
|
1713 |
+
|
1714 |
+
if ( !is_numeric( $row ) || 0 === strpos( $row, '0' ) || $row != preg_replace( '/[^0-9]/', '', $row ) ) {
|
1715 |
+
$mode = 'slug';
|
1716 |
+
$id = $row;
|
1717 |
+
}
|
1718 |
+
|
1719 |
+
$row = false;
|
1720 |
+
|
1721 |
+
// @todo Figure out why taking out this in_array() causes cached data issues in User edit screen
|
1722 |
+
if ( !empty( $this->pod ) && in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
|
1723 |
+
$row = pods_cache_get( $id, 'pods_items_' . $this->pod );
|
1724 |
+
}
|
1725 |
+
|
1726 |
+
$current_row_id = false;
|
1727 |
+
$get_table_data = false;
|
1728 |
+
|
1729 |
+
$old_row = $this->row;
|
1730 |
+
|
1731 |
+
if ( false !== $row && is_array( $row ) )
|
1732 |
+
$this->row = $row;
|
1733 |
+
elseif ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) {
|
1734 |
+
if ( 'post_type' == $this->pod_data[ 'type' ] ) {
|
1735 |
+
if ( empty( $this->pod_data[ 'object' ] ) ) {
|
1736 |
+
$post_type = $this->pod_data[ 'name' ];
|
1737 |
+
}
|
1738 |
+
else {
|
1739 |
+
$post_type = $this->pod_data[ 'object' ];
|
1740 |
+
}
|
1741 |
+
}
|
1742 |
+
else
|
1743 |
+
$post_type = 'attachment';
|
1744 |
+
|
1745 |
+
if ( 'id' == $mode ) {
|
1746 |
+
$this->row = get_post( $id, ARRAY_A );
|
1747 |
+
|
1748 |
+
if ( is_array( $this->row ) && $this->row[ 'post_type' ] != $post_type )
|
1749 |
+
$this->row = false;
|
1750 |
+
}
|
1751 |
+
else {
|
1752 |
+
$args = array(
|
1753 |
+
'post_type' => $post_type,
|
1754 |
+
'name' => $id,
|
1755 |
+
'numberposts' => 5
|
1756 |
+
);
|
1757 |
+
|
1758 |
+
$find = get_posts( $args );
|
1759 |
+
|
1760 |
+
if ( !empty( $find ) )
|
1761 |
+
$this->row = get_object_vars( $find[ 0 ] );
|
1762 |
+
}
|
1763 |
+
|
1764 |
+
if ( is_wp_error( $this->row ) || empty( $this->row ) )
|
1765 |
+
$this->row = false;
|
1766 |
+
else
|
1767 |
+
$current_row_id = $this->row[ 'ID' ];
|
1768 |
+
|
1769 |
+
$get_table_data = true;
|
1770 |
+
}
|
1771 |
+
elseif ( 'taxonomy' == $this->pod_data[ 'type' ] ) {
|
1772 |
+
$taxonomy = $this->pod_data[ 'object' ];
|
1773 |
+
|
1774 |
+
if ( empty( $taxonomy ) )
|
1775 |
+
$taxonomy = $this->pod_data[ 'name' ];
|
1776 |
+
|
1777 |
+
// Taxonomies are registered during init, so they aren't available before then
|
1778 |
+
if ( !did_action( 'init' ) ) {
|
1779 |
+
// hackaround :(
|
1780 |
+
if ( 'id' == $mode )
|
1781 |
+
$term_where = 't.term_id = %d';
|
1782 |
+
else
|
1783 |
+
$term_where = 't.slug = %s';
|
1784 |
+
|
1785 |
+
$filter = 'raw';
|
1786 |
+
$term = $id;
|
1787 |
+
|
1788 |
+
if ( 'id' != $mode || !$_term = wp_cache_get( $term, $taxonomy ) ) {
|
1789 |
+
$_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND {$term_where} LIMIT 1", $taxonomy, $term ) );
|
1790 |
+
|
1791 |
+
if ( $_term )
|
1792 |
+
wp_cache_add( $term, $_term, $taxonomy );
|
1793 |
+
}
|
1794 |
+
|
1795 |
+
$_term = apply_filters( 'get_term', $_term, $taxonomy );
|
1796 |
+
$_term = apply_filters( "get_$taxonomy", $_term, $taxonomy );
|
1797 |
+
$_term = sanitize_term( $_term, $taxonomy, $filter );
|
1798 |
+
|
1799 |
+
if ( is_object( $_term ) )
|
1800 |
+
$this->row = get_object_vars( $_term );
|
1801 |
+
}
|
1802 |
+
elseif ( 'id' == $mode )
|
1803 |
+
$this->row = get_term( $id, $taxonomy, ARRAY_A );
|
1804 |
+
else
|
1805 |
+
$this->row = get_term_by( 'slug', $id, $taxonomy, ARRAY_A );
|
1806 |
+
|
1807 |
+
if ( is_wp_error( $this->row ) || empty( $this->row ) )
|
1808 |
+
$this->row = false;
|
1809 |
+
else
|
1810 |
+
$current_row_id = $this->row[ 'term_id' ];
|
1811 |
+
|
1812 |
+
$get_table_data = true;
|
1813 |
+
}
|
1814 |
+
elseif ( 'user' == $this->pod_data[ 'type' ] ) {
|
1815 |
+
if ( 'id' == $mode )
|
1816 |
+
$this->row = get_userdata( $id );
|
1817 |
+
else
|
1818 |
+
$this->row = get_user_by( 'slug', $id );
|
1819 |
+
|
1820 |
+
if ( is_wp_error( $this->row ) || empty( $this->row ) )
|
1821 |
+
$this->row = false;
|
1822 |
+
else {
|
1823 |
+
// Get other vars
|
1824 |
+
$roles = $this->row->roles;
|
1825 |
+
$caps = $this->row->caps;
|
1826 |
+
$allcaps = $this->row->allcaps;
|
1827 |
+
|
1828 |
+
$this->row = get_object_vars( $this->row->data );
|
1829 |
+
|
1830 |
+
// Set other vars
|
1831 |
+
$this->row[ 'roles' ] = $roles;
|
1832 |
+
$this->row[ 'caps' ] = $caps;
|
1833 |
+
$this->row[ 'allcaps' ] = $allcaps;
|
1834 |
+
|
1835 |
+
unset( $this->row[ 'user_pass' ] );
|
1836 |
+
|
1837 |
+
$current_row_id = $this->row[ 'ID' ];
|
1838 |
+
}
|
1839 |
+
|
1840 |
+
$get_table_data = true;
|
1841 |
+
}
|
1842 |
+
elseif ( 'comment' == $this->pod_data[ 'type' ] ) {
|
1843 |
+
$this->row = get_comment( $id, ARRAY_A );
|
1844 |
+
|
1845 |
+
// No slug handling here
|
1846 |
+
|
1847 |
+
if ( is_wp_error( $this->row ) || empty( $this->row ) )
|
1848 |
+
$this->row = false;
|
1849 |
+
else
|
1850 |
+
$current_row_id = $this->row[ 'comment_ID' ];
|
1851 |
+
|
1852 |
+
$get_table_data = true;
|
1853 |
+
}
|
1854 |
+
elseif ( 'settings' == $this->pod_data[ 'type' ] ) {
|
1855 |
+
$this->row = array();
|
1856 |
+
|
1857 |
+
if ( empty( $this->fields ) )
|
1858 |
+
$this->row = false;
|
1859 |
+
else {
|
1860 |
+
foreach ( $this->fields as $field ) {
|
1861 |
+
if ( !in_array( $field[ 'type' ], $tableless_field_types ) )
|
1862 |
+
$this->row[ $field[ 'name' ] ] = get_option( $this->pod_data[ 'name' ] . '_' . $field[ 'name' ], null );
|
1863 |
+
}
|
1864 |
+
|
1865 |
+
// Force ID
|
1866 |
+
$this->id = $this->pod_data[ 'id' ];
|
1867 |
+
$this->row[ 'option_id' ] = $this->id;
|
1868 |
+
}
|
1869 |
+
}
|
1870 |
+
else {
|
1871 |
+
$params = array(
|
1872 |
+
'table' => $this->table,
|
1873 |
+
'where' => "`t`.`{$this->field_id}` = " . (int) $id,
|
1874 |
+
'orderby' => "`t`.`{$this->field_id}` DESC",
|
1875 |
+
'page' => 1,
|
1876 |
+
'limit' => 1,
|
1877 |
+
'search' => false
|
1878 |
+
);
|
1879 |
+
|
1880 |
+
if ( 'slug' == $mode && !empty( $this->field_slug ) ) {
|
1881 |
+
$id = pods_sanitize( $id );
|
1882 |
+
$params[ 'where' ] = "`t`.`{$this->field_slug}` = '{$id}'";
|
1883 |
+
}
|
1884 |
+
|
1885 |
+
$this->row = pods_data()->select( $params );
|
1886 |
+
|
1887 |
+
if ( empty( $this->row ) )
|
1888 |
+
$this->row = false;
|
1889 |
+
else {
|
1890 |
+
$current_row = (array) $this->row;
|
1891 |
+
$this->row = get_object_vars( (object) @current( $current_row ) );
|
1892 |
+
}
|
1893 |
+
}
|
1894 |
+
|
1895 |
+
if ( !$explicit_set && is_array( $this->row ) && !empty( $this->row ) && !empty( $old_row ) ) {
|
1896 |
+
$this->row = array_merge( $old_row, $this->row );
|
1897 |
+
}
|
1898 |
+
|
1899 |
+
if ( 'table' == $this->pod_data[ 'storage' ] && false !== $get_table_data && is_numeric( $current_row_id ) ) {
|
1900 |
+
$params = array(
|
1901 |
+
'table' => $wpdb->prefix . "pods_",
|
1902 |
+
'where' => "`t`.`id` = {$current_row_id}",
|
1903 |
+
'orderby' => "`t`.`id` DESC",
|
1904 |
+
'page' => 1,
|
1905 |
+
'limit' => 1,
|
1906 |
+
'search' => false,
|
1907 |
+
'strict' => true
|
1908 |
+
);
|
1909 |
+
|
1910 |
+
if ( empty( $this->pod_data[ 'object' ] ) )
|
1911 |
+
$params[ 'table' ] .= $this->pod_data[ 'name' ];
|
1912 |
+
else
|
1913 |
+
$params[ 'table' ] .= $this->pod_data[ 'object' ];
|
1914 |
+
|
1915 |
+
$row = pods_data()->select( $params );
|
1916 |
+
|
1917 |
+
if ( !empty( $row ) ) {
|
1918 |
+
$current_row = (array) $row;
|
1919 |
+
$row = get_object_vars( (object) @current( $current_row ) );
|
1920 |
+
|
1921 |
+
if ( is_array( $this->row ) && !empty( $this->row ) )
|
1922 |
+
$this->row = array_merge( $row, $this->row );
|
1923 |
+
else
|
1924 |
+
$this->row = $row;
|
1925 |
+
}
|
1926 |
+
}
|
1927 |
+
|
1928 |
+
// @todo Figure out why taking out this in_array() causes cached data issues in User edit screen
|
1929 |
+
if ( !empty( $this->pod ) && in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
|
1930 |
+
pods_cache_set( $id, $this->row, 'pods_items_' . $this->pod, 0 );
|
1931 |
+
}
|
1932 |
+
}
|
1933 |
+
|
1934 |
+
$this->row = $this->do_hook( 'fetch', $this->row, $id, $this->row_number );
|
1935 |
+
|
1936 |
+
return $this->row;
|
1937 |
+
}
|
1938 |
+
|
1939 |
+
/**
|
1940 |
+
* Reset the current data
|
1941 |
+
*
|
1942 |
+
* @param int $row Row number to reset to
|
1943 |
+
*
|
1944 |
+
* @return mixed
|
1945 |
+
*
|
1946 |
+
* @since 2.0
|
1947 |
+
*/
|
1948 |
+
public function reset ( $row = null ) {
|
1949 |
+
$row = pods_absint( $row );
|
1950 |
+
|
1951 |
+
$this->row = false;
|
1952 |
+
|
1953 |
+
if ( isset( $this->data[ $row ] ) )
|
1954 |
+
$this->row = get_object_vars( $this->data[ $row ] );
|
1955 |
+
|
1956 |
+
if ( empty( $row ) )
|
1957 |
+
$this->row_number = -1;
|
1958 |
+
else
|
1959 |
+
$this->row_number = $row - 1;
|
1960 |
+
|
1961 |
+
return $this->row;
|
1962 |
+
}
|
1963 |
+
|
1964 |
+
/**
|
1965 |
+
* @static
|
1966 |
+
*
|
1967 |
+
* Do a query on the database
|
1968 |
+
*
|
1969 |
+
* @param string|array $sql The SQL to execute
|
1970 |
+
* @param string $error Error to throw on problems
|
1971 |
+
* @param null $results_error (optional)
|
1972 |
+
* @param null $no_results_error (optional)
|
1973 |
+
*
|
1974 |
+
* @return array|bool|mixed|null|void Result of the query
|
1975 |
+
*
|
1976 |
+
* @since 2.0
|
1977 |
+
*/
|
1978 |
+
public static function query ( $sql, $error = 'Database Error', $results_error = null, $no_results_error = null ) {
|
1979 |
+
/**
|
1980 |
+
* @var $wpdb wpdb
|
1981 |
+
*/
|
1982 |
+
global $wpdb;
|
1983 |
+
|
1984 |
+
if ( $wpdb->show_errors )
|
1985 |
+
self::$display_errors = true;
|
1986 |
+
|
1987 |
+
$display_errors = self::$display_errors;
|
1988 |
+
|
1989 |
+
if ( is_object( $error ) ) {
|
1990 |
+
if ( isset( $error->display_errors ) && false === $error->display_errors )
|
1991 |
+
$display_errors = false;
|
1992 |
+
|
1993 |
+
$error = 'Database Error';
|
1994 |
+
}
|
1995 |
+
elseif ( is_bool( $error ) ) {
|
1996 |
+
$display_errors = $error;
|
1997 |
+
|
1998 |
+
if ( false !== $error )
|
1999 |
+
$error = 'Database Error';
|
2000 |
+
}
|
2001 |
+
|
2002 |
+
$params = (object) array(
|
2003 |
+
'sql' => $sql,
|
2004 |
+
'error' => $error,
|
2005 |
+
'results_error' => $results_error,
|
2006 |
+
'no_results_error' => $no_results_error,
|
2007 |
+
'display_errors' => $display_errors
|
2008 |
+
);
|
2009 |
+
|
2010 |
+
// Handle Preparations of Values (sprintf format)
|
2011 |
+
if ( is_array( $sql ) ) {
|
2012 |
+
if ( isset( $sql[ 0 ] ) && 1 < count( $sql ) ) {
|
2013 |
+
if ( 2 == count( $sql ) ) {
|
2014 |
+
if ( !is_array( $sql[ 1 ] ) )
|
2015 |
+
$sql[ 1 ] = array( $sql[ 1 ] );
|
2016 |
+
|
2017 |
+
$params->sql = self::prepare( $sql[ 0 ], $sql[ 1 ] );
|
2018 |
+
}
|
2019 |
+
elseif ( 3 == count( $sql ) )
|
2020 |
+
$params->sql = self::prepare( $sql[ 0 ], array( $sql[ 1 ], $sql[ 2 ] ) );
|
2021 |
+
else
|
2022 |
+
$params->sql = self::prepare( $sql[ 0 ], array( $sql[ 1 ], $sql[ 2 ], $sql[ 3 ] ) );
|
2023 |
+
}
|
2024 |
+
else
|
2025 |
+
$params = array_merge( $params, $sql );
|
2026 |
+
|
2027 |
+
if ( 1 == pods_var( 'pods_debug_sql_all', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
2028 |
+
echo '<textarea cols="100" rows="24">' . str_replace( array( '@wp_users', '@wp_' ), array( $wpdb->users, $wpdb->prefix ), $params->sql ) . '</textarea>';
|
2029 |
+
}
|
2030 |
+
|
2031 |
+
$params->sql = trim( $params->sql );
|
2032 |
+
|
2033 |
+
// Run Query
|
2034 |
+
$params->sql = self::do_hook( 'query', $params->sql, $params );
|
2035 |
+
|
2036 |
+
$result = $wpdb->query( $params->sql );
|
2037 |
+
|
2038 |
+
$result = self::do_hook( 'query_result', $result, $params );
|
2039 |
+
|
2040 |
+
if ( false === $result && !empty( $params->error ) && !empty( $wpdb->last_error ) )
|
2041 |
+
return pods_error( "{$params->error}; SQL: {$params->sql}; Response: {$wpdb->last_error}", $params->display_errors );
|
2042 |
+
|
2043 |
+
if ( 'INSERT' == strtoupper( substr( $params->sql, 0, 6 ) ) || 'REPLACE' == strtoupper( substr( $params->sql, 0, 7 ) ) )
|
2044 |
+
$result = $wpdb->insert_id;
|
2045 |
+
elseif ( preg_match( '/^[\s\r\n\(]*SELECT/', strtoupper( $params->sql ) ) ) {
|
2046 |
+
$result = (array) $wpdb->last_result;
|
2047 |
+
|
2048 |
+
if ( !empty( $result ) && !empty( $params->results_error ) )
|
2049 |
+
return pods_error( $params->results_error, $params->display_errors );
|
2050 |
+
elseif ( empty( $result ) && !empty( $params->no_results_error ) )
|
2051 |
+
return pods_error( $params->no_results_error, $params->display_errors );
|
2052 |
+
}
|
2053 |
+
|
2054 |
+
return $result;
|
2055 |
+
}
|
2056 |
+
|
2057 |
+
/**
|
2058 |
+
* Gets all tables in the WP database, optionally exclude WP core
|
2059 |
+
* tables, and/or Pods table by settings the parameters to false.
|
2060 |
+
*
|
2061 |
+
* @param boolean $wp_core
|
2062 |
+
* @param boolean $pods_tables restrict Pods 2.x tables
|
2063 |
+
*
|
2064 |
+
* @return array
|
2065 |
+
*
|
2066 |
+
* @since 2.0
|
2067 |
+
*/
|
2068 |
+
public static function get_tables ( $wp_core = true, $pods_tables = true ) {
|
2069 |
+
global $wpdb;
|
2070 |
+
|
2071 |
+
$core_wp_tables = array(
|
2072 |
+
$wpdb->options,
|
2073 |
+
$wpdb->comments,
|
2074 |
+
$wpdb->commentmeta,
|
2075 |
+
$wpdb->posts,
|
2076 |
+
$wpdb->postmeta,
|
2077 |
+
$wpdb->users,
|
2078 |
+
$wpdb->usermeta,
|
2079 |
+
$wpdb->links,
|
2080 |
+
$wpdb->terms,
|
2081 |
+
$wpdb->term_taxonomy,
|
2082 |
+
$wpdb->term_relationships
|
2083 |
+
);
|
2084 |
+
|
2085 |
+
$showTables = mysql_list_tables( DB_NAME );
|
2086 |
+
|
2087 |
+
$finalTables = array();
|
2088 |
+
|
2089 |
+
while ( $table = mysql_fetch_row( $showTables ) ) {
|
2090 |
+
if ( !$pods_tables && 0 === ( strpos( $table[ 0 ], $wpdb->prefix . rtrim( self::$prefix, '_' ) ) ) ) // don't include pods tables
|
2091 |
+
continue;
|
2092 |
+
elseif ( !$wp_core && in_array( $table[ 0 ], $core_wp_tables ) )
|
2093 |
+
continue;
|
2094 |
+
else
|
2095 |
+
$finalTables[] = $table[ 0 ];
|
2096 |
+
}
|
2097 |
+
|
2098 |
+
return $finalTables;
|
2099 |
+
}
|
2100 |
+
|
2101 |
+
/**
|
2102 |
+
* Gets column information from a table
|
2103 |
+
*
|
2104 |
+
* @param string $table Table Name
|
2105 |
+
*
|
2106 |
+
* @return array
|
2107 |
+
*
|
2108 |
+
* @since 2.0
|
2109 |
+
*/
|
2110 |
+
public static function get_table_columns ( $table ) {
|
2111 |
+
global $wpdb;
|
2112 |
+
|
2113 |
+
self::query( "SHOW COLUMNS FROM `{$table}` " );
|
2114 |
+
|
2115 |
+
$table_columns = $wpdb->last_result;
|
2116 |
+
|
2117 |
+
$table_cols_and_types = array();
|
2118 |
+
|
2119 |
+
foreach ( $table_columns as $table_col ) {
|
2120 |
+
// Get only the type, not the attributes
|
2121 |
+
if ( false === strpos( $table_col->Type, '(' ) )
|
2122 |
+
$modified_type = $table_col->Type;
|
2123 |
+
else
|
2124 |
+
$modified_type = substr( $table_col->Type, 0, ( strpos( $table_col->Type, '(' ) ) );
|
2125 |
+
|
2126 |
+
$table_cols_and_types[ $table_col->Field ] = $modified_type;
|
2127 |
+
}
|
2128 |
+
|
2129 |
+
return $table_cols_and_types;
|
2130 |
+
}
|
2131 |
+
|
2132 |
+
/**
|
2133 |
+
* Gets column data information from a table
|
2134 |
+
*
|
2135 |
+
* @param string $column_name Column name
|
2136 |
+
* @param string $table Table name
|
2137 |
+
*
|
2138 |
+
* @return array
|
2139 |
+
*
|
2140 |
+
* @since 2.0
|
2141 |
+
*/
|
2142 |
+
public static function get_column_data ( $column_name, $table ) {
|
2143 |
+
$describe_data = mysql_query( 'DESCRIBE ' . $table );
|
2144 |
+
|
2145 |
+
$column_data = array();
|
2146 |
+
|
2147 |
+
while ( $column_row = mysql_fetch_assoc( $describe_data ) ) {
|
2148 |
+
$column_data[] = $column_row;
|
2149 |
+
}
|
2150 |
+
|
2151 |
+
foreach ( $column_data as $single_column ) {
|
2152 |
+
if ( $column_name == $single_column[ 'Field' ] )
|
2153 |
+
return $single_column;
|
2154 |
+
}
|
2155 |
+
|
2156 |
+
return $column_data;
|
2157 |
+
}
|
2158 |
+
|
2159 |
+
/**
|
2160 |
+
* Prepare values for the DB
|
2161 |
+
*
|
2162 |
+
* @param string $sql SQL to prepare
|
2163 |
+
* @param array $data Data to add to the sql prepare statement
|
2164 |
+
*
|
2165 |
+
* @return bool|null|string
|
2166 |
+
*
|
2167 |
+
* @since 2.0
|
2168 |
+
*/
|
2169 |
+
public static function prepare ( $sql, $data ) {
|
2170 |
+
/**
|
2171 |
+
* @var $wpdb wpdb
|
2172 |
+
*/
|
2173 |
+
global $wpdb;
|
2174 |
+
list( $sql, $data ) = self::do_hook( 'prepare', array( $sql, $data ) );
|
2175 |
+
return $wpdb->prepare( $sql, $data );
|
2176 |
+
}
|
2177 |
+
|
2178 |
+
/**
|
2179 |
+
* Get the string to use in a query for WHERE/HAVING, uses WP_Query meta_query arguments
|
2180 |
+
*
|
2181 |
+
* @param array $fields Array of field matches for querying
|
2182 |
+
* @param array $pod Related Pod
|
2183 |
+
* @param object $params Parameters passed from select()
|
2184 |
+
*
|
2185 |
+
* @return string|null Query string for WHERE/HAVING
|
2186 |
+
*
|
2187 |
+
* @static
|
2188 |
+
* @since 2.3
|
2189 |
+
*/
|
2190 |
+
public static function query_fields ( $fields, $pod = null, &$params = null ) {
|
2191 |
+
$query_fields = array();
|
2192 |
+
|
2193 |
+
if ( !is_object( $params ) ) {
|
2194 |
+
$params = new stdClass();
|
2195 |
+
}
|
2196 |
+
|
2197 |
+
if ( !isset( $params->query_field_level ) || 0 == $params->query_field_level ) {
|
2198 |
+
$params->query_fields = array();
|
2199 |
+
$params->query_field_syntax = false;
|
2200 |
+
$params->query_field_level = 1;
|
2201 |
+
|
2202 |
+
if ( !isset( $params->where_default ) ) {
|
2203 |
+
$params->where_default = array();
|
2204 |
+
}
|
2205 |
+
|
2206 |
+
if ( !isset( $params->where_defaulted ) ) {
|
2207 |
+
$params->where_defaulted = false;
|
2208 |
+
}
|
2209 |
+
}
|
2210 |
+
|
2211 |
+
$current_level = $params->query_field_level;
|
2212 |
+
|
2213 |
+
$relation = 'AND';
|
2214 |
+
|
2215 |
+
if ( isset( $fields[ 'relation' ] ) ) {
|
2216 |
+
$relation = strtoupper( trim( pods_var( 'relation', $fields, 'AND', null, true ) ) );
|
2217 |
+
|
2218 |
+
if ( 'AND' != $relation )
|
2219 |
+
$relation = 'OR';
|
2220 |
+
|
2221 |
+
unset( $fields[ 'relation' ] );
|
2222 |
+
}
|
2223 |
+
|
2224 |
+
foreach ( $fields as $field => $match ) {
|
2225 |
+
if ( is_array( $match ) && isset( $match[ 'relation' ] ) ) {
|
2226 |
+
$params->query_field_level = $current_level + 1;
|
2227 |
+
|
2228 |
+
$query_field = self::query_fields( $match, $pod, $params );
|
2229 |
+
|
2230 |
+
$params->query_field_level = $current_level;
|
2231 |
+
|
2232 |
+
if ( !empty( $query_field ) ) {
|
2233 |
+
$query_fields[] = $query_field;
|
2234 |
+
}
|
2235 |
+
}
|
2236 |
+
else {
|
2237 |
+
$query_field = self::query_field( $field, $match, $pod, $params );
|
2238 |
+
|
2239 |
+
if ( !empty( $query_field ) ) {
|
2240 |
+
$query_fields[] = $query_field;
|
2241 |
+
}
|
2242 |
+
}
|
2243 |
+
}
|
2244 |
+
|
2245 |
+
if ( !empty( $query_fields ) ) {
|
2246 |
+
// If post_status not sent, detect it
|
2247 |
+
if ( !empty( $pod ) && 'post_type' == $pod[ 'type' ] && 1 == $current_level && !$params->where_defaulted && !empty( $params->where_default ) ) {
|
2248 |
+
$post_status_found = false;
|
2249 |
+
|
2250 |
+
if ( !$params->query_field_syntax ) {
|
2251 |
+
$haystack = implode( ' ', (array) $query_fields );
|
2252 |
+
$haystack = preg_replace( '/\s/', ' ', $haystack );
|
2253 |
+
$haystack = preg_replace( '/\w\(/', ' ', $haystack );
|
2254 |
+
$haystack = str_replace( array( '(', ')', ' ', '\\\'', "\\\"" ), ' ', $haystack );
|
2255 |
+
|
2256 |
+
preg_match_all( '/`?[\w]+`?(?:\\.`?[\w]+`?)+(?=[^"\']*(?:"[^"]*"[^"]*|\'[^\']*\'[^\']*)*$)/', $haystack, $found, PREG_PATTERN_ORDER );
|
2257 |
+
|
2258 |
+
$found = (array) @current( $found );
|
2259 |
+
|
2260 |
+
foreach ( $found as $value ) {
|
2261 |
+
$value = str_replace( '`', '', $value );
|
2262 |
+
$value = explode( '.', $value );
|
2263 |
+
|
2264 |
+
if ( ( 'post_status' == $value[ 0 ] && 1 == count( $value ) ) || ( 2 == count( $value ) && 't' == $value[ 0 ] && 'post_status' == $value[ 1 ] ) ) {
|
2265 |
+
$post_status_found = true;
|
2266 |
+
|
2267 |
+
break;
|
2268 |
+
}
|
2269 |
+
}
|
2270 |
+
}
|
2271 |
+
elseif ( !empty( $params->query_fields ) && in_array( 'post_status', $params->query_fields ) ) {
|
2272 |
+
$post_status_found = true;
|
2273 |
+
}
|
2274 |
+
|
2275 |
+
if ( !$post_status_found ) {
|
2276 |
+
$query_fields[] = $params->where_default;
|
2277 |
+
}
|
2278 |
+
}
|
2279 |
+
|
2280 |
+
if ( 1 < count( $query_fields ) )
|
2281 |
+
$query_fields = '( ( ' . implode( ' ) ' . $relation . ' ( ', $query_fields ) . ' ) )';
|
2282 |
+
else
|
2283 |
+
$query_fields = '( ' . implode( ' ' . $relation . ' ', $query_fields ) . ' )';
|
2284 |
+
}
|
2285 |
+
else
|
2286 |
+
$query_fields = null;
|
2287 |
+
|
2288 |
+
// query_fields level complete
|
2289 |
+
if ( 1 == $params->query_field_level ) {
|
2290 |
+
$params->query_field_level = 0;
|
2291 |
+
}
|
2292 |
+
|
2293 |
+
return $query_fields;
|
2294 |
+
}
|
2295 |
+
|
2296 |
+
/**
|
2297 |
+
* Get the string to use in a query for matching, uses WP_Query meta_query arguments
|
2298 |
+
*
|
2299 |
+
* @param string|int $field Field name or array index
|
2300 |
+
* @param array|string $q Query array (meta_query) or string for matching
|
2301 |
+
* @param array $pod Related Pod
|
2302 |
+
* @param object $params Parameters passed from select()
|
2303 |
+
*
|
2304 |
+
* @return string|null Query field string
|
2305 |
+
*
|
2306 |
+
* @see PodsData::query_fields
|
2307 |
+
* @static
|
2308 |
+
* @since 2.3
|
2309 |
+
*/
|
2310 |
+
public static function query_field ( $field, $q, $pod = null, &$params = null ) {
|
2311 |
+
global $wpdb;
|
2312 |
+
|
2313 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
2314 |
+
|
2315 |
+
$field_query = null;
|
2316 |
+
|
2317 |
+
// Plain queries
|
2318 |
+
if ( is_numeric( $field ) && !is_array( $q ) ) {
|
2319 |
+
return $q;
|
2320 |
+
}
|
2321 |
+
// key => value queries (backwards compatibility)
|
2322 |
+
elseif ( !is_numeric( $field ) && ( !is_array( $q ) || ( !isset( $q[ 'key' ] ) && !isset( $q[ 'field' ] ) ) ) ) {
|
2323 |
+
$new_q = array(
|
2324 |
+
'field' => $field,
|
2325 |
+
'compare' => pods_var_raw( 'compare', $q, '=', null, true ),
|
2326 |
+
'value' => pods_var_raw( 'value', $q, $q, null, true ),
|
2327 |
+
'sanitize' => pods_var_raw( 'sanitize', $q, true ),
|
2328 |
+
'sanitize_format' => pods_var_raw( 'sanitize_format', $q ),
|
2329 |
+
'cast' => pods_var_raw( 'cast', $q )
|
2330 |
+
);
|
2331 |
+
|
2332 |
+
if ( is_array( $new_q[ 'value' ] ) ) {
|
2333 |
+
if ( '=' == $new_q[ 'compare' ] )
|
2334 |
+
$new_q[ 'compare' ] = 'IN';
|
2335 |
+
|
2336 |
+
if ( isset( $new_q[ 'value' ][ 'compare' ] ) )
|
2337 |
+
unset( $new_q[ 'value' ][ 'compare' ] );
|
2338 |
+
}
|
2339 |
+
|
2340 |
+
$q = $new_q;
|
2341 |
+
}
|
2342 |
+
|
2343 |
+
$field_name = trim( pods_var_raw( 'field', $q, pods_var_raw( 'key', $q, $field, null, true ), null, true ) );
|
2344 |
+
$field_type = strtoupper( trim( pods_var_raw( 'type', $q, 'CHAR', null, true ) ) );
|
2345 |
+
$field_value = pods_var_raw( 'value', $q );
|
2346 |
+
$field_compare = strtoupper( trim( pods_var_raw( 'compare', $q, ( is_array( $field_value ? 'IN' : '=' ) ), null, true ) ) );
|
2347 |
+
$field_sanitize = (boolean) pods_var( 'sanitize', $q, true );
|
2348 |
+
$field_sanitize_format = pods_var_raw( 'sanitize_format', $q, null, null, true );
|
2349 |
+
$field_cast = pods_var_raw( 'cast', $q, null, null, true );
|
2350 |
+
|
2351 |
+
if ( is_object( $params ) ) {
|
2352 |
+
$params->meta_query_syntax = true;
|
2353 |
+
$params->query_fields[] = $field_name;
|
2354 |
+
}
|
2355 |
+
|
2356 |
+
// Deprecated WP type
|
2357 |
+
if ( 'NUMERIC' == $field_type )
|
2358 |
+
$field_type = 'SIGNED';
|
2359 |
+
// Restrict to supported types
|
2360 |
+
elseif ( !in_array( $field_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )
|
2361 |
+
$field_type = 'CHAR';
|
2362 |
+
|
2363 |
+
// Alias / Casting
|
2364 |
+
if ( empty( $field_cast ) ) {
|
2365 |
+
// Setup field casting from field name
|
2366 |
+
if ( false === strpos( $field_name, '`' ) && false === strpos( $field_name, '(' ) && false === strpos( $field_name, ' ' ) ) {
|
2367 |
+
// Handle field naming if Pod-based
|
2368 |
+
if ( !empty( $pod ) && false === strpos( $field_name, '.' ) ) {
|
2369 |
+
$field_cast = '';
|
2370 |
+
|
2371 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
2372 |
+
|
2373 |
+
if ( isset( $pod[ 'fields' ][ $field_name ] ) && in_array( $pod[ 'fields' ][ $field_name ][ 'type' ], $tableless_field_types ) ) {
|
2374 |
+
if ( in_array( $pod[ 'fields' ][ $field_name ][ 'pick_object' ], $simple_tableless_objects ) ) {
|
2375 |
+
if ( 'table' == $pod[ 'storage' ] )
|
2376 |
+
$field_cast = "`t`.`{$field_name}`";
|
2377 |
+
else
|
2378 |
+
$field_cast = "`{$field_name}`.`meta_value`";
|
2379 |
+
}
|
2380 |
+
else {
|
2381 |
+
$table = pods_api()->get_table_info( $pod[ 'fields' ][ $field_name ][ 'pick_object' ], $pod[ 'fields' ][ $field_name ][ 'pick_val' ] );
|
2382 |
+
|
2383 |
+
if ( !empty( $table ) )
|
2384 |
+
$field_cast = "`{$field_name}`.`" . $table[ 'field_index' ] . '`';
|
2385 |
+
}
|
2386 |
+
}
|
2387 |
+
|
2388 |
+
if ( empty( $field_cast ) ) {
|
2389 |
+
if ( !in_array( $pod[ 'type' ], array( 'pod', 'table' ) ) ) {
|
2390 |
+
if ( isset( $pod[ 'object_fields' ][ $field_name ] ) )
|
2391 |
+
$field_cast = "`t`.`{$field_name}`";
|
2392 |
+
elseif ( isset( $pod[ 'fields' ][ $field_name ] ) ) {
|
2393 |
+
if ( 'table' == $pod[ 'storage' ] )
|
2394 |
+
$field_cast = "`d`.`{$field_name}`";
|
2395 |
+
else
|
2396 |
+
$field_cast = "`{$field_name}`.`meta_value`";
|
2397 |
+
}
|
2398 |
+
else {
|
2399 |
+
foreach ( $pod[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
2400 |
+
if ( $object_field == $field_name || in_array( $field_name, $object_field_opt[ 'alias' ] ) ) {
|
2401 |
+
$field_cast = "`t`.`{$object_field}`";
|
2402 |
+
|
2403 |
+
break;
|
2404 |
+
}
|
2405 |
+
}
|
2406 |
+
}
|
2407 |
+
}
|
2408 |
+
elseif ( isset( $pod[ 'fields' ][ $field_name ] ) ) {
|
2409 |
+
if ( 'table' == $pod[ 'storage' ] )
|
2410 |
+
$field_cast = "`t`.`{$field_name}`";
|
2411 |
+
else
|
2412 |
+
$field_cast = "`{$field_name}`.`meta_value`";
|
2413 |
+
}
|
2414 |
+
|
2415 |
+
if ( empty( $field_cast ) ) {
|
2416 |
+
if ( 'table' == $pod[ 'storage' ] )
|
2417 |
+
$field_cast = "`{$field_name}`";
|
2418 |
+
else
|
2419 |
+
$field_cast = "`{$field_name}`.`meta_value`";
|
2420 |
+
}
|
2421 |
+
}
|
2422 |
+
}
|
2423 |
+
else {
|
2424 |
+
$field_cast = '`' . str_replace( '.', '`.`', $field_name ) . '`';
|
2425 |
+
}
|
2426 |
+
}
|
2427 |
+
else {
|
2428 |
+
$field_cast = $field_name;
|
2429 |
+
}
|
2430 |
+
|
2431 |
+
// Cast field if needed
|
2432 |
+
if ( 'CHAR' != $field_type ) {
|
2433 |
+
$field_cast = 'CAST( ' . $field_cast . ' AS ' . $field_type .' )';
|
2434 |
+
}
|
2435 |
+
}
|
2436 |
+
|
2437 |
+
// Setup string sanitizing for $wpdb->prepare()
|
2438 |
+
if ( empty( $field_sanitize_format ) ) {
|
2439 |
+
// Sanitize as string
|
2440 |
+
$field_sanitize_format = '%s';
|
2441 |
+
|
2442 |
+
// Sanitize as integer if needed
|
2443 |
+
if ( in_array( $field_type, array( 'UNSIGNED', 'SIGNED' ) ) )
|
2444 |
+
$field_sanitize_format = '%d';
|
2445 |
+
}
|
2446 |
+
|
2447 |
+
// Restrict to supported comparisons
|
2448 |
+
if ( !in_array( $field_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS', 'NOT EXISTS', 'REGEXP', 'NOT REGEXP', 'RLIKE' ) ) )
|
2449 |
+
$field_compare = '=';
|
2450 |
+
|
2451 |
+
// Restrict to supported array comparisons
|
2452 |
+
if ( is_array( $field_value ) && !in_array( $field_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
|
2453 |
+
if ( in_array( $field_compare, array( '!=', 'NOT LIKE' ) ) )
|
2454 |
+
$field_compare = 'NOT IN';
|
2455 |
+
else
|
2456 |
+
$field_compare = 'IN';
|
2457 |
+
}
|
2458 |
+
// Restrict to supported string comparisons
|
2459 |
+
elseif ( !is_array( $field_value ) && in_array( $field_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
|
2460 |
+
$check_value = preg_split( '/[,\s]+/', $field_value );
|
2461 |
+
|
2462 |
+
if ( 1 < count( $check_value ) )
|
2463 |
+
$field_value = $check_value;
|
2464 |
+
elseif ( in_array( $field_compare, array( 'NOT IN', 'NOT BETWEEN' ) ) )
|
2465 |
+
$field_compare = '!=';
|
2466 |
+
else
|
2467 |
+
$field_compare = '=';
|
2468 |
+
}
|
2469 |
+
|
2470 |
+
// Restrict to two values, force = and != if only one value provided
|
2471 |
+
if ( in_array( $field_compare, array( 'BETWEEN', 'NOT BETWEEN' ) ) ) {
|
2472 |
+
$field_value = array_values( array_slice( $field_value, 0, 2 ) );
|
2473 |
+
|
2474 |
+
if ( 1 == count( $field_value ) ) {
|
2475 |
+
if ( 'NOT IN' == $field_compare )
|
2476 |
+
$field_compare = '!=';
|
2477 |
+
else
|
2478 |
+
$field_compare = '=';
|
2479 |
+
}
|
2480 |
+
}
|
2481 |
+
|
2482 |
+
// Empty array handling
|
2483 |
+
if ( in_array( $field_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) && empty( $field_value ) ) {
|
2484 |
+
$field_compare = 'EXISTS';
|
2485 |
+
}
|
2486 |
+
|
2487 |
+
// Rebuild $q
|
2488 |
+
$q = array(
|
2489 |
+
'field' => $field_name,
|
2490 |
+
'type' => $field_type,
|
2491 |
+
'value' => $field_value,
|
2492 |
+
'compare' => $field_compare,
|
2493 |
+
'sanitize' => $field_sanitize,
|
2494 |
+
'sanitize_format' => $field_sanitize_format,
|
2495 |
+
'cast' => $field_cast
|
2496 |
+
);
|
2497 |
+
|
2498 |
+
// Make the query
|
2499 |
+
if ( in_array( $field_compare, array( '=', '!=', '>', '>=', '<', '<=', 'REGEXP', 'NOT REGEXP', 'RLIKE' ) ) ) {
|
2500 |
+
if ( $field_sanitize ) {
|
2501 |
+
$field_query = $wpdb->prepare( $field_cast . ' ' . $field_compare . ' ' . $field_sanitize_format, $field_value );
|
2502 |
+
}
|
2503 |
+
else {
|
2504 |
+
$field_query = $field_cast . ' ' . $field_compare . ' "' . $field_value . '"';
|
2505 |
+
}
|
2506 |
+
}
|
2507 |
+
elseif ( in_array( $field_compare, array( 'LIKE', 'NOT LIKE' ) ) ) {
|
2508 |
+
if ( $field_sanitize ) {
|
2509 |
+
$field_query = $field_cast . ' ' . $field_compare . ' "%' . pods_sanitize_like( $field_value ) . '%"';
|
2510 |
+
}
|
2511 |
+
else {
|
2512 |
+
$field_query = $field_cast . ' ' . $field_compare . ' "' . $field_value . '"';
|
2513 |
+
}
|
2514 |
+
}
|
2515 |
+
elseif ( in_array( $field_compare, array( 'IN', 'NOT IN' ) ) ) {
|
2516 |
+
if ( $field_sanitize ) {
|
2517 |
+
$field_query = $wpdb->prepare( $field_cast . ' ' . $field_compare . ' ( ' . substr( str_repeat( ', ' . $field_sanitize_format, count( $field_value ) ), 1 ) . ' )', $field_value );
|
2518 |
+
}
|
2519 |
+
else {
|
2520 |
+
$field_query = $field_cast . ' ' . $field_compare . ' ( "' . implode( '", "', $field_value ) . '" )';
|
2521 |
+
}
|
2522 |
+
}
|
2523 |
+
elseif ( in_array( $field_compare, array( 'BETWEEN', 'NOT BETWEEN' ) ) ) {
|
2524 |
+
if ( $field_sanitize ) {
|
2525 |
+
$field_query = $wpdb->prepare( $field_cast . ' ' . $field_compare . ' ' . $field_sanitize_format . ' AND ' . $field_sanitize_format, $field_value );
|
2526 |
+
}
|
2527 |
+
else {
|
2528 |
+
$field_query = $field_cast . ' ' . $field_compare . ' "' . $field_value[ 0 ] . '" AND "' . $field_value[ 1 ] . '"';
|
2529 |
+
}
|
2530 |
+
}
|
2531 |
+
elseif ( 'EXISTS' == $field_compare )
|
2532 |
+
$field_query = $field_cast . ' IS NOT NULL';
|
2533 |
+
elseif ( 'NOT EXISTS' == $field_compare )
|
2534 |
+
$field_query = $field_cast . ' IS NULL';
|
2535 |
+
|
2536 |
+
$field_query = apply_filters( 'pods_data_field_query', $field_query, $q );
|
2537 |
+
|
2538 |
+
return $field_query;
|
2539 |
+
}
|
2540 |
+
|
2541 |
+
/**
|
2542 |
+
* Setup fields for traversal
|
2543 |
+
*
|
2544 |
+
* @param array $fields Associative array of fields data
|
2545 |
+
*
|
2546 |
+
* @return array Traverse feed
|
2547 |
+
* @param object $params (optional) Parameters from build()
|
2548 |
+
*
|
2549 |
+
* @since 2.0
|
2550 |
+
*/
|
2551 |
+
function traverse_build ( $fields = null, $params = null ) {
|
2552 |
+
if ( null === $fields )
|
2553 |
+
$fields = $this->fields;
|
2554 |
+
|
2555 |
+
$feed = array();
|
2556 |
+
|
2557 |
+
foreach ( $fields as $field => $data ) {
|
2558 |
+
if ( !is_array( $data ) )
|
2559 |
+
$field = $data;
|
2560 |
+
|
2561 |
+
if ( !isset( $_GET[ 'filter_' . $field ] ) )
|
2562 |
+
continue;
|
2563 |
+
|
2564 |
+
$field_value = pods_var( 'filter_' . $field, 'get', false, null, true );
|
2565 |
+
|
2566 |
+
if ( !empty( $field_value ) || 0 < strlen( $field_value ) )
|
2567 |
+
$feed[ 'traverse_' . $field ] = array( $field );
|
2568 |
+
}
|
2569 |
+
|
2570 |
+
return $feed;
|
2571 |
+
}
|
2572 |
+
|
2573 |
+
/**
|
2574 |
+
* Recursively join tables based on fields
|
2575 |
+
*
|
2576 |
+
* @param array $traverse_recurse Array of traversal options
|
2577 |
+
*
|
2578 |
+
* @return array Array of table joins
|
2579 |
+
*
|
2580 |
+
* @since 2.0
|
2581 |
+
*/
|
2582 |
+
function traverse_recurse ( $traverse_recurse ) {
|
2583 |
+
global $wpdb;
|
2584 |
+
|
2585 |
+
$defaults = array(
|
2586 |
+
'pod' => null,
|
2587 |
+
'fields' => array(),
|
2588 |
+
'joined' => 't',
|
2589 |
+
'depth' => 0,
|
2590 |
+
'joined_id' => 'id',
|
2591 |
+
'joined_index' => 'id',
|
2592 |
+
'params' => new stdClass(),
|
2593 |
+
'last_table_info' => array()
|
2594 |
+
);
|
2595 |
+
|
2596 |
+
$traverse_recurse = array_merge( $defaults, $traverse_recurse );
|
2597 |
+
|
2598 |
+
$joins = array();
|
2599 |
+
|
2600 |
+
if ( 0 == $traverse_recurse[ 'depth' ] && !empty( $traverse_recurse[ 'pod' ] ) && !empty( $traverse_recurse [ 'last_table_info' ] ) && isset( $traverse_recurse [ 'last_table_info' ][ 'id' ] ) )
|
2601 |
+
$pod_data = $traverse_recurse [ 'last_table_info' ];
|
2602 |
+
elseif ( empty( $traverse_recurse[ 'pod' ] ) ) {
|
2603 |
+
if ( !empty( $traverse_recurse[ 'params' ] ) && !empty( $traverse_recurse[ 'params' ]->table ) && 0 === strpos( $traverse_recurse[ 'params' ]->table, $wpdb->prefix ) ) {
|
2604 |
+
if ( $wpdb->posts == $traverse_recurse[ 'params' ]->table )
|
2605 |
+
$traverse_recurse[ 'pod' ] = 'post_type';
|
2606 |
+
elseif ( $wpdb->terms == $traverse_recurse[ 'params' ]->table )
|
2607 |
+
$traverse_recurse[ 'pod' ] = 'taxonomy';
|
2608 |
+
elseif ( $wpdb->users == $traverse_recurse[ 'params' ]->table )
|
2609 |
+
$traverse_recurse[ 'pod' ] = 'user';
|
2610 |
+
elseif ( $wpdb->comments == $traverse_recurse[ 'params' ]->table )
|
2611 |
+
$traverse_recurse[ 'pod' ] = 'comment';
|
2612 |
+
else
|
2613 |
+
return $joins;
|
2614 |
+
|
2615 |
+
$pod_data = array();
|
2616 |
+
|
2617 |
+
if ( in_array( $traverse_recurse[ 'pod' ], array( 'user', 'comment' ) ) ) {
|
2618 |
+
$pod = $this->api->load_pod( array( 'name' => $traverse_recurse[ 'pod' ], 'table_info' => true ) );
|
2619 |
+
|
2620 |
+
if ( !empty( $pod ) && $pod[ 'type' ] == $pod )
|
2621 |
+
$pod_data = $pod;
|
2622 |
+
}
|
2623 |
+
|
2624 |
+
if ( empty( $pod_data ) ) {
|
2625 |
+
$pod_data = array(
|
2626 |
+
'id' => 0,
|
2627 |
+
'name' => '_table_' . $traverse_recurse[ 'pod' ],
|
2628 |
+
'type' => $traverse_recurse[ 'pod' ],
|
2629 |
+
'storage' => ( 'taxonomy' == $traverse_recurse[ 'pod' ] ? 'none' : 'meta' ),
|
2630 |
+
'fields' => array(),
|
2631 |
+
'object_fields' => $this->api->get_wp_object_fields( $traverse_recurse[ 'pod' ] )
|
2632 |
+
);
|
2633 |
+
|
2634 |
+
$pod_data = array_merge( $this->api->get_table_info( $traverse_recurse[ 'pod' ], '' ), $pod_data );
|
2635 |
+
}
|
2636 |
+
|
2637 |
+
$traverse_recurse[ 'pod' ] = $pod_data[ 'name' ];
|
2638 |
+
}
|
2639 |
+
else
|
2640 |
+
return $joins;
|
2641 |
+
}
|
2642 |
+
else {
|
2643 |
+
$pod_data = $this->api->load_pod( array( 'name' => $traverse_recurse[ 'pod' ], 'table_info' => true ), false );
|
2644 |
+
|
2645 |
+
if ( empty( $pod_data ) )
|
2646 |
+
return $joins;
|
2647 |
+
}
|
2648 |
+
|
2649 |
+
if ( isset( $pod_data[ 'object_fields' ] ) ) {
|
2650 |
+
$pod_data[ 'fields' ] = array_merge( $pod_data[ 'fields' ], $pod_data[ 'object_fields' ] );
|
2651 |
+
}
|
2652 |
+
|
2653 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
2654 |
+
$simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
|
2655 |
+
$file_field_types = PodsForm::file_field_types();
|
2656 |
+
|
2657 |
+
if ( !isset( $this->traversal[ $traverse_recurse[ 'pod' ] ] ) )
|
2658 |
+
$this->traversal[ $traverse_recurse[ 'pod' ] ] = array();
|
2659 |
+
|
2660 |
+
if ( ( empty( $pod_data[ 'meta_table' ] ) || $pod_data[ 'meta_table' ] == $pod_data[ 'table' ] ) && ( empty( $traverse_recurse[ 'fields' ] ) || !isset( $traverse_recurse[ 'fields' ][ $traverse_recurse[ 'depth' ] ] ) || empty( $traverse_recurse[ 'fields' ][ $traverse_recurse[ 'depth' ] ] ) ) )
|
2661 |
+
return $joins;
|
2662 |
+
|
2663 |
+
$field = $traverse_recurse[ 'fields' ][ $traverse_recurse[ 'depth' ] ];
|
2664 |
+
|
2665 |
+
$ignore_aliases = array(
|
2666 |
+
'wpml_languages',
|
2667 |
+
'polylang_languages'
|
2668 |
+
);
|
2669 |
+
|
2670 |
+
$ignore_aliases = $this->do_hook( 'traverse_recurse_ignore_aliases', $ignore_aliases, $field, $traverse_recurse );
|
2671 |
+
|
2672 |
+
if ( in_array( $field, $ignore_aliases ) )
|
2673 |
+
return $joins;
|
2674 |
+
|
2675 |
+
$meta_data_table = false;
|
2676 |
+
|
2677 |
+
if ( !isset( $pod_data[ 'fields' ][ $field ] ) && 'd' == $field && isset( $traverse_recurse[ 'fields' ][ $traverse_recurse[ 'depth' ] - 1 ] ) ) {
|
2678 |
+
$field = $traverse_recurse[ 'fields' ][ $traverse_recurse[ 'depth' ] - 1 ];
|
2679 |
+
|
2680 |
+
$field_type = 'pick';
|
2681 |
+
|
2682 |
+
if ( isset( $traverse_recurse[ 'last_table_info' ][ 'pod' ][ 'fields' ][ $field ] ) ) {
|
2683 |
+
$field_type = $traverse_recurse[ 'last_table_info' ][ 'pod' ][ 'fields' ][ $field ][ 'type' ];
|
2684 |
+
}
|
2685 |
+
elseif ( isset( $traverse_recurse[ 'last_table_info' ][ 'pod' ][ 'object_fields' ][ $field ] ) ) {
|
2686 |
+
$field_type = $traverse_recurse[ 'last_table_info' ][ 'pod' ][ 'object_fields' ][ $field ][ 'type' ];
|
2687 |
+
}
|
2688 |
+
|
2689 |
+
$pod_data[ 'fields' ][ $field ] = array(
|
2690 |
+
'id' => 0,
|
2691 |
+
'name' => $field,
|
2692 |
+
'type' => $field_type,
|
2693 |
+
'pick_object' => $traverse_recurse[ 'last_table_info' ][ 'pod' ][ 'type' ],
|
2694 |
+
'pick_val' => $traverse_recurse[ 'last_table_info' ][ 'pod' ][ 'name' ]
|
2695 |
+
);
|
2696 |
+
|
2697 |
+
$meta_data_table = true;
|
2698 |
+
}
|
2699 |
+
|
2700 |
+
// Fallback to meta table if the pod type supports it
|
2701 |
+
if ( !isset( $pod_data[ 'fields' ][ $field ] ) ) {
|
2702 |
+
$last = end( $traverse_recurse[ 'fields' ] );
|
2703 |
+
|
2704 |
+
if ( 'post_type' == $pod_data[ 'type' ] && !isset( $pod_data[ 'object_fields' ] ) )
|
2705 |
+
$pod_data[ 'object_fields' ] = $this->api->get_wp_object_fields( 'post_type', $pod_data );
|
2706 |
+
|
2707 |
+
if ( 'post_type' == $pod_data[ 'type' ] && isset( $pod_data[ 'object_fields'][ $field ] ) && in_array( $pod_data[ 'object_fields' ][ $field ][ 'type' ], $tableless_field_types ) )
|
2708 |
+
$pod_data[ 'fields' ][ $field ] = $pod_data[ 'object_fields' ][ $field ];
|
2709 |
+
elseif ( in_array( $pod_data[ 'type' ], array( 'post_type', 'media', 'user', 'comment' ) ) && 'meta_value' == $last )
|
2710 |
+
$pod_data[ 'fields' ][ $field ] = PodsForm::field_setup( array( 'name' => $field ) );
|
2711 |
+
else {
|
2712 |
+
if ( 'post_type' == $pod_data[ 'type' ] ) {
|
2713 |
+
$pod_data[ 'object_fields' ] = $this->api->get_wp_object_fields( 'post_type', $pod_data, true );
|
2714 |
+
|
2715 |
+
if ( 'post_type' == $pod_data[ 'type' ] && isset( $pod_data[ 'object_fields' ][ $field ] ) && in_array( $pod_data[ 'object_fields' ][ $field ][ 'type' ], $tableless_field_types ) )
|
2716 |
+
$pod_data[ 'fields' ][ $field ] = $pod_data[ 'object_fields' ][ $field ];
|
2717 |
+
else
|
2718 |
+
return $joins;
|
2719 |
+
}
|
2720 |
+
else
|
2721 |
+
return $joins;
|
2722 |
+
}
|
2723 |
+
}
|
2724 |
+
|
2725 |
+
$traverse = $pod_data[ 'fields' ][ $field ];
|
2726 |
+
|
2727 |
+
if ( 'taxonomy' == $traverse[ 'type' ] )
|
2728 |
+
$traverse[ 'table_info' ] = $this->api->get_table_info( $traverse[ 'type' ], $traverse[ 'name' ] );
|
2729 |
+
elseif ( in_array( $traverse[ 'type' ], $file_field_types ) )
|
2730 |
+
$traverse[ 'table_info' ] = $this->api->get_table_info( 'post_type', 'attachment' );
|
2731 |
+
elseif ( !in_array( $traverse[ 'type' ], $tableless_field_types ) )
|
2732 |
+
$traverse[ 'table_info' ] = $this->api->get_table_info( $pod_data[ 'type' ], $pod_data[ 'name' ], $pod_data[ 'name' ], $pod_data );
|
2733 |
+
elseif ( empty( $traverse[ 'table_info' ] ) || ( in_array( $traverse[ 'pick_object' ], $simple_tableless_objects ) && !empty( $traverse_recurse[ 'last_table_info' ] ) ) ) {
|
2734 |
+
if ( in_array( $traverse[ 'pick_object' ], $simple_tableless_objects ) && !empty( $traverse_recurse[ 'last_table_info' ] ) ) {
|
2735 |
+
$traverse[ 'table_info' ] = $traverse_recurse[ 'last_table_info' ];
|
2736 |
+
|
2737 |
+
if ( !empty( $traverse[ 'table_info' ][ 'meta_table' ] ) )
|
2738 |
+
$meta_data_table = true;
|
2739 |
+
}
|
2740 |
+
elseif ( !in_array( $traverse[ 'type' ], $tableless_field_types ) && isset( $traverse_recurse[ 'last_table_info' ] ) && !empty( $traverse_recurse[ 'last_table_info' ] ) && 0 == $traverse_recurse[ 'depth' ] )
|
2741 |
+
$traverse[ 'table_info' ] = $traverse_recurse[ 'last_table_info' ];
|
2742 |
+
else
|
2743 |
+
$traverse[ 'table_info' ] = $this->api->get_table_info( $traverse[ 'pick_object' ], $traverse[ 'pick_val' ], null, $traverse[ 'pod' ], $traverse );
|
2744 |
+
}
|
2745 |
+
|
2746 |
+
if ( isset( $this->traversal[ $traverse_recurse[ 'pod' ] ][ $traverse[ 'name' ] ] ) )
|
2747 |
+
$traverse = array_merge( $traverse, (array) $this->traversal[ $traverse_recurse[ 'pod' ] ][ $traverse[ 'name' ] ] );
|
2748 |
+
|
2749 |
+
$traverse = $this->do_hook( 'traverse', $traverse, compact( 'pod', 'fields', 'joined', 'depth', 'joined_id', 'params' ) );
|
2750 |
+
|
2751 |
+
if ( empty( $traverse ) )
|
2752 |
+
return $joins;
|
2753 |
+
|
2754 |
+
$traverse[ 'id' ] = (int) $traverse[ 'id' ];
|
2755 |
+
|
2756 |
+
if ( empty( $traverse[ 'id' ] ) )
|
2757 |
+
$traverse[ 'id' ] = $field;
|
2758 |
+
|
2759 |
+
$table_info = $traverse[ 'table_info' ];
|
2760 |
+
|
2761 |
+
$this->traversal[ $traverse_recurse[ 'pod' ] ][ $field ] = $traverse;
|
2762 |
+
|
2763 |
+
$field_joined = $field;
|
2764 |
+
|
2765 |
+
if ( 0 < $traverse_recurse[ 'depth' ] && 't' != $traverse_recurse[ 'joined' ] ) {
|
2766 |
+
if ( $meta_data_table && ( 'pick' != $traverse[ 'type' ] || !in_array( pods_var( 'pick_object', $traverse ), $simple_tableless_objects ) ) )
|
2767 |
+
$field_joined = $traverse_recurse[ 'joined' ] . '_d';
|
2768 |
+
else
|
2769 |
+
$field_joined = $traverse_recurse[ 'joined' ] . '_' . $field;
|
2770 |
+
}
|
2771 |
+
|
2772 |
+
$rel_alias = 'rel_' . $field_joined;
|
2773 |
+
|
2774 |
+
if ( pods_var( 'search', $traverse_recurse[ 'params' ], false ) && empty( $traverse_recurse[ 'params' ]->filters ) ) {
|
2775 |
+
if ( 0 < strlen( pods_var( 'filter_' . $field_joined, 'get' ) ) ) {
|
2776 |
+
$val = absint( pods_var( 'filter_' . $field_joined, 'get' ) );
|
2777 |
+
|
2778 |
+
$search = "`{$field_joined}`.`{$table_info[ 'field_id' ]}` = {$val}";
|
2779 |
+
|
2780 |
+
if ( 'text' == $this->search_mode ) {
|
2781 |
+
$val = pods_var( 'filter_' . $field_joined, 'get' );
|
2782 |
+
|
2783 |
+
$search = "`{$field_joined}`.`{$traverse[ 'name' ]}` = '{$val}'";
|
2784 |
+
}
|
2785 |
+
elseif ( 'text_like' == $this->search_mode ) {
|
2786 |
+
$val = pods_sanitize( pods_sanitize_like( pods_var_raw( 'filter_' . $field_joined ) ) );
|
2787 |
+
|
2788 |
+
$search = "`{$field_joined}`.`{$traverse[ 'name' ]}` LIKE '%{$val}%'";
|
2789 |
+
}
|
2790 |
+
|
2791 |
+
$this->search_where[] = " {$search} ";
|
2792 |
+
}
|
2793 |
+
}
|
2794 |
+
|
2795 |
+
$the_join = null;
|
2796 |
+
|
2797 |
+
$joined_id = $table_info[ 'field_id' ];
|
2798 |
+
$joined_index = $table_info[ 'field_index' ];
|
2799 |
+
|
2800 |
+
if ( 'taxonomy' == $traverse[ 'type' ] ) {
|
2801 |
+
$rel_tt_alias = 'rel_tt_' . $field_joined;
|
2802 |
+
|
2803 |
+
if ( $meta_data_table ) {
|
2804 |
+
$the_join = "
|
2805 |
+
LEFT JOIN `{$table_info[ 'pod_table' ]}` AS `{$field_joined}` ON
|
2806 |
+
`{$field_joined}`.`{$table_info[ 'pod_field_id' ]}` = `{$traverse_recurse[ 'rel_alias' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
|
2807 |
+
";
|
2808 |
+
}
|
2809 |
+
else {
|
2810 |
+
$the_join = "
|
2811 |
+
LEFT JOIN `{$wpdb->term_relationships}` AS `{$rel_alias}` ON
|
2812 |
+
`{$rel_alias}`.`object_id` = `{$traverse_recurse[ 'joined' ]}`.`ID`
|
2813 |
+
|
2814 |
+
LEFT JOIN `{$wpdb->term_taxonomy}` AS `{$rel_tt_alias}` ON
|
2815 |
+
`{$rel_tt_alias}`.`taxonomy` = '{$traverse[ 'name' ]}'
|
2816 |
+
AND `{$rel_tt_alias}`.`term_taxonomy_id` = `{$rel_alias}`.`term_taxonomy_id`
|
2817 |
+
|
2818 |
+
LEFT JOIN `{$table_info[ 'table' ]}` AS `{$field_joined}` ON
|
2819 |
+
`{$field_joined}`.`{$table_info[ 'field_id' ]}` = `{$rel_tt_alias}`.`{$table_info[ 'field_id' ]}`
|
2820 |
+
";
|
2821 |
+
|
2822 |
+
// Override $rel_alias
|
2823 |
+
$rel_alias = $field_joined;
|
2824 |
+
|
2825 |
+
$joined_id = $table_info[ 'field_id' ];
|
2826 |
+
$joined_index = $table_info[ 'field_index' ];
|
2827 |
+
}
|
2828 |
+
}
|
2829 |
+
elseif ( in_array( $traverse[ 'type' ], $tableless_field_types ) && ( 'pick' != $traverse[ 'type' ] || !in_array( pods_var( 'pick_object', $traverse ), $simple_tableless_objects ) ) ) {
|
2830 |
+
if ( pods_tableless() ) {
|
2831 |
+
$the_join = "
|
2832 |
+
LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$rel_alias}` ON
|
2833 |
+
`{$rel_alias}`.`{$table_info[ 'meta_field_index' ]}` = '{$traverse[ 'name' ]}'
|
2834 |
+
AND `{$rel_alias}`.`{$table_info[ 'meta_field_id' ]}` = `{$traverse_recurse[ 'joined' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
|
2835 |
+
|
2836 |
+
LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$field_joined}` ON
|
2837 |
+
`{$field_joined}`.`{$table_info[ 'meta_field_index' ]}` = '{$traverse[ 'name' ]}'
|
2838 |
+
AND `{$field_joined}`.`{$table_info[ 'meta_field_id' ]}` = CONVERT( `{$rel_alias}`.`{$table_info[ 'meta_field_value' ]}`, SIGNED )
|
2839 |
+
";
|
2840 |
+
|
2841 |
+
$joined_id = $table_info[ 'meta_field_id' ];
|
2842 |
+
$joined_index = $table_info[ 'meta_field_index' ];
|
2843 |
+
}
|
2844 |
+
elseif ( $meta_data_table ) {
|
2845 |
+
$the_join = "
|
2846 |
+
LEFT JOIN `{$table_info[ 'pod_table' ]}` AS `{$field_joined}` ON
|
2847 |
+
`{$field_joined}`.`{$table_info[ 'pod_field_id' ]}` = `{$traverse_recurse[ 'rel_alias' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
|
2848 |
+
";
|
2849 |
+
}
|
2850 |
+
else {
|
2851 |
+
$the_join = "
|
2852 |
+
LEFT JOIN `@wp_podsrel` AS `{$rel_alias}` ON
|
2853 |
+
`{$rel_alias}`.`field_id` = {$traverse[ 'id' ]}
|
2854 |
+
AND `{$rel_alias}`.`item_id` = `{$traverse_recurse[ 'joined' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
|
2855 |
+
|
2856 |
+
LEFT JOIN `{$table_info[ 'table' ]}` AS `{$field_joined}` ON
|
2857 |
+
`{$field_joined}`.`{$table_info[ 'field_id' ]}` = `{$rel_alias}`.`related_item_id`
|
2858 |
+
";
|
2859 |
+
}
|
2860 |
+
}
|
2861 |
+
elseif ( 'meta' == $pod_data[ 'storage' ] ) {
|
2862 |
+
if (
|
2863 |
+
( $traverse_recurse[ 'depth' ] + 2 ) == count( $traverse_recurse[ 'fields' ] )
|
2864 |
+
&& ( 'pick' != $traverse[ 'type' ] || !in_array( pods_var( 'pick_object', $traverse ), $simple_tableless_objects ) )
|
2865 |
+
&& $table_info[ 'meta_field_value' ] == $traverse_recurse[ 'fields' ][ $traverse_recurse[ 'depth' ] + 1 ] ) {
|
2866 |
+
$the_join = "
|
2867 |
+
LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$field_joined}` ON
|
2868 |
+
`{$field_joined}`.`{$table_info[ 'meta_field_index' ]}` = '{$traverse[ 'name' ]}'
|
2869 |
+
AND `{$field_joined}`.`{$table_info[ 'meta_field_id' ]}` = `{$traverse_recurse[ 'joined' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
|
2870 |
+
";
|
2871 |
+
|
2872 |
+
$table_info[ 'recurse' ] = false;
|
2873 |
+
}
|
2874 |
+
else {
|
2875 |
+
$the_join = "
|
2876 |
+
LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$field_joined}` ON
|
2877 |
+
`{$field_joined}`.`{$table_info[ 'meta_field_index' ]}` = '{$traverse[ 'name' ]}'
|
2878 |
+
AND `{$field_joined}`.`{$table_info[ 'meta_field_id' ]}` = `{$traverse_recurse[ 'joined' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
|
2879 |
+
";
|
2880 |
+
|
2881 |
+
$joined_id = $table_info[ 'meta_field_id' ];
|
2882 |
+
$joined_index = $table_info[ 'meta_field_index' ];
|
2883 |
+
}
|
2884 |
+
}
|
2885 |
+
|
2886 |
+
$traverse_recursive = array(
|
2887 |
+
'pod' => pods_var_raw( 'name', pods_var_raw( 'pod', $table_info ) ),
|
2888 |
+
'fields' => $traverse_recurse[ 'fields' ],
|
2889 |
+
'joined' => $field_joined,
|
2890 |
+
'depth' => ( $traverse_recurse[ 'depth' ] + 1 ),
|
2891 |
+
'joined_id' => $joined_id,
|
2892 |
+
'joined_index' => $joined_index,
|
2893 |
+
'params' => $traverse_recurse[ 'params' ],
|
2894 |
+
'rel_alias' => $rel_alias,
|
2895 |
+
'last_table_info' => $table_info
|
2896 |
+
);
|
2897 |
+
|
2898 |
+
$the_join = $this->do_hook( 'traverse_the_join', $the_join, $traverse_recurse, $traverse_recursive );
|
2899 |
+
|
2900 |
+
if ( empty( $the_join ) )
|
2901 |
+
return $joins;
|
2902 |
+
|
2903 |
+
$joins[ $traverse_recurse[ 'pod' ] . '_' . $traverse_recurse[ 'depth' ] . '_' . $traverse[ 'id' ] ] = $the_join;
|
2904 |
+
|
2905 |
+
if ( ( $traverse_recurse[ 'depth' ] + 1 ) < count( $traverse_recurse[ 'fields' ] ) && !empty( $traverse_recurse[ 'pod' ] ) && false !== $table_info[ 'recurse' ] )
|
2906 |
+
$joins = array_merge( $joins, $this->traverse_recurse( $traverse_recursive ) );
|
2907 |
+
|
2908 |
+
return $joins;
|
2909 |
+
}
|
2910 |
+
|
2911 |
+
/**
|
2912 |
+
* Recursively join tables based on fields
|
2913 |
+
*
|
2914 |
+
* @param array $fields Fields to recurse
|
2915 |
+
* @param null $all_fields (optional) If $fields is empty then traverse all fields, argument does not need to be passed
|
2916 |
+
* @param object $params (optional) Parameters from build()
|
2917 |
+
*
|
2918 |
+
* @return array Array of joins
|
2919 |
+
*/
|
2920 |
+
function traverse ( $fields = null, $all_fields = null, $params = null ) {
|
2921 |
+
$joins = array();
|
2922 |
+
|
2923 |
+
if ( null === $fields )
|
2924 |
+
$fields = $this->traverse_build( $all_fields, $params );
|
2925 |
+
|
2926 |
+
foreach ( (array) $fields as $field_group ) {
|
2927 |
+
$traverse_recurse = array(
|
2928 |
+
'pod' => $this->pod,
|
2929 |
+
'fields' => $fields,
|
2930 |
+
'params' => $params,
|
2931 |
+
'last_table_info' => $this->pod_data,
|
2932 |
+
'joined_id' => $this->pod_data[ 'field_id' ],
|
2933 |
+
'joined_index' => $this->pod_data[ 'field_index' ]
|
2934 |
+
);
|
2935 |
+
|
2936 |
+
if ( is_array( $field_group ) ) {
|
2937 |
+
$traverse_recurse[ 'fields' ] = $field_group;
|
2938 |
+
|
2939 |
+
$joins = array_merge( $joins, $this->traverse_recurse( $traverse_recurse ) );
|
2940 |
+
}
|
2941 |
+
else {
|
2942 |
+
$joins = array_merge( $joins, $this->traverse_recurse( $traverse_recurse ) );
|
2943 |
+
$joins = array_filter( $joins );
|
2944 |
+
|
2945 |
+
return $joins;
|
2946 |
+
}
|
2947 |
+
}
|
2948 |
+
|
2949 |
+
$joins = array_filter( $joins );
|
2950 |
+
|
2951 |
+
return $joins;
|
2952 |
+
}
|
2953 |
+
|
2954 |
+
/**
|
2955 |
+
* Handle filters / actions for the class
|
2956 |
+
*
|
2957 |
+
* @since 2.0
|
2958 |
+
*/
|
2959 |
+
private static function do_hook () {
|
2960 |
+
$args = func_get_args();
|
2961 |
+
|
2962 |
+
if ( empty( $args ) )
|
2963 |
+
return false;
|
2964 |
+
|
2965 |
+
$name = array_shift( $args );
|
2966 |
+
|
2967 |
+
return pods_do_hook( 'data', $name, $args );
|
2968 |
+
}
|
2969 |
+
|
2970 |
+
/**
|
2971 |
+
* Get the complete sql
|
2972 |
+
*
|
2973 |
+
* @since 2.0.5
|
2974 |
+
*/
|
2975 |
+
public function get_sql ( $sql ) {
|
2976 |
+
global $wpdb;
|
2977 |
+
|
2978 |
+
if ( empty( $sql ) )
|
2979 |
+
$sql = $this->sql;
|
2980 |
+
|
2981 |
+
$sql = str_replace( array( '@wp_users', '@wp_' ), array( $wpdb->users, $wpdb->prefix ), $sql );
|
2982 |
+
|
2983 |
+
$s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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsField {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Whether this field is running under 1.x deprecated forms
|
9 |
+
*
|
10 |
+
* @var bool
|
11 |
+
* @since 2.0
|
12 |
+
*/
|
13 |
+
public static $deprecated = false;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Field Type Identifier
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
* @since 2.0
|
20 |
+
*/
|
21 |
+
public static $type = 'text';
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Field Type Label
|
25 |
+
*
|
26 |
+
* @var string
|
27 |
+
* @since 2.0
|
28 |
+
*/
|
29 |
+
public static $label = 'Unknown';
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Field Type Preparation
|
33 |
+
*
|
34 |
+
* @var string
|
35 |
+
* @since 2.0
|
36 |
+
*/
|
37 |
+
public static $prepare = '%s';
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Pod Types supported on (true for all, false for none, or give array of specific types supported)
|
41 |
+
*
|
42 |
+
* @var array|bool
|
43 |
+
* @since 2.1
|
44 |
+
*/
|
45 |
+
public static $pod_types = true;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* API caching for fields that need it during validate/save
|
49 |
+
*
|
50 |
+
* @var \PodsAPI
|
51 |
+
* @since 2.3
|
52 |
+
*/
|
53 |
+
private static $api = false;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Do things like register/enqueue scripts and stylesheets
|
57 |
+
*
|
58 |
+
* @return \PodsField
|
59 |
+
*
|
60 |
+
* @since 2.0
|
61 |
+
*/
|
62 |
+
public function __construct () {
|
63 |
+
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Add options and set defaults for field type, shows in admin area
|
68 |
+
*
|
69 |
+
* @return array $options
|
70 |
+
*
|
71 |
+
* @since 2.0
|
72 |
+
* @see PodsField::ui_options
|
73 |
+
*/
|
74 |
+
public function options () {
|
75 |
+
$options = array( /*
|
76 |
+
'option_name' => array(
|
77 |
+
'label' => 'Option Label',
|
78 |
+
'depends-on' => array( 'another_option' => 'specific-value' ),
|
79 |
+
'default' => 'default-value',
|
80 |
+
'type' => 'field_type',
|
81 |
+
'data' => array(
|
82 |
+
'value1' => 'Label 1',
|
83 |
+
|
84 |
+
// Group your options together
|
85 |
+
'Option Group' => array(
|
86 |
+
'gvalue1' => 'Option Label 1',
|
87 |
+
'gvalue2' => 'Option Label 2'
|
88 |
+
),
|
89 |
+
|
90 |
+
// below is only if the option_name above is the "{$fieldtype}_format_type"
|
91 |
+
'value2' => array(
|
92 |
+
'label' => 'Label 2',
|
93 |
+
'regex' => '[a-zA-Z]' // Uses JS regex validation for the value saved if this option selected
|
94 |
+
)
|
95 |
+
),
|
96 |
+
|
97 |
+
// below is only for a boolean group
|
98 |
+
'group' => array(
|
99 |
+
'option_boolean1' => array(
|
100 |
+
'label' => 'Option boolean 1?',
|
101 |
+
'default' => 1,
|
102 |
+
'type' => 'boolean'
|
103 |
+
),
|
104 |
+
'option_boolean2' => array(
|
105 |
+
'label' => 'Option boolean 2?',
|
106 |
+
'default' => 0,
|
107 |
+
'type' => 'boolean'
|
108 |
+
)
|
109 |
+
)
|
110 |
+
) */
|
111 |
+
);
|
112 |
+
|
113 |
+
return $options;
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Options for the Admin area, defaults to $this->options()
|
118 |
+
*
|
119 |
+
* @return array $options
|
120 |
+
*
|
121 |
+
* @since 2.0
|
122 |
+
* @see PodsField::options
|
123 |
+
*/
|
124 |
+
public function ui_options () {
|
125 |
+
return $this->options();
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Define the current field's schema for DB table storage
|
130 |
+
*
|
131 |
+
* @param array $options
|
132 |
+
*
|
133 |
+
* @return string
|
134 |
+
* @since 2.0
|
135 |
+
*/
|
136 |
+
public function schema ( $options = null ) {
|
137 |
+
$schema = 'VARCHAR(255)';
|
138 |
+
|
139 |
+
return $schema;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Define the current field's preparation for sprintf
|
144 |
+
*
|
145 |
+
* @param array $options
|
146 |
+
*
|
147 |
+
* @return array
|
148 |
+
* @since 2.0
|
149 |
+
*/
|
150 |
+
public function prepare ( $options = null ) {
|
151 |
+
$format = self::$prepare;
|
152 |
+
|
153 |
+
return $format;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Change the value of the field
|
158 |
+
*
|
159 |
+
* @param mixed $value
|
160 |
+
* @param string $name
|
161 |
+
* @param array $options
|
162 |
+
* @param array $pod
|
163 |
+
* @param int $id
|
164 |
+
*
|
165 |
+
* @return mixed|null|string
|
166 |
+
* @since 2.3
|
167 |
+
*/
|
168 |
+
public function value ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
|
169 |
+
return $value;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Change the way the value of the field is displayed with Pods::get
|
174 |
+
*
|
175 |
+
* @param mixed $value
|
176 |
+
* @param string $name
|
177 |
+
* @param array $options
|
178 |
+
* @param array $pod
|
179 |
+
* @param int $id
|
180 |
+
*
|
181 |
+
* @return mixed|null|string
|
182 |
+
* @since 2.0
|
183 |
+
*/
|
184 |
+
public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
|
185 |
+
return $value;
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Customize output of the form field
|
190 |
+
*
|
191 |
+
* @param string $name
|
192 |
+
* @param mixed $value
|
193 |
+
* @param array $options
|
194 |
+
* @param array $pod
|
195 |
+
* @param int $id
|
196 |
+
*
|
197 |
+
* @return void
|
198 |
+
*
|
199 |
+
* @since 2.0
|
200 |
+
*/
|
201 |
+
public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
|
202 |
+
$options = (array) $options;
|
203 |
+
$form_field_type = PodsForm::$field_type;
|
204 |
+
|
205 |
+
if ( is_array( $value ) )
|
206 |
+
$value = implode( ' ', $value );
|
207 |
+
|
208 |
+
pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) );
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Get the data from the field
|
213 |
+
*
|
214 |
+
* @param string $name The name of the field
|
215 |
+
* @param string|array $value The value of the field
|
216 |
+
* @param array $options
|
217 |
+
* @param array $pod
|
218 |
+
* @param int $id
|
219 |
+
* @param boolean $in_form
|
220 |
+
*
|
221 |
+
* @return array Array of possible field data
|
222 |
+
*
|
223 |
+
* @since 2.0
|
224 |
+
*/
|
225 |
+
public function data ( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) {
|
226 |
+
return (array) $value;
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Build regex necessary for JS validation
|
231 |
+
*
|
232 |
+
* @param mixed $value
|
233 |
+
* @param string $name
|
234 |
+
* @param array $options
|
235 |
+
* @param string $pod
|
236 |
+
* @param int $id
|
237 |
+
*
|
238 |
+
* @return bool
|
239 |
+
* @since 2.0
|
240 |
+
*/
|
241 |
+
public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
|
242 |
+
return false;
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Validate a value before it's saved
|
247 |
+
*
|
248 |
+
* @param mixed $value
|
249 |
+
* @param string $name
|
250 |
+
* @param array $options
|
251 |
+
* @param array $fields
|
252 |
+
* @param array $pod
|
253 |
+
* @param int $id
|
254 |
+
* @param array $params
|
255 |
+
*
|
256 |
+
* @return bool
|
257 |
+
* @since 2.0
|
258 |
+
*/
|
259 |
+
public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
|
260 |
+
return true;
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Change the value or perform actions after validation but before saving to the DB
|
265 |
+
*
|
266 |
+
* @param mixed $value
|
267 |
+
* @param int $id
|
268 |
+
* @param string $name
|
269 |
+
* @param array $options
|
270 |
+
* @param array $fields
|
271 |
+
* @param array $pod
|
272 |
+
* @param object $params
|
273 |
+
*
|
274 |
+
* @return mixed
|
275 |
+
* @since 2.0
|
276 |
+
*/
|
277 |
+
public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
|
278 |
+
return $value;
|
279 |
+
}
|
280 |
+
|
281 |
+
/**
|
282 |
+
* Save the value to the DB
|
283 |
+
*
|
284 |
+
* @param mixed $value
|
285 |
+
* @param int $id
|
286 |
+
* @param string $name
|
287 |
+
* @param array $options
|
288 |
+
* @param array $fields
|
289 |
+
* @param array $pod
|
290 |
+
* @param object $params
|
291 |
+
*
|
292 |
+
* @return bool|void Whether the value was saved
|
293 |
+
*
|
294 |
+
* @since 2.3
|
295 |
+
*/
|
296 |
+
public function save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
|
297 |
+
return null;
|
298 |
+
}
|
299 |
+
|
300 |
+
/**
|
301 |
+
* Perform actions after saving to the DB
|
302 |
+
*
|
303 |
+
* @param mixed $value
|
304 |
+
* @param int $id
|
305 |
+
* @param string $name
|
306 |
+
* @param array $options
|
307 |
+
* @param array $fields
|
308 |
+
* @param array $pod
|
309 |
+
* @param object $params
|
310 |
+
*
|
311 |
+
* @since void
|
312 |
+
*
|
313 |
+
* @since 2.0
|
314 |
+
*/
|
315 |
+
public function post_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
|
316 |
+
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Perform actions before deleting from the DB
|
321 |
+
*
|
322 |
+
* @param int $id
|
323 |
+
* @param string $name
|
324 |
+
* @param null $options
|
325 |
+
* @param string $pod
|
326 |
+
*
|
327 |
+
* @since void
|
328 |
+
*
|
329 |
+
* @since 2.0
|
330 |
+
*/
|
331 |
+
public function pre_delete ( $id = null, $name = null, $options = null, $pod = null ) {
|
332 |
+
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Delete the value from the DB
|
337 |
+
*
|
338 |
+
* @param int $id
|
339 |
+
* @param string $name
|
340 |
+
* @param array $options
|
341 |
+
* @param array $pod
|
342 |
+
*
|
343 |
+
* @since void
|
344 |
+
*
|
345 |
+
* @since 2.3
|
346 |
+
*/
|
347 |
+
public function delete ( $id = null, $name = null, $options = null, $pod = null ) {
|
348 |
+
|
349 |
+
}
|
350 |
+
|
351 |
+
/**
|
352 |
+
* Perform actions after deleting from the DB
|
353 |
+
*
|
354 |
+
* @param int $id
|
355 |
+
* @param string $name
|
356 |
+
* @param array $options
|
357 |
+
* @param array $pod
|
358 |
+
*
|
359 |
+
* @since void
|
360 |
+
*
|
361 |
+
* @since 2.0
|
362 |
+
*/
|
363 |
+
public function post_delete ( $id = null, $name = null, $options = null, $pod = null ) {
|
364 |
+
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Customize the Pods UI manage table column output
|
369 |
+
*
|
370 |
+
* @param int $id
|
371 |
+
* @param mixed $value
|
372 |
+
* @param string $name
|
373 |
+
* @param array $options
|
374 |
+
* @param array $fields
|
375 |
+
* @param array $pod
|
376 |
+
*
|
377 |
+
* @since string Value to be shown in the UI
|
378 |
+
*
|
379 |
+
* @since 2.0
|
380 |
+
*/
|
381 |
+
public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
|
382 |
+
return $value;
|
383 |
+
}
|
384 |
+
}
|
classes/PodsForm.php
ADDED
@@ -0,0 +1,1449 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsForm {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var PodsForm
|
9 |
+
*/
|
10 |
+
protected static $instance = null;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var string
|
14 |
+
*/
|
15 |
+
static $field = null;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
+
static $field_group = null;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var string
|
24 |
+
*/
|
25 |
+
static $field_type = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var array
|
29 |
+
*/
|
30 |
+
static $field_types = array();
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var array
|
34 |
+
*/
|
35 |
+
static $loaded = array();
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @var int
|
39 |
+
*/
|
40 |
+
static $form_counter = 0;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Singleton handling for a basic pods_form() request
|
44 |
+
*
|
45 |
+
* @return \PodsForm
|
46 |
+
*
|
47 |
+
* @since 2.3.5
|
48 |
+
*/
|
49 |
+
public static function init () {
|
50 |
+
if ( !is_object( self::$instance ) )
|
51 |
+
self::$instance = new PodsForm();
|
52 |
+
|
53 |
+
return self::$instance;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Master handler for all field / form methods
|
58 |
+
*
|
59 |
+
* @return \PodsForm
|
60 |
+
*
|
61 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
62 |
+
* @since 2.0
|
63 |
+
*/
|
64 |
+
private function __construct() {
|
65 |
+
add_action( 'admin_init', array( $this, 'admin_init' ), 14 );
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Prevent clones
|
70 |
+
*
|
71 |
+
* @since 2.3
|
72 |
+
*/
|
73 |
+
private function __clone() {
|
74 |
+
// Hulk smash
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Output a field's label
|
79 |
+
*
|
80 |
+
* @since 2.0
|
81 |
+
*/
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Output a field's label
|
85 |
+
*
|
86 |
+
* @param string $name Field name
|
87 |
+
* @param string $label Label text
|
88 |
+
* @param string $help Help text
|
89 |
+
* @param array $options Field options
|
90 |
+
*
|
91 |
+
* @return string Label HTML
|
92 |
+
*
|
93 |
+
* @since 2.0
|
94 |
+
*/
|
95 |
+
public static function label( $name, $label, $help = '', $options = null ) {
|
96 |
+
if ( is_array( $label ) || is_object( $label ) ) {
|
97 |
+
$options = $label;
|
98 |
+
$label = $options[ 'label' ];
|
99 |
+
|
100 |
+
if ( empty( $label ) )
|
101 |
+
$label = ucwords( str_replace( '_', ' ', $name ) );
|
102 |
+
|
103 |
+
$help = $options[ 'help' ];
|
104 |
+
}
|
105 |
+
else
|
106 |
+
$options = self::options( null, $options );
|
107 |
+
|
108 |
+
$label = apply_filters( 'pods_form_ui_label_text', $label, $name, $help, $options );
|
109 |
+
$help = apply_filters( 'pods_form_ui_label_help', $help, $name, $label, $options );
|
110 |
+
|
111 |
+
ob_start();
|
112 |
+
|
113 |
+
$name_clean = self::clean( $name );
|
114 |
+
$name_more_clean = self::clean( $name, true );
|
115 |
+
|
116 |
+
$type = 'label';
|
117 |
+
$attributes = array();
|
118 |
+
$attributes[ 'class' ] = 'pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean;
|
119 |
+
$attributes[ 'for' ] = ( false === strpos( $name_clean, 'pods-form-ui-' ) ? 'pods-form-ui-' : '' ) . $name_clean;
|
120 |
+
$attributes = self::merge_attributes( $attributes, $name, $type, $options, false );
|
121 |
+
|
122 |
+
pods_view( PODS_DIR . 'ui/fields/_label.php', compact( array_keys( get_defined_vars() ) ) );
|
123 |
+
|
124 |
+
$output = ob_get_clean();
|
125 |
+
|
126 |
+
return apply_filters( 'pods_form_ui_' . $type, $output, $name, $label, $help, $attributes, $options );
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Output a Field Comment Paragraph
|
131 |
+
*
|
132 |
+
* @param string $name Field name
|
133 |
+
* @param string $message Field comments
|
134 |
+
* @param array $options Field options
|
135 |
+
*
|
136 |
+
* @return string Comment HTML
|
137 |
+
*
|
138 |
+
* @since 2.0
|
139 |
+
*/
|
140 |
+
public static function comment( $name, $message = null, $options = null ) {
|
141 |
+
$options = self::options( null, $options );
|
142 |
+
|
143 |
+
$name_more_clean = self::clean( $name, true );
|
144 |
+
|
145 |
+
if ( isset( $options[ 'description' ] ) && !empty( $options[ 'description' ] ) )
|
146 |
+
$message = $options[ 'description' ];
|
147 |
+
elseif ( empty( $message ) )
|
148 |
+
return '';
|
149 |
+
|
150 |
+
$message = apply_filters( 'pods_form_ui_comment_text', $message, $name, $options );
|
151 |
+
|
152 |
+
ob_start();
|
153 |
+
|
154 |
+
$type = 'comment';
|
155 |
+
$attributes = array();
|
156 |
+
$attributes[ 'class' ] = 'pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean;
|
157 |
+
$attributes = self::merge_attributes( $attributes, $name, $type, $options, false );
|
158 |
+
|
159 |
+
pods_view( PODS_DIR . 'ui/fields/_comment.php', compact( array_keys( get_defined_vars() ) ) );
|
160 |
+
|
161 |
+
$output = ob_get_clean();
|
162 |
+
|
163 |
+
return apply_filters( 'pods_form_ui_' . $type, $output, $name, $message, $attributes, $options );
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Output a field
|
168 |
+
*
|
169 |
+
* @param string $name Field name
|
170 |
+
* @param mixed $value Field value
|
171 |
+
* @param string $type Field type
|
172 |
+
* @param array $options Field options
|
173 |
+
* @param array $pod Pod data
|
174 |
+
* @param int $id Item ID
|
175 |
+
*
|
176 |
+
* @return string Field HTML
|
177 |
+
*
|
178 |
+
* @since 2.0
|
179 |
+
*/
|
180 |
+
public static function field( $name, $value, $type = 'text', $options = null, $pod = null, $id = null ) {
|
181 |
+
// Take a field array
|
182 |
+
if ( is_array( $name ) || is_object( $name ) ) {
|
183 |
+
$options = $name;
|
184 |
+
|
185 |
+
if ( is_object( $type ) ) {
|
186 |
+
$pod = $type;
|
187 |
+
$id = $options;
|
188 |
+
}
|
189 |
+
|
190 |
+
$name = pods_v( 'name', $options );
|
191 |
+
$type = pods_v( 'type', $options );
|
192 |
+
}
|
193 |
+
|
194 |
+
$options = self::options( $type, $options );
|
195 |
+
|
196 |
+
if ( null === $value || ( '' === $value && 'boolean' == $type ) || ( !empty( $pod ) && empty( $id ) ) )
|
197 |
+
$value = self::default_value( $value, $type, $name, $options, $pod, $id );
|
198 |
+
|
199 |
+
if ( false === self::permission( $type, $name, $options, null, $pod, $id ) )
|
200 |
+
return false;
|
201 |
+
|
202 |
+
$value = apply_filters( 'pods_form_ui_field_' . $type . '_value', $value, $name, $options, $pod, $id );
|
203 |
+
$form_field_type = self::$field_type;
|
204 |
+
|
205 |
+
ob_start();
|
206 |
+
|
207 |
+
$helper = false;
|
208 |
+
|
209 |
+
if ( 0 < strlen( pods_v( 'input_helper', $options ) ) )
|
210 |
+
$helper = pods_api()->load_helper( array( 'name' => $options[ 'input_helper' ] ) );
|
211 |
+
|
212 |
+
if ( ( !isset( $options[ 'data' ] ) || empty( $options[ 'data' ] ) ) && is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'data' ) )
|
213 |
+
$data = $options[ 'data' ] = self::$loaded[ $type ]->data( $name, $value, $options, $pod, $id, true );
|
214 |
+
|
215 |
+
if ( true === apply_filters( 'pods_form_ui_field_' . $type . '_override', false, $name, $value, $options, $pod, $id ) )
|
216 |
+
do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id );
|
217 |
+
elseif ( !empty( $helper ) && 0 < strlen( pods_v( 'code', $helper ) ) && false === strpos( $helper[ 'code' ], '$this->' ) && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) )
|
218 |
+
eval( '?>' . $helper[ 'code' ] );
|
219 |
+
elseif ( method_exists( get_class(), 'field_' . $type ) )
|
220 |
+
echo call_user_func( array( get_class(), 'field_' . $type ), $name, $value, $options );
|
221 |
+
elseif ( is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'input' ) )
|
222 |
+
self::$loaded[ $type ]->input( $name, $value, $options, $pod, $id );
|
223 |
+
else
|
224 |
+
do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id );
|
225 |
+
|
226 |
+
$output = ob_get_clean();
|
227 |
+
|
228 |
+
return apply_filters( 'pods_form_ui_field_' . $type, $output, $name, $value, $options, $pod, $id );
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Output field type 'db'
|
233 |
+
*
|
234 |
+
* Used for field names and other places where only [a-z0-9_] is accepted
|
235 |
+
*
|
236 |
+
* @since 2.0
|
237 |
+
*/
|
238 |
+
protected static function field_db( $name, $value = null, $options = null ) {
|
239 |
+
$form_field_type = self::$field_type;
|
240 |
+
|
241 |
+
ob_start();
|
242 |
+
|
243 |
+
pods_view( PODS_DIR . 'ui/fields/_db.php', compact( array_keys( get_defined_vars() ) ) );
|
244 |
+
|
245 |
+
$output = ob_get_clean();
|
246 |
+
|
247 |
+
return apply_filters( 'pods_form_ui_field_db', $output, $name, $value, $options );
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Output a hidden field
|
252 |
+
*/
|
253 |
+
protected static function field_hidden( $name, $value = null, $options = null ) {
|
254 |
+
$form_field_type = self::$field_type;
|
255 |
+
|
256 |
+
ob_start();
|
257 |
+
|
258 |
+
pods_view( PODS_DIR . 'ui/fields/_hidden.php', compact( array_keys( get_defined_vars() ) ) );
|
259 |
+
|
260 |
+
$output = ob_get_clean();
|
261 |
+
|
262 |
+
return apply_filters( 'pods_form_ui_field_hidden', $output, $name, $value, $options );
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Returns a submit button, with provided text and appropriate class, copied from WP Core for use on the frontend
|
267 |
+
*
|
268 |
+
* @see get_submit_button
|
269 |
+
*
|
270 |
+
* @param string $text The text of the button (defaults to 'Save Changes')
|
271 |
+
* @param string $type The type of button. One of: primary, secondary, delete
|
272 |
+
* @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
|
273 |
+
* is given in $other_attributes below, $name will be used as the button's id.
|
274 |
+
* @param bool $wrap True if the output button should be wrapped in a paragraph tag,
|
275 |
+
* false otherwise. Defaults to true
|
276 |
+
* @param array|string $other_attributes Other attributes that should be output with the button,
|
277 |
+
* mapping attributes to their values, such as array( 'tabindex' => '1' ).
|
278 |
+
* These attributes will be output as attribute="value", such as tabindex="1".
|
279 |
+
* Defaults to no other attributes. Other attributes can also be provided as a
|
280 |
+
* string such as 'tabindex="1"', though the array format is typically cleaner.
|
281 |
+
*
|
282 |
+
* @since 3.0
|
283 |
+
*/
|
284 |
+
public static function submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) {
|
285 |
+
|
286 |
+
if ( function_exists( 'get_submit_button' ) ) {
|
287 |
+
return get_submit_button( $text, $type, $name, $wrap, $other_attributes );
|
288 |
+
}
|
289 |
+
|
290 |
+
if ( !is_array( $type ) ) {
|
291 |
+
$type = explode( ' ', $type );
|
292 |
+
}
|
293 |
+
|
294 |
+
$button_shorthand = array(
|
295 |
+
'primary',
|
296 |
+
'small',
|
297 |
+
'large'
|
298 |
+
);
|
299 |
+
|
300 |
+
$classes = array(
|
301 |
+
'button'
|
302 |
+
);
|
303 |
+
|
304 |
+
foreach ( $type as $t ) {
|
305 |
+
if ( 'secondary' === $t || 'button-secondary' === $t ) {
|
306 |
+
continue;
|
307 |
+
}
|
308 |
+
|
309 |
+
$classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
|
310 |
+
}
|
311 |
+
|
312 |
+
$class = implode( ' ', array_unique( $classes ) );
|
313 |
+
|
314 |
+
if ( 'delete' === $type ) {
|
315 |
+
$class = 'button-secondary delete';
|
316 |
+
}
|
317 |
+
|
318 |
+
$text = $text ? $text : __( 'Save Changes' );
|
319 |
+
|
320 |
+
// Default the id attribute to $name unless an id was specifically provided in $other_attributes
|
321 |
+
$id = $name;
|
322 |
+
|
323 |
+
if ( is_array( $other_attributes ) && isset( $other_attributes[ 'id' ] ) ) {
|
324 |
+
$id = $other_attributes[ 'id' ];
|
325 |
+
unset( $other_attributes[ 'id' ] );
|
326 |
+
}
|
327 |
+
|
328 |
+
$attributes = '';
|
329 |
+
|
330 |
+
if ( is_array( $other_attributes ) ) {
|
331 |
+
foreach ( $other_attributes as $attribute => $value ) {
|
332 |
+
$attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
|
333 |
+
}
|
334 |
+
}
|
335 |
+
elseif ( !empty( $other_attributes ) ) { // Attributes provided as a string
|
336 |
+
$attributes = $other_attributes;
|
337 |
+
}
|
338 |
+
|
339 |
+
$button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
|
340 |
+
$button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
|
341 |
+
|
342 |
+
if ( $wrap ) {
|
343 |
+
$button = '<p class="submit">' . $button . '</p>';
|
344 |
+
}
|
345 |
+
|
346 |
+
return $button;
|
347 |
+
|
348 |
+
}
|
349 |
+
|
350 |
+
/**
|
351 |
+
* Output a row (label, field, and comment)
|
352 |
+
*
|
353 |
+
* @param string $name Field name
|
354 |
+
* @param mixed $value Field value
|
355 |
+
* @param string $type Field type
|
356 |
+
* @param array $options Field options
|
357 |
+
* @param array $pod Pod data
|
358 |
+
* @param int $id Item ID
|
359 |
+
*
|
360 |
+
* @return string Row HTML
|
361 |
+
*
|
362 |
+
* @since 2.0
|
363 |
+
*/
|
364 |
+
public static function row( $name, $value, $type = 'text', $options = null, $pod = null, $id = null ) {
|
365 |
+
$options = self::options( null, $options );
|
366 |
+
|
367 |
+
ob_start();
|
368 |
+
|
369 |
+
pods_view( PODS_DIR . 'ui/fields/_row.php', compact( array_keys( get_defined_vars() ) ) );
|
370 |
+
|
371 |
+
$output = ob_get_clean();
|
372 |
+
|
373 |
+
return apply_filters( 'pods_form_ui_field_row', $output, $name, $value, $options, $pod, $id );
|
374 |
+
}
|
375 |
+
|
376 |
+
/**
|
377 |
+
* Output a field's attributes
|
378 |
+
*
|
379 |
+
* @since 2.0
|
380 |
+
*/
|
381 |
+
public static function attributes( $attributes, $name = null, $type = null, $options = null ) {
|
382 |
+
$attributes = (array) apply_filters( 'pods_form_ui_field_' . $type . '_attributes', $attributes, $name, $options );
|
383 |
+
|
384 |
+
foreach ( $attributes as $attribute => $value ) {
|
385 |
+
if ( null === $value )
|
386 |
+
continue;
|
387 |
+
|
388 |
+
echo ' ' . esc_attr( (string) $attribute ) . '="' . esc_attr( (string) $value ) . '"';
|
389 |
+
}
|
390 |
+
}
|
391 |
+
|
392 |
+
/**
|
393 |
+
* Output a field's data (for use with jQuery)
|
394 |
+
*
|
395 |
+
* @since 2.0
|
396 |
+
*/
|
397 |
+
public static function data( $data, $name = null, $type = null, $options = null ) {
|
398 |
+
$data = (array) apply_filters( 'pods_form_ui_field_' . $type . '_data', $data, $name, $options );
|
399 |
+
|
400 |
+
foreach ( $data as $key => $value ) {
|
401 |
+
if ( null === $value )
|
402 |
+
continue;
|
403 |
+
|
404 |
+
$key = sanitize_title( $key );
|
405 |
+
|
406 |
+
if ( is_array( $value ) )
|
407 |
+
$value = implode( ',', $value );
|
408 |
+
|
409 |
+
echo ' data-' . esc_attr( (string) $key ) . '="' . esc_attr( (string) $value ) . '"';
|
410 |
+
}
|
411 |
+
}
|
412 |
+
|
413 |
+
/**
|
414 |
+
* Merge attributes and handle classes
|
415 |
+
*
|
416 |
+
* @since 2.0
|
417 |
+
*/
|
418 |
+
public static function merge_attributes( $attributes, $name = null, $type = null, $options = null, $classes = '' ) {
|
419 |
+
$options = (array) $options;
|
420 |
+
|
421 |
+
if ( !in_array( $type, array( 'label', 'comment' ) ) ) {
|
422 |
+
$name_clean = self::clean( $name );
|
423 |
+
$name_more_clean = self::clean( $name, true );
|
424 |
+
$_attributes = array();
|
425 |
+
$_attributes[ 'name' ] = $name;
|
426 |
+
$_attributes[ 'data-name-clean' ] = $name_more_clean;
|
427 |
+
|
428 |
+
if ( 0 < strlen( pods_v( 'label', $options, '' ) ) )
|
429 |
+
$_attributes[ 'data-label' ] = strip_tags( pods_v( 'label', $options ) );
|
430 |
+
|
431 |
+
$_attributes[ 'id' ] = 'pods-form-ui-' . $name_clean;
|
432 |
+
$_attributes[ 'class' ] = 'pods-form-ui-field-type-' . $type . ' pods-form-ui-field-name-' . $name_more_clean;
|
433 |
+
|
434 |
+
if ( isset( $options[ 'dependency' ] ) && false !== $options[ 'dependency' ] )
|
435 |
+
$_attributes[ 'class' ] .= ' pods-dependent-toggle';
|
436 |
+
|
437 |
+
$attributes = array_merge( $_attributes, (array) $attributes );
|
438 |
+
|
439 |
+
if ( isset( $options[ 'attributes' ] ) && is_array( $options[ 'attributes' ] ) && !empty( $options[ 'attributes' ] ) )
|
440 |
+
$attributes = array_merge( $attributes, $options[ 'attributes' ] );
|
441 |
+
}
|
442 |
+
elseif ( isset( $options[ $type . '_attributes' ] ) && is_array( $options[ $type . '_attributes' ] ) && !empty( $options[ $type . '_attributes' ] ) )
|
443 |
+
$attributes = array_merge( $attributes, $options[ $type . '_attributes' ] );
|
444 |
+
|
445 |
+
if ( isset( $options[ 'class' ] ) && !empty( $options[ 'class' ] ) ) {
|
446 |
+
if ( is_array( $options[ 'class' ] ) )
|
447 |
+
$options[ 'class' ] = implode( ' ', $options[ 'class' ] );
|
448 |
+
|
449 |
+
$options[ 'class' ] = (string) $options[ 'class' ];
|
450 |
+
if ( isset( $attributes[ 'class' ] ) )
|
451 |
+
$attributes[ 'class' ] = $attributes[ 'class' ] . ' ' . $options[ 'class' ];
|
452 |
+
else
|
453 |
+
$attributes[ 'class' ] = $options[ 'class' ];
|
454 |
+
|
455 |
+
$attributes[ 'class' ] = trim( $attributes[ 'class' ] );
|
456 |
+
}
|
457 |
+
|
458 |
+
if ( !empty( $classes ) ) {
|
459 |
+
if ( isset( $attributes[ 'class' ] ) )
|
460 |
+
$attributes[ 'class' ] = $attributes[ 'class' ] . ' ' . $classes;
|
461 |
+
else
|
462 |
+
$attributes[ 'class' ] = $classes;
|
463 |
+
}
|
464 |
+
|
465 |
+
if ( isset( $options[ 'placeholder' ] ) && !empty( $options[ 'placeholder' ] ) ) {
|
466 |
+
if ( is_array( $options[ 'placeholder' ] ) )
|
467 |
+
$options[ 'placeholder' ] = implode( ' ', $options[ 'placeholder' ] );
|
468 |
+
|
469 |
+
$options[ 'placeholder' ] = (string) $options[ 'placeholder' ];
|
470 |
+
$attributes[ 'placeholder' ] = trim( $options[ 'placeholder' ] );
|
471 |
+
}
|
472 |
+
|
473 |
+
if ( 1 == pods_v( 'required', $options, 0 ) )
|
474 |
+
$attributes[ 'class' ] .= ' pods-validate pods-validate-required';
|
475 |
+
|
476 |
+
$max_length = (int) pods_var( 'maxlength', $options, pods_v( $type . '_max_length', $options, 0 ), null, true );
|
477 |
+
|
478 |
+
if ( 0 < $max_length )
|
479 |
+
$attributes[ 'maxlength' ] = $max_length;
|
480 |
+
|
481 |
+
$attributes = (array) apply_filters( 'pods_form_ui_field_' . $type . '_merge_attributes', $attributes, $name, $options );
|
482 |
+
return $attributes;
|
483 |
+
}
|
484 |
+
|
485 |
+
/**
|
486 |
+
* Setup options for a field and store them for later use
|
487 |
+
*
|
488 |
+
* @param $type
|
489 |
+
* @param $options
|
490 |
+
*
|
491 |
+
* @return array
|
492 |
+
*
|
493 |
+
* @static
|
494 |
+
*
|
495 |
+
* @since 2.0
|
496 |
+
*/
|
497 |
+
public static function options( $type, $options ) {
|
498 |
+
$options = (array) $options;
|
499 |
+
|
500 |
+
if ( !is_object( $options ) && isset( $options[ 'options' ] ) ) {
|
501 |
+
$options_temp = $options[ 'options' ];
|
502 |
+
|
503 |
+
unset( $options[ 'options' ] );
|
504 |
+
|
505 |
+
$options = array_merge( $options_temp, $options );
|
506 |
+
|
507 |
+
$override = array(
|
508 |
+
'class'
|
509 |
+
);
|
510 |
+
|
511 |
+
foreach ( $override as $check ) {
|
512 |
+
if ( isset( $options_temp[ $check ] ) )
|
513 |
+
$options[ $check ] = $options_temp[ $check ];
|
514 |
+
}
|
515 |
+
}
|
516 |
+
|
517 |
+
$defaults = self::options_setup( $type, $options );
|
518 |
+
|
519 |
+
$core_defaults = array(
|
520 |
+
'id' => 0,
|
521 |
+
'label' => '',
|
522 |
+
'description' => '',
|
523 |
+
'help' => '',
|
524 |
+
'default' => null,
|
525 |
+
'attributes' => array(),
|
526 |
+
'class' => '',
|
527 |
+
'grouped' => 0,
|
528 |
+
);
|
529 |
+
|
530 |
+
$defaults = array_merge( $core_defaults, $defaults );
|
531 |
+
|
532 |
+
foreach ( $defaults as $option => $settings ) {
|
533 |
+
$default = $settings;
|
534 |
+
|
535 |
+
if ( is_array( $settings ) && isset( $settings[ 'default' ] ) )
|
536 |
+
$default = $settings[ 'default' ];
|
537 |
+
|
538 |
+
if ( !isset( $options[ $option ] ) )
|
539 |
+
$options[ $option ] = $default;
|
540 |
+
}
|
541 |
+
|
542 |
+
return $options;
|
543 |
+
}
|
544 |
+
|
545 |
+
/**
|
546 |
+
* Get options for a field type and setup defaults
|
547 |
+
*
|
548 |
+
* @static
|
549 |
+
*
|
550 |
+
* @param $type
|
551 |
+
*
|
552 |
+
* @return array|null
|
553 |
+
*
|
554 |
+
* @since 2.0
|
555 |
+
*/
|
556 |
+
public static function options_setup( $type = null, $options = null ) {
|
557 |
+
$core_defaults = array(
|
558 |
+
'id' => 0,
|
559 |
+
'name' => '',
|
560 |
+
'label' => '',
|
561 |
+
'description' => '',
|
562 |
+
'help' => '',
|
563 |
+
'default' => null,
|
564 |
+
'attributes' => array(),
|
565 |
+
'class' => '',
|
566 |
+
'type' => 'text',
|
567 |
+
'group' => 0,
|
568 |
+
'grouped' => 0,
|
569 |
+
'developer_mode' => false,
|
570 |
+
'dependency' => false,
|
571 |
+
'depends-on' => array(),
|
572 |
+
'excludes-on' => array(),
|
573 |
+
'options' => array()
|
574 |
+
);
|
575 |
+
|
576 |
+
if ( !empty( $options ) && is_array( $options ) )
|
577 |
+
$core_defaults = array_merge( $core_defaults, $options );
|
578 |
+
|
579 |
+
if ( null === $type )
|
580 |
+
return $core_defaults;
|
581 |
+
else
|
582 |
+
self::field_loader( $type );
|
583 |
+
|
584 |
+
$options = apply_filters( 'pods_field_' . $type . '_options', (array) self::$loaded[ $type ]->options(), $type );
|
585 |
+
|
586 |
+
$first_field = current( $options );
|
587 |
+
|
588 |
+
if ( !empty( $options ) && !isset( $first_field[ 'name' ] ) && !isset( $first_field[ 'label' ] ) ) {
|
589 |
+
$all_options = array();
|
590 |
+
|
591 |
+
foreach ( $options as $group => $group_options ) {
|
592 |
+
$all_options = array_merge( $all_options, self::fields_setup( $group_options, $core_defaults ) );
|
593 |
+
}
|
594 |
+
|
595 |
+
$options = $all_options;
|
596 |
+
}
|
597 |
+
else
|
598 |
+
$options = self::fields_setup( $options, $core_defaults );
|
599 |
+
|
600 |
+
return $options;
|
601 |
+
}
|
602 |
+
|
603 |
+
/**
|
604 |
+
* Get Admin options for a field type and setup defaults
|
605 |
+
*
|
606 |
+
* @static
|
607 |
+
*
|
608 |
+
* @param $type
|
609 |
+
*
|
610 |
+
* @return array|null
|
611 |
+
*
|
612 |
+
* @since 2.0
|
613 |
+
*/
|
614 |
+
public static function ui_options( $type ) {
|
615 |
+
$core_defaults = array(
|
616 |
+
'id' => 0,
|
617 |
+
'name' => '',
|
618 |
+
'label' => '',
|
619 |
+
'description' => '',
|
620 |
+
'help' => '',
|
621 |
+
'default' => null,
|
622 |
+
'attributes' => array(),
|
623 |
+
'class' => '',
|
624 |
+
'type' => 'text',
|
625 |
+
'group' => 0,
|
626 |
+
'grouped' => 0,
|
627 |
+
'developer_mode' => false,
|
628 |
+
'dependency' => false,
|
629 |
+
'depends-on' => array(),
|
630 |
+
'excludes-on' => array(),
|
631 |
+
'options' => array()
|
632 |
+
);
|
633 |
+
|
634 |
+
self::field_loader( $type );
|
635 |
+
|
636 |
+
$options = apply_filters( 'pods_field_' . $type . '_ui_options', (array) self::$loaded[ $type ]->ui_options(), $type );
|
637 |
+
|
638 |
+
$first_field = current( $options );
|
639 |
+
|
640 |
+
if ( !empty( $options ) && !isset( $first_field[ 'name' ] ) && !isset( $first_field[ 'label' ] ) ) {
|
641 |
+
foreach ( $options as $group => $group_options ) {
|
642 |
+
$options[ $group ] = self::fields_setup( $group_options, $core_defaults );
|
643 |
+
}
|
644 |
+
}
|
645 |
+
else
|
646 |
+
$options = self::fields_setup( $options, $core_defaults );
|
647 |
+
|
648 |
+
return $options;
|
649 |
+
}
|
650 |
+
|
651 |
+
/**
|
652 |
+
* Get options for a field and setup defaults
|
653 |
+
*
|
654 |
+
*
|
655 |
+
* @param null $fields
|
656 |
+
* @param null $core_defaults
|
657 |
+
* @param bool $single
|
658 |
+
*
|
659 |
+
* @return array|null
|
660 |
+
*
|
661 |
+
* @static
|
662 |
+
* @since 2.0
|
663 |
+
*/
|
664 |
+
public static function fields_setup( $fields = null, $core_defaults = null, $single = false ) {
|
665 |
+
if ( empty( $core_defaults ) ) {
|
666 |
+
$core_defaults = array(
|
667 |
+
'id' => 0,
|
668 |
+
'name' => '',
|
669 |
+
'label' => '',
|
670 |
+
'description' => '',
|
671 |
+
'help' => '',
|
672 |
+
'default' => null,
|
673 |
+
'attributes' => array(),
|
674 |
+
'class' => '',
|
675 |
+
'type' => 'text',
|
676 |
+
'group' => 0,
|
677 |
+
'grouped' => 0,
|
678 |
+
'developer_mode' => false,
|
679 |
+
'dependency' => false,
|
680 |
+
'depends-on' => array(),
|
681 |
+
'excludes-on' => array(),
|
682 |
+
'options' => array()
|
683 |
+
);
|
684 |
+
}
|
685 |
+
|
686 |
+
if ( $single )
|
687 |
+
$fields = array( $fields );
|
688 |
+
|
689 |
+
foreach ( $fields as $f => $field ) {
|
690 |
+
$fields[ $f ] = self::field_setup( $field, $core_defaults, pods_var( 'type', $field, 'text' ) );
|
691 |
+
|
692 |
+
if ( !$single && strlen( $fields[ $f ][ 'name' ] ) < 1 )
|
693 |
+
$fields[ $f ][ 'name' ] = $f;
|
694 |
+
}
|
695 |
+
|
696 |
+
if ( $single )
|
697 |
+
$fields = $fields[ 0 ];
|
698 |
+
|
699 |
+
return $fields;
|
700 |
+
}
|
701 |
+
|
702 |
+
/**
|
703 |
+
* Get options for a field and setup defaults
|
704 |
+
*
|
705 |
+
* @static
|
706 |
+
*
|
707 |
+
* @param null $field
|
708 |
+
* @param null $core_defaults
|
709 |
+
* @param null $type
|
710 |
+
*
|
711 |
+
* @return array|null
|
712 |
+
*
|
713 |
+
* @since 2.0
|
714 |
+
*/
|
715 |
+
public static function field_setup( $field = null, $core_defaults = null, $type = null ) {
|
716 |
+
$options = array();
|
717 |
+
|
718 |
+
if ( empty( $core_defaults ) ) {
|
719 |
+
$core_defaults = array(
|
720 |
+
'id' => 0,
|
721 |
+
'name' => '',
|
722 |
+
'label' => '',
|
723 |
+
'description' => '',
|
724 |
+
'help' => '',
|
725 |
+
'default' => null,
|
726 |
+
'attributes' => array(),
|
727 |
+
'class' => '',
|
728 |
+
'type' => 'text',
|
729 |
+
'group' => 0,
|
730 |
+
'grouped' => 0,
|
731 |
+
'developer_mode' => false,
|
732 |
+
'dependency' => false,
|
733 |
+
'depends-on' => array(),
|
734 |
+
'excludes-on' => array(),
|
735 |
+
'options' => array()
|
736 |
+
);
|
737 |
+
|
738 |
+
if ( null !== $type ) {
|
739 |
+
self::field_loader( $type );
|
740 |
+
|
741 |
+
if ( method_exists( self::$loaded[ $type ], 'options' ) )
|
742 |
+
$options = apply_filters( 'pods_field_' . $type . '_options', (array) self::$loaded[ $type ]->options(), $type );
|
743 |
+
}
|
744 |
+
}
|
745 |
+
|
746 |
+
if ( !is_array( $field ) )
|
747 |
+
$field = array( 'default' => $field );
|
748 |
+
|
749 |
+
if ( isset( $field[ 'group' ] ) && is_array( $field[ 'group' ] ) ) {
|
750 |
+
foreach ( $field[ 'group' ] as $g => $group_option ) {
|
751 |
+
$field[ 'group' ][ $g ] = array_merge( $core_defaults, $group_option );
|
752 |
+
|
753 |
+
if ( strlen( $field[ 'group' ][ $g ][ 'name' ] ) < 1 )
|
754 |
+
$field[ 'group' ][ $g ][ 'name' ] = $g;
|
755 |
+
}
|
756 |
+
}
|
757 |
+
|
758 |
+
$field = array_merge( $core_defaults, $field );
|
759 |
+
|
760 |
+
foreach ( $options as $option => $settings ) {
|
761 |
+
$v = null;
|
762 |
+
|
763 |
+
if ( isset( $settings[ 'default' ] ) )
|
764 |
+
$v = $settings[ 'default' ];
|
765 |
+
|
766 |
+
if ( !isset( $field[ 'options' ][ $option ] ) )
|
767 |
+
$field[ 'options' ][ $option ] = $v;
|
768 |
+
}
|
769 |
+
|
770 |
+
return $field;
|
771 |
+
}
|
772 |
+
|
773 |
+
/**
|
774 |
+
* Setup dependency / exclusion classes
|
775 |
+
*
|
776 |
+
* @param array $options array( 'depends-on' => ..., 'excludes-on' => ...)
|
777 |
+
* @param string $prefix
|
778 |
+
*
|
779 |
+
* @return string
|
780 |
+
* @static
|
781 |
+
* @since 2.0
|
782 |
+
*/
|
783 |
+
public static function dependencies( $options, $prefix = '' ) {
|
784 |
+
$options = (array) $options;
|
785 |
+
|
786 |
+
$depends_on = $excludes_on = array();
|
787 |
+
if ( isset( $options[ 'depends-on' ] ) )
|
788 |
+
$depends_on = (array) $options[ 'depends-on' ];
|
789 |
+
|
790 |
+
if ( isset( $options[ 'excludes-on' ] ) )
|
791 |
+
$excludes_on = (array) $options[ 'excludes-on' ];
|
792 |
+
|
793 |
+
$classes = array();
|
794 |
+
|
795 |
+
if ( !empty( $depends_on ) ) {
|
796 |
+
$classes[] = 'pods-depends-on';
|
797 |
+
|
798 |
+
foreach ( $depends_on as $depends => $on ) {
|
799 |
+
$classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true );
|
800 |
+
|
801 |
+
if ( !is_bool( $on ) ) {
|
802 |
+
$on = (array) $on;
|
803 |
+
|
804 |
+
foreach ( $on as $o ) {
|
805 |
+
$classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true ) . '-' . self::clean( $o, true );
|
806 |
+
}
|
807 |
+
}
|
808 |
+
}
|
809 |
+
}
|
810 |
+
|
811 |
+
if ( !empty( $excludes_on ) ) {
|
812 |
+
$classes[] = 'pods-excludes-on';
|
813 |
+
foreach ( $excludes_on as $excludes => $on ) {
|
814 |
+
$classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true );
|
815 |
+
|
816 |
+
$on = (array) $on;
|
817 |
+
|
818 |
+
foreach ( $on as $o ) {
|
819 |
+
$classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true ) . '-' . self::clean( $o, true );
|
820 |
+
}
|
821 |
+
}
|
822 |
+
}
|
823 |
+
|
824 |
+
$classes = implode( ' ', $classes );
|
825 |
+
|
826 |
+
return $classes;
|
827 |
+
}
|
828 |
+
|
829 |
+
/**
|
830 |
+
* Change the value of the field
|
831 |
+
*
|
832 |
+
* @param mixed $value
|
833 |
+
* @param string $name
|
834 |
+
* @param array $options
|
835 |
+
* @param array $fields
|
836 |
+
* @param array $pod
|
837 |
+
* @param int $id
|
838 |
+
* @param array $traverse
|
839 |
+
*
|
840 |
+
* @since 2.3
|
841 |
+
*/
|
842 |
+
public static function value( $type, $value = null, $name = null, $options = null, $pod = null, $id = null, $traverse = null ) {
|
843 |
+
self::field_loader( $type );
|
844 |
+
|
845 |
+
$tableless_field_types = self::tableless_field_types();
|
846 |
+
$repeatable_field_types = self::repeatable_field_types();
|
847 |
+
|
848 |
+
if ( in_array( $type, $repeatable_field_types ) && 1 == pods_v( $type . '_repeatable', $options, 0 ) && !is_array( $value ) ) {
|
849 |
+
if ( 0 < strlen( $value ) ) {
|
850 |
+
$simple = @json_decode( $value, true );
|
851 |
+
|
852 |
+
if ( is_array( $simple ) )
|
853 |
+
$value = $simple;
|
854 |
+
else
|
855 |
+
$value = (array) $value;
|
856 |
+
}
|
857 |
+
else
|
858 |
+
$value = array();
|
859 |
+
}
|
860 |
+
|
861 |
+
if ( method_exists( self::$loaded[ $type ], 'value' ) ) {
|
862 |
+
if ( is_array( $value ) && in_array( $type, $tableless_field_types ) ) {
|
863 |
+
foreach ( $value as &$display_value ) {
|
864 |
+
$display_value = call_user_func_array( array( self::$loaded[ $type ], 'value' ), array( $display_value, $name, $options, $pod, $id, $traverse ) );
|
865 |
+
}
|
866 |
+
}
|
867 |
+
else
|
868 |
+
$value = call_user_func_array( array( self::$loaded[ $type ], 'value' ), array( $value, $name, $options, $pod, $id, $traverse ) );
|
869 |
+
}
|
870 |
+
|
871 |
+
return $value;
|
872 |
+
}
|
873 |
+
|
874 |
+
/**
|
875 |
+
* Change the way the value of the field is displayed with Pods::get
|
876 |
+
*
|
877 |
+
* @param mixed $value
|
878 |
+
* @param string $name
|
879 |
+
* @param array $options
|
880 |
+
* @param array $fields
|
881 |
+
* @param array $pod
|
882 |
+
* @param int $id
|
883 |
+
* @param array $traverse
|
884 |
+
*
|
885 |
+
* @since 2.0
|
886 |
+
*/
|
887 |
+
public static function display( $type, $value = null, $name = null, $options = null, $pod = null, $id = null, $traverse = null ) {
|
888 |
+
self::field_loader( $type );
|
889 |
+
|
890 |
+
$tableless_field_types = self::tableless_field_types();
|
891 |
+
|
892 |
+
if ( method_exists( self::$loaded[ $type ], 'display' ) ) {
|
893 |
+
if ( is_array( $value ) && !in_array( $type, $tableless_field_types ) ) {
|
894 |
+
foreach ( $value as $k => $display_value ) {
|
895 |
+
$value[ $k ] = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $display_value, $name, $options, $pod, $id, $traverse ) );
|
896 |
+
}
|
897 |
+
}
|
898 |
+
else
|
899 |
+
$value = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $value, $name, $options, $pod, $id, $traverse ) );
|
900 |
+
}
|
901 |
+
|
902 |
+
$value = apply_filters( 'pods_form_display_' . $type, $value, $name, $options, $pod, $id, $traverse );
|
903 |
+
|
904 |
+
return $value;
|
905 |
+
}
|
906 |
+
|
907 |
+
/**
|
908 |
+
* Setup regex for JS / PHP
|
909 |
+
*
|
910 |
+
* @static
|
911 |
+
*
|
912 |
+
* @param $type
|
913 |
+
* @param $options
|
914 |
+
*
|
915 |
+
* @return mixed|void
|
916 |
+
* @since 2.0
|
917 |
+
*/
|
918 |
+
public static function regex( $type, $options ) {
|
919 |
+
self::field_loader( $type );
|
920 |
+
|
921 |
+
$regex = false;
|
922 |
+
|
923 |
+
if ( method_exists( self::$loaded[ $type ], 'regex' ) )
|
924 |
+
$regex = self::$loaded[ $type ]->regex( $options );
|
925 |
+
|
926 |
+
$regex = apply_filters( 'pods_field_' . $type . '_regex', $regex, $options, $type );
|
927 |
+
|
928 |
+
return $regex;
|
929 |
+
}
|
930 |
+
|
931 |
+
/**
|
932 |
+
* Setup value preparation for sprintf
|
933 |
+
*
|
934 |
+
* @static
|
935 |
+
*
|
936 |
+
* @param $type
|
937 |
+
* @param $options
|
938 |
+
*
|
939 |
+
* @return mixed|void
|
940 |
+
* @since 2.0
|
941 |
+
*/
|
942 |
+
public static function prepare( $type, $options ) {
|
943 |
+
self::field_loader( $type );
|
944 |
+
|
945 |
+
$prepare = '%s';
|
946 |
+
|
947 |
+
if ( method_exists( self::$loaded[ $type ], 'prepare' ) )
|
948 |
+
$prepare = self::$loaded[ $type ]->prepare( $options );
|
949 |
+
|
950 |
+
$prepare = apply_filters( 'pods_field_' . $type . '_prepare', $prepare, $options, $type );
|
951 |
+
|
952 |
+
return $prepare;
|
953 |
+
}
|
954 |
+
|
955 |
+
/**
|
956 |
+
* Validate a value before it's saved
|
957 |
+
*
|
958 |
+
* @param string $type
|
959 |
+
* @param mixed $value
|
960 |
+
* @param string $name
|
961 |
+
* @param array $options
|
962 |
+
* @param array $fields
|
963 |
+
* @param array $pod
|
964 |
+
* @param int $id
|
965 |
+
* @param array|object $params
|
966 |
+
*
|
967 |
+
* @static
|
968 |
+
*
|
969 |
+
* @since 2.0
|
970 |
+
*/
|
971 |
+
public static function validate( $type, $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
|
972 |
+
self::field_loader( $type );
|
973 |
+
|
974 |
+
$validate = true;
|
975 |
+
|
976 |
+
if ( 1 == pods_v( 'pre_save', $options, 1 ) && method_exists( self::$loaded[ $type ], 'validate' ) )
|
977 |
+
$validate = self::$loaded[ $type ]->validate( $value, $name, $options, $fields, $pod, $id, $params );
|
978 |
+
|
979 |
+
$validate = apply_filters( 'pods_field_' . $type . '_validate', $validate, $value, $name, $options, $fields, $pod, $id, $type, $params );
|
980 |
+
|
981 |
+
return $validate;
|
982 |
+
}
|
983 |
+
|
984 |
+
/**
|
985 |
+
* Change the value or perform actions after validation but before saving to the DB
|
986 |
+
*
|
987 |
+
* @param string $type
|
988 |
+
* @param mixed $value
|
989 |
+
* @param int $id
|
990 |
+
* @param string $name
|
991 |
+
* @param array $options
|
992 |
+
* @param array $fields
|
993 |
+
* @param array $pod
|
994 |
+
* @param object $params
|
995 |
+
*
|
996 |
+
* @static
|
997 |
+
*
|
998 |
+
* @since 2.0
|
999 |
+
*/
|
1000 |
+
public static function pre_save( $type, $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
|
1001 |
+
self::field_loader( $type );
|
1002 |
+
|
1003 |
+
if ( 1 == pods_v( 'field_pre_save', $options, 1 ) && method_exists( self::$loaded[ $type ], 'pre_save' ) )
|
1004 |
+
$value = self::$loaded[ $type ]->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
|
1005 |
+
|
1006 |
+
return $value;
|
1007 |
+
}
|
1008 |
+
|
1009 |
+
/**
|
1010 |
+
* Save the value to the DB
|
1011 |
+
*
|
1012 |
+
* @param string $type
|
1013 |
+
* @param mixed $value
|
1014 |
+
* @param int $id
|
1015 |
+
* @param string $name
|
1016 |
+
* @param array $options
|
1017 |
+
* @param array $fields
|
1018 |
+
* @param array $pod
|
1019 |
+
* @param object $params
|
1020 |
+
*
|
1021 |
+
* @static
|
1022 |
+
*
|
1023 |
+
* @since 2.3
|
1024 |
+
*/
|
1025 |
+
public static function save( $type, $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
|
1026 |
+
self::field_loader( $type );
|
1027 |
+
|
1028 |
+
$saved = null;
|
1029 |
+
|
1030 |
+
if ( 1 == pods_v( 'field_save', $options, 1 ) && method_exists( self::$loaded[ $type ], 'save' ) )
|
1031 |
+
$saved = self::$loaded[ $type ]->save( $value, $id, $name, $options, $fields, $pod, $params );
|
1032 |
+
|
1033 |
+
return $saved;
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
/**
|
1037 |
+
* Delete the value from the DB
|
1038 |
+
*
|
1039 |
+
* @param string $type
|
1040 |
+
* @param int $id
|
1041 |
+
* @param string $name
|
1042 |
+
* @param array $options
|
1043 |
+
* @param array $pod
|
1044 |
+
*
|
1045 |
+
* @static
|
1046 |
+
*
|
1047 |
+
* @since 2.3
|
1048 |
+
*/
|
1049 |
+
public static function delete( $type, $id = null, $name = null, $options = null, $pod = null ) {
|
1050 |
+
self::field_loader( $type );
|
1051 |
+
|
1052 |
+
$deleted = null;
|
1053 |
+
|
1054 |
+
if ( 1 == pods_v( 'field_delete', $options, 1 ) && method_exists( self::$loaded[ $type ], 'delete' ) )
|
1055 |
+
$deleted = self::$loaded[ $type ]->delete( $id, $name, $options, $pod );
|
1056 |
+
|
1057 |
+
return $deleted;
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
/**
|
1061 |
+
* Check if a user has permission to be editing a field
|
1062 |
+
*
|
1063 |
+
* @param $type
|
1064 |
+
* @param null $name
|
1065 |
+
* @param null $options
|
1066 |
+
* @param null $fields
|
1067 |
+
* @param null $pod
|
1068 |
+
* @param null $id
|
1069 |
+
* @param null $params
|
1070 |
+
*
|
1071 |
+
* @static
|
1072 |
+
*
|
1073 |
+
* @since 2.0
|
1074 |
+
*/
|
1075 |
+
public static function permission( $type, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
|
1076 |
+
$permission = pods_permission( $options );
|
1077 |
+
|
1078 |
+
$permission = (boolean) apply_filters( 'pods_form_field_permission', $permission, $type, $name, $options, $fields, $pod, $id, $params );
|
1079 |
+
|
1080 |
+
return $permission;
|
1081 |
+
}
|
1082 |
+
|
1083 |
+
/**
|
1084 |
+
* Parse the default the value
|
1085 |
+
*
|
1086 |
+
* @since 2.0
|
1087 |
+
*/
|
1088 |
+
public static function default_value( $value, $type = 'text', $name = null, $options = null, $pod = null, $id = null ) {
|
1089 |
+
$default_value = pods_v( 'default_value', $options );
|
1090 |
+
|
1091 |
+
if ( '' === $default_value || null === $default_value ) {
|
1092 |
+
$default_value = $value;
|
1093 |
+
}
|
1094 |
+
|
1095 |
+
$default = pods_v( 'default', $options, $default_value, true );
|
1096 |
+
|
1097 |
+
$default_value = str_replace( array( '{@', '}' ), '', trim( $default ) );
|
1098 |
+
|
1099 |
+
if ( $default != $default_value && 1 == (int) pods_v( 'default_evaluate_tags', $options, 1 ) )
|
1100 |
+
$default = pods_evaluate_tags( $default );
|
1101 |
+
|
1102 |
+
$default = pods_var_raw( pods_v( 'default_value_parameter', $options ), 'request', $default, null, true );
|
1103 |
+
|
1104 |
+
if ( $default != $value )
|
1105 |
+
$value = $default;
|
1106 |
+
|
1107 |
+
if ( is_array( $value ) )
|
1108 |
+
$value = pods_serial_comma( $value );
|
1109 |
+
|
1110 |
+
return apply_filters( 'pods_form_field_default_value', $value, $default, $type, $options, $pod, $id );
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
/**
|
1114 |
+
* Clean a value for use in class / id
|
1115 |
+
*
|
1116 |
+
* @since 2.0
|
1117 |
+
*/
|
1118 |
+
public static function clean( $input, $noarray = false, $db_field = false ) {
|
1119 |
+
$input = str_replace( array( '--1', '__1' ), '00000', (string) $input );
|
1120 |
+
if ( false !== $noarray )
|
1121 |
+
$input = preg_replace( '/\[\d*\]/', '-', $input );
|
1122 |
+
$output = str_replace( array( '[', ']' ), '-', strtolower( $input ) );
|
1123 |
+
$output = preg_replace( '/([^a-z0-9\-_])/', '', $output );
|
1124 |
+
$output = trim( str_replace( array( '__', '_', '--' ), '-', $output ), '-' );
|
1125 |
+
$output = str_replace( '00000', '--1', $output );
|
1126 |
+
if ( false !== $db_field )
|
1127 |
+
$output = str_replace( '-', '_', $output );
|
1128 |
+
return $output;
|
1129 |
+
}
|
1130 |
+
|
1131 |
+
/**
|
1132 |
+
* Run admin_init methods for each field type
|
1133 |
+
*
|
1134 |
+
* @since 2.3
|
1135 |
+
*/
|
1136 |
+
public function admin_init() {
|
1137 |
+
$admin_field_types = pods_transient_get( 'pods_form_admin_init_field_types' );
|
1138 |
+
|
1139 |
+
if ( empty( $admin_field_types ) ) {
|
1140 |
+
$admin_field_types = array();
|
1141 |
+
|
1142 |
+
$field_types = self::field_types();
|
1143 |
+
|
1144 |
+
foreach ( $field_types as $field_type => $field_type_data ) {
|
1145 |
+
$has_ajax = self::field_method( $field_type_data[ 'type' ], 'admin_init' );
|
1146 |
+
|
1147 |
+
if ( false !== $has_ajax )
|
1148 |
+
$admin_field_types[] = $field_type;
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
pods_transient_set( 'pods_form_admin_init_field_types', $admin_field_types );
|
1152 |
+
}
|
1153 |
+
else {
|
1154 |
+
foreach ( $admin_field_types as $field_type ) {
|
1155 |
+
self::field_method( $field_type, 'admin_init' );
|
1156 |
+
}
|
1157 |
+
}
|
1158 |
+
}
|
1159 |
+
|
1160 |
+
/**
|
1161 |
+
* Autoload a Field Type's class
|
1162 |
+
*
|
1163 |
+
* @param string $field_type Field Type indentifier
|
1164 |
+
* @param string $file The Field Type class file location
|
1165 |
+
*
|
1166 |
+
* @return string
|
1167 |
+
* @access public
|
1168 |
+
* @static
|
1169 |
+
* @since 2.0
|
1170 |
+
*/
|
1171 |
+
public static function field_loader( $field_type, $file = '' ) {
|
1172 |
+
if ( isset( self::$loaded[ $field_type ] ) ) {
|
1173 |
+
$class_vars = get_class_vars( get_class( self::$loaded[ $field_type ] ) ); // PHP 5.2.x workaround
|
1174 |
+
|
1175 |
+
self::$field_group = ( isset( $class_vars[ 'group' ] ) ? $class_vars[ 'group' ] : '' );
|
1176 |
+
self::$field_type = $class_vars[ 'type' ];
|
1177 |
+
|
1178 |
+
if ( 'Unknown' != $class_vars[ 'label' ] )
|
1179 |
+
return self::$loaded[ $field_type ];
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
include_once PODS_DIR . 'classes/PodsField.php';
|
1183 |
+
|
1184 |
+
$field_type = self::clean( $field_type, true, true );
|
1185 |
+
|
1186 |
+
$class_name = ucfirst( $field_type );
|
1187 |
+
$class_name = "PodsField_{$class_name}";
|
1188 |
+
|
1189 |
+
$content_dir = realpath( WP_CONTENT_DIR );
|
1190 |
+
$plugins_dir = realpath( WP_PLUGIN_DIR );
|
1191 |
+
$muplugins_dir = realpath( WPMU_PLUGIN_DIR );
|
1192 |
+
$abspath_dir = realpath( ABSPATH );
|
1193 |
+
|
1194 |
+
if ( !class_exists( $class_name ) ) {
|
1195 |
+
if ( isset( self::$field_types[ $field_type ] ) && !empty( self::$field_types[ $field_type ][ 'file' ] ) )
|
1196 |
+
$file = realpath( self::$field_types[ $field_type ][ 'file' ] );
|
1197 |
+
|
1198 |
+
if ( !empty( $file ) && 0 === strpos( $file, $abspath_dir ) && file_exists( $file ) )
|
1199 |
+
include_once $file;
|
1200 |
+
else {
|
1201 |
+
$file = str_replace( '../', '', apply_filters( 'pods_form_field_include', PODS_DIR . 'classes/fields/' . basename( $field_type ) . '.php', $field_type ) );
|
1202 |
+
$file = realpath( $file );
|
1203 |
+
|
1204 |
+
if ( file_exists( $file ) && ( 0 === strpos( $file, $content_dir ) || 0 === strpos( $file, $plugins_dir ) || 0 === strpos( $file, $muplugins_dir ) || 0 === strpos( $file, $abspath_dir ) ) )
|
1205 |
+
include_once $file;
|
1206 |
+
}
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
if ( class_exists( $class_name ) )
|
1210 |
+
$class = new $class_name();
|
1211 |
+
else {
|
1212 |
+
$class = new PodsField();
|
1213 |
+
$class_name = 'PodsField';
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
$class_vars = get_class_vars( $class_name ); // PHP 5.2.x workaround
|
1217 |
+
|
1218 |
+
self::$field_group = ( isset( $class_vars[ 'group' ] ) ? $class_vars[ 'group' ] : '' );
|
1219 |
+
self::$field_type = $class_vars[ 'type' ];
|
1220 |
+
|
1221 |
+
self::$loaded[ $field_type ] =& $class;
|
1222 |
+
|
1223 |
+
return self::$loaded[ $field_type ];
|
1224 |
+
}
|
1225 |
+
|
1226 |
+
/**
|
1227 |
+
* Run a method from a Field Type's class
|
1228 |
+
*
|
1229 |
+
* @param string $field_type Field Type indentifier
|
1230 |
+
* @param string $method Method name
|
1231 |
+
* @param mixed $arg More arguments
|
1232 |
+
*
|
1233 |
+
* @return mixed
|
1234 |
+
* @access public
|
1235 |
+
* @static
|
1236 |
+
* @since 2.0
|
1237 |
+
*/
|
1238 |
+
public static function field_method() {
|
1239 |
+
$args = func_get_args();
|
1240 |
+
|
1241 |
+
if ( empty( $args ) && count( $args ) < 2 )
|
1242 |
+
return false;
|
1243 |
+
|
1244 |
+
$field_type = array_shift( $args );
|
1245 |
+
$method = array_shift( $args );
|
1246 |
+
|
1247 |
+
$class = self::field_loader( $field_type );
|
1248 |
+
|
1249 |
+
if ( method_exists( $class, $method ) )
|
1250 |
+
return call_user_func_array( array( $class, $method ), $args );
|
1251 |
+
|
1252 |
+
return false;
|
1253 |
+
}
|
1254 |
+
|
1255 |
+
/**
|
1256 |
+
* Add a new Pod field type
|
1257 |
+
*
|
1258 |
+
* @param string $type The new field type identifier
|
1259 |
+
* @param string $file The new field type class file location
|
1260 |
+
*
|
1261 |
+
* @return array Field Type data
|
1262 |
+
*
|
1263 |
+
* @since 2.3
|
1264 |
+
*/
|
1265 |
+
public static function register_field_type( $type, $file = null ) {
|
1266 |
+
$field_type = pods_transient_get( 'pods_field_type_' . $type );
|
1267 |
+
|
1268 |
+
if ( empty( $field_type ) || $field_type[ 'type' ] != $type || $field_type[ 'file' ] != $file ) {
|
1269 |
+
self::field_loader( $type, $file );
|
1270 |
+
|
1271 |
+
$class_vars = get_class_vars( get_class( self::$loaded[ $type ] ) ); // PHP 5.2.x workaround
|
1272 |
+
|
1273 |
+
self::$field_types[ $type ] = $class_vars;
|
1274 |
+
self::$field_types[ $type ][ 'file' ] = $file;
|
1275 |
+
|
1276 |
+
pods_transient_set( 'pods_field_type_' . $type, self::$field_types[ $type ] );
|
1277 |
+
}
|
1278 |
+
else
|
1279 |
+
self::$field_types[ $type ] = $field_type;
|
1280 |
+
|
1281 |
+
return self::$field_types[ $type ];
|
1282 |
+
}
|
1283 |
+
|
1284 |
+
/**
|
1285 |
+
* Get a list of all available field types and include
|
1286 |
+
*
|
1287 |
+
* @return array Registered Field Types data
|
1288 |
+
*
|
1289 |
+
* @since 2.3
|
1290 |
+
*/
|
1291 |
+
public static function field_types() {
|
1292 |
+
$field_types = array(
|
1293 |
+
'text',
|
1294 |
+
'website',
|
1295 |
+
'phone',
|
1296 |
+
'email',
|
1297 |
+
'password',
|
1298 |
+
'paragraph',
|
1299 |
+
'wysiwyg',
|
1300 |
+
'code',
|
1301 |
+
'datetime',
|
1302 |
+
'date',
|
1303 |
+
'time',
|
1304 |
+
'number',
|
1305 |
+
'currency',
|
1306 |
+
'file',
|
1307 |
+
'avatar',
|
1308 |
+
'pick',
|
1309 |
+
'boolean',
|
1310 |
+
'color',
|
1311 |
+
'slug'
|
1312 |
+
);
|
1313 |
+
|
1314 |
+
$field_types = array_merge( $field_types, array_keys( self::$field_types ) );
|
1315 |
+
|
1316 |
+
$field_types = array_filter( array_unique( $field_types ) );
|
1317 |
+
|
1318 |
+
$types = apply_filters( 'pods_api_field_types', $field_types );
|
1319 |
+
|
1320 |
+
$field_types = pods_transient_get( 'pods_field_types' );
|
1321 |
+
|
1322 |
+
if ( empty( $field_types ) || count( $types ) != count( $field_types ) ) {
|
1323 |
+
$field_types = array();
|
1324 |
+
|
1325 |
+
foreach ( $types as $field_type ) {
|
1326 |
+
$file = null;
|
1327 |
+
|
1328 |
+
if ( isset( self::$field_types[ $field_type ] ) )
|
1329 |
+
$file = self::$field_types[ $field_type ][ 'file' ];
|
1330 |
+
|
1331 |
+
self::field_loader( $field_type, $file );
|
1332 |
+
|
1333 |
+
if ( !isset( self::$loaded[ $field_type ] ) || !is_object( self::$loaded[ $field_type ] ) )
|
1334 |
+
continue;
|
1335 |
+
|
1336 |
+
$class_vars = get_class_vars( get_class( self::$loaded[ $field_type ] ) ); // PHP 5.2.x workaround
|
1337 |
+
|
1338 |
+
$field_types[ $field_type ] = $class_vars;
|
1339 |
+
$field_types[ $field_type ][ 'file' ] = $file;
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
self::$field_types = $field_types;
|
1343 |
+
|
1344 |
+
pods_transient_set( 'pods_field_types', self::$field_types );
|
1345 |
+
}
|
1346 |
+
else
|
1347 |
+
self::$field_types = array_merge( $field_types, self::$field_types );
|
1348 |
+
|
1349 |
+
return self::$field_types;
|
1350 |
+
}
|
1351 |
+
|
1352 |
+
/**
|
1353 |
+
* Get list of available tableless field types
|
1354 |
+
*
|
1355 |
+
* @return array Tableless field types
|
1356 |
+
*
|
1357 |
+
* @since 2.3
|
1358 |
+
*/
|
1359 |
+
public static function tableless_field_types() {
|
1360 |
+
$field_types = array( 'pick', 'file', 'avatar', 'taxonomy' );
|
1361 |
+
|
1362 |
+
return apply_filters( 'pods_tableless_field_types', $field_types );
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
/**
|
1366 |
+
* Get list of available file field types
|
1367 |
+
*
|
1368 |
+
* @return array File field types
|
1369 |
+
*
|
1370 |
+
* @since 2.3
|
1371 |
+
*/
|
1372 |
+
public static function file_field_types() {
|
1373 |
+
$field_types = array( 'file', 'avatar' );
|
1374 |
+
|
1375 |
+
return apply_filters( 'pods_file_field_types', $field_types );
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
/**
|
1379 |
+
* Get list of available repeatable field types
|
1380 |
+
*
|
1381 |
+
* @return array Repeatable field types
|
1382 |
+
*
|
1383 |
+
* @since 2.3
|
1384 |
+
*/
|
1385 |
+
public static function repeatable_field_types() {
|
1386 |
+
$field_types = array( 'code', 'color', 'currency', 'date', 'datetime', 'email', 'number', 'paragraph', 'phone', 'text', 'time', 'website', 'wysiwyg' );
|
1387 |
+
|
1388 |
+
return apply_filters( 'pods_repeatable_field_types', $field_types );
|
1389 |
+
}
|
1390 |
+
|
1391 |
+
/**
|
1392 |
+
* Get list of available number field types
|
1393 |
+
*
|
1394 |
+
* @return array Number field types
|
1395 |
+
*
|
1396 |
+
* @since 2.3
|
1397 |
+
*/
|
1398 |
+
public static function number_field_types() {
|
1399 |
+
$field_types = array( 'currency', 'number' );
|
1400 |
+
|
1401 |
+
return apply_filters( 'pods_tableless_field_types', $field_types );
|
1402 |
+
}
|
1403 |
+
|
1404 |
+
/**
|
1405 |
+
* Get list of available date field types
|
1406 |
+
*
|
1407 |
+
* @return array Date field types
|
1408 |
+
*
|
1409 |
+
* @since 2.3
|
1410 |
+
*/
|
1411 |
+
public static function date_field_types() {
|
1412 |
+
$field_types = array( 'date', 'datetime', 'time' );
|
1413 |
+
|
1414 |
+
return apply_filters( 'pods_tableless_field_types', $field_types );
|
1415 |
+
}
|
1416 |
+
|
1417 |
+
/**
|
1418 |
+
* Get list of available text field types
|
1419 |
+
*
|
1420 |
+
* @return array Text field types
|
1421 |
+
*
|
1422 |
+
* @since 2.3
|
1423 |
+
*/
|
1424 |
+
public static function text_field_types() {
|
1425 |
+
$field_types = array( 'code', 'paragraph', 'slug','password', 'text', 'wysiwyg' );
|
1426 |
+
|
1427 |
+
return apply_filters( 'pods_text_field_types', $field_types );
|
1428 |
+
}
|
1429 |
+
|
1430 |
+
/**
|
1431 |
+
* Get list of available text field types
|
1432 |
+
*
|
1433 |
+
* @return array Text field types
|
1434 |
+
*
|
1435 |
+
* @since 2.3
|
1436 |
+
*/
|
1437 |
+
public static function block_field_types() {
|
1438 |
+
$field_types = array( 'heading', 'html' );
|
1439 |
+
|
1440 |
+
/**
|
1441 |
+
* Returns the available text field types
|
1442 |
+
*
|
1443 |
+
* @since unknown
|
1444 |
+
*
|
1445 |
+
* @param object $field_types Outputs the field types
|
1446 |
+
*/
|
1447 |
+
return apply_filters( 'pods_block_field_types', $field_types );
|
1448 |
+
}
|
1449 |
+
}
|
classes/PodsInit.php
ADDED
@@ -0,0 +1,1281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsInit {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var PodsInit
|
9 |
+
*/
|
10 |
+
static $instance = null;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var array
|
14 |
+
*/
|
15 |
+
static $no_conflict = array();
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var array
|
19 |
+
*/
|
20 |
+
static $content_types_registered = array();
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var PodsComponents
|
24 |
+
*/
|
25 |
+
static $components;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var PodsMeta
|
29 |
+
*/
|
30 |
+
static $meta;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var PodsAdmin
|
34 |
+
*/
|
35 |
+
static $admin;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @var mixed|void
|
39 |
+
*/
|
40 |
+
static $version;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @var mixed|void
|
44 |
+
*/
|
45 |
+
static $version_last;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var mixed|void
|
49 |
+
*/
|
50 |
+
static $db_version;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Upgrades to trigger (last installed version => upgrade version)
|
54 |
+
*
|
55 |
+
* @var array
|
56 |
+
*/
|
57 |
+
static $upgrades = array(
|
58 |
+
'1.0.0' => '2.0.0'
|
59 |
+
//'2.0.0' => '2.1.0'
|
60 |
+
);
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Whether an Upgrade for 1.x has happened
|
64 |
+
*
|
65 |
+
* @var bool
|
66 |
+
*/
|
67 |
+
static $upgraded;
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Whether an Upgrade is needed
|
71 |
+
*
|
72 |
+
* @var bool
|
73 |
+
*/
|
74 |
+
static $upgrade_needed = false;
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Singleton handling for a basic pods_init() request
|
78 |
+
*
|
79 |
+
* @return \PodsInit
|
80 |
+
*
|
81 |
+
* @since 2.3.5
|
82 |
+
*/
|
83 |
+
public static function init () {
|
84 |
+
if ( !is_object( self::$instance ) )
|
85 |
+
self::$instance = new PodsInit();
|
86 |
+
|
87 |
+
return self::$instance;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Setup and Initiate Pods
|
92 |
+
*
|
93 |
+
* @return \PodsInit
|
94 |
+
*
|
95 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
96 |
+
* @since 1.8.9
|
97 |
+
*/
|
98 |
+
function __construct () {
|
99 |
+
self::$version = get_option( 'pods_framework_version' );
|
100 |
+
self::$version_last = get_option( 'pods_framework_version_last' );
|
101 |
+
self::$db_version = get_option( 'pods_framework_db_version' );
|
102 |
+
self::$upgraded = (int) get_option( 'pods_framework_upgraded_1_x' );
|
103 |
+
|
104 |
+
if ( empty( self::$version_last ) && 0 < strlen( get_option( 'pods_version' ) ) ) {
|
105 |
+
$old_version = get_option( 'pods_version' );
|
106 |
+
|
107 |
+
if ( !empty( $old_version ) ) {
|
108 |
+
if ( false === strpos( $old_version, '.' ) )
|
109 |
+
$old_version = pods_version_to_point( $old_version );
|
110 |
+
|
111 |
+
update_option( 'pods_framework_version_last', $old_version );
|
112 |
+
|
113 |
+
self::$version_last = $old_version;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
self::$upgrade_needed = $this->needs_upgrade();
|
118 |
+
|
119 |
+
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
|
120 |
+
|
121 |
+
add_action( 'init', array( $this, 'activate_install' ), 9 );
|
122 |
+
|
123 |
+
if ( !empty( self::$version ) ) {
|
124 |
+
add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 );
|
125 |
+
|
126 |
+
add_action( 'setup_theme', array( $this, 'load_meta' ), 14 );
|
127 |
+
|
128 |
+
add_action( 'init', array( $this, 'core' ), 11 );
|
129 |
+
|
130 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ), 15 );
|
131 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ), 15 );
|
132 |
+
add_action( 'login_enqueue_scripts', array( $this, 'register_assets' ), 15 );
|
133 |
+
|
134 |
+
add_action( 'init', array( $this, 'setup_content_types' ), 11 );
|
135 |
+
|
136 |
+
add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
|
137 |
+
add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
|
138 |
+
|
139 |
+
if ( is_admin() )
|
140 |
+
add_action( 'init', array( $this, 'admin_init' ), 12 );
|
141 |
+
|
142 |
+
// Register widgets
|
143 |
+
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
|
144 |
+
|
145 |
+
// Show admin bar links
|
146 |
+
add_action( 'admin_bar_menu', array( $this, 'admin_bar_links' ), 81 );
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Load the plugin textdomain and set default constants
|
152 |
+
*/
|
153 |
+
public function plugins_loaded () {
|
154 |
+
if ( !defined( 'PODS_LIGHT' ) )
|
155 |
+
define( 'PODS_LIGHT', false );
|
156 |
+
|
157 |
+
if ( !defined( 'PODS_TABLELESS' ) )
|
158 |
+
define( 'PODS_TABLELESS', false );
|
159 |
+
|
160 |
+
load_plugin_textdomain( 'pods', false, dirname( plugin_basename( PODS_DIR . 'init.php' ) ) . '/languages/' );
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Load Pods Components
|
165 |
+
*/
|
166 |
+
public function load_components () {
|
167 |
+
if ( !defined( 'PODS_LIGHT' ) || !PODS_LIGHT )
|
168 |
+
self::$components = pods_components();
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Load Pods Meta
|
173 |
+
*/
|
174 |
+
public function load_meta () {
|
175 |
+
self::$meta = pods_meta()->core();
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Set up the Pods core
|
180 |
+
*/
|
181 |
+
public function core () {
|
182 |
+
// Session start
|
183 |
+
pods_session_start();
|
184 |
+
|
185 |
+
add_shortcode( 'pods', 'pods_shortcode' );
|
186 |
+
add_shortcode( 'pods-form', 'pods_shortcode_form' );
|
187 |
+
|
188 |
+
$security_settings = array(
|
189 |
+
'pods_disable_file_browser' => 0,
|
190 |
+
'pods_files_require_login' => 1,
|
191 |
+
'pods_files_require_login_cap' => '',
|
192 |
+
'pods_disable_file_upload' => 0,
|
193 |
+
'pods_upload_require_login' => 1,
|
194 |
+
'pods_upload_require_login_cap' => ''
|
195 |
+
);
|
196 |
+
|
197 |
+
foreach ( $security_settings as $security_setting => $setting ) {
|
198 |
+
$setting = get_option( $security_setting );
|
199 |
+
if ( !empty( $setting ) )
|
200 |
+
$security_settings[ $security_setting ] = $setting;
|
201 |
+
}
|
202 |
+
|
203 |
+
foreach ( $security_settings as $security_setting => $setting ) {
|
204 |
+
if ( 0 == $setting )
|
205 |
+
$setting = false;
|
206 |
+
elseif ( 1 == $setting )
|
207 |
+
$setting = true;
|
208 |
+
|
209 |
+
if ( in_array( $security_setting, array( 'pods_files_require_login', 'pods_upload_require_login' ) ) ) {
|
210 |
+
if ( 0 < strlen( $security_settings[ $security_setting . '_cap' ] ) )
|
211 |
+
$setting = $security_settings[ $security_setting . '_cap' ];
|
212 |
+
}
|
213 |
+
elseif ( in_array( $security_setting, array( 'pods_files_require_login_cap', 'pods_upload_require_login_cap' ) ) )
|
214 |
+
continue;
|
215 |
+
|
216 |
+
if ( !defined( strtoupper( $security_setting ) ) )
|
217 |
+
define( strtoupper( $security_setting ), $setting );
|
218 |
+
}
|
219 |
+
|
220 |
+
$this->register_pods();
|
221 |
+
|
222 |
+
$avatar = PodsForm::field_loader( 'avatar' );
|
223 |
+
|
224 |
+
if ( method_exists( $avatar, 'get_avatar' ) )
|
225 |
+
add_filter( 'get_avatar', array( $avatar, 'get_avatar' ), 10, 4 );
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Register Scripts and Styles
|
230 |
+
*/
|
231 |
+
public function register_assets () {
|
232 |
+
if ( !wp_style_is( 'jquery-ui', 'registered' ) )
|
233 |
+
wp_register_style( 'jquery-ui', PODS_URL . 'ui/css/smoothness/jquery-ui.custom.css', array(), '1.8.16' );
|
234 |
+
|
235 |
+
wp_register_script( 'pods-json', PODS_URL . 'ui/js/jquery.json.js', array( 'jquery' ), '2.3' );
|
236 |
+
|
237 |
+
wp_register_style( 'pods-qtip', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.0-2012-07-03' );
|
238 |
+
wp_register_script( 'jquery-qtip', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.0-2012-07-03' );
|
239 |
+
|
240 |
+
wp_register_script( 'pods', PODS_URL . 'ui/js/jquery.pods.js', array( 'jquery', 'pods-json', 'jquery-qtip' ), PODS_VERSION );
|
241 |
+
|
242 |
+
wp_register_style( 'pods-form', PODS_URL . 'ui/css/pods-form.css', array(), PODS_VERSION );
|
243 |
+
|
244 |
+
wp_register_style( 'pods-cleditor', PODS_URL . 'ui/css/jquery.cleditor.css', array(), '1.3.0' );
|
245 |
+
wp_register_script( 'pods-cleditor', PODS_URL . 'ui/js/jquery.cleditor.min.js', array( 'jquery' ), '1.3.0' );
|
246 |
+
|
247 |
+
wp_register_style( 'pods-codemirror', PODS_URL . 'ui/css/codemirror.css', array(), '2.33' );
|
248 |
+
wp_register_script( 'pods-codemirror', PODS_URL . 'ui/js/codemirror.js', array(), '2.33', true );
|
249 |
+
wp_register_script( 'pods-codemirror-loadmode', PODS_URL . 'ui/js/codemirror/utils/loadmode.js', array( 'pods-codemirror' ), '2.33', true );
|
250 |
+
|
251 |
+
if ( !wp_style_is( 'jquery-ui-timepicker', 'registered' ) )
|
252 |
+
wp_register_style( 'jquery-ui-timepicker', PODS_URL . 'ui/css/jquery.ui.timepicker.css', array(), '1.1.1' );
|
253 |
+
|
254 |
+
if ( !wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) {
|
255 |
+
wp_register_script( 'jquery-ui-timepicker', PODS_URL . 'ui/js/jquery.ui.timepicker.min.js', array(
|
256 |
+
'jquery',
|
257 |
+
'jquery-ui-core',
|
258 |
+
'jquery-ui-datepicker',
|
259 |
+
'jquery-ui-slider'
|
260 |
+
), '1.1.1' );
|
261 |
+
}
|
262 |
+
|
263 |
+
wp_register_style( 'pods-attach', PODS_URL . 'ui/css/jquery.pods.attach.css', array(), PODS_VERSION );
|
264 |
+
wp_register_script( 'pods-attach', PODS_URL . 'ui/js/jquery.pods.attach.js', array(), PODS_VERSION );
|
265 |
+
|
266 |
+
wp_register_style( 'pods-select2', PODS_URL . 'ui/js/select2/select2.css', array(), '3.3.1' );
|
267 |
+
wp_register_script( 'pods-select2', PODS_URL . 'ui/js/select2/select2.min.js', array( 'jquery' ), '3.3.1' );
|
268 |
+
|
269 |
+
wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' );
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Register internal Post Types
|
274 |
+
*/
|
275 |
+
public function register_pods () {
|
276 |
+
$args = array(
|
277 |
+
'label' => 'Pods',
|
278 |
+
'labels' => array( 'singular_name' => 'Pod' ),
|
279 |
+
'public' => false,
|
280 |
+
'can_export' => false,
|
281 |
+
'query_var' => false,
|
282 |
+
'rewrite' => false,
|
283 |
+
'capability_type' => 'pods_pod',
|
284 |
+
'has_archive' => false,
|
285 |
+
'hierarchical' => false,
|
286 |
+
'supports' => array( 'title', 'author' ),
|
287 |
+
'menu_icon' => PODS_URL . 'ui/images/icon16.png'
|
288 |
+
);
|
289 |
+
|
290 |
+
$args = self::object_label_fix( $args, 'post_type' );
|
291 |
+
|
292 |
+
register_post_type( '_pods_pod', apply_filters( 'pods_internal_register_post_type_pod', $args ) );
|
293 |
+
|
294 |
+
$args = array(
|
295 |
+
'label' => 'Pod Fields',
|
296 |
+
'labels' => array( 'singular_name' => 'Pod Field' ),
|
297 |
+
'public' => false,
|
298 |
+
'can_export' => false,
|
299 |
+
'query_var' => false,
|
300 |
+
'rewrite' => false,
|
301 |
+
'capability_type' => 'pods_pod',
|
302 |
+
'has_archive' => false,
|
303 |
+
'hierarchical' => true,
|
304 |
+
'supports' => array( 'title', 'editor', 'author' ),
|
305 |
+
'menu_icon' => PODS_URL . 'ui/images/icon16.png'
|
306 |
+
);
|
307 |
+
|
308 |
+
$args = self::object_label_fix( $args, 'post_type' );
|
309 |
+
|
310 |
+
register_post_type( '_pods_field', apply_filters( 'pods_internal_register_post_type_field', $args ) );
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Include Admin
|
315 |
+
*/
|
316 |
+
public function admin_init () {
|
317 |
+
self::$admin = pods_admin();
|
318 |
+
}
|
319 |
+
|
320 |
+
/**
|
321 |
+
* Register Post Types and Taxonomies
|
322 |
+
*/
|
323 |
+
public function setup_content_types ( $force = false ) {
|
324 |
+
$post_types = PodsMeta::$post_types;
|
325 |
+
$taxonomies = PodsMeta::$taxonomies;
|
326 |
+
|
327 |
+
$existing_post_types = get_post_types();
|
328 |
+
$existing_taxonomies = get_taxonomies();
|
329 |
+
|
330 |
+
$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
|
331 |
+
|
332 |
+
$cpt_positions = array();
|
333 |
+
|
334 |
+
if ( empty( $pods_cpt_ct ) && ( !empty( $post_types ) || !empty( $taxonomies ) ) )
|
335 |
+
$force = true;
|
336 |
+
elseif ( !empty( $pods_cpt_ct ) && empty( $pods_cpt_ct[ 'post_types' ] ) && !empty( $post_types ) )
|
337 |
+
$force = true;
|
338 |
+
elseif ( !empty( $pods_cpt_ct ) && empty( $pods_cpt_ct[ 'taxonomies' ] ) && !empty( $taxonomies ) )
|
339 |
+
$force = true;
|
340 |
+
|
341 |
+
if ( false === $pods_cpt_ct || $force ) {
|
342 |
+
/**
|
343 |
+
* @var WP_Query
|
344 |
+
*/
|
345 |
+
global $wp_query;
|
346 |
+
|
347 |
+
$reserved_query_vars = array(
|
348 |
+
'post_type',
|
349 |
+
'taxonomy',
|
350 |
+
'output'
|
351 |
+
);
|
352 |
+
|
353 |
+
if ( is_object( $wp_query ) ) {
|
354 |
+
$reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
|
355 |
+
}
|
356 |
+
|
357 |
+
$pods_cpt_ct = array(
|
358 |
+
'post_types' => array(),
|
359 |
+
'taxonomies' => array()
|
360 |
+
);
|
361 |
+
|
362 |
+
$pods_post_types = $pods_taxonomies = array();
|
363 |
+
$supported_post_types = $supported_taxonomies = array();
|
364 |
+
|
365 |
+
foreach ( $post_types as $post_type ) {
|
366 |
+
// Post Type exists already
|
367 |
+
if ( isset( $pods_cpt_ct[ 'post_types' ][ $post_type[ 'name' ] ] ) )
|
368 |
+
continue;
|
369 |
+
elseif ( !empty( $post_type[ 'object' ] ) && isset( $existing_post_types[ $post_type[ 'object' ] ] ) )
|
370 |
+
continue;
|
371 |
+
elseif ( !$force && isset( $existing_post_types[ $post_type[ 'name' ] ] ) )
|
372 |
+
continue;
|
373 |
+
|
374 |
+
$post_type[ 'options' ][ 'name' ] = $post_type[ 'name' ];
|
375 |
+
$post_type = array_merge( $post_type, (array) $post_type[ 'options' ] );
|
376 |
+
|
377 |
+
$post_type_name = pods_var( 'name', $post_type );
|
378 |
+
|
379 |
+
// Labels
|
380 |
+
$cpt_label = esc_html( pods_var_raw( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $post_type ) ) ), null, true ) );
|
381 |
+
$cpt_singular = esc_html( pods_var_raw( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_var_raw( 'label', $post_type, $post_type_name, null, true ) ) ), null, true ) );
|
382 |
+
|
383 |
+
$cpt_labels = array();
|
384 |
+
$cpt_labels[ 'name' ] = $cpt_label;
|
385 |
+
$cpt_labels[ 'singular_name' ] = $cpt_singular;
|
386 |
+
$cpt_labels[ 'menu_name' ] = pods_var_raw( 'menu_name', $post_type, '', null, true );
|
387 |
+
$cpt_labels[ 'add_new' ] = pods_var_raw( 'label_add_new', $post_type, '', null, true );
|
388 |
+
$cpt_labels[ 'add_new_item' ] = pods_var_raw( 'label_add_new_item', $post_type, '', null, true );
|
389 |
+
$cpt_labels[ 'new_item' ] = pods_var_raw( 'label_new_item', $post_type, '', null, true );
|
390 |
+
$cpt_labels[ 'edit' ] = pods_var_raw( 'label_edit', $post_type, '', null, true );
|
391 |
+
$cpt_labels[ 'edit_item' ] = pods_var_raw( 'label_edit_item', $post_type, '', null, true );
|
392 |
+
$cpt_labels[ 'view' ] = pods_var_raw( 'label_view', $post_type, '', null, true );
|
393 |
+
$cpt_labels[ 'view_item' ] = pods_var_raw( 'label_view_item', $post_type, '', null, true );
|
394 |
+
$cpt_labels[ 'all_items' ] = pods_var_raw( 'label_all_items', $post_type, '', null, true );
|
395 |
+
$cpt_labels[ 'search_items' ] = pods_var_raw( 'label_search_items', $post_type, '', null, true );
|
396 |
+
$cpt_labels[ 'not_found' ] = pods_var_raw( 'label_not_found', $post_type, '', null, true );
|
397 |
+
$cpt_labels[ 'not_found_in_trash' ] = pods_var_raw( 'label_not_found_in_trash', $post_type, '', null, true );
|
398 |
+
$cpt_labels[ 'parent' ] = pods_var_raw( 'label_parent', $post_type, '', null, true );
|
399 |
+
$cpt_labels[ 'parent_item_colon' ] = pods_var_raw( 'label_parent_item_colon', $post_type, '', null, true );
|
400 |
+
|
401 |
+
// Supported
|
402 |
+
$cpt_supported = array(
|
403 |
+
'title' => (boolean) pods_var( 'supports_title', $post_type, false ),
|
404 |
+
'editor' => (boolean) pods_var( 'supports_editor', $post_type, false ),
|
405 |
+
'author' => (boolean) pods_var( 'supports_author', $post_type, false ),
|
406 |
+
'thumbnail' => (boolean) pods_var( 'supports_thumbnail', $post_type, false ),
|
407 |
+
'excerpt' => (boolean) pods_var( 'supports_excerpt', $post_type, false ),
|
408 |
+
'trackbacks' => (boolean) pods_var( 'supports_trackbacks', $post_type, false ),
|
409 |
+
'custom-fields' => (boolean) pods_var( 'supports_custom_fields', $post_type, false ),
|
410 |
+
'comments' => (boolean) pods_var( 'supports_comments', $post_type, false ),
|
411 |
+
'revisions' => (boolean) pods_var( 'supports_revisions', $post_type, false ),
|
412 |
+
'page-attributes' => (boolean) pods_var( 'supports_page_attributes', $post_type, false ),
|
413 |
+
'post-formats' => (boolean) pods_var( 'supports_post_formats', $post_type, false )
|
414 |
+
);
|
415 |
+
|
416 |
+
// Custom Supported
|
417 |
+
$cpt_supported_custom = pods_var( 'supports_custom', $post_type, '' );
|
418 |
+
|
419 |
+
if ( !empty( $cpt_supported_custom ) ) {
|
420 |
+
$cpt_supported_custom = explode( ',', $cpt_supported_custom );
|
421 |
+
$cpt_supported_custom = array_filter( array_unique( $cpt_supported_custom ) );
|
422 |
+
|
423 |
+
foreach ( $cpt_supported_custom as $cpt_support ) {
|
424 |
+
$cpt_supported[ $cpt_support ] = true;
|
425 |
+
}
|
426 |
+
}
|
427 |
+
|
428 |
+
// Genesis Support
|
429 |
+
if ( function_exists( 'genesis' ) ) {
|
430 |
+
$cpt_supported[ 'genesis-seo' ] = (boolean) pods_var( 'supports_genesis_seo', $post_type, false );
|
431 |
+
$cpt_supported[ 'genesis-layouts' ] = (boolean) pods_var( 'supports_genesis_layouts', $post_type, false );
|
432 |
+
$cpt_supported[ 'genesis-simple-sidebars' ] = (boolean) pods_var( 'supports_genesis_simple_sidebars', $post_type, false );
|
433 |
+
}
|
434 |
+
|
435 |
+
// YARPP Support
|
436 |
+
if ( defined( 'YARPP_VERSION' ) ) {
|
437 |
+
$cpt_supported[ 'yarpp_support' ] = (boolean) pods_var( 'supports_yarpp_support', $post_type, false );
|
438 |
+
}
|
439 |
+
|
440 |
+
// Jetpack Support
|
441 |
+
if ( class_exists( 'Jetpack' ) ) {
|
442 |
+
$cpt_supported[ 'supports_jetpack_publicize' ] = (boolean) pods_var( 'supports_jetpack_publicize', $post_type, false );
|
443 |
+
$cpt_supported[ 'supports_jetpack_markdown' ] = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false );
|
444 |
+
}
|
445 |
+
|
446 |
+
// WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :(
|
447 |
+
$cpt_supports = array();
|
448 |
+
|
449 |
+
if ( !pods_version_check( 'wp', '3.5' ) )
|
450 |
+
$cpt_supports = array( '_bug_fix_pre_35' );
|
451 |
+
|
452 |
+
foreach ( $cpt_supported as $cpt_support => $supported ) {
|
453 |
+
if ( true === $supported )
|
454 |
+
$cpt_supports[] = $cpt_support;
|
455 |
+
}
|
456 |
+
|
457 |
+
if ( empty( $cpt_supports ) && pods_version_check( 'wp', '3.5' ) )
|
458 |
+
$cpt_supports = false;
|
459 |
+
|
460 |
+
// Rewrite
|
461 |
+
$cpt_rewrite = (boolean) pods_var( 'rewrite', $post_type, true );
|
462 |
+
$cpt_rewrite_array = array(
|
463 |
+
'slug' => pods_var( 'rewrite_custom_slug', $post_type, str_replace( '_', '-', $post_type_name ), null, true ),
|
464 |
+
'with_front' => (boolean) pods_var( 'rewrite_with_front', $post_type, true ),
|
465 |
+
'feeds' => (boolean) pods_var( 'rewrite_feeds', $post_type, (boolean) pods_var( 'has_archive', $post_type, false ) ),
|
466 |
+
'pages' => (boolean) pods_var( 'rewrite_pages', $post_type, true )
|
467 |
+
);
|
468 |
+
|
469 |
+
if ( false !== $cpt_rewrite )
|
470 |
+
$cpt_rewrite = $cpt_rewrite_array;
|
471 |
+
|
472 |
+
$capability_type = pods_var( 'capability_type', $post_type, 'post' );
|
473 |
+
|
474 |
+
if ( 'custom' == $capability_type )
|
475 |
+
$capability_type = pods_var( 'capability_type_custom', $post_type, 'post' );
|
476 |
+
|
477 |
+
$show_in_menu = (boolean) pods_var( 'show_in_menu', $post_type, true );
|
478 |
+
|
479 |
+
if ( $show_in_menu && 0 < strlen( pods_var_raw( 'menu_location_custom', $post_type ) ) )
|
480 |
+
$show_in_menu = pods_var_raw( 'menu_location_custom', $post_type );
|
481 |
+
|
482 |
+
$menu_icon = pods_var( 'menu_icon', $post_type, null, null, true );
|
483 |
+
|
484 |
+
if ( !empty( $menu_icon ) ) {
|
485 |
+
$menu_icon = pods_evaluate_tags( $menu_icon );
|
486 |
+
}
|
487 |
+
|
488 |
+
// Register Post Type
|
489 |
+
$pods_post_types[ $post_type_name ] = array(
|
490 |
+
'label' => $cpt_label,
|
491 |
+
'labels' => $cpt_labels,
|
492 |
+
'description' => esc_html( pods_var_raw( 'description', $post_type ) ),
|
493 |
+
'public' => (boolean) pods_var( 'public', $post_type, true ),
|
494 |
+
'publicly_queryable' => (boolean) pods_var( 'publicly_queryable', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
|
495 |
+
'exclude_from_search' => (boolean) pods_var( 'exclude_from_search', $post_type, ( (boolean) pods_var( 'public', $post_type, true ) ? false : true ) ),
|
496 |
+
'show_ui' => (boolean) pods_var( 'show_ui', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
|
497 |
+
'show_in_menu' => $show_in_menu,
|
498 |
+
'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $post_type, (boolean) pods_var( 'public', $post_type, true ) ),
|
499 |
+
'show_in_admin_bar' => (boolean) pods_var( 'show_in_admin_bar', $post_type, (boolean) pods_var( 'show_in_menu', $post_type, true ) ),
|
500 |
+
'menu_position' => (int) pods_var( 'menu_position', $post_type, 0, null, true ),
|
501 |
+
'menu_icon' => $menu_icon,
|
502 |
+
'capability_type' => $capability_type,
|
503 |
+
//'capabilities' => $cpt_capabilities,
|
504 |
+
'map_meta_cap' => (boolean) pods_var( 'capability_type_extra', $post_type, true ),
|
505 |
+
'hierarchical' => (boolean) pods_var( 'hierarchical', $post_type, false ),
|
506 |
+
'supports' => $cpt_supports,
|
507 |
+
//'register_meta_box_cb' => array($this, 'manage_meta_box'),
|
508 |
+
//'permalink_epmask' => EP_PERMALINK,
|
509 |
+
'has_archive' => pods_v( 'has_archive_slug', $post_type, (boolean) pods_v( 'has_archive', $post_type, false ), true ),
|
510 |
+
'rewrite' => $cpt_rewrite,
|
511 |
+
'query_var' => ( false !== (boolean) pods_var( 'query_var', $post_type, true ) ? pods_var( 'query_var_string', $post_type, $post_type_name, null, true ) : false ),
|
512 |
+
'can_export' => (boolean) pods_var( 'can_export', $post_type, true )
|
513 |
+
);
|
514 |
+
|
515 |
+
// Prevent reserved query_var issues
|
516 |
+
if ( in_array( $pods_post_types[ $post_type_name ][ 'query_var' ], $reserved_query_vars ) ) {
|
517 |
+
$pods_post_types[ $post_type_name ][ 'query_var' ] = 'post_type_' . $pods_post_types[ $post_type_name ][ 'query_var' ];
|
518 |
+
}
|
519 |
+
|
520 |
+
if ( 25 == $pods_post_types[ $post_type_name ][ 'menu_position' ] )
|
521 |
+
$pods_post_types[ $post_type_name ][ 'menu_position' ]++;
|
522 |
+
|
523 |
+
if ( $pods_post_types[ $post_type_name ][ 'menu_position' ] < 1 || in_array( $pods_post_types[ $post_type_name ][ 'menu_position' ], $cpt_positions ) )
|
524 |
+
unset( $pods_post_types[ $post_type_name ][ 'menu_position' ] );
|
525 |
+
else {
|
526 |
+
$cpt_positions[] = $pods_post_types[ $post_type_name ][ 'menu_position' ];
|
527 |
+
|
528 |
+
// This would be nice if WP supported floats in menu_position
|
529 |
+
// $pods_post_types[ $post_type_name ][ 'menu_position' ] = $pods_post_types[ $post_type_name ][ 'menu_position' ] . '.1';
|
530 |
+
}
|
531 |
+
|
532 |
+
// Taxonomies
|
533 |
+
$cpt_taxonomies = array();
|
534 |
+
$_taxonomies = get_taxonomies();
|
535 |
+
$_taxonomies = array_merge_recursive( $_taxonomies, $pods_taxonomies );
|
536 |
+
$ignore = array( 'nav_menu', 'link_category', 'post_format' );
|
537 |
+
|
538 |
+
foreach ( $_taxonomies as $taxonomy => $label ) {
|
539 |
+
if ( in_array( $taxonomy, $ignore ) )
|
540 |
+
continue;
|
541 |
+
|
542 |
+
if ( false !== (boolean) pods_var( 'built_in_taxonomies_' . $taxonomy, $post_type, false ) ) {
|
543 |
+
$cpt_taxonomies[] = $taxonomy;
|
544 |
+
|
545 |
+
if ( isset( $supported_post_types[ $taxonomy ] ) && !in_array( $post_type_name, $supported_post_types[ $taxonomy ] ) )
|
546 |
+
$supported_post_types[ $taxonomy ][] = $post_type_name;
|
547 |
+
}
|
548 |
+
}
|
549 |
+
|
550 |
+
if ( isset( $supported_taxonomies[ $post_type_name ] ) )
|
551 |
+
$supported_taxonomies[ $post_type_name ] = array_merge( (array) $supported_taxonomies[ $post_type_name ], $cpt_taxonomies );
|
552 |
+
else
|
553 |
+
$supported_taxonomies[ $post_type_name ] = $cpt_taxonomies;
|
554 |
+
}
|
555 |
+
|
556 |
+
foreach ( $taxonomies as $taxonomy ) {
|
557 |
+
// Taxonomy Type exists already
|
558 |
+
if ( isset( $pods_cpt_ct[ 'taxonomies' ][ $taxonomy[ 'name' ] ] ) )
|
559 |
+
continue;
|
560 |
+
elseif ( !empty( $taxonomy[ 'object' ] ) && isset( $existing_taxonomies[ $taxonomy[ 'object' ] ] ) )
|
561 |
+
continue;
|
562 |
+
elseif ( !$force && isset( $existing_taxonomies[ $taxonomy[ 'name' ] ] ) )
|
563 |
+
continue;
|
564 |
+
|
565 |
+
$taxonomy[ 'options' ][ 'name' ] = $taxonomy[ 'name' ];
|
566 |
+
$taxonomy = array_merge( $taxonomy, (array) $taxonomy[ 'options' ] );
|
567 |
+
|
568 |
+
$taxonomy_name = pods_var( 'name', $taxonomy );
|
569 |
+
|
570 |
+
// Labels
|
571 |
+
$ct_label = esc_html( pods_var_raw( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $taxonomy ) ) ), null, true ) );
|
572 |
+
$ct_singular = esc_html( pods_var_raw( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_var_raw( 'label', $taxonomy, pods_var_raw( 'name', $taxonomy ), null, true ) ) ), null, true ) );
|
573 |
+
|
574 |
+
$ct_labels = array();
|
575 |
+
$ct_labels[ 'name' ] = $ct_label;
|
576 |
+
$ct_labels[ 'singular_name' ] = $ct_singular;
|
577 |
+
$ct_labels[ 'menu_name' ] = pods_var_raw( 'menu_name', $taxonomy, '', null, true );
|
578 |
+
$ct_labels[ 'search_items' ] = pods_var_raw( 'label_search_items', $taxonomy, '', null, true );
|
579 |
+
$ct_labels[ 'popular_items' ] = pods_var_raw( 'label_popular_items', $taxonomy, '', null, true );
|
580 |
+
$ct_labels[ 'all_items' ] = pods_var_raw( 'label_all_items', $taxonomy, '', null, true );
|
581 |
+
$ct_labels[ 'parent_item' ] = pods_var_raw( 'label_parent_item', $taxonomy, '', null, true );
|
582 |
+
$ct_labels[ 'parent_item_colon' ] = pods_var_raw( 'label_parent_item_colon', $taxonomy, '', null, true );
|
583 |
+
$ct_labels[ 'edit_item' ] = pods_var_raw( 'label_edit_item', $taxonomy, '', null, true );
|
584 |
+
$ct_labels[ 'update_item' ] = pods_var_raw( 'label_update_item', $taxonomy, '', null, true );
|
585 |
+
$ct_labels[ 'add_new_item' ] = pods_var_raw( 'label_add_new_item', $taxonomy, '', null, true );
|
586 |
+
$ct_labels[ 'new_item_name' ] = pods_var_raw( 'label_new_item_name', $taxonomy, '', null, true );
|
587 |
+
$ct_labels[ 'separate_items_with_commas' ] = pods_var_raw( 'label_separate_items_with_commas', $taxonomy, '', null, true );
|
588 |
+
$ct_labels[ 'add_or_remove_items' ] = pods_var_raw( 'label_add_or_remove_items', $taxonomy, '', null, true );
|
589 |
+
$ct_labels[ 'choose_from_most_used' ] = pods_var_raw( 'label_choose_from_the_most_used', $taxonomy, '', null, true );
|
590 |
+
|
591 |
+
// Rewrite
|
592 |
+
$ct_rewrite = (boolean) pods_var( 'rewrite', $taxonomy, true );
|
593 |
+
$ct_rewrite_array = array(
|
594 |
+
'slug' => pods_var( 'rewrite_custom_slug', $taxonomy, str_replace( '_', '-', $taxonomy_name ), null, true ),
|
595 |
+
'with_front' => (boolean) pods_var( 'rewrite_with_front', $taxonomy, true ),
|
596 |
+
'hierarchical' => (boolean) pods_var( 'rewrite_hierarchical', $taxonomy, (boolean) pods_var( 'hierarchical', $taxonomy, false ) )
|
597 |
+
);
|
598 |
+
|
599 |
+
if ( false !== $ct_rewrite )
|
600 |
+
$ct_rewrite = $ct_rewrite_array;
|
601 |
+
|
602 |
+
// Register Taxonomy
|
603 |
+
$pods_taxonomies[ $taxonomy_name ] = array(
|
604 |
+
'label' => $ct_label,
|
605 |
+
'labels' => $ct_labels,
|
606 |
+
'public' => (boolean) pods_var( 'public', $taxonomy, true ),
|
607 |
+
'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
|
608 |
+
'show_ui' => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
|
609 |
+
'show_tagcloud' => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
|
610 |
+
'hierarchical' => (boolean) pods_var( 'hierarchical', $taxonomy, false ),
|
611 |
+
'update_count_callback' => pods_var( 'update_count_callback', $taxonomy, null, null, true ),
|
612 |
+
'query_var' => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ),
|
613 |
+
'rewrite' => $ct_rewrite,
|
614 |
+
'show_admin_column' => (boolean) pods_var( 'show_admin_column', $taxonomy, false ),
|
615 |
+
'sort' => (boolean) pods_var( 'sort', $taxonomy, false )
|
616 |
+
);
|
617 |
+
|
618 |
+
if ( is_array( $ct_rewrite ) && !$pods_taxonomies[ $taxonomy_name ][ 'query_var' ] )
|
619 |
+
$pods_taxonomies[ $taxonomy_name ]['query_var'] = pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true );;
|
620 |
+
|
621 |
+
// Prevent reserved query_var issues
|
622 |
+
if ( in_array( $pods_taxonomies[ $taxonomy_name ][ 'query_var' ], $reserved_query_vars ) ) {
|
623 |
+
$pods_taxonomies[ $taxonomy_name ][ 'query_var' ] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ][ 'query_var' ];
|
624 |
+
}
|
625 |
+
|
626 |
+
// Integration for Single Value Taxonomy UI
|
627 |
+
if ( function_exists( 'tax_single_value_meta_box' ) ) {
|
628 |
+
$pods_taxonomies[ $taxonomy_name ][ 'single_value' ] = (boolean) pods_var( 'single_value', $taxonomy, false );
|
629 |
+
$pods_taxonomies[ $taxonomy_name ][ 'required' ] = (boolean) pods_var( 'single_value_required', $taxonomy, false );
|
630 |
+
}
|
631 |
+
|
632 |
+
// Post Types
|
633 |
+
$ct_post_types = array();
|
634 |
+
$_post_types = get_post_types();
|
635 |
+
$_post_types = array_merge_recursive( $_post_types, $pods_post_types );
|
636 |
+
$ignore = array( 'revision', 'nav_menu_item' );
|
637 |
+
|
638 |
+
foreach ( $_post_types as $post_type => $options ) {
|
639 |
+
if ( in_array( $post_type, $ignore ) )
|
640 |
+
continue;
|
641 |
+
|
642 |
+
if ( false !== (boolean) pods_var( 'built_in_post_types_' . $post_type, $taxonomy, false ) ) {
|
643 |
+
$ct_post_types[] = $post_type;
|
644 |
+
|
645 |
+
if ( isset( $supported_taxonomies[ $post_type ] ) && !in_array( $taxonomy_name, $supported_taxonomies[ $post_type ] ) )
|
646 |
+
$supported_taxonomies[ $post_type ][] = $taxonomy_name;
|
647 |
+
}
|
648 |
+
}
|
649 |
+
|
650 |
+
if ( isset( $supported_post_types[ $taxonomy_name ] ) )
|
651 |
+
$supported_post_types[ $taxonomy_name ] = array_merge( $supported_post_types[ $taxonomy_name ], $ct_post_types );
|
652 |
+
else
|
653 |
+
$supported_post_types[ $taxonomy_name ] = $ct_post_types;
|
654 |
+
}
|
655 |
+
|
656 |
+
$pods_post_types = apply_filters( 'pods_wp_post_types', $pods_post_types );
|
657 |
+
$pods_taxonomies = apply_filters( 'pods_wp_taxonomies', $pods_taxonomies );
|
658 |
+
|
659 |
+
$supported_post_types = apply_filters( 'pods_wp_supported_post_types', $supported_post_types );
|
660 |
+
$supported_taxonomies = apply_filters( 'pods_wp_supported_taxonomies', $supported_taxonomies );
|
661 |
+
|
662 |
+
foreach ( $pods_taxonomies as $taxonomy => $options ) {
|
663 |
+
$ct_post_types = null;
|
664 |
+
|
665 |
+
if ( isset( $supported_post_types[ $taxonomy ] ) && !empty( $supported_post_types[ $taxonomy ] ) )
|
666 |
+
$ct_post_types = $supported_post_types[ $taxonomy ];
|
667 |
+
|
668 |
+
$pods_cpt_ct[ 'taxonomies' ][ $taxonomy ] = array(
|
669 |
+
'post_types' => $ct_post_types,
|
670 |
+
'options' => $options
|
671 |
+
);
|
672 |
+
}
|
673 |
+
|
674 |
+
foreach ( $pods_post_types as $post_type => $options ) {
|
675 |
+
if ( isset( $supported_taxonomies[ $post_type ] ) && !empty( $supported_taxonomies[ $post_type ] ) )
|
676 |
+
$options[ 'taxonomies' ] = $supported_taxonomies[ $post_type ];
|
677 |
+
|
678 |
+
$pods_cpt_ct[ 'post_types' ][ $post_type ] = $options;
|
679 |
+
}
|
680 |
+
|
681 |
+
pods_transient_set( 'pods_wp_cpt_ct', $pods_cpt_ct );
|
682 |
+
}
|
683 |
+
|
684 |
+
foreach ( $pods_cpt_ct[ 'taxonomies' ] as $taxonomy => $options ) {
|
685 |
+
if ( isset( self::$content_types_registered[ 'taxonomies' ] ) && in_array( $taxonomy, self::$content_types_registered[ 'taxonomies' ] ) )
|
686 |
+
continue;
|
687 |
+
|
688 |
+
$ct_post_types = $options[ 'post_types' ];
|
689 |
+
$options = $options[ 'options' ];
|
690 |
+
|
691 |
+
$options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy );
|
692 |
+
$options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy );
|
693 |
+
|
694 |
+
$options = self::object_label_fix( $options, 'taxonomy' );
|
695 |
+
|
696 |
+
// Max length for taxonomies are 32 characters
|
697 |
+
$taxonomy = substr( $taxonomy, 0, 32 );
|
698 |
+
|
699 |
+
// i18n compatibility for plugins that override it
|
700 |
+
if ( is_array( $options[ 'rewrite' ] ) && isset( $options[ 'rewrite' ][ 'slug' ] ) && !empty( $options[ 'rewrite' ][ 'slug' ] ) )
|
701 |
+
$options[ 'rewrite' ][ 'slug' ] = _x( $options[ 'rewrite' ][ 'slug' ], 'URL taxonomy slug', 'pods' );
|
702 |
+
|
703 |
+
if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
704 |
+
pods_debug( array( $taxonomy, $ct_post_types, $options ) );
|
705 |
+
|
706 |
+
register_taxonomy( $taxonomy, $ct_post_types, $options );
|
707 |
+
|
708 |
+
if ( !isset( self::$content_types_registered[ 'taxonomies' ] ) )
|
709 |
+
self::$content_types_registered[ 'taxonomies' ] = array();
|
710 |
+
|
711 |
+
self::$content_types_registered[ 'taxonomies' ][] = $taxonomy;
|
712 |
+
}
|
713 |
+
|
714 |
+
foreach ( $pods_cpt_ct[ 'post_types' ] as $post_type => $options ) {
|
715 |
+
if ( isset( self::$content_types_registered[ 'post_types' ] ) && in_array( $post_type, self::$content_types_registered[ 'post_types' ] ) )
|
716 |
+
continue;
|
717 |
+
|
718 |
+
$options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type );
|
719 |
+
$options = apply_filters( 'pods_register_post_type', $options, $post_type );
|
720 |
+
|
721 |
+
$options = self::object_label_fix( $options, 'post_type' );
|
722 |
+
|
723 |
+
// Max length for post types are 20 characters
|
724 |
+
$post_type = substr( $post_type, 0, 20 );
|
725 |
+
|
726 |
+
// i18n compatibility for plugins that override it
|
727 |
+
if ( is_array( $options[ 'rewrite' ] ) && isset( $options[ 'rewrite' ][ 'slug' ] ) && !empty( $options[ 'rewrite' ][ 'slug' ] ) )
|
728 |
+
$options[ 'rewrite' ][ 'slug' ] = _x( $options[ 'rewrite' ][ 'slug' ], 'URL slug', 'pods' );
|
729 |
+
|
730 |
+
if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
731 |
+
pods_debug( array( $post_type, $options ) );
|
732 |
+
|
733 |
+
register_post_type( $post_type, $options );
|
734 |
+
|
735 |
+
if ( !isset( self::$content_types_registered[ 'post_types' ] ) )
|
736 |
+
self::$content_types_registered[ 'post_types' ] = array();
|
737 |
+
|
738 |
+
self::$content_types_registered[ 'post_types' ][] = $post_type;
|
739 |
+
}
|
740 |
+
|
741 |
+
$flush = pods_transient_get( 'pods_flush_rewrites' );
|
742 |
+
|
743 |
+
if ( 1 == $flush ) {
|
744 |
+
global $wp_rewrite;
|
745 |
+
$wp_rewrite->flush_rules();
|
746 |
+
$wp_rewrite->init();
|
747 |
+
|
748 |
+
pods_transient_set( 'pods_flush_rewrites', 0 );
|
749 |
+
}
|
750 |
+
}
|
751 |
+
|
752 |
+
/**
|
753 |
+
* Update Post Type messages
|
754 |
+
*
|
755 |
+
* @param array $messages
|
756 |
+
*
|
757 |
+
* @return array
|
758 |
+
* @since 2.0.2
|
759 |
+
*/
|
760 |
+
public function setup_updated_messages ( $messages ) {
|
761 |
+
global $post, $post_ID;
|
762 |
+
|
763 |
+
$post_types = PodsMeta::$post_types;
|
764 |
+
$existing_post_types = get_post_types();
|
765 |
+
|
766 |
+
$pods_cpt_ct = pods_transient_get( 'pods_wp_cpt_ct' );
|
767 |
+
|
768 |
+
if ( empty( $pods_cpt_ct ) || empty( $post_types ) )
|
769 |
+
return $messages;
|
770 |
+
|
771 |
+
foreach ( $post_types as $post_type ) {
|
772 |
+
if ( !isset( $pods_cpt_ct[ 'post_types' ][ $post_type[ 'name' ] ] ) )
|
773 |
+
continue;
|
774 |
+
|
775 |
+
$labels = self::object_label_fix( $pods_cpt_ct[ 'post_types' ][ $post_type[ 'name' ] ], 'post_type' );
|
776 |
+
$labels = $labels[ 'labels' ];
|
777 |
+
|
778 |
+
$messages[ $post_type[ 'name' ] ] = array(
|
779 |
+
1 => sprintf( __( '%s updated. <a href="%s">%s</a>', 'pods' ), $labels[ 'singular_name' ], esc_url( get_permalink( $post_ID ) ), $labels[ 'view_item' ] ),
|
780 |
+
2 => __( 'Custom field updated.', 'pods' ),
|
781 |
+
3 => __( 'Custom field deleted.', 'pods' ),
|
782 |
+
4 => sprintf( __( '%s updated.', 'pods' ), $labels[ 'singular_name' ] ),
|
783 |
+
/* translators: %s: date and time of the revision */
|
784 |
+
5 => isset( $_GET[ 'revision' ] ) ? sprintf( __( '%s restored to revision from %s', 'pods' ), $labels[ 'singular_name' ], wp_post_revision_title( (int) $_GET[ 'revision' ], false ) ) : false,
|
785 |
+
6 => sprintf( __( '%s published. <a href="%s">%s</a>', 'pods' ), $labels[ 'singular_name' ], esc_url( get_permalink( $post_ID ) ), $labels[ 'view_item' ] ),
|
786 |
+
7 => sprintf( __( '%s saved.', 'pods' ), $labels[ 'singular_name' ] ),
|
787 |
+
8 => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels[ 'singular_name' ], esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels[ 'singular_name' ] ),
|
788 |
+
9 => sprintf( __( '%s scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview %s</a>', 'pods' ),
|
789 |
+
$labels[ 'singular_name' ],
|
790 |
+
// translators: Publish box date format, see http://php.net/date
|
791 |
+
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ),
|
792 |
+
esc_url( get_permalink( $post_ID ) ),
|
793 |
+
$labels[ 'singular_name' ]
|
794 |
+
),
|
795 |
+
10 => sprintf( __( '%s draft updated. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels[ 'singular_name' ], esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels[ 'singular_name' ] )
|
796 |
+
);
|
797 |
+
|
798 |
+
if ( false === (boolean) $pods_cpt_ct[ 'post_types' ][ $post_type[ 'name' ] ][ 'public' ] ) {
|
799 |
+
$messages[ $post_type[ 'name' ] ][ 1 ] = sprintf( __( '%s updated.', 'pods' ), $labels[ 'singular_name' ] );
|
800 |
+
$messages[ $post_type[ 'name' ] ][ 6 ] = sprintf( __( '%s published.', 'pods' ), $labels[ 'singular_name' ] );
|
801 |
+
$messages[ $post_type[ 'name' ] ][ 8 ] = sprintf( __( '%s submitted.', 'pods' ), $labels[ 'singular_name' ] );
|
802 |
+
$messages[ $post_type[ 'name' ] ][ 9 ] = sprintf( __( '%s scheduled for: <strong>%1$s</strong>.', 'pods' ),
|
803 |
+
$labels[ 'singular_name' ],
|
804 |
+
// translators: Publish box date format, see http://php.net/date
|
805 |
+
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) )
|
806 |
+
);
|
807 |
+
$messages[ $post_type[ 'name' ] ][ 10 ] = sprintf( __( '%s draft updated.', 'pods' ), $labels[ 'singular_name' ] );
|
808 |
+
}
|
809 |
+
}
|
810 |
+
|
811 |
+
return $messages;
|
812 |
+
}
|
813 |
+
|
814 |
+
/**
|
815 |
+
* @param $args
|
816 |
+
* @param string $type
|
817 |
+
*
|
818 |
+
* @return array
|
819 |
+
*/
|
820 |
+
public static function object_label_fix ( $args, $type = 'post_type' ) {
|
821 |
+
if ( empty( $args ) || !is_array( $args ) )
|
822 |
+
$args = array();
|
823 |
+
|
824 |
+
if ( !isset( $args[ 'labels' ] ) || !is_array( $args[ 'labels' ] ) )
|
825 |
+
$args[ 'labels' ] = array();
|
826 |
+
|
827 |
+
$label = pods_var_raw( 'name', $args[ 'labels' ], pods_var_raw( 'label', $args, __( 'Items', 'pods' ), null, true ), null, true );
|
828 |
+
$singular_label = pods_var_raw( 'singular_name', $args[ 'labels' ], pods_var_raw( 'label_singular', $args, __( 'Item', 'pods' ), null, true ), null, true );
|
829 |
+
|
830 |
+
$labels = $args[ 'labels' ];
|
831 |
+
|
832 |
+
$labels[ 'name' ] = $label;
|
833 |
+
$labels[ 'singular_name' ] = $singular_label;
|
834 |
+
|
835 |
+
if ( 'post_type' == $type ) {
|
836 |
+
$labels[ 'menu_name' ] = pods_var_raw( 'menu_name', $labels, $label, null, true );
|
837 |
+
$labels[ 'add_new' ] = pods_var_raw( 'add_new', $labels, __( 'Add New', 'pods' ), null, true );
|
838 |
+
$labels[ 'add_new_item' ] = pods_var_raw( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), null, true );
|
839 |
+
$labels[ 'new_item' ] = pods_var_raw( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), null, true );
|
840 |
+
$labels[ 'edit' ] = pods_var_raw( 'edit', $labels, __( 'Edit', 'pods' ), null, true );
|
841 |
+
$labels[ 'edit_item' ] = pods_var_raw( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), null, true );
|
842 |
+
$labels[ 'view' ] = pods_var_raw( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), null, true );
|
843 |
+
$labels[ 'view_item' ] = pods_var_raw( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), null, true );
|
844 |
+
$labels[ 'all_items' ] = pods_var_raw( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), null, true );
|
845 |
+
$labels[ 'search_items' ] = pods_var_raw( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), null, true );
|
846 |
+
$labels[ 'not_found' ] = pods_var_raw( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), null, true );
|
847 |
+
$labels[ 'not_found_in_trash' ] = pods_var_raw( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), null, true );
|
848 |
+
$labels[ 'parent' ] = pods_var_raw( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), null, true );
|
849 |
+
$labels[ 'parent_item_colon' ] = pods_var_raw( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), null, true );
|
850 |
+
}
|
851 |
+
elseif ( 'taxonomy' == $type ) {
|
852 |
+
$labels[ 'menu_name' ] = pods_var_raw( 'menu_name', $labels, $label, null, true );
|
853 |
+
$labels[ 'search_items' ] = pods_var_raw( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), null, true );
|
854 |
+
$labels[ 'popular_items' ] = pods_var_raw( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), null, true );
|
855 |
+
$labels[ 'all_items' ] = pods_var_raw( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), null, true );
|
856 |
+
$labels[ 'parent_item' ] = pods_var_raw( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), null, true );
|
857 |
+
$labels[ 'parent_item_colon' ] = pods_var_raw( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), null, true );
|
858 |
+
$labels[ 'edit_item' ] = pods_var_raw( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), null, true );
|
859 |
+
$labels[ 'update_item' ] = pods_var_raw( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), null, true );
|
860 |
+
$labels[ 'add_new_item' ] = pods_var_raw( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), null, true );
|
861 |
+
$labels[ 'new_item_name' ] = pods_var_raw( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), null, true );
|
862 |
+
$labels[ 'separate_items_with_commas' ] = pods_var_raw( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), null, true );
|
863 |
+
$labels[ 'add_or_remove_items' ] = pods_var_raw( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), null, true );
|
864 |
+
$labels[ 'choose_from_most_used' ] = pods_var_raw( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), null, true );
|
865 |
+
}
|
866 |
+
|
867 |
+
$args[ 'labels' ] = $labels;
|
868 |
+
|
869 |
+
return $args;
|
870 |
+
}
|
871 |
+
|
872 |
+
/**
|
873 |
+
* Activate and Install
|
874 |
+
*/
|
875 |
+
public function activate_install () {
|
876 |
+
register_activation_hook( PODS_DIR . 'init.php', array( $this, 'activate' ) );
|
877 |
+
register_deactivation_hook( PODS_DIR . 'init.php', array( $this, 'deactivate' ) );
|
878 |
+
|
879 |
+
add_action( 'wpmu_new_blog', array( $this, 'new_blog' ), 10, 6 );
|
880 |
+
|
881 |
+
if ( empty( self::$version ) || version_compare( self::$version, PODS_VERSION, '<' ) || version_compare( self::$version, PODS_DB_VERSION, '<=' ) || self::$upgrade_needed )
|
882 |
+
$this->setup();
|
883 |
+
elseif ( self::$version != PODS_VERSION ) {
|
884 |
+
delete_option( 'pods_framework_version' );
|
885 |
+
add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
|
886 |
+
|
887 |
+
pods_api()->cache_flush_pods();
|
888 |
+
}
|
889 |
+
}
|
890 |
+
|
891 |
+
/**
|
892 |
+
*
|
893 |
+
*/
|
894 |
+
public function activate () {
|
895 |
+
global $wpdb;
|
896 |
+
|
897 |
+
if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET[ 'networkwide' ] ) && 1 == $_GET[ 'networkwide' ] ) {
|
898 |
+
$_blog_ids = $wpdb->get_col( "SELECT `blog_id` FROM `{$wpdb->blogs}`" );
|
899 |
+
|
900 |
+
foreach ( $_blog_ids as $_blog_id ) {
|
901 |
+
$this->setup( $_blog_id );
|
902 |
+
}
|
903 |
+
}
|
904 |
+
else
|
905 |
+
$this->setup();
|
906 |
+
}
|
907 |
+
|
908 |
+
/**
|
909 |
+
*
|
910 |
+
*/
|
911 |
+
public function deactivate () {
|
912 |
+
pods_api()->cache_flush_pods();
|
913 |
+
}
|
914 |
+
|
915 |
+
/**
|
916 |
+
*
|
917 |
+
*/
|
918 |
+
public function needs_upgrade ( $current = null, $last = null ) {
|
919 |
+
if ( null === $current )
|
920 |
+
$current = self::$version;
|
921 |
+
|
922 |
+
if ( null === $last )
|
923 |
+
$last = self::$version_last;
|
924 |
+
|
925 |
+
$upgrade_needed = false;
|
926 |
+
|
927 |
+
if ( !empty( $current ) ) {
|
928 |
+
foreach ( self::$upgrades as $old_version => $new_version ) {
|
929 |
+
/*if ( '2.1.0' == $new_version && ( is_developer() ) )
|
930 |
+
continue;*/
|
931 |
+
|
932 |
+
if ( version_compare( $last, $old_version, '>=' )
|
933 |
+
&& version_compare( $last, $new_version, '<' )
|
934 |
+
&& version_compare( $current, $new_version, '>=' )
|
935 |
+
&& 1 != self::$upgraded
|
936 |
+
) {
|
937 |
+
$upgrade_needed = true;
|
938 |
+
|
939 |
+
break;
|
940 |
+
}
|
941 |
+
}
|
942 |
+
}
|
943 |
+
|
944 |
+
return $upgrade_needed;
|
945 |
+
}
|
946 |
+
|
947 |
+
/**
|
948 |
+
* @param $_blog_id
|
949 |
+
* @param $user_id
|
950 |
+
* @param $domain
|
951 |
+
* @param $path
|
952 |
+
* @param $site_id
|
953 |
+
* @param $meta
|
954 |
+
*/
|
955 |
+
public function new_blog ( $_blog_id, $user_id, $domain, $path, $site_id, $meta ) {
|
956 |
+
if ( function_exists( 'is_multisite' ) && is_multisite() && is_plugin_active_for_network( basename( PODS_DIR ) . '/init.php' ) )
|
957 |
+
$this->setup( $_blog_id );
|
958 |
+
}
|
959 |
+
|
960 |
+
/**
|
961 |
+
* @param null $_blog_id
|
962 |
+
*/
|
963 |
+
public function setup ( $_blog_id = null ) {
|
964 |
+
global $wpdb;
|
965 |
+
|
966 |
+
// Switch DB table prefixes
|
967 |
+
if ( null !== $_blog_id && $_blog_id != $wpdb->blogid )
|
968 |
+
switch_to_blog( pods_absint( $_blog_id ) );
|
969 |
+
else
|
970 |
+
$_blog_id = null;
|
971 |
+
|
972 |
+
// Setup DB tables
|
973 |
+
$pods_version = get_option( 'pods_framework_version' );
|
974 |
+
$pods_version_last = get_option( 'pods_framework_version_last' );
|
975 |
+
|
976 |
+
// Install Pods
|
977 |
+
if ( empty( $pods_version ) ) {
|
978 |
+
pods_upgrade()->install( $_blog_id );
|
979 |
+
|
980 |
+
$old_version = get_option( 'pods_version' );
|
981 |
+
|
982 |
+
if ( !empty( $old_version ) ) {
|
983 |
+
if ( false === strpos( $old_version, '.' ) )
|
984 |
+
$old_version = pods_version_to_point( $old_version );
|
985 |
+
|
986 |
+
delete_option( 'pods_framework_version_last' );
|
987 |
+
add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
|
988 |
+
|
989 |
+
self::$version_last = $old_version;
|
990 |
+
}
|
991 |
+
}
|
992 |
+
// Upgrade Wizard needed
|
993 |
+
elseif ( $this->needs_upgrade( $pods_version, $pods_version_last ) ) {
|
994 |
+
// Do not do anything
|
995 |
+
return;
|
996 |
+
}
|
997 |
+
// Update Pods and run any required DB updates
|
998 |
+
elseif ( version_compare( $pods_version, PODS_VERSION, '<=' ) ) {
|
999 |
+
if ( false !== apply_filters( 'pods_update_run', null, PODS_VERSION, $pods_version, $_blog_id ) && !isset( $_GET[ 'pods_bypass_update' ] ) ) {
|
1000 |
+
do_action( 'pods_update', PODS_VERSION, $pods_version, $_blog_id );
|
1001 |
+
|
1002 |
+
// Update 2.0 alpha / beta sites
|
1003 |
+
if ( version_compare( '2.0.0-a-1', $pods_version, '<=' ) && version_compare( $pods_version, '2.0.0-b-15', '<=' ) )
|
1004 |
+
include( PODS_DIR . 'sql/update-2.0-beta.php' );
|
1005 |
+
|
1006 |
+
if ( version_compare( $pods_version, PODS_DB_VERSION, '<=' ) )
|
1007 |
+
include( PODS_DIR . 'sql/update.php' );
|
1008 |
+
|
1009 |
+
do_action( 'pods_update_post', PODS_VERSION, $pods_version, $_blog_id );
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
delete_option( 'pods_framework_version_last' );
|
1013 |
+
add_option( 'pods_framework_version_last', $pods_version, '', 'yes' );
|
1014 |
+
|
1015 |
+
self::$version_last = $pods_version;
|
1016 |
+
}
|
1017 |
+
|
1018 |
+
delete_option( 'pods_framework_version' );
|
1019 |
+
add_option( 'pods_framework_version', PODS_VERSION, '', 'yes' );
|
1020 |
+
|
1021 |
+
delete_option( 'pods_framework_db_version' );
|
1022 |
+
add_option( 'pods_framework_db_version', PODS_DB_VERSION, '', 'yes' );
|
1023 |
+
|
1024 |
+
pods_api()->cache_flush_pods();
|
1025 |
+
|
1026 |
+
// Restore DB table prefix (if switched)
|
1027 |
+
if ( null !== $_blog_id )
|
1028 |
+
restore_current_blog();
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
/**
|
1032 |
+
* @param null $_blog_id
|
1033 |
+
*/
|
1034 |
+
public function reset ( $_blog_id = null ) {
|
1035 |
+
global $wpdb;
|
1036 |
+
|
1037 |
+
// Switch DB table prefixes
|
1038 |
+
if ( null !== $_blog_id && $_blog_id != $wpdb->blogid )
|
1039 |
+
switch_to_blog( pods_absint( $_blog_id ) );
|
1040 |
+
else
|
1041 |
+
$_blog_id = null;
|
1042 |
+
|
1043 |
+
$api = pods_api();
|
1044 |
+
|
1045 |
+
$pods = $api->load_pods( array( 'names_ids' => true ) );
|
1046 |
+
|
1047 |
+
foreach ( $pods as $pod_id => $pod_label ) {
|
1048 |
+
$api->delete_pod( array( 'id' => $pod_id ) );
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
$templates = $api->load_templates();
|
1052 |
+
|
1053 |
+
foreach ( $templates as $template ) {
|
1054 |
+
$api->delete_template( array( 'id' => $template[ 'id' ] ) );
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
$pages = $api->load_pages();
|
1058 |
+
|
1059 |
+
foreach ( $pages as $page ) {
|
1060 |
+
$api->delete_page( array( 'id' => $page[ 'id' ] ) );
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
$helpers = $api->load_helpers();
|
1064 |
+
|
1065 |
+
foreach ( $helpers as $helper ) {
|
1066 |
+
$api->delete_helper( array( 'id' => $helper[ 'id' ] ) );
|
1067 |
+
}
|
1068 |
+
|
1069 |
+
$tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pods%'", ARRAY_N );
|
1070 |
+
|
1071 |
+
if ( !empty( $tables ) ) {
|
1072 |
+
foreach ( $tables as $table ) {
|
1073 |
+
$table = $table[ 0 ];
|
1074 |
+
|
1075 |
+
pods_query( "DROP TABLE `{$table}`", false );
|
1076 |
+
}
|
1077 |
+
}
|
1078 |
+
|
1079 |
+
// Remove any orphans
|
1080 |
+
$wpdb->query( "
|
1081 |
+
DELETE `p`, `pm`
|
1082 |
+
FROM `{$wpdb->posts}` AS `p`
|
1083 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm`
|
1084 |
+
ON `pm`.`post_id` = `p`.`ID`
|
1085 |
+
WHERE
|
1086 |
+
`p`.`post_type` LIKE '_pods_%'
|
1087 |
+
" );
|
1088 |
+
|
1089 |
+
delete_option( 'pods_framework_version' );
|
1090 |
+
delete_option( 'pods_framework_db_version' );
|
1091 |
+
delete_option( 'pods_framework_upgrade_2_0' );
|
1092 |
+
delete_option( 'pods_framework_upgraded_1_x' );
|
1093 |
+
|
1094 |
+
// @todo Make sure all entries are being cleaned and do something about the pods_framework_upgrade_{version} dynamic entries created by PodsUpgrade
|
1095 |
+
delete_option( 'pods_framework_upgrade_2_0_0' );
|
1096 |
+
delete_option( 'pods_framework_upgrade_2_0_sister_ids' );
|
1097 |
+
delete_option( 'pods_framework_version_last' );
|
1098 |
+
|
1099 |
+
delete_option( 'pods_component_settings' );
|
1100 |
+
|
1101 |
+
$api->cache_flush_pods();
|
1102 |
+
|
1103 |
+
pods_transient_clear( 'pods_flush_rewrites' );
|
1104 |
+
|
1105 |
+
self::$version = '';
|
1106 |
+
|
1107 |
+
// Restore DB table prefix (if switched)
|
1108 |
+
if ( null !== $_blog_id )
|
1109 |
+
restore_current_blog();
|
1110 |
+
}
|
1111 |
+
|
1112 |
+
/**
|
1113 |
+
* Delete Attachments from relationships
|
1114 |
+
*
|
1115 |
+
* @param int $_ID
|
1116 |
+
*/
|
1117 |
+
public function delete_attachment ( $_ID ) {
|
1118 |
+
global $wpdb;
|
1119 |
+
|
1120 |
+
$_ID = (int) $_ID;
|
1121 |
+
|
1122 |
+
do_action( 'pods_delete_attachment', $_ID );
|
1123 |
+
|
1124 |
+
$file_types = "'" . implode( "', '", PodsForm::file_field_types() ) . "'";
|
1125 |
+
|
1126 |
+
if ( !pods_tableless() ) {
|
1127 |
+
$sql = "
|
1128 |
+
DELETE `rel`
|
1129 |
+
FROM `@wp_podsrel` AS `rel`
|
1130 |
+
LEFT JOIN `{$wpdb->posts}` AS `p`
|
1131 |
+
ON
|
1132 |
+
`p`.`post_type` = '_pods_field'
|
1133 |
+
AND ( `p`.`ID` = `rel`.`field_id` OR `p`.`ID` = `rel`.`related_field_id` )
|
1134 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm`
|
1135 |
+
ON
|
1136 |
+
`pm`.`post_id` = `p`.`ID`
|
1137 |
+
AND `pm`.`meta_key` = 'type'
|
1138 |
+
AND `pm`.`meta_value` IN ( {$file_types} )
|
1139 |
+
WHERE
|
1140 |
+
`p`.`ID` IS NOT NULL
|
1141 |
+
AND `pm`.`meta_id` IS NOT NULL
|
1142 |
+
AND `rel`.`item_id` = {$_ID}";
|
1143 |
+
|
1144 |
+
pods_query( $sql, false );
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
// Post Meta
|
1148 |
+
if ( !empty( PodsMeta::$post_types ) ) {
|
1149 |
+
$sql = "
|
1150 |
+
DELETE `rel`
|
1151 |
+
FROM `@wp_postmeta` AS `rel`
|
1152 |
+
LEFT JOIN `{$wpdb->posts}` AS `p`
|
1153 |
+
ON
|
1154 |
+
`p`.`post_type` = '_pods_field'
|
1155 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm`
|
1156 |
+
ON
|
1157 |
+
`pm`.`post_id` = `p`.`ID`
|
1158 |
+
AND `pm`.`meta_key` = 'type'
|
1159 |
+
AND `pm`.`meta_value` IN ( {$file_types} )
|
1160 |
+
WHERE
|
1161 |
+
`p`.`ID` IS NOT NULL
|
1162 |
+
AND `pm`.`meta_id` IS NOT NULL
|
1163 |
+
AND `rel`.`meta_key` = `p`.`post_name`
|
1164 |
+
AND `rel`.`meta_value` = '{$_ID}'";
|
1165 |
+
|
1166 |
+
pods_query( $sql, false );
|
1167 |
+
}
|
1168 |
+
|
1169 |
+
// User Meta
|
1170 |
+
if ( !empty( PodsMeta::$user ) ) {
|
1171 |
+
$sql = "
|
1172 |
+
DELETE `rel`
|
1173 |
+
FROM `@wp_usermeta` AS `rel`
|
1174 |
+
LEFT JOIN `{$wpdb->posts}` AS `p`
|
1175 |
+
ON
|
1176 |
+
`p`.`post_type` = '_pods_field'
|
1177 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm`
|
1178 |
+
ON
|
1179 |
+
`pm`.`post_id` = `p`.`ID`
|
1180 |
+
AND `pm`.`meta_key` = 'type'
|
1181 |
+
AND `pm`.`meta_value` IN ( {$file_types} )
|
1182 |
+
WHERE
|
1183 |
+
`p`.`ID` IS NOT NULL
|
1184 |
+
AND `pm`.`meta_id` IS NOT NULL
|
1185 |
+
AND `rel`.`meta_key` = `p`.`post_name`
|
1186 |
+
AND `rel`.`meta_value` = '{$_ID}'";
|
1187 |
+
|
1188 |
+
pods_query( $sql, false );
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
// Comment Meta
|
1192 |
+
if ( !empty( PodsMeta::$comment ) ) {
|
1193 |
+
$sql = "
|
1194 |
+
DELETE `rel`
|
1195 |
+
FROM `@wp_commentmeta` AS `rel`
|
1196 |
+
LEFT JOIN `{$wpdb->posts}` AS `p`
|
1197 |
+
ON
|
1198 |
+
`p`.`post_type` = '_pods_field'
|
1199 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm`
|
1200 |
+
ON
|
1201 |
+
`pm`.`post_id` = `p`.`ID`
|
1202 |
+
AND `pm`.`meta_key` = 'type'
|
1203 |
+
AND `pm`.`meta_value` IN ( {$file_types} )
|
1204 |
+
WHERE
|
1205 |
+
`p`.`ID` IS NOT NULL
|
1206 |
+
AND `pm`.`meta_id` IS NOT NULL
|
1207 |
+
AND `rel`.`meta_key` = `p`.`post_name`
|
1208 |
+
AND `rel`.`meta_value` = '{$_ID}'";
|
1209 |
+
|
1210 |
+
pods_query( $sql, false );
|
1211 |
+
}
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
/**
|
1215 |
+
* Register widgets for Pods
|
1216 |
+
*/
|
1217 |
+
public function register_widgets () {
|
1218 |
+
$widgets = array(
|
1219 |
+
'PodsWidgetSingle',
|
1220 |
+
'PodsWidgetList',
|
1221 |
+
'PodsWidgetField',
|
1222 |
+
'PodsWidgetForm',
|
1223 |
+
'PodsWidgetView'
|
1224 |
+
);
|
1225 |
+
|
1226 |
+
foreach ( $widgets as $widget ) {
|
1227 |
+
if ( !file_exists( PODS_DIR . 'classes/widgets/' . $widget . '.php' ) )
|
1228 |
+
continue;
|
1229 |
+
|
1230 |
+
require_once PODS_DIR . 'classes/widgets/' . $widget . '.php';
|
1231 |
+
|
1232 |
+
register_widget( $widget );
|
1233 |
+
}
|
1234 |
+
}
|
1235 |
+
|
1236 |
+
/**
|
1237 |
+
* Add Admin Bar links
|
1238 |
+
*/
|
1239 |
+
public function admin_bar_links () {
|
1240 |
+
global $wp_admin_bar, $pods;
|
1241 |
+
|
1242 |
+
if ( !is_user_logged_in() || !is_admin_bar_showing() )
|
1243 |
+
return;
|
1244 |
+
|
1245 |
+
$all_pods = pods_api()->load_pods( array( 'type' => 'pod', 'fields' => false ) );
|
1246 |
+
|
1247 |
+
// Add New item links for all pods
|
1248 |
+
foreach ( $all_pods as $pod ) {
|
1249 |
+
if ( 0 == $pod[ 'options' ][ 'show_in_menu' ] )
|
1250 |
+
continue;
|
1251 |
+
|
1252 |
+
if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ] ) ) )
|
1253 |
+
continue;
|
1254 |
+
|
1255 |
+
$singular_label = pods_var_raw( 'label_singular', $pod[ 'options' ], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ), null, true );
|
1256 |
+
|
1257 |
+
$wp_admin_bar->add_node( array(
|
1258 |
+
'id' => 'new-pod-' . $pod[ 'name' ],
|
1259 |
+
'title' => $singular_label,
|
1260 |
+
'parent' => 'new-content',
|
1261 |
+
'href' => admin_url( 'admin.php?page=pods-manage-' . $pod[ 'name' ] . '&action=add' )
|
1262 |
+
) );
|
1263 |
+
}
|
1264 |
+
|
1265 |
+
// Add edit link if we're on a pods page
|
1266 |
+
if ( is_object( $pods ) && !is_wp_error( $pods ) && !empty( $pods->id ) && isset( $pods->pod_data ) && !empty( $pods->pod_data ) && 'pod' == $pods->pod_data[ 'type' ] ) {
|
1267 |
+
$pod = $pods->pod_data;
|
1268 |
+
|
1269 |
+
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) ) {
|
1270 |
+
$singular_label = pods_var_raw( 'label_singular', $pod[ 'options' ], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ), null, true );
|
1271 |
+
|
1272 |
+
$wp_admin_bar->add_node( array(
|
1273 |
+
'title' => sprintf( __( 'Edit %s', 'pods' ), $singular_label ),
|
1274 |
+
'id' => 'edit-p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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsMeta {
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var PodsMeta
|
9 |
+
*/
|
10 |
+
static $instance = null;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var PodsAPI
|
14 |
+
*/
|
15 |
+
private $api;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var Pods
|
19 |
+
*/
|
20 |
+
private static $current_pod;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var array
|
24 |
+
*/
|
25 |
+
private static $current_pod_data;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var Pods
|
29 |
+
*/
|
30 |
+
private static $current_field_pod;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var int
|
34 |
+
*/
|
35 |
+
public static $object_identifier = -1;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @var array
|
39 |
+
*/
|
40 |
+
public static $advanced_content_types = array();
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @var array
|
44 |
+
*/
|
45 |
+
public static $post_types = array();
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var array
|
49 |
+
*/
|
50 |
+
public static $taxonomies = array();
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @var array
|
54 |
+
*/
|
55 |
+
public static $media = array();
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @var array
|
59 |
+
*/
|
60 |
+
public static $user = array();
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @var array
|
64 |
+
*/
|
65 |
+
public static $comment = array();
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @var array
|
69 |
+
*/
|
70 |
+
public static $settings = array();
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @var array
|
74 |
+
*/
|
75 |
+
public static $queue = array();
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @var array
|
79 |
+
*/
|
80 |
+
public static $groups = array();
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @var string
|
84 |
+
*/
|
85 |
+
public static $old_post_status = '';
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Singleton handling for a basic pods_meta() request
|
89 |
+
*
|
90 |
+
* @return \PodsMeta
|
91 |
+
*
|
92 |
+
* @since 2.3.5
|
93 |
+
*/
|
94 |
+
public static function init () {
|
95 |
+
if ( !is_object( self::$instance ) )
|
96 |
+
self::$instance = new PodsMeta();
|
97 |
+
|
98 |
+
return self::$instance;
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* @return \PodsMeta
|
103 |
+
*
|
104 |
+
* @since 2.0
|
105 |
+
*/
|
106 |
+
function __construct () {
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* @return \PodsMeta
|
112 |
+
*/
|
113 |
+
public function core () {
|
114 |
+
self::$advanced_content_types = pods_api()->load_pods( array( 'type' => 'pod' ) );
|
115 |
+
self::$post_types = pods_api()->load_pods( array( 'type' => 'post_type' ) );
|
116 |
+
self::$taxonomies = pods_api()->load_pods( array( 'type' => 'taxonomy' ) );
|
117 |
+
self::$media = pods_api()->load_pods( array( 'type' => 'media' ) );
|
118 |
+
self::$user = pods_api()->load_pods( array( 'type' => 'user' ) );
|
119 |
+
self::$comment = pods_api()->load_pods( array( 'type' => 'comment' ) );
|
120 |
+
self::$settings = pods_api()->load_pods( array( 'type' => 'settings' ) );
|
121 |
+
|
122 |
+
// Handle Post Type Editor (needed for Pods core)
|
123 |
+
|
124 |
+
// Loop through and add meta boxes for individual types (can't use this, Tabify doesn't pick it up)
|
125 |
+
/*
|
126 |
+
foreach ( self::$post_types as $post_type ) {
|
127 |
+
$post_type_name = $post_type[ 'name' ];
|
128 |
+
|
129 |
+
if ( !empty( $post_type[ 'object' ] ) )
|
130 |
+
$post_type_name = $post_type[ 'object' ];
|
131 |
+
|
132 |
+
add_action( 'add_meta_boxes_' . $post_type_name, array( $this, 'meta_post_add' ) );
|
133 |
+
}
|
134 |
+
*/
|
135 |
+
|
136 |
+
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
|
137 |
+
add_action( 'transition_post_status', array( $this, 'save_post_detect_new' ), 10, 3 );
|
138 |
+
add_action( 'save_post', array( $this, 'save_post' ), 10, 3 );
|
139 |
+
|
140 |
+
if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
|
141 |
+
// Handle *_post_meta
|
142 |
+
if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
|
143 |
+
add_filter( 'get_post_metadata', array( $this, 'get_post_meta' ), 10, 4 );
|
144 |
+
}
|
145 |
+
|
146 |
+
if ( !pods_tableless() ) {
|
147 |
+
add_filter( 'add_post_metadata', array( $this, 'add_post_meta' ), 10, 5 );
|
148 |
+
add_filter( 'update_post_metadata', array( $this, 'update_post_meta' ), 10, 5 );
|
149 |
+
add_filter( 'delete_post_metadata', array( $this, 'delete_post_meta' ), 10, 5 );
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
add_action( 'delete_post', array( $this, 'delete_post' ), 10, 1 );
|
154 |
+
|
155 |
+
if ( !empty( self::$taxonomies ) ) {
|
156 |
+
$has_fields = false;
|
157 |
+
|
158 |
+
// Handle Taxonomy Editor
|
159 |
+
foreach ( self::$taxonomies as $taxonomy ) {
|
160 |
+
if ( empty( $taxonomy[ 'fields' ] ) ) {
|
161 |
+
continue;
|
162 |
+
}
|
163 |
+
|
164 |
+
$has_fields = true;
|
165 |
+
|
166 |
+
$taxonomy_name = $taxonomy[ 'name' ];
|
167 |
+
if ( !empty( $taxonomy[ 'object' ] ) )
|
168 |
+
$taxonomy_name = $taxonomy[ 'object' ];
|
169 |
+
|
170 |
+
add_action( $taxonomy_name . '_edit_form_fields', array( $this, 'meta_taxonomy' ), 10, 2 );
|
171 |
+
add_action( $taxonomy_name . '_add_form_fields', array( $this, 'meta_taxonomy' ), 10, 1 );
|
172 |
+
}
|
173 |
+
|
174 |
+
if ( $has_fields ) {
|
175 |
+
// Handle Term Editor
|
176 |
+
add_action( 'edit_term', array( $this, 'save_taxonomy' ), 10, 3 );
|
177 |
+
add_action( 'create_term', array( $this, 'save_taxonomy' ), 10, 3 );
|
178 |
+
|
179 |
+
if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
|
180 |
+
// Handle *_term_meta
|
181 |
+
if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) {
|
182 |
+
add_filter( 'get_term_metadata', array( $this, 'get_term_meta' ), 10, 4 );
|
183 |
+
}
|
184 |
+
|
185 |
+
if ( !pods_tableless() ) {
|
186 |
+
add_filter( 'add_term_metadata', array( $this, 'add_term_meta' ), 10, 5 );
|
187 |
+
add_filter( 'update_term_metadata', array( $this, 'update_term_meta' ), 10, 5 );
|
188 |
+
add_filter( 'delete_term_metadata', array( $this, 'delete_term_meta' ), 10, 5 );
|
189 |
+
}
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
// Handle Delete
|
195 |
+
add_action( 'delete_term_taxonomy', array( $this, 'delete_taxonomy' ), 10, 1 );
|
196 |
+
|
197 |
+
if ( !empty( self::$media ) ) {
|
198 |
+
if ( pods_version_check( 'wp', '3.5' ) ) {
|
199 |
+
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
|
200 |
+
add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 );
|
201 |
+
}
|
202 |
+
|
203 |
+
add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 );
|
204 |
+
|
205 |
+
add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 );
|
206 |
+
add_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 );
|
207 |
+
|
208 |
+
if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
|
209 |
+
// Handle *_post_meta
|
210 |
+
if ( !has_filter( 'get_post_metadata', array( $this, 'get_post_meta' ) ) ) {
|
211 |
+
if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
|
212 |
+
add_filter( 'get_post_metadata', array( $this, 'get_post_meta' ), 10, 4 );
|
213 |
+
}
|
214 |
+
|
215 |
+
if ( !pods_tableless() ) {
|
216 |
+
add_filter( 'add_post_metadata', array( $this, 'add_post_meta' ), 10, 5 );
|
217 |
+
add_filter( 'update_post_metadata', array( $this, 'update_post_meta' ), 10, 5 );
|
218 |
+
add_filter( 'delete_post_metadata', array( $this, 'delete_post_meta' ), 10, 5 );
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
// Handle Delete
|
225 |
+
add_action( 'delete_attachment', array( $this, 'delete_media' ), 10, 1 );
|
226 |
+
|
227 |
+
if ( !empty( self::$user ) ) {
|
228 |
+
// Handle User Editor
|
229 |
+
add_action( 'show_user_profile', array( $this, 'meta_user' ) );
|
230 |
+
add_action( 'edit_user_profile', array( $this, 'meta_user' ) );
|
231 |
+
//add_action( 'user_register', array( $this, 'save_user' ) );
|
232 |
+
add_action( 'profile_update', array( $this, 'save_user' ) );
|
233 |
+
|
234 |
+
if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
|
235 |
+
// Handle *_user_meta
|
236 |
+
if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) {
|
237 |
+
add_filter( 'get_user_metadata', array( $this, 'get_user_meta' ), 10, 4 );
|
238 |
+
}
|
239 |
+
|
240 |
+
if ( !pods_tableless() ) {
|
241 |
+
add_filter( 'add_user_metadata', array( $this, 'add_user_meta' ), 10, 5 );
|
242 |
+
add_filter( 'update_user_metadata', array( $this, 'update_user_meta' ), 10, 5 );
|
243 |
+
add_filter( 'delete_user_metadata', array( $this, 'delete_user_meta' ), 10, 5 );
|
244 |
+
}
|
245 |
+
}
|
246 |
+
}
|
247 |
+
|
248 |
+
// Handle Delete
|
249 |
+
add_action( 'delete_user', array( $this, 'delete_user' ), 10, 1 );
|
250 |
+
|
251 |
+
if ( !empty( self::$comment ) ) {
|
252 |
+
// Handle Comment Form / Editor
|
253 |
+
add_action( 'comment_form_logged_in_after', array( $this, 'meta_comment_new_logged_in' ), 10, 2 );
|
254 |
+
add_filter( 'comment_form_default_fields', array( $this, 'meta_comment_new' ) );
|
255 |
+
add_action( 'add_meta_boxes_comment', array( $this, 'meta_comment_add' ) );
|
256 |
+
add_filter( 'pre_comment_approved', array( $this, 'validate_comment' ), 10, 2 );
|
257 |
+
add_action( 'comment_post', array( $this, 'save_comment' ) );
|
258 |
+
add_action( 'edit_comment', array( $this, 'save_comment' ) );
|
259 |
+
|
260 |
+
if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
|
261 |
+
// Handle *_comment_meta
|
262 |
+
add_filter( 'get_comment_metadata', array( $this, 'get_comment_meta' ), 10, 4 );
|
263 |
+
|
264 |
+
if ( !pods_tableless() ) {
|
265 |
+
add_filter( 'add_comment_metadata', array( $this, 'add_comment_meta' ), 10, 5 );
|
266 |
+
add_filter( 'update_comment_metadata', array( $this, 'update_comment_meta' ), 10, 5 );
|
267 |
+
add_filter( 'delete_comment_metadata', array( $this, 'delete_comment_meta' ), 10, 5 );
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
|
272 |
+
// Handle Delete
|
273 |
+
add_action( 'delete_comment', array( $this, 'delete_comment' ), 10, 1 );
|
274 |
+
|
275 |
+
// @todo Patch core to provide $option back in filters, patch core to add filter pre_add_option to add_option
|
276 |
+
/*if ( !empty( self::$settings ) ) {
|
277 |
+
foreach ( self::$settings as $setting_pod ) {
|
278 |
+
foreach ( $setting_pod[ 'fields' ] as $option ) {
|
279 |
+
add_filter( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( $this, 'get_option' ), 10, 1 );
|
280 |
+
add_action( 'add_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( $this, 'add_option' ), 10, 2 );
|
281 |
+
add_filter( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( $this, 'update_option' ), 10, 2 );
|
282 |
+
}
|
283 |
+
}
|
284 |
+
}*/
|
285 |
+
|
286 |
+
if ( is_admin() )
|
287 |
+
$this->integrations();
|
288 |
+
|
289 |
+
add_action( 'init', array( $this, 'enqueue' ), 9 );
|
290 |
+
|
291 |
+
if ( function_exists( 'pll_current_language' ) )
|
292 |
+
add_action( 'init', array( $this, 'cache_pods' ), 101 );
|
293 |
+
|
294 |
+
do_action( 'pods_meta_init' );
|
295 |
+
|
296 |
+
return $this;
|
297 |
+
}
|
298 |
+
|
299 |
+
public static function enqueue () {
|
300 |
+
foreach ( self::$queue as $type => $objects ) {
|
301 |
+
foreach ( $objects as $pod_name => $pod ) {
|
302 |
+
pods_transient_set( 'pods_pod_' . $pod_name, $pod );
|
303 |
+
}
|
304 |
+
|
305 |
+
self::$$type = array_merge( self::$$type, $objects );
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Go back through and cache the Pods now that Polylang has loaded
|
311 |
+
*/
|
312 |
+
public function cache_pods () {
|
313 |
+
self::$advanced_content_types = pods_api()->load_pods( array( 'type' => 'pod', 'refresh' => true ) );
|
314 |
+
self::$post_types = pods_api()->load_pods( array( 'type' => 'post_type', 'refresh' => true ) );
|
315 |
+
self::$taxonomies = pods_api()->load_pods( array( 'type' => 'taxonomy', 'refresh' => true ) );
|
316 |
+
self::$media = pods_api()->load_pods( array( 'type' => 'media', 'refresh' => true ) );
|
317 |
+
self::$user = pods_api()->load_pods( array( 'type' => 'user', 'refresh' => true ) );
|
318 |
+
self::$comment = pods_api()->load_pods( array( 'type' => 'comment', 'refresh' => true ) );
|
319 |
+
self::$settings = pods_api()->load_pods( array( 'type' => 'settings', 'refresh' => true ) );
|
320 |
+
}
|
321 |
+
|
322 |
+
public function register ( $type, $pod ) {
|
323 |
+
$pod_type = $type;
|
324 |
+
|
325 |
+
if ( 'post_type' == $type )
|
326 |
+
$type = 'post_types';
|
327 |
+
elseif ( 'taxonomy' == $type )
|
328 |
+
$type = 'taxonomies';
|
329 |
+
elseif ( 'pod' == $type )
|
330 |
+
$type = 'advanced_content_types';
|
331 |
+
|
332 |
+
if ( !isset( self::$queue[ $type ] ) )
|
333 |
+
self::$queue[ $type ] = array();
|
334 |
+
|
335 |
+
if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) {
|
336 |
+
$data = array();
|
337 |
+
|
338 |
+
foreach ( $pod as $p ) {
|
339 |
+
$data[] = $this->register( $type, $p );
|
340 |
+
}
|
341 |
+
|
342 |
+
return $data;
|
343 |
+
}
|
344 |
+
|
345 |
+
$pod[ 'type' ] = $pod_type;
|
346 |
+
$pod = pods_api()->save_pod( $pod, false, false );
|
347 |
+
|
348 |
+
if ( !empty( $pod ) ) {
|
349 |
+
self::$object_identifier--;
|
350 |
+
|
351 |
+
self::$queue[ $type ][ $pod[ 'name' ] ] = $pod;
|
352 |
+
|
353 |
+
return $pod;
|
354 |
+
}
|
355 |
+
|
356 |
+
return false;
|
357 |
+
}
|
358 |
+
|
359 |
+
public function register_field ( $pod, $field ) {
|
360 |
+
if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) {
|
361 |
+
$data = array();
|
362 |
+
|
363 |
+
foreach ( $pod as $p ) {
|
364 |
+
$data[] = $this->register_field( $p, $field );
|
365 |
+
}
|
366 |
+
|
367 |
+
return $data;
|
368 |
+
}
|
369 |
+
|
370 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $pod )
|
371 |
+
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $pod ), false );
|
372 |
+
|
373 |
+
$pod = self::$current_pod_data;
|
374 |
+
|
375 |
+
if ( !empty( $pod ) ) {
|
376 |
+
$type = $pod[ 'type' ];
|
377 |
+
|
378 |
+
if ( 'post_type' == $pod[ 'type' ] )
|
379 |
+
$type = 'post_types';
|
380 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] )
|
381 |
+
$type = 'taxonomies';
|
382 |
+
elseif ( 'pod' == $pod[ 'type' ] )
|
383 |
+
$type = 'advanced_content_types';
|
384 |
+
|
385 |
+
if ( !isset( self::$queue[ $pod[ 'type' ] ] ) )
|
386 |
+
self::$queue[ $type ] = array();
|
387 |
+
|
388 |
+
$field = pods_api()->save_field( $field, false, false, $pod[ 'id' ] );
|
389 |
+
|
390 |
+
if ( !empty( $field ) ) {
|
391 |
+
$pod[ 'fields' ][ $field[ 'name' ] ] = $field;
|
392 |
+
|
393 |
+
self::$queue[ $type ][ $pod[ 'name' ] ] = $pod;
|
394 |
+
|
395 |
+
return $field;
|
396 |
+
}
|
397 |
+
}
|
398 |
+
|
399 |
+
return false;
|
400 |
+
}
|
401 |
+
|
402 |
+
public function integrations () {
|
403 |
+
// Codepress Admin Columns 2.x
|
404 |
+
add_filter( 'cac/meta_keys/storage_key=post', array( $this, 'cpac_meta_keys_get' ), 10, 2 );
|
405 |
+
add_filter( 'cac/meta_keys/storage_key=link', array( $this, 'cpac_meta_keys_get' ), 10, 2 );
|
406 |
+
add_filter( 'cac/meta_keys/storage_key=media', array( $this, 'cpac_meta_keys_get' ), 10, 2 );
|
407 |
+
add_filter( 'cac/meta_keys/storage_key=user', array( $this, 'cpac_meta_keys_get' ), 10, 2 );
|
408 |
+
add_filter( 'cac/meta_keys/storage_key=comment', array( $this, 'cpac_meta_keys_get' ), 10, 2 );
|
409 |
+
add_filter( 'cac/post_types', array( $this, 'cpac_post_types' ), 10, 1 );
|
410 |
+
add_filter( 'cac/column/meta/value', array( $this, 'cpac_meta_value' ), 10, 3 );
|
411 |
+
|
412 |
+
// Codepress Admin Columns 1.x
|
413 |
+
add_filter( 'cpac-get-meta-by-type', array( $this, 'cpac_meta_keys' ), 10, 2 );
|
414 |
+
add_filter( 'cpac-get-post-types', array( $this, 'cpac_post_types' ), 10, 1 );
|
415 |
+
add_filter( 'cpac_get_column_value_custom_field', array( $this, 'cpac_meta_values' ), 10, 5 );
|
416 |
+
}
|
417 |
+
|
418 |
+
public function cpac_meta_keys_get ( $meta_fields, $obj ) {
|
419 |
+
return $this->cpac_meta_keys( $meta_fields, $obj->key, $obj->type );
|
420 |
+
}
|
421 |
+
|
422 |
+
public function cpac_meta_keys ( $meta_fields, $cac_key, $cac_type = null ) {
|
423 |
+
$object_type = 'post_type';
|
424 |
+
$object = $cac_key;
|
425 |
+
|
426 |
+
if ( !empty( $cac_type ) )
|
427 |
+
$object_type = $cac_key;
|
428 |
+
|
429 |
+
if ( in_array( $cac_key, array( 'wp-links', 'link' ) ) )
|
430 |
+
$object_type = $object = 'link';
|
431 |
+
elseif ( in_array( $cac_key, array( 'wp-media', 'media' ) ) )
|
432 |
+
$object_type = $object = 'media';
|
433 |
+
elseif ( in_array( $cac_key, array( 'wp-users', 'user' ) ) )
|
434 |
+
$object_type = $object = 'user';
|
435 |
+
elseif ( in_array( $cac_key, array( 'wp-comments', 'comment' ) ) )
|
436 |
+
$object_type = $object = 'comment';
|
437 |
+
|
438 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object )
|
439 |
+
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
|
440 |
+
|
441 |
+
$pod = self::$current_pod_data;
|
442 |
+
|
443 |
+
// Add Pods fields
|
444 |
+
if ( !empty( $pod ) && $object_type == $pod[ 'type' ] ) {
|
445 |
+
foreach ( $pod[ 'fields' ] as $field => $field_data ) {
|
446 |
+
if ( !is_array( $meta_fields ) )
|
447 |
+
$meta_fields = array();
|
448 |
+
|
449 |
+
if ( !in_array( $field, $meta_fields ) )
|
450 |
+
$meta_fields[] = $field;
|
451 |
+
}
|
452 |
+
}
|
453 |
+
|
454 |
+
// Remove internal Pods fields
|
455 |
+
if ( is_array( $meta_fields ) ) {
|
456 |
+
foreach ( $meta_fields as $k => $meta_field ) {
|
457 |
+
if ( 0 === strpos( $meta_field, '_pods_' ) )
|
458 |
+
unset( $meta_fields[ $k ] );
|
459 |
+
}
|
460 |
+
}
|
461 |
+
|
462 |
+
return $meta_fields;
|
463 |
+
}
|
464 |
+
|
465 |
+
public function cpac_post_types ( $post_types ) {
|
466 |
+
// Remove internal Pods post types
|
467 |
+
foreach ( $post_types as $post_type => $post_type_name ) {
|
468 |
+
if ( 0 === strpos( $post_type, '_pods_' ) || 0 === strpos( $post_type_name, '_pods_' ) )
|
469 |
+
unset( $post_types[ $post_type ] );
|
470 |
+
}
|
471 |
+
|
472 |
+
return $post_types;
|
473 |
+
}
|
474 |
+
|
475 |
+
public function cpac_meta_value ( $meta, $id, $obj ) {
|
476 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
477 |
+
|
478 |
+
$object_type = 'post_type';
|
479 |
+
$object = $obj->storage_model->key;
|
480 |
+
|
481 |
+
if ( in_array( $obj->storage_model->type, array( 'wp-links', 'link' ) ) )
|
482 |
+
$object_type = $object = 'link';
|
483 |
+
elseif ( in_array( $obj->storage_model->type, array( 'wp-media', 'media' ) ) )
|
484 |
+
$object_type = $object = 'media';
|
485 |
+
elseif ( in_array( $obj->storage_model->type, array( 'wp-users', 'user' ) ) )
|
486 |
+
$object_type = $object = 'user';
|
487 |
+
elseif ( in_array( $obj->storage_model->type, array( 'wp-comments', 'comment' ) ) )
|
488 |
+
$object_type = $object = 'comment';
|
489 |
+
|
490 |
+
$field = substr( $obj->options->field, 0, 10 ) == "cpachidden" ? str_replace( 'cpachidden', '', $obj->options->field ) : $obj->options->field;
|
491 |
+
$field_type = $obj->options->field_type;
|
492 |
+
|
493 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object )
|
494 |
+
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
|
495 |
+
|
496 |
+
$pod = self::$current_pod_data;
|
497 |
+
|
498 |
+
// Add Pods fields
|
499 |
+
if ( !empty( $pod ) && isset( $pod[ 'fields' ][ $field ] ) ) {
|
500 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'user', 'comment', 'media' ) ) && ( !empty( $field_type ) || in_array( $pod[ 'fields' ][ $field ][ 'type' ], $tableless_field_types ) ) )
|
501 |
+
$meta = get_metadata( ( 'post_type' == $pod[ 'type' ] ? 'post' : $pod[ 'type' ] ), $id, $field, true );
|
502 |
+
|
503 |
+
$meta = PodsForm::field_method( $pod[ 'fields' ][ $field ][ 'type' ], 'ui', $id, $meta, $field, array_merge( $pod[ 'fields' ][ $field ], $pod[ 'fields' ][ $field ][ 'options' ] ), $pod[ 'fields' ], $pod );
|
504 |
+
}
|
505 |
+
|
506 |
+
return $meta;
|
507 |
+
}
|
508 |
+
|
509 |
+
public function cpac_meta_values ( $meta, $field_type, $field, $type, $id ) {
|
510 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
511 |
+
|
512 |
+
$object = $type;
|
513 |
+
|
514 |
+
if ( 'wp-media' == $type )
|
515 |
+
$object = 'media';
|
516 |
+
elseif ( 'wp-users' == $type )
|
517 |
+
$object = 'user';
|
518 |
+
elseif ( 'wp-comments' == $type )
|
519 |
+
$object = 'comment';
|
520 |
+
|
521 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object )
|
522 |
+
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
|
523 |
+
|
524 |
+
$pod = self::$current_pod_data;
|
525 |
+
|
526 |
+
// Add Pods fields
|
527 |
+
if ( !empty( $pod ) && isset( $pod[ 'fields' ][ $field ] ) ) {
|
528 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'user', 'comment', 'media' ) ) && ( !empty( $field_type ) || in_array( $pod[ 'fields' ][ $field ][ 'type' ], $tableless_field_types ) ) )
|
529 |
+
$meta = get_metadata( ( 'post_type' == $pod[ 'type' ] ? 'post' : $pod[ 'type' ] ), $id, $field, true );
|
530 |
+
|
531 |
+
$meta = PodsForm::field_method( $pod[ 'fields' ][ $field ][ 'type' ], 'ui', $id, $meta, $field, array_merge( $pod[ 'fields' ][ $field ], $pod[ 'fields' ][ $field ][ 'options' ] ), $pod[ 'fields' ], $pod );
|
532 |
+
}
|
533 |
+
|
534 |
+
return $meta;
|
535 |
+
}
|
536 |
+
|
537 |
+
/**
|
538 |
+
* Add a meta group of fields to add/edit forms
|
539 |
+
*
|
540 |
+
* @param string|array $pod The pod or type of element to attach the group to.
|
541 |
+
* @param string $label Title of the edit screen section, visible to user.
|
542 |
+
* @param string|array $fields Either a comma separated list of text fields or an associative array containing field infomration.
|
543 |
+
* @param string $context (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').
|
544 |
+
* @param string $priority (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low').
|
545 |
+
*
|
546 |
+
* @since 2.0
|
547 |
+
*
|
548 |
+
* @return mixed|void
|
549 |
+
*/
|
550 |
+
public function group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default' ) {
|
551 |
+
if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) {
|
552 |
+
foreach ( $pod as $p ) {
|
553 |
+
$this->group_add( $pod, $label, $fields, $context, $priority );
|
554 |
+
}
|
555 |
+
|
556 |
+
return true;
|
557 |
+
}
|
558 |
+
|
559 |
+
if ( !is_array( $pod ) ) {
|
560 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $pod )
|
561 |
+
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $pod ), false );
|
562 |
+
|
563 |
+
if ( !empty( self::$current_pod_data ) )
|
564 |
+
$pod = self::$current_pod_data;
|
565 |
+
else {
|
566 |
+
$type = 'post_type';
|
567 |
+
|
568 |
+
if ( in_array( $pod, array( 'media', 'user', 'comment' ) ) )
|
569 |
+
$type = $pod;
|
570 |
+
|
571 |
+
$pod = array(
|
572 |
+
'name' => $pod,
|
573 |
+
'type' => $type
|
574 |
+
);
|
575 |
+
}
|
576 |
+
}
|
577 |
+
|
578 |
+
if ( is_array( $pod ) && !isset( $pod[ 'id' ] ) ) {
|
579 |
+
$defaults = array(
|
580 |
+
'name' => '',
|
581 |
+
'type' => 'post_type'
|
582 |
+
);
|
583 |
+
|
584 |
+
$pod = array_merge( $defaults, $pod );
|
585 |
+
}
|
586 |
+
|
587 |
+
if ( 'post' == $pod[ 'type' ] )
|
588 |
+
$pod[ 'type' ] = 'post_type';
|
589 |
+
|
590 |
+
if ( empty( $pod[ 'name' ] ) && isset( $pod[ 'object' ] ) && !empty( $pod[ 'object' ] ) )
|
591 |
+
$pod[ 'name' ] = $pod[ 'object' ];
|
592 |
+
elseif ( !isset( $pod[ 'object' ] ) || empty( $pod[ 'object' ] ) )
|
593 |
+
$pod[ 'object' ] = $pod[ 'name' ];
|
594 |
+
|
595 |
+
if ( empty( $pod[ 'object' ] ) )
|
596 |
+
return pods_error( __( 'Object required to add a Pods meta group', 'pods' ) );
|
597 |
+
|
598 |
+
$object_name = $pod[ 'object' ];
|
599 |
+
|
600 |
+
if ( 'pod' == $pod[ 'type' ] )
|
601 |
+
$object_name = $pod[ 'name' ];
|
602 |
+
|
603 |
+
if ( !isset( self::$groups[ $pod[ 'type' ] ] ) )
|
604 |
+
self::$groups[ $pod[ 'type' ] ] = array();
|
605 |
+
|
606 |
+
if ( !isset( self::$groups[ $pod[ 'type' ] ][ $object_name ] ) )
|
607 |
+
self::$groups[ $pod[ 'type' ] ][ $object_name ] = array();
|
608 |
+
|
609 |
+
$_fields = array();
|
610 |
+
|
611 |
+
if ( !is_array( $fields ) )
|
612 |
+
$fields = explode( ',', $fields );
|
613 |
+
|
614 |
+
foreach ( $fields as $k => $field ) {
|
615 |
+
$name = $k;
|
616 |
+
|
617 |
+
$defaults = array(
|
618 |
+
'name' => $name,
|
619 |
+
'label' => $name,
|
620 |
+
'type' => 'text'
|
621 |
+
);
|
622 |
+
|
623 |
+
if ( !is_array( $field ) ) {
|
624 |
+
$name = trim( $field );
|
625 |
+
|
626 |
+
$field = array(
|
627 |
+
'name' => $name,
|
628 |
+
'label' => $name
|
629 |
+
);
|
630 |
+
}
|
631 |
+
|
632 |
+
$field = array_merge( $defaults, $field );
|
633 |
+
|
634 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
635 |
+
|
636 |
+
if ( isset( $pod[ 'fields' ] ) && isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) )
|
637 |
+
$field = array_merge( $field, $pod[ 'fields' ][ $field[ 'name' ] ] );
|
638 |
+
|
639 |
+
$_fields[ $k ] = $field;
|
640 |
+
}
|
641 |
+
|
642 |
+
// Setup field options
|
643 |
+
$fields = PodsForm::fields_setup( $_fields );
|
644 |
+
|
645 |
+
$group = array(
|
646 |
+
'pod' => $pod,
|
647 |
+
'label' => $label,
|
648 |
+
'fields' => $fields,
|
649 |
+
'context' => $context,
|
650 |
+
'priority' => $priority
|
651 |
+
);
|
652 |
+
|
653 |
+
// Filter group data, pass vars separately for reference down the line (in case array changed by other filter)
|
654 |
+
$group = apply_filters( 'pods_meta_group_add_' . $pod[ 'type' ] . '_' . $object_name, $group, $pod, $label, $fields );
|
655 |
+
$group = apply_filters( 'pods_meta_group_add_' . $pod[ 'type' ], $group, $pod, $label, $fields );
|
656 |
+
$group = apply_filters( 'pods_meta_group_add', $group, $pod, $label, $fields );
|
657 |
+
|
658 |
+
self::$groups[ $pod[ 'type' ] ][ $object_name ][] = $group;
|
659 |
+
|
660 |
+
// Hook it up!
|
661 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
662 |
+
if ( !has_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) ) )
|
663 |
+
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
|
664 |
+
|
665 |
+
/*if ( !has_action( 'save_post', array( $this, 'save_post' ), 10, 3 ) )
|
666 |
+
add_action( 'save_post', array( $this, 'save_post' ), 10, 3 );*/
|
667 |
+
}
|
668 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
669 |
+
if ( !has_action( $pod[ 'object' ] . '_edit_form_fields', array( $this, 'meta_taxonomy' ), 10, 2 ) ) {
|
670 |
+
add_action( $pod[ 'object' ] . '_edit_form_fields', array( $this, 'meta_taxonomy' ), 10, 2 );
|
671 |
+
add_action( $pod[ 'object' ] . '_add_form_fields', array( $this, 'meta_taxonomy' ), 10, 1 );
|
672 |
+
}
|
673 |
+
|
674 |
+
if ( !has_action( 'edit_term', array( $this, 'save_taxonomy' ), 10, 3 ) ) {
|
675 |
+
add_action( 'edit_term', array( $this, 'save_taxonomy' ), 10, 3 );
|
676 |
+
add_action( 'create_term', array( $this, 'save_taxonomy' ), 10, 3 );
|
677 |
+
}
|
678 |
+
}
|
679 |
+
elseif ( 'media' == $pod[ 'type' ] ) {
|
680 |
+
if ( !has_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 ) ) {
|
681 |
+
if ( pods_version_check( 'wp', '3.5' ) ) {
|
682 |
+
add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
|
683 |
+
add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 );
|
684 |
+
}
|
685 |
+
|
686 |
+
add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 );
|
687 |
+
|
688 |
+
add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 );
|
689 |
+
add_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 );
|
690 |
+
}
|
691 |
+
}
|
692 |
+
elseif ( 'user' == $pod[ 'type' ] ) {
|
693 |
+
if ( !has_action( 'show_user_profile', array( $this, 'meta_user' ) ) ) {
|
694 |
+
add_action( 'show_user_profile', array( $this, 'meta_user' ) );
|
695 |
+
add_action( 'edit_user_profile', array( $this, 'meta_user' ) );
|
696 |
+
//add_action( 'user_register', array( $this, 'save_user' ) );
|
697 |
+
add_action( 'profile_update', array( $this, 'save_user' ) );
|
698 |
+
}
|
699 |
+
}
|
700 |
+
elseif ( 'comment' == $pod[ 'type' ] ) {
|
701 |
+
if ( !has_action( 'comment_form_logged_in_after', array( $this, 'meta_comment_new_logged_in' ), 10, 2 ) ) {
|
702 |
+
add_action( 'comment_form_logged_in_after', array( $this, 'meta_comment_new_logged_in' ), 10, 2 );
|
703 |
+
add_filter( 'comment_form_default_fields', array( $this, 'meta_comment_new' ) );
|
704 |
+
add_action( 'add_meta_boxes_comment', array( $this, 'meta_comment_add' ) );
|
705 |
+
add_action( 'wp_insert_comment', array( $this, 'save_comment' ) );
|
706 |
+
add_action( 'edit_comment', array( $this, 'save_comment' ) );
|
707 |
+
}
|
708 |
+
}
|
709 |
+
}
|
710 |
+
|
711 |
+
public function object_get ( $type, $name ) {
|
712 |
+
$object = self::$post_types;
|
713 |
+
|
714 |
+
if ( 'taxonomy' == $type )
|
715 |
+
$object = self::$taxonomies;
|
716 |
+
elseif ( 'media' == $type )
|
717 |
+
$object = self::$media;
|
718 |
+
elseif ( 'user' == $type )
|
719 |
+
$object = self::$user;
|
720 |
+
elseif ( 'comment' == $type )
|
721 |
+
$object = self::$comment;
|
722 |
+
|
723 |
+
if ( 'pod' != $type && !empty( $object ) && is_array( $object ) && isset( $object[ $name ] ) )
|
724 |
+
$pod = $object[ $name ];
|
725 |
+
else {
|
726 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $name )
|
727 |
+
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $name ), false );
|
728 |
+
|
729 |
+
$pod = self::$current_pod_data;
|
730 |
+
}
|
731 |
+
|
732 |
+
if ( empty( $pod ) )
|
733 |
+
return array();
|
734 |
+
|
735 |
+
$defaults = array(
|
736 |
+
'name' => 'post',
|
737 |
+
'object' => 'post',
|
738 |
+
'type' => 'post_type'
|
739 |
+
);
|
740 |
+
|
741 |
+
$pod = array_merge( $defaults, (array) $pod );
|
742 |
+
|
743 |
+
if ( empty( $pod[ 'name' ] ) )
|
744 |
+
$pod[ 'name' ] = $pod[ 'object' ];
|
745 |
+
elseif ( empty( $pod[ 'object' ] ) )
|
746 |
+
$pod[ 'object' ] = $pod[ 'name' ];
|
747 |
+
|
748 |
+
if ( $pod[ 'type' ] != $type )
|
749 |
+
return array();
|
750 |
+
|
751 |
+
return $pod;
|
752 |
+
}
|
753 |
+
|
754 |
+
/**
|
755 |
+
* @param $type
|
756 |
+
* @param $name
|
757 |
+
*
|
758 |
+
* @return array
|
759 |
+
*/
|
760 |
+
public function groups_get ( $type, $name ) {
|
761 |
+
if ( 'post_type' == $type && 'attachment' == $name ) {
|
762 |
+
$type = 'media';
|
763 |
+
$name = 'media';
|
764 |
+
}
|
765 |
+
|
766 |
+
do_action( 'pods_meta_groups', $type, $name );
|
767 |
+
|
768 |
+
$pod = array();
|
769 |
+
$fields = array();
|
770 |
+
|
771 |
+
$object = self::$post_types;
|
772 |
+
|
773 |
+
if ( 'taxonomy' == $type )
|
774 |
+
$object = self::$taxonomies;
|
775 |
+
elseif ( 'media' == $type )
|
776 |
+
$object = self::$media;
|
777 |
+
elseif ( 'user' == $type )
|
778 |
+
$object = self::$user;
|
779 |
+
elseif ( 'comment' == $type )
|
780 |
+
$object = self::$comment;
|
781 |
+
|
782 |
+
if ( 'pod' != $type && !empty( $object ) && is_array( $object ) && isset( $object[ $name ] ) )
|
783 |
+
$fields = $object[ $name ][ 'fields' ];
|
784 |
+
else {
|
785 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $name )
|
786 |
+
self::$current_pod_data = pods_api()->load_pod( array( 'name' => $name ), false );
|
787 |
+
|
788 |
+
$pod = self::$current_pod_data;
|
789 |
+
|
790 |
+
if ( !empty( $pod ) )
|
791 |
+
$fields = $pod[ 'fields' ];
|
792 |
+
}
|
793 |
+
|
794 |
+
$defaults = array(
|
795 |
+
'name' => 'post',
|
796 |
+
'object' => 'post',
|
797 |
+
'type' => 'post_type'
|
798 |
+
);
|
799 |
+
|
800 |
+
$pod = array_merge( $defaults, (array) $pod );
|
801 |
+
|
802 |
+
if ( empty( $pod[ 'name' ] ) )
|
803 |
+
$pod[ 'name' ] = $pod[ 'object' ];
|
804 |
+
elseif ( empty( $pod[ 'object' ] ) )
|
805 |
+
$pod[ 'object' ] = $pod[ 'name' ];
|
806 |
+
|
807 |
+
if ( $pod[ 'type' ] != $type )
|
808 |
+
return array();
|
809 |
+
|
810 |
+
$groups = array(
|
811 |
+
array(
|
812 |
+
'pod' => $pod,
|
813 |
+
/**
|
814 |
+
* Filter the title of the Pods Metabox In The Post Editor
|
815 |
+
*
|
816 |
+
* @param string $title The title to use, default is 'More Fields'
|
817 |
+
* @param obj|Pod $pod Current Pods Object
|
818 |
+
* @param array $fields Array of fields that will go in the metabox
|
819 |
+
* @param string $type The type of Pod
|
820 |
+
* @params string $name Name of the Pod
|
821 |
+
*
|
822 |
+
* @returns string The title for the metabox.
|
823 |
+
*
|
824 |
+
* @since unknown
|
825 |
+
*/
|
826 |
+
'label' => apply_filters( 'pods_meta_default_box_title', __( 'More Fields', 'pods' ), $pod, $fields, $type, $name ),
|
827 |
+
'fields' => $fields,
|
828 |
+
'context' => 'normal',
|
829 |
+
'priority' => 'default'
|
830 |
+
)
|
831 |
+
);
|
832 |
+
|
833 |
+
if ( isset( self::$groups[ $type ] ) && isset( self::$groups[ $type ][ $name ] ) )
|
834 |
+
$groups = self::$groups[ $type ][ $name ];
|
835 |
+
|
836 |
+
return $groups;
|
837 |
+
}
|
838 |
+
|
839 |
+
/**
|
840 |
+
* @param $post_type
|
841 |
+
* @param null $post
|
842 |
+
*/
|
843 |
+
public function meta_post_add ( $post_type, $post = null ) {
|
844 |
+
if ( 'comment' == $post_type )
|
845 |
+
return;
|
846 |
+
|
847 |
+
if ( is_object( $post ) )
|
848 |
+
$post_type = $post->post_type;
|
849 |
+
|
850 |
+
$groups = $this->groups_get( 'post_type', $post_type );
|
851 |
+
|
852 |
+
foreach ( $groups as $group ) {
|
853 |
+
if ( empty( $group[ 'fields' ] ) )
|
854 |
+
continue;
|
855 |
+
|
856 |
+
$field_found = false;
|
857 |
+
|
858 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
859 |
+
if ( false !== PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ] ) ) {
|
860 |
+
$field_found = true;
|
861 |
+
break;
|
862 |
+
}
|
863 |
+
}
|
864 |
+
|
865 |
+
if ( empty( $group[ 'label' ] ) )
|
866 |
+
$group[ 'label' ] = get_post_type_object( $post_type )->labels->label;
|
867 |
+
|
868 |
+
if ( $field_found ) {
|
869 |
+
add_meta_box(
|
870 |
+
'pods-meta-' . sanitize_title( $group[ 'label' ] ),
|
871 |
+
$group[ 'label' ],
|
872 |
+
array( $this, 'meta_post' ),
|
873 |
+
$post_type,
|
874 |
+
$group[ 'context' ],
|
875 |
+
$group[ 'priority' ],
|
876 |
+
array( 'group' => $group )
|
877 |
+
);
|
878 |
+
|
879 |
+
}
|
880 |
+
}
|
881 |
+
}
|
882 |
+
|
883 |
+
/**
|
884 |
+
* @param $post
|
885 |
+
* @param $metabox
|
886 |
+
*/
|
887 |
+
public function meta_post ( $post, $metabox ) {
|
888 |
+
wp_enqueue_style( 'pods-form' );
|
889 |
+
wp_enqueue_script( 'pods' );
|
890 |
+
|
891 |
+
$pod_type = 'post';
|
892 |
+
|
893 |
+
if ( 'attachment' == $post->post_type ) {
|
894 |
+
$pod_type = 'media';
|
895 |
+
}
|
896 |
+
|
897 |
+
do_action( 'pods_meta_' . __FUNCTION__, $post );
|
898 |
+
|
899 |
+
$hidden_fields = array();
|
900 |
+
?>
|
901 |
+
<table class="form-table pods-metabox pods-admin pods-dependency">
|
902 |
+
<?php echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_' . $pod_type ), 'hidden' ); ?>
|
903 |
+
|
904 |
+
<?php
|
905 |
+
$id = null;
|
906 |
+
|
907 |
+
if ( is_object( $post ) && false === strpos( $_SERVER[ 'REQUEST_URI' ], '/post-new.php' ) )
|
908 |
+
$id = $post->ID;
|
909 |
+
|
910 |
+
if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod ) || self::$current_pod->pod != $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ] )
|
911 |
+
self::$current_pod = pods( $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ], $id, true );
|
912 |
+
elseif ( self::$current_pod->id() != $id )
|
913 |
+
self::$current_pod->fetch( $id );
|
914 |
+
|
915 |
+
$pod = self::$current_pod;
|
916 |
+
|
917 |
+
foreach ( $metabox[ 'args' ][ 'group' ][ 'fields' ] as $field ) {
|
918 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $metabox[ 'args' ][ 'group' ][ 'fields' ], $pod, $id ) ) {
|
919 |
+
if ( pods_var( 'hidden', $field[ 'options' ], false ) )
|
920 |
+
$field[ 'type' ] = 'hidden';
|
921 |
+
else
|
922 |
+
continue;
|
923 |
+
}
|
924 |
+
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) )
|
925 |
+
$field[ 'type' ] = 'hidden';
|
926 |
+
|
927 |
+
$value = '';
|
928 |
+
|
929 |
+
if ( !empty( $pod ) ) {
|
930 |
+
pods_no_conflict_on( 'post' );
|
931 |
+
|
932 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) );
|
933 |
+
|
934 |
+
pods_no_conflict_off( 'post' );
|
935 |
+
}
|
936 |
+
elseif ( !empty( $id ) )
|
937 |
+
$value = get_post_meta( $id, $field[ 'name' ], true );
|
938 |
+
|
939 |
+
if ( 'hidden' == $field[ 'type' ] ) {
|
940 |
+
$hidden_fields[] = array(
|
941 |
+
'field' => $field,
|
942 |
+
'value' => $value
|
943 |
+
);
|
944 |
+
}
|
945 |
+
else {
|
946 |
+
$depends = PodsForm::dependencies( $field, 'pods-meta-' );
|
947 |
+
|
948 |
+
do_action( 'pods_meta_' . __FUNCTION__ . '_' . $field[ 'name' ], $post, $field, $pod );
|
949 |
+
?>
|
950 |
+
<tr class="form-field pods-field <?php echo 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ); ?> <?php echo $depends; ?>">
|
951 |
+
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th>
|
952 |
+
<td>
|
953 |
+
<?php
|
954 |
+
// Remove any extra ? help icons
|
955 |
+
if ( isset( $field[ 'help' ] ) )
|
956 |
+
unset( $field[ 'help' ] );
|
957 |
+
?>
|
958 |
+
<?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?>
|
959 |
+
<?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?>
|
960 |
+
</td>
|
961 |
+
</tr>
|
962 |
+
<?php
|
963 |
+
do_action( 'pods_meta_' . __FUNCTION__ . '_' . $field[ 'name' ] . '_post', $post, $field, $pod );
|
964 |
+
}
|
965 |
+
}
|
966 |
+
?>
|
967 |
+
</table>
|
968 |
+
|
969 |
+
<?php
|
970 |
+
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $post );
|
971 |
+
|
972 |
+
foreach ( $hidden_fields as $hidden_field ) {
|
973 |
+
$field = $hidden_field[ 'field' ];
|
974 |
+
|
975 |
+
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $hidden_field[ 'value' ], 'hidden' );
|
976 |
+
}
|
977 |
+
?>
|
978 |
+
|
979 |
+
<script type="text/javascript">
|
980 |
+
jQuery( function ( $ ) {
|
981 |
+
$( document ).Pods( 'dependency', true );
|
982 |
+
} );
|
983 |
+
</script>
|
984 |
+
<?php
|
985 |
+
}
|
986 |
+
|
987 |
+
/**
|
988 |
+
* @param $new_status
|
989 |
+
* @param $old_status
|
990 |
+
* @param $post
|
991 |
+
*/
|
992 |
+
public function save_post_detect_new ( $new_status, $old_status, $post ) {
|
993 |
+
self::$old_post_status = $old_status;
|
994 |
+
}
|
995 |
+
|
996 |
+
/**
|
997 |
+
* @param $post_id
|
998 |
+
* @param $post
|
999 |
+
* @param $update
|
1000 |
+
*
|
1001 |
+
* @return int Post ID
|
1002 |
+
*/
|
1003 |
+
public function save_post ( $post_id, $post, $update = null ) {
|
1004 |
+
$is_new_item = false;
|
1005 |
+
|
1006 |
+
if ( is_bool( $update ) )
|
1007 |
+
$is_new_item = !$update; // false is new item
|
1008 |
+
elseif ( 'new' == self::$old_post_status ) {
|
1009 |
+
$is_new_item = true;
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
if ( empty( $_POST ) ) {
|
1013 |
+
return $post_id;
|
1014 |
+
}
|
1015 |
+
elseif ( !$is_new_item && !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_post' ) ) {
|
1016 |
+
return $post_id;
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
// Reset to avoid manual new post issues
|
1020 |
+
self::$old_post_status = '';
|
1021 |
+
|
1022 |
+
$blacklisted_types = array(
|
1023 |
+
'revision',
|
1024 |
+
'_pods_pod',
|
1025 |
+
'_pods_field'
|
1026 |
+
);
|
1027 |
+
|
1028 |
+
$blacklisted_types = apply_filters( 'pods_meta_save_post_blacklist_types', $blacklisted_types, $post_id, $post );
|
1029 |
+
|
1030 |
+
// @todo Figure out how to hook into autosave for saving meta
|
1031 |
+
|
1032 |
+
// Block Autosave and Revisions
|
1033 |
+
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || in_array( $post->post_type, $blacklisted_types ) )
|
1034 |
+
return $post_id;
|
1035 |
+
|
1036 |
+
// Block Quick Edits / Bulk Edits
|
1037 |
+
if ( 'edit.php' == pods_var( 'pagenow', 'global' ) && ( 'inline-save' == pods_var( 'action', 'post' ) || null != pods_var( 'bulk_edit', 'get' ) || is_array( pods_var( 'post', 'get' ) ) ) )
|
1038 |
+
return $post_id;
|
1039 |
+
|
1040 |
+
// Block Trash
|
1041 |
+
if ( in_array( pods_var( 'action', 'get' ), array( 'untrash', 'trash' ) ) )
|
1042 |
+
return $post_id;
|
1043 |
+
|
1044 |
+
// Block Auto-drafting and Trash (not via Admin action)
|
1045 |
+
$blacklisted_status = array(
|
1046 |
+
'auto-draft',
|
1047 |
+
'trash'
|
1048 |
+
);
|
1049 |
+
|
1050 |
+
$blacklisted_status = apply_filters( 'pods_meta_save_post_blacklist_status', $blacklisted_status, $post_id, $post );
|
1051 |
+
|
1052 |
+
if ( in_array( $post->post_status, $blacklisted_status ) )
|
1053 |
+
return $post_id;
|
1054 |
+
|
1055 |
+
$groups = $this->groups_get( 'post_type', $post->post_type );
|
1056 |
+
|
1057 |
+
if ( empty( $groups ) )
|
1058 |
+
return $post_id;
|
1059 |
+
|
1060 |
+
$data = array();
|
1061 |
+
|
1062 |
+
$id = $post_id;
|
1063 |
+
$pod = null;
|
1064 |
+
|
1065 |
+
foreach ( $groups as $group ) {
|
1066 |
+
if ( empty( $group[ 'fields' ] ) )
|
1067 |
+
continue;
|
1068 |
+
|
1069 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1070 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1071 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1072 |
+
elseif ( self::$current_pod->id() != $id )
|
1073 |
+
self::$current_pod->fetch( $id );
|
1074 |
+
|
1075 |
+
$pod = self::$current_pod;
|
1076 |
+
}
|
1077 |
+
|
1078 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1079 |
+
|
1080 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1081 |
+
if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
|
1082 |
+
continue;
|
1083 |
+
}
|
1084 |
+
|
1085 |
+
$data[ $field[ 'name' ] ] = '';
|
1086 |
+
|
1087 |
+
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
|
1088 |
+
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
|
1089 |
+
}
|
1090 |
+
}
|
1091 |
+
|
1092 |
+
if ( $is_new_item ) {
|
1093 |
+
do_action( 'pods_meta_create_pre_post', $data, $pod, $id, $groups, $post, $post->post_type );
|
1094 |
+
do_action( "pods_meta_create_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post );
|
1095 |
+
}
|
1096 |
+
|
1097 |
+
do_action( 'pods_meta_save_pre_post', $data, $pod, $id, $groups, $post, $post->post_type, $is_new_item );
|
1098 |
+
do_action( "pods_meta_save_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post, $is_new_item );
|
1099 |
+
|
1100 |
+
pods_no_conflict_on( 'post' );
|
1101 |
+
|
1102 |
+
if ( !empty( $pod ) ) {
|
1103 |
+
// Fix for Pods doing it's own sanitization
|
1104 |
+
$data = pods_unslash( (array) $data );
|
1105 |
+
|
1106 |
+
$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item ) );
|
1107 |
+
}
|
1108 |
+
elseif ( !empty( $id ) ) {
|
1109 |
+
foreach ( $data as $field => $value ) {
|
1110 |
+
update_post_meta( $id, $field, $value );
|
1111 |
+
}
|
1112 |
+
}
|
1113 |
+
|
1114 |
+
pods_no_conflict_off( 'post' );
|
1115 |
+
|
1116 |
+
if ( $is_new_item ) {
|
1117 |
+
do_action( 'pods_meta_create_post', $data, $pod, $id, $groups, $post, $post->post_type );
|
1118 |
+
do_action( "pods_meta_create_post_{$post->post_type}", $data, $pod, $id, $groups, $post );
|
1119 |
+
}
|
1120 |
+
|
1121 |
+
do_action( 'pods_meta_save_post', $data, $pod, $id, $groups, $post, $post->post_type, $is_new_item );
|
1122 |
+
do_action( "pods_meta_save_post_{$post->post_type}", $data, $pod, $id, $groups, $post, $is_new_item );
|
1123 |
+
|
1124 |
+
return $post_id;
|
1125 |
+
|
1126 |
+
}
|
1127 |
+
|
1128 |
+
/**
|
1129 |
+
* @param $form_fields
|
1130 |
+
* @param $post
|
1131 |
+
*
|
1132 |
+
* @return array
|
1133 |
+
*/
|
1134 |
+
public function meta_media ( $form_fields, $post ) {
|
1135 |
+
$groups = $this->groups_get( 'media', 'media' );
|
1136 |
+
|
1137 |
+
if ( empty( $groups ) || 'attachment' == pods_var( 'typenow', 'global' ) )
|
1138 |
+
return $form_fields;
|
1139 |
+
|
1140 |
+
wp_enqueue_style( 'pods-form' );
|
1141 |
+
|
1142 |
+
$id = null;
|
1143 |
+
|
1144 |
+
if ( is_object( $post ) )
|
1145 |
+
$id = $post->ID;
|
1146 |
+
|
1147 |
+
$pod = null;
|
1148 |
+
|
1149 |
+
$meta_nonce = PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_media' ), 'hidden' );
|
1150 |
+
|
1151 |
+
foreach ( $groups as $group ) {
|
1152 |
+
if ( empty( $group[ 'fields' ] ) )
|
1153 |
+
continue;
|
1154 |
+
|
1155 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1156 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1157 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1158 |
+
elseif ( self::$current_pod->id() != $id )
|
1159 |
+
self::$current_pod->fetch( $id );
|
1160 |
+
|
1161 |
+
$pod = self::$current_pod;
|
1162 |
+
}
|
1163 |
+
|
1164 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1165 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1166 |
+
if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
|
1167 |
+
continue;
|
1168 |
+
}
|
1169 |
+
|
1170 |
+
$value = '';
|
1171 |
+
|
1172 |
+
if ( !empty( $pod ) )
|
1173 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) );
|
1174 |
+
elseif ( !empty( $id ) ) {
|
1175 |
+
pods_no_conflict_on( 'post' );
|
1176 |
+
|
1177 |
+
$value = get_post_meta( $id, $field[ 'name' ], true );
|
1178 |
+
|
1179 |
+
pods_no_conflict_off( 'post' );
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
$form_fields[ 'pods_meta_' . $field[ 'name' ] ] = array(
|
1183 |
+
'label' => $field[ 'label' ],
|
1184 |
+
'input' => 'html',
|
1185 |
+
'html' => PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ) . $meta_nonce,
|
1186 |
+
'helps' => PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field )
|
1187 |
+
);
|
1188 |
+
}
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
$form_fields = apply_filters( 'pods_meta_' . __FUNCTION__, $form_fields );
|
1192 |
+
|
1193 |
+
return $form_fields;
|
1194 |
+
}
|
1195 |
+
|
1196 |
+
/**
|
1197 |
+
* @param $post
|
1198 |
+
* @param $attachment
|
1199 |
+
*
|
1200 |
+
* @return mixed
|
1201 |
+
*/
|
1202 |
+
public function save_media ( $post, $attachment ) {
|
1203 |
+
$groups = $this->groups_get( 'media', 'media' );
|
1204 |
+
|
1205 |
+
if ( empty( $groups ) )
|
1206 |
+
return $post;
|
1207 |
+
|
1208 |
+
$post_id = $attachment;
|
1209 |
+
|
1210 |
+
if ( empty( $_POST ) || !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_media' ) ) {
|
1211 |
+
return $post;
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
if ( is_array( $post ) && !empty( $post ) && isset( $post[ 'ID' ] ) && 'attachment' == $post[ 'post_type' ] )
|
1215 |
+
$post_id = $post[ 'ID' ];
|
1216 |
+
|
1217 |
+
if ( is_array( $post_id ) || empty( $post_id ) )
|
1218 |
+
return $post;
|
1219 |
+
|
1220 |
+
$data = array();
|
1221 |
+
|
1222 |
+
$id = $post_id;
|
1223 |
+
$pod = null;
|
1224 |
+
|
1225 |
+
foreach ( $groups as $group ) {
|
1226 |
+
if ( empty( $group[ 'fields' ] ) )
|
1227 |
+
continue;
|
1228 |
+
|
1229 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1230 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1231 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1232 |
+
elseif ( self::$current_pod->id() != $id )
|
1233 |
+
self::$current_pod->fetch( $id );
|
1234 |
+
|
1235 |
+
$pod = self::$current_pod;
|
1236 |
+
}
|
1237 |
+
|
1238 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1239 |
+
|
1240 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1241 |
+
if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
|
1242 |
+
continue;
|
1243 |
+
}
|
1244 |
+
|
1245 |
+
$data[ $field[ 'name' ] ] = '';
|
1246 |
+
|
1247 |
+
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
|
1248 |
+
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
|
1249 |
+
}
|
1250 |
+
}
|
1251 |
+
|
1252 |
+
do_action( 'pods_meta_save_pre_media', $data, $pod, $id, $groups, $post, $attachment );
|
1253 |
+
|
1254 |
+
if ( !empty( $pod ) ) {
|
1255 |
+
// Fix for Pods doing it's own sanitization
|
1256 |
+
$data = pods_unslash( (array) $data );
|
1257 |
+
|
1258 |
+
$pod->save( $data );
|
1259 |
+
}
|
1260 |
+
elseif ( !empty( $id ) ) {
|
1261 |
+
pods_no_conflict_on( 'post' );
|
1262 |
+
|
1263 |
+
foreach ( $data as $field => $value ) {
|
1264 |
+
update_post_meta( $id, $field, $value );
|
1265 |
+
}
|
1266 |
+
|
1267 |
+
pods_no_conflict_off( 'post' );
|
1268 |
+
}
|
1269 |
+
|
1270 |
+
do_action( 'pods_meta_save_media', $data, $pod, $id, $groups, $post, $attachment );
|
1271 |
+
|
1272 |
+
return $post;
|
1273 |
+
}
|
1274 |
+
|
1275 |
+
public function save_media_ajax () {
|
1276 |
+
if ( !isset( $_POST[ 'id' ] ) || empty( $_POST[ 'id' ] ) || absint( $_POST[ 'id' ] ) < 1 )
|
1277 |
+
return;
|
1278 |
+
|
1279 |
+
$id = absint( $_POST[ 'id' ] );
|
1280 |
+
|
1281 |
+
if ( !isset( $_POST[ 'nonce' ] ) || empty( $_POST[ 'nonce' ] ) )
|
1282 |
+
return;
|
1283 |
+
|
1284 |
+
check_ajax_referer( 'update-post_' . $id, 'nonce' );
|
1285 |
+
|
1286 |
+
if ( !current_user_can( 'edit_post', $id ) )
|
1287 |
+
return;
|
1288 |
+
|
1289 |
+
$post = get_post( $id, ARRAY_A );
|
1290 |
+
|
1291 |
+
if ( 'attachment' != $post[ 'post_type' ] )
|
1292 |
+
return;
|
1293 |
+
|
1294 |
+
// fix ALL THE THINGS
|
1295 |
+
|
1296 |
+
if ( !isset( $_REQUEST[ 'attachments' ] ) )
|
1297 |
+
$_REQUEST[ 'attachments' ] = array();
|
1298 |
+
|
1299 |
+
if ( !isset( $_REQUEST[ 'attachments' ][ $id ] ) )
|
1300 |
+
$_REQUEST[ 'attachments' ][ $id ] = array();
|
1301 |
+
|
1302 |
+
if ( empty( $_REQUEST[ 'attachments' ][ $id ] ) )
|
1303 |
+
$_REQUEST[ 'attachments' ][ $id ][ '_fix_wp' ] = 1;
|
1304 |
+
}
|
1305 |
+
|
1306 |
+
/**
|
1307 |
+
* @param $tag
|
1308 |
+
* @param null $taxonomy
|
1309 |
+
*/
|
1310 |
+
public function meta_taxonomy ( $tag, $taxonomy = null ) {
|
1311 |
+
wp_enqueue_style( 'pods-form' );
|
1312 |
+
|
1313 |
+
do_action( 'pods_meta_' . __FUNCTION__, $tag, $taxonomy );
|
1314 |
+
|
1315 |
+
$taxonomy_name = $taxonomy;
|
1316 |
+
|
1317 |
+
if ( !is_object( $tag ) )
|
1318 |
+
$taxonomy_name = $tag;
|
1319 |
+
|
1320 |
+
$groups = $this->groups_get( 'taxonomy', $taxonomy_name );
|
1321 |
+
|
1322 |
+
$id = null;
|
1323 |
+
|
1324 |
+
if ( is_object( $tag ) )
|
1325 |
+
$id = $tag->term_id;
|
1326 |
+
|
1327 |
+
$pod = null;
|
1328 |
+
|
1329 |
+
echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_taxonomy' ), 'hidden' );
|
1330 |
+
|
1331 |
+
foreach ( $groups as $group ) {
|
1332 |
+
if ( empty( $group[ 'fields' ] ) )
|
1333 |
+
continue;
|
1334 |
+
|
1335 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1336 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1337 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1338 |
+
elseif ( self::$current_pod->id() != $id )
|
1339 |
+
self::$current_pod->fetch( $id );
|
1340 |
+
|
1341 |
+
$pod = self::$current_pod;
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1345 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1346 |
+
if ( pods_var( 'hidden', $field[ 'options' ], false ) )
|
1347 |
+
$field[ 'type' ] = 'hidden';
|
1348 |
+
else
|
1349 |
+
continue;
|
1350 |
+
}
|
1351 |
+
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) )
|
1352 |
+
$field[ 'type' ] = 'hidden';
|
1353 |
+
|
1354 |
+
$value = '';
|
1355 |
+
|
1356 |
+
if ( !empty( $pod ) )
|
1357 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) );
|
1358 |
+
|
1359 |
+
if ( !is_object( $tag ) ) {
|
1360 |
+
?>
|
1361 |
+
<div class="form-field pods-field"<?php echo( 'hidden' == $field[ 'type' ] ? ' style="display:none;"' : '' ); ?>>
|
1362 |
+
<?php
|
1363 |
+
echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field );
|
1364 |
+
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id );
|
1365 |
+
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field );
|
1366 |
+
?>
|
1367 |
+
</div>
|
1368 |
+
<?php
|
1369 |
+
}
|
1370 |
+
else {
|
1371 |
+
?>
|
1372 |
+
<tr class="form-field pods-field <?php echo 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ); ?>"<?php echo( 'hidden' == $field[ 'type' ] ? ' style="display:none;"' : '' ); ?>>
|
1373 |
+
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th>
|
1374 |
+
<td>
|
1375 |
+
<?php
|
1376 |
+
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id );
|
1377 |
+
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field );
|
1378 |
+
?>
|
1379 |
+
</td>
|
1380 |
+
</tr>
|
1381 |
+
<?php
|
1382 |
+
}
|
1383 |
+
}
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $tag, $taxonomy );
|
1387 |
+
}
|
1388 |
+
|
1389 |
+
/**
|
1390 |
+
* @param $term_id
|
1391 |
+
* @param $term_taxonomy_id
|
1392 |
+
* @param $taxonomy
|
1393 |
+
*/
|
1394 |
+
public function save_taxonomy ( $term_id, $term_taxonomy_id, $taxonomy ) {
|
1395 |
+
$is_new_item = false;
|
1396 |
+
|
1397 |
+
if ( 'create_term' == current_filter() )
|
1398 |
+
$is_new_item = true;
|
1399 |
+
|
1400 |
+
if ( empty( $_POST ) || !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_taxonomy' ) ) {
|
1401 |
+
return $term_id;
|
1402 |
+
}
|
1403 |
+
|
1404 |
+
// Block Quick Edits / Bulk Edits
|
1405 |
+
if ( 'inline-save-tax' == pods_var( 'action', 'post' ) || null != pods_var( 'delete_tags', 'post' ) ) {
|
1406 |
+
return $term_id;
|
1407 |
+
}
|
1408 |
+
|
1409 |
+
$groups = $this->groups_get( 'taxonomy', $taxonomy );
|
1410 |
+
|
1411 |
+
if ( empty( $groups ) )
|
1412 |
+
return $term_id;
|
1413 |
+
|
1414 |
+
$term = null;
|
1415 |
+
|
1416 |
+
$id = $term_id;
|
1417 |
+
$pod = null;
|
1418 |
+
|
1419 |
+
$has_fields = false;
|
1420 |
+
|
1421 |
+
foreach ( $groups as $group ) {
|
1422 |
+
if ( empty( $group[ 'fields' ] ) )
|
1423 |
+
continue;
|
1424 |
+
|
1425 |
+
if ( null === $term ) {
|
1426 |
+
$term = get_term( $term_id, $taxonomy );
|
1427 |
+
|
1428 |
+
$data = array(
|
1429 |
+
'name' => $term->name
|
1430 |
+
);
|
1431 |
+
}
|
1432 |
+
|
1433 |
+
$has_fields = true;
|
1434 |
+
|
1435 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1436 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1437 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1438 |
+
elseif ( self::$current_pod->id() != $id )
|
1439 |
+
self::$current_pod->fetch( $id );
|
1440 |
+
|
1441 |
+
$pod = self::$current_pod;
|
1442 |
+
}
|
1443 |
+
|
1444 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1445 |
+
|
1446 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1447 |
+
if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
|
1448 |
+
continue;
|
1449 |
+
}
|
1450 |
+
|
1451 |
+
$data[ $field[ 'name' ] ] = '';
|
1452 |
+
|
1453 |
+
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
|
1454 |
+
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
|
1455 |
+
}
|
1456 |
+
}
|
1457 |
+
|
1458 |
+
if ( !$has_fields ) {
|
1459 |
+
return $term_id;
|
1460 |
+
}
|
1461 |
+
|
1462 |
+
if ( $is_new_item ) {
|
1463 |
+
do_action( 'pods_meta_create_pre_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy );
|
1464 |
+
do_action( "pods_meta_create_pre_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy );
|
1465 |
+
}
|
1466 |
+
|
1467 |
+
do_action( 'pods_meta_save_pre_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item );
|
1468 |
+
do_action( "pods_meta_save_pre_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item );
|
1469 |
+
|
1470 |
+
pods_no_conflict_on( 'taxonomy' );
|
1471 |
+
|
1472 |
+
if ( !empty( $pod ) ) {
|
1473 |
+
// Fix for Pods doing it's own sanitization
|
1474 |
+
$data = pods_unslash( (array) $data );
|
1475 |
+
|
1476 |
+
$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item ) );
|
1477 |
+
}
|
1478 |
+
|
1479 |
+
pods_no_conflict_off( 'taxonomy' );
|
1480 |
+
|
1481 |
+
if ( $is_new_item ) {
|
1482 |
+
do_action( 'pods_meta_create_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy );
|
1483 |
+
do_action( "pods_meta_create_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy );
|
1484 |
+
}
|
1485 |
+
|
1486 |
+
do_action( 'pods_meta_save_taxonomy', $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item );
|
1487 |
+
do_action( "pods_meta_save_taxonomy_{$taxonomy}", $data, $pod, $id, $groups, $term_id, $term_taxonomy_id, $taxonomy, $is_new_item );
|
1488 |
+
|
1489 |
+
return $term_id;
|
1490 |
+
}
|
1491 |
+
|
1492 |
+
/**
|
1493 |
+
* @param $user_id
|
1494 |
+
*/
|
1495 |
+
public function meta_user ( $user_id ) {
|
1496 |
+
wp_enqueue_style( 'pods-form' );
|
1497 |
+
|
1498 |
+
do_action( 'pods_meta_' . __FUNCTION__, $user_id );
|
1499 |
+
|
1500 |
+
$groups = $this->groups_get( 'user', 'user' );
|
1501 |
+
|
1502 |
+
if ( is_object( $user_id ) )
|
1503 |
+
$user_id = $user_id->ID;
|
1504 |
+
|
1505 |
+
$id = $user_id;
|
1506 |
+
$pod = null;
|
1507 |
+
|
1508 |
+
foreach ( $groups as $group ) {
|
1509 |
+
if ( empty( $group[ 'fields' ] ) )
|
1510 |
+
continue;
|
1511 |
+
|
1512 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1513 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1514 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1515 |
+
elseif ( self::$current_pod->id() != $id )
|
1516 |
+
self::$current_pod->fetch( $id );
|
1517 |
+
|
1518 |
+
$pod = self::$current_pod;
|
1519 |
+
}
|
1520 |
+
|
1521 |
+
$hidden_fields = array();
|
1522 |
+
?>
|
1523 |
+
<h3><?php echo $group[ 'label' ]; ?></h3>
|
1524 |
+
|
1525 |
+
<?php echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_user' ), 'hidden' ); ?>
|
1526 |
+
|
1527 |
+
<table class="form-table pods-meta">
|
1528 |
+
<tbody>
|
1529 |
+
<?php
|
1530 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1531 |
+
|
1532 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1533 |
+
if ( pods_var( 'hidden', $field[ 'options' ], false ) )
|
1534 |
+
$field[ 'type' ] = 'hidden';
|
1535 |
+
else
|
1536 |
+
continue;
|
1537 |
+
}
|
1538 |
+
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) )
|
1539 |
+
$field[ 'type' ] = 'hidden';
|
1540 |
+
|
1541 |
+
$value = '';
|
1542 |
+
|
1543 |
+
if ( !empty( $pod ) )
|
1544 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) );
|
1545 |
+
elseif ( !empty( $id ) ) {
|
1546 |
+
pods_no_conflict_on( 'user' );
|
1547 |
+
|
1548 |
+
$value = get_user_meta( $id, $field[ 'name' ], true );
|
1549 |
+
|
1550 |
+
pods_no_conflict_off( 'user' );
|
1551 |
+
}
|
1552 |
+
|
1553 |
+
if ( 'hidden' == $field[ 'type' ] ) {
|
1554 |
+
$hidden_fields[] = array(
|
1555 |
+
'field' => $field,
|
1556 |
+
'value' => $value
|
1557 |
+
);
|
1558 |
+
}
|
1559 |
+
else {
|
1560 |
+
?>
|
1561 |
+
<tr class="form-field pods-field <?php echo 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ); ?>">
|
1562 |
+
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th>
|
1563 |
+
<td>
|
1564 |
+
<?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?>
|
1565 |
+
<?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?>
|
1566 |
+
</td>
|
1567 |
+
</tr>
|
1568 |
+
<?php
|
1569 |
+
}
|
1570 |
+
}
|
1571 |
+
?>
|
1572 |
+
</tbody>
|
1573 |
+
</table>
|
1574 |
+
<?php
|
1575 |
+
foreach ( $hidden_fields as $hidden_field ) {
|
1576 |
+
$field = $hidden_field[ 'field' ];
|
1577 |
+
|
1578 |
+
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $hidden_field[ 'value' ], 'hidden' );
|
1579 |
+
}
|
1580 |
+
}
|
1581 |
+
|
1582 |
+
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $user_id );
|
1583 |
+
}
|
1584 |
+
|
1585 |
+
/**
|
1586 |
+
* @param $user_id
|
1587 |
+
*/
|
1588 |
+
public function save_user ( $user_id ) {
|
1589 |
+
|
1590 |
+
$is_new_item = false;
|
1591 |
+
|
1592 |
+
if ( 'user_register' == current_filter() ) {
|
1593 |
+
$is_new_item = true;
|
1594 |
+
}
|
1595 |
+
|
1596 |
+
if ( empty( $_POST ) ) {
|
1597 |
+
return $user_id;
|
1598 |
+
}
|
1599 |
+
elseif ( $is_new_item || !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_user' ) ) {
|
1600 |
+
return $user_id;
|
1601 |
+
}
|
1602 |
+
|
1603 |
+
$groups = $this->groups_get( 'user', 'user' );
|
1604 |
+
|
1605 |
+
if ( empty( $groups ) ) {
|
1606 |
+
return $user_id;
|
1607 |
+
}
|
1608 |
+
|
1609 |
+
if ( is_object( $user_id ) ) {
|
1610 |
+
$user_id = $user_id->ID;
|
1611 |
+
}
|
1612 |
+
|
1613 |
+
$data = array();
|
1614 |
+
|
1615 |
+
$id = $user_id;
|
1616 |
+
$pod = null;
|
1617 |
+
|
1618 |
+
foreach ( $groups as $group ) {
|
1619 |
+
if ( empty( $group[ 'fields' ] ) ) {
|
1620 |
+
continue;
|
1621 |
+
}
|
1622 |
+
|
1623 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1624 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) {
|
1625 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1626 |
+
}
|
1627 |
+
elseif ( self::$current_pod->id() != $id ) {
|
1628 |
+
self::$current_pod->fetch( $id );
|
1629 |
+
}
|
1630 |
+
|
1631 |
+
$pod = self::$current_pod;
|
1632 |
+
}
|
1633 |
+
|
1634 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1635 |
+
|
1636 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1637 |
+
if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) {
|
1638 |
+
continue;
|
1639 |
+
}
|
1640 |
+
}
|
1641 |
+
|
1642 |
+
$data[ $field[ 'name' ] ] = '';
|
1643 |
+
|
1644 |
+
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) {
|
1645 |
+
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
|
1646 |
+
}
|
1647 |
+
}
|
1648 |
+
}
|
1649 |
+
|
1650 |
+
if ( $is_new_item ) {
|
1651 |
+
do_action( 'pods_meta_create_pre_user', $data, $pod, $id, $groups );
|
1652 |
+
}
|
1653 |
+
|
1654 |
+
do_action( 'pods_meta_save_pre_user', $data, $pod, $id, $groups, $is_new_item );
|
1655 |
+
|
1656 |
+
pods_no_conflict_on( 'user' );
|
1657 |
+
|
1658 |
+
if ( !empty( $pod ) ) {
|
1659 |
+
// Fix for Pods doing it's own sanitization
|
1660 |
+
$data = pods_unslash( (array) $data );
|
1661 |
+
|
1662 |
+
$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item ) );
|
1663 |
+
}
|
1664 |
+
elseif ( !empty( $id ) ) {
|
1665 |
+
foreach ( $data as $field => $value ) {
|
1666 |
+
update_user_meta( $id, $field, $value );
|
1667 |
+
}
|
1668 |
+
}
|
1669 |
+
|
1670 |
+
pods_no_conflict_off( 'user' );
|
1671 |
+
|
1672 |
+
if ( $is_new_item ) {
|
1673 |
+
do_action( 'pods_meta_create_user', $data, $pod, $id, $groups );
|
1674 |
+
}
|
1675 |
+
|
1676 |
+
do_action( 'pods_meta_save_user', $data, $pod, $id, $groups, $is_new_item );
|
1677 |
+
|
1678 |
+
return $user_id;
|
1679 |
+
|
1680 |
+
}
|
1681 |
+
|
1682 |
+
/**
|
1683 |
+
* @param $commenter
|
1684 |
+
* @param $user_identity
|
1685 |
+
*/
|
1686 |
+
public function meta_comment_new_logged_in ( $commenter, $user_identity ) {
|
1687 |
+
wp_enqueue_style( 'pods-form' );
|
1688 |
+
|
1689 |
+
do_action( 'pods_meta_' . __FUNCTION__, $commenter, $user_identity );
|
1690 |
+
|
1691 |
+
$groups = $this->groups_get( 'comment', 'comment' );
|
1692 |
+
|
1693 |
+
$id = null;
|
1694 |
+
$pod = null;
|
1695 |
+
|
1696 |
+
echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_comment' ), 'hidden' );
|
1697 |
+
|
1698 |
+
foreach ( $groups as $group ) {
|
1699 |
+
if ( empty( $group[ 'fields' ] ) )
|
1700 |
+
continue;
|
1701 |
+
|
1702 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1703 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1704 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1705 |
+
elseif ( self::$current_pod->id() != $id )
|
1706 |
+
self::$current_pod->fetch( $id );
|
1707 |
+
|
1708 |
+
$pod = self::$current_pod;
|
1709 |
+
}
|
1710 |
+
|
1711 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1712 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1713 |
+
if ( pods_var( 'hidden', $field[ 'options' ], false ) )
|
1714 |
+
$field[ 'type' ] = 'hidden';
|
1715 |
+
else
|
1716 |
+
continue;
|
1717 |
+
}
|
1718 |
+
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) )
|
1719 |
+
$field[ 'type' ] = 'hidden';
|
1720 |
+
|
1721 |
+
$value = '';
|
1722 |
+
|
1723 |
+
if ( !empty( $pod ) )
|
1724 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) );
|
1725 |
+
elseif ( !empty( $id ) ) {
|
1726 |
+
pods_no_conflict_on( 'comment' );
|
1727 |
+
|
1728 |
+
$value = get_comment_meta( $id, $field[ 'name' ], true );
|
1729 |
+
|
1730 |
+
pods_no_conflict_off( 'comment' );
|
1731 |
+
}
|
1732 |
+
?>
|
1733 |
+
<p class="comment-form-author comment-form-pods-meta-<?php echo $field[ 'name' ]; ?> pods-field"<?php echo ( 'hidden' == $field[ 'type' ] ? ' style="display:none;"' : '' ); ?>>
|
1734 |
+
<?php
|
1735 |
+
echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field );
|
1736 |
+
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id );
|
1737 |
+
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field );
|
1738 |
+
?>
|
1739 |
+
</p>
|
1740 |
+
<?php
|
1741 |
+
}
|
1742 |
+
}
|
1743 |
+
|
1744 |
+
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $commenter, $user_identity );
|
1745 |
+
}
|
1746 |
+
|
1747 |
+
/**
|
1748 |
+
* @param $form_fields
|
1749 |
+
*
|
1750 |
+
* @return array
|
1751 |
+
*/
|
1752 |
+
public function meta_comment_new ( $form_fields ) {
|
1753 |
+
wp_enqueue_style( 'pods-form' );
|
1754 |
+
|
1755 |
+
$groups = $this->groups_get( 'comment', 'comment' );
|
1756 |
+
|
1757 |
+
$id = null;
|
1758 |
+
$pod = null;
|
1759 |
+
|
1760 |
+
$form_fields[ 'pods_meta' ] = PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_comment' ), 'hidden' );
|
1761 |
+
|
1762 |
+
foreach ( $groups as $group ) {
|
1763 |
+
if ( empty( $group[ 'fields' ] ) )
|
1764 |
+
continue;
|
1765 |
+
|
1766 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1767 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1768 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1769 |
+
elseif ( self::$current_pod->id() != $id )
|
1770 |
+
self::$current_pod->fetch( $id );
|
1771 |
+
|
1772 |
+
$pod = self::$current_pod;
|
1773 |
+
}
|
1774 |
+
|
1775 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1776 |
+
|
1777 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1778 |
+
if ( pods_var( 'hidden', $field[ 'options' ], false ) )
|
1779 |
+
$field[ 'type' ] = 'hidden';
|
1780 |
+
else
|
1781 |
+
continue;
|
1782 |
+
}
|
1783 |
+
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) )
|
1784 |
+
$field[ 'type' ] = 'hidden';
|
1785 |
+
|
1786 |
+
$value = '';
|
1787 |
+
|
1788 |
+
if ( !empty( $pod ) )
|
1789 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) );
|
1790 |
+
elseif ( !empty( $id ) ) {
|
1791 |
+
pods_no_conflict_on( 'comment' );
|
1792 |
+
|
1793 |
+
$value = get_comment_meta( $id, $field[ 'name' ], true );
|
1794 |
+
|
1795 |
+
pods_no_conflict_off( 'comment' );
|
1796 |
+
}
|
1797 |
+
|
1798 |
+
ob_start();
|
1799 |
+
?>
|
1800 |
+
<p class="comment-form-author comment-form-pods-meta-<?php echo $field[ 'name' ]; ?> pods-field"<?php echo( 'hidden' == $field[ 'type' ] ? ' style="display:none;"' : '' ); ?>>
|
1801 |
+
<?php
|
1802 |
+
echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field );
|
1803 |
+
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id );
|
1804 |
+
echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field );
|
1805 |
+
?>
|
1806 |
+
</p>
|
1807 |
+
<?php
|
1808 |
+
$form_fields[ 'pods_meta_' . $field[ 'name' ] ] = ob_get_clean();
|
1809 |
+
}
|
1810 |
+
}
|
1811 |
+
|
1812 |
+
$form_fields = apply_filters( 'pods_meta_' . __FUNCTION__, $form_fields );
|
1813 |
+
|
1814 |
+
return $form_fields;
|
1815 |
+
}
|
1816 |
+
|
1817 |
+
/**
|
1818 |
+
* @param $comment_type
|
1819 |
+
* @param null $comment
|
1820 |
+
*/
|
1821 |
+
public function meta_comment_add ( $comment_type, $comment = null ) {
|
1822 |
+
if ( is_object( $comment ) && isset( $comment_type->comment_type ) )
|
1823 |
+
$comment_type = $comment->comment_type;
|
1824 |
+
|
1825 |
+
if ( is_object( $comment_type ) && isset( $comment_type->comment_type ) ) {
|
1826 |
+
$comment = $comment_type;
|
1827 |
+
$comment_type = $comment_type->comment_type;
|
1828 |
+
}
|
1829 |
+
|
1830 |
+
if ( is_object( $comment_type ) )
|
1831 |
+
return;
|
1832 |
+
elseif ( empty( $comment_type ) )
|
1833 |
+
$comment_type = 'comment';
|
1834 |
+
|
1835 |
+
$groups = $this->groups_get( 'comment', $comment_type );
|
1836 |
+
|
1837 |
+
foreach ( $groups as $group ) {
|
1838 |
+
if ( empty( $group[ 'fields' ] ) )
|
1839 |
+
continue;
|
1840 |
+
|
1841 |
+
$field_found = false;
|
1842 |
+
|
1843 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1844 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], null, null ) ) {
|
1845 |
+
if ( pods_var( 'hidden', $field[ 'options' ], false ) ) {
|
1846 |
+
$field_found = true;
|
1847 |
+
break;
|
1848 |
+
}
|
1849 |
+
else {
|
1850 |
+
continue;
|
1851 |
+
}
|
1852 |
+
}
|
1853 |
+
else {
|
1854 |
+
$field_found = true;
|
1855 |
+
break;
|
1856 |
+
}
|
1857 |
+
}
|
1858 |
+
|
1859 |
+
if ( $field_found ) {
|
1860 |
+
add_meta_box(
|
1861 |
+
'pods-meta-' . sanitize_title( $group[ 'label' ] ),
|
1862 |
+
$group[ 'label' ],
|
1863 |
+
array( $this, 'meta_comment' ),
|
1864 |
+
$comment_type,
|
1865 |
+
$group[ 'context' ],
|
1866 |
+
$group[ 'priority' ],
|
1867 |
+
array( 'group' => $group )
|
1868 |
+
);
|
1869 |
+
}
|
1870 |
+
}
|
1871 |
+
}
|
1872 |
+
|
1873 |
+
/**
|
1874 |
+
* @param $comment
|
1875 |
+
* @param $metabox
|
1876 |
+
*/
|
1877 |
+
public function meta_comment ( $comment, $metabox ) {
|
1878 |
+
wp_enqueue_style( 'pods-form' );
|
1879 |
+
|
1880 |
+
do_action( 'pods_meta_' . __FUNCTION__, $comment, $metabox );
|
1881 |
+
|
1882 |
+
$hidden_fields = array();
|
1883 |
+
|
1884 |
+
echo PodsForm::field( 'pods_meta', wp_create_nonce( 'pods_meta_comment' ), 'hidden' );
|
1885 |
+
?>
|
1886 |
+
<table class="form-table editcomment pods-metabox">
|
1887 |
+
<?php
|
1888 |
+
$id = null;
|
1889 |
+
|
1890 |
+
if ( is_object( $comment ) )
|
1891 |
+
$id = $comment->comment_ID;
|
1892 |
+
|
1893 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ] )
|
1894 |
+
self::$current_pod = pods( $metabox[ 'args' ][ 'group' ][ 'pod' ][ 'name' ], $id, true );
|
1895 |
+
elseif ( self::$current_pod->id() != $id )
|
1896 |
+
self::$current_pod->fetch( $id );
|
1897 |
+
|
1898 |
+
$pod = self::$current_pod;
|
1899 |
+
|
1900 |
+
foreach ( $metabox[ 'args' ][ 'group' ][ 'fields' ] as $field ) {
|
1901 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $metabox[ 'args' ][ 'group' ][ 'fields' ], $pod, $id ) ) {
|
1902 |
+
if ( pods_var( 'hidden', $field[ 'options' ], false ) )
|
1903 |
+
$field[ 'type' ] = 'hidden';
|
1904 |
+
else
|
1905 |
+
continue;
|
1906 |
+
}
|
1907 |
+
elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) )
|
1908 |
+
$field[ 'type' ] = 'hidden';
|
1909 |
+
|
1910 |
+
$value = '';
|
1911 |
+
|
1912 |
+
if ( !empty( $pod ) )
|
1913 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) );
|
1914 |
+
|
1915 |
+
if ( 'hidden' == $field[ 'type' ] ) {
|
1916 |
+
$hidden_fields[] = array(
|
1917 |
+
'field' => $field,
|
1918 |
+
'value' => $value
|
1919 |
+
);
|
1920 |
+
}
|
1921 |
+
else {
|
1922 |
+
?>
|
1923 |
+
<tr class="form-field pods-field <?php echo 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ); ?>">
|
1924 |
+
<th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th>
|
1925 |
+
<td>
|
1926 |
+
<?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?>
|
1927 |
+
<?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?>
|
1928 |
+
</td>
|
1929 |
+
</tr>
|
1930 |
+
<?php
|
1931 |
+
}
|
1932 |
+
}
|
1933 |
+
?>
|
1934 |
+
</table>
|
1935 |
+
<?php
|
1936 |
+
foreach ( $hidden_fields as $hidden_field ) {
|
1937 |
+
$field = $hidden_field[ 'field' ];
|
1938 |
+
|
1939 |
+
echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $hidden_field[ 'value' ], 'hidden' );
|
1940 |
+
}
|
1941 |
+
|
1942 |
+
do_action( 'pods_meta_' . __FUNCTION__ . '_post', $comment, $metabox );
|
1943 |
+
}
|
1944 |
+
|
1945 |
+
/**
|
1946 |
+
* @param $approved
|
1947 |
+
* @param $commentdata
|
1948 |
+
*/
|
1949 |
+
public function validate_comment ( $approved, $commentdata ) {
|
1950 |
+
$groups = $this->groups_get( 'comment', 'comment' );
|
1951 |
+
|
1952 |
+
if ( empty( $groups ) )
|
1953 |
+
return $approved;
|
1954 |
+
|
1955 |
+
$data = array();
|
1956 |
+
|
1957 |
+
$pod = null;
|
1958 |
+
$id = null;
|
1959 |
+
|
1960 |
+
foreach ( $groups as $group ) {
|
1961 |
+
if ( empty( $group[ 'fields' ] ) )
|
1962 |
+
continue;
|
1963 |
+
|
1964 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
1965 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
1966 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
1967 |
+
elseif ( self::$current_pod->id() != $id )
|
1968 |
+
self::$current_pod->fetch( $id );
|
1969 |
+
|
1970 |
+
$pod = self::$current_pod;
|
1971 |
+
}
|
1972 |
+
|
1973 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
1974 |
+
|
1975 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
1976 |
+
if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
|
1977 |
+
continue;
|
1978 |
+
}
|
1979 |
+
|
1980 |
+
$data[ $field[ 'name' ] ] = '';
|
1981 |
+
|
1982 |
+
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
|
1983 |
+
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
|
1984 |
+
|
1985 |
+
$validate = pods_api()->handle_field_validation( $data[ $field[ 'name' ] ], $field[ 'name' ], pods_api()->get_wp_object_fields( 'comment' ), $pod->fields(), $pod, array() );
|
1986 |
+
|
1987 |
+
if ( false === $validate )
|
1988 |
+
$validate = sprintf( __( 'There was an issue validating the field %s', 'pods' ), $field[ 'label' ] );
|
1989 |
+
|
1990 |
+
if ( !is_bool( $validate ) && !empty( $validate ) )
|
1991 |
+
return pods_error( $validate, $this );
|
1992 |
+
}
|
1993 |
+
}
|
1994 |
+
|
1995 |
+
return $approved;
|
1996 |
+
}
|
1997 |
+
|
1998 |
+
/**
|
1999 |
+
* @param $comment_id
|
2000 |
+
*/
|
2001 |
+
public function save_comment ( $comment_id ) {
|
2002 |
+
$groups = $this->groups_get( 'comment', 'comment' );
|
2003 |
+
|
2004 |
+
if ( empty( $groups ) ) {
|
2005 |
+
return $comment_id;
|
2006 |
+
}
|
2007 |
+
elseif ( empty( $_POST ) ) {
|
2008 |
+
return $comment_id;
|
2009 |
+
}
|
2010 |
+
elseif ( !wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_comment' ) ) {
|
2011 |
+
return $comment_id;
|
2012 |
+
}
|
2013 |
+
|
2014 |
+
$data = array();
|
2015 |
+
|
2016 |
+
$id = $comment_id;
|
2017 |
+
$pod = null;
|
2018 |
+
|
2019 |
+
foreach ( $groups as $group ) {
|
2020 |
+
if ( empty( $group[ 'fields' ] ) )
|
2021 |
+
continue;
|
2022 |
+
|
2023 |
+
if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
|
2024 |
+
if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
|
2025 |
+
self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
|
2026 |
+
elseif ( self::$current_pod->id() != $id )
|
2027 |
+
self::$current_pod->fetch( $id );
|
2028 |
+
|
2029 |
+
$pod = self::$current_pod;
|
2030 |
+
}
|
2031 |
+
|
2032 |
+
foreach ( $group[ 'fields' ] as $field ) {
|
2033 |
+
if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
|
2034 |
+
if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
|
2035 |
+
continue;
|
2036 |
+
}
|
2037 |
+
|
2038 |
+
$data[ $field[ 'name' ] ] = '';
|
2039 |
+
|
2040 |
+
if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
|
2041 |
+
$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
|
2042 |
+
}
|
2043 |
+
}
|
2044 |
+
|
2045 |
+
do_action( 'pods_meta_save_pre_comment', $data, $pod, $id, $groups );
|
2046 |
+
|
2047 |
+
if ( !empty( $pod ) ) {
|
2048 |
+
// Fix for Pods doing it's own sanitization
|
2049 |
+
$data = pods_unslash( (array) $data );
|
2050 |
+
|
2051 |
+
$pod->save( $data );
|
2052 |
+
}
|
2053 |
+
elseif ( !empty( $id ) ) {
|
2054 |
+
pods_no_conflict_on( 'comment' );
|
2055 |
+
|
2056 |
+
foreach ( $data as $field => $value ) {
|
2057 |
+
update_comment_meta( $id, $field, $value );
|
2058 |
+
}
|
2059 |
+
|
2060 |
+
pods_no_conflict_off( 'comment' );
|
2061 |
+
}
|
2062 |
+
|
2063 |
+
do_action( 'pods_meta_save_comment', $data, $pod, $id, $groups );
|
2064 |
+
|
2065 |
+
return $comment_id;
|
2066 |
+
}
|
2067 |
+
|
2068 |
+
/**
|
2069 |
+
* All *_*_meta filter handler aliases
|
2070 |
+
*
|
2071 |
+
* @return mixed
|
2072 |
+
*/
|
2073 |
+
public function get_post_meta () {
|
2074 |
+
$args = func_get_args();
|
2075 |
+
|
2076 |
+
array_unshift( $args, 'post_type' );
|
2077 |
+
|
2078 |
+
$_null = apply_filters( 'pods_meta_get_post_meta', null, $args );
|
2079 |
+
|
2080 |
+
if ( null !== $_null )
|
2081 |
+
return $_null;
|
2082 |
+
|
2083 |
+
return call_user_func_array( array( $this, 'get_meta' ), $args );
|
2084 |
+
}
|
2085 |
+
|
2086 |
+
/**
|
2087 |
+
* @return mixed
|
2088 |
+
*/
|
2089 |
+
public function get_user_meta () {
|
2090 |
+
$args = func_get_args();
|
2091 |
+
|
2092 |
+
array_unshift( $args, 'user' );
|
2093 |
+
|
2094 |
+
$_null = apply_filters( 'pods_meta_get_user_meta', null, $args );
|
2095 |
+
|
2096 |
+
if ( null !== $_null )
|
2097 |
+
return $_null;
|
2098 |
+
|
2099 |
+
return call_user_func_array( array( $this, 'get_meta' ), $args );
|
2100 |
+
}
|
2101 |
+
|
2102 |
+
/**
|
2103 |
+
* @return mixed
|
2104 |
+
*/
|
2105 |
+
public function get_comment_meta () {
|
2106 |
+
$args = func_get_args();
|
2107 |
+
|
2108 |
+
array_unshift( $args, 'comment' );
|
2109 |
+
|
2110 |
+
$_null = apply_filters( 'pods_meta_get_comment_meta', null, $args );
|
2111 |
+
|
2112 |
+
if ( null !== $_null )
|
2113 |
+
return $_null;
|
2114 |
+
|
2115 |
+
return call_user_func_array( array( $this, 'get_meta' ), $args );
|
2116 |
+
}
|
2117 |
+
|
2118 |
+
/**
|
2119 |
+
* @return mixed
|
2120 |
+
*/
|
2121 |
+
public function get_term_meta () {
|
2122 |
+
$args = func_get_args();
|
2123 |
+
|
2124 |
+
array_unshift( $args, 'term' );
|
2125 |
+
|
2126 |
+
$_null = apply_filters( 'pods_meta_get_term_meta', null, $args );
|
2127 |
+
|
2128 |
+
if ( null !== $_null )
|
2129 |
+
return $_null;
|
2130 |
+
|
2131 |
+
return call_user_func_array( array( $this, 'get_meta' ), $args );
|
2132 |
+
}
|
2133 |
+
|
2134 |
+
/**
|
2135 |
+
* All *_*_meta filter handler aliases
|
2136 |
+
*
|
2137 |
+
* @return mixed
|
2138 |
+
*/
|
2139 |
+
public function get_option () {
|
2140 |
+
$args = func_get_args();
|
2141 |
+
|
2142 |
+
array_unshift( $args, 'settings' );
|
2143 |
+
|
2144 |
+
$_null = apply_filters( 'pods_meta_get_option', null, $args );
|
2145 |
+
|
2146 |
+
if ( null !== $_null )
|
2147 |
+
return $_null;
|
2148 |
+
|
2149 |
+
return call_user_func_array( array( $this, 'get_meta' ), $args );
|
2150 |
+
}
|
2151 |
+
|
2152 |
+
/**
|
2153 |
+
* @return mixed
|
2154 |
+
*/
|
2155 |
+
public function add_post_meta () {
|
2156 |
+
$args = func_get_args();
|
2157 |
+
|
2158 |
+
array_unshift( $args, 'post_type' );
|
2159 |
+
|
2160 |
+
$_null = apply_filters( 'pods_meta_add_post_meta', null, $args );
|
2161 |
+
|
2162 |
+
if ( null !== $_null )
|
2163 |
+
return $_null;
|
2164 |
+
|
2165 |
+
return call_user_func_array( array( $this, 'add_meta' ), $args );
|
2166 |
+
}
|
2167 |
+
|
2168 |
+
/**
|
2169 |
+
* @return mixed
|
2170 |
+
*/
|
2171 |
+
public function add_user_meta () {
|
2172 |
+
$args = func_get_args();
|
2173 |
+
|
2174 |
+
array_unshift( $args, 'user' );
|
2175 |
+
|
2176 |
+
$_null = apply_filters( 'pods_meta_add_user_meta', null, $args );
|
2177 |
+
|
2178 |
+
if ( null !== $_null )
|
2179 |
+
return $_null;
|
2180 |
+
|
2181 |
+
return call_user_func_array( array( $this, 'add_meta' ), $args );
|
2182 |
+
}
|
2183 |
+
|
2184 |
+
/**
|
2185 |
+
* @return mixed
|
2186 |
+
*/
|
2187 |
+
public function add_comment_meta () {
|
2188 |
+
$args = func_get_args();
|
2189 |
+
|
2190 |
+
array_unshift( $args, 'comment' );
|
2191 |
+
|
2192 |
+
$_null = apply_filters( 'pods_meta_add_comment_meta', null, $args );
|
2193 |
+
|
2194 |
+
if ( null !== $_null )
|
2195 |
+
return $_null;
|
2196 |
+
|
2197 |
+
return call_user_func_array( array( $this, 'add_meta' ), $args );
|
2198 |
+
}
|
2199 |
+
|
2200 |
+
/**
|
2201 |
+
* @return mixed
|
2202 |
+
*/
|
2203 |
+
public function add_term_meta () {
|
2204 |
+
$args = func_get_args();
|
2205 |
+
|
2206 |
+
array_unshift( $args, 'term' );
|
2207 |
+
|
2208 |
+
$_null = apply_filters( 'pods_meta_add_term_meta', null, $args );
|
2209 |
+
|
2210 |
+
if ( null !== $_null )
|
2211 |
+
return $_null;
|
2212 |
+
|
2213 |
+
return call_user_func_array( array( $this, 'add_meta' ), $args );
|
2214 |
+
}
|
2215 |
+
|
2216 |
+
/**
|
2217 |
+
* @return mixed
|
2218 |
+
*/
|
2219 |
+
public function add_option () {
|
2220 |
+
$args = func_get_args();
|
2221 |
+
|
2222 |
+
array_unshift( $args, 'settings' );
|
2223 |
+
|
2224 |
+
$_null = apply_filters( 'pods_meta_add_option', null, $args );
|
2225 |
+
|
2226 |
+
if ( null !== $_null )
|
2227 |
+
return $_null;
|
2228 |
+
|
2229 |
+
return call_user_func_array( array( $this, 'add_meta' ), $args );
|
2230 |
+
}
|
2231 |
+
|
2232 |
+
/**
|
2233 |
+
* @return mixed
|
2234 |
+
*/
|
2235 |
+
public function update_post_meta () {
|
2236 |
+
$args = func_get_args();
|
2237 |
+
|
2238 |
+
array_unshift( $args, 'post_type' );
|
2239 |
+
|
2240 |
+
$_null = apply_filters( 'pods_meta_update_post_meta', null, $args );
|
2241 |
+
|
2242 |
+
if ( null !== $_null )
|
2243 |
+
return $_null;
|
2244 |
+
|
2245 |
+
return call_user_func_array( array( $this, 'update_meta' ), $args );
|
2246 |
+
}
|
2247 |
+
|
2248 |
+
/**
|
2249 |
+
* @return mixed
|
2250 |
+
*/
|
2251 |
+
public function update_user_meta () {
|
2252 |
+
$args = func_get_args();
|
2253 |
+
|
2254 |
+
array_unshift( $args, 'user' );
|
2255 |
+
|
2256 |
+
$_null = apply_filters( 'pods_meta_update_user_meta', null, $args );
|
2257 |
+
|
2258 |
+
if ( null !== $_null )
|
2259 |
+
return $_null;
|
2260 |
+
|
2261 |
+
return call_user_func_array( array( $this, 'update_meta' ), $args );
|
2262 |
+
}
|
2263 |
+
|
2264 |
+
/**
|
2265 |
+
* @return mixed
|
2266 |
+
*/
|
2267 |
+
public function update_comment_meta () {
|
2268 |
+
$args = func_get_args();
|
2269 |
+
|
2270 |
+
array_unshift( $args, 'comment' );
|
2271 |
+
|
2272 |
+
$_null = apply_filters( 'pods_meta_update_comment_meta', null, $args );
|
2273 |
+
|
2274 |
+
if ( null !== $_null )
|
2275 |
+
return $_null;
|
2276 |
+
|
2277 |
+
return call_user_func_array( array( $this, 'update_meta' ), $args );
|
2278 |
+
}
|
2279 |
+
|
2280 |
+
/**
|
2281 |
+
* @return mixed
|
2282 |
+
*/
|
2283 |
+
public function update_term_meta () {
|
2284 |
+
$args = func_get_args();
|
2285 |
+
|
2286 |
+
array_unshift( $args, 'term' );
|
2287 |
+
|
2288 |
+
$_null = apply_filters( 'pods_meta_update_term_meta', null, $args );
|
2289 |
+
|
2290 |
+
if ( null !== $_null )
|
2291 |
+
return $_null;
|
2292 |
+
|
2293 |
+
return call_user_func_array( array( $this, 'update_meta' ), $args );
|
2294 |
+
}
|
2295 |
+
|
2296 |
+
/**
|
2297 |
+
* @return mixed
|
2298 |
+
*/
|
2299 |
+
public function update_option () {
|
2300 |
+
$args = func_get_args();
|
2301 |
+
|
2302 |
+
array_unshift( $args, 'settings' );
|
2303 |
+
|
2304 |
+
$_null = apply_filters( 'pods_meta_update_option', null, $args );
|
2305 |
+
|
2306 |
+
if ( null !== $_null )
|
2307 |
+
return $_null;
|
2308 |
+
|
2309 |
+
return call_user_func_array( array( $this, 'update_meta' ), $args );
|
2310 |
+
}
|
2311 |
+
|
2312 |
+
/**
|
2313 |
+
* @return mixed
|
2314 |
+
*/
|
2315 |
+
public function delete_post_meta () {
|
2316 |
+
$args = func_get_args();
|
2317 |
+
|
2318 |
+
array_unshift( $args, 'post_type' );
|
2319 |
+
|
2320 |
+
$_null = apply_filters( 'pods_meta_delete_post_meta', null, $args );
|
2321 |
+
|
2322 |
+
if ( null !== $_null )
|
2323 |
+
return $_null;
|
2324 |
+
|
2325 |
+
return call_user_func_array( array( $this, 'delete_meta' ), $args );
|
2326 |
+
}
|
2327 |
+
|
2328 |
+
/**
|
2329 |
+
* @return mixed
|
2330 |
+
*/
|
2331 |
+
public function delete_user_meta () {
|
2332 |
+
$args = func_get_args();
|
2333 |
+
|
2334 |
+
array_unshift( $args, 'user' );
|
2335 |
+
|
2336 |
+
$_null = apply_filters( 'pods_meta_delete_user_meta', null, $args );
|
2337 |
+
|
2338 |
+
if ( null !== $_null )
|
2339 |
+
return $_null;
|
2340 |
+
|
2341 |
+
return call_user_func_array( array( $this, 'delete_meta' ), $args );
|
2342 |
+
}
|
2343 |
+
|
2344 |
+
/**
|
2345 |
+
* @return mixed
|
2346 |
+
*/
|
2347 |
+
public function delete_comment_meta () {
|
2348 |
+
$args = func_get_args();
|
2349 |
+
|
2350 |
+
array_unshift( $args, 'comment' );
|
2351 |
+
|
2352 |
+
$_null = apply_filters( 'pods_meta_delete_comment_meta', null, $args );
|
2353 |
+
|
2354 |
+
if ( null !== $_null )
|
2355 |
+
return $_null;
|
2356 |
+
|
2357 |
+
return call_user_func_array( array( $this, 'delete_meta' ), $args );
|
2358 |
+
}
|
2359 |
+
|
2360 |
+
/**
|
2361 |
+
* @return mixed
|
2362 |
+
*/
|
2363 |
+
public function delete_term_meta () {
|
2364 |
+
$args = func_get_args();
|
2365 |
+
|
2366 |
+
array_unshift( $args, 'term' );
|
2367 |
+
|
2368 |
+
$_null = apply_filters( 'pods_meta_delete_term_meta', null, $args );
|
2369 |
+
|
2370 |
+
if ( null !== $_null )
|
2371 |
+
return $_null;
|
2372 |
+
|
2373 |
+
return call_user_func_array( array( $this, 'delete_meta' ), $args );
|
2374 |
+
}
|
2375 |
+
|
2376 |
+
/**
|
2377 |
+
* @return mixed
|
2378 |
+
*/
|
2379 |
+
public function delete_option () {
|
2380 |
+
$args = func_get_args();
|
2381 |
+
|
2382 |
+
array_unshift( $args, 'settings' );
|
2383 |
+
|
2384 |
+
$_null = apply_filters( 'pods_meta_delete_option', null, $args );
|
2385 |
+
|
2386 |
+
if ( null !== $_null )
|
2387 |
+
return $_null;
|
2388 |
+
|
2389 |
+
return call_user_func_array( array( $this, 'delete_meta' ), $args );
|
2390 |
+
}
|
2391 |
+
|
2392 |
+
/*
|
2393 |
+
* The real meta functions
|
2394 |
+
*/
|
2395 |
+
/**
|
2396 |
+
* @param $object_type
|
2397 |
+
* @param $object_id
|
2398 |
+
* @param string $aux
|
2399 |
+
*
|
2400 |
+
* @return bool|mixed
|
2401 |
+
*/
|
2402 |
+
public function get_object ( $object_type, $object_id, $aux = '' ) {
|
2403 |
+
if ( 'post_type' == $object_type )
|
2404 |
+
$objects = self::$post_types;
|
2405 |
+
elseif ( 'taxonomy' == $object_type )
|
2406 |
+
$objects = self::$taxonomies;
|
2407 |
+
elseif ( 'media' == $object_type )
|
2408 |
+
$objects = self::$media;
|
2409 |
+
elseif ( 'user' == $object_type )
|
2410 |
+
$objects = self::$user;
|
2411 |
+
elseif ( 'comment' == $object_type )
|
2412 |
+
$objects = self::$comment;
|
2413 |
+
elseif ( 'settings' == $object_type )
|
2414 |
+
$objects = self::$settings;
|
2415 |
+
else
|
2416 |
+
return false;
|
2417 |
+
|
2418 |
+
if ( empty( $objects ) || !is_array( $objects ) )
|
2419 |
+
return false;
|
2420 |
+
|
2421 |
+
$object_name = null;
|
2422 |
+
|
2423 |
+
if ( 'media' == $object_type )
|
2424 |
+
return @current( $objects );
|
2425 |
+
elseif ( 'user' == $object_type )
|
2426 |
+
return @current( $objects );
|
2427 |
+
elseif ( 'comment' == $object_type )
|
2428 |
+
return @current( $objects );
|
2429 |
+
elseif ( 'post_type' == $object_type ) {
|
2430 |
+
$object = get_post( $object_id );
|
2431 |
+
|
2432 |
+
if ( !is_object( $object ) || !isset( $object->post_type ) )
|
2433 |
+
return false;
|
2434 |
+
|
2435 |
+
$object_name = $object->post_type;
|
2436 |
+
}
|
2437 |
+
elseif ( 'taxonomy' == $object_type )
|
2438 |
+
$object_name = $aux;
|
2439 |
+
elseif ( 'settings' == $object_type )
|
2440 |
+
$object = $object_id;
|
2441 |
+
else
|
2442 |
+
return false;
|
2443 |
+
|
2444 |
+
$reserved_post_types = array(
|
2445 |
+
'nav_menu_item',
|
2446 |
+
'revision'
|
2447 |
+
);
|
2448 |
+
|
2449 |
+
$reserved_post_types = apply_filters( 'pods_meta_reserved_post_types', $reserved_post_types, $object_type, $object_id, $object_name, $objects );
|
2450 |
+
|
2451 |
+
if ( empty( $object_name ) || ( 'post_type' == $object_type && ( 0 === strpos( $object_name, '_pods_' ) ) || in_array( $object_name, $reserved_post_types ) ) ) {
|
2452 |
+
return false;
|
2453 |
+
}
|
2454 |
+
elseif ( 'attachment' == $object_name ) {
|
2455 |
+
return @current( self::$media );
|
2456 |
+
}
|
2457 |
+
|
2458 |
+
$recheck = array();
|
2459 |
+
|
2460 |
+
// Return first created by Pods, save extended for later
|
2461 |
+
foreach ( $objects as $pod ) {
|
2462 |
+
if ( $object_name == $pod[ 'object' ] )
|
2463 |
+
$recheck[] = $pod;
|
2464 |
+
|
2465 |
+
if ( '' == $pod[ 'object' ] && $object_name == $pod[ 'name' ] )
|
2466 |
+
return $pod;
|
2467 |
+
}
|
2468 |
+
|
2469 |
+
// If no objects created by Pods, return first extended
|
2470 |
+
foreach ( $recheck as $pod ) {
|
2471 |
+
return $pod;
|
2472 |
+
}
|
2473 |
+
|
2474 |
+
return false;
|
2475 |
+
}
|
2476 |
+
|
2477 |
+
/**
|
2478 |
+
* @param $object_type
|
2479 |
+
* @param null $_null
|
2480 |
+
* @param int $object_id
|
2481 |
+
* @param string $meta_key
|
2482 |
+
* @param bool $single
|
2483 |
+
*
|
2484 |
+
* @return array|bool|int|mixed|null|string|void
|
2485 |
+
*/
|
2486 |
+
public function get_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $single = false ) {
|
2487 |
+
$meta_type = $object_type;
|
2488 |
+
|
2489 |
+
if ( 'post_type' == $meta_type )
|
2490 |
+
$meta_type = 'post';
|
2491 |
+
|
2492 |
+
if ( empty( $meta_key ) ) {
|
2493 |
+
if ( !defined( 'PODS_ALLOW_FULL_META' ) || !PODS_ALLOW_FULL_META ) {
|
2494 |
+
return $_null; // don't cover get_post_meta( $id )
|
2495 |
+
}
|
2496 |
+
|
2497 |
+
$single = false;
|
2498 |
+
}
|
2499 |
+
|
2500 |
+
$object = $this->get_object( $object_type, $object_id );
|
2501 |
+
|
2502 |
+
if ( empty( $object_id ) || empty( $object ) )
|
2503 |
+
return $_null;
|
2504 |
+
|
2505 |
+
$no_conflict = pods_no_conflict_check( $meta_type );
|
2506 |
+
|
2507 |
+
if ( !$no_conflict )
|
2508 |
+
pods_no_conflict_on( $meta_type );
|
2509 |
+
|
2510 |
+
$meta_cache = array();
|
2511 |
+
|
2512 |
+
if ( !$single && isset( $GLOBALS[ 'wp_object_cache' ] ) && is_object( $GLOBALS[ 'wp_object_cache' ] ) ) {
|
2513 |
+
$meta_cache = wp_cache_get( $object_id, 'pods_' . $meta_type . '_meta' );
|
2514 |
+
|
2515 |
+
if ( empty( $meta_cache ) ) {
|
2516 |
+
$meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' );
|
2517 |
+
|
2518 |
+
if ( empty( $meta_cache ) ) {
|
2519 |
+
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
|
2520 |
+
$meta_cache = $meta_cache[ $object_id ];
|
2521 |
+
}
|
2522 |
+
}
|
2523 |
+
}
|
2524 |
+
|
2525 |
+
if ( empty( $meta_cache ) || !is_array( $meta_cache ) )
|
2526 |
+
$meta_cache = array();
|
2527 |
+
|
2528 |
+
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] )
|
2529 |
+
self::$current_field_pod = pods( $object[ 'name' ], $object_id );
|
2530 |
+
elseif ( self::$current_field_pod->id() != $object_id )
|
2531 |
+
self::$current_field_pod->fetch( $object_id );
|
2532 |
+
|
2533 |
+
$pod = self::$current_field_pod;
|
2534 |
+
|
2535 |
+
$meta_keys = array( $meta_key );
|
2536 |
+
|
2537 |
+
if ( empty( $meta_key ) )
|
2538 |
+
$meta_keys = array_keys( $meta_cache );
|
2539 |
+
|
2540 |
+
$key_found = false;
|
2541 |
+
|
2542 |
+
foreach ( $meta_keys as $meta_k ) {
|
2543 |
+
if ( !empty( $pod ) ) {
|
2544 |
+
if ( isset( $pod->fields[ $meta_k ] ) ) {
|
2545 |
+
$key_found = true;
|
2546 |
+
|
2547 |
+
$meta_cache[ $meta_k ] = $pod->field( array( 'name' => $meta_k, 'single' => $single, 'get_meta' => true ) );
|
2548 |
+
|
2549 |
+
if ( ( !is_array( $meta_cache[ $meta_k ] ) || !isset( $meta_cache[ $meta_k ][ 0 ] ) ) ) {
|
2550 |
+
if ( empty( $meta_cache[ $meta_k ] ) && !is_array( $meta_cache[ $meta_k ] ) && $single )
|
2551 |
+
$meta_cache[ $meta_k ] = array();
|
2552 |
+
else
|
2553 |
+
$meta_cache[ $meta_k ] = array( $meta_cache[ $meta_k ] );
|
2554 |
+
}
|
2555 |
+
|
2556 |
+
if ( in_array( $pod->fields[ $meta_k ][ 'type' ], PodsForm::tableless_field_types() ) && isset( $meta_cache[ '_pods_' . $meta_k ] ) )
|
2557 |
+
unset( $meta_cache[ '_pods_' . $meta_k ] );
|
2558 |
+
}
|
2559 |
+
elseif ( false !== strpos( $meta_k, '.' ) ) {
|
2560 |
+
$key_found = true;
|
2561 |
+
|
2562 |
+
$first = current( explode( '.', $meta_k ) );
|
2563 |
+
|
2564 |
+
if ( isset( $pod->fields[ $first ] ) ) {
|
2565 |
+
$meta_cache[ $meta_k ] = $pod->field( array( 'name' => $meta_k, 'single' => $single, 'get_meta' => true ) );
|
2566 |
+
|
2567 |
+
if ( ( !is_array( $meta_cache[ $meta_k ] ) || !isset( $meta_cache[ $meta_k ][ 0 ] ) ) && $single ) {
|
2568 |
+
if ( empty( $meta_cache[ $meta_k ] ) && !is_array( $meta_cache[ $meta_k ] ) && $single )
|
2569 |
+
$meta_cache[ $meta_k ] = array();
|
2570 |
+
else
|
2571 |
+
$meta_cache[ $meta_k ] = array( $meta_cache[ $meta_k ] );
|
2572 |
+
}
|
2573 |
+
|
2574 |
+
if ( in_array( $pod->fields[ $first ][ 'type' ], PodsForm::tableless_field_types() ) && isset( $meta_cache[ '_pods_' . $first ] ) )
|
2575 |
+
unset( $meta_cache[ '_pods_' . $first ] );
|
2576 |
+
}
|
2577 |
+
}
|
2578 |
+
}
|
2579 |
+
}
|
2580 |
+
|
2581 |
+
if ( !$no_conflict )
|
2582 |
+
pods_no_conflict_off( $meta_type );
|
2583 |
+
|
2584 |
+
unset( $pod ); // memory clear
|
2585 |
+
|
2586 |
+
if ( !$key_found )
|
2587 |
+
return $_null;
|
2588 |
+
|
2589 |
+
if ( !$single && isset( $GLOBALS[ 'wp_object_cache' ] ) && is_object( $GLOBALS[ 'wp_object_cache' ] ) )
|
2590 |
+
wp_cache_set( $object_id, $meta_cache, 'pods_' . $meta_type . '_meta' );
|
2591 |
+
|
2592 |
+
if ( empty( $meta_key ) )
|
2593 |
+
return $meta_cache;
|
2594 |
+
elseif ( isset( $meta_cache[ $meta_key ] ) )
|
2595 |
+
$value = $meta_cache[ $meta_key ];
|
2596 |
+
else
|
2597 |
+
$value = '';
|
2598 |
+
|
2599 |
+
if ( !is_numeric( $value ) && empty( $value ) ) {
|
2600 |
+
if ( $single )
|
2601 |
+
$value = '';
|
2602 |
+
else
|
2603 |
+
$value = array();
|
2604 |
+
}
|
2605 |
+
// get_metadata requires $meta[ 0 ] to be set for first value to be retrieved
|
2606 |
+
elseif ( !is_array( $value ) )
|
2607 |
+
$value = array( $value );
|
2608 |
+
|
2609 |
+
return $value;
|
2610 |
+
}
|
2611 |
+
|
2612 |
+
/**
|
2613 |
+
* @param $object_type
|
2614 |
+
* @param null $_null
|
2615 |
+
* @param int $object_id
|
2616 |
+
* @param string $meta_key
|
2617 |
+
* @param string $meta_value
|
2618 |
+
* @param bool $unique
|
2619 |
+
*
|
2620 |
+
* @return bool|int|null
|
2621 |
+
*/
|
2622 |
+
public function add_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $unique = false ) {
|
2623 |
+
if ( pods_tableless() )
|
2624 |
+
return $_null;
|
2625 |
+
|
2626 |
+
$object = $this->get_object( $object_type, $object_id );
|
2627 |
+
|
2628 |
+
if ( empty( $object_id ) || empty( $object ) || !isset( $object[ 'fields' ][ $meta_key ] ) )
|
2629 |
+
return $_null;
|
2630 |
+
|
2631 |
+
if ( in_array( $object[ 'fields' ][ $meta_key ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
2632 |
+
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] )
|
2633 |
+
self::$current_field_pod = pods( $object[ 'name' ], $object_id );
|
2634 |
+
elseif ( self::$current_field_pod->id() != $object_id )
|
2635 |
+
self::$current_field_pod->fetch( $object_id );
|
2636 |
+
|
2637 |
+
$pod = self::$current_field_pod;
|
2638 |
+
|
2639 |
+
$pod->add_to( $meta_key, $meta_value );
|
2640 |
+
}
|
2641 |
+
else {
|
2642 |
+
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] )
|
2643 |
+
self::$current_field_pod = pods( $object[ 'name' ] );
|
2644 |
+
|
2645 |
+
$pod = self::$current_field_pod;
|
2646 |
+
|
2647 |
+
$pod->save( $meta_key, $meta_value, $object_id );
|
2648 |
+
}
|
2649 |
+
|
2650 |
+
return $object_id;
|
2651 |
+
}
|
2652 |
+
|
2653 |
+
/**
|
2654 |
+
* @param $object_type
|
2655 |
+
* @param null $_null
|
2656 |
+
* @param int $object_id
|
2657 |
+
* @param string $meta_key
|
2658 |
+
* @param string $meta_value
|
2659 |
+
* @param string $prev_value
|
2660 |
+
*
|
2661 |
+
* @return bool|int|null
|
2662 |
+
*/
|
2663 |
+
public function update_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
|
2664 |
+
if ( pods_tableless() )
|
2665 |
+
return $_null;
|
2666 |
+
|
2667 |
+
$object = $this->get_object( $object_type, $object_id );
|
2668 |
+
|
2669 |
+
if ( empty( $object_id ) || empty( $object ) || !isset( $object[ 'fields' ][ $meta_key ] ) )
|
2670 |
+
return $_null;
|
2671 |
+
|
2672 |
+
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] )
|
2673 |
+
self::$current_field_pod = pods( $object[ 'name' ] );
|
2674 |
+
|
2675 |
+
$pod = self::$current_field_pod;
|
2676 |
+
|
2677 |
+
$pod->save( $meta_key, $meta_value, $object_id );
|
2678 |
+
|
2679 |
+
return $object_id;
|
2680 |
+
}
|
2681 |
+
|
2682 |
+
/**
|
2683 |
+
* @param $object_type
|
2684 |
+
* @param null $_null
|
2685 |
+
* @param int $object_id
|
2686 |
+
* @param string $meta_key
|
2687 |
+
* @param string $meta_value
|
2688 |
+
* @param bool $delete_all
|
2689 |
+
*
|
2690 |
+
* @return null
|
2691 |
+
*/
|
2692 |
+
public function delete_meta ( $object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $delete_all = false ) {
|
2693 |
+
if ( pods_tableless() )
|
2694 |
+
return $_null;
|
2695 |
+
|
2696 |
+
$object = $this->get_object( $object_type, $object_id );
|
2697 |
+
|
2698 |
+
if ( empty( $object_id ) || empty( $object ) || !isset( $object[ 'fields' ][ $meta_key ] ) )
|
2699 |
+
return $_null;
|
2700 |
+
|
2701 |
+
// @todo handle $delete_all (delete the field values from all pod items)
|
2702 |
+
if ( !empty( $meta_value ) && in_array( $object[ 'fields' ][ $meta_key ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
2703 |
+
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] )
|
2704 |
+
self::$current_field_pod = pods( $object[ 'name' ], $object_id );
|
2705 |
+
elseif ( self::$current_field_pod->id() != $object_id )
|
2706 |
+
self::$current_field_pod->fetch( $object_id );
|
2707 |
+
|
2708 |
+
$pod = self::$current_field_pod;
|
2709 |
+
|
2710 |
+
$pod->remove_from( $meta_key, $meta_value );
|
2711 |
+
}
|
2712 |
+
else {
|
2713 |
+
if ( !is_object( self::$current_field_pod ) || self::$current_field_pod->pod != $object[ 'name' ] )
|
2714 |
+
self::$current_field_pod = pods( $object[ 'name' ] );
|
2715 |
+
|
2716 |
+
$pod = self::$current_field_pod;
|
2717 |
+
|
2718 |
+
$pod->save( array( $meta_key => null ), null, $object_id );
|
2719 |
+
}
|
2720 |
+
|
2721 |
+
return $_null;
|
2722 |
+
}
|
2723 |
+
|
2724 |
+
public function delete_post ( $id ) {
|
2725 |
+
$post = get_post( $id );
|
2726 |
+
|
2727 |
+
if ( empty( $post ) )
|
2728 |
+
return;
|
2729 |
+
|
2730 |
+
$id = $post->ID;
|
2731 |
+
$post_type = $post->post_type;
|
2732 |
+
|
2733 |
+
return $this->delete_object( 'post_type', $id, $post_type );
|
2734 |
+
}
|
2735 |
+
|
2736 |
+
public function delete_taxonomy ( $id ) {
|
2737 |
+
/**
|
2738 |
+
* @var $wpdb WPDB
|
2739 |
+
*/
|
2740 |
+
global $wpdb;
|
2741 |
+
|
2742 |
+
$terms = $wpdb->get_results( "SELECT `term_id`, `taxonomy` FROM `{$wpdb->term_taxonomy}` WHERE `term_taxonomy_id` = {$id}" );
|
2743 |
+
|
2744 |
+
if ( empty( $terms ) )
|
2745 |
+
return;
|
2746 |
+
|
2747 |
+
foreach ( $terms as $term ) {
|
2748 |
+
$id = $term->term_id;
|
2749 |
+
$taxonomy = $term->taxonomy;
|
2750 |
+
|
2751 |
+
$this->delete_object( 'taxonomy', $id, $taxonomy );
|
2752 |
+
}
|
2753 |
+
}
|
2754 |
+
|
2755 |
+
public function delete_user ( $id ) {
|
2756 |
+
return $this->delete_object( 'user', $id );
|
2757 |
+
}
|
2758 |
+
|
2759 |
+
public function delete_comment ( $id ) {
|
2760 |
+
return $this->delete_object( 'comment', $id );
|
2761 |
+
}
|
2762 |
+
|
2763 |
+
public function delete_media ( $id ) {
|
2764 |
+
return $this->delete_object( 'media', $id );
|
2765 |
+
}
|
2766 |
+
|
2767 |
+
public function delete_object ( $type, $id, $name = null ) {
|
2768 |
+
if ( empty( $name ) )
|
2769 |
+
$name = $type;
|
2770 |
+
|
2771 |
+
$object = $this->object_get( $type, $name );
|
2772 |
+
|
2773 |
+
if ( !empty( $object ) ) {
|
2774 |
+
$params = array(
|
2775 |
+
'pod' => pods_var( 'name', $object ),
|
2776 |
+
'pod_id' => pods_var( 'id', $object ),
|
2777 |
+
'id' => $id
|
2778 |
+
);
|
2779 |
+
|
2780 |
+
return pods_api()->delete_pod_item( $params, false );
|
2781 |
+
}
|
2782 |
+
else
|
2783 |
+
return pods_api()->delete_object_from_relationships( $id, $type, $name );
|
2784 |
+
}
|
2785 |
+
}
|
classes/PodsMigrate.php
ADDED
@@ -0,0 +1,1021 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
18 |
+
* @var array
|
19 |
+
*/
|
20 |
+
var $mimes = array(
|
21 |
+
'json' => 'application/json',
|
22 |
+
'csv' => 'text/csv',
|
23 |
+
'tsv' => 'text/tsv',
|
24 |
+
'xml' => 'text/xml',
|
25 |
+
);
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var null|string
|
29 |
+
*/
|
30 |
+
var $delimiter = ',';
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var null
|
34 |
+
*/
|
35 |
+
var $data = array(
|
36 |
+
'items' => array(),
|
37 |
+
'columns' => array(),
|
38 |
+
'fields' => array()
|
39 |
+
);
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @var null
|
43 |
+
*/
|
44 |
+
var $input;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var
|
48 |
+
*/
|
49 |
+
var $parsed;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var
|
53 |
+
*/
|
54 |
+
var $built;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Migrate Data to and from Pods
|
58 |
+
*
|
59 |
+
* @param string $type Export Type (php, json, sv, xml)
|
60 |
+
* @param string $delimiter Delimiter for export type 'sv'
|
61 |
+
* @param array $data Array of data settings
|
62 |
+
*
|
63 |
+
* @return \PodsMigrate
|
64 |
+
*
|
65 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
66 |
+
* @since 2.0
|
67 |
+
*/
|
68 |
+
function __construct ( $type = null, $delimiter = null, $data = null ) {
|
69 |
+
if ( !empty( $type ) && in_array( $type, $this->types ) )
|
70 |
+
$this->type = $type;
|
71 |
+
|
72 |
+
if ( !empty( $delimiter ) )
|
73 |
+
$this->delimiter = $delimiter;
|
74 |
+
|
75 |
+
if ( !empty( $data ) )
|
76 |
+
$this->set_data( $data );
|
77 |
+
}
|
78 |
+
|
79 |
+
function set_data ( $data ) {
|
80 |
+
$defaults = array(
|
81 |
+
'items' => array(),
|
82 |
+
'columns' => array(),
|
83 |
+
'fields' => array()
|
84 |
+
);
|
85 |
+
|
86 |
+
$this->data = array_merge( $defaults, (array) $data );
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Importing / Parsing / Validating Code
|
91 |
+
*
|
92 |
+
* @param array $data Array of data
|
93 |
+
* @param string $type Export Type (php, json, sv, xml)
|
94 |
+
* @param string $delimiter Delimiter for export type 'sv'
|
95 |
+
*/
|
96 |
+
function import ( $data = null, $type = null, $delimiter = null ) {
|
97 |
+
if ( !empty( $data ) )
|
98 |
+
$this->input = $data;
|
99 |
+
|
100 |
+
if ( !empty( $type ) && in_array( $type, $this->types ) )
|
101 |
+
$this->type = $type;
|
102 |
+
|
103 |
+
if ( !empty( $delimiter ) )
|
104 |
+
$this->delimiter = $delimiter;
|
105 |
+
|
106 |
+
if ( method_exists( $this, "parse_{$this->type}" ) )
|
107 |
+
call_user_func( array( $this, 'parse_' . $this->type ) );
|
108 |
+
|
109 |
+
return $this->import_pod_items();
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* @param array $data Array of data
|
114 |
+
* @param string $type Export Type (php, json, sv, xml)
|
115 |
+
*/
|
116 |
+
public function import_pod_items ( $data = null, $type = null ) {
|
117 |
+
if ( !empty( $data ) )
|
118 |
+
$this->input = $data;
|
119 |
+
|
120 |
+
if ( !empty( $type ) && in_array( $type, $this->types ) )
|
121 |
+
$this->type = $type;
|
122 |
+
|
123 |
+
return false;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* @param array $data Array of data
|
128 |
+
* @param string $type Export Type (php, json, sv, xml)
|
129 |
+
*
|
130 |
+
* @return null
|
131 |
+
*/
|
132 |
+
public function parse ( $data = null, $type = null ) {
|
133 |
+
if ( !empty( $data ) )
|
134 |
+
$this->input = $data;
|
135 |
+
|
136 |
+
if ( !empty( $type ) && in_array( $type, $this->types ) )
|
137 |
+
$this->type = $type;
|
138 |
+
|
139 |
+
if ( method_exists( $this, "parse_{$this->type}" ) )
|
140 |
+
return call_user_func( array( $this, 'parse_' . $this->type ) );
|
141 |
+
|
142 |
+
return $this->parsed;
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* @param array $data Array of data
|
147 |
+
*
|
148 |
+
* @return bool
|
149 |
+
*/
|
150 |
+
public function parse_json ( $data = null ) {
|
151 |
+
if ( !empty( $data ) )
|
152 |
+
$this->input = $data;
|
153 |
+
|
154 |
+
$items = @json_decode( $this->input, true );
|
155 |
+
|
156 |
+
if ( !is_array( $items ) )
|
157 |
+
return false;
|
158 |
+
|
159 |
+
$data = array(
|
160 |
+
'columns' => array(),
|
161 |
+
'items' => array(),
|
162 |
+
'fields' => array()
|
163 |
+
);
|
164 |
+
|
165 |
+
foreach ( $items as $key => $item ) {
|
166 |
+
if ( !is_array( $item ) )
|
167 |
+
continue;
|
168 |
+
|
169 |
+
foreach ( $item as $column => $value ) {
|
170 |
+
if ( !in_array( $column, $data[ 'columns' ] ) )
|
171 |
+
$data[ 'columns' ][] = $column;
|
172 |
+
}
|
173 |
+
|
174 |
+
$data[ 'items' ][ $key ] = $item;
|
175 |
+
}
|
176 |
+
|
177 |
+
$this->parsed = $data;
|
178 |
+
|
179 |
+
return $this->parsed;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* @param array $data Array of data
|
184 |
+
* @param string $delimiter Delimiter for export type 'sv'
|
185 |
+
*
|
186 |
+
* @return bool
|
187 |
+
*/
|
188 |
+
public function parse_sv ( $data = null, $delimiter = null ) {
|
189 |
+
if ( !empty( $data ) )
|
190 |
+
$this->input = $data;
|
191 |
+
|
192 |
+
if ( !empty( $delimiter ) )
|
193 |
+
$this->delimiter = $delimiter;
|
194 |
+
|
195 |
+
$rows = $this->str_getcsv( $this->input, '\n' );
|
196 |
+
|
197 |
+
if ( empty( $rows ) || 2 > count( $rows ) )
|
198 |
+
return false;
|
199 |
+
|
200 |
+
$data = array(
|
201 |
+
'columns' => array(),
|
202 |
+
'items' => array()
|
203 |
+
);
|
204 |
+
|
205 |
+
foreach ( $rows as $key => $row ) {
|
206 |
+
if ( 0 == $key )
|
207 |
+
$data[ 'columns' ] = $this->str_getcsv( $row, $this->delimiter );
|
208 |
+
else {
|
209 |
+
$row = $this->str_getcsv( $row, $this->delimiter );
|
210 |
+
|
211 |
+
$data[ 'items' ][ $key ] = array();
|
212 |
+
|
213 |
+
foreach ( $data[ 'columns' ] as $ckey => $column ) {
|
214 |
+
$data[ 'items' ][ $key ][ $column ] = ( isset( $row[ $ckey ] ) ? $row[ $ckey ] : '' );
|
215 |
+
|
216 |
+
if ( 'NULL' === $data[ 'items' ][ $key ][ $column ] )
|
217 |
+
$data[ 'items' ][ $key ][ $column ] = null;
|
218 |
+
}
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
$this->parsed = $data;
|
223 |
+
|
224 |
+
return $this->parsed;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Handle str_getcsv for cases where it's not set
|
229 |
+
*
|
230 |
+
* @param $line
|
231 |
+
* @param string $delimiter
|
232 |
+
* @param string $enclosure
|
233 |
+
* @param string $escape
|
234 |
+
*
|
235 |
+
* @return array|mixed
|
236 |
+
*/
|
237 |
+
public function str_getcsv ( $line, $delimiter = ',', $enclosure = '"', $escape = '\\' ) {
|
238 |
+
$line = str_replace( "\r\n", "\n", $line );
|
239 |
+
$line = str_replace( "\r", "\n", $line );
|
240 |
+
|
241 |
+
if ( '\n' != $delimiter && function_exists( 'str_getcsv' ) )
|
242 |
+
return str_getcsv( $line, $delimiter, $enclosure, $escape );
|
243 |
+
|
244 |
+
$delimiter = str_replace( '/', '\/', $delimiter );
|
245 |
+
$enclosure = preg_quote( $enclosure, '/' );
|
246 |
+
|
247 |
+
$split = "/{$delimiter}(?=(?:[^{$enclosure}]*{$enclosure}[^{$enclosure}]*{$enclosure})*(?![^{$enclosure}]*{$enclosure}))/";
|
248 |
+
|
249 |
+
$data = preg_split( $split, trim( $line ), -1, PREG_SPLIT_NO_EMPTY );
|
250 |
+
|
251 |
+
if ( '\n' != $delimiter )
|
252 |
+
$data = preg_replace( "/^{$enclosure}(.*){$enclosure}$/s", "$1", $data );
|
253 |
+
|
254 |
+
return $data;
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* @param array $data Array of data
|
259 |
+
*
|
260 |
+
* @return bool
|
261 |
+
*/
|
262 |
+
public function parse_xml ( $data = null ) {
|
263 |
+
if ( !empty( $data ) )
|
264 |
+
$this->input = $data;
|
265 |
+
|
266 |
+
$xml = new SimpleXMLElement( $this->input );
|
267 |
+
|
268 |
+
if ( !isset( $xml->items ) )
|
269 |
+
return false;
|
270 |
+
|
271 |
+
$data = array( 'columns' => array(), 'items' => array() );
|
272 |
+
|
273 |
+
/**
|
274 |
+
* @var $child SimpleXMLElement
|
275 |
+
* @var $item_child SimpleXMLElement
|
276 |
+
* @var $data_child SimpleXMLElement
|
277 |
+
*/
|
278 |
+
|
279 |
+
if ( isset( $xml->columns ) ) {
|
280 |
+
foreach ( $xml->columns->children() as $child ) {
|
281 |
+
$sub = $child->getName();
|
282 |
+
|
283 |
+
if ( empty( $sub ) || 'column' != $sub )
|
284 |
+
continue;
|
285 |
+
|
286 |
+
if ( isset( $child->name ) ) {
|
287 |
+
if ( is_array( $child->name ) )
|
288 |
+
$column = $child->name[ 0 ];
|
289 |
+
else
|
290 |
+
$column = $child->name;
|
291 |
+
|
292 |
+
$data[ 'columns' ][] = $column;
|
293 |
+
}
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
foreach ( $xml->items->children() as $child ) {
|
298 |
+
$sub = $child->getName();
|
299 |
+
|
300 |
+
if ( empty( $sub ) || 'item' != $sub )
|
301 |
+
continue;
|
302 |
+
|
303 |
+
$item = array();
|
304 |
+
|
305 |
+
$attributes = $child->attributes();
|
306 |
+
|
307 |
+
if ( !empty( $attributes ) ) {
|
308 |
+
foreach ( $attributes as $column => $value ) {
|
309 |
+
if ( !in_array( $column, $data[ 'columns' ] ) )
|
310 |
+
$data[ 'columns' ][] = $column;
|
311 |
+
|
312 |
+
$item[ $column ] = $value;
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
$item_child = $child->children();
|
317 |
+
|
318 |
+
if ( !empty( $item_child ) ) {
|
319 |
+
foreach ( $item_child->children() as $data_child ) {
|
320 |
+
$column = $data_child->getName();
|
321 |
+
|
322 |
+
if ( !in_array( $column, $data[ 'columns' ] ) )
|
323 |
+
$data[ 'columns' ][] = $column;
|
324 |
+
|
325 |
+
$item[ $column ] = $item_child->$column;
|
326 |
+
}
|
327 |
+
}
|
328 |
+
|
329 |
+
if ( !empty( $item ) )
|
330 |
+
$data[ 'items' ][] = $item;
|
331 |
+
}
|
332 |
+
|
333 |
+
$this->parsed = $data;
|
334 |
+
|
335 |
+
return $this->parsed;
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* @param array $data Array of data
|
340 |
+
*
|
341 |
+
* @return mixed
|
342 |
+
*
|
343 |
+
* @todo For much much later
|
344 |
+
*/
|
345 |
+
public function parse_sql ( $data = null ) {
|
346 |
+
if ( !empty( $data ) )
|
347 |
+
$this->input = $data;
|
348 |
+
|
349 |
+
$this->parsed = $data;
|
350 |
+
|
351 |
+
return $this->parsed;
|
352 |
+
}
|
353 |
+
|
354 |
+
/**
|
355 |
+
* Exporting / Building Code
|
356 |
+
*
|
357 |
+
* @param array $data Array of data
|
358 |
+
* @param string $type Export Type (php, json, sv, xml)
|
359 |
+
* @param string $delimiter Delimiter for export type 'sv'
|
360 |
+
*/
|
361 |
+
public function export ( $data = null, $type = null, $delimiter = null ) {
|
362 |
+
if ( !empty( $data ) )
|
363 |
+
$this->set_data( $data );
|
364 |
+
|
365 |
+
if ( !empty( $type ) && in_array( $type, $this->types ) )
|
366 |
+
$this->type = $type;
|
367 |
+
|
368 |
+
if ( !empty( $delimiter ) )
|
369 |
+
$this->delimiter = $delimiter;
|
370 |
+
|
371 |
+
if ( method_exists( $this, "build_{$this->type}" ) )
|
372 |
+
call_user_func( array( $this, 'build_' . $this->type ) );
|
373 |
+
|
374 |
+
return $this->built;
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* @param array $data Array of data
|
379 |
+
*/
|
380 |
+
public function export_pod_items ( $data = null ) {
|
381 |
+
if ( !empty( $data ) )
|
382 |
+
$this->set_data( $data );
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* @param array $data Array of data
|
387 |
+
* @param string $type Export Type (php, json, sv, xml)
|
388 |
+
*
|
389 |
+
* @return null
|
390 |
+
*/
|
391 |
+
public function build ( $data = null, $type = null ) {
|
392 |
+
if ( !empty( $data ) )
|
393 |
+
$this->set_data( $data );
|
394 |
+
|
395 |
+
if ( !empty( $type ) && in_array( $type, $this->types ) )
|
396 |
+
$this->type = $type;
|
397 |
+
|
398 |
+
if ( method_exists( $this, "build_{$this->type}" ) )
|
399 |
+
call_user_func( array( $this, 'build_' . $this->type ) );
|
400 |
+
|
401 |
+
return $this->data;
|
402 |
+
}
|
403 |
+
|
404 |
+
/**
|
405 |
+
* @param array $data Array of data
|
406 |
+
*
|
407 |
+
* @return bool
|
408 |
+
*/
|
409 |
+
public function build_json ( $data = null ) {
|
410 |
+
if ( !empty( $data ) )
|
411 |
+
$this->set_data( $data );
|
412 |
+
|
413 |
+
if ( empty( $this->data ) || !is_array( $this->data ) )
|
414 |
+
return false;
|
415 |
+
|
416 |
+
$data = array(
|
417 |
+
'items' => array(
|
418 |
+
'count' => count( $this->data[ 'items' ] ),
|
419 |
+
'item' => array()
|
420 |
+
)
|
421 |
+
);
|
422 |
+
|
423 |
+
foreach ( $this->data[ 'items' ] as $item ) {
|
424 |
+
$row = array();
|
425 |
+
|
426 |
+
foreach ( $this->data[ 'columns' ] as $column => $label ) {
|
427 |
+
if ( is_numeric( $column ) && ( ( is_object( $item ) && !isset( $item->$column ) ) || ( is_array( $item ) && !isset( $item[ $column ] ) ) ) )
|
428 |
+
$column = $label;
|
429 |
+
|
430 |
+
$value = '';
|
431 |
+
|
432 |
+
if ( is_object( $item ) ) {
|
433 |
+
if ( !isset( $item->$column ) )
|
434 |
+
$item->$column = '';
|
435 |
+
|
436 |
+
$value = $item->$column;
|
437 |
+
}
|
438 |
+
elseif ( is_array( $item ) ) {
|
439 |
+
if ( !isset( $item[ $column ] ) )
|
440 |
+
$item[ $column ] = '';
|
441 |
+
|
442 |
+
$value = $item[ $column ];
|
443 |
+
}
|
444 |
+
|
445 |
+
$row[ $column ] = $value;
|
446 |
+
}
|
447 |
+
|
448 |
+
$data[ 'items' ][ 'item' ][] = $row;
|
449 |
+
}
|
450 |
+
|
451 |
+
$this->built = @json_encode( $data );
|
452 |
+
|
453 |
+
return $this->built;
|
454 |
+
}
|
455 |
+
|
456 |
+
/**
|
457 |
+
* @param array $data Array of data
|
458 |
+
* @param string $delimiter Delimiter for export type 'sv'
|
459 |
+
*
|
460 |
+
* @return bool
|
461 |
+
*/
|
462 |
+
public function build_sv ( $data = null, $delimiter = null ) {
|
463 |
+
if ( !empty( $data ) )
|
464 |
+
$this->set_data( $data );
|
465 |
+
|
466 |
+
if ( !empty( $delimiter ) )
|
467 |
+
$this->delimiter = $delimiter;
|
468 |
+
|
469 |
+
if ( empty( $this->data ) || !is_array( $this->data ) )
|
470 |
+
return false;
|
471 |
+
|
472 |
+
$head = $lines = '';
|
473 |
+
|
474 |
+
foreach ( $this->data[ 'columns' ] as $column => $label ) {
|
475 |
+
$head .= '"' . $label . '"' . $this->delimiter;
|
476 |
+
}
|
477 |
+
|
478 |
+
$head = substr( $head, 0, -1 );
|
479 |
+
|
480 |
+
foreach ( $this->data[ 'items' ] as $item ) {
|
481 |
+
$line = '';
|
482 |
+
|
483 |
+
foreach ( $this->data[ 'columns' ] as $column => $label ) {
|
484 |
+
if ( is_numeric( $column ) && ( ( is_object( $item ) && !isset( $item->$column ) ) || ( is_array( $item ) && !isset( $item[ $column ] ) ) ) )
|
485 |
+
$column = $label;
|
486 |
+
|
487 |
+
$value = '';
|
488 |
+
|
489 |
+
if ( is_object( $item ) ) {
|
490 |
+
if ( !isset( $item->$column ) )
|
491 |
+
$item->$column = '';
|
492 |
+
|
493 |
+
$value = $item->$column;
|
494 |
+
}
|
495 |
+
elseif ( is_array( $item ) ) {
|
496 |
+
if ( !isset( $item[ $column ] ) )
|
497 |
+
$item[ $column ] = '';
|
498 |
+
|
499 |
+
$value = $item[ $column ];
|
500 |
+
}
|
501 |
+
|
502 |
+
if ( is_array( $value ) || is_object( $value ) )
|
503 |
+
$value = pods_serial_comma( $value, array( 'field' => $column, 'fields' => pods_var_raw( $column, $this->data[ 'fields' ] ), 'and' => '' ) );
|
504 |
+
|
505 |
+
$value = str_replace( array( '"', "\r\n", "\r", "\n" ), array( '\\"', "\n", "\n", '\n' ), $value );
|
506 |
+
|
507 |
+
$line .= '"' . $value . '"' . $this->delimiter;
|
508 |
+
}
|
509 |
+
|
510 |
+
$lines .= substr( $line, 0, -1 ) . "\n";
|
511 |
+
}
|
512 |
+
|
513 |
+
if ( !empty( $lines ) )
|
514 |
+
$lines = "\n" . substr( $lines, 0, -1 );
|
515 |
+
|
516 |
+
$this->built = $head . $lines;
|
517 |
+
|
518 |
+
return $this->built;
|
519 |
+
}
|
520 |
+
|
521 |
+
/**
|
522 |
+
* @param array $data Array of data
|
523 |
+
*
|
524 |
+
* @return bool
|
525 |
+
*/
|
526 |
+
public function build_xml ( $data = null ) {
|
527 |
+
if ( !empty( $data ) )
|
528 |
+
$this->set_data( $data );
|
529 |
+
|
530 |
+
if ( empty( $this->data ) || !is_array( $this->data ) )
|
531 |
+
return false;
|
532 |
+
|
533 |
+
$head = '<' . '?' . 'xml version="1.0" encoding="utf-8" ' . '?' . '>' . "\r\n<items count=\"" . count( $this->data[ 'items' ] ) . "\">\r\n";
|
534 |
+
$lines = '';
|
535 |
+
|
536 |
+
foreach ( $this->data[ 'items' ] as $item ) {
|
537 |
+
$line = "\t<item>\r\n";
|
538 |
+
|
539 |
+
foreach ( $this->data[ 'columns' ] as $column => $label ) {
|
540 |
+
if ( is_numeric( $column ) && ( ( is_object( $item ) && !isset( $item->$column ) ) || ( is_array( $item ) && !isset( $item[ $column ] ) ) ) )
|
541 |
+
$column = $label;
|
542 |
+
|
543 |
+
$line .= $this->build_xml_level( $item, $column );
|
544 |
+
}
|
545 |
+
|
546 |
+
$line .= "\t</item>\r\n";
|
547 |
+
$lines .= $line;
|
548 |
+
}
|
549 |
+
|
550 |
+
$foot = '</items>';
|
551 |
+
|
552 |
+
$this->built = $head . $lines . $foot;
|
553 |
+
|
554 |
+
return $this->built;
|
555 |
+
}
|
556 |
+
|
557 |
+
public function build_xml_level ( $item, $column, $level = 2, $column_name = '' ) {
|
558 |
+
$column = pods_clean_name( $column, false, false );
|
559 |
+
|
560 |
+
$line = '';
|
561 |
+
|
562 |
+
$value = '';
|
563 |
+
|
564 |
+
if ( is_object( $item ) ) {
|
565 |
+
if ( !isset( $item->$column ) )
|
566 |
+
$item->$column = '';
|
567 |
+
|
568 |
+
$value = $item->$column;
|
569 |
+
}
|
570 |
+
elseif ( is_array( $item ) ) {
|
571 |
+
if ( !isset( $item[ $column ] ) )
|
572 |
+
$item[ $column ] = '';
|
573 |
+
|
574 |
+
$value = $item[ $column ];
|
575 |
+
}
|
576 |
+
|
577 |
+
if ( !empty( $column_name ) )
|
578 |
+
$column = $column_name;
|
579 |
+
|
580 |
+
$tabs = str_repeat( "\t", $level );
|
581 |
+
|
582 |
+
$line .= $tabs . "<{$column}>";
|
583 |
+
|
584 |
+
if ( is_array( $value ) || is_object( $value ) ) {
|
585 |
+
if ( is_object( $value ) )
|
586 |
+
$value = get_object_vars( $value );
|
587 |
+
|
588 |
+
foreach ( $value as $k => $v ) {
|
589 |
+
if ( is_int( $k ) )
|
590 |
+
$line .= $this->build_xml_level( $value, $k, $level + 1, 'value' );
|
591 |
+
else
|
592 |
+
$line .= $this->build_xml_level( $value, $k, $level + 1 );
|
593 |
+
}
|
594 |
+
}
|
595 |
+
elseif ( false !== strpos( $value, '<' ) ) {
|
596 |
+
$value = str_replace( array( '<![CDATA[', ']]>' ), array( '<![CDATA[', ']]>' ), $value );
|
597 |
+
|
598 |
+
$line .= "<![CDATA[" . $value . "]]>";
|
599 |
+
}
|
600 |
+
else
|
601 |
+
$line .= str_replace( '&', '&', $value );
|
602 |
+
|
603 |
+
$line .= "</{$column}>\r\n";
|
604 |
+
|
605 |
+
return $line;
|
606 |
+
}
|
607 |
+
|
608 |
+
/**
|
609 |
+
* @param array $data Array of data
|
610 |
+
*
|
611 |
+
* @return mixed
|
612 |
+
*/
|
613 |
+
public function build_sql ( $data = null ) {
|
614 |
+
if ( !empty( $data ) )
|
615 |
+
$this->set_data( $data );
|
616 |
+
|
617 |
+
$this->built = $data;
|
618 |
+
|
619 |
+
return $this->built;
|
620 |
+
}
|
621 |
+
|
622 |
+
/**
|
623 |
+
* Save export to a file
|
624 |
+
*/
|
625 |
+
public function save() {
|
626 |
+
$extension = 'txt';
|
627 |
+
|
628 |
+
if ( 'sv' == $this->type ) {
|
629 |
+
if ( ',' == $this->delimiter )
|
630 |
+
$extension = 'csv';
|
631 |
+
elseif ( "\t" == $this->delimiter )
|
632 |
+
$extension = 'tsv';
|
633 |
+
}
|
634 |
+
else
|
635 |
+
$extension = $this->type;
|
636 |
+
|
637 |
+
$export_file = 'pods_export_' . wp_create_nonce( date_i18n( 'm-d-Y_h-i-sa' ) ) . '.' . $extension;
|
638 |
+
|
639 |
+
if ( !( ( $uploads = wp_upload_dir( current_time( 'mysql' ) ) ) && false === $uploads[ 'error' ] ) )
|
640 |
+
return pods_error( __( 'There was an issue saving the export file in your uploads folder.', 'pods' ), true );
|
641 |
+
|
642 |
+
// Generate unique file name
|
643 |
+
$filename = wp_unique_filename( $uploads[ 'path' ], $export_file );
|
644 |
+
|
645 |
+
// move the file to the uploads dir
|
646 |
+
$new_file = $uploads[ 'path' ] . '/' . $filename;
|
647 |
+
|
648 |
+
file_put_contents( $new_file, $this->built );
|
649 |
+
|
650 |
+
// Set correct file permissions
|
651 |
+
$stat = stat( dirname( $new_file ) );
|
652 |
+
$perms = $stat[ 'mode' ] & 0000666;
|
653 |
+
@chmod( $new_file, $perms );
|
654 |
+
|
655 |
+
// Get the file type
|
656 |
+
$wp_filetype = wp_check_filetype( $filename, $this->mimes );
|
657 |
+
|
658 |
+
// construct the attachment array
|
659 |
+
$attachment = array(
|
660 |
+
'post_mime_type' => ( !$wp_filetype[ 'type' ] ? 'text/' . $extension : $wp_filetype[ 'type' ] ),
|
661 |
+
'guid' => $uploads[ 'url' ] . '/' . $filename,
|
662 |
+
'post_parent' => null,
|
663 |
+
'post_title' => 'Pods Export (' . $export_file . ')',
|
664 |
+
'post_content' => '',
|
665 |
+
'post_status' => 'private'
|
666 |
+
);
|
667 |
+
|
668 |
+
// insert attachment
|
669 |
+
$attachment_id = wp_insert_attachment( $attachment, $new_file );
|
670 |
+
|
671 |
+
// error!
|
672 |
+
if ( is_wp_error( $attachment_id ) )
|
673 |
+
return pods_error( __( 'There was an issue saving the export file in your uploads folder.', 'pods' ), true );
|
674 |
+
|
675 |
+
return $attachment[ 'guid' ];
|
676 |
+
}
|
677 |
+
|
678 |
+
/*
|
679 |
+
* The real enchilada!
|
680 |
+
*/
|
681 |
+
/* EXAMPLES
|
682 |
+
//// minimal import (if your fields match on both your pods and tables)
|
683 |
+
$import = array('my_pod' => array('table' => 'my_table')); // if your table name doesn't match the pod name
|
684 |
+
$import = array('my_pod'); // if your table name matches your pod name
|
685 |
+
|
686 |
+
//// advanced import
|
687 |
+
$import = array();
|
688 |
+
$import['my_pod'] = array();
|
689 |
+
$import['my_pod']['fields']['this_field'] = 'field_name_in_table'; // if the field name doesn't match on table and pod
|
690 |
+
$import['my_pod']['fields'][] = 'that_field'; // if the field name matches on table and pod
|
691 |
+
$import['my_pod']['fields']['this_other_field'] = array('filter' => 'wpautop'); // if you want the value to be different than is provided, set a filter function to use [filter uses = filter_name($value,$rowdata)]
|
692 |
+
$import['my_pod']['fields']['another_field'] = array('field' => 'the_real_field_in_table','filter' => 'my_custom_function'); // if you want the value to be filtered, and the field name doesn't match on the table and pod
|
693 |
+
$import[] = 'my_other_pod'; // if your table name matches your pod name
|
694 |
+
$import['another_pod'] = array('update_on' => 'main_field'); // you can update a pod item if the value of this field is the same on both tables
|
695 |
+
$import['another_pod'] = array('reset' => true); // you can choose to reset all data in a pod before importing
|
696 |
+
|
697 |
+
//// run import
|
698 |
+
pods_import_it($import);
|
699 |
+
*/
|
700 |
+
/**
|
701 |
+
* @param $import
|
702 |
+
* @param bool $output
|
703 |
+
*/
|
704 |
+
public function heres_the_beef ( $import, $output = true ) {
|
705 |
+
global $wpdb;
|
706 |
+
|
707 |
+
$api = pods_api();
|
708 |
+
|
709 |
+
for ( $i = 0; $i < 40000; $i++ ) {
|
710 |
+
echo " \t"; // extra spaces
|
711 |
+
}
|
712 |
+
|
713 |
+
$default_data = array(
|
714 |
+
'pod' => null,
|
715 |
+
'table' => null,
|
716 |
+
'reset' => null,
|
717 |
+
'update_on' => null,
|
718 |
+
'where' => null,
|
719 |
+
'fields' => array(),
|
720 |
+
'row_filter' => null,
|
721 |
+
'pre_save' => null,
|
722 |
+
'post_save' => null,
|
723 |
+
'sql' => null,
|
724 |
+
'sort' => null,
|
725 |
+
'limit' => null,
|
726 |
+
'page' => null,
|
727 |
+
'output' => null,
|
728 |
+
'page_var' => 'ipg',
|
729 |
+
'bypass_helpers' => false
|
730 |
+
);
|
731 |
+
|
732 |
+
$default_field_data = array( 'field' => null, 'filter' => null );
|
733 |
+
|
734 |
+
if ( !is_array( $import ) )
|
735 |
+
$import = array( $import );
|
736 |
+
elseif ( empty( $import ) )
|
737 |
+
die( '<h1 style="color:red;font-weight:bold;">ERROR: No imports configured</h1>' );
|
738 |
+
|
739 |
+
$import_counter = 0;
|
740 |
+
$total_imports = count( $import );
|
741 |
+
$paginated = false;
|
742 |
+
$avg_time = -1;
|
743 |
+
$total_time = 0;
|
744 |
+
$counter = 0;
|
745 |
+
$avg_unit = 100;
|
746 |
+
$avg_counter = 0;
|
747 |
+
|
748 |
+
foreach ( $import as $datatype => $data ) {
|
749 |
+
$import_counter++;
|
750 |
+
|
751 |
+
flush();
|
752 |
+
@ob_end_flush();
|
753 |
+
usleep( 50000 );
|
754 |
+
|
755 |
+
if ( !is_array( $data ) ) {
|
756 |
+
$datatype = $data;
|
757 |
+
$data = array( 'table' => $data );
|
758 |
+
}
|
759 |
+
|
760 |
+
if ( isset( $data[ 0 ] ) )
|
761 |
+
$data = array( 'table' => $data[ 0 ] );
|
762 |
+
|
763 |
+
$data = array_merge( $default_data, $data );
|
764 |
+
|
765 |
+
if ( null === $data[ 'pod' ] )
|
766 |
+
$data[ 'pod' ] = array( 'name' => $datatype );
|
767 |
+
|
768 |
+
if ( false !== $output )
|
769 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - <strong>Loading Pod: " . $data[ 'pod' ][ 'name' ] . "</strong>\n";
|
770 |
+
|
771 |
+
if ( 2 > count( $data[ 'pod' ] ) )
|
772 |
+
$data[ 'pod' ] = $api->load_pod( array( 'name' => $data[ 'pod' ][ 'name' ] ) );
|
773 |
+
|
774 |
+
if ( empty( $data[ 'pod' ][ 'fields' ] ) )
|
775 |
+
continue;
|
776 |
+
|
777 |
+
if ( null === $data[ 'table' ] )
|
778 |
+
$data[ 'table' ] = $data[ 'pod' ][ 'name' ];
|
779 |
+
|
780 |
+
if ( $data[ 'reset' ] === true ) {
|
781 |
+
if ( false !== $output )
|
782 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - <strong style='color:blue;'>Resetting Pod: " . $data[ 'pod' ][ 'name' ] . "</strong>\n";
|
783 |
+
|
784 |
+
$api->reset_pod( array( 'id' => $data[ 'pod' ][ 'id' ], 'name' => $data[ 'pod' ][ 'name' ] ) );
|
785 |
+
}
|
786 |
+
|
787 |
+
if ( null === $data[ 'sort' ] && null !== $data[ 'update_on' ] && isset( $data[ 'fields' ][ $data[ 'update_on' ] ] ) ) {
|
788 |
+
if ( isset( $data[ 'fields' ][ $data[ 'update_on' ] ][ 'field' ] ) )
|
789 |
+
$data[ 'sort' ] = $data[ 'fields' ][ $data[ 'update_on' ] ][ 'field' ];
|
790 |
+
else
|
791 |
+
$data[ 'sort' ] = $data[ 'update_on' ];
|
792 |
+
}
|
793 |
+
|
794 |
+
$page = 1;
|
795 |
+
|
796 |
+
if ( false !== $data[ 'page_var' ] && isset( $_GET[ $data[ 'page_var' ] ] ) )
|
797 |
+
$page = absval( $_GET[ $data[ 'page_var' ] ] );
|
798 |
+
|
799 |
+
if ( null === $data[ 'sql' ] )
|
800 |
+
$data[ 'sql' ] = "SELECT * FROM {$data['table']}" . ( null !== $data[ 'where' ] ? " WHERE {$data['where']}" : '' ) . ( null !== $data[ 'sort' ] ? " ORDER BY {$data['sort']}" : '' ) . ( null !== $data[ 'limit' ] ? " LIMIT " . ( 1 < $page ? ( ( $page - 1 ) * $data[ 'limit' ] ) . ',' : '' ) . "{$data['limit']}" : '' );
|
801 |
+
|
802 |
+
if ( false !== $output )
|
803 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Getting Results: " . $data[ 'pod' ][ 'name' ] . "\n";
|
804 |
+
|
805 |
+
if ( false !== $output )
|
806 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Using Query: <small><code>" . $data[ 'sql' ] . "</code></small>\n";
|
807 |
+
|
808 |
+
$result = $wpdb->get_results( $data[ 'sql' ], ARRAY_A );
|
809 |
+
|
810 |
+
if ( false !== $output )
|
811 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Results Found: " . count( $result ) . "\n";
|
812 |
+
|
813 |
+
$avg_time = -1;
|
814 |
+
$total_time = 0;
|
815 |
+
$counter = 0;
|
816 |
+
$avg_unit = 100;
|
817 |
+
$avg_counter = 0;
|
818 |
+
$result_count = count( $result );
|
819 |
+
$paginated = false;
|
820 |
+
|
821 |
+
if ( false !== $data[ 'page_var' ] && $result_count == $data[ 'limit' ] )
|
822 |
+
$paginated = "<input type=\"button\" onclick=\"document.location=\'" . pods_ui_var_update( array( $data[ 'page_var' ] => $page + 1 ), false, false ) . "\';\" value=\" Continue Import » \" />";
|
823 |
+
|
824 |
+
if ( $result_count < $avg_unit && 5 < $result_count )
|
825 |
+
$avg_unit = number_format( $result_count / 5, 0, '', '' );
|
826 |
+
elseif ( 2000 < $result_count && 10 < count( $data[ 'pod' ][ 'fields' ] ) )
|
827 |
+
$avg_unit = 40;
|
828 |
+
|
829 |
+
$data[ 'count' ] = $result_count;
|
830 |
+
timer_start();
|
831 |
+
|
832 |
+
if ( false !== $output && 1 == $import_counter )
|
833 |
+
echo "<div style='width:50%;background-color:navy;padding:10px 10px 30px 10px;color:#FFF;position:absolute;top:10px;left:25%;text-align:center;'><p id='progress_status' align='center'>" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Running Importer..</p><br /><small>This will automatically update every " . $avg_unit . " rows</small></div>\n";
|
834 |
+
|
835 |
+
foreach ( $result as $k => $row ) {
|
836 |
+
flush();
|
837 |
+
@ob_end_flush();
|
838 |
+
usleep( 50000 );
|
839 |
+
|
840 |
+
if ( false !== $output )
|
841 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Processing Row #" . ( $k + 1 ) . "\n";
|
842 |
+
|
843 |
+
if ( null !== $data[ 'row_filter' ] && function_exists( $data[ 'row_filter' ] ) ) {
|
844 |
+
if ( false !== $output )
|
845 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Filtering <strong>" . $data[ 'row_filter' ] . "</strong> on Row #" . ( $k + 1 ) . "\n";
|
846 |
+
|
847 |
+
$row = $data[ 'row_filter' ]( $row, $data );
|
848 |
+
}
|
849 |
+
|
850 |
+
if ( !is_array( $row ) )
|
851 |
+
continue;
|
852 |
+
|
853 |
+
$params = array(
|
854 |
+
'datatype' => $data[ 'pod' ][ 'name' ],
|
855 |
+
'columns' => array(),
|
856 |
+
'bypass_helpers' => $data[ 'bypass_helpers' ]
|
857 |
+
);
|
858 |
+
|
859 |
+
foreach ( $data[ 'pod' ][ 'fields' ] as $fk => $field_info ) {
|
860 |
+
$field = $field_info[ 'name' ];
|
861 |
+
|
862 |
+
if ( !empty( $data[ 'fields' ] ) && !isset( $data[ 'fields' ][ $field ] ) && !in_array( $field, $data[ 'fields' ] ) )
|
863 |
+
continue;
|
864 |
+
|
865 |
+
if ( isset( $data[ 'fields' ][ $field ] ) ) {
|
866 |
+
if ( is_array( $data[ 'fields' ][ $field ] ) )
|
867 |
+
$field_data = $data[ 'fields' ][ $field ];
|
868 |
+
else
|
869 |
+
$field_data = array( 'field' => $data[ 'fields' ][ $field ] );
|
870 |
+
}
|
871 |
+
else
|
872 |
+
$field_data = array();
|
873 |
+
|
874 |
+
if ( !is_array( $field_data ) ) {
|
875 |
+
$field = $field_data;
|
876 |
+
$field_data = array();
|
877 |
+
}
|
878 |
+
|
879 |
+
$field_data = array_merge( $default_field_data, $field_data );
|
880 |
+
|
881 |
+
if ( null === $field_data[ 'field' ] )
|
882 |
+
$field_data[ 'field' ] = $field;
|
883 |
+
|
884 |
+
$data[ 'fields' ][ $field ] = $field_data;
|
885 |
+
$value = '';
|
886 |
+
|
887 |
+
if ( isset( $row[ $field_data[ 'field' ] ] ) )
|
888 |
+
$value = $row[ $field_data[ 'field' ] ];
|
889 |
+
|
890 |
+
if ( null !== $field_data[ 'filter' ] ) {
|
891 |
+
if ( function_exists( $field_data[ 'filter' ] ) ) {
|
892 |
+
if ( false !== $output )
|
893 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Filtering <strong>" . $field_data[ 'filter' ] . "</strong> on Field: " . $field . "\n";
|
894 |
+
|
895 |
+
$value = $field_data[ 'filter' ]( $value, $row, $data );
|
896 |
+
}
|
897 |
+
else
|
898 |
+
$value = '';
|
899 |
+
}
|
900 |
+
|
901 |
+
if ( 1 > strlen( $value ) && 1 == $field_info[ 'required' ] )
|
902 |
+
die( '<h1 style="color:red;font-weight:bold;">ERROR: Field Required for <strong>' . $field . '</strong></h1>' );
|
903 |
+
|
904 |
+
$params[ 'columns' ][ $field ] = $value;
|
905 |
+
|
906 |
+
unset( $value );
|
907 |
+
unset( $field_data );
|
908 |
+
unset( $field_info );
|
909 |
+
unset( $fk );
|
910 |
+
}
|
911 |
+
|
912 |
+
if ( empty( $params[ 'columns' ] ) )
|
913 |
+
continue;
|
914 |
+
|
915 |
+
$params[ 'columns' ] = pods_sanitize( $params[ 'columns' ] );
|
916 |
+
|
917 |
+
if ( null !== $data[ 'update_on' ] && isset( $params[ 'columns' ][ $data[ 'update_on' ] ] ) ) {
|
918 |
+
if ( false !== $output )
|
919 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Checking for Existing Item\n";
|
920 |
+
|
921 |
+
$check = new Pod( $data[ 'pod' ][ 'name' ] );
|
922 |
+
$check->findRecords( array(
|
923 |
+
'orderby' => 't.id',
|
924 |
+
'limit' => 1,
|
925 |
+
'where' => "t.{$data['update_on']} = '{$params['columns'][$data['update_on']]}'",
|
926 |
+
'search' => false,
|
927 |
+
'page' => 1
|
928 |
+
) );
|
929 |
+
|
930 |
+
if ( 0 < $check->getTotalRows() ) {
|
931 |
+
$check->fetchRecord();
|
932 |
+
|
933 |
+
$params[ 'tbl_row_id' ] = $check->get_field( 'id' );
|
934 |
+
$params[ 'pod_id' ] = $check->get_pod_id();
|
935 |
+
|
936 |
+
if ( false !== $output )
|
937 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Found Existing Item w/ ID: " . $params[ 'tbl_row_id' ] . "\n";
|
938 |
+
|
939 |
+
unset( $check );
|
940 |
+
}
|
941 |
+
|
942 |
+
if ( !isset( $params[ 'tbl_row_id' ] ) && false !== $output )
|
943 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Existing item not found - Creating New\n";
|
944 |
+
}
|
945 |
+
|
946 |
+
if ( null !== $data[ 'pre_save' ] && function_exists( $data[ 'pre_save' ] ) ) {
|
947 |
+
if ( false !== $output )
|
948 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Running Pre Save <strong>" . $data[ 'pre_save' ] . "</strong> on " . $data[ 'pod' ][ 'name' ] . "\n";
|
949 |
+
|
950 |
+
$params = $data[ 'pre_save' ]( $params, $row, $data );
|
951 |
+
}
|
952 |
+
|
953 |
+
$id = $api->save_pod_item( $params );
|
954 |
+
|
955 |
+
if ( false !== $output )
|
956 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - <strong>Saved Row #" . ( $k + 1 ) . " w/ ID: " . $id . "</strong>\n";
|
957 |
+
|
958 |
+
$params[ 'tbl_row_id' ] = $id;
|
959 |
+
|
960 |
+
if ( null !== $data[ 'post_save' ] && function_exists( $data[ 'post_save' ] ) ) {
|
961 |
+
if ( false !== $output )
|
962 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - Running Post Save <strong>" . $data[ 'post_save' ] . "</strong> on " . $data[ 'pod' ][ 'name' ] . "\n";
|
963 |
+
|
964 |
+
$data[ 'post_save' ]( $params, $row, $data );
|
965 |
+
}
|
966 |
+
|
967 |
+
unset( $params );
|
968 |
+
unset( $result[ $k ] );
|
969 |
+
unset( $row );
|
970 |
+
|
971 |
+
wp_cache_flush();
|
972 |
+
$wpdb->queries = array();
|
973 |
+
|
974 |
+
$avg_counter++;
|
975 |
+
$counter++;
|
976 |
+
|
977 |
+
if ( $avg_counter == $avg_unit && false !== $output ) {
|
978 |
+
$avg_counter = 0;
|
979 |
+
$avg_time = timer_stop( 0, 10 );
|
980 |
+
$total_time += $avg_time;
|
981 |
+
$rows_left = $result_count - $counter;
|
982 |
+
$estimated_time_left = ( ( $total_time / $counter ) * $rows_left ) / 60;
|
983 |
+
$percent_complete = 100 - ( ( $rows_left * 100 ) / $result_count );
|
984 |
+
|
985 |
+
echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em><br /><strong>" . $percent_complete . "% Complete</strong><br /><strong>Estimated Time Left:</strong> " . $estimated_time_left . " minute(s) or " . ( $estimated_time_left / 60 ) . " hours(s)<br /><strong>Time Spent:</strong> " . ( $total_time / 60 ) . " minute(s)<br /><strong>Rows Done:</strong> " . ( $result_count - $rows_left ) . "/" . $result_count . "<br /><strong>Rows Left:</strong> " . $rows_left . "';</script>\n";
|
986 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - <strong>Updated Status:</strong> " . $percent_complete . "% Complete</strong>\n";
|
987 |
+
}
|
988 |
+
}
|
989 |
+
|
990 |
+
if ( false !== $output ) {
|
991 |
+
$avg_counter = 0;
|
992 |
+
$avg_time = timer_stop( 0, 10 );
|
993 |
+
$total_time += $avg_time;
|
994 |
+
$rows_left = $result_count - $counter;
|
995 |
+
$estimated_time_left = ( ( $total_time / $counter ) * $rows_left ) / 60;
|
996 |
+
$percent_complete = 100 - ( ( $rows_left * 100 ) / $result_count );
|
997 |
+
|
998 |
+
echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em><br /><strong style=\'color:green;\'>100% Complete</strong><br /><br /><strong>Time Spent:</strong> " . ( $total_time / 60 ) . " minute(s)<br /><strong>Rows Imported:</strong> " . $result_count . ( false !== $paginated ? "<br /><br />" . $paginated : '' ) . "';</script>\n";
|
999 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <em>" . $data[ 'pod' ][ 'name' ] . "</em> - <strong style='color:green;'>Done Importing: " . $data[ 'pod' ][ 'name' ] . "</strong>\n";
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
unset( $result );
|
1003 |
+
unset( $import[ $datatype ] );
|
1004 |
+
unset( $datatype );
|
1005 |
+
unset( $data );
|
1006 |
+
|
1007 |
+
wp_cache_flush();
|
1008 |
+
$wpdb->queries = array();
|
1009 |
+
}
|
1010 |
+
|
1011 |
+
if ( false !== $output ) {
|
1012 |
+
$avg_counter = 0;
|
1013 |
+
$avg_time = timer_stop( 0, 10 );
|
1014 |
+
$total_time += $avg_time;
|
1015 |
+
$rows_left = $result_count - $counter;
|
1016 |
+
|
1017 |
+
echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date( 'Y-m-d h:i:sa' ) . " - <strong style=\'color:green;\'>Import Complete</strong><br /><br /><strong>Time Spent:</strong> " . ( $total_time / 60 ) . " minute(s)<br /><strong>Rows Imported:</strong> " . $result_count . ( false !== $paginated ? "<br /><br />" . $paginated : '' ) . "';</script>\n";
|
1018 |
+
echo "<br />" . date( 'Y-m-d h:i:sa' ) . " - <strong style='color:green;'>Import Complete</strong>\n";
|
1019 |
+
}
|
1020 |
+
}
|
1021 |
+
}
|
classes/PodsUI.php
ADDED
@@ -0,0 +1,4477 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Pods
|
4 |
+
*/
|
5 |
+
class PodsUI {
|
6 |
+
|
7 |
+
// internal
|
8 |
+
/**
|
9 |
+
* @var bool|PodsData
|
10 |
+
*/
|
11 |
+
private $pods_data = false;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @var array
|
15 |
+
*/
|
16 |
+
private $actions = array(
|
17 |
+
'manage',
|
18 |
+
'add',
|
19 |
+
'edit',
|
20 |
+
'duplicate',
|
21 |
+
'save',
|
22 |
+
//'view',
|
23 |
+
'delete',
|
24 |
+
'reorder',
|
25 |
+
'export'
|
26 |
+
);
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var array
|
30 |
+
*/
|
31 |
+
private $ui_page = array();
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @var bool
|
35 |
+
*/
|
36 |
+
private $unique_identifier = false;
|
37 |
+
|
38 |
+
// base
|
39 |
+
public $x = array();
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @var array|bool|mixed|null|Pods
|
43 |
+
*/
|
44 |
+
public $pod = false;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var int
|
48 |
+
*/
|
49 |
+
public $id = 0;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var string
|
53 |
+
*/
|
54 |
+
public $num = ''; // allows multiple co-existing PodsUI instances with separate functionality in URL
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @var array
|
58 |
+
*/
|
59 |
+
static $excluded = array(
|
60 |
+
'do',
|
61 |
+
'id',
|
62 |
+
'pg',
|
63 |
+
'search',
|
64 |
+
'filter_*',
|
65 |
+
'orderby',
|
66 |
+
'orderby_dir',
|
67 |
+
'limit',
|
68 |
+
'action',
|
69 |
+
'action_bulk',
|
70 |
+
'action_bulk_ids',
|
71 |
+
'view',
|
72 |
+
'export',
|
73 |
+
'export_type',
|
74 |
+
'export_delimiter',
|
75 |
+
'remove_export',
|
76 |
+
'updated',
|
77 |
+
'duplicate',
|
78 |
+
'message'
|
79 |
+
); // used in var_update
|
80 |
+
|
81 |
+
static $allowed = array(
|
82 |
+
'page',
|
83 |
+
'post_type'
|
84 |
+
);
|
85 |
+
|
86 |
+
// ui
|
87 |
+
/**
|
88 |
+
* @var bool
|
89 |
+
*/
|
90 |
+
public $item = false; // to be set with localized string
|
91 |
+
/**
|
92 |
+
* @var bool
|
93 |
+
*/
|
94 |
+
public $items = false; // to be set with localized string
|
95 |
+
/**
|
96 |
+
* @var bool
|
97 |
+
*/
|
98 |
+
public $heading = false; // to be set with localized string array
|
99 |
+
/**
|
100 |
+
* @var bool
|
101 |
+
*/
|
102 |
+
public $header = false; // to be set with localized string array
|
103 |
+
/**
|
104 |
+
* @var bool
|
105 |
+
*/
|
106 |
+
public $label = false; // to be set with localized string array
|
107 |
+
/**
|
108 |
+
* @var bool
|
109 |
+
*/
|
110 |
+
public $icon = false;
|
111 |
+
|
112 |
+
/**
|
113 |
+
* @var bool
|
114 |
+
*/
|
115 |
+
public $css = false; // set to a URL of stylesheet to include
|
116 |
+
/**
|
117 |
+
* @var bool
|
118 |
+
*/
|
119 |
+
public $wpcss = false; // set to true to include WP Admin stylesheets
|
120 |
+
/**
|
121 |
+
* @var array
|
122 |
+
*/
|
123 |
+
public $fields = array(
|
124 |
+
'manage' => array(),
|
125 |
+
'search' => array(),
|
126 |
+
'form' => array(),
|
127 |
+
'add' => array(),
|
128 |
+
'edit' => array(),
|
129 |
+
'duplicate' => array(),
|
130 |
+
'view' => array(),
|
131 |
+
'reorder' => array(),
|
132 |
+
'export' => array()
|
133 |
+
);
|
134 |
+
|
135 |
+
/**
|
136 |
+
* @var bool
|
137 |
+
*/
|
138 |
+
public $searchable = true;
|
139 |
+
|
140 |
+
/**
|
141 |
+
* @var bool
|
142 |
+
*/
|
143 |
+
public $sortable = true;
|
144 |
+
|
145 |
+
/**
|
146 |
+
* @var bool
|
147 |
+
*/
|
148 |
+
public $pagination = true;
|
149 |
+
|
150 |
+
/**
|
151 |
+
* @var bool
|
152 |
+
*/
|
153 |
+
public $pagination_total = true;
|
154 |
+
|
155 |
+
/**
|
156 |
+
* @var array
|
157 |
+
*/
|
158 |
+
public $export = array(
|
159 |
+
'on' => false,
|
160 |
+
'formats' => array(
|
161 |
+
'csv' => ',',
|
162 |
+
'tsv' => "\t",
|
163 |
+
'xml' => false,
|
164 |
+
'json' => false
|
165 |
+
),
|
166 |
+
'url' => false,
|
167 |
+
'type' => false
|
168 |
+
);
|
169 |
+
|
170 |
+
/**
|
171 |
+
* @var array
|
172 |
+
*/
|
173 |
+
public $reorder = array(
|
174 |
+
'on' => false,
|
175 |
+
'limit' => 250,
|
176 |
+
'orderby' => false,
|
177 |
+
'orderby_dir' => 'ASC',
|
178 |
+
'sql' => null
|
179 |
+
);
|
180 |
+
|
181 |
+
/**
|
182 |
+
* @var array
|
183 |
+
*/
|
184 |
+
public $screen_options = array(); // set to 'page' => 'Text'; false hides link
|
185 |
+
/**
|
186 |
+
* @var array
|
187 |
+
*/
|
188 |
+
public $help = array(); // set to 'page' => 'Text'; 'page' => array('link' => 'yourhelplink'); false hides link
|
189 |
+
|
190 |
+
// data
|
191 |
+
/**
|
192 |
+
* @var bool
|
193 |
+
*/
|
194 |
+
public $search = false;
|
195 |
+
|
196 |
+
/**
|
197 |
+
* @var bool
|
198 |
+
*/
|
199 |
+
public $filters_enhanced = false;
|
200 |
+
|
201 |
+
/**
|
202 |
+
* @var array
|
203 |
+
*/
|
204 |
+
public $filters = array();
|
205 |
+
|
206 |
+
/**
|
207 |
+
* @var string
|
208 |
+
*/
|
209 |
+
public $view = false;
|
210 |
+
|
211 |
+
/**
|
212 |
+
* @var array
|
213 |
+
*/
|
214 |
+
public $views = array();
|
215 |
+
|
216 |
+
/**
|
217 |
+
* @var bool
|
218 |
+
*/
|
219 |
+
public $search_across = true;
|
220 |
+
|
221 |
+
/**
|
222 |
+
* @var bool
|
223 |
+
*/
|
224 |
+
public $search_across_picks = false;
|
225 |
+
|
226 |
+
/**
|
227 |
+
* @var bool
|
228 |
+
*/
|
229 |
+
public $default_none = false;
|
230 |
+
|
231 |
+
/**
|
232 |
+
* @var array
|
233 |
+
*/
|
234 |
+
public $where = array(
|
235 |
+
'manage' => null,
|
236 |
+
/*'edit' => null,
|
237 |
+
'duplicate' => null,
|
238 |
+
'delete' => null,*/
|
239 |
+
'reorder' => null
|
240 |
+
);
|
241 |
+
|
242 |
+
/**
|
243 |
+
* @var bool
|
244 |
+
*/
|
245 |
+
public $orderby = false;
|
246 |
+
|
247 |
+
/**
|
248 |
+
* @var string
|
249 |
+
*/
|
250 |
+
public $orderby_dir = 'DESC';
|
251 |
+
|
252 |
+
/**
|
253 |
+
* @var int
|
254 |
+
*/
|
255 |
+
public $limit = 25;
|
256 |
+
|
257 |
+
/**
|
258 |
+
* @var int
|
259 |
+
*/
|
260 |
+
public $page = 1;
|
261 |
+
|
262 |
+
/**
|
263 |
+
* @var int
|
264 |
+
*/
|
265 |
+
public $total = 0;
|
266 |
+
|
267 |
+
/**
|
268 |
+
* @var int
|
269 |
+
*/
|
270 |
+
public $total_found = 0;
|
271 |
+
|
272 |
+
/**
|
273 |
+
* @var array
|
274 |
+
*/
|
275 |
+
public $session = array(
|
276 |
+
'search',
|
277 |
+
'filters'
|
278 |
+
); // allowed: search, filters, show_per_page, orderby (priority over usermeta)
|
279 |
+
/**
|
280 |
+
* @var array
|
281 |
+
*/
|
282 |
+
public $user = array(
|
283 |
+
'show_per_page',
|
284 |
+
'orderby'
|
285 |
+
); // allowed: search, filters, show_per_page, orderby (priority under session)
|
286 |
+
|
287 |
+
// advanced data
|
288 |
+
/**
|
289 |
+
* @var array
|
290 |
+
*/
|
291 |
+
public $sql = array(
|
292 |
+
'table' => null,
|
293 |
+
'field_id' => 'id',
|
294 |
+
'field_index' => 'name',
|
295 |
+
'select' => null,
|
296 |
+
'sql' => null
|
297 |
+
);
|
298 |
+
|
299 |
+
/**
|
300 |
+
* @var array
|
301 |
+
*/
|
302 |
+
public $params = array();
|
303 |
+
|
304 |
+
/**
|
305 |
+
* @var bool|array
|
306 |
+
*/
|
307 |
+
public $data = false;
|
308 |
+
|
309 |
+
/**
|
310 |
+
* @var bool|array
|
311 |
+
*/
|
312 |
+
public $data_full = false;
|
313 |
+
|
314 |
+
/**
|
315 |
+
* @var array
|
316 |
+
*/
|
317 |
+
public $data_keys = array();
|
318 |
+
|
319 |
+
/**
|
320 |
+
* @var array
|
321 |
+
*/
|
322 |
+
public $row = array();
|
323 |
+
|
324 |
+
// actions
|
325 |
+
/**
|
326 |
+
* @var string
|
327 |
+
*/
|
328 |
+
public $action = 'manage';
|
329 |
+
|
330 |
+
/**
|
331 |
+
* @var string
|
332 |
+
*/
|
333 |
+
public $action_bulk = false;
|
334 |
+
|
335 |
+
/**
|
336 |
+
* @var array
|
337 |
+
*/
|
338 |
+
public $bulk = array();
|
339 |
+
|
340 |
+
/**
|
341 |
+
* @var array
|
342 |
+
*/
|
343 |
+
public $action_after = array(
|
344 |
+
'add' => 'edit',
|
345 |
+
'edit' => 'edit',
|
346 |
+
'duplicate' => 'edit'
|
347 |
+
); // set action to 'manage'
|
348 |
+
/**
|
349 |
+
* @var bool
|
350 |
+
*/
|
351 |
+
public $do = false;
|
352 |
+
|
353 |
+
/**
|
354 |
+
* @var array
|
355 |
+
*/
|
356 |
+
public $action_links = array(
|
357 |
+
'manage' => null,
|
358 |
+
'add' => null,
|
359 |
+
'edit' => null,
|
360 |
+
'duplicate' => null,
|
361 |
+
'view' => null,
|
362 |
+
'delete' => null,
|
363 |
+
'reorder' => null
|
364 |
+
); // custom links (ex. /my-link/{@id}/
|
365 |
+
|
366 |
+
/**
|
367 |
+
* @var array
|
368 |
+
*/
|
369 |
+
public $actions_disabled = array(
|
370 |
+
'view',
|
371 |
+
'export'
|
372 |
+
); // disable actions
|
373 |
+
|
374 |
+
/**
|
375 |
+
* @var array
|
376 |
+
*/
|
377 |
+
public $actions_hidden = array(); // hide actions to not show them but allow them
|
378 |
+
|
379 |
+
/**
|
380 |
+
* @var array
|
381 |
+
*/
|
382 |
+
public $actions_custom = array(); // overwrite existing actions or add your own
|
383 |
+
|
384 |
+
/**
|
385 |
+
* @var array
|
386 |
+
*/
|
387 |
+
public $actions_bulk = array(); // enabled bulk actions
|
388 |
+
|
389 |
+
/**
|
390 |
+
* @var array
|
391 |
+
*/
|
392 |
+
public $restrict = array(
|
393 |
+
'manage' => null,
|
394 |
+
'edit' => null,
|
395 |
+
'duplicate' => null,
|
396 |
+
'delete' => null,
|
397 |
+
'reorder' => null,
|
398 |
+
'author_restrict' => null
|
399 |
+
);
|
400 |
+
|
401 |
+
/**
|
402 |
+
* @var array
|
403 |
+
*/
|
404 |
+
public $extra = array(
|
405 |
+
'total' => null
|
406 |
+
);
|
407 |
+
|
408 |
+
/**
|
409 |
+
* @var string
|
410 |
+
*/
|
411 |
+
public $style = 'post_type';
|
412 |
+
|
413 |
+
/**
|
414 |
+
* @var bool
|
415 |
+
*/
|
416 |
+
public $save = false; // Allow custom save handling for tables that aren't Pod-based
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Generate UI for Data Management
|
420 |
+
*
|
421 |
+
* @param mixed $options Object, Array, or String containing Pod or Options to be used
|
422 |
+
* @param bool $deprecated Set to true to support old options array from Pods UI plugin
|
423 |
+
*
|
424 |
+
* @return \PodsUI
|
425 |
+
*
|
426 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
427 |
+
* @since 2.0
|
428 |
+
*/
|
429 |
+
public function __construct ( $options, $deprecated = false ) {
|
430 |
+
$object = null;
|
431 |
+
|
432 |
+
if ( is_object( $options ) ) {
|
433 |
+
$object = $options;
|
434 |
+
$options = array();
|
435 |
+
|
436 |
+
if ( isset( $object->ui ) ) {
|
437 |
+
$options = (array) $object->ui;
|
438 |
+
|
439 |
+
unset( $object->ui );
|
440 |
+
}
|
441 |
+
|
442 |
+
if ( is_object( $object ) && ( 'Pods' == get_class( $object ) || 'Pod' == get_class( $object ) ) )
|
443 |
+
$this->pod =& $object;
|
444 |
+
}
|
445 |
+
|
446 |
+
if ( !is_array( $options ) ) {
|
447 |
+
// @todo need to come back to this and allow for multi-dimensional strings
|
448 |
+
// like: option=value&option2=value2&option3=key[val],key2[val2]&option4=this,that,another
|
449 |
+
if ( false !== strpos( $options, '=' ) || false !== strpos( $options, '&' ) )
|
450 |
+
parse_str( $options, $options );
|
451 |
+
else
|
452 |
+
$options = array( 'pod' => $options );
|
453 |
+
}
|
454 |
+
|
455 |
+
if ( !is_object( $object ) && isset( $options[ 'pod' ] ) ) {
|
456 |
+
if ( is_object( $options[ 'pod' ] ) )
|
457 |
+
$this->pod = $options[ 'pod' ];
|
458 |
+
elseif ( isset( $options[ 'id' ] ) )
|
459 |
+
$this->pod = pods( $options[ 'pod' ], $options[ 'id' ] );
|
460 |
+
else
|
461 |
+
$this->pod = pods( $options[ 'pod' ] );
|
462 |
+
|
463 |
+
unset( $options[ 'pod' ] );
|
464 |
+
}
|
465 |
+
elseif ( is_object( $object ) )
|
466 |
+
$this->pod = $object;
|
467 |
+
|
468 |
+
if ( false !== $deprecated || ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) ) )
|
469 |
+
$options = $this->setup_deprecated( $options );
|
470 |
+
|
471 |
+
if ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) && is_object( $this->pod->_data ) )
|
472 |
+
$this->pods_data =& $this->pod->_data;
|
473 |
+
elseif ( is_object( $this->pod ) && 'Pods' == get_class( $this->pod ) && is_object( $this->pod->data ) )
|
474 |
+
$this->pods_data =& $this->pod->data;
|
475 |
+
elseif ( is_object( $this->pod ) )
|
476 |
+
$this->pods_data = pods_data( $this->pod->pod );
|
477 |
+
elseif ( !is_object( $this->pod ) )
|
478 |
+
$this->pods_data = pods_data( $this->pod );
|
479 |
+
|
480 |
+
$options = $this->do_hook( 'pre_init', $options );
|
481 |
+
$this->setup( $options );
|
482 |
+
|
483 |
+
if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id ) {
|
484 |
+
if ( $this->id != $this->pods_data->id )
|
485 |
+
$this->row = $this->pods_data->fetch( $this->id );
|
486 |
+
else
|
487 |
+
$this->row = $this->pods_data->row;
|
488 |
+
}
|
489 |
+
|
490 |
+
if ( ( !is_object( $this->pod ) || 'Pods' != get_class( $this->pod ) ) && false === $this->sql[ 'table' ] && false === $this->data ) {
|
491 |
+
echo $this->error( __( '<strong>Error:</strong> Pods UI needs a Pods object or a Table definition to run from, see the User Guide for more information.', 'pods' ) );
|
492 |
+
|
493 |
+
return false;
|
494 |
+
}
|
495 |
+
|
496 |
+
$this->go();
|
497 |
+
}
|
498 |
+
|
499 |
+
/**
|
500 |
+
* @param $deprecated_options
|
501 |
+
*
|
502 |
+
* @return array
|
503 |
+
*/
|
504 |
+
public function setup_deprecated ( $deprecated_options ) {
|
505 |
+
$options = array();
|
506 |
+
|
507 |
+
if ( isset( $deprecated_options[ 'id' ] ) )
|
508 |
+
$options[ 'id' ] = $deprecated_options[ 'id' ];
|
509 |
+
if ( isset( $deprecated_options[ 'action' ] ) )
|
510 |
+
$options[ 'action' ] = $deprecated_options[ 'action' ];
|
511 |
+
if ( isset( $deprecated_options[ 'num' ] ) )
|
512 |
+
$options[ 'num' ] = $deprecated_options[ 'num' ];
|
513 |
+
|
514 |
+
if ( isset( $deprecated_options[ 'title' ] ) )
|
515 |
+
$options[ 'items' ] = $deprecated_options[ 'title' ];
|
516 |
+
if ( isset( $deprecated_options[ 'item' ] ) )
|
517 |
+
$options[ 'item' ] = $deprecated_options[ 'item' ];
|
518 |
+
|
519 |
+
if ( isset( $deprecated_options[ 'label' ] ) )
|
520 |
+
$options[ 'label' ] = array(
|
521 |
+
'add' => $deprecated_options[ 'label' ],
|
522 |
+
'edit' => $deprecated_options[ 'label' ],
|
523 |
+
'duplicate' => $deprecated_options[ 'label' ]
|
524 |
+
);
|
525 |
+
if ( isset( $deprecated_options[ 'label_add' ] ) ) {
|
526 |
+
if ( isset( $options[ 'label' ] ) )
|
527 |
+
$options[ 'label' ][ 'add' ] = $deprecated_options[ 'label_add' ];
|
528 |
+
else
|
529 |
+
$options[ 'label' ] = array( 'add' => $deprecated_options[ 'label_add' ] );
|
530 |
+
}
|
531 |
+
if ( isset( $deprecated_options[ 'label_edit' ] ) ) {
|
532 |
+
if ( isset( $options[ 'label' ] ) )
|
533 |
+
$options[ 'label' ][ 'edit' ] = $deprecated_options[ 'label_edit' ];
|
534 |
+
else
|
535 |
+
$options[ 'label' ] = array( 'edit' => $deprecated_options[ 'label_edit' ] );
|
536 |
+
}
|
537 |
+
if ( isset( $deprecated_options[ 'label_duplicate' ] ) ) {
|
538 |
+
if ( isset( $options[ 'label' ] ) )
|
539 |
+
$options[ 'label' ][ 'duplicate' ] = $deprecated_options[ 'label_duplicate' ];
|
540 |
+
else
|
541 |
+
$options[ 'label' ] = array( 'duplicate' => $deprecated_options[ 'label_duplicate' ] );
|
542 |
+
}
|
543 |
+
|
544 |
+
if ( isset( $deprecated_options[ 'icon' ] ) )
|
545 |
+
$options[ 'icon' ] = $deprecated_options[ 'icon' ];
|
546 |
+
|
547 |
+
if ( isset( $deprecated_options[ 'columns' ] ) )
|
548 |
+
$options[ 'fields' ] = array( 'manage' => $deprecated_options[ 'columns' ] );
|
549 |
+
if ( isset( $deprecated_options[ 'reorder_columns' ] ) ) {
|
550 |
+
if ( isset( $options[ 'fields' ] ) )
|
551 |
+
$options[ 'fields' ][ 'reorder' ] = $deprecated_options[ 'reorder_columns' ];
|
552 |
+
else
|
553 |
+
$options[ 'fields' ] = array( 'reorder' => $deprecated_options[ 'reorder_columns' ] );
|
554 |
+
}
|
555 |
+
if ( isset( $deprecated_options[ 'add_fields' ] ) ) {
|
556 |
+
if ( isset( $options[ 'fields' ] ) ) {
|
557 |
+
if ( !isset( $options[ 'fields' ][ 'add' ] ) )
|
558 |
+
$options[ 'fields' ][ 'add' ] = $deprecated_options[ 'add_fields' ];
|
559 |
+
if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
|
560 |
+
$options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'add_fields' ];
|
561 |
+
if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
|
562 |
+
$options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'add_fields' ];
|
563 |
+
}
|
564 |
+
else
|
565 |
+
$options[ 'fields' ] = array(
|
566 |
+
'add' => $deprecated_options[ 'add_fields' ],
|
567 |
+
'edit' => $deprecated_options[ 'add_fields' ],
|
568 |
+
'duplicate' => $deprecated_options[ 'add_fields' ]
|
569 |
+
);
|
570 |
+
}
|
571 |
+
if ( isset( $deprecated_options[ 'edit_fields' ] ) ) {
|
572 |
+
if ( isset( $options[ 'fields' ] ) ) {
|
573 |
+
if ( !isset( $options[ 'fields' ][ 'add' ] ) )
|
574 |
+
$options[ 'fields' ][ 'add' ] = $deprecated_options[ 'edit_fields' ];
|
575 |
+
if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
|
576 |
+
$options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'edit_fields' ];
|
577 |
+
if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
|
578 |
+
$options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'edit_fields' ];
|
579 |
+
}
|
580 |
+
else
|
581 |
+
$options[ 'fields' ] = array(
|
582 |
+
'add' => $deprecated_options[ 'edit_fields' ],
|
583 |
+
'edit' => $deprecated_options[ 'edit_fields' ],
|
584 |
+
'duplicate' => $deprecated_options[ 'edit_fields' ]
|
585 |
+
);
|
586 |
+
}
|
587 |
+
if ( isset( $deprecated_options[ 'duplicate_fields' ] ) ) {
|
588 |
+
if ( isset( $options[ 'fields' ] ) )
|
589 |
+
$options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_fields' ];
|
590 |
+
else
|
591 |
+
$options[ 'fields' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_fields' ] );
|
592 |
+
}
|
593 |
+
|
594 |
+
if ( isset( $deprecated_options[ 'session_filters' ] ) && false === $deprecated_options[ 'session_filters' ] )
|
595 |
+
$options[ 'session' ] = false;
|
596 |
+
if ( isset( $deprecated_options[ 'user_per_page' ] ) ) {
|
597 |
+
if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
|
598 |
+
$options[ 'user' ] = array( 'orderby' );
|
599 |
+
else
|
600 |
+
$options[ 'user' ] = false;
|
601 |
+
}
|
602 |
+
if ( isset( $deprecated_options[ 'user_sort' ] ) ) {
|
603 |
+
if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
|
604 |
+
$options[ 'user' ] = array( 'show_per_page' );
|
605 |
+
else
|
606 |
+
$options[ 'user' ] = false;
|
607 |
+
}
|
608 |
+
|
609 |
+
if ( isset( $deprecated_options[ 'custom_list' ] ) ) {
|
610 |
+
if ( isset( $options[ 'actions_custom' ] ) )
|
611 |
+
$options[ 'actions_custom' ][ 'manage' ] = $deprecated_options[ 'custom_list' ];
|
612 |
+
else
|
613 |
+
$options[ 'actions_custom' ] = array( 'manage' => $deprecated_options[ 'custom_list' ] );
|
614 |
+
}
|
615 |
+
if ( isset( $deprecated_options[ 'custom_reorder' ] ) ) {
|
616 |
+
if ( isset( $options[ 'actions_custom' ] ) )
|
617 |
+
$options[ 'actions_custom' ][ 'reorder' ] = $deprecated_options[ 'custom_reorder' ];
|
618 |
+
else
|
619 |
+
$options[ 'actions_custom' ] = array( 'reorder' => $deprecated_options[ 'custom_reorder' ] );
|
620 |
+
}
|
621 |
+
if ( isset( $deprecated_options[ 'custom_add' ] ) ) {
|
622 |
+
if ( isset( $options[ 'actions_custom' ] ) )
|
623 |
+
$options[ 'actions_custom' ][ 'add' ] = $deprecated_options[ 'custom_add' ];
|
624 |
+
else
|
625 |
+
$options[ 'actions_custom' ] = array( 'add' => $deprecated_options[ 'custom_add' ] );
|
626 |
+
}
|
627 |
+
if ( isset( $deprecated_options[ 'custom_edit' ] ) ) {
|
628 |
+
if ( isset( $options[ 'actions_custom' ] ) )
|
629 |
+
$options[ 'actions_custom' ][ 'edit' ] = $deprecated_options[ 'custom_edit' ];
|
630 |
+
else
|
631 |
+
$options[ 'actions_custom' ] = array( 'edit' => $deprecated_options[ 'custom_edit' ] );
|
632 |
+
}
|
633 |
+
if ( isset( $deprecated_options[ 'custom_duplicate' ] ) ) {
|
634 |
+
if ( isset( $options[ 'actions_custom' ] ) )
|
635 |
+
$options[ 'actions_custom' ][ 'duplicate' ] = $deprecated_options[ 'custom_duplicate' ];
|
636 |
+
else
|
637 |
+
$options[ 'actions_custom' ] = array( 'duplicate' => $deprecated_options[ 'custom_duplicate' ] );
|
638 |
+
}
|
639 |
+
if ( isset( $deprecated_options[ 'custom_delete' ] ) ) {
|
640 |
+
if ( isset( $options[ 'actions_custom' ] ) )
|
641 |
+
$options[ 'actions_custom' ][ 'delete' ] = $deprecated_options[ 'custom_delete' ];
|
642 |
+
else
|
643 |
+
$options[ 'actions_custom' ] = array( 'delete' => $deprecated_options[ 'custom_delete' ] );
|
644 |
+
}
|
645 |
+
if ( isset( $deprecated_options[ 'custom_save' ] ) ) {
|
646 |
+
if ( isset( $options[ 'actions_custom' ] ) )
|
647 |
+
$options[ 'actions_custom' ][ 'save' ] = $deprecated_options[ 'custom_save' ];
|
648 |
+
else
|
649 |
+
$options[ 'actions_custom' ] = array( 'save' => $deprecated_options[ 'custom_save' ] );
|
650 |
+
}
|
651 |
+
|
652 |
+
if ( isset( $deprecated_options[ 'custom_actions' ] ) )
|
653 |
+
$options[ 'actions_custom' ] = $deprecated_options[ 'custom_actions' ];
|
654 |
+
if ( isset( $deprecated_options[ 'action_after_save' ] ) )
|
655 |
+
$options[ 'action_after' ] = array(
|
656 |
+
'add' => $deprecated_options[ 'action_after_save' ],
|
657 |
+
'edit' => $deprecated_options[ 'action_after_save' ],
|
658 |
+
'duplicate' => $deprecated_options[ 'action_after_save' ]
|
659 |
+
);
|
660 |
+
if ( isset( $deprecated_options[ 'edit_link' ] ) ) {
|
661 |
+
if ( isset( $options[ 'action_links' ] ) )
|
662 |
+
$options[ 'action_links' ][ 'edit' ] = $deprecated_options[ 'edit_link' ];
|
663 |
+
else
|
664 |
+
$options[ 'action_links' ] = array( 'edit' => $deprecated_options[ 'edit_link' ] );
|
665 |
+
}
|
666 |
+
if ( isset( $deprecated_options[ 'view_link' ] ) ) {
|
667 |
+
if ( isset( $options[ 'action_links' ] ) )
|
668 |
+
$options[ 'action_links' ][ 'view' ] = $deprecated_options[ 'view_link' ];
|
669 |
+
else
|
670 |
+
$options[ 'action_links' ] = array( 'view' => $deprecated_options[ 'view_link' ] );
|
671 |
+
}
|
672 |
+
if ( isset( $deprecated_options[ 'duplicate_link' ] ) ) {
|
673 |
+
if ( isset( $options[ 'action_links' ] ) )
|
674 |
+
$options[ 'action_links' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_link' ];
|
675 |
+
else
|
676 |
+
$options[ 'action_links' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_link' ] );
|
677 |
+
}
|
678 |
+
|
679 |
+
if ( isset( $deprecated_options[ 'reorder' ] ) )
|
680 |
+
$options[ 'reorder' ] = array(
|
681 |
+
'on' => $deprecated_options[ 'reorder' ],
|
682 |
+
'orderby' => $deprecated_options[ 'reorder' ]
|
683 |
+
);
|
684 |
+
if ( isset( $deprecated_options[ 'reorder_sort' ] ) && isset( $options[ 'reorder' ] ) )
|
685 |
+
$options[ 'reorder' ][ 'orderby' ] = $deprecated_options[ 'reorder_sort' ];
|
686 |
+
if ( isset( $deprecated_options[ 'reorder_limit' ] ) && isset( $options[ 'reorder' ] ) )
|
687 |
+
$options[ 'reorder' ][ 'limit' ] = $deprecated_options[ 'reorder_limit' ];
|
688 |
+
if ( isset( $deprecated_options[ 'reorder_sql' ] ) && isset( $options[ 'reorder' ] ) )
|
689 |
+
$options[ 'reorder' ][ 'sql' ] = $deprecated_options[ 'reorder_sql' ];
|
690 |
+
|
691 |
+
if ( isset( $deprecated_options[ 'sort' ] ) )
|
692 |
+
$options[ 'orderby' ] = $deprecated_options[ 'sort' ];
|
693 |
+
if ( isset( $deprecated_options[ 'sortable' ] ) )
|
694 |
+
$options[ 'sortable' ] = $deprecated_options[ 'sortable' ];
|
695 |
+
if ( isset( $deprecated_options[ 'limit' ] ) )
|
696 |
+
$options[ 'limit' ] = $deprecated_options[ 'limit' ];
|
697 |
+
|
698 |
+
if ( isset( $deprecated_options[ 'where' ] ) ) {
|
699 |
+
if ( isset( $options[ 'where' ] ) )
|
700 |
+
$options[ 'where' ][ 'manage' ] = $deprecated_options[ 'where' ];
|
701 |
+
else
|
702 |
+
$options[ 'where' ] = array( 'manage' => $deprecated_options[ 'where' ] );
|
703 |
+
}
|
704 |
+
if ( isset( $deprecated_options[ 'edit_where' ] ) ) {
|
705 |
+
/*if ( isset( $options[ 'where' ] ) )
|
706 |
+
$options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ];
|
707 |
+
else
|
708 |
+
$options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );*/
|
709 |
+
|
710 |
+
if ( isset( $options[ 'restrict' ] ) )
|
711 |
+
$options[ 'restrict' ][ 'edit' ] = (array) $deprecated_options[ 'edit_where' ];
|
712 |
+
else
|
713 |
+
$options[ 'restrict' ] = array( 'edit' => (array) $deprecated_options[ 'edit_where' ] );
|
714 |
+
}
|
715 |
+
if ( isset( $deprecated_options[ 'duplicate_where' ] ) ) {
|
716 |
+
/*if ( isset( $options[ 'where' ] ) )
|
717 |
+
$options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ];
|
718 |
+
else
|
719 |
+
$options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );*/
|
720 |
+
|
721 |
+
if ( isset( $options[ 'restrict' ] ) )
|
722 |
+
$options[ 'restrict' ][ 'duplicate' ] = (array) $deprecated_options[ 'duplicate_where' ];
|
723 |
+
else
|
724 |
+
$options[ 'restrict' ] = array( 'duplicate' => (array) $deprecated_options[ 'duplicate_where' ] );
|
725 |
+
}
|
726 |
+
if ( isset( $deprecated_options[ 'delete_where' ] ) ) {
|
727 |
+
/*if ( isset( $options[ 'where' ] ) )
|
728 |
+
$options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ];
|
729 |
+
else
|
730 |
+
$options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );*/
|
731 |
+
|
732 |
+
if ( isset( $options[ 'restrict' ] ) )
|
733 |
+
$options[ 'restrict' ][ 'delete' ] = (array) $deprecated_options[ 'delete_where' ];
|
734 |
+
else
|
735 |
+
$options[ 'restrict' ] = array( 'delete' => (array) $deprecated_options[ 'delete_where' ] );
|
736 |
+
}
|
737 |
+
if ( isset( $deprecated_options[ 'reorder_where' ] ) ) {
|
738 |
+
if ( isset( $options[ 'where' ] ) )
|
739 |
+
$options[ 'where' ][ 'reorder' ] = $deprecated_options[ 'reorder_where' ];
|
740 |
+
else
|
741 |
+
$options[ 'where' ] = array( 'reorder' => $deprecated_options[ 'reorder_where' ] );
|
742 |
+
}
|
743 |
+
|
744 |
+
if ( isset( $deprecated_options[ 'sql' ] ) )
|
745 |
+
$options[ 'sql' ] = array( 'sql' => $deprecated_options[ 'sql' ] );
|
746 |
+
|
747 |
+
if ( isset( $deprecated_options[ 'search' ] ) )
|
748 |
+
$options[ 'searchable' ] = $deprecated_options[ 'search' ];
|
749 |
+
if ( isset( $deprecated_options[ 'search_across' ] ) )
|
750 |
+
$options[ 'search_across' ] = $deprecated_options[ 'search_across' ];
|
751 |
+
if ( isset( $deprecated_options[ 'search_across_picks' ] ) )
|
752 |
+
$options[ 'search_across_picks' ] = $deprecated_options[ 'search_across_picks' ];
|
753 |
+
if ( isset( $deprecated_options[ 'filters' ] ) )
|
754 |
+
$options[ 'filters' ] = $deprecated_options[ 'filters' ];
|
755 |
+
if ( isset( $deprecated_options[ 'custom_filters' ] ) ) {
|
756 |
+
if ( is_callable( $deprecated_options[ 'custom_filters' ] ) )
|
757 |
+
add_filter( 'pods_ui_filters', $deprecated_options[ 'custom_filters' ] );
|
758 |
+
else {
|
759 |
+
global $pods_ui_custom_filters;
|
760 |
+
$pods_ui_custom_filters = $deprecated_options[ 'custom_filters' ];
|
761 |
+
add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) );
|
762 |
+
}
|
763 |
+
}
|
764 |
+
|
765 |
+
if ( isset( $deprecated_options[ 'disable_actions' ] ) )
|
766 |
+
$options[ 'actions_disabled' ] = $deprecated_options[ 'disable_actions' ];
|
767 |
+
if ( isset( $deprecated_options[ 'hide_actions' ] ) )
|
768 |
+
$options[ 'actions_hidden' ] = $deprecated_options[ 'hide_actions' ];
|
769 |
+
|
770 |
+
if ( isset( $deprecated_options[ 'wpcss' ] ) )
|
771 |
+
$options[ 'wpcss' ] = $deprecated_options[ 'wpcss' ];
|
772 |
+
|
773 |
+
$remaining_options = array_diff_assoc( $options, $deprecated_options );
|
774 |
+
|
775 |
+
foreach ( $remaining_options as $option => $value ) {
|
776 |
+
if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) )
|
777 |
+
$options[ $option ] = $value;
|
778 |
+
}
|
779 |
+
|
780 |
+
return $options;
|
781 |
+
}
|
782 |
+
|
783 |
+
/**
|
784 |
+
*
|
785 |
+
*/
|
786 |
+
public function deprecated_filters () {
|
787 |
+
global $pods_ui_custom_filters;
|
788 |
+
echo $pods_ui_custom_filters;
|
789 |
+
}
|
790 |
+
|
791 |
+
/**
|
792 |
+
* @param $options
|
793 |
+
*
|
794 |
+
* @return array|bool|mixed|null|PodsArray
|
795 |
+
*/
|
796 |
+
public function setup ( $options ) {
|
797 |
+
$options = pods_array( $options );
|
798 |
+
|
799 |
+
$options->validate( 'num', '', 'absint' );
|
800 |
+
|
801 |
+
if ( empty( $options->num ) )
|
802 |
+
$options->num = '';
|
803 |
+
|
804 |
+
$options->validate( 'id', pods_var( 'id' . $options->num, 'get', $this->id ) );
|
805 |
+
|
806 |
+
$options->validate( 'do', pods_var( 'do' . $options->num, 'get', $this->do ), 'in_array', array(
|
807 |
+
'save',
|
808 |
+
'create'
|
809 |
+
) );
|
810 |
+
|
811 |
+
$options->validate( 'excluded', self::$excluded, 'array_merge' );
|
812 |
+
|
813 |
+
$options->validate( 'action', pods_var( 'action' . $options->num, 'get', $this->action, null, true ), 'in_array', $this->actions );
|
814 |
+
$options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' );
|
815 |
+
$options->validate( 'action_bulk', pods_var( 'action_bulk' . $options->num, 'get', $this->action_bulk, null, true ), 'isset', $this->actions_bulk );
|
816 |
+
|
817 |
+
$bulk = pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true );
|
818 |
+
|
819 |
+
if ( !empty( $bulk ) )
|
820 |
+
$bulk = (array) pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true );
|
821 |
+
else
|
822 |
+
$bulk = array();
|
823 |
+
|
824 |
+
$options->validate( 'bulk', $bulk, 'array_merge', $this->bulk );
|
825 |
+
|
826 |
+
$options->validate( 'views', $this->views, 'array' );
|
827 |
+
$options->validate( 'view', pods_var( 'view' . $options->num, 'get', $this->view, null, true ), 'isset', $this->views );
|
828 |
+
|
829 |
+
$options->validate( 'searchable', $this->searchable, 'boolean' );
|
830 |
+
$options->validate( 'search', pods_var( 'search' . $options->num, 'get' ) );
|
831 |
+
$options->validate( 'search_across', $this->search_across, 'boolean' );
|
832 |
+
$options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' );
|
833 |
+
$options->validate( 'filters', $this->filters, 'array' );
|
834 |
+
$options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' );
|
835 |
+
$options->validate( 'where', $this->where, 'array_merge' );
|
836 |
+
|
837 |
+
$options->validate( 'pagination', $this->pagination, 'boolean' );
|
838 |
+
$options->validate( 'page', pods_var( 'pg' . $options->num, 'get', $this->page ), 'absint' );
|
839 |
+
$options->validate( 'limit', pods_var( 'limit' . $options->num, 'get', $this->limit ), 'int' );
|
840 |
+
|
841 |
+
if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) {
|
842 |
+
$this->sql = array(
|
843 |
+
'table' => $this->pods_data->table,
|
844 |
+
'field_id' => $this->pods_data->field_id,
|
845 |
+
'field_index' => $this->pods_data->field_index
|
846 |
+
);
|
847 |
+
}
|
848 |
+
$options->validate( 'sql', $this->sql, 'array_merge' );
|
849 |
+
|
850 |
+
$options->validate( 'orderby_dir', strtoupper( pods_var_raw( 'orderby_dir' . $options[ 'num' ], 'get', $this->orderby_dir, null, true ) ), 'in_array', array( 'ASC', 'DESC' ) );
|
851 |
+
|
852 |
+
$orderby = $this->orderby;
|
853 |
+
|
854 |
+
// Enforce strict DB column name usage
|
855 |
+
if ( ! empty( $_GET[ 'orderby' . $options->num ] ) ) {
|
856 |
+
$orderby = pods_clean_name( $_GET[ 'orderby' . $options->num ], true, false );
|
857 |
+
}
|
858 |
+
|
859 |
+
if ( !empty( $orderby ) ) {
|
860 |
+
$orderby = array(
|
861 |
+
'default' => $orderby
|
862 |
+
);
|
863 |
+
}
|
864 |
+
else
|
865 |
+
$orderby = array();
|
866 |
+
|
867 |
+
$options->validate( 'orderby', $orderby, 'array_merge' );
|
868 |
+
$options->validate( 'sortable', $this->sortable, 'boolean' );
|
869 |
+
|
870 |
+
$options->validate( 'params', $this->params, 'array' );
|
871 |
+
|
872 |
+
$options->validate( 'restrict', $this->restrict, 'array_merge' );
|
873 |
+
|
874 |
+
// handle author restrictions
|
875 |
+
if ( !empty( $options[ 'restrict' ][ 'author_restrict' ] ) ) {
|
876 |
+
$restrict = $options[ 'restrict' ];
|
877 |
+
|
878 |
+
if ( !is_array( $restrict[ 'author_restrict' ] ) )
|
879 |
+
$restrict[ 'author_restrict' ] = array( $restrict[ 'author_restrict' ] => get_current_user_id() );
|
880 |
+
|
881 |
+
if ( null === $restrict[ 'edit' ] )
|
882 |
+
$restrict[ 'edit' ] = $restrict[ 'author_restrict' ];
|
883 |
+
|
884 |
+
$options->restrict = $restrict;
|
885 |
+
}
|
886 |
+
|
887 |
+
if ( null !== $options[ 'restrict' ][ 'edit' ] ) {
|
888 |
+
$restrict = $options[ 'restrict' ];
|
889 |
+
|
890 |
+
if ( null === $restrict[ 'duplicate' ] )
|
891 |
+
$restrict[ 'duplicate' ] = $restrict[ 'edit' ];
|
892 |
+
|
893 |
+
if ( null === $restrict[ 'delete' ] )
|
894 |
+
$restrict[ 'delete' ] = $restrict[ 'edit' ];
|
895 |
+
|
896 |
+
if ( null === $restrict[ 'manage' ] )
|
897 |
+
$restrict[ 'manage' ] = $restrict[ 'edit' ];
|
898 |
+
|
899 |
+
if ( null === $restrict[ 'reorder' ] )
|
900 |
+
$restrict[ 'reorder' ] = $restrict[ 'edit' ];
|
901 |
+
|
902 |
+
$options->restrict = $restrict;
|
903 |
+
}
|
904 |
+
|
905 |
+
$item = __( 'Item', 'pods' );
|
906 |
+
$items = __( 'Items', 'pods' );
|
907 |
+
|
908 |
+
if ( is_object( $this->pod ) ) {
|
909 |
+
$item = pods_var_raw( 'label_singular', $this->pod->pod_data[ 'options' ], pods_var_raw( 'label', $this->pod->pod_data, $item, null, true ), null, true );
|
910 |
+
$items = pods_var_raw( 'label', $this->pod->pod_data, $items, null, true );
|
911 |
+
}
|
912 |
+
|
913 |
+
$options->validate( 'item', $item );
|
914 |
+
$options->validate( 'items', $items );
|
915 |
+
|
916 |
+
$options->validate( 'heading', array(
|
917 |
+
'manage' => __( 'Manage', 'pods' ),
|
918 |
+
'add' => __( 'Add New', 'pods' ),
|
919 |
+
'edit' => __( 'Edit', 'pods' ),
|
920 |
+
'duplicate' => __( 'Duplicate', 'pods' ),
|
921 |
+
'view' => __( 'View', 'pods' ),
|
922 |
+
'reorder' => __( 'Reorder', 'pods' ),
|
923 |
+
'search' => __( 'Search', 'pods' ),
|
924 |
+
'views' => __( 'View', 'pods' )
|
925 |
+
), 'array_merge' );
|
926 |
+
|
927 |
+
$options->validate( 'header', array(
|
928 |
+
'manage' => sprintf( __( 'Manage %s', 'pods' ), $options->items ),
|
929 |
+
'add' => sprintf( __( 'Add New %s', 'pods' ), $options->item ),
|
930 |
+
'edit' => sprintf( __( 'Edit %s', 'pods' ), $options->item ),
|
931 |
+
'duplicate' => sprintf( __( 'Duplicate %s', 'pods' ), $options->item ),
|
932 |
+
'view' => sprintf( __( 'View %s', 'pods' ), $options->item ),
|
933 |
+
'reorder' => sprintf( __( 'Reorder %s', 'pods' ), $options->items ),
|
934 |
+
'search' => sprintf( __( 'Search %s', 'pods' ), $options->items )
|
935 |
+
), 'array_merge' );
|
936 |
+
|
937 |
+
$options->validate( 'label', array(
|
938 |
+
'add' => sprintf( __( 'Save New %s', 'pods' ), $options->item ),
|
939 |
+
'add_new' => __( 'Add New', 'pods' ),
|
940 |
+
'edit' => sprintf( __( 'Save %s', 'pods' ), $options->item ),
|
941 |
+
'duplicate' => sprintf( __( 'Save New %s', 'pods' ), $options->item ),
|
942 |
+
'delete' => sprintf( __( 'Delete this %s', 'pods' ), $options->item ),
|
943 |
+
'view' => sprintf( __( 'View %s', 'pods' ), $options->item ),
|
944 |
+
'reorder' => sprintf( __( 'Reorder %s', 'pods' ), $options->items )
|
945 |
+
), 'array_merge' );
|
946 |
+
|
947 |
+
$options->validate( 'fields', array(
|
948 |
+
'manage' => array(
|
949 |
+
$options->sql[ 'field_index' ] => array( 'label' => __( 'Name', 'pods' ) )
|
950 |
+
)
|
951 |
+
), 'array' );
|
952 |
+
|
953 |
+
$options->validate( 'export', $this->export, 'array_merge' );
|
954 |
+
$options->validate( 'reorder', $this->reorder, 'array_merge' );
|
955 |
+
$options->validate( 'screen_options', $this->screen_options, 'array_merge' );
|
956 |
+
|
957 |
+
$options->validate( 'session', $this->session, 'in_array', array(
|
958 |
+
'search',
|
959 |
+
'filters',
|
960 |
+
'show_per_page',
|
961 |
+
'orderby'
|
962 |
+
) );
|
963 |
+
$options->validate( 'user', $this->user, 'in_array', array(
|
964 |
+
'search',
|
965 |
+
'filters',
|
966 |
+
'show_per_page',
|
967 |
+
'orderby'
|
968 |
+
) );
|
969 |
+
|
970 |
+
$options->validate( 'action_after', $this->action_after, 'array_merge' );
|
971 |
+
$options->validate( 'action_links', $this->action_links, 'array_merge' );
|
972 |
+
$options->validate( 'actions_disabled', $this->actions_disabled, 'array' );
|
973 |
+
$options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' );
|
974 |
+
$options->validate( 'actions_custom', $this->actions_custom, 'array_merge' );
|
975 |
+
|
976 |
+
if ( !empty( $options->actions_disabled ) ) {
|
977 |
+
if ( !empty( $options->actions_bulk ) ) {
|
978 |
+
$actions_bulk = $options->actions_bulk;
|
979 |
+
|
980 |
+
foreach ( $actions_bulk as $action => $action_opt ) {
|
981 |
+
if ( in_array( $action, $options->actions_disabled ) ) {
|
982 |
+
unset( $actions_bulk[ $action ] );
|
983 |
+
}
|
984 |
+
}
|
985 |
+
|
986 |
+
$options->actions_bulk = $actions_bulk;
|
987 |
+
}
|
988 |
+
|
989 |
+
if ( !empty( $options->actions_custom ) ) {
|
990 |
+
$actions_custom = $options->actions_custom;
|
991 |
+
|
992 |
+
foreach ( $actions_custom as $action => $action_opt ) {
|
993 |
+
if ( in_array( $action, $options->actions_disabled ) ) {
|
994 |
+
unset( $actions_custom[ $action ] );
|
995 |
+
}
|
996 |
+
}
|
997 |
+
|
998 |
+
$options->actions_custom = $actions_custom;
|
999 |
+
}
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
$options->validate( 'extra', $this->extra, 'array_merge' );
|
1003 |
+
|
1004 |
+
$options->validate( 'style', $this->style );
|
1005 |
+
$options->validate( 'icon', $this->icon );
|
1006 |
+
$options->validate( 'css', $this->css );
|
1007 |
+
$options->validate( 'wpcss', $this->wpcss, 'boolean' );
|
1008 |
+
|
1009 |
+
if ( true === $options[ 'wpcss' ] ) {
|
1010 |
+
global $user_ID;
|
1011 |
+
get_currentuserinfo();
|
1012 |
+
|
1013 |
+
$color = get_user_meta( $user_ID, 'admin_color', true );
|
1014 |
+
if ( strlen( $color ) < 1 )
|
1015 |
+
$color = 'fresh';
|
1016 |
+
|
1017 |
+
$this->wpcss = "colors-{$color}";
|
1018 |
+
}
|
1019 |
+
|
1020 |
+
$options = $options->dump();
|
1021 |
+
|
1022 |
+
if ( is_object( $this->pod ) )
|
1023 |
+
$options = $this->do_hook( $this->pod->pod . '_setup_options', $options );
|
1024 |
+
|
1025 |
+
$options = $this->do_hook( 'setup_options', $options );
|
1026 |
+
|
1027 |
+
if ( false !== $options && !empty( $options ) ) {
|
1028 |
+
foreach ( $options as $option => $value ) {
|
1029 |
+
if ( isset( $this->{$option} ) )
|
1030 |
+
$this->{$option} = $value;
|
1031 |
+
else
|
1032 |
+
$this->x[ $option ] = $value;
|
1033 |
+
}
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
$unique_identifier = pods_var( 'page', 'get' ); // wp-admin page
|
1037 |
+
if ( is_object( $this->pod ) && isset( $this->pod->pod ) )
|
1038 |
+
$unique_identifier = '_' . $this->pod->pod;
|
1039 |
+
elseif ( 0 < strlen( $this->sql[ 'table' ] ) )
|
1040 |
+
$unique_identifier = '_' . $this->sql[ 'table' ];
|
1041 |
+
|
1042 |
+
$unique_identifier .= '_' . $this->page;
|
1043 |
+
if ( 0 < strlen( $this->num ) )
|
1044 |
+
$unique_identifier .= '_' . $this->num;
|
1045 |
+
|
1046 |
+
$this->unique_identifier = 'pods_ui_' . md5( $unique_identifier );
|
1047 |
+
|
1048 |
+
$this->setup_fields();
|
1049 |
+
|
1050 |
+
return $options;
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
/**
|
1054 |
+
* @param null $fields
|
1055 |
+
* @param string $which
|
1056 |
+
*
|
1057 |
+
* @return array|bool|mixed|null
|
1058 |
+
*/
|
1059 |
+
public function setup_fields ( $fields = null, $which = 'fields' ) {
|
1060 |
+
$init = false;
|
1061 |
+
if ( null === $fields ) {
|
1062 |
+
if ( isset( $this->fields[ $which ] ) )
|
1063 |
+
$fields = (array) $this->fields[ $which ];
|
1064 |
+
elseif ( isset( $this->fields[ 'manage' ] ) )
|
1065 |
+
$fields = (array) $this->fields[ 'manage' ];
|
1066 |
+
else
|
1067 |
+
$fields = array();
|
1068 |
+
if ( 'fields' == $which )
|
1069 |
+
$init = true;
|
1070 |
+
}
|
1071 |
+
if ( !empty( $fields ) ) {
|
1072 |
+
// Available Attributes
|
1073 |
+
// type = field type
|
1074 |
+
// type = date (data validation as date)
|
1075 |
+
// type = time (data validation as time)
|
1076 |
+
// type = datetime (data validation as datetime)
|
1077 |
+
// date_touch = use current timestamp when saving (even if readonly, if type is date-related)
|
1078 |
+
// date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related)
|
1079 |
+
// date_ongoing = use this additional field to search between as if the first is the "start" and the date_ongoing is the "end" for filter
|
1080 |
+
// type = text / other (single line text box)
|
1081 |
+
// type = desc (textarea)
|
1082 |
+
// type = number (data validation as int float)
|
1083 |
+
// type = decimal (data validation as decimal)
|
1084 |
+
// type = password (single line password box)
|
1085 |
+
// type = bool (checkbox)
|
1086 |
+
// type = related (select box)
|
1087 |
+
// related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items
|
1088 |
+
// related_field = field name on table to show (if type=related) - default "name"
|
1089 |
+
// related_multiple = true (ability to select multiple values if type=related)
|
1090 |
+
// related_sql = custom where / order by SQL (if type=related)
|
1091 |
+
// readonly = true (shows as text)
|
1092 |
+
// display = false (doesn't show on form, but can be saved)
|
1093 |
+
// search = this field is searchable
|
1094 |
+
// filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box)
|
1095 |
+
// comments = comments to show for field
|
1096 |
+
// comments_top = true (shows comments above field instead of below)
|
1097 |
+
// real_name = the real name of the field (if using an alias for 'name')
|
1098 |
+
// group_related = true (uses HAVING instead of WHERE for filtering field)
|
1099 |
+
$new_fields = array();
|
1100 |
+
$filterable = false;
|
1101 |
+
if ( empty( $this->filters ) && ( empty( $this->fields[ 'search' ] ) || 'search' == $which ) && false !== $this->searchable ) {
|
1102 |
+
$filterable = true;
|
1103 |
+
$this->filters = array();
|
1104 |
+
}
|
1105 |
+
|
1106 |
+
foreach ( $fields as $field => $attributes ) {
|
1107 |
+
if ( !is_array( $attributes ) ) {
|
1108 |
+
if ( is_int( $field ) ) {
|
1109 |
+
$field = $attributes;
|
1110 |
+
$attributes = array();
|
1111 |
+
}
|
1112 |
+
else
|
1113 |
+
$attributes = array( 'label' => $attributes );
|
1114 |
+
}
|
1115 |
+
|
1116 |
+
if ( !isset( $attributes[ 'real_name' ] ) )
|
1117 |
+
$attributes[ 'real_name' ] = pods_var( 'name', $attributes, $field );
|
1118 |
+
|
1119 |
+
if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes[ 'real_name' ] ] ) )
|
1120 |
+
$attributes = array_merge( $this->pod->fields[ $attributes[ 'real_name' ] ], $attributes );
|
1121 |
+
|
1122 |
+
if ( !isset( $attributes[ 'options' ] ) )
|
1123 |
+
$attributes[ 'options' ] = array();
|
1124 |
+
if ( !isset( $attributes[ 'id' ] ) )
|
1125 |
+
$attributes[ 'id' ] = '';
|
1126 |
+
if ( !isset( $attributes[ 'label' ] ) )
|
1127 |
+
$attributes[ 'label' ] = ucwords( str_replace( '_', ' ', $field ) );
|
1128 |
+
if ( !isset( $attributes[ 'type' ] ) )
|
1129 |
+
$attributes[ 'type' ] = 'text';
|
1130 |
+
if ( !isset( $attributes[ 'options' ][ 'date_format_type' ] ) )
|
1131 |
+
$attributes[ 'options' ][ 'date_format_type' ] = 'date';
|
1132 |
+
if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related' ] ) )
|
1133 |
+
$attributes[ 'related' ] = false;
|
1134 |
+
if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_id' ] ) )
|
1135 |
+
$attributes[ 'related_id' ] = 'id';
|
1136 |
+
if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_field' ] ) )
|
1137 |
+
$attributes[ 'related_field' ] = 'name';
|
1138 |
+
if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_multiple' ] ) )
|
1139 |
+
$attributes[ 'related_multiple' ] = false;
|
1140 |
+
if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_sql' ] ) )
|
1141 |
+
$attributes[ 'related_sql' ] = false;
|
1142 |
+
if ( 'related' == $attributes[ 'type' ] && ( is_array( $attributes[ 'related' ] ) || strpos( $attributes[ 'related' ], ',' ) ) ) {
|
1143 |
+
if ( !is_array( $attributes[ 'related' ] ) ) {
|
1144 |
+
$attributes[ 'related' ] = @explode( ',', $attributes[ 'related' ] );
|
1145 |
+
$related_items = array();
|
1146 |
+
foreach ( $attributes[ 'related' ] as $key => $label ) {
|
1147 |
+
if ( is_numeric( $key ) ) {
|
1148 |
+
$key = $label;
|
1149 |
+
$label = ucwords( str_replace( '_', ' ', $label ) );
|
1150 |
+
}
|
1151 |
+
$related_items[ $key ] = $label;
|
1152 |
+
}
|
1153 |
+
$attributes[ 'related' ] = $related_items;
|
1154 |
+
}
|
1155 |
+
if ( empty( $attributes[ 'related' ] ) )
|
1156 |
+
$attributes[ 'related' ] = false;
|
1157 |
+
}
|
1158 |
+
if ( !isset( $attributes[ 'readonly' ] ) )
|
1159 |
+
$attributes[ 'readonly' ] = false;
|
1160 |
+
if ( !isset( $attributes[ 'date_touch' ] ) || 'date' != $attributes[ 'type' ] )
|
1161 |
+
$attributes[ 'date_touch' ] = false;
|
1162 |
+
if ( !isset( $attributes[ 'date_touch_on_create' ] ) || 'date' != $attributes[ 'type' ] )
|
1163 |
+
$attributes[ 'date_touch_on_create' ] = false;
|
1164 |
+
if ( !isset( $attributes[ 'display' ] ) )
|
1165 |
+
$attributes[ 'display' ] = true;
|
1166 |
+
if ( !isset( $attributes[ 'hidden' ] ) )
|
1167 |
+
$attributes[ 'hidden' ] = false;
|
1168 |
+
if ( !isset( $attributes[ 'sortable' ] ) || false === $this->sortable )
|
1169 |
+
$attributes[ 'sortable' ] = $this->sortable;
|
1170 |
+
if ( !isset( $attributes[ 'options' ][ 'search' ] ) || false === $this->searchable )
|
1171 |
+
$attributes[ 'options' ][ 'search' ] = $this->searchable;
|
1172 |
+
if ( !isset( $attributes[ 'options' ][ 'filter' ] ) || false === $this->searchable )
|
1173 |
+
$attributes[ 'options' ][ 'filter' ] = $this->searchable;
|
1174 |
+
/*if ( false !== $attributes[ 'options' ][ 'filter' ] && false !== $filterable )
|
1175 |
+
$this->filters[] = $field;*/
|
1176 |
+
if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_label' ] ) || !in_array( $field, $this->filters ) )
|
1177 |
+
$attributes[ 'filter_label' ] = $attributes[ 'label' ];
|
1178 |
+
if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_default' ] ) || !in_array( $field, $this->filters ) )
|
1179 |
+
$attributes[ 'filter_default' ] = false;
|
1180 |
+
if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !in_array( $field, $this->filters ) )
|
1181 |
+
$attributes[ 'date_ongoing' ] = false;
|
1182 |
+
if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !isset( $attributes[ 'date_ongoing_default' ] ) || !in_array( $field, $this->filters ) )
|
1183 |
+
$attributes[ 'date_ongoing_default' ] = false;
|
1184 |
+
if ( !isset( $attributes[ 'export' ] ) )
|
1185 |
+
$attributes[ 'export' ] = true;
|
1186 |
+
if ( !isset( $attributes[ 'group_related' ] ) )
|
1187 |
+
$attributes[ 'group_related' ] = false;
|
1188 |
+
if ( !isset( $attributes[ 'comments' ] ) )
|
1189 |
+
$attributes[ 'comments' ] = '';
|
1190 |
+
if ( !isset( $attributes[ 'comments_top' ] ) )
|
1191 |
+
$attributes[ 'comments_top' ] = false;
|
1192 |
+
if ( !isset( $attributes[ 'custom_view' ] ) )
|
1193 |
+
$attributes[ 'custom_view' ] = false;
|
1194 |
+
if ( !isset( $attributes[ 'custom_input' ] ) )
|
1195 |
+
$attributes[ 'custom_input' ] = false;
|
1196 |
+
if ( isset( $attributes[ 'display_helper' ] ) ) // pods ui backward compatibility
|
1197 |
+
$attributes[ 'custom_display' ] = $attributes[ 'display_helper' ];
|
1198 |
+
if ( !isset( $attributes[ 'custom_display' ] ) )
|
1199 |
+
$attributes[ 'custom_display' ] = false;
|
1200 |
+
if ( !isset( $attributes[ 'custom_relate' ] ) )
|
1201 |
+
$attributes[ 'custom_relate' ] = false;
|
1202 |
+
if ( !isset( $attributes[ 'custom_form_display' ] ) )
|
1203 |
+
$attributes[ 'custom_form_display' ] = false;
|
1204 |
+
if ( !isset( $attributes[ 'css_values' ] ) )
|
1205 |
+
$attributes[ 'css_values' ] = true;
|
1206 |
+
if ( 'search_columns' == $which && !$attributes[ 'options' ][ 'search' ] )
|
1207 |
+
continue;
|
1208 |
+
|
1209 |
+
$attributes = PodsForm::field_setup( $attributes, null, $attributes[ 'type' ] );
|
1210 |
+
|
1211 |
+
$new_fields[ $field ] = $attributes;
|
1212 |
+
}
|
1213 |
+
$fields = $new_fields;
|
1214 |
+
}
|
1215 |
+
if ( false !== $init ) {
|
1216 |
+
if ( 'fields' != $which && !empty( $this->fields ) )
|
1217 |
+
$this->fields = $this->setup_fields( $this->fields, 'fields' );
|
1218 |
+
else
|
1219 |
+
$this->fields[ 'manage' ] = $fields;
|
1220 |
+
|
1221 |
+
if ( !in_array( 'add', $this->actions_disabled ) || !in_array( 'edit', $this->actions_disabled ) || !in_array( 'duplicate', $this->actions_disabled ) ) {
|
1222 |
+
if ( 'form' != $which && isset( $this->fields[ 'form' ] ) && is_array( $this->fields[ 'form' ] ) )
|
1223 |
+
$this->fields[ 'form' ] = $this->setup_fields( $this->fields[ 'form' ], 'form' );
|
1224 |
+
else
|
1225 |
+
$this->fields[ 'form' ] = $fields;
|
1226 |
+
|
1227 |
+
if ( !in_array( 'add', $this->actions_disabled ) ) {
|
1228 |
+
if ( 'add' != $which && isset( $this->fields[ 'add' ] ) && is_array( $this->fields[ 'add' ] ) )
|
1229 |
+
$this->fields[ 'add' ] = $this->setup_fields( $this->fields[ 'add' ], 'add' );
|
1230 |
+
}
|
1231 |
+
if ( !in_array( 'edit', $this->actions_disabled ) ) {
|
1232 |
+
if ( 'edit' != $which && isset( $this->fields[ 'edit' ] ) && is_array( $this->fields[ 'edit' ] ) )
|
1233 |
+
$this->fields[ 'edit' ] = $this->setup_fields( $this->fields[ 'edit' ], 'edit' );
|
1234 |
+
}
|
1235 |
+
if ( !in_array( 'duplicate', $this->actions_disabled ) ) {
|
1236 |
+
if ( 'duplicate' != $which && isset( $this->fields[ 'duplicate' ] ) && is_array( $this->fields[ 'duplicate' ] ) )
|
1237 |
+
$this->fields[ 'duplicate' ] = $this->setup_fields( $this->fields[ 'duplicate' ], 'duplicate' );
|
1238 |
+
}
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
if ( false !== $this->searchable ) {
|
1242 |
+
if ( 'search' != $which && isset( $this->fields[ 'search' ] ) &&!empty( $this->fields[ 'search' ] ) )
|
1243 |
+
$this->fields[ 'search' ] = $this->setup_fields( $this->fields[ 'search' ], 'search' );
|
1244 |
+
else
|
1245 |
+
$this->fields[ 'search' ] = $fields;
|
1246 |
+
}
|
1247 |
+
else
|
1248 |
+
$this->fields[ 'search' ] = false;
|
1249 |
+
|
1250 |
+
if ( !in_array( 'export', $this->actions_disabled ) ) {
|
1251 |
+
if ( 'export' != $which && isset( $this->fields[ 'export' ] ) &&!empty( $this->fields[ 'export' ] ) )
|
1252 |
+
$this->fields[ 'export' ] = $this->setup_fields( $this->fields[ 'export' ], 'export' );
|
1253 |
+
}
|
1254 |
+
|
1255 |
+
if ( !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
|
1256 |
+
if ( 'reorder' != $which && isset( $this->fields[ 'reorder' ] ) &&!empty( $this->fields[ 'reorder' ] ) )
|
1257 |
+
$this->fields[ 'reorder' ] = $this->setup_fields( $this->fields[ 'reorder' ], 'reorder' );
|
1258 |
+
else
|
1259 |
+
$this->fields[ 'reorder' ] = $fields;
|
1260 |
+
}
|
1261 |
+
}
|
1262 |
+
return $this->do_hook( 'setup_fields', $fields, $which, $init );
|
1263 |
+
}
|
1264 |
+
|
1265 |
+
/**
|
1266 |
+
* @param $msg
|
1267 |
+
* @param bool $error
|
1268 |
+
*/
|
1269 |
+
public function message ( $msg, $error = false ) {
|
1270 |
+
$msg = $this->do_hook( ( $error ) ? 'error' : 'message', $msg );
|
1271 |
+
?>
|
1272 |
+
<div id="message" class="<?php echo ( $error ) ? 'error' : 'updated'; ?> fade"><p><?php echo $msg; ?></p></div>
|
1273 |
+
<?php
|
1274 |
+
}
|
1275 |
+
|
1276 |
+
/**
|
1277 |
+
* @param $msg
|
1278 |
+
*
|
1279 |
+
* @return bool
|
1280 |
+
*/
|
1281 |
+
public function error ( $msg ) {
|
1282 |
+
$this->message( $msg, true );
|
1283 |
+
|
1284 |
+
return false;
|
1285 |
+
}
|
1286 |
+
|
1287 |
+
/**
|
1288 |
+
* @return mixed
|
1289 |
+
*/
|
1290 |
+
public function go () {
|
1291 |
+
$this->do_hook( 'go' );
|
1292 |
+
$_GET = pods_unsanitize( $_GET ); // fix wp sanitization
|
1293 |
+
$_POST = pods_unsanitize( $_POST ); // fix wp sanitization
|
1294 |
+
|
1295 |
+
if ( false !== $this->css ) {
|
1296 |
+
?>
|
1297 |
+
<link type="text/css" rel="stylesheet" href="<?php echo $this->css; ?>" />
|
1298 |
+
<?php
|
1299 |
+
}
|
1300 |
+
if ( false !== $this->wpcss ) {
|
1301 |
+
$stylesheets = array( 'global', 'wp-admin', $this->wpcss );
|
1302 |
+
foreach ( $stylesheets as $style ) {
|
1303 |
+
if ( !wp_style_is( $style, 'queue' ) && !wp_style_is( $style, 'to_do' ) && !wp_style_is( $style, 'done' ) )
|
1304 |
+
wp_enqueue_style( $style );
|
1305 |
+
}
|
1306 |
+
}
|
1307 |
+
|
1308 |
+
$this->ui_page = array( $this->action );
|
1309 |
+
if ( 'add' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
|
1310 |
+
$this->ui_page[] = 'form';
|
1311 |
+
if ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
|
1312 |
+
$this->ui_page[] = $this->do;
|
1313 |
+
$this->save( true );
|
1314 |
+
$this->manage();
|
1315 |
+
}
|
1316 |
+
else
|
1317 |
+
$this->add();
|
1318 |
+
}
|
1319 |
+
elseif ( ( 'edit' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ) {
|
1320 |
+
$this->ui_page[] = 'form';
|
1321 |
+
if ( 'save' == $this->do && $this->save && !empty( $_POST ) )
|
1322 |
+
$this->save();
|
1323 |
+
$this->edit( ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ? true : false );
|
1324 |
+
}
|
1325 |
+
elseif ( 'delete' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
|
1326 |
+
$this->delete( $this->id );
|
1327 |
+
$this->manage();
|
1328 |
+
}
|
1329 |
+
elseif ( 'reorder' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
|
1330 |
+
if ( 'save' == $this->do ) {
|
1331 |
+
$this->ui_page[] = $this->do;
|
1332 |
+
$this->reorder();
|
1333 |
+
}
|
1334 |
+
$this->manage( true );
|
1335 |
+
}
|
1336 |
+
elseif ( 'save' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
|
1337 |
+
$this->ui_page[] = $this->do;
|
1338 |
+
$this->save();
|
1339 |
+
$this->manage();
|
1340 |
+
}
|
1341 |
+
elseif ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
|
1342 |
+
$this->ui_page[] = $this->do;
|
1343 |
+
$this->save( true );
|
1344 |
+
$this->manage();
|
1345 |
+
}
|
1346 |
+
elseif ( 'view' == $this->action && !in_array( $this->action, $this->actions_disabled ) )
|
1347 |
+
$this->view();
|
1348 |
+
else {
|
1349 |
+
if ( isset( $this->actions_custom[ $this->action ] ) ) {
|
1350 |
+
$more_args = false;
|
1351 |
+
|
1352 |
+
if ( is_array( $this->actions_custom[ $this->action ] ) && isset( $this->actions_custom[ $this->action ][ 'more_args' ] ) ) {
|
1353 |
+
$more_args = $this->actions_custom[ $this->action ][ 'more_args' ];
|
1354 |
+
}
|
1355 |
+
|
1356 |
+
$row = $this->row;
|
1357 |
+
|
1358 |
+
if ( empty( $row ) ) {
|
1359 |
+
$row = $this->get_row();
|
1360 |
+
}
|
1361 |
+
|
1362 |
+
if ( $this->restricted( $this->action, $row ) ) {
|
1363 |
+
return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
|
1364 |
+
}
|
1365 |
+
elseif ( $more_args && false !== $this->callback_action( true, $this->action, $this->id, $row ) ) {
|
1366 |
+
return null;
|
1367 |
+
}
|
1368 |
+
elseif ( false !== $this->callback_action( true, $this->action, $this->id ) ) {
|
1369 |
+
return null;
|
1370 |
+
}
|
1371 |
+
}
|
1372 |
+
|
1373 |
+
if ( !in_array( 'manage', $this->actions_disabled ) ) {
|
1374 |
+
// handle session / user persistent settings for show_per_page, orderby, search, and filters
|
1375 |
+
$methods = array( 'session', 'user' );
|
1376 |
+
|
1377 |
+
// @todo fix this to set ($this) AND save (setting)
|
1378 |
+
foreach ( $methods as $method ) {
|
1379 |
+
foreach ( $this->$method as $setting ) {
|
1380 |
+
if ( 'show_per_page' == $setting )
|
1381 |
+
$value = $this->limit;
|
1382 |
+
elseif ( 'orderby' == $setting ) {
|
1383 |
+
if ( empty( $this->orderby ) )
|
1384 |
+
$value = '';
|
1385 |
+
// save this if we have a default index set
|
1386 |
+
elseif ( isset( $this->orderby[ 'default' ] ) ) {
|
1387 |
+
$value = $this->orderby[ 'default' ] . ' '
|
1388 |
+
. ( false === strpos( $this->orderby[ 'default' ], ' ' ) ? $this->orderby_dir : '' );
|
1389 |
+
}
|
1390 |
+
else
|
1391 |
+
$value = '';
|
1392 |
+
}
|
1393 |
+
else
|
1394 |
+
$value = $this->$setting;
|
1395 |
+
|
1396 |
+
pods_var_set( $value, $setting, $method );
|
1397 |
+
}
|
1398 |
+
}
|
1399 |
+
|
1400 |
+
$this->manage();
|
1401 |
+
}
|
1402 |
+
}
|
1403 |
+
}
|
1404 |
+
|
1405 |
+
/**
|
1406 |
+
* @return mixed
|
1407 |
+
*/
|
1408 |
+
public function add () {
|
1409 |
+
if ( false !== $this->callback_action( 'add' ) ) {
|
1410 |
+
return null;
|
1411 |
+
}
|
1412 |
+
?>
|
1413 |
+
<div class="wrap pods-ui">
|
1414 |
+
<div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo $this->icon; ?>);"<?php } ?>><br /></div>
|
1415 |
+
<h2>
|
1416 |
+
<?php
|
1417 |
+
echo $this->header[ 'add' ];
|
1418 |
+
|
1419 |
+
$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
|
1420 |
+
|
1421 |
+
if ( !empty( $this->action_links[ 'manage' ] ) ) {
|
1422 |
+
$link = $this->action_links[ 'manage' ];
|
1423 |
+
}
|
1424 |
+
?>
|
1425 |
+
<a href="<?php echo $link; ?>" class="add-new-h2">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
|
1426 |
+
</h2>
|
1427 |
+
|
1428 |
+
<?php $this->form( true ); ?>
|
1429 |
+
</div>
|
1430 |
+
<?php
|
1431 |
+
}
|
1432 |
+
|
1433 |
+
/**
|
1434 |
+
* @param bool $duplicate
|
1435 |
+
*
|
1436 |
+
* @return mixed
|
1437 |
+
*/
|
1438 |
+
public function edit ( $duplicate = false ) {
|
1439 |
+
if ( in_array( 'duplicate', $this->actions_disabled ) )
|
1440 |
+
$duplicate = false;
|
1441 |
+
|
1442 |
+
if ( empty( $this->row ) )
|
1443 |
+
$this->get_row();
|
1444 |
+
|
1445 |
+
if ( $duplicate && false !== $this->callback_action( 'duplicate' ) ) {
|
1446 |
+
return null;
|
1447 |
+
}
|
1448 |
+
elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) {
|
1449 |
+
return null;
|
1450 |
+
}
|
1451 |
+
?>
|
1452 |
+
<div class="wrap pods-ui">
|
1453 |
+
<div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo $this->icon; ?>);"<?php } ?>><br /></div>
|
1454 |
+
<h2>
|
1455 |
+
<?php
|
1456 |
+
echo $this->do_template( $duplicate ? $this->header[ 'duplicate' ] : $this->header[ 'edit' ] );
|
1457 |
+
|
1458 |
+
if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
|
1459 |
+
$link = pods_var_update( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
|
1460 |
+
|
1461 |
+
if ( !empty( $this->action_links[ 'add' ] ) )
|
1462 |
+
$link = $this->action_links[ 'add' ];
|
1463 |
+
?>
|
1464 |
+
<a href="<?php echo $link; ?>" class="add-new-h2"><?php echo $this->heading[ 'add' ]; ?></a>
|
1465 |
+
<?php
|
1466 |
+
}
|
1467 |
+
elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
|
1468 |
+
$link = pods_var_update( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
|
1469 |
+
|
1470 |
+
if ( !empty( $this->action_links[ 'manage' ] ) )
|
1471 |
+
$link = $this->action_links[ 'manage' ];
|
1472 |
+
?>
|
1473 |
+
<a href="<?php echo $link; ?>" class="add-new-h2">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
|
1474 |
+
<?php
|
1475 |
+
}
|
1476 |
+
?>
|
1477 |
+
</h2>
|
1478 |
+
|
1479 |
+
<?php $this->form( false, $duplicate ); ?>
|
1480 |
+
</div>
|
1481 |
+
<?php
|
1482 |
+
}
|
1483 |
+
|
1484 |
+
/**
|
1485 |
+
* @param bool $create
|
1486 |
+
* @param bool $duplicate
|
1487 |
+
*
|
1488 |
+
* @return bool|mixed
|
1489 |
+
*/
|
1490 |
+
public function form ( $create = false, $duplicate = false ) {
|
1491 |
+
if ( in_array( 'duplicate', $this->actions_disabled ) )
|
1492 |
+
$duplicate = false;
|
1493 |
+
|
1494 |
+
if ( false !== $this->callback( 'form' ) ) {
|
1495 |
+
return null;
|
1496 |
+
}
|
1497 |
+
|
1498 |
+
$label = $this->label[ 'add' ];
|
1499 |
+
$id = null;
|
1500 |
+
$vars = array(
|
1501 |
+
'action' . $this->num => $this->action_after[ 'add' ],
|
1502 |
+
'do' . $this->num => 'create',
|
1503 |
+
'id' . $this->num => 'X_ID_X'
|
1504 |
+
);
|
1505 |
+
|
1506 |
+
$alt_vars = $vars;
|
1507 |
+
$alt_vars[ 'action' ] = 'manage';
|
1508 |
+
unset( $alt_vars[ 'id' ] );
|
1509 |
+
|
1510 |
+
if ( false === $create ) {
|
1511 |
+
if ( empty( $this->row ) )
|
1512 |
+
$this->get_row();
|
1513 |
+
|
1514 |
+
if ( empty( $this->row ) && ( !is_object( $this->pod ) || 'settings' != $this->pod->pod_data[ 'type' ] ) )
|
1515 |
+
return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
|
1516 |
+
|
1517 |
+
if ( $this->restricted( $this->action, $this->row ) )
|
1518 |
+
return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
|
1519 |
+
|
1520 |
+
$label = $this->do_template( $this->label[ 'edit' ] );
|
1521 |
+
$id = $this->row[ $this->sql[ 'field_id' ] ];
|
1522 |
+
$vars = array(
|
1523 |
+
'action' . $this->num => $this->action_after[ 'edit' ],
|
1524 |
+
'do' . $this->num => 'save',
|
1525 |
+
'id' . $this->num => $id
|
1526 |
+
);
|
1527 |
+
|
1528 |
+
$alt_vars = $vars;
|
1529 |
+
$alt_vars[ 'action' ] = 'manage';
|
1530 |
+
unset( $alt_vars[ 'id' ] );
|
1531 |
+
|
1532 |
+
if ( $duplicate ) {
|
1533 |
+
$label = $this->do_template( $this->label[ 'duplicate' ] );
|
1534 |
+
$id = null;
|
1535 |
+
$vars = array(
|
1536 |
+
'action' . $this->num => $this->action_after[ 'duplicate' ],
|
1537 |
+
'do' . $this->num => 'create',
|
1538 |
+
'id' . $this->num => 'X_ID_X'
|
1539 |
+
);
|
1540 |
+
|
1541 |
+
$alt_vars = $vars;
|
1542 |
+
$alt_vars[ 'action' ] = 'manage';
|
1543 |
+
unset( $alt_vars[ 'id' ] );
|
1544 |
+
}
|
1545 |
+
}
|
1546 |
+
|
1547 |
+
$fields = array();
|
1548 |
+
|
1549 |
+
if ( isset( $this->fields[ $this->action ] ) )
|
1550 |
+
$fields = $this->fields[ $this->action ];
|
1551 |
+
|
1552 |
+
if ( is_object( $this->pod ) ) {
|
1553 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
|
1554 |
+
|
1555 |
+
if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], array( 'post_type', 'taxonomy', 'media', 'user', 'comment' ) ) )
|
1556 |
+
$object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data );
|
1557 |
+
|
1558 |
+
if ( empty( $fields ) ) {
|
1559 |
+
// Add core object fields if $fields is empty
|
1560 |
+
$fields = array_merge( $object_fields, $this->pod->fields );
|
1561 |
+
}
|
1562 |
+
}
|
1563 |
+
|
1564 |
+
$form_fields = $fields; // Temporary
|
1565 |
+
|
1566 |
+
$fields = array();
|
1567 |
+
|
1568 |
+
foreach ( $form_fields as $k => $field ) {
|
1569 |
+
$name = $k;
|
1570 |
+
|
1571 |
+
$defaults = array(
|
1572 |
+
'name' => $name
|
1573 |
+
);
|
1574 |
+
|
1575 |
+
if ( !is_array( $field ) ) {
|
1576 |
+
$name = $field;
|
1577 |
+
|
1578 |
+
$field = array(
|
1579 |
+
'name' => $name
|
1580 |
+
);
|
1581 |
+
}
|
1582 |
+
|
1583 |
+
$field = array_merge( $defaults, $field );
|
1584 |
+
|
1585 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
1586 |
+
|
1587 |
+
$default_value = pods_var_raw( 'default', $field );
|
1588 |
+
$value = pods_var_raw( 'value', $field );
|
1589 |
+
|
1590 |
+
if ( empty( $field[ 'name' ] ) )
|
1591 |
+
$field[ 'name' ] = trim( $name );
|
1592 |
+
|
1593 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) )
|
1594 |
+
$field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
|
1595 |
+
elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) )
|
1596 |
+
$field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field );
|
1597 |
+
|
1598 |
+
if ( pods_var_raw( 'hidden', $field, false, null, true ) )
|
1599 |
+
$field[ 'type' ] = 'hidden';
|
1600 |
+
|
1601 |
+
$fields[ $field[ 'name' ] ] = $field;
|
1602 |
+
|
1603 |
+
if ( empty( $this->id ) && null !== $default_value ) {
|
1604 |
+
$this->pod->row_override[ $field[ 'name' ] ] = $default_value;
|
1605 |
+
}
|
1606 |
+
elseif ( !empty( $this->id ) && null !== $value ) {
|
1607 |
+
$this->pod->row[ $field[ 'name' ] ] = $value;
|
1608 |
+
}
|
1609 |
+
}
|
1610 |
+
|
1611 |
+
unset( $form_fields ); // Cleanup
|
1612 |
+
|
1613 |
+
$fields = $this->do_hook( 'form_fields', $fields, $this->pod );
|
1614 |
+
|
1615 |
+
$pod =& $this->pod;
|
1616 |
+
$thank_you = pods_var_update( $vars, self::$allowed, $this->exclusion() );
|
1617 |
+
$thank_you_alt = pods_var_update( $alt_vars, self::$allowed, $this->exclusion() );
|
1618 |
+
$obj =& $this;
|
1619 |
+
$singular_label = $this->item;
|
1620 |
+
$plural_label = $this->items;
|
1621 |
+
|
1622 |
+
if ( is_object( $this->pod ) && 'settings' == $this->pod->pod_data[ 'type' ] && 'settings' == $this->style )
|
1623 |
+
pods_view( PODS_DIR . 'ui/admin/form-settings.php', compact( array_keys( get_defined_vars() ) ) );
|
1624 |
+
else
|
1625 |
+
pods_view( PODS_DIR . 'ui/admin/form.php', compact( array_keys( get_defined_vars() ) ) );
|
1626 |
+
}
|
1627 |
+
|
1628 |
+
/**
|
1629 |
+
* @return bool|mixed
|
1630 |
+
* @since 2.3.10
|
1631 |
+
*/
|
1632 |
+
public function view () {
|
1633 |
+
|
1634 |
+
if ( false !== $this->callback_action( 'view' ) ) {
|
1635 |
+
return null;
|
1636 |
+
}
|
1637 |
+
|
1638 |
+
if ( empty( $this->row ) ) {
|
1639 |
+
$this->get_row();
|
1640 |
+
}
|
1641 |
+
|
1642 |
+
if ( empty( $this->row ) ) {
|
1643 |
+
return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
|
1644 |
+
}
|
1645 |
+
|
1646 |
+
$pod =& $this->pod;
|
1647 |
+
|
1648 |
+
$fields = array();
|
1649 |
+
|
1650 |
+
if ( isset( $this->fields[ $this->action ] ) ) {
|
1651 |
+
$fields = $this->fields[ $this->action ];
|
1652 |
+
}
|
1653 |
+
|
1654 |
+
if ( is_object( $this->pod ) ) {
|
1655 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
|
1656 |
+
|
1657 |
+
$object_field_objects = array(
|
1658 |
+
'post_type',
|
1659 |
+
'taxonomy',
|
1660 |
+
'media',
|
1661 |
+
'user',
|
1662 |
+
'comment'
|
1663 |
+
);
|
1664 |
+
|
1665 |
+
if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], $object_field_objects ) ) {
|
1666 |
+
$object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data );
|
1667 |
+
}
|
1668 |
+
|
1669 |
+
if ( empty( $fields ) ) {
|
1670 |
+
// Add core object fields if $fields is empty
|
1671 |
+
$fields = array_merge( $object_fields, $this->pod->fields );
|
1672 |
+
}
|
1673 |
+
}
|
1674 |
+
|
1675 |
+
$view_fields = $fields; // Temporary
|
1676 |
+
|
1677 |
+
$fields = array();
|
1678 |
+
|
1679 |
+
foreach ( $view_fields as $k => $field ) {
|
1680 |
+
$name = $k;
|
1681 |
+
|
1682 |
+
$defaults = array(
|
1683 |
+
'name' => $name,
|
1684 |
+
'type' => 'text',
|
1685 |
+
'options' => 'text'
|
1686 |
+
);
|
1687 |
+
|
1688 |
+
if ( !is_array( $field ) ) {
|
1689 |
+
$name = $field;
|
1690 |
+
|
1691 |
+
$field = array(
|
1692 |
+
'name' => $name
|
1693 |
+
);
|
1694 |
+
}
|
1695 |
+
|
1696 |
+
$field = array_merge( $defaults, $field );
|
1697 |
+
|
1698 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
1699 |
+
|
1700 |
+
$value = pods_var_raw( 'default', $field );
|
1701 |
+
|
1702 |
+
if ( empty( $field[ 'name' ] ) ) {
|
1703 |
+
$field[ 'name' ] = trim( $name );
|
1704 |
+
}
|
1705 |
+
|
1706 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
|
1707 |
+
$field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
|
1708 |
+
}
|
1709 |
+
elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) ) {
|
1710 |
+
$field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field );
|
1711 |
+
}
|
1712 |
+
|
1713 |
+
if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' == $field[ 'type' ] ) {
|
1714 |
+
continue;
|
1715 |
+
}
|
1716 |
+
elseif ( !PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
|
1717 |
+
continue;
|
1718 |
+
}
|
1719 |
+
|
1720 |
+
$fields[ $field[ 'name' ] ] = $field;
|
1721 |
+
|
1722 |
+
if ( empty( $this->id ) && null !== $value ) {
|
1723 |
+
$this->pod->row_override[ $field[ 'name' ] ] = $value;
|
1724 |
+
}
|
1725 |
+
}
|
1726 |
+
|
1727 |
+
unset( $view_fields ); // Cleanup
|
1728 |
+
?>
|
1729 |
+
<div class="wrap pods-ui">
|
1730 |
+
<div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo $this->icon; ?>);"<?php } ?>><br /></div>
|
1731 |
+
<h2>
|
1732 |
+
<?php
|
1733 |
+
echo $this->do_template( $this->header[ 'view' ] );
|
1734 |
+
|
1735 |
+
if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
|
1736 |
+
$link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
|
1737 |
+
|
1738 |
+
if ( !empty( $this->action_links[ 'add' ] ) ) {
|
1739 |
+
$link = $this->action_links[ 'add' ];
|
1740 |
+
}
|
1741 |
+
?>
|
1742 |
+
<a href="<?php echo $link; ?>" class="add-new-h2"><?php echo $this->heading[ 'add' ]; ?></a>
|
1743 |
+
<?php
|
1744 |
+
}
|
1745 |
+
elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
|
1746 |
+
$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
|
1747 |
+
|
1748 |
+
if ( !empty( $this->action_links[ 'manage' ] ) ) {
|
1749 |
+
$link = $this->action_links[ 'manage' ];
|
1750 |
+
}
|
1751 |
+
?>
|
1752 |
+
<a href="<?php echo $link; ?>" class="add-new-h2">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
|
1753 |
+
<?php
|
1754 |
+
}
|
1755 |
+
|
1756 |
+
pods_view( PODS_DIR . 'ui/admin/view.php', compact( array_keys( get_defined_vars() ) ) );
|
1757 |
+
?>
|
1758 |
+
|
1759 |
+
</h2>
|
1760 |
+
</div>
|
1761 |
+
<?php
|
1762 |
+
}
|
1763 |
+
|
1764 |
+
|
1765 |
+
/**
|
1766 |
+
* Reorder data
|
1767 |
+
*/
|
1768 |
+
public function reorder () {
|
1769 |
+
// loop through order
|
1770 |
+
$order = (array) pods_var_raw( 'order', 'post', array(), null, true );
|
1771 |
+
|
1772 |
+
$params = array(
|
1773 |
+
'pod' => $this->pod->pod,
|
1774 |
+
'field' => $this->reorder[ 'on' ],
|
1775 |
+
'order' => $order
|
1776 |
+
);
|
1777 |
+
|
1778 |
+
$reorder = pods_api()->reorder_pod_item( $params );
|
1779 |
+
|
1780 |
+
if ( $reorder )
|
1781 |
+
$this->message( sprintf( __( "<strong>Success!</strong> %s reordered successfully.", 'pods' ), $this->items ) );
|
1782 |
+
else
|
1783 |
+
$this->error( sprintf( __( "<strong>Error:</strong> %s has not been reordered.", 'pods' ), $this->items ) );
|
1784 |
+
}
|
1785 |
+
|
1786 |
+
/**
|
1787 |
+
* @param bool $insert
|
1788 |
+
*
|
1789 |
+
* @return mixed
|
1790 |
+
*/
|
1791 |
+
public function save ( $insert = false ) {
|
1792 |
+
$this->do_hook( 'pre_save', $insert );
|
1793 |
+
|
1794 |
+
if ( $this->callback( 'save', $insert ) ) {
|
1795 |
+
return null;
|
1796 |
+
}
|
1797 |
+
|
1798 |
+
global $wpdb;
|
1799 |
+
$action = __( 'saved', 'pods' );
|
1800 |
+
if ( true === $insert )
|
1801 |
+
$action = __( 'created', 'pods' );
|
1802 |
+
$field_sql = array();
|
1803 |
+
$values = array();
|
1804 |
+
$data = array();
|
1805 |
+
foreach ( $this->fields[ 'form' ] as $field => $attributes ) {
|
1806 |
+
$vartype = '%s';
|
1807 |
+
if ( 'bool' == $attributes[ 'type' ] )
|
1808 |
+
$selected = ( 1 == pods_var( $field, 'post', 0 ) ) ? 1 : 0;
|
1809 |
+
elseif ( '' == pods_var( $field, 'post', '' ) )
|
1810 |
+
continue;
|
1811 |
+
if ( false === $attributes[ 'display' ] || false !== $attributes[ 'readonly' ] ) {
|
1812 |
+
if ( !in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) )
|
1813 |
+
continue;
|
1814 |
+
if ( false === $attributes[ 'date_touch' ] && ( false === $attributes[ 'date_touch_on_create' ] || false === $insert || 0 < $this->id ) )
|
1815 |
+
continue;
|
1816 |
+
}
|
1817 |
+
if ( in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) ) {
|
1818 |
+
$format = "Y-m-d H:i:s";
|
1819 |
+
if ( 'date' == $attributes[ 'type' ] )
|
1820 |
+
$format = "Y-m-d";
|
1821 |
+
if ( 'time' == $attributes[ 'type' ] )
|
1822 |
+
$format = "H:i:s";
|
1823 |
+
if ( false !== $attributes[ 'date_touch' ] || ( false !== $attributes[ 'date_touch_on_create' ] && true === $insert && $this->id < 1 ) )
|
1824 |
+
$value = date_i18n( $format );
|
1825 |
+
else
|
1826 |
+
$value = date_i18n( $format, strtotime( ( 'time' == $attributes[ 'type' ] ) ? date_i18n( 'Y-m-d ' ) : pods_var( $field, 'post', '' ) ) );
|
1827 |
+
}
|
1828 |
+
else {
|
1829 |
+
if ( 'bool' == $attributes[ 'type' ] ) {
|
1830 |
+
$vartype = '%d';
|
1831 |
+
$value = 0;
|
1832 |
+
if ( '' != pods_var( $field, 'post', '' ) )
|
1833 |
+
$value = 1;
|
1834 |
+
}
|
1835 |
+
elseif ( 'number' == $attributes[ 'type' ] ) {
|
1836 |
+
$vartype = '%d';
|
1837 |
+
$value = number_format( pods_var( $field, 'post', 0 ), 0, '', '' );
|
1838 |
+
}
|
1839 |
+
elseif ( 'decimal' == $attributes[ 'type' ] ) {
|
1840 |
+
$vartype = '%d';
|
1841 |
+
$value = number_format( pods_var( $field, 'post', 0 ), 2, '.', '' );
|
1842 |
+
}
|
1843 |
+
elseif ( 'related' == $attributes[ 'type' ] ) {
|
1844 |
+
if ( is_array( pods_var( $field, 'post', '' ) ) )
|
1845 |
+
$value = implode( ',', pods_var( $field, 'post', '' ) );
|
1846 |
+
else
|
1847 |
+
$value = pods_var( $field, 'post', '' );
|
1848 |
+
}
|
1849 |
+
else
|
1850 |
+
$value = pods_var( $field, 'post', '' );
|
1851 |
+
}
|
1852 |
+
|
1853 |
+
if ( isset( $attributes[ 'custom_save' ] ) && false !== $attributes[ 'custom_save' ] && is_callable( $attributes[ 'custom_save' ] ) )
|
1854 |
+
$value = call_user_func_array( $attributes[ 'custom_save' ], array( $value, $field, $attributes, &$this ) );
|
1855 |
+
|
1856 |
+
$field_sql[] = "`$field`=$vartype";
|
1857 |
+
$values[] = $value;
|
1858 |
+
$data[ $field ] = $value;
|
1859 |
+
}
|
1860 |
+
$field_sql = implode( ',', $field_sql );
|
1861 |
+
if ( false === $insert && 0 < $this->id ) {
|
1862 |
+
$this->insert_id = $this->id;
|
1863 |
+
$values[] = $this->id;
|
1864 |
+
$check = $wpdb->query( $wpdb->prepare( "UPDATE $this->sql['table'] SET $field_sql WHERE id=%d", $values ) );
|
1865 |
+
}
|
1866 |
+
else
|
1867 |
+
$check = $wpdb->query( $wpdb->prepare( "INSERT INTO $this->sql['table'] SET $field_sql", $values ) );
|
1868 |
+
if ( $check ) {
|
1869 |
+
if ( 0 == $this->insert_id )
|
1870 |
+
$this->insert_id = $wpdb->insert_id;
|
1871 |
+
$this->message( sprintf( __( "<strong>Success!</strong> %s %s successfully.", 'pods' ), $this->item, $action ) );
|
1872 |
+
}
|
1873 |
+
else
|
1874 |
+
$this->error( sprintf( __( "<strong>Error:</strong> %s has not been %s.", 'pods' ), $this->item, $action ) );
|
1875 |
+
$this->do_hook( 'post_save', $this->insert_id, $data, $insert );
|
1876 |
+
}
|
1877 |
+
|
1878 |
+
/**
|
1879 |
+
* @param null $id
|
1880 |
+
*
|
1881 |
+
* @return bool|mixed
|
1882 |
+
*/
|
1883 |
+
public function delete ( $id = null ) {
|
1884 |
+
$this->do_hook( 'pre_delete', $id );
|
1885 |
+
|
1886 |
+
if ( false !== $this->callback_action( 'delete', $id ) ) {
|
1887 |
+
return null;
|
1888 |
+
}
|
1889 |
+
|
1890 |
+
$id = pods_absint( $id );
|
1891 |
+
|
1892 |
+
if ( empty( $id ) )
|
1893 |
+
$id = pods_absint( $this->id );
|
1894 |
+
|
1895 |
+
if ( $id < 1 )
|
1896 |
+
return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods' ) );
|
1897 |
+
|
1898 |
+
if ( false === $id )
|
1899 |
+
$id = $this->id;
|
1900 |
+
|
1901 |
+
if ( is_object( $this->pod ) )
|
1902 |
+
$check = $this->pod->delete( $id );
|
1903 |
+
else
|
1904 |
+
$check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) );
|
1905 |
+
|
1906 |
+
if ( $check )
|
1907 |
+
$this->message( sprintf( __( "<strong>Deleted:</strong> %s has been deleted.", 'pods' ), $this->item ) );
|
1908 |
+
else
|
1909 |
+
$this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) );
|
1910 |
+
|
1911 |
+
$this->do_hook( 'post_delete', $id );
|
1912 |
+
}
|
1913 |
+
|
1914 |
+
/**
|
1915 |
+
* @param null $id
|
1916 |
+
*
|
1917 |
+
* @return bool|mixed
|
1918 |
+
*/
|
1919 |
+
public function delete_bulk () {
|
1920 |
+
$this->do_hook( 'pre_delete_bulk' );
|
1921 |
+
|
1922 |
+
if ( 1 != pods_var( 'deleted_bulk', 'get', 0 ) ) {
|
1923 |
+
$ids = $this->bulk;
|
1924 |
+
|
1925 |
+
$success = false;
|
1926 |
+
|
1927 |
+
if ( !empty( $ids ) ) {
|
1928 |
+
$ids = (array) $ids;
|
1929 |
+
|
1930 |
+
foreach ( $ids as $id ) {
|
1931 |
+
$id = pods_absint( $id );
|
1932 |
+
|
1933 |
+
if ( empty( $id ) )
|
1934 |
+
continue;
|
1935 |
+
|
1936 |
+
if ( $callback = $this->callback( 'delete', $id ) ) {
|
1937 |
+
$check = $callback;
|
1938 |
+
}
|
1939 |
+
elseif ( is_object( $this->pod ) )
|
1940 |
+
$check = $this->pod->delete( $id );
|
1941 |
+
else
|
1942 |
+
$check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) );
|
1943 |
+
|
1944 |
+
if ( $check )
|
1945 |
+
$success = true;
|
1946 |
+
}
|
1947 |
+
}
|
1948 |
+
|
1949 |
+
if ( $success )
|
1950 |
+
pods_redirect( pods_var_update( array( 'action_bulk' => 'delete', 'deleted_bulk' => 1 ), array( 'page', 'lang', 'action', 'id' ) ) );
|
1951 |
+
else
|
1952 |
+
$this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) );
|
1953 |
+
}
|
1954 |
+
else {
|
1955 |
+
$this->message( sprintf( __( "<strong>Deleted:</strong> %s have been deleted.", 'pods' ), $this->items ) );
|
1956 |
+
|
1957 |
+
unset( $_GET[ 'deleted_bulk' ] );
|
1958 |
+
}
|
1959 |
+
|
1960 |
+
$this->action_bulk = false;
|
1961 |
+
unset( $_GET[ 'action_bulk' ] );
|
1962 |
+
|
1963 |
+
$this->do_hook( 'post_delete_bulk' );
|
1964 |
+
|
1965 |
+
$this->manage();
|
1966 |
+
}
|
1967 |
+
|
1968 |
+
public function export () {
|
1969 |
+
$export_type = pods_var( 'export_type', 'get', 'csv' );
|
1970 |
+
|
1971 |
+
$type = 'sv'; // covers csv + tsv
|
1972 |
+
|
1973 |
+
if ( in_array( $export_type, array( 'xml', 'json' ) ) )
|
1974 |
+
$type = $export_type;
|
1975 |
+
|
1976 |
+
$delimiter = ',';
|
1977 |
+
|
1978 |
+
if ( 'tsv' == $export_type )
|
1979 |
+
$delimiter = "\t";
|
1980 |
+
|
1981 |
+
$columns = array();
|
1982 |
+
|
1983 |
+
if ( empty( $this->fields[ 'export' ] ) ) {
|
1984 |
+
$this->fields[ 'export' ] = $this->pod->fields;
|
1985 |
+
|
1986 |
+
$columns = array(
|
1987 |
+
$this->pod->pod_data[ 'field_id' ] => 'ID'
|
1988 |
+
);
|
1989 |
+
}
|
1990 |
+
|
1991 |
+
foreach ( $this->fields[ 'export' ] as $field ) {
|
1992 |
+
$columns[ $field[ 'name' ] ] = $field[ 'label' ];
|
1993 |
+
}
|
1994 |
+
|
1995 |
+
$params = array(
|
1996 |
+
'full' => true,
|
1997 |
+
'flatten' => true,
|
1998 |
+
'fields' => array_keys( $columns ),
|
1999 |
+
'type' => $type,
|
2000 |
+
'delimiter' => $delimiter,
|
2001 |
+
'columns' => $columns
|
2002 |
+
);
|
2003 |
+
|
2004 |
+
$items = $this->get_data( $params );
|
2005 |
+
|
2006 |
+
$data = array(
|
2007 |
+
'columns' => $columns,
|
2008 |
+
'items' => $items,
|
2009 |
+
'fields' => $this->fields[ 'export' ]
|
2010 |
+
);
|
2011 |
+
|
2012 |
+
$migrate = pods_migrate( $type, $delimiter, $data );
|
2013 |
+
|
2014 |
+
$migrate->export();
|
2015 |
+
|
2016 |
+
$export_file = $migrate->save();
|
2017 |
+
|
2018 |
+
$this->message( sprintf( __( '<strong>Success:</strong> Your export is ready, you can download it <a href="%s" target="_blank">here</a>', 'pods' ), $export_file ) );
|
2019 |
+
|
2020 |
+
//echo '<script type="text/javascript">window.open("' . esc_js( $export_file ) . '");</script>';
|
2021 |
+
|
2022 |
+
$this->get_data();
|
2023 |
+
}
|
2024 |
+
|
2025 |
+
/**
|
2026 |
+
* @param $field
|
2027 |
+
*
|
2028 |
+
* @return array|bool|mixed|null
|
2029 |
+
*/
|
2030 |
+
public function get_field ( $field ) {
|
2031 |
+
$value = null;
|
2032 |
+
|
2033 |
+
// use PodsData to get field
|
2034 |
+
|
2035 |
+
if ( $callback = $this->callback( 'get_field', $field ) ) {
|
2036 |
+
return $callback;
|
2037 |
+
}
|
2038 |
+
|
2039 |
+
if ( isset( $this->row[ $field ] ) ) {
|
2040 |
+
$value = $this->row[ $field ];
|
2041 |
+
}
|
2042 |
+
elseif ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
|
2043 |
+
if ( 'Pod' == get_class( $this->pod ) )
|
2044 |
+
$value = $this->pod->get_field( $field );
|
2045 |
+
else
|
2046 |
+
$value = $this->pod->field( $field );
|
2047 |
+
}
|
2048 |
+
|
2049 |
+
return $this->do_hook( 'get_field', $value, $field );
|
2050 |
+
}
|
2051 |
+
|
2052 |
+
/**
|
2053 |
+
* @param bool $full Whether to get ALL data or use pagination
|
2054 |
+
*
|
2055 |
+
* @return bool
|
2056 |
+
*/
|
2057 |
+
public function get_data ( $params = null ) {
|
2058 |
+
$action = $this->action;
|
2059 |
+
|
2060 |
+
$defaults = array(
|
2061 |
+
'full' => false,
|
2062 |
+
'flatten' => true,
|
2063 |
+
'fields' => null,
|
2064 |
+
'type' => ''
|
2065 |
+
);
|
2066 |
+
|
2067 |
+
if ( !empty( $params ) && is_array( $params ) )
|
2068 |
+
$params = (object) array_merge( $defaults, $params );
|
2069 |
+
else
|
2070 |
+
$params = (object) $defaults;
|
2071 |
+
|
2072 |
+
if ( !in_array( $action, array( 'manage', 'reorder' ) ) )
|
2073 |
+
$action = 'manage';
|
2074 |
+
|
2075 |
+
if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
|
2076 |
+
$orderby = array();
|
2077 |
+
|
2078 |
+
$limit = $this->limit;
|
2079 |
+
|
2080 |
+
$sql = null;
|
2081 |
+
|
2082 |
+
if ( 'reorder' == $this->action ) {
|
2083 |
+
if ( !empty( $this->reorder[ 'orderby' ] ) )
|
2084 |
+
$orderby[ $this->reorder[ 'orderby' ] ] = $this->reorder[ 'orderby_dir' ];
|
2085 |
+
else
|
2086 |
+
$orderby[ $this->reorder[ 'on' ] ] = $this->reorder[ 'orderby_dir' ];
|
2087 |
+
|
2088 |
+
if ( !empty( $this->reorder[ 'limit' ] ) )
|
2089 |
+
$limit = $this->reorder[ 'limit' ];
|
2090 |
+
|
2091 |
+
if ( !empty( $this->reorder[ 'sql' ] ) )
|
2092 |
+
$sql = $this->reorder[ 'sql' ];
|
2093 |
+
}
|
2094 |
+
|
2095 |
+
if ( !empty( $this->orderby ) ) {
|
2096 |
+
$this->orderby = (array) $this->orderby;
|
2097 |
+
|
2098 |
+
foreach ( $this->orderby as $order ) {
|
2099 |
+
if ( false === strpos( ' ', $order ) && !isset( $orderby[ $order ] ) )
|
2100 |
+
$orderby[ $order ] = $this->orderby_dir;
|
2101 |
+
}
|
2102 |
+
}
|
2103 |
+
|
2104 |
+
$find_params = array(
|
2105 |
+
'where' => pods_var_raw( $action, $this->where, null, null, true ),
|
2106 |
+
'orderby' => $orderby,
|
2107 |
+
'page' => (int) $this->page,
|
2108 |
+
'pagination' => true,
|
2109 |
+
'limit' => (int) $limit,
|
2110 |
+
'search' => $this->searchable,
|
2111 |
+
'search_query' => $this->search,
|
2112 |
+
'search_across' => $this->search_across,
|
2113 |
+
'search_across_picks' => $this->search_across_picks,
|
2114 |
+
'filters' => $this->filters,
|
2115 |
+
'sql' => $sql
|
2116 |
+
);
|
2117 |
+
|
2118 |
+
if ( empty( $find_params[ 'where' ] ) && $this->restricted( $this->action ) )
|
2119 |
+
$find_params[ 'where' ] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
|
2120 |
+
|
2121 |
+
if ( $params->full )
|
2122 |
+
$find_params[ 'limit' ] = -1;
|
2123 |
+
|
2124 |
+
$find_params = array_merge( $find_params, (array) $this->params );
|
2125 |
+
|
2126 |
+
// Debug purposes
|
2127 |
+
if ( 1 == pods_var( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
2128 |
+
pods_debug( $find_params );
|
2129 |
+
|
2130 |
+
$this->pod->find( $find_params );
|
2131 |
+
|
2132 |
+
if ( !$params->full ) {
|
2133 |
+
$data = $this->pod->data();
|
2134 |
+
|
2135 |
+
$this->data = $data;
|
2136 |
+
|
2137 |
+
if ( !empty( $this->data ) )
|
2138 |
+
$this->data_keys = array_keys( $this->data );
|
2139 |
+
|
2140 |
+
$this->total = $this->pod->total();
|
2141 |
+
$this->total_found = $this->pod->total_found();
|
2142 |
+
}
|
2143 |
+
else {
|
2144 |
+
$this->data_full = array();
|
2145 |
+
|
2146 |
+
$export_params = array(
|
2147 |
+
'fields' => $params->fields,
|
2148 |
+
'flatten' => true
|
2149 |
+
);
|
2150 |
+
|
2151 |
+
if ( in_array( $params->type, array( 'json', 'xml' ) ) )
|
2152 |
+
$export_params[ 'flatten' ] = false;
|
2153 |
+
|
2154 |
+
$export_params = $this->do_hook( 'export_options', $export_params, $params );
|
2155 |
+
|
2156 |
+
while ( $this->pod->fetch() ) {
|
2157 |
+
$this->data_full[ $this->pod->id() ] = $this->pod->export( $export_params );
|
2158 |
+
}
|
2159 |
+
|
2160 |
+
$this->pod->reset();
|
2161 |
+
|
2162 |
+
return $this->data_full;
|
2163 |
+
}
|
2164 |
+
}
|
2165 |
+
else {
|
2166 |
+
if ( !empty( $this->data ) )
|
2167 |
+
return $this->data;
|
2168 |
+
|
2169 |
+
if ( empty( $this->sql[ 'table' ] ) )
|
2170 |
+
return $this->data;
|
2171 |
+
|
2172 |
+
$orderby = array();
|
2173 |
+
|
2174 |
+
if ( !empty( $this->orderby ) ) {
|
2175 |
+
$this->orderby = (array) $this->orderby;
|
2176 |
+
|
2177 |
+
foreach ( $this->orderby as $k => $order ) {
|
2178 |
+
if ( false === strpos( $order, ' ' ) ) {
|
2179 |
+
if ( in_array( strtoupper( $order ), array( 'ASC', 'DESC' ) ) ) {
|
2180 |
+
$orderby[ $k ] = $order;
|
2181 |
+
}
|
2182 |
+
elseif ( !isset( $orderby[ $order ] ) ) {
|
2183 |
+
$orderby[ $order ] = $this->orderby_dir;
|
2184 |
+
}
|
2185 |
+
}
|
2186 |
+
else {
|
2187 |
+
$orderby[] = $order;
|
2188 |
+
}
|
2189 |
+
}
|
2190 |
+
}
|
2191 |
+
|
2192 |
+
// Allow orderby array ( 'field' => 'asc|desc' )
|
2193 |
+
if ( !empty( $orderby ) && is_array( $orderby ) ) {
|
2194 |
+
foreach ( $orderby as $k => &$orderby_value ) {
|
2195 |
+
if ( !is_numeric( $k ) ) {
|
2196 |
+
$order = 'ASC';
|
2197 |
+
|
2198 |
+
if ( 'DESC' == strtoupper( $orderby_value ) )
|
2199 |
+
$order = 'DESC';
|
2200 |
+
|
2201 |
+
if ( false !== strpos( $k, '.' ) ) {
|
2202 |
+
$key = $k;
|
2203 |
+
|
2204 |
+
if ( false === strpos( $key, ' ' ) && false === strpos( $key, '`' ) )
|
2205 |
+
$key = '`' . str_replace( '.', '`.`', $key ) . '`';
|
2206 |
+
}
|
2207 |
+
else {
|
2208 |
+
$key = "`t`.`{$k}`";
|
2209 |
+
}
|
2210 |
+
|
2211 |
+
$orderby_value = $key;
|
2212 |
+
|
2213 |
+
if ( false === strpos( $orderby_value, ' ' ) )
|
2214 |
+
$orderby_value .= ' ' . $order;
|
2215 |
+
}
|
2216 |
+
}
|
2217 |
+
}
|
2218 |
+
|
2219 |
+
// Add prefix to $orderby if needed
|
2220 |
+
if ( !empty( $orderby ) ) {
|
2221 |
+
if ( !is_array( $orderby ) )
|
2222 |
+
$orderby = array( $orderby );
|
2223 |
+
|
2224 |
+
foreach ( $orderby as &$prefix_orderby ) {
|
2225 |
+
if ( false === strpos( $prefix_orderby, ',' ) && false === strpos( $prefix_orderby, '(' ) && false === stripos( $prefix_orderby, ' AS ' ) && false === strpos( $prefix_orderby, '`' ) && false === strpos( $prefix_orderby, '.' ) ) {
|
2226 |
+
if ( false !== stripos( $prefix_orderby, ' DESC' ) ) {
|
2227 |
+
$k = trim( str_ireplace( array( '`', ' DESC' ), '', $prefix_orderby ) );
|
2228 |
+
$dir = 'DESC';
|
2229 |
+
}
|
2230 |
+
else {
|
2231 |
+
$k = trim( str_ireplace( array( '`', ' ASC' ), '', $prefix_orderby ) );
|
2232 |
+
$dir = 'ASC';
|
2233 |
+
}
|
2234 |
+
|
2235 |
+
$key = "`t`.`{$k}`";
|
2236 |
+
|
2237 |
+
$prefix_orderby = "{$key} {$dir}";
|
2238 |
+
}
|
2239 |
+
}
|
2240 |
+
}
|
2241 |
+
|
2242 |
+
$find_params = array(
|
2243 |
+
'table' => $this->sql[ 'table' ],
|
2244 |
+
'id' => $this->sql[ 'field_id' ],
|
2245 |
+
'index' => $this->sql[ 'field_index' ],
|
2246 |
+
'where' => pods_var_raw( $action, $this->where, null, null, true ),
|
2247 |
+
'orderby' => $orderby,
|
2248 |
+
'page' => (int) $this->page,
|
2249 |
+
'pagination' => true,
|
2250 |
+
'limit' => (int) $this->limit,
|
2251 |
+
'search' => $this->searchable,
|
2252 |
+
'search_query' => $this->search,
|
2253 |
+
'fields' => $this->fields[ 'search' ]
|
2254 |
+
);
|
2255 |
+
|
2256 |
+
if ( empty( $find_params[ 'where' ] ) && $this->restricted( $this->action ) )
|
2257 |
+
$find_params[ 'where' ] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
|
2258 |
+
|
2259 |
+
if ( $params->full )
|
2260 |
+
$find_params[ 'limit' ] = -1;
|
2261 |
+
|
2262 |
+
// Debug purposes
|
2263 |
+
if ( 1 == pods_var( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
|
2264 |
+
pods_debug( $find_params );
|
2265 |
+
|
2266 |
+
$this->pods_data->select( $find_params );
|
2267 |
+
|
2268 |
+
if ( !$params->full ) {
|
2269 |
+
$this->data = $this->pods_data->data;
|
2270 |
+
|
2271 |
+
if ( !empty( $this->data ) ) {
|
2272 |
+
$this->data_keys = array_keys( $this->data );
|
2273 |
+
}
|
2274 |
+
|
2275 |
+
$this->total = $this->pods_data->total();
|
2276 |
+
$this->total_found = $this->pods_data->total_found();
|
2277 |
+
}
|
2278 |
+
else {
|
2279 |
+
$this->data_full = $this->pods_data->data;
|
2280 |
+
|
2281 |
+
if ( !empty( $this->data_full ) ) {
|
2282 |
+
$this->data_keys = array_keys( $this->data_full );
|
2283 |
+
}
|
2284 |
+
|
2285 |
+
return $this->data_full;
|
2286 |
+
}
|
2287 |
+
}
|
2288 |
+
|
2289 |
+
return $this->data;
|
2290 |
+
}
|
2291 |
+
|
2292 |
+
/**
|
2293 |
+
* Sort out data alphabetically by a key
|
2294 |
+
*/
|
2295 |
+
public function sort_data () {
|
2296 |
+
// only do this if we have a default orderby
|
2297 |
+
if ( isset( $this->orderby[ 'default' ] ) ) {
|
2298 |
+
$orderby = $this->orderby[ 'default' ];
|
2299 |
+
foreach ( $this->data as $k => $v ) {
|
2300 |
+
$sorter[ $k ] = strtolower( $v[ $orderby ] );
|
2301 |
+
}
|
2302 |
+
if ( $this->orderby_dir == 'ASC' )
|
2303 |
+
asort( $sorter );
|
2304 |
+
else
|
2305 |
+
arsort( $sorter );
|
2306 |
+
foreach ( $sorter as $key => $val ) {
|
2307 |
+
$intermediary[] = $this->data[ $key ];
|
2308 |
+
}
|
2309 |
+
if ( isset( $intermediary ) ) {
|
2310 |
+
$this->data = $intermediary;
|
2311 |
+
$this->data_keys = array_keys( $this->data );
|
2312 |
+
}
|
2313 |
+
}
|
2314 |
+
}
|
2315 |
+
|
2316 |
+
/**
|
2317 |
+
* @return array
|
2318 |
+
*/
|
2319 |
+
public function get_row ( &$counter = 0, $method = null ) {
|
2320 |
+
if ( !empty( $this->row ) && 0 < (int) $this->id && 'table' != $method )
|
2321 |
+
return $this->row;
|
2322 |
+
|
2323 |
+
if ( is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) )
|
2324 |
+
$this->row = $this->pod->fetch();
|
2325 |
+
else {
|
2326 |
+
$this->row = false;
|
2327 |
+
|
2328 |
+
if ( !empty( $this->data ) ) {
|
2329 |
+
if ( empty( $this->data_keys ) || count( $this->data ) != count( $this->data_keys ) ) {
|
2330 |
+
$this->data_keys = array_keys( $this->data );
|
2331 |
+
}
|
2332 |
+
|
2333 |
+
if ( count( $this->data ) == $this->total && isset( $this->data_keys[ $counter ] ) && isset( $this->data[ $this->data_keys[ $counter ] ] ) ) {
|
2334 |
+
$this->row = $this->data[ $this->data_keys[ $counter ] ];
|
2335 |
+
|
2336 |
+
$counter++;
|
2337 |
+
}
|
2338 |
+
}
|
2339 |
+
|
2340 |
+
if ( false === $this->row && 0 < (int) $this->id && !empty( $this->sql[ 'table' ] ) ) {
|
2341 |
+
$this->pods_data->select(
|
2342 |
+
array(
|
2343 |
+
'table' => $this->sql[ 'table' ],
|
2344 |
+
'where' => '`' . $this->sql[ 'field_id' ] . '` = ' . (int) $this->id,
|
2345 |
+
'limit' => 1
|
2346 |
+
)
|
2347 |
+
);
|
2348 |
+
|
2349 |
+
$this->row = $this->pods_data->fetch();
|
2350 |
+
}
|
2351 |
+
}
|
2352 |
+
|
2353 |
+
return $this->row;
|
2354 |
+
}
|
2355 |
+
|
2356 |
+
/**
|
2357 |
+
* @param bool $reorder
|
2358 |
+
*
|
2359 |
+
* @return mixed|null
|
2360 |
+
*/
|
2361 |
+
public function manage ( $reorder = false ) {
|
2362 |
+
if ( false !== $this->callback_action( 'manage', $reorder ) ) {
|
2363 |
+
return null;
|
2364 |
+
}
|
2365 |
+
|
2366 |
+
if ( !empty( $this->action_bulk ) && !empty( $this->actions_bulk ) && isset( $this->actions_bulk[ $this->action_bulk ] ) && !in_array( $this->action_bulk, $this->actions_disabled ) && !empty( $this->bulk ) ) {
|
2367 |
+
if ( false !== $this->callback_bulk( $this->action_bulk, $this->bulk ) ) {
|
2368 |
+
return null;
|
2369 |
+
}
|
2370 |
+
elseif ( 'delete' == $this->action_bulk ) {
|
2371 |
+
return $this->delete_bulk();
|
2372 |
+
}
|
2373 |
+
}
|
2374 |
+
|
2375 |
+
$this->screen_meta();
|
2376 |
+
|
2377 |
+
if ( true === $reorder )
|
2378 |
+
wp_enqueue_script( 'jquery-ui-sortable' );
|
2379 |
+
?>
|
2380 |
+
<div class="wrap pods-admin pods-ui">
|
2381 |
+
<div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo $this->icon; ?>);"<?php } ?>><br /></div>
|
2382 |
+
<h2>
|
2383 |
+
<?php
|
2384 |
+
if ( true === $reorder ) {
|
2385 |
+
echo $this->header[ 'reorder' ];
|
2386 |
+
|
2387 |
+
$link = pods_var_update( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
|
2388 |
+
|
2389 |
+
if ( !empty( $this->action_links[ 'manage' ] ) )
|
2390 |
+
$link = $this->action_links[ 'manage' ];
|
2391 |
+
?>
|
2392 |
+
<small>(<a href="<?php echo $link; ?>">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>)</small>
|
2393 |
+
<?php
|
2394 |
+
}
|
2395 |
+
else
|
2396 |
+
echo $this->header[ 'manage' ];
|
2397 |
+
|
2398 |
+
if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
|
2399 |
+
$link = pods_var_update( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num => '' ), self::$allowed, $this->exclusion() );
|
2400 |
+
|
2401 |
+
if ( !empty( $this->action_links[ 'add' ] ) )
|
2402 |
+
$link = $this->action_links[ 'add' ];
|
2403 |
+
?>
|
2404 |
+
<a href="<?php echo $link; ?>" class="add-new-h2"><?php echo $this->label[ 'add_new' ]; ?></a>
|
2405 |
+
<?php
|
2406 |
+
}
|
2407 |
+
if ( !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) {
|
2408 |
+
$link = pods_var_update( array( 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() );
|
2409 |
+
|
2410 |
+
if ( !empty( $this->action_links[ 'reorder' ] ) )
|
2411 |
+
$link = $this->action_links[ 'reorder' ];
|
2412 |
+
?>
|
2413 |
+
<a href="<?php echo $link; ?>" class="add-new-h2"><?php echo $this->label[ 'reorder' ]; ?></a>
|
2414 |
+
<?php
|
2415 |
+
}
|
2416 |
+
?>
|
2417 |
+
</h2>
|
2418 |
+
|
2419 |
+
<form id="posts-filter" action="" method="get">
|
2420 |
+
<?php
|
2421 |
+
$excluded_filters = array(
|
2422 |
+
'search' . $this->num,
|
2423 |
+
'pg' . $this->num,
|
2424 |
+
'action' . $this->num,
|
2425 |
+
'action_bulk' . $this->num,
|
2426 |
+
'action_bulk_ids' . $this->num
|
2427 |
+
);
|
2428 |
+
|
2429 |
+
$filters = $this->filters;
|
2430 |
+
|
2431 |
+
foreach ( $filters as $k => $filter ) {
|
2432 |
+
if ( isset( $this->pod->fields[ $filter ] ) ) {
|
2433 |
+
$filter_field = $this->pod->fields[ $filter ];
|
2434 |
+
}
|
2435 |
+
elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
|
2436 |
+
$filter_field = $this->fields[ 'manage' ][ $filter ];
|
2437 |
+
}
|
2438 |
+
else {
|
2439 |
+
unset( $filters[ $k ] );
|
2440 |
+
continue;
|
2441 |
+
}
|
2442 |
+
|
2443 |
+
if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
|
2444 |
+
if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) {
|
2445 |
+
unset( $filters[ $k ] );
|
2446 |
+
continue;
|
2447 |
+
}
|
2448 |
+
}
|
2449 |
+
elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) {
|
2450 |
+
unset( $filters[ $k ] );
|
2451 |
+
continue;
|
2452 |
+
}
|
2453 |
+
|
2454 |
+
$excluded_filters[] = 'filter_' . $filter . '_start';
|
2455 |
+
$excluded_filters[] = 'filter_' . $filter . '_end';
|
2456 |
+
$excluded_filters[] = 'filter_' . $filter;
|
2457 |
+
}
|
2458 |
+
|
2459 |
+
$get = $_GET;
|
2460 |
+
|
2461 |
+
foreach ( $get as $k => $v ) {
|
2462 |
+
if ( is_array( $v ) || in_array( $k, $excluded_filters ) || strlen( $v ) < 1 )
|
2463 |
+
continue;
|
2464 |
+
?>
|
2465 |
+
<input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
|
2466 |
+
<?php
|
2467 |
+
}
|
2468 |
+
|
2469 |
+
if ( false !== $this->callback( 'header', $reorder ) ) {
|
2470 |
+
return null;
|
2471 |
+
}
|
2472 |
+
|
2473 |
+
if ( false === $this->data )
|
2474 |
+
$this->get_data();
|
2475 |
+
elseif ( $this->sortable ) // we have the data already as an array
|
2476 |
+
$this->sort_data();
|
2477 |
+
|
2478 |
+
if ( !in_array( 'export', $this->actions_disabled ) && 'export' == $this->action )
|
2479 |
+
$this->export();
|
2480 |
+
|
2481 |
+
if ( ( !empty( $this->data ) || false !== $this->search || ( $this->filters_enhanced && !empty( $this->views ) ) ) && ( ( $this->filters_enhanced && !empty( $this->views ) ) || false !== $this->searchable ) ) {
|
2482 |
+
if ( $this->filters_enhanced )
|
2483 |
+
$this->filters();
|
2484 |
+
else {
|
2485 |
+
?>
|
2486 |
+
<p class="search-box" align="right">
|
2487 |
+
<?php
|
2488 |
+
$excluded_filters = array( 'search' . $this->num, 'pg' . $this->num );
|
2489 |
+
|
2490 |
+
foreach ( $this->filters as $filter ) {
|
2491 |
+
$excluded_filters[] = 'filter_' . $filter . '_start';
|
2492 |
+
$excluded_filters[] = 'filter_' . $filter . '_end';
|
2493 |
+
$excluded_filters[] = 'filter_' . $filter;
|
2494 |
+
}
|
2495 |
+
|
2496 |
+
$this->hidden_vars( $excluded_filters );
|
2497 |
+
|
2498 |
+
foreach ( $this->filters as $filter ) {
|
2499 |
+
if ( isset( $this->pod->fields[ $filter ] ) ) {
|
2500 |
+
$filter_field = $this->pod->fields[ $filter ];
|
2501 |
+
}
|
2502 |
+
elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
|
2503 |
+
$filter_field = $this->fields[ 'manage' ][ $filter ];
|
2504 |
+
}
|
2505 |
+
else {
|
2506 |
+
continue;
|
2507 |
+
}
|
2508 |
+
|
2509 |
+
if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
|
2510 |
+
$start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
|
2511 |
+
$end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
|
2512 |
+
|
2513 |
+
// override default value
|
2514 |
+
$filter_field[ 'options' ][ 'default_value' ] = '';
|
2515 |
+
$filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1;
|
2516 |
+
|
2517 |
+
|
2518 |
+
if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
|
2519 |
+
$start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
|
2520 |
+
|
2521 |
+
if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
|
2522 |
+
$end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
|
2523 |
+
?>
|
2524 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>_start">
|
2525 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
2526 |
+
</label>
|
2527 |
+
<?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
|
2528 |
+
|
2529 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>_end">
|
2530 |
+
to
|
2531 |
+
</label>
|
2532 |
+
<?php
|
2533 |
+
echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field );
|
2534 |
+
}
|
2535 |
+
elseif ( 'pick' == $filter_field[ 'type' ] ) {
|
2536 |
+
$value = pods_var_raw( 'filter_' . $filter, 'get' );
|
2537 |
+
|
2538 |
+
if ( strlen( $value ) < 1 )
|
2539 |
+
$value = pods_var_raw( 'filter_default', $filter_field );
|
2540 |
+
|
2541 |
+
// override default value
|
2542 |
+
$filter_field[ 'options' ][ 'default_value' ] = '';
|
2543 |
+
|
2544 |
+
$filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
|
2545 |
+
$filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
|
2546 |
+
|
2547 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
|
2548 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
|
2549 |
+
|
2550 |
+
$options = array_merge( $filter_field, $filter_field[ 'options' ] );
|
2551 |
+
?>
|
2552 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>">
|
2553 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
2554 |
+
</label>
|
2555 |
+
<?php
|
2556 |
+
echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
|
2557 |
+
}
|
2558 |
+
elseif ( 'boolean' == $filter_field[ 'type' ] ) {
|
2559 |
+
$value = pods_var_raw( 'filter_' . $filter, 'get', '' );
|
2560 |
+
|
2561 |
+
if ( strlen( $value ) < 1 )
|
2562 |
+
$value = pods_var_raw( 'filter_default', $filter_field );
|
2563 |
+
|
2564 |
+
// override default value
|
2565 |
+
$filter_field[ 'options' ][ 'default_value' ] = '';
|
2566 |
+
|
2567 |
+
$filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
|
2568 |
+
$filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
|
2569 |
+
|
2570 |
+
$filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple';
|
2571 |
+
$filter_field[ 'options' ][ 'pick_custom' ] = array(
|
2572 |
+
'1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
|
2573 |
+
'0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
|
2574 |
+
);
|
2575 |
+
|
2576 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
|
2577 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
|
2578 |
+
|
2579 |
+
$options = array_merge( $filter_field, $filter_field[ 'options' ] );
|
2580 |
+
?>
|
2581 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>">
|
2582 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
2583 |
+
</label>
|
2584 |
+
<?php
|
2585 |
+
echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
|
2586 |
+
}
|
2587 |
+
else {
|
2588 |
+
$value = pods_var_raw( 'filter_' . $filter, 'get' );
|
2589 |
+
|
2590 |
+
if ( strlen( $value ) < 1 )
|
2591 |
+
$value = pods_var_raw( 'filter_default', $filter_field );
|
2592 |
+
|
2593 |
+
// override default value
|
2594 |
+
$filter_field[ 'options' ][ 'default_value' ] = '';
|
2595 |
+
|
2596 |
+
$options = array();
|
2597 |
+
$options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
|
2598 |
+
$options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $options, $filter_field[ 'options' ][ 'input_helper' ], null, true );
|
2599 |
+
?>
|
2600 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>">
|
2601 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
2602 |
+
</label>
|
2603 |
+
<?php
|
2604 |
+
echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options );
|
2605 |
+
}
|
2606 |
+
}
|
2607 |
+
|
2608 |
+
if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
|
2609 |
+
?>
|
2610 |
+
<label<?php echo ( empty( $this->filters ) ) ? ' class="screen-reader-text"' : ''; ?> for="page-search<?php echo $this->num; ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
|
2611 |
+
<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
|
2612 |
+
<?php
|
2613 |
+
}
|
2614 |
+
else {
|
2615 |
+
echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
|
2616 |
+
}
|
2617 |
+
?>
|
2618 |
+
<?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?>
|
2619 |
+
<?php
|
2620 |
+
if ( 0 < strlen( $this->search ) ) {
|
2621 |
+
$clear_filters = array(
|
2622 |
+
'search' . $this->num => false
|
2623 |
+
);
|
2624 |
+
|
2625 |
+
foreach ( $this->filters as $filter ) {
|
2626 |
+
$clear_filters[ 'filter_' . $filter . '_start' ] = false;
|
2627 |
+
$clear_filters[ 'filter_' . $filter . '_end' ] = false;
|
2628 |
+
$clear_filters[ 'filter_' . $filter ] = false;
|
2629 |
+
}
|
2630 |
+
?>
|
2631 |
+
<br class="clear" />
|
2632 |
+
<small>[<a href="<?php echo pods_var_update( $clear_filters, array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'limit' . $this->num, 'page' ), $this->exclusion() ); ?>"><?php _e( 'Reset Filters', 'pods' ); ?></a>]</small>
|
2633 |
+
<br class="clear" />
|
2634 |
+
<?php
|
2635 |
+
}
|
2636 |
+
?>
|
2637 |
+
</p>
|
2638 |
+
<?php
|
2639 |
+
}
|
2640 |
+
}
|
2641 |
+
else {
|
2642 |
+
?>
|
2643 |
+
<br class="clear" />
|
2644 |
+
<?php
|
2645 |
+
}
|
2646 |
+
|
2647 |
+
if ( !empty( $this->data ) && ( false !== $this->pagination_total || false !== $this->pagination || true === $reorder ) || ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) || !empty( $this->actions_disabled ) ) {
|
2648 |
+
?>
|
2649 |
+
<div class="tablenav">
|
2650 |
+
<?php
|
2651 |
+
if ( !empty( $this->data ) && !empty( $this->actions_bulk ) ) {
|
2652 |
+
?>
|
2653 |
+
<div class="alignleft actions">
|
2654 |
+
<select name="action_bulk<?php echo $this->num; ?>">
|
2655 |
+
<option value="-1" selected="selected"><?php _e( 'Bulk Actions', 'pods' ); ?></option>
|
2656 |
+
|
2657 |
+
<?php
|
2658 |
+
foreach ( $this->actions_bulk as $action => $action_data ) {
|
2659 |
+
if ( in_array( $action, $this->actions_hidden ) || in_array( $action, $this->actions_hidden ) )
|
2660 |
+
continue;
|
2661 |
+
|
2662 |
+
if ( !isset( $action_data[ 'label' ] ) )
|
2663 |
+
$action_data[ 'label' ] = ucwords( str_replace( '_', ' ', $action ) );
|
2664 |
+
?>
|
2665 |
+
<option value="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $action_data[ 'label' ] ); ?></option>
|
2666 |
+
<?php
|
2667 |
+
}
|
2668 |
+
?>
|
2669 |
+
</select>
|
2670 |
+
|
2671 |
+
<input type="submit" id="doaction_bulk<?php echo $this->num; ?>" class="button-secondary action" value="<?php _e( 'Apply', 'pods' ); ?>">
|
2672 |
+
</div>
|
2673 |
+
<?php
|
2674 |
+
}
|
2675 |
+
|
2676 |
+
if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
|
2677 |
+
?>
|
2678 |
+
<div class="tablenav-pages<?php echo ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page'; ?>">
|
2679 |
+
<?php $this->pagination( 1 ); ?>
|
2680 |
+
</div>
|
2681 |
+
<?php
|
2682 |
+
}
|
2683 |
+
|
2684 |
+
if ( true === $reorder ) {
|
2685 |
+
$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
|
2686 |
+
|
2687 |
+
if ( !empty( $this->action_links[ 'manage' ] ) ) {
|
2688 |
+
$link = $this->action_links[ 'manage' ];
|
2689 |
+
}
|
2690 |
+
?>
|
2691 |
+
<input type="button" value="<?php _e( 'Update Order', 'pods' ); ?>" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" />
|
2692 |
+
<input type="button" value="<?php _e( 'Cancel', 'pods' ); ?>" class="button" onclick="document.location='<?php echo esc_attr( $link ); ?>';" />
|
2693 |
+
</form>
|
2694 |
+
<?php
|
2695 |
+
}
|
2696 |
+
/*
|
2697 |
+
elseif (!in_array('delete', $this->actions_disabled) && !in_array('delete', $this->actions_hidden) && is_developer() ) {
|
2698 |
+
?>
|
2699 |
+
<div class="alignleft actions">
|
2700 |
+
<select name="action">
|
2701 |
+
<option value="-1" selected="selected"><?php _e('Bulk Actions', 'pods'); ?></option>
|
2702 |
+
<option value="delete"><?php _e('Delete', 'pods'); ?></option>
|
2703 |
+
</select> <input type="submit" id="doaction" class="button-secondary action" value="<?php _e('Apply', 'pods'); ?>">
|
2704 |
+
</div>
|
2705 |
+
<?php
|
2706 |
+
}*/
|
2707 |
+
elseif ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) {
|
2708 |
+
?>
|
2709 |
+
<div class="alignleft actions">
|
2710 |
+
<strong><?php _e( 'Export', 'pods' ); ?>:</strong>
|
2711 |
+
<?php
|
2712 |
+
foreach ( $this->export[ 'formats' ] as $format => $separator ) {
|
2713 |
+
?>
|
2714 |
+
<input type="button" value=" <?php echo strtoupper( $format ); ?> " class="button" onclick="document.location='<?php echo pods_var_update( array( 'action' . $this->num => 'export', 'export_type' . $this->num => $format ), self::$allowed, $this->exclusion() ); ?>';" />
|
2715 |
+
<?php
|
2716 |
+
}
|
2717 |
+
?>
|
2718 |
+
</div>
|
2719 |
+
<?php
|
2720 |
+
}
|
2721 |
+
?>
|
2722 |
+
<br class="clear" />
|
2723 |
+
</div>
|
2724 |
+
<?php
|
2725 |
+
}
|
2726 |
+
else {
|
2727 |
+
?>
|
2728 |
+
<br class="clear" />
|
2729 |
+
<?php
|
2730 |
+
}
|
2731 |
+
?>
|
2732 |
+
<div class="clear"></div>
|
2733 |
+
<?php
|
2734 |
+
if ( empty( $this->data ) && false !== $this->default_none && false === $this->search ) {
|
2735 |
+
?>
|
2736 |
+
<p><?php _e( 'Please use the search filter(s) above to display data', 'pods' ); ?><?php if ( $this->export ) { ?>, <?php _e( 'or click on an Export to download a full copy of the data', 'pods' ); ?><?php } ?>.</p>
|
2737 |
+
<?php
|
2738 |
+
}
|
2739 |
+
else
|
2740 |
+
$this->table( $reorder );
|
2741 |
+
if ( !empty( $this->data ) ) {
|
2742 |
+
if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
|
2743 |
+
?>
|
2744 |
+
<div class="tablenav">
|
2745 |
+
<div class="tablenav-pages<?php echo ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page'; ?>">
|
2746 |
+
<?php $this->pagination( 0 ); ?>
|
2747 |
+
<br class="clear" />
|
2748 |
+
</div>
|
2749 |
+
</div>
|
2750 |
+
<?php
|
2751 |
+
}
|
2752 |
+
}
|
2753 |
+
|
2754 |
+
?>
|
2755 |
+
</form>
|
2756 |
+
</div>
|
2757 |
+
<?php
|
2758 |
+
if ( $this->filters_enhanced )
|
2759 |
+
$this->filters_popup();
|
2760 |
+
}
|
2761 |
+
|
2762 |
+
public function filters () {
|
2763 |
+
include_once ABSPATH . 'wp-admin/includes/template.php';
|
2764 |
+
|
2765 |
+
wp_enqueue_script( 'thickbox' );
|
2766 |
+
wp_enqueue_style( 'pods-ui-list-table', PODS_URL . 'ui/css/pods-ui-list-table.css', array( 'thickbox' ), PODS_VERSION );
|
2767 |
+
|
2768 |
+
$filters = $this->filters;
|
2769 |
+
|
2770 |
+
foreach ( $filters as $k => $filter ) {
|
2771 |
+
if ( isset( $this->pod->fields[ $filter ] ) ) {
|
2772 |
+
$filter_field = $this->pod->fields[ $filter ];
|
2773 |
+
}
|
2774 |
+
elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
|
2775 |
+
$filter_field = $this->fields[ 'manage' ][ $filter ];
|
2776 |
+
}
|
2777 |
+
else {
|
2778 |
+
continue;
|
2779 |
+
}
|
2780 |
+
|
2781 |
+
if ( isset( $filter_field ) && in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
|
2782 |
+
if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) )
|
2783 |
+
unset( $filters[ $k ] );
|
2784 |
+
}
|
2785 |
+
elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) )
|
2786 |
+
unset( $filters[ $k ] );
|
2787 |
+
}
|
2788 |
+
|
2789 |
+
$filtered = false;
|
2790 |
+
|
2791 |
+
if ( !empty( $filters ) )
|
2792 |
+
$filtered = true;
|
2793 |
+
?>
|
2794 |
+
<div class="pods-ui-filter-bar">
|
2795 |
+
<div class="pods-ui-filter-bar-primary">
|
2796 |
+
<?php
|
2797 |
+
if ( !empty( $this->views ) ) {
|
2798 |
+
?>
|
2799 |
+
<ul class="subsubsub">
|
2800 |
+
<li class="pods-ui-filter-view-label"><strong><?php echo $this->heading[ 'views' ]; ?></strong></li>
|
2801 |
+
|
2802 |
+
<?php
|
2803 |
+
foreach ( $this->views as $view => $label ) {
|
2804 |
+
if ( false === strpos( $label, '<a' ) ) {
|
2805 |
+
$link = pods_var_update( array( 'view' . $this->num => $view, 'pg' . $this->num => '' ), self::$allowed, $this->exclusion() );
|
2806 |
+
|
2807 |
+
if ( $this->view == $view )
|
2808 |
+
$label = '<a href="' . $link . '" class="current">' . $label . '</a>';
|
2809 |
+
else
|
2810 |
+
$label = '<a href="' . $link . '">' . $label . '</a>';
|
2811 |
+
}
|
2812 |
+
?>
|
2813 |
+
<li class="<?php echo $view; ?>"><?php echo $label; ?></li>
|
2814 |
+
<?php
|
2815 |
+
}
|
2816 |
+
?>
|
2817 |
+
</ul>
|
2818 |
+
<?php
|
2819 |
+
}
|
2820 |
+
?>
|
2821 |
+
|
2822 |
+
<?php
|
2823 |
+
if ( false !== $this->search && false !== $this->searchable ) {
|
2824 |
+
?>
|
2825 |
+
<p class="search-box">
|
2826 |
+
<?php
|
2827 |
+
if ( $filtered || '' != pods_var_raw( 'search' . $this->num, 'get', '', null, true ) ) {
|
2828 |
+
$clear_filters = array(
|
2829 |
+
'search' . $this->num => false
|
2830 |
+
);
|
2831 |
+
|
2832 |
+
foreach ( $this->filters as $filter ) {
|
2833 |
+
$clear_filters[ 'filter_' . $filter . '_start' ] = false;
|
2834 |
+
$clear_filters[ 'filter_' . $filter . '_end' ] = false;
|
2835 |
+
$clear_filters[ 'filter_' . $filter ] = false;
|
2836 |
+
}
|
2837 |
+
?>
|
2838 |
+
<a href="<?php echo pods_var_update( $clear_filters, array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'limit' . $this->num, 'page' ), $this->exclusion() ); ?>" class="pods-ui-filter-reset">[<?php _e( 'Reset', 'pods' ); ?>]</a>
|
2839 |
+
<?php
|
2840 |
+
}
|
2841 |
+
|
2842 |
+
if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
|
2843 |
+
?>
|
2844 |
+
<label class="screen-reader-text" for="page-search<?php echo $this->num; ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
|
2845 |
+
<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
|
2846 |
+
<?php
|
2847 |
+
}
|
2848 |
+
else {
|
2849 |
+
echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
|
2850 |
+
}
|
2851 |
+
?>
|
2852 |
+
|
2853 |
+
<?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?>
|
2854 |
+
</p>
|
2855 |
+
<?php
|
2856 |
+
}
|
2857 |
+
?>
|
2858 |
+
</div>
|
2859 |
+
|
2860 |
+
<?php
|
2861 |
+
if ( !empty( $this->filters ) ) {
|
2862 |
+
?>
|
2863 |
+
<div class="pods-ui-filter-bar-secondary">
|
2864 |
+
<ul class="subsubsub">
|
2865 |
+
<?php
|
2866 |
+
if ( !$filtered ) {
|
2867 |
+
?>
|
2868 |
+
<li class="pods-ui-filter-bar-add-filter">
|
2869 |
+
<a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
|
2870 |
+
<?php _e( 'Advanced Filters', 'pods' ); ?>
|
2871 |
+
</a>
|
2872 |
+
</li>
|
2873 |
+
<?php
|
2874 |
+
}
|
2875 |
+
else {
|
2876 |
+
?>
|
2877 |
+
<li class="pods-ui-filter-bar-add-filter">
|
2878 |
+
<a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
|
2879 |
+
+ <?php _e( 'Add Filter', 'pods' ); ?>
|
2880 |
+
</a>
|
2881 |
+
</li>
|
2882 |
+
<?php
|
2883 |
+
}
|
2884 |
+
|
2885 |
+
foreach ( $filters as $filter ) {
|
2886 |
+
$value = pods_var_raw( 'filter_' . $filter, 'get' );
|
2887 |
+
|
2888 |
+
if ( isset( $this->pod->fields[ $filter ] ) ) {
|
2889 |
+
$filter_field = $this->pod->fields[ $filter ];
|
2890 |
+
}
|
2891 |
+
elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
|
2892 |
+
$filter_field = $this->fields[ 'manage' ][ $filter ];
|
2893 |
+
}
|
2894 |
+
else {
|
2895 |
+
continue;
|
2896 |
+
}
|
2897 |
+
|
2898 |
+
$data_filter = 'filter_' . $filter;
|
2899 |
+
|
2900 |
+
$start = $end = $value_label = '';
|
2901 |
+
|
2902 |
+
if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
|
2903 |
+
$start = pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true );
|
2904 |
+
$end = pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true );
|
2905 |
+
|
2906 |
+
if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
|
2907 |
+
$start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
|
2908 |
+
|
2909 |
+
if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
|
2910 |
+
$end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
|
2911 |
+
|
2912 |
+
$value = trim( $start . ' - ' . $end, ' -' );
|
2913 |
+
|
2914 |
+
$data_filter = 'filter_' . $filter . '_start';
|
2915 |
+
}
|
2916 |
+
elseif ( 'pick' == $filter_field[ 'type' ] )
|
2917 |
+
$value_label = trim( PodsForm::field_method( 'pick', 'value_to_label', $filter, $value, $filter_field, $this->pod->pod_data, null ) );
|
2918 |
+
elseif ( 'boolean' == $filter_field[ 'type' ] ) {
|
2919 |
+
$yesno_options = array(
|
2920 |
+
'1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
|
2921 |
+
'0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
|
2922 |
+
);
|
2923 |
+
|
2924 |
+
if ( isset( $yesno_options[ (string) $value ] ) )
|
2925 |
+
$value_label = $yesno_options[ (string) $value ];
|
2926 |
+
}
|
2927 |
+
|
2928 |
+
if ( strlen( $value_label ) < 1 )
|
2929 |
+
$value_label = $value;
|
2930 |
+
?>
|
2931 |
+
<li class="pods-ui-filter-bar-filter" data-filter="<?php echo $data_filter; ?>">
|
2932 |
+
<a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
|
2933 |
+
<strong><?php echo $filter_field[ 'label' ]; ?>:</strong>
|
2934 |
+
<?php echo esc_html( $value_label ); ?>
|
2935 |
+
</a>
|
2936 |
+
|
2937 |
+
<a href="#remove-filter" class="remove-filter" title="<?php esc_attr_e( 'Remove Filter', 'pods' ); ?>">x</a>
|
2938 |
+
|
2939 |
+
<?php
|
2940 |
+
if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
|
2941 |
+
echo PodsForm::field( 'filter_' . $filter . '_start', $start, 'hidden' );
|
2942 |
+
echo PodsForm::field( 'filter_' . $filter . '_end', $end, 'hidden' );
|
2943 |
+
}
|
2944 |
+
else
|
2945 |
+
echo PodsForm::field( $data_filter, $value, 'hidden' );
|
2946 |
+
?>
|
2947 |
+
</li>
|
2948 |
+
<?php
|
2949 |
+
}
|
2950 |
+
?>
|
2951 |
+
</ul>
|
2952 |
+
</div>
|
2953 |
+
<?php
|
2954 |
+
}
|
2955 |
+
?>
|
2956 |
+
</div>
|
2957 |
+
|
2958 |
+
<script type="text/javascript">
|
2959 |
+
jQuery( function() {
|
2960 |
+
jQuery( '.pods-ui-filter-bar-secondary' ).on( 'click', '.remove-filter', function ( e ) {
|
2961 |
+
jQuery( '.pods-ui-filter-popup #' + jQuery( this ).parent().data( 'filter' ) ).remove();
|
2962 |
+
|
2963 |
+
jQuery( this ).parent().find( 'input' ).each( function () {
|
2964 |
+
jQuery( this ).remove();
|
2965 |
+
} );
|
2966 |
+
|
2967 |
+
jQuery( 'form#posts-filter [name="pg"]' ).prop( 'disabled', true );
|
2968 |
+
jQuery( 'form#posts-filter [name="action"]' ).prop( 'disabled', true );
|
2969 |
+
jQuery( 'form#posts-filter [name="action_bulk<?php echo $this->num; ?>"]' ).prop( 'disabled', true );
|
2970 |
+
|
2971 |
+
jQuery( 'form#posts-filter' ).submit();
|
2972 |
+
|
2973 |
+
e.preventDefault();
|
2974 |
+
} );
|
2975 |
+
} );
|
2976 |
+
</script>
|
2977 |
+
<?php
|
2978 |
+
}
|
2979 |
+
|
2980 |
+
public function filters_popup () {
|
2981 |
+
$filters = $this->filters;
|
2982 |
+
?>
|
2983 |
+
<div id="pods-ui-posts-filter-popup" class="hidden">
|
2984 |
+
<form action="" method="get" class="pods-ui-posts-filter-popup">
|
2985 |
+
<h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
|
2986 |
+
|
2987 |
+
<div class="pods-ui-posts-filters">
|
2988 |
+
<?php
|
2989 |
+
$excluded_filters = array(
|
2990 |
+
'search' . $this->num,
|
2991 |
+
'pg' . $this->num,
|
2992 |
+
'action' . $this->num,
|
2993 |
+
'action_bulk' . $this->num,
|
2994 |
+
'action_bulk_ids' . $this->num
|
2995 |
+
);
|
2996 |
+
|
2997 |
+
foreach ( $filters as $filter ) {
|
2998 |
+
$excluded_filters[] = 'filters_relation';
|
2999 |
+
$excluded_filters[] = 'filters_compare_' . $filter;
|
3000 |
+
$excluded_filters[] = 'filter_' . $filter . '_start';
|
3001 |
+
$excluded_filters[] = 'filter_' . $filter . '_end';
|
3002 |
+
$excluded_filters[] = 'filter_' . $filter;
|
3003 |
+
}
|
3004 |
+
|
3005 |
+
$get = $_GET;
|
3006 |
+
|
3007 |
+
foreach ( $get as $k => $v ) {
|
3008 |
+
if ( in_array( $k, $excluded_filters ) || strlen( $v ) < 1 )
|
3009 |
+
continue;
|
3010 |
+
?>
|
3011 |
+
<input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
|
3012 |
+
<?php
|
3013 |
+
}
|
3014 |
+
|
3015 |
+
$zebra = true;
|
3016 |
+
|
3017 |
+
foreach ( $filters as $filter ) {
|
3018 |
+
if ( empty( $filter ) )
|
3019 |
+
continue;
|
3020 |
+
|
3021 |
+
if ( isset( $this->pod->fields[ $filter ] ) ) {
|
3022 |
+
$filter_field = $this->pod->fields[ $filter ];
|
3023 |
+
}
|
3024 |
+
elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
|
3025 |
+
$filter_field = $this->fields[ 'manage' ][ $filter ];
|
3026 |
+
}
|
3027 |
+
else {
|
3028 |
+
continue;
|
3029 |
+
}
|
3030 |
+
?>
|
3031 |
+
<p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-<?php echo $filter . ( $zebra ? ' clear' : '' ); ?>">
|
3032 |
+
<?php
|
3033 |
+
if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
|
3034 |
+
$start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
|
3035 |
+
$end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
|
3036 |
+
|
3037 |
+
// override default value
|
3038 |
+
$filter_field[ 'options' ][ 'default_value' ] = '';
|
3039 |
+
$filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1;
|
3040 |
+
|
3041 |
+
if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
|
3042 |
+
$start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
|
3043 |
+
|
3044 |
+
if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
|
3045 |
+
$end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
|
3046 |
+
?>
|
3047 |
+
<span class="pods-ui-posts-filter-toggle toggle-on<?php echo ( ( empty( $start ) && empty( $end ) ) ? '' : ' hidden' ); ?>">+</span>
|
3048 |
+
<span class="pods-ui-posts-filter-toggle toggle-off<?php echo ( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
|
3049 |
+
|
3050 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>_start">
|
3051 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
3052 |
+
</label>
|
3053 |
+
|
3054 |
+
<span class="pods-ui-posts-filter<?php echo ( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>">
|
3055 |
+
<?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
|
3056 |
+
|
3057 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>_end">to</label>
|
3058 |
+
<?php echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field ); ?>
|
3059 |
+
</span>
|
3060 |
+
<?php
|
3061 |
+
}
|
3062 |
+
elseif ( 'pick' == $filter_field[ 'type' ] ) {
|
3063 |
+
$value = pods_var_raw( 'filter_' . $filter, 'get', '' );
|
3064 |
+
|
3065 |
+
if ( strlen( $value ) < 1 )
|
3066 |
+
$value = pods_var_raw( 'filter_default', $filter_field );
|
3067 |
+
|
3068 |
+
// override default value
|
3069 |
+
$filter_field[ 'options' ][ 'default_value' ] = '';
|
3070 |
+
|
3071 |
+
$filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
|
3072 |
+
$filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
|
3073 |
+
|
3074 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
|
3075 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
|
3076 |
+
|
3077 |
+
$options = array_merge( $filter_field, $filter_field[ 'options' ] );
|
3078 |
+
?>
|
3079 |
+
<span class="pods-ui-posts-filter-toggle toggle-on<?php echo ( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
|
3080 |
+
<span class="pods-ui-posts-filter-toggle toggle-off<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
|
3081 |
+
|
3082 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>">
|
3083 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
3084 |
+
</label>
|
3085 |
+
|
3086 |
+
<span class="pods-ui-posts-filter<?php echo ( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
|
3087 |
+
<?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
|
3088 |
+
</span>
|
3089 |
+
<?php
|
3090 |
+
}
|
3091 |
+
elseif ( 'boolean' == $filter_field[ 'type' ] ) {
|
3092 |
+
$value = pods_var_raw( 'filter_' . $filter, 'get', '' );
|
3093 |
+
|
3094 |
+
if ( strlen( $value ) < 1 )
|
3095 |
+
$value = pods_var_raw( 'filter_default', $filter_field );
|
3096 |
+
|
3097 |
+
// override default value
|
3098 |
+
$filter_field[ 'options' ][ 'default_value' ] = '';
|
3099 |
+
|
3100 |
+
$filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
|
3101 |
+
$filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
|
3102 |
+
|
3103 |
+
$filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple';
|
3104 |
+
$filter_field[ 'options' ][ 'pick_custom' ] = array(
|
3105 |
+
'1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
|
3106 |
+
'0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
|
3107 |
+
);
|
3108 |
+
|
3109 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
|
3110 |
+
$filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
|
3111 |
+
|
3112 |
+
$options = array_merge( $filter_field, $filter_field[ 'options' ] );
|
3113 |
+
?>
|
3114 |
+
<span class="pods-ui-posts-filter-toggle toggle-on<?php echo ( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
|
3115 |
+
<span class="pods-ui-posts-filter-toggle toggle-off<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
|
3116 |
+
|
3117 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>">
|
3118 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
3119 |
+
</label>
|
3120 |
+
|
3121 |
+
<span class="pods-ui-posts-filter<?php echo ( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
|
3122 |
+
<?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
|
3123 |
+
</span>
|
3124 |
+
<?php
|
3125 |
+
}
|
3126 |
+
else {
|
3127 |
+
$value = pods_var_raw( 'filter_' . $filter, 'get' );
|
3128 |
+
|
3129 |
+
if ( strlen( $value ) < 1 )
|
3130 |
+
$value = pods_var_raw( 'filter_default', $filter_field );
|
3131 |
+
|
3132 |
+
$options = array(
|
3133 |
+
'input_helper' => pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true )
|
3134 |
+
);
|
3135 |
+
|
3136 |
+
if ( empty( $options[ 'input_helper' ] ) && isset( $filter_field[ 'options' ] ) && isset( $filter_field[ 'options' ][ 'input_helper' ] ) )
|
3137 |
+
$options[ 'input_helper' ] = $filter_field[ 'options' ][ 'input_helper' ];
|
3138 |
+
?>
|
3139 |
+
<span class="pods-ui-posts-filter-toggle toggle-on<?php echo ( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
|
3140 |
+
<span class="pods-ui-posts-filter-toggle toggle-off<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
|
3141 |
+
|
3142 |
+
<label for="pods-form-ui-filter-<?php echo $filter; ?>">
|
3143 |
+
<?php echo $filter_field[ 'label' ]; ?>
|
3144 |
+
</label>
|
3145 |
+
|
3146 |
+
<span class="pods-ui-posts-filter<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>">
|
3147 |
+
<?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?>
|
3148 |
+
</span>
|
3149 |
+
<?php
|
3150 |
+
}
|
3151 |
+
?>
|
3152 |
+
</p>
|
3153 |
+
<?php
|
3154 |
+
$zebra = empty( $zebra );
|
3155 |
+
}
|
3156 |
+
|