Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
quasel committed Feb 25, 2017
1 parent 86ef3cb commit a9e7140
Show file tree
Hide file tree
Showing 6 changed files with 820 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .gitignore
@@ -0,0 +1,76 @@
# Created by .ignore support plugin (hsz.mobi)
### Sass template
.sass-cache/
*.css.map
### macOS template
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

253 changes: 253 additions & 0 deletions classes/class-pods-page-data.php
@@ -0,0 +1,253 @@
<?php

/**
* Handles logic for page data Pods properties.
*
* @since 1.0
*/
final class PodsPageData {
/**
* @since 1.0
*
*/
static public function init() {
FLPageData::add_group( 'pods', array(
'label' => __( 'Pods', 'fl-theme-builder' )
) );
}

/**
*
* Just Basic Field Display
* @todo add settings/code for qutput_type ( e.g IMAGES as url, image-link, ...)
* @todo add settings/code for image_size
*
*
* @since 1.0
* @return string
*/
static public function get_field_display( $settings, $property ) {

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

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

/**
*
* Basic URL
*
* @since 1.0
* @return string
*/
static public function get_field_display_url( $settings, $property ) {

return esc_url( self::get_field_display( $settings, $property ) );
}


/**
*
* Multiple Photos - Returns an array of Image Gallery ID's
*
* @since 1.0
* @return array
*/
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 = $settings->field . '.ID';
$content = pods( get_post_type(), get_the_ID() )->field( $field );

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

/**
*
* Single Image / Photo - Returns Image Gallery ID && URL
*
* @since 1.0
*
* @param $settings
* @param $property
*
* @return array
*/
static public function get_field_photo( $settings, $property ) {

$field_id = $settings->field . '.ID';

$content = array(
'id' => pods( get_post_type(), get_the_ID() )->display( $field_id ),
'url' => pods( get_post_type(), get_the_ID() )->display( $settings->field )
);

return $content;
}


/**
*
* @todo: $option['file_type'] if a user chooses 'custom' check further if only image file type???
*
* @since 1.0
*
* @param array $options
*
* @return array
* @internal param $option
*
*/
static public function pods_get_fields( $options = array() ) {

$fields = array();
$pods = pods_api()->load_pods( array( 'names' => true ) );

// 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 ( $options ) {
foreach ( $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
}
}
}

$fields[ $field_name ] .= $_field['label'] . " (" . $label . ") ";
}

}

return $fields;
}


/**
*
* Limit fields from pods to image fields ( -> file_format = 'images' )
*
* @since 1.0
* @return array
*/
static public function pods_get_image_fields() {
$options['file_format'] = 'images';
$fields = self::pods_get_fields( $options );

return $fields;
}

/**
*
* Limit fields from pods to image fields ( -> file_format = 'images', file_format_type = 'multi' )
*
* @since 1.0
* @return array
*/
static public function pods_get_multiple_images_fields() {
$options['file_type'] = 'images';
$options['file_format_type'] = 'multi';
$fields = self::pods_get_fields( $options );

return $fields;
}





/**
*
* Experimental in Development not used yet -> goall full dynamic settings to allow e.g. for image fields to select output size & Style (url, wp, gallery,...)
*
*/


/**
* @since 1.0
* @return array
*/
static public function pods_get_option_fields() {

// $pods = Pods_Templates_Auto_Template_Front_End::the_pods();
$pods = pods_api()->load_pods( array( 'names' => true ) );
$fields = array();

foreach ( $pods as $name => $label ) {
$fields[ $name ]['fields'] = array( $name );
}

return $fields;
}

/**
*
* Helper to get a list of configured pods, maybe limit to the "location" the template is used (Filter fom Themer)
*
* @since 1.0
* @return array
*/
static public function pods_get_pods() {
//$pods = array();
// $pods = Pods_Templates_Auto_Template_Front_End::the_pods();
$api = pods_api();

/* $_pods = $api->load_pods();
foreach ( $_pods as $pod ) {
$pods[ $pod['name'] ] = $pod['label'];
}*/

return $pods = $api->load_pods( array( 'names' => true ) );
}


/**
*
* Generates Settings Form -
*
* @since 1.0
* @return array
*/
static public function pods_settings_form() {
$form = array(
'pods_pod' => array(
'type' => 'select',
'label' => __( 'Configured Pod Fields', 'fl-theme-builder' ),
'options' => self::pods_get_pods(),
'toggle' => self::pods_get_option_fields(),
'help' => __( 'Some Help Text', 'fl-theme-builder' ),
'description' => __( 'Some Description', 'fl-theme-builder' ),
'placeholder' => __( 'Some Placeholder', 'fl-theme-builder' )

)
);

$pods = self::pods_get_pods();

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

$form[ $name ] = array(
'type' => 'select',
'label' => $label
);

foreach ( $pod_fields as $field_name => $data ) {
$form[ $name ]['options'][ $field_name ] = $data['label'];
}
}

return $form;
}

}

PodsPageData::init();

0 comments on commit a9e7140

Please sign in to comment.