Example #1
0
 public function build()
 {
     $set = $this->things;
     $result = array('scripts' => array(), 'styles' => array(), 'localize_name' => 'vp_opt', 'localize_default' => array('nonce', 'impexp_msg'), 'localize' => array('name' => 'vpt_option'), 'use_upload' => false, 'use_new_media_upload' => false, 'main_js' => array('name' => 'vp-option', 'path' => VP_PUBLIC_URL . '/js/option.min.js'), 'main_css' => array('name' => 'vp-option', 'path' => VP_PUBLIC_URL . '/css/option.min.css'));
     $result['scripts'] = VP_Util_Config::instance()->load('dependencies', 'scripts.always');
     $result['styles'] = VP_Util_Config::instance()->load('dependencies', 'styles.always');
     $scripts = VP_Util_Config::instance()->load('dependencies', 'scripts.paths');
     $styles = VP_Util_Config::instance()->load('dependencies', 'styles.paths');
     $rules = VP_Util_Config::instance()->load('dependencies', 'rules');
     $fields = $set->get_fields();
     foreach ($fields as $field) {
         $type = VP_Util_Reflection::field_type_from_class(get_class($field));
         if (array_key_exists($type, $rules)) {
             $result['scripts'] = array_merge($result['scripts'], $rules[$type]['js']);
             $result['styles'] = array_merge($result['styles'], $rules[$type]['css']);
         }
         // check if using upload button
         if ($type == 'upload') {
             $result['use_upload'] = true;
         }
     }
     $result['scripts'] = array_unique($result['scripts']);
     $result['styles'] = array_unique($result['styles']);
     return $result;
 }
Example #2
0
 function _enfactor_field($field, $mb, $in_group = false)
 {
     $is_multi = VP_Util_Reflection::is_multiselectable($field['type']);
     if (!$is_multi) {
         $mb->the_field($field['name']);
     } else {
         $mb->the_field($field['name'], WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI);
     }
     $field['name'] = $mb->get_the_name();
     // create the object
     $make = VP_Util_Reflection::field_class_from_type($field['type']);
     $vp_field = call_user_func("{$make}::withArray", $field);
     // get value from mb
     $value = $mb->get_the_value();
     // get default from array
     $default = $vp_field->get_default();
     // if tocopy always assign default
     if ($mb->is_parent_multi() and $mb->is_in_multi_last()) {
         $value = $default;
     } else {
         // if value is null and default exist, use default
         if (is_null($value) and !is_null($default) and empty($this->meta)) {
             $value = $default;
         } else {
             if (VP_Util_Reflection::is_multiselectable($field['type'])) {
                 if (!is_array($value)) {
                     $value = array($value);
                 }
             }
         }
     }
     $vp_field->set_value($value);
     if (!$in_group) {
         $vp_field->add_container_extra_classes(array('vp-meta-single'));
     }
     return $vp_field;
 }
Example #3
0
 public function populate_values($opt, $force_update = false)
 {
     $fields = $this->get_fields();
     foreach ($fields as $field) {
         $is_multi = VP_Util_Reflection::is_multiselectable($field);
         if (array_key_exists($field->get_name(), $opt)) {
             if ($is_multi and is_array($opt[$field->get_name()])) {
                 $field->set_value($opt[$field->get_name()]);
             }
             if (!$is_multi and !is_array($opt[$field->get_name()])) {
                 $field->set_value($opt[$field->get_name()]);
             }
         } else {
             if ($force_update) {
                 if ($is_multi) {
                     $field->set_value(array());
                 } else {
                     $field->set_value('');
                 }
             }
         }
     }
 }
Example #4
0
    function print_form($attributes)
    {
        ?>
		<div class="vp-sc-fields">
		<?php 
        foreach ($attributes as $attr) {
            // create the object
            $make = VP_Util_Reflection::field_class_from_type($attr['type']);
            // prefix name
            $attr['name'] = '_' . $attr['name'];
            $field = call_user_func("{$make}::withArray", $attr);
            $default = $field->get_default();
            if (!is_null($default)) {
                $field->set_value($default);
            }
            ?>

			<?php 
            if ($attr['type'] !== 'notebox') {
                ?>
				<div class="vp-sc-field vp-<?php 
                echo $attr['type'];
                ?>
" data-vp-type="vp-<?php 
                echo $attr['type'];
                ?>
">
					<div class="label"><label><?php 
                echo $attr['label'];
                ?>
</label></div>
					<div class="field"><div class="input"><?php 
                echo $field->render(true);
                ?>
</div></div>
				</div>
			<?php 
            } else {
                ?>
				<?php 
                $status = isset($attr['status']) ? $attr['status'] : 'normal';
                ?>
				<div class="vp-sc-field vp-<?php 
                echo $attr['type'];
                ?>
 note-<?php 
                echo $status;
                ?>
" data-vp-type="vp-<?php 
                echo $attr['type'];
                ?>
">
					<?php 
                echo $field->render(true);
                ?>
				</div>
			<?php 
            }
            ?>

			<?php 
        }
        ?>
		</div>
		<div class="vp-sc-action">
			<button class="vp-sc-insert button"><?php 
        _e('Insert', 'vp_textdomain');
        ?>
</button>
			<button class="vp-sc-cancel button"><?php 
        _e('Cancel', 'vp_textdomain');
        ?>
</button>
		</div>
		<?php 
    }
Example #5
0
 private function parse_field($field)
 {
     if (sh_set($field, 'type') == 'group') {
         foreach ($field['fields'] as $f) {
             //printr($f);
             $this->parse_field($f);
         }
     } else {
         $class = VP_Util_Reflection::field_class_from_type($field['type']);
         $vp_field = call_user_func("{$class}::withArray", $field);
         return $vp_field;
     }
 }
 /**
  * Setter for $_default
  *
  * @param mixed $_default default value of the field
  */
 public function set_default($_default)
 {
     if (is_array($_default) and !VP_Util_Reflection::is_multiselectable($this)) {
         $_default = VP_Util_Array::first($_default);
     }
     $this->_default = $_default;
     return $this;
 }
Example #7
0
        /**
         * Output the settings update form.
         *
         * @see WP_Widget::form
         * @param array $instance Current settings.
         *
         * @access public
         * @return string
         */
        public function form($instance)
        {
            foreach ($this->controls as $control) {
                $control->addHtmlAttribute('id', $this->get_field_id($control->getName()));
                $control->addHtmlAttribute('class', 'widefat');
                $attributes = $control->getSettings();
                $attributes['name'] = $this->get_field_name($control->getName());
                // create field object
                $make = \VP_Util_Reflection::field_class_from_type($attributes['type']);
                $field = call_user_func("{$make}::withArray", $attributes);
                $default = $field->get_default();
                //@todo rebuild this!!!
                if ($attributes['type'] == 'checkbox') {
                    $value = isset($instance[$control->getName()]) ? $instance[$control->getName()] : '';
                    $field->set_value($value);
                } else {
                    if (isset($instance[$control->getName()]) && !empty($instance[$control->getName()])) {
                        $field->set_value($instance[$control->getName()]);
                    } else {
                        if (!is_null($default)) {
                            $field->set_value($default);
                        }
                    }
                }
                ?>
				<p>
					<label for="<?php 
                echo $this->get_field_id($field->get_name());
                ?>
">
						<?php 
                echo $field->get_label();
                ?>
						<?php 
                echo $field->render(true);
                ?>
						<?php 
                \VP_Util_Text::print_if_exists($field->get_description(), '<div class="description">%s</div>');
                ?>
					</label>
				</p>
				<?php 
            }
        }
Example #8
0
 private function parse_field($field)
 {
     $class = VP_Util_Reflection::field_class_from_type($field['type']);
     $vp_field = call_user_func("{$class}::withArray", $field);
     return $vp_field;
 }