Skip to content

Commit

Permalink
Release 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
quasel committed May 17, 2017
1 parent 10fedc3 commit eb63b9c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 115 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ The Template Field Connection for Archive Pages is planned, meahnwhile you cna j

## Planned:
- add settings/code for output_type ( e.g IMAGES as url, image-link, ...)
- add settings/code for image_size (depending on BB )
- Add Support to Select Templates http://pods.io/tutorials/how-tos-sceencasts-series/using-pods-templates-part-1/ use `[pods template='your_template']` or similar shortcode




Expand Down
146 changes: 45 additions & 101 deletions classes/class-pods-page-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ static public function get_field_display( $settings, $property ) {

$content = pods( get_post_type(), get_the_ID() )->display( $settings->field );

// return is_string( $content ) ? $content : '';
return $content;
}

Expand All @@ -56,13 +55,14 @@ static public function get_field_display_url( $settings, $property ) {
*/
static public function get_field_multiple_photos( $settings, $property ) {

// $content = pods( get_post_type(), get_the_ID() )->display($settings->field)."<hr><pre>".print_r( pods( get_post_type(), get_the_ID() )->field($settings->field) )."<hr><hr></pre>";

$field_ID = $settings->field . '.ID';
$content = pods( get_post_type(), get_the_ID() )->field( $field_ID );

if ( ! is_array( $content ) ) {
$content = array( $content );
}

return $content;
// return is_string($content) ? $content : '';
}

/**
Expand Down Expand Up @@ -122,49 +122,10 @@ static public function get_template( $settings, $property ) {
static public function pods_get_fields( $field_options = array() ) {
global $post;

$location = explode( ':', FLThemeBuilderRulesLocation::get_preview_location( $post->ID ) );
$pod_name = $location[1];


// change to just get_post_type() ?
$fields = array();
$pods = pods_api()->load_pods( array( 'names' => true ) );

$location = FLThemeBuilderRulesLocation::get_preview_location( $post->ID );
$location = explode( ':', $location );

$test_load = pods_api()->load_pod( array( 'name' => $location[1] ), false );

$field_options['name'] = $location[1];


$all_fields = self::recurse_pod_fields( $field_options );

$pods = array( $location[1] => 'current' );
// check for xxx_formate_type

foreach ( $pods as $name => $label ) {
$pod = pods( $name );
$pod_fields = $pod->fields();


foreach ( $pod_fields as $field_name => $_field ) {
if ( $field_options ) {
if ( $field_options['type'] == $_field['type'] ) {
foreach ( $field_options['options'] as $_option => $option_value ) {
if ( $option_value !== pods_v( $_option, $_field['options'] ) ) { //$pod->fields( $field_name, 'file_type' )
continue 2; // if one option it not matched we don't need the field -> go check the next one
}
}

} else {
continue 1;
}
}
$fields[ $field_name ] .= $_field['name'] . " (" . $name . ") ";


}

}
$all_fields = self::recurse_pod_fields( $pod_name, $field_options );

return $all_fields;
}
Expand Down Expand Up @@ -196,7 +157,7 @@ static public function pods_get_url_fields() {
static public function pods_get_image_fields() {
$field_options['type'] = 'file';
// $field_options['options']['file_type'] = 'images';
// $field_options['options']['file_format_type'] = 'single';
$field_options['options']['file_format_type'] = 'single';
// $field_options['options']['file_uploader'] = 'attachment';
$fields = self::pods_get_fields( $field_options );

Expand All @@ -213,8 +174,8 @@ static public function pods_get_image_fields() {
*/
static public function pods_get_multiple_images_fields() {
$field_options['type'] = 'file';
$field_options['options']['file_type'] = 'images';
$field_options['options']['file_format_type'] = 'multi';
// $field_options['options']['file_type'] = 'images';
// $field_options['options']['file_format_type'] = 'multi';
$fields = self::pods_get_fields( $field_options );

return $fields;
Expand Down Expand Up @@ -337,80 +298,63 @@ static public function pods_settings_form() {
return $form;
}

private function recurse_pod_fields( $params, $prefix = '', &$pods_visited = array() ) {

$pod_name = $params['name'];
/**
* @param string $pod_name
* @param array $field_options (based on pod_data array
* @param string $prefix
* @param array $pods_visited
*
* @return array
*/
private function recurse_pod_fields( $pod_name, $field_options = array(), $prefix = '', &$pods_visited = array() ) {

$fields = array();
if ( empty( $pod_name ) ) {
return $fields;
}
$pod = pods( $pod_name );
$all_pod_fields = array();
$recurse_queue = array();


foreach ( $pod->pod_data['object_fields'] as $name => $field ) {
// Add WordPress object fields
/* if ( isset( $params['type'] ) ) {
if ( $params['type'] === $field['type'] && 'attachment' === $field['options']['file_uploader'] ) {
$fields[ $prefix . $name ] = $prefix . $name;
}
} else {
$fields[ $prefix . $name ] = $prefix . $name;
}
$all_pod_fields[ $name ] = $field;*/
$all_pod_fields = array_merge( $pod->pod_data['object_fields'], $pod->fields() );


foreach ( $all_pod_fields as $field_name => $field ) {
if ( 'taxonomy' === $field['type'] ) {
$linked_pod = $name;
if ( ! isset( $pods_visited[ $linked_pod ] ) || ! in_array( $name, $pods_visited[ $linked_pod ] ) ) {
$pods_visited[ $linked_pod ][] = $name;
$recurse_queue[ $linked_pod ] = "{$prefix}{$name}.";
$linked_pod = $field_name;
if ( ! isset( $pods_visited[ $linked_pod ] ) || ! in_array( $field_name, $pods_visited[ $linked_pod ] ) ) {
$pods_visited[ $linked_pod ][] = $field_name;
$recurse_queue[ $linked_pod ] = "{$prefix}{$field_name}.";
}
}

}

$all_pod_fields = array_merge( $pod->pod_data['object_fields'], $pod->fields() );
foreach ( $all_pod_fields as $name => $field ) {
// Add base field name
if ( isset( $params['type'] ) ) {
if ( $params['type'] === $field['type'] && 'attachment' === $field['options']['file_uploader'] ) {
$fields[ $prefix . $name ] = $prefix . $name;
if ( ! empty( $field['table_info'] ) && ! empty( $field['table_info']['pod'] ) ) {
$linked_pod = $field['table_info']['pod']['name'];
if ( ! isset( $pods_visited[ $linked_pod ] ) || ! in_array( $field_name, $pods_visited[ $linked_pod ] ) ) {
$pods_visited[ $linked_pod ][] = $field_name;
$recurse_queue[ $linked_pod ] = "{$prefix}{$field_name}.";
}
} else {
$fields[ $prefix . $name ] = $prefix . $name;

}

// Field type specific handling
if ( 'file' === $field['type'] && 'attachment' === $field['options']['file_uploader'] ) {
/* $fields[] = $prefix . $name . '._src';
$fields[] = $prefix . $name . '._img';
$sizes = get_intermediate_image_sizes();
foreach ( $sizes as $size ) {
$fields[] = "{$prefix}{$name}._src.{$size}";
if ( 'multi' != $field['options']['file_format_type'] ) {
$fields[] = "{$prefix}{$name}._src_relative.{$size}";
$fields[] = "{$prefix}{$name}._src_schemeless.{$size}";
}
$fields[] = "{$prefix}{$name}._img.{$size}";
}*/

} elseif ( ! empty( $field['table_info'] ) && ! empty( $field['table_info']['pod'] ) ) {
$linked_pod = $field['table_info']['pod']['name'];
if ( ! isset( $pods_visited[ $linked_pod ] ) || ! in_array( $name, $pods_visited[ $linked_pod ] ) ) {
$pods_visited[ $linked_pod ][] = $name;
$recurse_queue[ $linked_pod ] = "{$prefix}{$name}.";
}
if ( $field_options ) {
if ( $field_options['type'] === $field['type'] ) {
foreach ( $field_options['options'] as $_option => $option_value ) {
if ( $option_value !== pods_v( $_option, $field['options'] ) ) {
continue 2; // don't check further if one option it not matched
}
}

} else {
continue 1; // don't add to $fields if type doesn't match
}
}
$fields[ $prefix . $field_name ] = $prefix . $field_name . " (" . $pod_name . ") ";

}

foreach ( $recurse_queue as $recurse_name => $recurse_prefix ) {
$params['name'] = $recurse_name;
$fields = array_merge( $fields, self::recurse_pod_fields( $params, $recurse_prefix, $pods_visited ) );
$fields = array_merge( $fields, self::recurse_pod_fields( $recurse_name, $field_options, $recurse_prefix, $pods_visited ) );
}

return $fields;
Expand Down
24 changes: 12 additions & 12 deletions includes/pods-page-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
'type' => 'select',
'label' => __( 'Field Name (CPT):', 'fl-theme-builder' ),
'options' => 'PodsPageData::pods_get_fields',
'help' => __( 'If two CPT have a field with the same name - the field is only listed once - this way you could use the same Template for diffrent CPT if they use the same field names.)', 'fl-theme-builder' ),
'description' => __( 'Select one!', 'fl-theme-builder' ),
'help' => __( 'Fields filterd based on current "preview" settings', 'fl-theme-builder' ),
'description' => __( 'Fields based on Preview', 'fl-theme-builder' ),
'placeholder' => __( 'Field Name (CPT)', 'fl-theme-builder' ),
'toggle' => array(),
),
Expand Down Expand Up @@ -47,8 +47,8 @@
'type' => 'select',
'label' => __( 'Field Name (CPT):', 'fl-theme-builder' ),
'options' => 'PodsPageData::pods_get_url_fields',
'help' => __( 'If two CPT have a field with the same name - the field is only listed once - this way you could use the same Template for diffrent CPT if they use the same field names.)', 'fl-theme-builder' ),
'description' => __( 'Select one', 'fl-theme-builder' ),
'help' => __( 'Fields filterd based on current "preview" settings', 'fl-theme-builder' ),
'description' => __( 'Fields based on Preview', 'fl-theme-builder' ),
'placeholder' => __( 'Field Name (CPT)', 'fl-theme-builder' )
)
);
Expand All @@ -73,8 +73,8 @@
'type' => 'select',
'label' => __( 'Field Name (CPT):', 'fl-theme-builder' ),
'options' => 'PodsPageData::pods_get_multiple_images_fields',
'help' => __( 'If two CPT have a field with the same name - the field is only listed once - this way you could use the same Template for diffrent CPT if they use the same field names.)', 'fl-theme-builder' ),
'description' => __( 'Select one', 'fl-theme-builder' ),
'help' => __( 'Fields filterd based on current "preview" settings', 'fl-theme-builder' ),
'description' => __( 'Fields based on Preview', 'fl-theme-builder' ),
)
);

Expand All @@ -98,8 +98,8 @@
'type' => 'select',
'label' => __( 'Field Name (CPT):', 'fl-theme-builder' ),
'options' => 'PodsPageData::pods_get_image_fields',
'help' => __( 'If two CPT have a field with the same name - the field is only listed once - this way you could use the same Template for diffrent CPT if they use the same field names.)', 'fl-theme-builder' ),
'description' => __( 'Select one', 'fl-theme-builder' ),
'help' => __( 'Fields filterd based on current "preview" settings', 'fl-theme-builder' ),
'description' => __( 'Fields based on Preview', 'fl-theme-builder' ),
'placeholder' => __( 'Field Name (CPT)', 'fl-theme-builder' ),
),
'image_size' => array(
Expand Down Expand Up @@ -134,8 +134,8 @@
'type' => 'select',
'label' => __( 'Field Name (CPT):', 'fl-theme-builder' ),
'options' => 'PodsPageData::pods_get_templates',
'help' => __( 'If two CPT have a field with the same name - the field is only listed once - this way you could use the same Template for diffrent CPT if they use the same field names.)', 'fl-theme-builder' ),
'description' => __( 'Select one', 'fl-theme-builder' ),
'help' => __( 'Fields filterd based on current "preview" settings', 'fl-theme-builder' ),
'description' => __( 'Fields based on Preview', 'fl-theme-builder' ),
'placeholder' => __( 'Field Name (CPT)', 'fl-theme-builder' )
)
);
Expand All @@ -150,7 +150,7 @@
* Pods All using Magic Tag Syntax
*/
$data = array(
'label' => __( 'Advanced (Text Field)', 'fl-theme-builder' ),
'label' => __( 'Advanced Magic Tag (improvements in a future release)', 'fl-theme-builder' ),
'group' => 'pods',
'type' => array( 'string', 'html', 'custom_field', 'photo', 'multiple-photos' ),
'getter' => 'PodsPageData::get_field_display',
Expand All @@ -162,7 +162,7 @@
'type' => 'text',
'label' => __( 'Field Name (CPT):', 'fl-theme-builder' ),
'options' => 'PodsPageData::pods_get_fields',
'help' => __( 'If two CPT have a field with the same name - the field is only listed once - this way you could use the same Template for diffrent CPT if they use the same field names.)', 'fl-theme-builder' ),
'help' => __( 'Fields based on current "preview" settings', 'fl-theme-builder' ),
'description' => __( 'Field Name', 'fl-theme-builder' ),
'placeholder' => __( 'Field Name (CPT)', 'fl-theme-builder' )

Expand Down
10 changes: 10 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ To be done ;)

== Changelog ==

= 0.3-beta - May 17, 2017 =

* Added Support to Select Templates http://pods.io/tutorials/how-tos-sceencasts-series/using-pods-templates-part-1/ you cna use `[pods template='your_template']` or similar shortcode too
* Major Cleanup
* introduced recurse_pod_fields() for filtering and creating the dropwdon
* Fixed Multiple Images if single field is selected
* Minor Bug fixes & Improvments
* added settings for image_size


= 0.2.1-beta - May 9, 2017 =

* fixed single image field filtering ( wrong logic )
Expand Down

0 comments on commit eb63b9c

Please sign in to comment.