Pods_Deprecated

The Pods - Custom Content Types and Fields Pods Deprecated class.

Defined (1)

The class is defined in the following location(s).

/deprecated/classes/Pods.php  
  1. class Pods_Deprecated 
  2. private $obj; 
  3.  
  4. var $id; 
  5.  
  6. var $data; 
  7.  
  8. var $datatype; 
  9.  
  10. var $datatype_id; 
  11.  
  12. /** 
  13. * Constructor - Pods Deprecated functionality (pre 2.0) 
  14. * @param object $obj The Pods object 
  15. * @license http://www.gnu.org/licenses/gpl-2.0.html 
  16. * @since 2.0 
  17. */ 
  18. public function __construct ( $obj ) { 
  19. // backwards-compatibility with references to $this->var_name 
  20. $vars = get_object_vars( $obj ); 
  21.  
  22. foreach ( (array) $vars as $key => $val ) { 
  23. $this->{$key} = $val; 
  24.  
  25. // keeping references pointing back to the source 
  26. $this->obj =& $obj; 
  27.  
  28. /** 
  29. * Set a custom data value (no database changes) 
  30. * @param string $name The field name 
  31. * @param mixed $data The value to set 
  32. * @return mixed The value of $data 
  33. * @since 1.2.0 
  34. */ 
  35. public function set_field ( $name, $data = null ) { 
  36. if ( Pod::$deprecated_notice ) { 
  37. pods_deprecated( 'Pods::set_field', '2.0' ); 
  38.  
  39. $this->obj->row[ $name ] = $data; 
  40.  
  41. return $this->obj->row[ $name ]; 
  42.  
  43. /** 
  44. * Display HTML for all datatype fields 
  45. * @deprecated deprecated since 2.0 
  46. */ 
  47. public function showform ( $id = null, $public_fields = null, $label = 'Save changes' ) { 
  48. if ( Pod::$deprecated_notice ) { 
  49. pods_deprecated( 'Pods::showform', '2.0' ); 
  50.  
  51. $public_columns =& $public_fields; 
  52.  
  53. $pod = $this->obj->pod; 
  54. $pod_id = $this->obj->pod_id; 
  55. $this->obj->type_counter = array(); 
  56.  
  57. if ( !empty( $public_fields ) ) { 
  58. $attributes = array(); 
  59.  
  60. foreach ( $public_fields as $key => $value ) { 
  61. if ( is_array( $public_fields[ $key ] ) ) 
  62. $attributes[ $key ] = $value; 
  63. else 
  64. $attributes[ $value ] = array(); 
  65.  
  66. $fields = $this->obj->fields; 
  67.  
  68. // Re-order the fields if a public form 
  69. if ( !empty( $attributes ) ) { 
  70. $fields = array(); 
  71.  
  72. foreach ( $attributes as $key => $value ) { 
  73. if ( isset( $this->obj->fields[ $key ] ) ) 
  74. $fields[ $key ] = $this->obj->fields[ $key ]; 
  75.  
  76. do_action( 'pods_showform_pre', $pod_id, $public_fields, $label, $this ); 
  77.  
  78. foreach ( $fields as $key => $field ) { 
  79. if ( !is_array( $field ) || in_array( $key, array( 'created', 'modified' ) ) ) 
  80. continue; 
  81.  
  82. // Pass options so they can be manipulated via form 
  83. $field = array_merge( $field[ 'options' ], $field ); 
  84.  
  85. // Replace field attributes with public form attributes 
  86. if ( !empty( $attributes ) && is_array( $attributes[ $key ] ) ) 
  87. $field = array_merge( $field, $attributes[ $key ] ); 
  88.  
  89. // Replace the input helper name with the helper code 
  90. if ( !empty( $field[ 'input_helper' ] ) ) { 
  91. $helper = $this->obj->api->load_helper( array( 'name' => $field[ 'input_helper' ] ) ); 
  92. $field[ 'input_helper' ] = ''; 
  93.  
  94. if ( !empty( $helper ) ) 
  95. $field[ 'input_helper' ] = $helper[ 'code' ]; 
  96.  
  97. if ( empty( $field[ 'label' ] ) ) 
  98. $field[ 'label' ] = ucwords( $key ); 
  99.  
  100. if ( 1 == $field[ 'required' ] ) 
  101. $field[ 'label' ] .= ' <span class="red">*</span>'; 
  102.  
  103. if ( !empty( $field[ 'pick_val' ] ) ) { 
  104. $selected_ids = array(); 
  105. $pick_object = $field[ 'pick_object' ]; 
  106. $pick_val = $field[ 'pick_val' ]; 
  107.  
  108. if ( 'pod' == $pick_object ) { 
  109. $pick_pod = $this->obj->api->load_pod( array( 'name' => $pick_val ) ); 
  110. $pick_object = $pick_pod[ 'type' ]; 
  111. $pick_val = $pick_pod[ 'name' ]; 
  112.  
  113. $pick_table = $pick_join = $pick_where = ''; 
  114.  
  115. $pick_field_id = 'id'; 
  116. $pick_field_name = 'name'; 
  117. switch ( $pick_object ) { 
  118. case 'pod': 
  119. $pick_table = "@wp_pods_{$pick_val}"; 
  120. $pick_field_id = 'id'; 
  121. $pick_field_name = 'name'; 
  122. break; 
  123. case 'post_type': 
  124. $pick_table = '@wp_posts'; 
  125. $pick_field_id = 'ID'; 
  126. $pick_field_name = 'post_title'; 
  127. $pick_where = "t.`post_type` = '{$pick_val}'"; 
  128. break; 
  129. case 'taxonomy': 
  130. $pick_table = '@wp_terms'; 
  131. $pick_field_id = 'term_id'; 
  132. $pick_field_name = 'name'; 
  133. $pick_join = "`@wp_term_taxonomy` AS tx ON tx.`term_id` = t.`term_id"; 
  134. $pick_where = "tx.`taxonomy` = '{$pick_val}' AND tx.`taxonomy` IS NOT NULL"; 
  135. break; 
  136. case 'user': 
  137. $pick_table = '@wp_users'; 
  138. $pick_field_id = 'ID'; 
  139. $pick_field_name = 'user_login'; 
  140. break; 
  141. case 'comment': 
  142. $pick_table = '@wp_comments'; 
  143. $pick_field_id = 'comment_ID'; 
  144. $pick_field_name = 'comment_date'; 
  145. $pick_where = "t.`comment_type` = '{$pick_val}'"; 
  146. break; 
  147. case 'table': 
  148. $pick_table = "{$pick_val}"; 
  149. $pick_field_id = 'id'; 
  150. $pick_field_name = 'name'; 
  151. break; 
  152.  
  153. $sql = "SELECT `related_item_id` FROM `@wp_podsrel` WHERE `item_id` = %d AND `field_id` = %d"; 
  154.  
  155. $sql = array( $sql, array( $id, $field[ 'id' ] ) ); 
  156.  
  157. $result = pods_query( $sql, $this ); 
  158.  
  159. foreach ( $result as $row ) { 
  160. $selected_ids[] = $row->related_item_id; 
  161.  
  162. // Use default values for public forms 
  163. if ( empty( $selected_ids ) && !empty( $field[ 'default' ] ) ) { 
  164. $default_ids = $field[ 'default' ]; 
  165.  
  166. if ( !is_array( $field[ 'default' ] ) ) 
  167. $default_ids = explode( ', ', $default_ids ); 
  168.  
  169. foreach ( $default_ids as $default_id ) { 
  170. $default_id = pods_absint( $default_id ); 
  171.  
  172. if ( 0 < $default_id ) 
  173. $selected_ids[] = $default_id; 
  174.  
  175. // If the PICK field is unique, get values already chosen 
  176. $exclude = false; 
  177.  
  178. if ( 1 == $field[ 'unique' ] ) { 
  179. $unique_where = ( empty( $id ) ) ? '' : " AND `item_id` != %d"; 
  180.  
  181. $sql = "SELECT `related_item_id` FROM `@wp_podsrel` WHERE `field_id` = %d {$unique_where}"; 
  182.  
  183. $sql = array( $sql, array( $field[ 'id' ] ) ); 
  184.  
  185. if ( !empty( $id ) ) 
  186. $sql[ 1 ][] = $id; 
  187.  
  188. $result = pods_query( $sql, $this ); 
  189.  
  190. if ( !empty( $result ) ) { 
  191.  
  192. $exclude = array(); 
  193.  
  194. foreach ( $result as $row ) { 
  195. $exclude[] = (int) $row->related_item_id; 
  196.  
  197. $exclude = implode( ', ', $exclude ); 
  198.  
  199. if ( !empty( $field[ 'options' ][ 'pick_filter' ] ) ) 
  200. $pick_where .= ' AND ' . $field[ 'options' ][ 'pick_filter' ]; 
  201.  
  202. $params = array( 
  203. 'exclude' => $exclude,  
  204. 'selected_ids' => $selected_ids,  
  205. 'table' => $pick_table,  
  206. 'field_id' => $pick_field_id,  
  207. 'field_name' => $pick_field_name,  
  208. 'join' => $pick_join,  
  209. 'orderby' => $field[ 'options' ][ 'pick_orderby' ],  
  210. 'where' => $pick_where 
  211. ); 
  212.  
  213. $this->obj->row[ $key ] = $this->get_dropdown_values( $params ); 
  214. else { 
  215. // Set a default value if no value is entered 
  216. if ( !isset( $this->obj->row[ $key ] ) || ( null === $this->obj->row[ $key ] || false === $this->obj->row[ $key ] ) ) { 
  217. if ( !empty( $field[ 'default' ] ) ) 
  218. $this->obj->row[ $key ] = $field[ 'default' ]; 
  219. else 
  220. $this->obj->row[ $key ] = null; 
  221.  
  222. $this->obj->build_field_html( $field ); 
  223.  
  224. $uri_hash = wp_hash( $_SERVER[ 'REQUEST_URI' ] ); 
  225.  
  226. $save_button_atts = array( 
  227. 'type' => 'button',  
  228. 'class' => 'button btn_save',  
  229. 'value' => $label,  
  230. 'onclick' => "saveForm(1)" 
  231. ); 
  232.  
  233. $save_button_atts = apply_filters( 'pods_showform_save_button_atts', $save_button_atts, $this ); 
  234. $atts = ''; 
  235.  
  236. foreach ( $save_button_atts as $att => $value ) { 
  237. $atts .= ' ' . esc_attr( $att ) . '="' . esc_attr( $value ) . '"'; 
  238.  
  239. $save_button = '<input ' . $atts . '/>'; 
  240. ?> 
  241. <div> 
  242. <input type="hidden" class="form num id" value="<?php echo esc_attr( $id ); ?>" /> 
  243. <input type="hidden" class="form txt pod" value="<?php echo esc_attr( $pod ); ?>" /> 
  244. <input type="hidden" class="form txt pod_id" value="<?php echo esc_attr( $pod_id ); ?>" /> 
  245. <input type="hidden" class="form txt form_count" value="1" /> 
  246. <input type="hidden" class="form txt token" value="<?php echo esc_attr( pods_generate_key($pod, $uri_hash, $public_fields, 1) ); ?>" /> 
  247. <input type="hidden" class="form txt uri_hash" value="<?php echo esc_attr( $uri_hash ); ?>" /> 
  248. <?php echo apply_filters('pods_showform_save_button', $save_button, $save_button_atts, $this); ?> 
  249. </div> 
  250. <?php 
  251. do_action( 'pods_showform_post', $pod_id, $public_fields, $label, $this ); 
  252.  
  253. /** 
  254. * Get pod or category drop-down values 
  255. * @param array $params 
  256. * @return array 
  257. */ 
  258. public function get_dropdown_values ( $params ) { 
  259. if ( Pod::$deprecated_notice ) { 
  260. pods_deprecated( 'Pods::get_dropdown_values', '2.0' ); 
  261.  
  262. global $wpdb; 
  263.  
  264. $params = (object) $params; 
  265.  
  266. $params->orderby = empty( $params->orderby ) ? '' : ' ORDER BY ' . $params->orderby; 
  267. $params->join = empty( $params->join ) ? '' : ' LEFT JOIN ' . $params->join; 
  268.  
  269. $where = ( false !== $params->exclude ) ? "WHERE `t`.term_id NOT IN ({$params->exclude})" : ''; 
  270.  
  271. if ( !empty( $params->pick_filter ) ) { 
  272. $where .= ( empty( $where ) ? ' WHERE ' : ' AND ' ) . $params->pick_filter; 
  273.  
  274. if ( !empty( $params->where ) ) { 
  275. $where .= ( empty( $where ) ? ' WHERE ' : ' AND ' ) . $params->where; 
  276.  
  277. $sql = " 
  278. SELECT 
  279. `t`.`{$params->field_id}` AS `id`,  
  280. `t`.`{$params->field_name}` AS `name` 
  281. FROM `{$params->table}` AS `t` 
  282. {$params->join} 
  283. {$where} 
  284. {$params->orderby} 
  285. "; 
  286.  
  287. //override with custom dropdown values 
  288. $sql = apply_filters( 'pods_get_dropdown_values', $sql, $params, $this ); 
  289.  
  290. $val = array(); 
  291. $result = pods_query( $sql ); 
  292.  
  293. foreach ( $result as $row ) { 
  294. $row = get_object_vars( $row ); 
  295. $row[ 'active' ] = false; 
  296.  
  297. if ( !empty( $params->selected_ids ) ) 
  298. $row[ 'active' ] = in_array( $row[ 'id' ], $params->selected_ids ); 
  299.  
  300. $val[] = $row; 
  301.  
  302. return $val; 
  303.  
  304. /** 
  305. * Build public input form 
  306. * @deprecated deprecated since 2.0 
  307. */ 
  308. public function publicForm ( $fields = null, $label = 'Save Changes', $thankyou_url = null ) { 
  309. if ( Pod::$deprecated_notice ) { 
  310. pods_deprecated( 'Pods::publicForm', '2.0', 'Pods::form' ); 
  311.  
  312. if ( !empty( $fields ) ) { 
  313. // Just update field name here, form() will handle the rest 
  314. foreach ( $fields as $k => $field ) { 
  315. $name = $k; 
  316.  
  317. if ( !is_array( $field ) ) { 
  318. $name = $field; 
  319. $field = array(); 
  320. elseif ( isset( $field[ 'name' ] ) ) 
  321. $name = $field[ 'name' ]; 
  322.  
  323. if ( in_array( $name, array( 'created', 'modified', 'author' ) ) && isset( $this->obj->fields[ $name . '2' ] ) ) 
  324. $name .= '2'; 
  325.  
  326. $field[ 'name' ] = $name; 
  327.  
  328. $fields[ $k ] = $field; 
  329.  
  330. echo $this->obj->form( $fields, $label, $thankyou_url ); 
  331.  
  332. /** 
  333. * Build HTML for a single field 
  334. * @deprecated deprecated since 2.0 
  335. */ 
  336. public function build_field_html ( $field ) { 
  337. if ( Pod::$deprecated_notice ) { 
  338. pods_deprecated( 'Pods::build_field_html', '2.0' ); 
  339.  
  340. include PODS_DIR . 'deprecated/input_fields.php'; 
  341.  
  342. /** 
  343. * Fetch a row of results from the DB 
  344. * @since 1.2.0 
  345. * @deprecated deprecated since 2.0 
  346. */ 
  347. public function fetchRecord () { 
  348. if ( Pod::$deprecated_notice ) { 
  349. pods_deprecated( 'Pods::fetchRecord', '2.0', 'Pods::fetch' ); 
  350.  
  351. return $this->obj->fetch(); 
  352.  
  353. /** 
  354. * Return a field's value(s) 
  355. * @param string $name The field name 
  356. * @param string $orderby (optional) The orderby string, for PICK fields 
  357. * @since 1.2.0 
  358. * @deprecated deprecated since version 2.0 
  359. */ 
  360. public function get_field ( $name, $orderby = null ) { 
  361. if ( Pod::$deprecated_notice ) { 
  362. pods_deprecated( 'Pods::get_field', '2.0', 'Pods::field' ); 
  363.  
  364. $value = $this->obj->field( array( 'name' => $name, 'orderby' => $orderby, 'deprecated' => true ) ); 
  365.  
  366. if ( is_array( $value ) && !empty( $value ) ) { 
  367. if ( false === strpos( $name, '.' ) && !isset( $value[ 0 ] ) ) 
  368. $value = array( $value ); // fix for single tableless fields 
  369. elseif ( false !== strpos( $name, '.' ) && 1 == count( $value ) ) 
  370. $value = current( $value ); 
  371.  
  372. return $value; 
  373.  
  374. /** 
  375. * Get the current item's pod ID from its datatype ID and tbl_row_id 
  376. * @return int The ID from the wp_pod table 
  377. * @since 1.2.0 
  378. * @deprecated deprecated since version 2.0 
  379. */ 
  380. public function get_pod_id () { 
  381. if ( Pod::$deprecated_notice ) { 
  382. pods_deprecated( 'Pods::get_pod_id', '2.0' ); 
  383.  
  384. if ( !empty( $this->obj->row ) ) 
  385. return $this->obj->row[ $this->obj->data->field_id ]; 
  386.  
  387. return false; 
  388.  
  389. /** 
  390. * Search and filter records 
  391. * @since 1.x 
  392. * @deprecated deprecated since version 2.0 
  393. */ 
  394. public function findRecords ( $orderby = null, $rows_per_page = 15, $where = null, $sql = null ) { 
  395. if ( Pod::$deprecated_notice ) { 
  396. pods_deprecated( 'Pods::findRecords', '2.0', 'Pods::find' ); 
  397.  
  398. $find = array( 
  399. ' p.created',  
  400. '`p`.`created`',  
  401. '`p`.created',  
  402. ' p.`created`',  
  403. ' p.modified',  
  404. '`p`.`modified`',  
  405. '`p`.modified',  
  406. ' p.`modified`',  
  407. ' p.id',  
  408. '`p`.`id`',  
  409. '`p`.id',  
  410. ' p.`id`',  
  411. ' p.pod_id',  
  412. '`p`.`pod_id`',  
  413. '`p`.pod_id',  
  414. ' p.`pod_id`' 
  415. ); 
  416.  
  417. $replace = array( 
  418. ' t.created',  
  419. '`t`.`created`',  
  420. '`t`.created',  
  421. ' t.`created`',  
  422. ' t.modified',  
  423. '`t`.`modified`',  
  424. '`t`.modified',  
  425. ' t.`modified`',  
  426. ' t.id',  
  427. '`t`.`id`',  
  428. '`t`.id',  
  429. ' t.`id`',  
  430. ' t.id',  
  431. '`t`.`id`',  
  432. '`t`.id',  
  433. ' t.`id`' 
  434. ); 
  435.  
  436. $params = array( 
  437. 'where' => $where,  
  438. 'orderby' => "`t`.`{$this->obj->data->field_id}` DESC",  
  439. 'limit' => (int) $rows_per_page,  
  440. 'page' => $this->obj->page,  
  441. 'search' => $this->obj->search,  
  442. 'search_across' => true,  
  443. 'search_across_picks' => false,  
  444. 'sql' => $sql 
  445. ); 
  446.  
  447. if ( is_array( $orderby ) ) 
  448. $params = array_merge( $params, $orderby ); 
  449. elseif ( !empty( $orderby ) ) 
  450. $params[ 'orderby' ] = $orderby; 
  451.  
  452. $params[ 'where' ] = trim( str_replace( $find, $replace, ' ' . $params[ 'where' ] ) ); 
  453. $params[ 'orderby' ] = trim( str_replace( $find, $replace, ' ' . $params[ 'orderby' ] ) ); 
  454.  
  455. $params = (object) $params; 
  456.  
  457. $this->obj->limit = $params->limit; 
  458. $this->obj->page = $params->page; 
  459. $this->obj->search = $params->search; 
  460.  
  461. return $this->obj->find( $params ); 
  462.  
  463. /** 
  464. * Return a single record 
  465. * @since 1.x 
  466. * @deprecated deprecated since version 2.0 
  467. */ 
  468. public function getRecordById ( $id ) { 
  469. if ( Pod::$deprecated_notice ) { 
  470. pods_deprecated( 'Pods::getRecordById', '2.0', 'Pods::fetch_item' ); 
  471.  
  472. return $this->obj->fetch_item( $id ); 
  473.  
  474. /** 
  475. * Fetch the total row count 
  476. * @deprecated deprecated since version 2.0 
  477. */ 
  478. public function getTotalRows () { 
  479. if ( Pod::$deprecated_notice ) { 
  480. pods_deprecated( 'Pods::getTotalRows', '2.0', 'Pods::total_found' ); 
  481.  
  482. return $this->obj->total_found(); 
  483.  
  484. /** 
  485. * (Re)set the MySQL result pointer 
  486. * @deprecated deprecated since version 2.0 
  487. */ 
  488. public function resetPointer ( $row_number = 0 ) { 
  489. if ( Pod::$deprecated_notice ) { 
  490. pods_deprecated( 'Pods::resetPointer', '2.0', 'Pods::reset' ); 
  491.  
  492. return $this->obj->reset( $row_number ); 
  493.  
  494. /** 
  495. * Display the pagination controls 
  496. * @deprecated deprecated since 2.0 
  497. */ 
  498. public function getPagination ( $label = 'Go to page:' ) { 
  499. if ( Pod::$deprecated_notice ) { 
  500. pods_deprecated( 'Pods::getPagination', '2.0', 'Pods::pagination' ); 
  501.  
  502. echo $this->obj->pagination( array( 'type' => 'advanced', 'label' => $label ) ); 
  503.  
  504. /** 
  505. * Display the list filters 
  506. * @deprecated deprecated since 2.0 
  507. */ 
  508. public function getFilters ( $filters = null, $label = 'Filter', $action = '' ) { 
  509. if ( Pod::$deprecated_notice ) { 
  510. pods_deprecated( 'Pods::getFilters', '2.0', 'Pods::filters' ); 
  511.  
  512. $params = array( 
  513. 'fields' => $filters,  
  514. 'label' => $label,  
  515. 'action' => $action 
  516. ); 
  517.  
  518. if ( is_array( $filters ) ) 
  519. $params = array_merge( $params, $filters ); 
  520.  
  521. echo $this->obj->filters( $params ); 
  522.  
  523. /** 
  524. * Run a helper within a Pod Page or WP Template 
  525. * @param string $helper The helper name 
  526. * @return mixed Anything returned by the helper 
  527. * @since 1.2.0 
  528. * @deprecated deprecated since version 2.0 
  529. */ 
  530. public function pod_helper ( $helper_name, $value = null, $name = null ) { 
  531. if ( Pod::$deprecated_notice ) { 
  532. pods_deprecated( 'Pods::pod_helper', '2.0', 'Pods::helper' ); 
  533.  
  534. $params = array( 
  535. 'helper' => $helper_name,  
  536. 'value' => $value,  
  537. 'name' => $name,  
  538. 'deprecated' => true 
  539. ); 
  540.  
  541. return $this->obj->helper( $params ); 
  542.  
  543. /** 
  544. * Display the page template 
  545. * @deprecated deprecated since version 2.0 
  546. */ 
  547. public function showTemplate ( $template_name, $code = null ) { 
  548. if ( Pod::$deprecated_notice ) { 
  549. pods_deprecated( 'Pods::showTemplate', '2.0', 'Pods::template' ); 
  550.  
  551. return $this->obj->template( $template_name, $code, true );