public function widget($args, $instance)
    {
        $this->instance = $instance;
        $register = hocwp_get_value_by_key($instance, 'register', hocwp_get_value_by_key($this->args, 'register'));
        $button_text = hocwp_get_value_by_key($instance, 'button_text', hocwp_get_value_by_key($this->args, 'button_text'));
        $captcha = (bool) hocwp_get_value_by_key($instance, 'captcha', hocwp_get_value_by_key($this->args, 'captcha'));
        if ($captcha) {
            add_filter('hocwp_use_session', '__return_true');
        }
        $description = hocwp_get_value_by_key($instance, 'description', hocwp_get_value_by_key($this->args, 'description'));
        $desc_position = hocwp_get_value_by_key($instance, 'desc_position', hocwp_get_value_by_key($this->args, 'desc_position'));
        $fields = $this->get_value_fields($instance);
        $all_fields = explode(',', $fields);
        hocwp_widget_before($args, $instance);
        ob_start();
        ?>
		<form class="subscribe-form hocwp-subscribe-form" method="post"
		      data-captcha="<?php 
        echo hocwp_bool_to_int($captcha);
        ?>
"
		      data-register="<?php 
        echo hocwp_bool_to_int($register);
        ?>
">
			<?php 
        echo '<div class="messages"></div>';
        if (!empty($description) && 'before' == $desc_position) {
            echo '<p class="description">' . $description . '</p>';
        }
        foreach ($all_fields as $field_name) {
            $field = hocwp_get_value_by_key($this->args['fields'], $field_name);
            if (hocwp_array_has_value($field)) {
                $label = $this->get_value_field($instance, $field_name, 'label');
                $placeholder = $this->get_value_field($instance, $field_name, 'placeholder');
                $required = $this->get_value_field($instance, $field_name, 'required');
                $class = hocwp_sanitize_html_class($field_name);
                $field_args = array('id' => $this->get_field_id('subscribe_' . $field_name), 'name' => $this->get_field_name('subscribe_' . $field_name), 'value' => '', 'label' => $label, 'placeholder' => $placeholder, 'required' => $required, 'class' => 'form-control input-' . $class, 'before' => '<div class="form-group field-' . $class . '">', 'after' => '</div>');
                hocwp_field_input($field_args);
            }
        }
        if (!empty($description) && 'after' == $desc_position) {
            echo '<p class="description">' . $description . '</p>';
        }
        if ($captcha) {
            $captcha_label = hocwp_get_value_by_key($instance, 'captcha_label', hocwp_get_value_by_key($this->args, 'captcha_label'));
            $captcha_placeholder = hocwp_get_value_by_key($instance, 'captcha_placeholder', hocwp_get_value_by_key($this->args, 'captcha_placeholder'));
            $field_args = array('id' => $this->get_field_id('captcha'), 'name' => $this->get_field_name('captcha'), 'input_width' => '100%', 'class' => 'form-control', 'label' => $captcha_label, 'placeholder' => $captcha_placeholder, 'before' => '<div class="form-group field-captcha">', 'after' => '</div>');
            hocwp_field_captcha($field_args);
        }
        $field_args = array('type' => 'submit', 'name' => 'submit', 'value' => $button_text, 'class' => 'form-control', 'before' => '<div class="form-group field-submit">', 'after' => '</div>');
        hocwp_field_input($field_args);
        hocwp_loading_image(array('name' => 'icon-loading-long.gif'));
        ?>
		</form>
		<?php 
        $widget_html = ob_get_clean();
        $widget_html = apply_filters('hocwp_widget_subscribe_html', $widget_html, $args, $instance, $this);
        echo $widget_html;
        hocwp_widget_after($args, $instance);
    }
示例#2
0
function hocwp_field_media_upload($args = array())
{
    hocwp_field_sanitize_args($args);
    $id = isset($args['id']) ? $args['id'] : '';
    $name = isset($args['name']) ? $args['name'] : '';
    $value = isset($args['value']) ? $args['value'] : '';
    $value = hocwp_sanitize_media_value($value);
    $media_url = $value['url'];
    $container = (bool) hocwp_get_value_by_key($args, 'container');
    hocwp_field_before($args);
    if ($container) {
        echo '<div class="media-container field-group">';
    }
    $media_preview = new HOCWP_HTML('span');
    $media_preview->set_class('media-preview');
    if (!empty($media_url)) {
        $image = new HOCWP_HTML('img');
        $image->set_attribute('src', $media_url);
        if (isset($value['is_image']) && !(bool) $value['is_image']) {
            $type_icon = hocwp_get_value_by_key($value, 'type_icon');
            if (!empty($type_icon)) {
                $image->set_attribute('src', $type_icon);
            }
        }
        $media_preview->set_text($image->build());
    }
    $media_preview->output();
    if (empty($id)) {
        $id = hocwp_sanitize_id($name);
    }
    $url_args = array('id' => $id . '_url', 'name' => $name . '[url]', 'class' => 'media-url', 'type' => 'url', 'value' => $media_url, 'attributes' => array('autocomplete' => 'off'));
    hocwp_field_input($url_args);
    $btn_insert_args = array('data_editor' => $id . '_url');
    if (!empty($media_url)) {
        $btn_insert_args['class'] = 'hidden';
    }
    hocwp_field_insert_media_button($btn_insert_args);
    $btn_remove_args = array();
    if (empty($media_url)) {
        $btn_remove_args['class'] = 'hidden';
    }
    hocwp_field_remove_button($btn_remove_args);
    $id_args = array('id' => $id . '_id', 'name' => $name . '[id]', 'class' => 'media-id', 'value' => $value['id']);
    hocwp_field_input_hidden($id_args);
    if ($container) {
        echo '</div>';
    }
    hocwp_field_after($args);
}