示例#1
0
 /**
  * Catch the ajax search and push results
  *
  * @since 1.0.0
  * @access public
  */
 public function init()
 {
     $defaults = array('add_label' => __('Add Related Post', 'uix'), 'config' => array('limit' => 1), 'query' => array('post_type' => 'any', 'post_per_page' => 5));
     $this->struct = array_merge($defaults, $this->struct);
     $data = uix()->request_vars('post');
     if (!empty($data['uixId']) && $data['uixId'] === $this->id()) {
         $this->do_lookup($data);
     }
 }
示例#2
0
 /**
  * Sets the controls data
  *
  * @since 1.0.0
  * @see \uix\uix
  * @access public
  */
 public function setup()
 {
     // run parents to setup sanitization filters
     parent::setup();
     $value = array($this->slug, '');
     $data = uix()->request_vars('post');
     if (!empty($this->struct['value'])) {
         $value[$this->slug] = $this->struct['value'];
     }
     if (isset($data[$this->id()])) {
         $value[$this->slug] = $data[$this->id()];
     }
     $this->set_data($value);
     // base attributes defined
     $this->attributes['name'] = $this->name();
     $this->attributes['id'] = $this->id() . '-control';
 }
示例#3
0
 public function test_controls()
 {
     $uix = uix();
     // radio atts
     $uix->ui->box['saving']->child['radio']->set_attributes();
     $radio_atts = $uix->ui->box['saving']->child['radio']->attributes;
     $test_atts = array('name' => 'uix-saving-radio', 'class' => 'widefat', 'type' => 'radio');
     $this->assertSame($radio_atts, $test_atts);
     // checkbox atts
     $uix->ui->box['saving']->child['checkbox']->set_attributes();
     $check_atts = $uix->ui->box['saving']->child['checkbox']->attributes;
     $test_atts = array('name' => 'uix-saving-checkbox[]', 'class' => 'widefat', 'type' => 'checkbox');
     $this->assertSame($check_atts, $test_atts);
     // render checks
     $check_html = $uix->ui->box['saving']->child['checkbox']->render();
     $hash = md5($check_html);
     $this->assertSame($hash, '6ebe1a4425d8d05f029f46ca673c8c96');
     // text classes
     $text_classes = $uix->ui->box['saving']->child['text']->classes();
     $test_classes = array('regular-text');
     $this->assertSame($text_classes, $test_classes);
 }
示例#4
0
 function test_fields()
 {
     $email = uix()->add('control', 'email_field', array('type' => 'email'));
     $this->assertSame($email->type, 'email');
     $file = uix()->add('control', 'file_field', array('type' => 'file'));
     $this->assertSame($file->type, 'file');
     $hidden = uix()->add('control', 'hidden_field', array('type' => 'hidden'));
     $this->assertSame($hidden->type, 'hidden');
     $this->assertSame('<input type="hidden" value="" name="uix-hidden_field" id="uix-hidden_field-control" class="widefat">', $hidden->render());
     $number = uix()->add('control', 'number_field', array('type' => 'number'));
     $this->assertSame($number->type, 'number');
     $color = uix()->add('control', 'color_field', array('type' => 'color'));
     $this->assertSame($color->type, 'color');
     $color->enqueue_core();
     $separator = uix()->add('control', 'separator_field', array('type' => 'separator'));
     $this->assertSame($separator->type, 'separator');
     $button = uix()->add('control', 'button_field', array('type' => 'button', 'label' => 'button', 'attributes' => array('class' => 'special')));
     $this->assertSame($button->type, 'button');
     $this->assertSame('<button name="uix-button_field" id="uix-button_field-control" class="special">button</button>', $button->render());
     ob_start();
     $separator->enqueue_core();
     $html = ob_get_clean();
     $this->assertTrue(is_string($html));
     ob_start();
     $separator->render();
     $html = ob_get_clean();
     $this->assertTrue(is_string($html));
     $template = uix()->add('control', 'template_field', array('type' => 'template', 'template' => __DIR__ . '/ui/page/template.php'));
     $this->assertSame($template->type, 'template');
     ob_start();
     $template->render();
     $html = ob_get_clean();
     $this->assertTrue(is_string($html));
     $textarea = uix()->add('control', 'textarea_field', array('type' => 'textarea', 'rows' => 12));
     $this->assertSame($textarea->type, 'textarea');
     ob_start();
     $textarea->render();
     $html = ob_get_clean();
     $this->assertTrue(is_string($html));
     $toggle = uix()->add('control', 'toggle_field', array('type' => 'toggle'));
     $this->assertSame($toggle->type, 'toggle');
     ob_start();
     $toggle->render();
     $html = ob_get_clean();
     $this->assertTrue(is_string($html));
 }
示例#5
0
 /**
  * prepares Data for extraction and saving
  *
  * @since 1.0.0
  * @see \uix\uix
  * @access public
  */
 public function prepare_data()
 {
     $submit_data = uix()->request_vars('post');
     if (!empty($submit_data)) {
         $instances = array_filter(array_keys($submit_data), array($this, 'compare_var_key'));
         $instances = array_map(array($this, 'build_instance_count'), $instances);
         array_map(array($this, 'push_instance_setup'), array_unique($instances));
     }
     $this->instance = 0;
     // reset instance;
 }
示例#6
0
 /**
  * Sets the controls data
  *
  * @since 1.0.0
  * @see \uix\uix
  * @access public
  */
 public function is_submitted()
 {
     $data = uix()->request_vars('post');
     return isset($data['uixNonce_' . $this->id()]) && wp_verify_nonce($data['uixNonce_' . $this->id()], $this->id());
 }
示例#7
0
文件: box.php 项目: Desertsnowman/UIX
 /**
  * Sets the wrappers attributes
  *
  * @since 1.0.0
  * @access public
  */
 public function set_attributes()
 {
     $action = uix()->request_vars('server');
     $attributes = array('enctype' => 'multipart/form-data', 'method' => 'POST', 'class' => 'uix-ajax uix-' . $this->type, 'data-uix' => $this->slug, 'action' => $action['REQUEST_URI']);
     if (!empty($this->struct['static'])) {
         $attributes = array('class' => 'uix-' . $this->type, 'data-uix' => $this->slug);
     }
     $this->attributes += $attributes;
     parent::set_attributes();
 }
示例#8
0
文件: uix.php 项目: Desertsnowman/UIX
 /**
  * enqueue core assets
  *
  * @since 1.0.0
  * @access public
  */
 public function enqueue_core()
 {
     // attempt to get a config
     if (!$this->is_active()) {
         return;
     }
     // register uix core asset
     $this->core_assets();
     /**
      * do object initilisation
      *
      * @param object current uix instance
      */
     do_action('uix_admin_enqueue_scripts' . $this->type, $this);
     // push assets to ui manager
     uix()->set_assets($this->assets);
     // done enqueuing - dpo inline or manual enqueue.
     $this->enqueue_active_assets();
 }