示例#1
0
 /**
  * Constructor
  */
 public function __construct($scope, $options, $allowed_hooks = array())
 {
     // Merge default options
     $this->default_options = array_merge($this->default_options, array('max' => 0, 'min' => 1, 'std' => array(), 'fieldsets' => array(), 'fields' => array(), 'depth' => 0, 'add_text' => __('Add', 'youxi'), 'edit_text' => __('Edit', 'youxi'), 'delete_text' => __('Delete', 'youxi'), 'preview_template' => false, 'confirm_delete' => __('Are you sure you want to remove this item?', 'youxi')));
     parent::__construct($scope, $options, $allowed_hooks);
     /* Construct the template fields */
     $fields = (array) $this->get_option('fields');
     $depth = $this->get_option('depth');
     $scope = "{$this->scope}[{$this->field_name}][{{ data.index_{$depth} }}]";
     $the_fields = array();
     foreach ($fields as $name => $atts) {
         if (isset($atts['type'])) {
             $options = array_merge(compact('name'), (array) $atts);
             /* Check for nested repeaters */
             if ('repeater' == $options['type']) {
                 $options['depth'] = $depth + 1;
             }
             /* Prevent a TinyMCE field added to the repeater */
             if ('richtext' == $options['type']) {
                 $options['type'] = 'textarea';
                 unset($options['tinymce']);
             }
             $field = Youxi_Form_Field::factory($scope, $options);
             if (is_a($field, 'Youxi_Form_Field')) {
                 $the_fields[$name] = $field;
             }
         }
     }
     $this->set_option('fields', $the_fields);
 }
示例#2
0
 /**
  * Constructor
  */
 public function __construct($shortcode, $form_data)
 {
     $this->shortcode = $shortcode;
     $this->form_data = $form_data;
     $this->fields = array();
     /* Loop through the shortcode attributes generating field objects */
     foreach (array_merge($shortcode->atts, array('content' => $shortcode->content)) as $name => $atts) {
         $options = array_merge(compact('name'), (array) $atts);
         $field = Youxi_Form_Field::factory($shortcode->tag, $options);
         if (is_a($field, 'Youxi_Form_Field')) {
             $this->fields[] = $field;
         }
     }
 }
 /**
  * Constructor
  */
 public function __construct($scope, $options, $allowed_hooks = array())
 {
     // Merge default options
     $this->default_options = array_merge($this->default_options, array('fieldsets' => array()));
     parent::__construct($scope, $options, $allowed_hooks);
     /* Construct the template fieldsets */
     $fieldsets = (array) $this->get_option('fieldsets');
     foreach ($fieldsets as $id => $fieldset) {
         if (!isset($fieldset['fields'])) {
             unset($fieldsets[$id]);
             continue;
         }
         foreach ((array) $fieldset['fields'] as $name => $atts) {
             if (isset($atts['type'])) {
                 $options = array_merge(compact('name'), (array) $atts);
                 $field = Youxi_Form_Field::factory("{$this->scope}[{$this->field_name}][{$id}]", $options);
                 if (is_a($field, 'Youxi_Form_Field')) {
                     $fieldsets[$id]['fields'][$name] = $field;
                 }
             }
         }
     }
     $this->set_option('fieldsets', $fieldsets);
 }
示例#4
0
 /**
  * Helper method to generate the form object
  *
  * @param string The current metabox post type name
  *
  * @return Youxi_Form The generated form instance
  */
 public function get_form($post_type)
 {
     $metabox_id = "{$post_type}_{$this->id}";
     if (isset($this->form_cache[$metabox_id]) && is_a($this->form_cache[$metabox_id], 'Youxi_Form')) {
         return $this->form_cache[$metabox_id];
     }
     /* Instantiate the form fields */
     $fields = array();
     foreach ($this->fields as $id => $field) {
         $fields[$id] = Youxi_Form_Field::factory("{$post_type}[{$this->id}]", $field);
     }
     /* Generate the form */
     $form = new Youxi_Form($fields, array('form_tag' => 'div', 'form_attr' => array('class' => 'youxi-form youxi-form-inline'), 'before_fields' => wp_nonce_field("youxi_mb_{$metabox_id}", "{$metabox_id}_nonce", true, false), 'group_attr' => array('class' => array('youxi-form-row', 'youxi-form-block' => array('type' => array('checkbox', 'gallery')))), 'control_attr' => array('class' => 'youxi-form-item'), 'label_attr' => array('class' => 'youxi-form-label'), 'field_attr' => array('class' => array('youxi-form-large' => array('type' => array('text', 'textarea', 'code', 'url', 'select', 'iconchooser')))), 'fieldsets' => $this->fieldsets));
     /* Cache the form object */
     $this->form_cache[$metabox_id] = $form;
     return $form;
 }