Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/release/2.7' into f…
Browse files Browse the repository at this point in the history
…eature/#3967
  • Loading branch information
JoryHogeveen committed May 17, 2017
2 parents 6abfd41 + 53b09bc commit ba8e959
Show file tree
Hide file tree
Showing 53 changed files with 2,735 additions and 2,040 deletions.
17 changes: 9 additions & 8 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
exclude_paths:
- vendor/*
- tests/*
- .tx/*,
- includes/libraries/*,
- bin/*
- assets/*
- templates/*
- ui/js/select2/*
- vendor/*
- tests/*
- .tx/*
- includes/libraries/*
- bin/*
- assets/*
- templates/*
- ui/js/select2/*

engines:
phpcodesniffer:
enabled: true
config:
standard: "WordPress"

1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"esnext": true,
"esversion": 6,
"mocha": true,
"module": true,
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# [Pods Framework](http://pods.io) #
[![Travis](https://secure.travis-ci.org/pods-framework/pods.png?branch=2.x)](http://travis-ci.org/pods-framework/pods)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/pods-framework/pods/badges/quality-score.png?b=2.x)](https://scrutinizer-ci.com/g/pods-framework/pods/?branch=2.x)
[![Dependency Status](https://gemnasium.com/badges/github.com/pods-framework/pods.svg)](https://gemnasium.com/github.com/pods-framework/pods)
[![License](https://img.shields.io/badge/license-GPL--2.0%2B-green.svg)](https://github.com/pods-framework/pods/blob/2.x/license.txt)
[![Code Climate](https://codeclimate.com/github/pods-framework/pods/badges/gpa.svg)](https://codeclimate.com/github/pods-framework/pods)

[![WordPress Plugin version](https://img.shields.io/wordpress/plugin/v/pods.svg?style=flat)](https://wordpress.org/plugins/pods/)
[![WordPress Plugin WP tested version](https://img.shields.io/wordpress/v/pods.svg?style=flat)](https://wordpress.org/plugins/pods/)
Expand Down
Empty file modified bin/install-wp-tests.sh
100644 → 100755
Empty file.
Empty file modified bin/vagrant-wp-tests.sh
100644 → 100755
Empty file.
66 changes: 51 additions & 15 deletions classes/Pods.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,17 +692,17 @@ public function field ( $name, $single = null, $raw = false ) {
}
elseif ( null === $params->output ) {
/**
* Override the way realted fields are output
* Override the way related fields are output
*
* @param string $output How to output related fields. Default is 'arrays'. Options: id|name|object|array|pod
* @param array|object $row Current row being outputted.
* @param array $params Params array passed to field().
* @param object|Pods $this Current Pods object.
* @param string $output How to output related fields. Default is 'arrays'. Options: ids|names|objects|arrays|pods|find
* @param array|object $row Current row being outputted.
* @param array $params Params array passed to field().
* @param Pods $this Current Pods object.
*/
$params->output = apply_filters( 'pods_pods_field_related_output_type', 'arrays', $this->row, $params, $this );
}

if ( in_array( $params->output, array( 'id', 'name', 'object', 'array', 'pod' ) ) )
if ( in_array( $params->output, array( 'id', 'name', 'object', 'array', 'pod' ), true ) )
$params->output .= 's';

// Support old $orderby variable
Expand Down Expand Up @@ -1153,7 +1153,7 @@ public function field ( $name, $single = null, $raw = false ) {
}

// Tableless handler
if ( $field_exists && ( !in_array( $all_fields[ $pod ][ $field ][ 'type' ], array( 'pick', 'taxonomy' ) ) || !$simple ) ) {
if ( $field_exists && ( !in_array( $all_fields[ $pod ][ $field ][ 'type' ], array( 'pick', 'taxonomy', 'comment' ) ) || !$simple ) ) {
$type = $all_fields[ $pod ][ $field ][ 'type' ];
$pick_object = $all_fields[ $pod ][ $field ][ 'pick_object' ];
$pick_val = $all_fields[ $pod ][ $field ][ 'pick_val' ];
Expand Down Expand Up @@ -1269,6 +1269,13 @@ public function field ( $name, $single = null, $raw = false ) {
*/
$related_obj = false;

// Check if we can return the full object/array or if we need to traverse into it
$is_field_output_full = false;

if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types ) && !$simple ) ) {
$is_field_output_full = true;
}

if ( 'pod' == $object_type )
$related_obj = pods( $object, null, false );
elseif ( !empty( $table[ 'pod' ] ) )
Expand All @@ -1288,7 +1295,7 @@ public function field ( $name, $single = null, $raw = false ) {
);

// Output types
if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ) ) )
if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ), true ) )
$sql[ 'select' ] = '`t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
$sql[ 'select' ] = '`t`.`' . $table[ 'field_index' ] . '` AS `pod_item_index`, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
Expand All @@ -1302,14 +1309,34 @@ public function field ( $name, $single = null, $raw = false ) {
$sql[ 'where' ] = array_merge( (array) $where, (array) $params->params['where' ] );
}

$item_data = array();

if ( empty( $related_obj ) ) {
if ( !is_object( $this->alt_data ) )
if ( ! is_object( $this->alt_data ) ) {
$this->alt_data = pods_data( null, 0, true, true );
}

$item_data = $this->alt_data->select( $sql );
} else {
// Support 'find' output ordering
if ( 'find' === $params->output && $is_field_output_full && empty( $sql['orderby'] ) && $ids ) {
// Handle default orderby for ordering by the IDs
$order_ids = implode( ', ', array_map( 'absint', $ids ) );

$sql['orderby'] = 'FIELD( `t`.`' . $table[ 'field_id' ] . '`, ' . $order_ids . ' )';
}

$related_obj->find( $sql );

// Support 'find' output
if ( 'find' === $params->output && $is_field_output_full ) {
$data = $related_obj;

$is_field_output_full = true;
} else {
$item_data = $related_obj->data();
}
}
else
$item_data = $related_obj->find( $sql )->data();

$items = array();

Expand Down Expand Up @@ -1417,7 +1444,7 @@ public function field ( $name, $single = null, $raw = false ) {
}

// Return entire array
if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types ) && !$simple ) )
if ( $is_field_output_full )
$value = $data;
// Return an array of single column values
else {
Expand All @@ -1442,14 +1469,23 @@ public function field ( $name, $single = null, $raw = false ) {
elseif ( ( ( 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() ) ) ) {
$size = 'full';

if ( false === strpos( 'image', get_post_mime_type( $item_id ) ) ) {
// No default sizes for non-images. When a size is defined this will be overwritten.
$size = null;
}

if ( false !== strpos( $full_field, '_src.' ) && 5 < strlen( $full_field ) )
$size = substr( $full_field, 5 );
elseif ( false !== strpos( $full_field, '_src_relative.' ) && 14 < strlen( $full_field ) )
$size = substr( $full_field, 14 );
elseif ( false !== strpos( $full_field, '_src_schemeless.' ) && 16 < strlen( $full_field ) )
$size = substr( $full_field, 16 );

$value_url = pods_image_url( $item_id, $size );
if ( $size ) {
$value_url = pods_image_url( $item_id, $size );
} else {
$value_url = wp_get_attachment_url( $item_id );
}

if ( false !== strpos( $full_field, '_src_relative' ) && !empty( $value_url ) ) {
$value_url_parsed = parse_url( $value_url );
Expand Down Expand Up @@ -1531,7 +1567,7 @@ public function field ( $name, $single = null, $raw = false ) {

$value = PodsForm::field_method( 'pick', 'simple_value', $field, $value, $last_options, $all_fields[ $pod ], 0, true );
}
elseif ( false === $params->in_form && !empty( $value ) )
elseif ( false === $params->in_form && !empty( $value ) && is_array( $value ) )
$value = array_values( $value );

// Return a single column value
Expand Down Expand Up @@ -3980,6 +4016,6 @@ public function __toString() {
}

return $string;

}
}
55 changes: 48 additions & 7 deletions classes/PodsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,18 @@ public function get_wp_object_fields ( $object = 'post_type', $pod = null, $refr
'type' => 'number',
'alias' => array(),
'hidden' => true
),
'comments' => array(
'name' => 'comments',
'label' => 'Comments',
'type' => 'comment',
'pick_object' => 'comment',
'pick_val' => 'comment',
'alias' => array(),
'hidden' => true,
'options' => array(
'comment_format_type' => 'multi'
)
)
);

Expand Down Expand Up @@ -3405,6 +3417,7 @@ public function save_pod_item ( $params ) {
$field_data[ 'value' ] = $value;

if ( isset( $object_fields[ $field ] ) ) {
// @todo Eventually support 'comment' field type saving here too
if ( 'taxonomy' == $object_fields[ $field ][ 'type' ] ) {
$post_term_data[ $field ] = $value;
}
Expand Down Expand Up @@ -4243,6 +4256,7 @@ public function duplicate_pod_item ( $params ) {

if ( in_array( $pod->pod_data['type'], array( 'post_type', 'media' ) ) ) {
$ignore_fields = array(
'ID',
'post_name',
'post_date',
'post_date_gmt',
Expand All @@ -4252,16 +4266,21 @@ public function duplicate_pod_item ( $params ) {
);
} elseif ( 'term' == $pod->pod_data['type'] ) {
$ignore_fields = array(
'term_id',
'term_taxonomy_id',
'slug',
);
} elseif ( 'user' == $pod->pod_data['type'] ) {
$ignore_fields = array(
'ID',
'user_nicename',
);
} elseif ( 'comment' == $pod->pod_data['type'] ) {
$ignore_fields = array(
'comment_ID',
);
} elseif ( 'settings' == $pod->pod_data['type'] ) {
return pods_error( __( 'Settings do not support duplication.', 'pods' ), $this );
}

/**
Expand Down Expand Up @@ -6785,6 +6804,9 @@ public function load_sister_fields ( $params, $pod = null ) {
$params->related_pod = pods_str_replace( 'taxonomy-', '', $params->related_pod, 1 );
$type = 'taxonomy';
}
elseif ( 'comment' === $params->related_pod ) {
$type = $params->related_pod;
}

$related_pod = $this->load_pod( array( 'name' => $params->related_pod, 'table_info' => false ), false );

Expand Down Expand Up @@ -7026,8 +7048,18 @@ public function lookup_related_items ( $field_id, $pod_id, $ids, $field = null,
if ( !is_wp_error( $related ) ) {
$related_ids = $related;
}
}
elseif ( !pods_tableless() ) {
} elseif ( 'comment' == $field_type ) {
$comment_args = array(
'post__in' => $ids,
'fields' => 'ids',
);

$related = get_comments( $comment_args );

if ( ! is_wp_error( $related ) ) {
$related_ids = $related;
}
} elseif ( !pods_tableless() ) {
$ids = implode( ', ', $ids );

$field_id = (int) $field_id;
Expand Down Expand Up @@ -8071,7 +8103,7 @@ public function import ( $import_data, $numeric_mode = false, $format = null ) {
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
$where = "`tt`.`term_id` = " . pods_absint( $pick_value );

$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 );
$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` LIMIT 1", $this );

if ( !empty( $result ) )
$pick_values[] = $result[ 0 ]->id;
Expand All @@ -8082,7 +8114,7 @@ public function import ( $import_data, $numeric_mode = false, $format = null ) {
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
$where = "`ID` = " . pods_absint( $pick_value );

$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID`", $this );
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID` LIMIT 1", $this );

if ( !empty( $result ) )
$pick_values[] = $result[ 0 ]->id;
Expand All @@ -8093,15 +8125,15 @@ public function import ( $import_data, $numeric_mode = false, $format = null ) {
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
$where = "`ID` = " . pods_absint( $pick_value );

$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID`", $this );
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );

if ( !empty( $result ) )
$pick_values[] = $result[ 0 ]->id;
}
elseif ( in_array( 'comment', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
$where = "`comment_ID` = " . pods_absint( $pick_value );

$result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID`", $this );
$result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );

if ( !empty( $result ) )
$pick_values[] = $result[ 0 ]->id;
Expand All @@ -8114,7 +8146,7 @@ public function import ( $import_data, $numeric_mode = false, $format = null ) {
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
$where = "`" . $related_pod[ 'field_id' ] . "` = " . pods_absint( $pick_value );

$result = pods_query( "SELECT `" . $related_pod[ 'field_id' ] . "` AS `id` FROM `" . $related_pod[ 'table' ] . "` WHERE {$where} ORDER BY `" . $related_pod[ 'field_id' ] . "`", $this );
$result = pods_query( "SELECT `" . $related_pod[ 'field_id' ] . "` AS `id` FROM `" . $related_pod[ 'table' ] . "` WHERE {$where} ORDER BY `" . $related_pod[ 'field_id' ] . "` LIMIT 1", $this );

if ( !empty( $result ) )
$pick_values[] = $result[ 0 ]->id;
Expand Down Expand Up @@ -8319,6 +8351,15 @@ public function process_form ( $params, $obj = null, $fields = null, $thank_you

$id = $this->save_pod_item( $params );

/**
* Fires after the form has been processed and save_pod_item has run.
*
* @param int $id Item ID.
* @param array $params save_pod_item parameters.
* @param null|Pods $obj Pod object (if set).
*/
do_action( 'pods_api_processed_form', $id, $params, $obj );

if ( 0 < $id && !empty( $thank_you ) ) {
$thank_you = str_replace( 'X_ID_X', $id, $thank_you );

Expand Down
Loading

0 comments on commit ba8e959

Please sign in to comment.