Permalink
Browse files

Merge branch '2.0' of https://github.com/pods-framework/pods into 2.0

  • Loading branch information...
2 parents c5ecae1 + baaded8 commit a0e6fc4c870cdd16f2e2f9f6b4959a3e50a69811 @mikedamage mikedamage committed Aug 2, 2012
Showing with 813 additions and 69 deletions.
  1. +35 −19 classes/Pods.php
  2. +47 −5 classes/PodsAPI.php
  3. +11 −19 classes/PodsAdmin.php
  4. +323 −0 classes/PodsData.php
  5. +7 −3 classes/PodsInit.php
  6. +298 −0 classes/PodsMeta.php
  7. +5 −2 classes/fields/number.php
  8. +31 −6 classes/fields/text.php
  9. +52 −10 functions.php
  10. +3 −4 pods.php
  11. +1 −1 readme.txt
View
@@ -112,6 +112,7 @@ public function __construct ( $pod = null, $id = null ) {
$this->fields =& $this->api->fields;
$this->detail_page =& $this->data->detail_page;
$this->id =& $this->data->id;
+ $this->row =& $this->data->row;
$this->results =& $this->data->data;
if ( is_array( $id ) || is_object( $id ) )
@@ -186,16 +187,23 @@ public function field ( $params, $single = false ) {
return null;
}
+ if ( $this->data->field_id == $params->name ) {
+ if ( isset( $this->row[ $params->name ] ) )
+ return $this->row[ $params->name ];
+ else
+ return 0;
+ }
+
$value = null;
$tableless_field_types = $this->do_hook( 'tableless_field_types', array( 'pick', 'file' ) );
if ( 'detail_url' == $params->name )
$value = get_bloginfo( 'url' ) . '/' . $this->do_template( $this->detail_page );
- elseif ( isset( $this->fields[ $params->name ] ) && isset( $this->row[ $params->name ] ) ) {
+ elseif ( isset( $this->row[ $params->name ] ) ) {
$value = $this->row[ $params->name ];
- if ( in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) ) {
+ if ( isset( $this->fields[ $params->name ] ) && in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) ) {
if ( 'custom-simple' == $this->fields[ $params->name ][ 'pick_object' ] ) {
if ( empty( $value ) )
return array();
@@ -237,12 +245,16 @@ public function field ( $params, $single = false ) {
}
if ( !isset( $this->fields[ $params->name ] ) || !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) || $simple ) {
+ pods_no_conflict_on( $this->pod_data[ 'type' ] );
+
if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) )
- $value = get_post_meta( $this->id, $params->name, $params->single );
+ $value = get_post_meta( $this->id(), $params->name, $params->single );
elseif ( 'user' == $this->pod_data[ 'type' ] )
- $value = get_user_meta( $this->id, $params->name, $params->single );
+ $value = get_user_meta( $this->id(), $params->name, $params->single );
elseif ( 'comment' == $this->pod_data[ 'type' ] )
- $value = get_comment_meta( $this->id, $params->name, $params->single );
+ $value = get_comment_meta( $this->id(), $params->name, $params->single );
+
+ pods_no_conflict_off( $this->pod_data[ 'type' ] );
}
else {
// Not ready yet
@@ -395,12 +407,12 @@ public function index () {
public function find ( $params = null, $limit = 15, $where = null, $sql = null ) {
$defaults = array(
'table' => $this->data->table,
- 'select' => 't.*',
+ 'select' => '`t`.*',
'join' => null,
'where' => $where,
'groupby' => null,
'having' => null,
- 'orderby' => "`t`.`{$this->data->field_id}` DESC",
+ 'orderby' => null,
'limit' => (int) $limit,
'page' => (int) $this->page,
'search' => (boolean) $this->search,
@@ -421,10 +433,16 @@ public function find ( $params = null, $limit = 15, $where = null, $sql = null )
$this->page = (int) $params->page;
$this->search = (boolean) $params->search;
- // also need to do better search/filtering using search_mode and auto join stuff for pick/file fields
-
$params = $this->do_hook( 'find', $params );
+ // Add "`t`." prefix to $orderby if needed
+ if ( !empty( $params->orderby ) && false === strpos( $params->orderby, ',' ) && false === strpos( $params->orderby, '(' ) && false === strpos( $params->orderby, '.' ) ) {
+ if ( false !== strpos( $params->orderby, ' ASC' ) )
+ $params->orderby = '`t`.`' . trim( str_replace( array( '`', ' ASC' ), '', $params->orderby ) ) . '` ASC';
+ else
+ $params->orderby = '`t`.`' . trim( str_replace( array( '`', ' DESC' ), '', $params->orderby ) ) . '` DESC';
+ }
+
$this->data->select( $params );
return $this;
@@ -438,7 +456,7 @@ public function find ( $params = null, $limit = 15, $where = null, $sql = null )
public function fetch ( $id = null ) {
$this->do_hook( 'fetch', $id );
- $this->row =& $this->data->fetch( $id );
+ $this->data->fetch( $id );
return $this->row;
}
@@ -448,12 +466,10 @@ public function fetch ( $id = null ) {
*
* @since 2.0.0
*/
- public function reset ( $row = 0 ) {
- $this->do_hook( 'reset' );
-
- $row = pods_absint( $row );
+ public function reset ( $row = null ) {
+ $this->do_hook( 'reset', $row );
- $this->row =& $this->data->fetch( $row );
+ $this->data->reset( $row );
return $this->row;
}
@@ -527,7 +543,7 @@ public function save ( $data = null, $value = null, $id = null ) {
$data = array( $data => $value );
if ( null === $id )
- $id = $this->id;
+ $id = $this->id();
$data = (array) $this->do_hook( 'save', $data, $id );
@@ -546,7 +562,7 @@ public function save ( $data = null, $value = null, $id = null ) {
*/
public function delete ( $id = null ) {
if ( null === $id )
- $id = $this->id;
+ $id = $this->id();
$id = (int) $this->do_hook( 'delete', $id );
@@ -565,7 +581,7 @@ public function delete ( $id = null ) {
*/
public function duplicate ( $id = null ) {
if ( null === $id )
- $id = $this->id;
+ $id = $this->id();
$id = (int) $this->do_hook( 'duplicate', $id );
@@ -584,7 +600,7 @@ public function duplicate ( $id = null ) {
*/
public function export ( $fields = null, $id = null ) {
if ( null === $id )
- $id = $this->id;
+ $id = $this->id();
$fields = (array) $this->do_hook( 'export', $fields, $id );
View
@@ -84,6 +84,8 @@ public function delete_wp_object ( $object_type, $id, $force_delete = true ) {
* @param bool $strict Whether to delete previously saved meta not in $post_meta
*/
public function save_post( $post_data, $post_meta = null, $strict = false ) {
+ pods_no_conflict_on( 'post' );
+
if ( !is_array( $post_data ) || empty( $post_data ) )
return pods_error( __( 'Post data is required but is either invalid or empty', 'pods' ), $this );
@@ -95,11 +97,16 @@ public function save_post( $post_data, $post_meta = null, $strict = false ) {
else
wp_update_post( $post_data );
- if ( is_wp_error( $post_data[ 'ID' ] ) )
+ if ( is_wp_error( $post_data[ 'ID' ] ) ) {
+ pods_no_conflict_off( 'post' );
+
return pods_error( $post_data[ 'ID' ]->get_error_message(), $this );
+ }
$this->save_post_meta( $post_data[ 'ID' ], $post_meta, $strict );
+ pods_no_conflict_off( 'post' );
+
return $post_data[ 'ID' ];
}
@@ -111,6 +118,8 @@ public function save_post( $post_data, $post_meta = null, $strict = false ) {
* @param bool $strict Whether to delete previously saved meta not in $post_meta
*/
public function save_post_meta ( $id, $post_meta = null, $strict = false ) {
+ pods_no_conflict_on( 'post' );
+
if ( !is_array( $post_meta ) )
$post_meta = array();
@@ -147,6 +156,7 @@ public function save_post_meta ( $id, $post_meta = null, $strict = false ) {
delete_post_meta( $id, $meta_key, $meta_value );
}
}
+ pods_no_conflict_off( 'post' );
return $id;
}
@@ -162,6 +172,8 @@ public function save_user ( $user_data, $user_meta = null, $strict = false ) {
if ( !is_array( $user_data ) || empty( $user_data ) )
return pods_error( __( 'User data is required but is either invalid or empty', 'pods' ), $this );
+ pods_no_conflict_on( 'user' );
+
if ( !is_array( $user_meta ) )
$user_meta = array();
@@ -170,11 +182,16 @@ public function save_user ( $user_data, $user_meta = null, $strict = false ) {
else
wp_update_user( $user_data );
- if ( is_wp_error( $user_data[ 'ID' ] ) )
+ if ( is_wp_error( $user_data[ 'ID' ] ) ) {
+ pods_no_conflict_off( 'user' );
+
return pods_error( $user_data[ 'ID' ]->get_error_message(), $this );
+ }
$this->save_user_meta( $user_data[ 'ID' ], $user_meta, $strict );
+ pods_no_conflict_off( 'user' );
+
return $user_data[ 'ID' ];
}
@@ -186,6 +203,8 @@ public function save_user ( $user_data, $user_meta = null, $strict = false ) {
* @param bool $strict Whether to delete previously saved meta not in $user_meta
*/
public function save_user_meta ( $id, $user_meta = null, $strict = false ) {
+ pods_no_conflict_on( 'user' );
+
if ( !is_array( $user_meta ) )
$user_meta = array();
@@ -211,6 +230,8 @@ public function save_user_meta ( $id, $user_meta = null, $strict = false ) {
}
}
+ pods_no_conflict_off( 'user' );
+
return $id;
}
@@ -225,6 +246,8 @@ public function save_comment ( $comment_data, $comment_meta = null, $strict = fa
if ( !is_array( $comment_data ) || empty( $comment_data ) )
return pods_error( __( 'Comment data is required but is either invalid or empty', 'pods' ), $this );
+ pods_no_conflict_on( 'comment' );
+
if ( !is_array( $comment_meta ) )
$comment_meta = array();
@@ -233,11 +256,16 @@ public function save_comment ( $comment_data, $comment_meta = null, $strict = fa
else
wp_update_comment( $comment_data );
- if ( is_wp_error( $comment_data[ 'comment_ID' ] ) )
+ if ( is_wp_error( $comment_data[ 'comment_ID' ] ) ) {
+ pods_no_conflict_off( 'comment' );
+
return pods_error( $comment_data[ 'comment_ID' ]->get_error_message(), $this );
+ }
$this->save_comment_meta( $comment_data[ 'comment_ID' ], $comment_meta, $strict );
+ pods_no_conflict_off( 'comment' );
+
return $comment_data[ 'comment_ID' ];
}
@@ -249,6 +277,8 @@ public function save_comment ( $comment_data, $comment_meta = null, $strict = fa
* @param bool $strict Whether to delete previously saved meta not in $comment_meta
*/
public function save_comment_meta ( $id, $comment_meta = null, $strict = false ) {
+ pods_no_conflict_on( 'comment' );
+
if ( !is_array( $comment_meta ) )
$comment_meta = array();
@@ -274,6 +304,8 @@ public function save_comment_meta ( $id, $comment_meta = null, $strict = false )
}
}
+ pods_no_conflict_off( 'comment' );
+
return $id;
}
@@ -286,6 +318,8 @@ public function save_comment_meta ( $id, $comment_meta = null, $strict = false )
* @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
*/
public function save_term ( $term_ID, $term, $taxonomy, $term_data ) {
+ pods_no_conflict_on( 'taxonomy' );
+
if( !is_array( $term_data ) )
$term_data = array();
@@ -295,17 +329,25 @@ public function save_term ( $term_ID, $term, $taxonomy, $term_data ) {
if ( 0 < strlen( $term ) )
$term_data[ 'term' ] = $term;
- if ( empty( $term_data ) )
+ if ( empty( $term_data ) ) {
+ pods_no_conflict_off( 'taxonomy' );
+
return pods_error( __( 'Taxonomy term data is required but is either invalid or empty', 'pods' ), $this );
+ }
wp_update_term( $term_ID, $taxonomy, $term_data );
}
- if ( is_wp_error( $term_ID ) )
+ if ( is_wp_error( $term_ID ) ) {
+ pods_no_conflict_off( 'taxonomy' );
+
return pods_error( $term_ID->get_error_message(), $this );
+ }
elseif ( is_array( $term_ID ) )
$term_ID = $term_ID[ 'term_id' ];
+ pods_no_conflict_off( 'taxonomy' );
+
return $term_ID;
}
Oops, something went wrong.

0 comments on commit a0e6fc4

Please sign in to comment.