* @version 1.2 */ class ACF_NGGallery_Field extends acf_Field { /** * WordPress Localization Text Domain * * The textdomain for the field is controlled by the helper class. * @var string */ private $l10n_domain; private $helper; /** * Class Constructor - Instantiates a new NGGallery Field */ public function __construct($parent) { parent::__construct($parent); error_log("plugin constuctor"); //Get the textdomain from the Helper class $this->l10n_domain = acf_nggallery_field_plugin::L10N_DOMAIN; $this->name = 'nggallery-field'; $this->category = __("Relational", 'acf'); // Basic, Content, Choice, etc $post_title = ( !class_exists('nggdb') ) ? '. ' . __( 'NextGEN Gallery plugin is not installed or activated!', $this->l10n_domain ) : false; $this->title = __( 'NextGEN Gallery'.$post_title, $this->l10n_domain ); $this->label = __( 'NextGEN Gallery'.$post_title, $this->l10n_domain ); $this->defaults = array( 'input_type' => 'select' , 'allow_null' => true , 'input_size' => 5 , 'nextgen_type' => 'Galleries and Albums' ); } /** * Creates the nggallery field for inside post metaboxes * * @see acf_Field::create_field() */ public function create_field( $field ) { global $ngg, $nggdb, $wp_query; $field = array_merge($this->defaults, $field); $values = $field[ 'value' ]; if ( !empty($values[0]) ): foreach ( $values as $form ) { if ( in_array ( 'gallery', $form ) ) $values_gallery[]=$form['ngg_id']; if ( in_array ( 'album', $form ) ) $values_album[]=$form['ngg_id']; } endif; if ( class_exists('nggdb') ) : // Settings of NextGEN Gallery SQL query $limit = 0; $start = 0; $order_by = 'title'; $order_dir = 'ASC'; // Seek to all NextGEN Galleries $gallerylist = $nggdb->find_all_galleries( $order_by, $order_dir , TRUE, $limit, $start, false); $albumlist = $nggdb->find_all_album( 'name', $order_dir, $limit, $start); $haystack = array( 'select', 'multiselect' ); if( in_array( $field[ 'input_type' ], $haystack ) ) : ?> defaults, $field); ?> parent->create_field(array( 'type' => 'radio', 'name' => 'fields['.$key.'][allow_null]', 'value' => $field['allow_null'], 'choices' => array( '1' => 'Yes', '0' => 'No', ), 'layout' => 'horizontal', )); ?>

domain ); ?>

parent->create_field( array( 'type' => 'select', 'name' => "fields[{$key}][nextgen_type]", 'value' => $field[ 'nextgen_type' ], 'class' => "nggallery_nextgen_type nggallery_nextgen_type_{$key}", 'choices' => array( 'Galleries and Albums' => __( 'Galleries and Albums', $this->domain ) , 'Galleries' => __( 'Galleries', $this->domain ) , 'Albums' => __( 'Albums', $this->domain ) ) ) ); ?>

l10n_domain ); ?>

parent->create_field( array( 'type' => 'select', 'name' => "fields[{$key}][input_type]", 'value' => $field[ 'input_type' ], 'class' => "nggallery_input_type nggallery_input_type_{$key}", 'choices' => array( 'select' => 'Select', 'multiselect' => 'Multi-Select', //'token' => 'Input Tokenizer', ) ) ); ?>

l10n_domain ); ?>

parent->create_field( array( 'type' => 'select', 'name' => "fields[{$key}][input_size]", 'value' => $field[ 'input_size' ], 'choices' => array_combine( range( 3, 15, 2 ), range( 3, 15, 2 ) ), ) ); ?> defaults, $field); foreach( $value as $key=>$item ) { $items = explode( ',', $item ); foreach( $items as $item ) { if( is_numeric( $item ) ) $values[$key]['ngg_id'] = intval ( $item ); else $values[$key]['ngg_form'] = strval( $item ); } } parent::update_value( $post_id, $field, $values ); } /** * Returns the values of the field * * @see acf_Field::get_value() * @param int $post_id * @param array $field * @return mixed */ public function get_value( $post_id, $field ) { $value = (array) parent::get_value( $post_id, $field ); return $value; } /** * Returns the value of the field for the advanced custom fields API * * @see acf_Field::get_value_for_api() * @param int $post_id * @param array $field * @return string */ public function get_value_for_api( $post_id, $field ) { return parent::get_value_for_api($post_id, $field); } } endif; ?>