Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add .gitattributes, fixes #323

  • Loading branch information...
commit 3bbfa722b8db3baa11558f3510720fb7b28ec167 1 parent 64b7f51
@unknownnf unknownnf authored
Showing with 12,477 additions and 12,455 deletions.
  1. +22 −0 .gitattributes
  2. +422 −422 classes/PodsComponents.php
  3. +265 −265 classes/PodsField.php
  4. +203 −203 classes/PodsView.php
  5. +262 −262 classes/fields/boolean.php
  6. +239 −239 classes/fields/color.php
  7. +374 −374 classes/fields/date.php
  8. +361 −361 classes/fields/file.php
  9. +438 −438 classes/fields/number.php
  10. +295 −295 classes/fields/paragraph.php
  11. +438 −438 classes/fields/pick.php
  12. +205 −205 classes/fields/slug.php
  13. +514 −514 classes/fields/text.php
  14. +75 −75 components/GravityForms/ui/field_option.php
  15. +1,682 −1,682 components/Markdown.php
  16. +270 −270 components/Migrate-CPTUI/Migrate-CPTUI.php
  17. +177 −177 components/Migrate-CPTUI/ui/wizard.php
  18. +42 −42 components/Migrate-Table/Migrate-Table.php
  19. +177 −177 components/Migrate-Table/ui/wizard.php
  20. +170 −170 components/Roles/ui/add.php
  21. +189 −189 components/Roles/ui/edit.php
  22. +1,698 −1,698 functions.php
  23. +975 −975 sql/PodsUpgrade.php
  24. +169 −169 sql/update.php
  25. +92 −92 ui/admin/field_option.php
  26. +279 −279 ui/admin/packages.php
  27. +333 −333 ui/admin/upgrade.php
  28. +26 −26 ui/css/less/mixins.less
  29. +409 −409 ui/css/less/pods-wizard.less
  30. +139 −139 ui/css/pods-form.css
  31. +264 −264 ui/css/pods-front.css
  32. +2 −2 ui/fields/_comment.php
  33. +14 −14 ui/fields/_db.php
  34. +6 −6 ui/fields/_hidden.php
  35. +7 −7 ui/fields/_label.php
  36. +4 −4 ui/fields/_row.php
  37. +98 −98 ui/fields/attachment.php
  38. +78 −78 ui/fields/checkbox.php
  39. +17 −17 ui/fields/cleditor.php
  40. +49 −49 ui/fields/color.php
  41. +148 −148 ui/fields/date.php
  42. +14 −14 ui/fields/email.php
  43. +40 −40 ui/fields/number.php
  44. +8 −8 ui/fields/password.php
  45. +14 −14 ui/fields/phone.php
  46. +228 −228 ui/fields/plupload.php
  47. +72 −72 ui/fields/radio.php
  48. +75 −75 ui/fields/select.php
  49. +74 −74 ui/fields/slider.php
  50. +19 −19 ui/fields/slug.php
  51. +8 −8 ui/fields/text.php
  52. +7 −7 ui/fields/textarea.php
  53. +18 −18 ui/fields/tinymce.php
  54. +14 −14 ui/fields/url.php
  55. +57 −57 ui/front/form.php
  56. +36 −36 ui/js/jquery.json.js
  57. +166 −166 ui/js/jquery.textareaCounter.plugin.js
View
22 .gitattributes
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
View
844 classes/PodsComponents.php
@@ -1,423 +1,423 @@
-<?php
-/**
- *
- */
-class PodsComponents {
-
- /**
- * Root of Components directory
- *
- * @var string
- *
- * @private
- * @since 2.0.0
- */
- private $components_dir = null;
-
- /**
- * Available components
- *
- * @var string
- *
- * @private
- * @since 2.0.0
- */
- public $components = array();
-
- /**
- * Components settings
- *
- * @var string
- *
- * @private
- * @since 2.0.0
- */
- public $settings = array();
-
- /**
- * Setup actions and get options
- *
- * @since 2.0.0
- */
- public function __construct () {
- $this->components_dir = apply_filters( 'pods_components_dir', PODS_DIR . 'components/' );
-
- $settings = get_option( 'pods_component_settings', '' );
-
- if ( !empty( $settings ) )
- $this->settings = (array) json_decode( $settings, true );
-
- if ( !isset( $this->settings[ 'components' ] ) )
- $this->settings[ 'components' ] = array();
-
- // Get components
- add_action( 'after_setup_theme', array( $this, 'get_components' ), 11 );
-
- // Load in components
- add_action( 'after_setup_theme', array( $this, 'load' ), 12 );
-
- // AJAX handling
- if ( is_admin() ) {
- add_action( 'wp_ajax_pods_admin_components', array( $this, 'admin_ajax' ) );
- add_action( 'wp_ajax_nopriv_pods_admin_components', array( $this, 'admin_ajax' ) );
- }
- }
-
- /**
- * Add menu item
- *
- * @since 2.0.0
- */
- public function menu ( $parent ) {
- foreach ( $this->components as $component => $component_data ) {
- if ( !empty( $component_data[ 'Hide' ] ) )
- continue;
-
- if ( true === (boolean) pods_var( 'DeveloperMode', $component_data, false ) && ( !defined( 'PODS_DEVELOPER' ) || !PODS_DEVELOPER ) )
- continue;
-
- if ( !isset( $component_data[ 'object' ] ) || !method_exists( $component_data[ 'object' ], 'admin' ) )
- continue;
-
- $page = add_submenu_page(
- $parent,
- strip_tags( $component_data[ 'Name' ] ),
- '- ' . strip_tags( $component_data[ 'MenuName' ] ),
- 'read',
- 'pods-component-' . $component_data[ 'ID' ],
- array( $this, 'admin_handler' )
- );
-
- if ( method_exists( $component_data[ 'object' ], 'admin_assets' ) )
- add_action( 'admin_print_styles-' . $page, array( $component_data[ 'object' ], 'admin_assets' ) );
- }
- }
-
- /**
- * Load activated components and init component
- *
- * @since 2.0.0
- */
- public function load () {
- foreach ( (array) $this->settings[ 'components' ] as $component => $options ) {
- if ( !isset( $this->components[ $component ] ) || 0 == $options )
- continue;
-
- if ( true === (boolean) pods_var( 'DeveloperMode', $this->components[ $component ], false ) && ( !defined( 'PODS_DEVELOPER' ) || !PODS_DEVELOPER ) )
- continue;
-
- if ( !empty( $this->components[ $component ][ 'PluginDependency' ] ) ) {
- $dependency = explode( '|', $this->components[ $component ][ 'PluginDependency' ] );
-
- if ( !pods_is_plugin_active( $dependency[ 1 ] ) )
- continue;
- }
-
- $component_data = $this->components[ $component ];
-
- if ( !file_exists( $component_data[ 'File' ] ) )
- continue;
-
- include_once $component_data[ 'File' ];
-
- if ( !empty( $component_data[ 'Class' ] ) && class_exists( $component_data[ 'Class' ] ) && !isset( $this->components[ $component ][ 'object' ] ) ) {
- $this->components[ $component ][ 'object' ] = new $component_data[ 'Class' ];
-
- if ( method_exists( $this->components[ $component ][ 'object' ], 'options' ) ) {
- $this->components[ $component ][ 'options' ] = $this->components[ $component ][ 'object' ]->options();
-
- $this->options( $component, $this->components[ $component ][ 'options' ] );
- }
-
- if ( method_exists( $this->components[ $component ][ 'object' ], 'handler' ) )
- $this->components[ $component ][ 'object' ]->handler( $this->settings[ 'components' ][ $component ] );
- }
- }
- }
-
- /**
- * Get list of components available
- *
- * @since 2.0.0
- */
- public function get_components () {
- $components = get_transient( 'pods_components' );
-
- if ( !is_array( $components ) || empty( $components ) || ( is_admin() && isset( $_GET[ 'page' ] ) && 'pods-components' == $_GET[ 'page' ] && false !== get_transient( 'pods_components_refresh' ) ) ) {
- $component_dir = @opendir( rtrim( $this->components_dir, '/' ) );
- $component_files = array();
-
- if ( false !== $component_dir ) {
- while ( false !== ( $file = readdir( $component_dir ) ) ) {
- if ( '.' == substr( $file, 0, 1 ) )
- continue;
- elseif ( is_dir( $this->components_dir . $file ) ) {
- $component_subdir = @opendir( $this->components_dir . $file );
-
- if ( $component_subdir ) {
- while ( false !== ( $subfile = readdir( $component_subdir ) ) ) {
- if ( '.' == substr( $subfile, 0, 1 ) )
- continue;
- elseif ( '.php' == substr( $subfile, -4 ) )
- $component_files[] = $this->components_dir . $file . '/' . $subfile;
- }
-
- closedir( $component_subdir );
- }
- }
- elseif ( '.php' == substr( $file, -4 ) )
- $component_files[] = $this->components_dir . $file;
- }
-
- closedir( $component_dir );
- }
-
- $default_headers = array(
- 'ID' => 'ID',
- 'Name' => 'Name',
- 'MenuName' => 'Menu Name',
- 'Description' => 'Description',
- 'Version' => 'Version',
- 'Author' => 'Author',
- 'Class' => 'Class',
- 'Hide' => 'Hide',
- 'PluginDependency' => 'Plugin Dependency',
- 'DeveloperMode' => 'Developer Mode'
- );
-
- $components = array();
-
- foreach ( $component_files as $component_file ) {
- if ( !is_readable( $component_file ) )
- continue;
-
- $component_data = get_file_data( $component_file, $default_headers, 'pods_component' );
-
- if ( empty( $component_data[ 'Name' ] ) || 'yes' == $component_data[ 'Hide' ] )
- continue;
-
- if ( empty( $component_data[ 'MenuName' ] ) )
- $component_data[ 'MenuName' ] = $component_data[ 'Name' ];
-
- if ( empty( $component_data[ 'Class' ] ) )
- $component_data[ 'Class' ] = 'Pods_' . pods_clean_name( basename( $component_file, '.php' ), false );
-
- if ( empty( $component_data[ 'ID' ] ) )
- $component_data[ 'ID' ] = sanitize_title( $component_data[ 'Name' ] );
-
- if ( 'on' == $component_data[ 'DeveloperMode' ] || 1 == $component_data[ 'DeveloperMode' ] )
- $component_data[ 'DeveloperMode' ] = true;
- else
- $component_data[ 'DeveloperMode' ] = false;
-
- if ( true === $component_data[ 'DeveloperMode' ] && ( !defined( 'PODS_DEVELOPER' ) || !PODS_DEVELOPER ) )
- continue;
-
- $component_data[ 'File' ] = $component_file;
-
- $components[ $component_data[ 'ID' ] ] = $component_data;
- }
-
- ksort( $components );
-
- set_transient( 'pods_components_refresh', 1, ( 60 * 60 * 12 ) );
-
- set_transient( 'pods_components', $components );
- }
-
- $this->components = $components;
-
- return $this->components;
- }
-
- /**
- * @param $component
- * @param $options
- */
- public function options ( $component, $options ) {
- if ( !isset( $this->settings[ 'components' ][ $component ] ) || !is_array( $this->settings[ 'components' ][ $component ] ) )
- $this->settings[ 'components' ][ $component ] = array();
-
- foreach ( $options as $option => $data ) {
- if ( !isset( $this->settings[ 'components' ][ $component ][ $option ] ) && isset( $data[ 'default' ] ) )
- $this->settings[ 'components' ][ $component ][ $option ] = $data[ 'default' ];
- }
- }
-
- /**
- *
- */
- public function admin_handler () {
- $component = str_replace( 'pods-component-', '', $_GET[ 'page' ] );
-
- if ( isset( $this->components[ $component ] ) && isset( $this->components[ $component ][ 'object' ] ) && method_exists( $this->components[ $component ][ 'object' ], 'admin' ) )
- $this->components[ $component ][ 'object' ]->admin( $this->settings[ 'components' ][ $component ], $component );
- }
-
- /**
- * @param $component
- *
- * @return bool
- */
- public function toggle ( $component ) {
- $toggle = null;
-
- if ( isset( $this->components[ $component ] ) ) {
- if ( 1 == pods_var( 'toggle', 'get' ) && ( !isset( $this->settings[ 'components' ][ $component ] ) || 0 == $this->settings[ 'components' ][ $component ] ) ) {
- $this->settings[ 'components' ][ $component ] = array();
- $toggle = true;
- }
- elseif ( 0 == pods_var( 'toggle', 'get' ) ) {
- $this->settings[ 'components' ][ $component ] = 0;
- $toggle = false;
- }
- }
-
- $settings = json_encode( $this->settings );
-
- update_option( 'pods_component_settings', $settings );
-
- return $toggle;
- }
-
- /**
- *
- */
- public function admin_ajax () {
- if ( false === headers_sent() ) {
- if ( '' == session_id() )
- @session_start();
-
- header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
- }
-
- // Sanitize input
- $params = stripslashes_deep( (array) $_POST );
-
- foreach ( $params as $key => $value ) {
- if ( 'action' == $key )
- continue;
-
- unset( $params[ $key ] );
-
- $params[ str_replace( '_podsfix_', '', $key ) ] = $value;
- }
-
- $params = (object) $params;
-
- $component = $params->component;
- $method = $params->method;
-
- if ( !isset( $component ) || !isset( $this->components[ $component ] ) || !isset( $this->settings[ 'components' ][ $component ] ) )
- pods_error( 'Invalid AJAX request', $this );
-
- if ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-component-' . $component . '-' . $method ) )
- pods_error( 'Unauthorized request', $this );
-
- if ( !isset( $this->components[ $component ][ 'object' ] ) || !method_exists( $this->components[ $component ][ 'object' ], 'ajax_' . $method ) )
- pods_error( 'API method does not exist', $this );
-
- // Cleaning up $params
- unset( $params->action );
- unset( $params->component );
- unset( $params->method );
- unset( $params->_wpnonce );
-
- $params = (object) apply_filters( 'pods_component_ajax_' . $component . '_' . $method, $params, $component, $method );
-
- $method = 'ajax_' . $method;
-
- // Dynamically call the component method
- $output = call_user_func( array( $this->components[ $component ][ 'object' ], $method ), $params );
-
- if ( !is_bool( $output ) )
- echo $output;
-
- die(); // KBAI!
- }
-}
-
-/**
- *
- */class PodsComponent {
-
- /**
- * Do things like register/enqueue scripts and stylesheets
- *
- * @since 2.0.0
- */
- public function __construct () {
-
- }
-
- /**
- * Add options and set defaults for field type, shows in admin area
- *
- * @return array $options
- *
- * @since 2.0.0
- */
- public function options () {
- $options = array( /*
- 'option_name' => array(
- 'label' => 'Option Label',
- 'depends-on' => array( 'another_option' => 'specific-value' ),
- 'default' => 'default-value',
- 'type' => 'field_type',
- 'data' => array(
- 'value1' => 'Label 1',
-
- // Group your options together
- 'Option Group' => array(
- 'gvalue1' => 'Option Label 1',
- 'gvalue2' => 'Option Label 2'
- ),
-
- // below is only if the option_name above is the "{$fieldtype}_format_type"
- 'value2' => array(
- 'label' => 'Label 2',
- 'regex' => '[a-zA-Z]' // Uses JS regex validation for the value saved if this option selected
- )
- ),
-
- // below is only for a boolean group
- 'group' => array(
- 'option_boolean1' => array(
- 'label' => 'Option boolean 1?',
- 'default' => 1,
- 'type' => 'boolean'
- ),
- 'option_boolean2' => array(
- 'label' => 'Option boolean 2?',
- 'default' => 0,
- 'type' => 'boolean'
- )
- )
- ) */
- );
-
- return $options;
- }
-
- /**
- * Handler to run code based on $options
- *
- * @param $options
- *
- * @since 2.0.0
- */
- public function handler ( $options ) {
- // run code based on $options set
- }
-
- /**
- * Build admin area
- *
- * @param $options
- *
- * @since 2.0.0
- public function admin ( $options ) {
- // run code based on $options set
- }
- */
+<?php
+/**
+ *
+ */
+class PodsComponents {
+
+ /**
+ * Root of Components directory
+ *
+ * @var string
+ *
+ * @private
+ * @since 2.0.0
+ */
+ private $components_dir = null;
+
+ /**
+ * Available components
+ *
+ * @var string
+ *
+ * @private
+ * @since 2.0.0
+ */
+ public $components = array();
+
+ /**
+ * Components settings
+ *
+ * @var string
+ *
+ * @private
+ * @since 2.0.0
+ */
+ public $settings = array();
+
+ /**
+ * Setup actions and get options
+ *
+ * @since 2.0.0
+ */
+ public function __construct () {
+ $this->components_dir = apply_filters( 'pods_components_dir', PODS_DIR . 'components/' );
+
+ $settings = get_option( 'pods_component_settings', '' );
+
+ if ( !empty( $settings ) )
+ $this->settings = (array) json_decode( $settings, true );
+
+ if ( !isset( $this->settings[ 'components' ] ) )
+ $this->settings[ 'components' ] = array();
+
+ // Get components
+ add_action( 'after_setup_theme', array( $this, 'get_components' ), 11 );
+
+ // Load in components
+ add_action( 'after_setup_theme', array( $this, 'load' ), 12 );
+
+ // AJAX handling
+ if ( is_admin() ) {
+ add_action( 'wp_ajax_pods_admin_components', array( $this, 'admin_ajax' ) );
+ add_action( 'wp_ajax_nopriv_pods_admin_components', array( $this, 'admin_ajax' ) );
+ }
+ }
+
+ /**
+ * Add menu item
+ *
+ * @since 2.0.0
+ */
+ public function menu ( $parent ) {
+ foreach ( $this->components as $component => $component_data ) {
+ if ( !empty( $component_data[ 'Hide' ] ) )
+ continue;
+
+ if ( true === (boolean) pods_var( 'DeveloperMode', $component_data, false ) && ( !defined( 'PODS_DEVELOPER' ) || !PODS_DEVELOPER ) )
+ continue;
+
+ if ( !isset( $component_data[ 'object' ] ) || !method_exists( $component_data[ 'object' ], 'admin' ) )
+ continue;
+
+ $page = add_submenu_page(
+ $parent,
+ strip_tags( $component_data[ 'Name' ] ),
+ '- ' . strip_tags( $component_data[ 'MenuName' ] ),
+ 'read',
+ 'pods-component-' . $component_data[ 'ID' ],
+ array( $this, 'admin_handler' )
+ );
+
+ if ( method_exists( $component_data[ 'object' ], 'admin_assets' ) )
+ add_action( 'admin_print_styles-' . $page, array( $component_data[ 'object' ], 'admin_assets' ) );
+ }
+ }
+
+ /**
+ * Load activated components and init component
+ *
+ * @since 2.0.0
+ */
+ public function load () {
+ foreach ( (array) $this->settings[ 'components' ] as $component => $options ) {
+ if ( !isset( $this->components[ $component ] ) || 0 == $options )
+ continue;
+
+ if ( true === (boolean) pods_var( 'DeveloperMode', $this->components[ $component ], false ) && ( !defined( 'PODS_DEVELOPER' ) || !PODS_DEVELOPER ) )
+ continue;
+
+ if ( !empty( $this->components[ $component ][ 'PluginDependency' ] ) ) {
+ $dependency = explode( '|', $this->components[ $component ][ 'PluginDependency' ] );
+
+ if ( !pods_is_plugin_active( $dependency[ 1 ] ) )
+ continue;
+ }
+
+ $component_data = $this->components[ $component ];
+
+ if ( !file_exists( $component_data[ 'File' ] ) )
+ continue;
+
+ include_once $component_data[ 'File' ];
+
+ if ( !empty( $component_data[ 'Class' ] ) && class_exists( $component_data[ 'Class' ] ) && !isset( $this->components[ $component ][ 'object' ] ) ) {
+ $this->components[ $component ][ 'object' ] = new $component_data[ 'Class' ];
+
+ if ( method_exists( $this->components[ $component ][ 'object' ], 'options' ) ) {
+ $this->components[ $component ][ 'options' ] = $this->components[ $component ][ 'object' ]->options();
+
+ $this->options( $component, $this->components[ $component ][ 'options' ] );
+ }
+
+ if ( method_exists( $this->components[ $component ][ 'object' ], 'handler' ) )
+ $this->components[ $component ][ 'object' ]->handler( $this->settings[ 'components' ][ $component ] );
+ }
+ }
+ }
+
+ /**
+ * Get list of components available
+ *
+ * @since 2.0.0
+ */
+ public function get_components () {
+ $components = get_transient( 'pods_components' );
+
+ if ( !is_array( $components ) || empty( $components ) || ( is_admin() && isset( $_GET[ 'page' ] ) && 'pods-components' == $_GET[ 'page' ] && false !== get_transient( 'pods_components_refresh' ) ) ) {
+ $component_dir = @opendir( rtrim( $this->components_dir, '/' ) );
+ $component_files = array();
+
+ if ( false !== $component_dir ) {
+ while ( false !== ( $file = readdir( $component_dir ) ) ) {
+ if ( '.' == substr( $file, 0, 1 ) )
+ continue;
+ elseif ( is_dir( $this->components_dir . $file ) ) {
+ $component_subdir = @opendir( $this->components_dir . $file );
+
+ if ( $component_subdir ) {
+ while ( false !== ( $subfile = readdir( $component_subdir ) ) ) {
+ if ( '.' == substr( $subfile, 0, 1 ) )
+ continue;
+ elseif ( '.php' == substr( $subfile, -4 ) )
+ $component_files[] = $this->components_dir . $file . '/' . $subfile;
+ }
+
+ closedir( $component_subdir );
+ }
+ }
+ elseif ( '.php' == substr( $file, -4 ) )
+ $component_files[] = $this->components_dir . $file;
+ }
+
+ closedir( $component_dir );
+ }
+
+ $default_headers = array(
+ 'ID' => 'ID',
+ 'Name' => 'Name',
+ 'MenuName' => 'Menu Name',
+ 'Description' => 'Description',
+ 'Version' => 'Version',
+ 'Author' => 'Author',
+ 'Class' => 'Class',
+ 'Hide' => 'Hide',
+ 'PluginDependency' => 'Plugin Dependency',
+ 'DeveloperMode' => 'Developer Mode'
+ );
+
+ $components = array();
+
+ foreach ( $component_files as $component_file ) {
+ if ( !is_readable( $component_file ) )
+ continue;
+
+ $component_data = get_file_data( $component_file, $default_headers, 'pods_component' );
+
+ if ( empty( $component_data[ 'Name' ] ) || 'yes' == $component_data[ 'Hide' ] )
+ continue;
+
+ if ( empty( $component_data[ 'MenuName' ] ) )
+ $component_data[ 'MenuName' ] = $component_data[ 'Name' ];
+
+ if ( empty( $component_data[ 'Class' ] ) )
+ $component_data[ 'Class' ] = 'Pods_' . pods_clean_name( basename( $component_file, '.php' ), false );
+
+ if ( empty( $component_data[ 'ID' ] ) )
+ $component_data[ 'ID' ] = sanitize_title( $component_data[ 'Name' ] );
+
+ if ( 'on' == $component_data[ 'DeveloperMode' ] || 1 == $component_data[ 'DeveloperMode' ] )
+ $component_data[ 'DeveloperMode' ] = true;
+ else
+ $component_data[ 'DeveloperMode' ] = false;
+
+ if ( true === $component_data[ 'DeveloperMode' ] && ( !defined( 'PODS_DEVELOPER' ) || !PODS_DEVELOPER ) )
+ continue;
+
+ $component_data[ 'File' ] = $component_file;
+
+ $components[ $component_data[ 'ID' ] ] = $component_data;
+ }
+
+ ksort( $components );
+
+ set_transient( 'pods_components_refresh', 1, ( 60 * 60 * 12 ) );
+
+ set_transient( 'pods_components', $components );
+ }
+
+ $this->components = $components;
+
+ return $this->components;
+ }
+
+ /**
+ * @param $component
+ * @param $options
+ */
+ public function options ( $component, $options ) {
+ if ( !isset( $this->settings[ 'components' ][ $component ] ) || !is_array( $this->settings[ 'components' ][ $component ] ) )
+ $this->settings[ 'components' ][ $component ] = array();
+
+ foreach ( $options as $option => $data ) {
+ if ( !isset( $this->settings[ 'components' ][ $component ][ $option ] ) && isset( $data[ 'default' ] ) )
+ $this->settings[ 'components' ][ $component ][ $option ] = $data[ 'default' ];
+ }
+ }
+
+ /**
+ *
+ */
+ public function admin_handler () {
+ $component = str_replace( 'pods-component-', '', $_GET[ 'page' ] );
+
+ if ( isset( $this->components[ $component ] ) && isset( $this->components[ $component ][ 'object' ] ) && method_exists( $this->components[ $component ][ 'object' ], 'admin' ) )
+ $this->components[ $component ][ 'object' ]->admin( $this->settings[ 'components' ][ $component ], $component );
+ }
+
+ /**
+ * @param $component
+ *
+ * @return bool
+ */
+ public function toggle ( $component ) {
+ $toggle = null;
+
+ if ( isset( $this->components[ $component ] ) ) {
+ if ( 1 == pods_var( 'toggle', 'get' ) && ( !isset( $this->settings[ 'components' ][ $component ] ) || 0 == $this->settings[ 'components' ][ $component ] ) ) {
+ $this->settings[ 'components' ][ $component ] = array();
+ $toggle = true;
+ }
+ elseif ( 0 == pods_var( 'toggle', 'get' ) ) {
+ $this->settings[ 'components' ][ $component ] = 0;
+ $toggle = false;
+ }
+ }
+
+ $settings = json_encode( $this->settings );
+
+ update_option( 'pods_component_settings', $settings );
+
+ return $toggle;
+ }
+
+ /**
+ *
+ */
+ public function admin_ajax () {
+ if ( false === headers_sent() ) {
+ if ( '' == session_id() )
+ @session_start();
+
+ header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
+ }
+
+ // Sanitize input
+ $params = stripslashes_deep( (array) $_POST );
+
+ foreach ( $params as $key => $value ) {
+ if ( 'action' == $key )
+ continue;
+
+ unset( $params[ $key ] );
+
+ $params[ str_replace( '_podsfix_', '', $key ) ] = $value;
+ }
+
+ $params = (object) $params;
+
+ $component = $params->component;
+ $method = $params->method;
+
+ if ( !isset( $component ) || !isset( $this->components[ $component ] ) || !isset( $this->settings[ 'components' ][ $component ] ) )
+ pods_error( 'Invalid AJAX request', $this );
+
+ if ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-component-' . $component . '-' . $method ) )
+ pods_error( 'Unauthorized request', $this );
+
+ if ( !isset( $this->components[ $component ][ 'object' ] ) || !method_exists( $this->components[ $component ][ 'object' ], 'ajax_' . $method ) )
+ pods_error( 'API method does not exist', $this );
+
+ // Cleaning up $params
+ unset( $params->action );
+ unset( $params->component );
+ unset( $params->method );
+ unset( $params->_wpnonce );
+
+ $params = (object) apply_filters( 'pods_component_ajax_' . $component . '_' . $method, $params, $component, $method );
+
+ $method = 'ajax_' . $method;
+
+ // Dynamically call the component method
+ $output = call_user_func( array( $this->components[ $component ][ 'object' ], $method ), $params );
+
+ if ( !is_bool( $output ) )
+ echo $output;
+
+ die(); // KBAI!
+ }
+}
+
+/**
+ *
+ */class PodsComponent {
+
+ /**
+ * Do things like register/enqueue scripts and stylesheets
+ *
+ * @since 2.0.0
+ */
+ public function __construct () {
+
+ }
+
+ /**
+ * Add options and set defaults for field type, shows in admin area
+ *
+ * @return array $options
+ *
+ * @since 2.0.0
+ */
+ public function options () {
+ $options = array( /*
+ 'option_name' => array(
+ 'label' => 'Option Label',
+ 'depends-on' => array( 'another_option' => 'specific-value' ),
+ 'default' => 'default-value',
+ 'type' => 'field_type',
+ 'data' => array(
+ 'value1' => 'Label 1',
+
+ // Group your options together
+ 'Option Group' => array(
+ 'gvalue1' => 'Option Label 1',
+ 'gvalue2' => 'Option Label 2'
+ ),
+
+ // below is only if the option_name above is the "{$fieldtype}_format_type"
+ 'value2' => array(
+ 'label' => 'Label 2',
+ 'regex' => '[a-zA-Z]' // Uses JS regex validation for the value saved if this option selected
+ )
+ ),
+
+ // below is only for a boolean group
+ 'group' => array(
+ 'option_boolean1' => array(
+ 'label' => 'Option boolean 1?',
+ 'default' => 1,
+ 'type' => 'boolean'
+ ),
+ 'option_boolean2' => array(
+ 'label' => 'Option boolean 2?',
+ 'default' => 0,
+ 'type' => 'boolean'
+ )
+ )
+ ) */
+ );
+
+ return $options;
+ }
+
+ /**
+ * Handler to run code based on $options
+ *
+ * @param $options
+ *
+ * @since 2.0.0
+ */
+ public function handler ( $options ) {
+ // run code based on $options set
+ }
+
+ /**
+ * Build admin area
+ *
+ * @param $options
+ *
+ * @since 2.0.0
+ public function admin ( $options ) {
+ // run code based on $options set
+ }
+ */
}
View
530 classes/PodsField.php
@@ -1,266 +1,266 @@
-<?php
-/**
- *
- */
-class PodsField {
-
- /**
- * Whether this field is running under 1.x deprecated forms
- *
- * @var bool
- * @since 2.0.0
- */
- public static $deprecated = false;
-
- /**
- * Field Type Identifier
- *
- * @var string
- * @since 2.0.0
- */
- public static $type = 'text';
-
- /**
- * Field Type Label
- *
- * @var string
- * @since 2.0.0
- */
- public static $label = 'Text';
-
- /**
- * Field Type Preparation
- *
- * @var string
- * @since 2.0.0
- */
- public static $prepare = '%s';
-
- /**
- * Do things like register/enqueue scripts and stylesheets
- *
- * @since 2.0.0
- */
- public function __construct () {
-
- }
-
- /**
- * Add options and set defaults for field type, shows in admin area
- *
- * @return array $options
- *
- * @since 2.0.0
- */
- public function options () {
- $options = array( /*
- 'option_name' => array(
- 'label' => 'Option Label',
- 'depends-on' => array( 'another_option' => 'specific-value' ),
- 'default' => 'default-value',
- 'type' => 'field_type',
- 'data' => array(
- 'value1' => 'Label 1',
-
- // Group your options together
- 'Option Group' => array(
- 'gvalue1' => 'Option Label 1',
- 'gvalue2' => 'Option Label 2'
- ),
-
- // below is only if the option_name above is the "{$fieldtype}_format_type"
- 'value2' => array(
- 'label' => 'Label 2',
- 'regex' => '[a-zA-Z]' // Uses JS regex validation for the value saved if this option selected
- )
- ),
-
- // below is only for a boolean group
- 'group' => array(
- 'option_boolean1' => array(
- 'label' => 'Option boolean 1?',
- 'default' => 1,
- 'type' => 'boolean'
- ),
- 'option_boolean2' => array(
- 'label' => 'Option boolean 2?',
- 'default' => 0,
- 'type' => 'boolean'
- )
- )
- ) */
- );
-
- return $options;
- }
-
- /**
- * Define the current field's schema for DB table storage
- *
- * @param array $options
- *
- * @return array
- * @since 2.0.0
- */
- public function schema ( $options = null ) {
- $schema = 'VARCHAR(255)';
-
- return $schema;
- }
-
- /**
- * Define the current field's preparation for sprintf
- *
- * @param array $options
- *
- * @return array
- * @since 2.0.0
- */
- public function prepare ( $options = null ) {
- $format = self::$prepare;
-
- return $format;
- }
-
- /**
- * Change the way the value of the field is displayed with Pods::get
- *
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
- return $value;
- }
-
- /**
- * Customize output of the form field
- *
- * @param string $name
- * @param mixed $value
- * @param array $options
- * @param array $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
- $options = (array) $options;
-
- pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) );
- }
-
- /**
- * Build regex necessary for JS validation
- *
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param string $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
- return false;
- }
-
- /**
- * Validate a value before it's saved
- *
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function validate ( &$value, $name = null, $options = null, $fields = null, $pod = null, $id = null ) {
- return true;
- }
-
- /**
- * Change the value or perform actions after validation but before saving to the DB
- *
- * @param mixed $value
- * @param int $id
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param object $params
- *
- * @since 2.0.0
- */
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
- return $value;
- }
-
- /**
- * Perform actions after saving to the DB
- *
- * @param mixed $value
- * @param int $id
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param object $params
- *
- * @since 2.0.0
- */
- public function post_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
-
- }
-
- /**
- * Perform actions before deleting from the DB
- *
- * @param string $name
- * @param string $pod
- * @param int $id
- * @param object $api
- *
- * @since 2.0.0
- */
- public function pre_delete ( $id = null, $name = null, $options = null, $pod = null ) {
-
- }
-
- /**
- * Perform actions after deleting from the DB
- *
- * @param int $id
- * @param string $name
- * @param array $options
- * @param array $pod
- *
- * @since 2.0.0
- */
- public function post_delete ( $id = null, $name = null, $options = null, $pod = null ) {
-
- }
-
- /**
- * Customize the Pods UI manage table column output
- *
- * @param int $id
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- *
- * @since 2.0.0
- */
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
-
- }
+<?php
+/**
+ *
+ */
+class PodsField {
+
+ /**
+ * Whether this field is running under 1.x deprecated forms
+ *
+ * @var bool
+ * @since 2.0.0
+ */
+ public static $deprecated = false;
+
+ /**
+ * Field Type Identifier
+ *
+ * @var string
+ * @since 2.0.0
+ */
+ public static $type = 'text';
+
+ /**
+ * Field Type Label
+ *
+ * @var string
+ * @since 2.0.0
+ */
+ public static $label = 'Text';
+
+ /**
+ * Field Type Preparation
+ *
+ * @var string
+ * @since 2.0.0
+ */
+ public static $prepare = '%s';
+
+ /**
+ * Do things like register/enqueue scripts and stylesheets
+ *
+ * @since 2.0.0
+ */
+ public function __construct () {
+
+ }
+
+ /**
+ * Add options and set defaults for field type, shows in admin area
+ *
+ * @return array $options
+ *
+ * @since 2.0.0
+ */
+ public function options () {
+ $options = array( /*
+ 'option_name' => array(
+ 'label' => 'Option Label',
+ 'depends-on' => array( 'another_option' => 'specific-value' ),
+ 'default' => 'default-value',
+ 'type' => 'field_type',
+ 'data' => array(
+ 'value1' => 'Label 1',
+
+ // Group your options together
+ 'Option Group' => array(
+ 'gvalue1' => 'Option Label 1',
+ 'gvalue2' => 'Option Label 2'
+ ),
+
+ // below is only if the option_name above is the "{$fieldtype}_format_type"
+ 'value2' => array(
+ 'label' => 'Label 2',
+ 'regex' => '[a-zA-Z]' // Uses JS regex validation for the value saved if this option selected
+ )
+ ),
+
+ // below is only for a boolean group
+ 'group' => array(
+ 'option_boolean1' => array(
+ 'label' => 'Option boolean 1?',
+ 'default' => 1,
+ 'type' => 'boolean'
+ ),
+ 'option_boolean2' => array(
+ 'label' => 'Option boolean 2?',
+ 'default' => 0,
+ 'type' => 'boolean'
+ )
+ )
+ ) */
+ );
+
+ return $options;
+ }
+
+ /**
+ * Define the current field's schema for DB table storage
+ *
+ * @param array $options
+ *
+ * @return array
+ * @since 2.0.0
+ */
+ public function schema ( $options = null ) {
+ $schema = 'VARCHAR(255)';
+
+ return $schema;
+ }
+
+ /**
+ * Define the current field's preparation for sprintf
+ *
+ * @param array $options
+ *
+ * @return array
+ * @since 2.0.0
+ */
+ public function prepare ( $options = null ) {
+ $format = self::$prepare;
+
+ return $format;
+ }
+
+ /**
+ * Change the way the value of the field is displayed with Pods::get
+ *
+ * @param mixed $value
+ * @param string $name
+ * @param array $options
+ * @param array $fields
+ * @param array $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
+ return $value;
+ }
+
+ /**
+ * Customize output of the form field
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ * @param array $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
+ $options = (array) $options;
+
+ pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) );
+ }
+
+ /**
+ * Build regex necessary for JS validation
+ *
+ * @param mixed $value
+ * @param string $name
+ * @param array $options
+ * @param string $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
+ return false;
+ }
+
+ /**
+ * Validate a value before it's saved
+ *
+ * @param mixed $value
+ * @param string $name
+ * @param array $options
+ * @param array $fields
+ * @param array $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function validate ( &$value, $name = null, $options = null, $fields = null, $pod = null, $id = null ) {
+ return true;
+ }
+
+ /**
+ * Change the value or perform actions after validation but before saving to the DB
+ *
+ * @param mixed $value
+ * @param int $id
+ * @param string $name
+ * @param array $options
+ * @param array $fields
+ * @param array $pod
+ * @param object $params
+ *
+ * @since 2.0.0
+ */
+ public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
+ return $value;
+ }
+
+ /**
+ * Perform actions after saving to the DB
+ *
+ * @param mixed $value
+ * @param int $id
+ * @param string $name
+ * @param array $options
+ * @param array $fields
+ * @param array $pod
+ * @param object $params
+ *
+ * @since 2.0.0
+ */
+ public function post_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
+
+ }
+
+ /**
+ * Perform actions before deleting from the DB
+ *
+ * @param string $name
+ * @param string $pod
+ * @param int $id
+ * @param object $api
+ *
+ * @since 2.0.0
+ */
+ public function pre_delete ( $id = null, $name = null, $options = null, $pod = null ) {
+
+ }
+
+ /**
+ * Perform actions after deleting from the DB
+ *
+ * @param int $id
+ * @param string $name
+ * @param array $options
+ * @param array $pod
+ *
+ * @since 2.0.0
+ */
+ public function post_delete ( $id = null, $name = null, $options = null, $pod = null ) {
+
+ }
+
+ /**
+ * Customize the Pods UI manage table column output
+ *
+ * @param int $id
+ * @param mixed $value
+ * @param string $name
+ * @param array $options
+ * @param array $fields
+ * @param array $pod
+ *
+ * @since 2.0.0
+ */
+ public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
+
+ }
}
View
406 classes/PodsView.php
@@ -1,204 +1,204 @@
-<?php
-/**
- *
- */
-class PodsView {
-
- /**
- * @var array
- */
- static $cache_modes = array( 'transient', 'site-transient', 'cache' );
-
- /**
- *
- */
- private function __construct () {
- }
-
- /**
- * @static
- *
- * @param $view
- * @param null $data
- * @param int $expires
- * @param string $cache_mode
- *
- * @return bool|mixed|null|string|void
- */
- public static function view ( $view, $data = null, $expires = 0, $cache_mode = 'cache' ) {
- if ( (int) $expires < 1 )
- $expires = 0;
-
- if ( !in_array( $cache_mode, self::$cache_modes ) )
- $cache_mode = 'cache';
-
- $cache_key = sanitize_title( pods_str_replace( array( PODS_DIR . 'ui/', ABSPATH, WP_CONTENT_DIR ), array( 'pods-ui-', 'pods-ui-' ), $view, 1 ) );
-
- if ( false === strpos( $view, PODS_DIR . 'ui/' ) && false === strpos( $view, PODS_DIR . 'components/' ) && false === strpos( $view, WP_CONTENT_DIR ) && false === strpos( $view, ABSPATH ) ) {
- $output = self::get( $cache_key, $cache_mode );
-
- if ( false !== $output && null !== $output ) {
- if ( 0 < $expires )
- return $output;
- else
- self::clear( $cache_key, $cache_mode );
- }
- }
-
- $output = self::get_template_part( $view, $data );
-
- if ( false === $output )
- return false;
-
- if ( 0 < $expires )
- self::set( $cache_key, $output, $cache_mode );
-
- $output = apply_filters( 'pods_view', $output, $view, $data, $expires, $cache_mode );
-
- return $output;
- }
-
- /**
- * @static
- * @param $key
- * @param string $cache_mode
- * @return bool|mixed|null|void
- */
- public static function get ( $key, $cache_mode = 'cache' ) {
- if ( !in_array( $cache_mode, self::$cache_modes ) )
- $cache_mode = 'cache';
-
- $value = null;
-
- if ( 'transient' == $cache_mode )
- $value = get_transient( 'pods_view_' . $key );
- elseif ( 'site-transient' == $cache_mode )
- $value = get_site_transient( 'pods_view_' . $key );
- elseif ( 'cache' == $cache_mode )
- $value = wp_cache_get( $key, 'pods_view' );
-
- $value = apply_filters( 'pods_view_get_' . $cache_mode, $value, $key );
-
- return $value;
- }
-
- /**
- * @static
- * @param $key
- * @param $value
- * @param int $expires
- * @param null $cache_mode
- * @return mixed
- */
- public static function set ( $key, $value, $expires = 0, $cache_mode = null ) {
- if ( (int) $expires < 1 )
- $expires = 0;
-
- if ( !in_array( $cache_mode, self::$cache_modes ) )
- $cache_mode = 'cache';
-
- if ( 'transient' == $cache_mode )
- set_transient( 'pods_view_' . $key, $value, $expires );
- elseif ( 'site-transient' == $cache_mode )
- set_site_transient( 'pods_view_' . $key, $value, $expires );
- elseif ( 'cache' == $cache_mode )
- wp_cache_set( $key, $value, 'pods_view', $expires );
-
- do_action( 'pods_view_set_' . $cache_mode, $key, $value, $expires );
-
- return $value;
- }
-
- /**
- * @static
- * @param $key
- * @param null $cache_mode
- * @return bool
- */
- public static function clear ( $key, $cache_mode = null ) {
- global $wpdb;
-
- if ( !in_array( $cache_mode, self::$cache_modes ) )
- $cache_mode = 'cache';
-
- if ( 'transient' == $cache_mode ) {
- if ( true === $key ) {
- $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE option_name LIKE '_transient_pods_view_%'");
- wp_cache_flush();
- }
- else
- delete_transient( 'pods_view_' . $key );
- }
- elseif ( 'site-transient' == $cache_mode ) {
- if ( true === $key ) {
- $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE option_name LIKE '_site_transient_pods_view_%'" );
- wp_cache_flush();
- }
- else
- delete_site_transient( 'pods_view_' . $key );
- }
- elseif ( 'cache' == $cache_mode ) {
- if ( true === $key )
- wp_cache_flush();
- else
- wp_cache_delete( $key, 'pods_view' );
- }
-
- do_action( 'pods_view_clear_' . $cache_mode, $key );
-
- return true;
- }
-
- /**
- * @static
- * @param $_view
- * @param null|array $_data
- * @return bool|mixed|string|void
- */
- private static function get_template_part ( $_view, $_data = null ) {
- $_view = self::locate_template( $_view );
- if ( empty( $_view ) )
- return $_view;
-
- if ( !empty( $_data ) && is_array( $_data ) )
- extract( $_data, EXTR_SKIP );
-
- ob_start();
- require $_view;
- $output = ob_get_clean();
-
- return $output;
- }
-
- /**
- * @static
- * @param $_view
- * @return bool|mixed|string|void
- */
- private static function locate_template ( $_view ) {
- // Keep it safe
- $_view = trim( str_replace( '../', '', (string) $_view ) );
-
- $located = false;
-
- if ( empty( $_view ) )
- return false;
- elseif ( false === strpos( $_view, PODS_DIR . 'ui/' ) && false === strpos( $_view, PODS_DIR . 'components/' ) && false === strpos( $_view, WP_CONTENT_DIR ) && false === strpos( $_view, ABSPATH ) ) {
- $_view = rtrim( $_view, '/' );
-
- if ( empty( $_view ) )
- return false;
-
- if ( file_exists( STYLESHEETPATH . '/' . $_view ) )
- $located = STYLESHEETPATH . '/' . $_view;
- elseif ( file_exists( TEMPLATEPATH . '/' . $_view ) )
- $located = TEMPLATEPATH . '/' . $_view;
- }
- elseif ( file_exists( $_view ) )
- $located = $_view;
- else
- $located = apply_filters( 'pods_view_locate_template', $located, $_view );
-
- return $located;
- }
+<?php
+/**
+ *
+ */
+class PodsView {
+
+ /**
+ * @var array
+ */
+ static $cache_modes = array( 'transient', 'site-transient', 'cache' );
+
+ /**
+ *
+ */
+ private function __construct () {
+ }
+
+ /**
+ * @static
+ *
+ * @param $view
+ * @param null $data
+ * @param int $expires
+ * @param string $cache_mode
+ *
+ * @return bool|mixed|null|string|void
+ */
+ public static function view ( $view, $data = null, $expires = 0, $cache_mode = 'cache' ) {
+ if ( (int) $expires < 1 )
+ $expires = 0;
+
+ if ( !in_array( $cache_mode, self::$cache_modes ) )
+ $cache_mode = 'cache';
+
+ $cache_key = sanitize_title( pods_str_replace( array( PODS_DIR . 'ui/', ABSPATH, WP_CONTENT_DIR ), array( 'pods-ui-', 'pods-ui-' ), $view, 1 ) );
+
+ if ( false === strpos( $view, PODS_DIR . 'ui/' ) && false === strpos( $view, PODS_DIR . 'components/' ) && false === strpos( $view, WP_CONTENT_DIR ) && false === strpos( $view, ABSPATH ) ) {
+ $output = self::get( $cache_key, $cache_mode );
+
+ if ( false !== $output && null !== $output ) {
+ if ( 0 < $expires )
+ return $output;
+ else
+ self::clear( $cache_key, $cache_mode );
+ }
+ }
+
+ $output = self::get_template_part( $view, $data );
+
+ if ( false === $output )
+ return false;
+
+ if ( 0 < $expires )
+ self::set( $cache_key, $output, $cache_mode );
+
+ $output = apply_filters( 'pods_view', $output, $view, $data, $expires, $cache_mode );
+
+ return $output;
+ }
+
+ /**
+ * @static
+ * @param $key
+ * @param string $cache_mode
+ * @return bool|mixed|null|void
+ */
+ public static function get ( $key, $cache_mode = 'cache' ) {
+ if ( !in_array( $cache_mode, self::$cache_modes ) )
+ $cache_mode = 'cache';
+
+ $value = null;
+
+ if ( 'transient' == $cache_mode )
+ $value = get_transient( 'pods_view_' . $key );
+ elseif ( 'site-transient' == $cache_mode )
+ $value = get_site_transient( 'pods_view_' . $key );
+ elseif ( 'cache' == $cache_mode )
+ $value = wp_cache_get( $key, 'pods_view' );
+
+ $value = apply_filters( 'pods_view_get_' . $cache_mode, $value, $key );
+
+ return $value;
+ }
+
+ /**
+ * @static
+ * @param $key
+ * @param $value
+ * @param int $expires
+ * @param null $cache_mode
+ * @return mixed
+ */
+ public static function set ( $key, $value, $expires = 0, $cache_mode = null ) {
+ if ( (int) $expires < 1 )
+ $expires = 0;
+
+ if ( !in_array( $cache_mode, self::$cache_modes ) )
+ $cache_mode = 'cache';
+
+ if ( 'transient' == $cache_mode )
+ set_transient( 'pods_view_' . $key, $value, $expires );
+ elseif ( 'site-transient' == $cache_mode )
+ set_site_transient( 'pods_view_' . $key, $value, $expires );
+ elseif ( 'cache' == $cache_mode )
+ wp_cache_set( $key, $value, 'pods_view', $expires );
+
+ do_action( 'pods_view_set_' . $cache_mode, $key, $value, $expires );
+
+ return $value;
+ }
+
+ /**
+ * @static
+ * @param $key
+ * @param null $cache_mode
+ * @return bool
+ */
+ public static function clear ( $key, $cache_mode = null ) {
+ global $wpdb;
+
+ if ( !in_array( $cache_mode, self::$cache_modes ) )
+ $cache_mode = 'cache';
+
+ if ( 'transient' == $cache_mode ) {
+ if ( true === $key ) {
+ $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE option_name LIKE '_transient_pods_view_%'");
+ wp_cache_flush();
+ }
+ else
+ delete_transient( 'pods_view_' . $key );
+ }
+ elseif ( 'site-transient' == $cache_mode ) {
+ if ( true === $key ) {
+ $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE option_name LIKE '_site_transient_pods_view_%'" );
+ wp_cache_flush();
+ }
+ else
+ delete_site_transient( 'pods_view_' . $key );
+ }
+ elseif ( 'cache' == $cache_mode ) {
+ if ( true === $key )
+ wp_cache_flush();
+ else
+ wp_cache_delete( $key, 'pods_view' );
+ }
+
+ do_action( 'pods_view_clear_' . $cache_mode, $key );
+
+ return true;
+ }
+
+ /**
+ * @static
+ * @param $_view
+ * @param null|array $_data
+ * @return bool|mixed|string|void
+ */
+ private static function get_template_part ( $_view, $_data = null ) {
+ $_view = self::locate_template( $_view );
+ if ( empty( $_view ) )
+ return $_view;
+
+ if ( !empty( $_data ) && is_array( $_data ) )
+ extract( $_data, EXTR_SKIP );
+
+ ob_start();
+ require $_view;
+ $output = ob_get_clean();
+
+ return $output;
+ }
+
+ /**
+ * @static
+ * @param $_view
+ * @return bool|mixed|string|void
+ */
+ private static function locate_template ( $_view ) {
+ // Keep it safe
+ $_view = trim( str_replace( '../', '', (string) $_view ) );
+
+ $located = false;
+
+ if ( empty( $_view ) )
+ return false;
+ elseif ( false === strpos( $_view, PODS_DIR . 'ui/' ) && false === strpos( $_view, PODS_DIR . 'components/' ) && false === strpos( $_view, WP_CONTENT_DIR ) && false === strpos( $_view, ABSPATH ) ) {
+ $_view = rtrim( $_view, '/' );
+
+ if ( empty( $_view ) )
+ return false;
+
+ if ( file_exists( STYLESHEETPATH . '/' . $_view ) )
+ $located = STYLESHEETPATH . '/' . $_view;
+ elseif ( file_exists( TEMPLATEPATH . '/' . $_view ) )
+ $located = TEMPLATEPATH . '/' . $_view;
+ }
+ elseif ( file_exists( $_view ) )
+ $located = $_view;
+ else
+ $located = apply_filters( 'pods_view_locate_template', $located, $_view );
+
+ return $located;
+ }
}
View
524 classes/fields/boolean.php
@@ -1,263 +1,263 @@
-<?php
-/**
- *
- */
-class PodsField_Boolean extends PodsField {
-
- /**
- * Field Type Identifier
- *
- * @var string
- * @since 2.0.0
- */
- public static $type = 'boolean';
-
- /**
- * Field Type Label
- *
- * @var string
- * @since 2.0.0
- */
- public static $label = 'Yes / No';
-
- /**
- * Field Type Preparation
- *
- * @var string
- * @since 2.0.0
- */
- public static $prepare = '%s';
-
- /**
- * Do things like register/enqueue scripts and stylesheets
- *
- * @since 2.0.0
- */
- public function __construct () {
-
- }
-
- /**
- * Add options and set defaults to
- *
- * @param array $options
- *
- * @since 2.0.0
- */
- public function options () {
- $options = array(
- 'boolean_format_type' => array(
- 'label' => __( 'Format Type', 'pods' ),
- 'default' => 'checkbox',
- 'type' => 'pick',
- 'data' => array(
- 'checkbox' => __( 'Checkbox', 'pods' ),
- 'radio' => __( 'Radio Buttons', 'pods' ),
- 'dropdown' => __( 'Drop Down', 'pods' )
- ),
- 'dependency' => true
- ),
- 'boolean_yes_label' => array(
- 'label' => __( 'Yes Label', 'pods' ),
- 'default' => __( 'Yes', 'pods' ),
- 'type' => 'text'
- ),
- 'boolean_no_label' => array(
- 'label' => __( 'No Label', 'pods' ),
- 'default' => __( 'No', 'pods' ),
- 'type' => 'text'
- )
- );
- return $options;
- }
-
- /**
- * Define the current field's schema for DB table storage
- *
- * @param array $options
- *
- * @return array
- * @since 2.0.0
- */
- public function schema ( $options = null ) {
- $schema = 'BOOL DEFAULT 0';
-
- return $schema;
- }
-
- /**
- * Change the way the value of the field is displayed with Pods::get
- *
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
- $yesno = array(
- 1 => pods_var( 'boolean_yes_label', $options ),
- 0 => pods_var( 'boolean_no_label', $options )
- );
-
- // Deprecated handling for 1.x
- if ( !parent::$deprecated && isset( $yesno[ (int) $value ] ) )
- $value = $yesno[ (int) $value ];
-
- return $value;
- }
-
- /**
- * Customize output of the form field
- *
- * @param string $name
- * @param mixed $value
- * @param array $options
- * @param array $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
- $options = (array) $options;
-
- if ( is_array( $value ) )
- $value = !empty( $value );
-
- $field_type = 'checkbox';
-
- if ( 'checkbox' != pods_var( 'boolean_format_type', $options ) ) {
- $options[ 'data' ] = array(
- 1 => pods_var( 'boolean_yes_label', $options ),
- 0 => pods_var( 'boolean_no_label', $options )
- );
-
- if ( 'radio' == pods_var( 'boolean_format_type', $options ) )
- $field_type = 'radio';
- elseif ( 'dropdown' == pods_var( 'boolean_format_type', $options ) )
- $field_type = 'select';
- }
- else {
- $options[ 'data' ] = array(
- 1 => pods_var( 'boolean_yes_label', $options )
- );
- }
-
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
- }
-
- /**
- * Build regex necessary for JS validation
- *
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param string $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
- return false;
- }
-
- /**
- * Validate a value before it's saved
- *
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param int $id
- *
- * @since 2.0.0
- */
- public function validate ( &$value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
- return true;
- }
-
- /**
- * Change the value or perform actions after validation but before saving to the DB
- *
- * @param mixed $value
- * @param int $id
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param object $params
- *
- * @since 2.0.0
- */
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
- // Only allow 0 / 1
- $value = ( 1 == (int) $value ? 1 : 0 );
-
- return $value;
- }
-
- /**
- * Perform actions after saving to the DB
- *
- * @param mixed $value
- * @param int $id
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- * @param object $params
- *
- * @since 2.0.0
- */
- public function post_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
-
- }
-
- /**
- * Perform actions before deleting from the DB
- *
- * @param string $name
- * @param string $pod
- * @param int $id
- * @param object $api
- *
- * @since 2.0.0
- */
- public function pre_delete ( $id = null, $name = null, $options = null, $pod = null ) {
-
- }
-
- /**
- * Perform actions after deleting from the DB
- *
- * @param int $id
- * @param string $name
- * @param array $options
- * @param array $pod
- *
- * @since 2.0.0
- */
- public function post_delete ( $id = null, $name = null, $options = null, $pod = null ) {
-
- }
-
- /**
- * Customize the Pods UI manage table column output
- *
- * @param int $id
- * @param mixed $value
- * @param string $name
- * @param array $options
- * @param array $fields
- * @param array $pod
- *
- * @since 2.0.0
- */
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
-
- }
+<?php
+/**
+ *
+ */
+class PodsField_Boolean extends PodsField {
+
+ /**
+ * Field Type Identifier
+ *
+ * @var string
+ * @since 2.0.0
+ */
+ public static $type = 'boolean';
+
+ /**
+ * Field Type Label
+ *
+ * @var string
+ * @since 2.0.0
+ */
+ public static $label = 'Yes / No';
+
+ /**
+ * Field Type Preparation
+ *
+ * @var string
+ * @since 2.0.0
+ */
+ public static $prepare = '%s';
+
+ /**
+ * Do things like register/enqueue scripts and stylesheets
+ *
+ * @since 2.0.0
+ */
+ public function __construct () {
+
+ }
+
+ /**
+ * Add options and set defaults to
+ *
+ * @param array $options
+ *
+ * @since 2.0.0
+ */
+ public function options () {
+ $options = array(
+ 'boolean_format_type' => array(
+ 'label' => __( 'Format Type', 'pods' ),
+ 'default' => 'checkbox',
+ 'type' => 'pick',
+ 'data' => array(
+ 'checkbox' => __( 'Checkbox', 'pods' ),
+ 'radio' => __( 'Radio Buttons', 'pods' ),
+ 'dropdown' => __( 'Drop Down', 'pods' )
+ ),
+ 'dependency' => true
+ ),
+ 'boolean_yes_label' => array(
+ 'label' => __( 'Yes Label', 'pods' ),
+ 'default' => __( 'Yes', 'pods' ),
+ 'type' => 'text'
+ ),
+ 'boolean_no_label' => array(
+ 'label' => __( 'No Label', 'pods' ),
+ 'default' => __( 'No', 'pods' ),
+ 'type' => 'text'
+ )
+ );
+ return $options;
+ }
+
+ /**
+ * Define the current field's schema for DB table storage
+ *
+ * @param array $options
+ *
+ * @return array
+ * @since 2.0.0
+ */
+ public function schema ( $options = null ) {
+ $schema = 'BOOL DEFAULT 0';
+
+ return $schema;
+ }
+
+ /**
+ * Change the way the value of the field is displayed with Pods::get
+ *
+ * @param mixed $value
+ * @param string $name
+ * @param array $options
+ * @param array $fields
+ * @param array $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
+ $yesno = array(
+ 1 => pods_var( 'boolean_yes_label', $options ),
+ 0 => pods_var( 'boolean_no_label', $options )
+ );
+
+ // Deprecated handling for 1.x
+ if ( !parent::$deprecated && isset( $yesno[ (int) $value ] ) )
+ $value = $yesno[ (int) $value ];
+
+ return $value;
+ }
+
+ /**
+ * Customize output of the form field
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ * @param array $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
+ $options = (array) $options;
+
+ if ( is_array( $value ) )
+ $value = !empty( $value );
+
+ $field_type = 'checkbox';
+
+ if ( 'checkbox' != pods_var( 'boolean_format_type', $options ) ) {
+ $options[ 'data' ] = array(
+ 1 => pods_var( 'boolean_yes_label', $options ),
+ 0 => pods_var( 'boolean_no_label', $options )
+ );
+
+ if ( 'radio' == pods_var( 'boolean_format_type', $options ) )
+ $field_type = 'radio';
+ elseif ( 'dropdown' == pods_var( 'boolean_format_type', $options ) )
+ $field_type = 'select';
+ }
+ else {
+ $options[ 'data' ] = array(
+ 1 => pods_var( 'boolean_yes_label', $options )
+ );
+ }
+
+ pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
+ }
+
+ /**
+ * Build regex necessary for JS validation
+ *
+ * @param mixed $value
+ * @param string $name
+ * @param array $options
+ * @param string $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
+ return false;
+ }
+
+ /**
+ * Validate a value before it's saved
+ *
+ * @param mixed $value
+ * @param string $name
+ * @param array $options
+ * @param array $fields
+ * @param array $pod
+ * @param int $id
+ *
+ * @since 2.0.0
+ */
+ public function validate ( &$value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
+ return true;
+ }
+
+ /**
+ * Change the value or perform actions after validation but before saving to the DB