diff --git a/README.md b/README.md index 84bbab9..404646d 100644 --- a/README.md +++ b/README.md @@ -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 + diff --git a/classes/class-pods-page-data.php b/classes/class-pods-page-data.php index 15b42f0..f739f97 100644 --- a/classes/class-pods-page-data.php +++ b/classes/class-pods-page-data.php @@ -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; } @@ -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)."
".print_r( pods( get_post_type(), get_the_ID() )->field($settings->field) )."

"; - $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 : ''; } /** @@ -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; } @@ -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 ); @@ -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; @@ -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; diff --git a/includes/pods-page-data.php b/includes/pods-page-data.php index 5846b6a..5993dbf 100644 --- a/includes/pods-page-data.php +++ b/includes/pods-page-data.php @@ -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(), ), @@ -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' ) ) ); @@ -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' ), ) ); @@ -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( @@ -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' ) ) ); @@ -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', @@ -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' ) diff --git a/readme.txt b/readme.txt index 131bb3a..ac10abc 100755 --- a/readme.txt +++ b/readme.txt @@ -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 )