| @@ -1,108 +1,62 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmShowForm extends WP_Widget { |
| 7 | 4 | |
| 8 | - public function __construct() { | |
| 9 | - $widget_ops = array( 'description' => __( 'Display a Formidable Form', 'formidable' ) ); | |
| 10 | - parent::__construct( 'frm_show_form', __( 'Formidable Form', 'formidable' ), $widget_ops ); | |
| 5 | + function __construct() { | |
| 6 | + $widget_ops = array( 'description' => __( "Display a Formidable Form", 'formidable') ); | |
| 7 | + $this->WP_Widget('frm_show_form', __('Formidable Form', 'formidable'), $widget_ops); | |
| 11 | 8 | } |
| 12 | 9 | |
| 13 | - /** | |
| 14 | - * @param array $args | |
| 15 | - * @param array $instance | |
| 16 | - * | |
| 17 | - * @return void | |
| 18 | - */ | |
| 19 | - public function widget( $args, $instance ) { | |
| 20 | - $title = apply_filters( 'widget_title', ! empty( $instance['title'] ) ? $instance['title'] : '', $instance, $this->id_base ); | |
| 21 | - | |
| 22 | - FrmAppHelper::kses_echo( $args['before_widget'], 'all' ); | |
| 23 | - | |
| 24 | - echo '<div class="frm_form_widget">'; | |
| 25 | - | |
| 26 | - if ( $title ) { | |
| 27 | - FrmAppHelper::kses_echo( $args['before_title'] . stripslashes( $title ) . $args['after_title'], 'all' ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - $form_atts = array( | |
| 31 | - 'id' => $instance['form'] ?? 0, | |
| 32 | - 'title' => false, | |
| 33 | - 'description' => $instance['description'] ?? false, | |
| 34 | - ); | |
| 35 | - | |
| 36 | - echo FrmFormsController::get_form_shortcode( $form_atts ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 37 | - | |
| 10 | + function widget( $args, $instance ) { | |
| 11 | + extract($args); | |
| 12 | + | |
| 13 | + $frm_form = new FrmForm(); | |
| 14 | + $form_name = $frm_form->getName( $instance['form'] ); | |
| 15 | + $title = apply_filters('widget_title', empty($instance['title']) ? $form_name : $instance['title']); | |
| 16 | + $instance['description'] = isset($instance['description']) ? $instance['description'] : false; | |
| 17 | + | |
| 18 | + echo $before_widget; | |
| 19 | + $select_class = (isset($instance['select_width']) and $instance['select_width']) ? ' frm_set_select' : ''; | |
| 20 | + echo '<div class="frm_form_widget'.$select_class.'">'; | |
| 21 | + if ( $title ) | |
| 22 | + echo $before_title . stripslashes($title) . $after_title; | |
| 23 | + | |
| 24 | + if(isset($instance['size']) and is_numeric($instance['size'])){ | |
| 25 | + global $frm_vars; | |
| 26 | + $frm_vars['sidebar_width'] = $instance['size']; | |
| 27 | + } | |
| 28 | + | |
| 29 | + echo FrmFormsController::show_form($instance['form'], '', false, $instance['description']); | |
| 30 | + $frm_vars['sidebar_width'] = ''; | |
| 38 | 31 | echo '</div>'; |
| 39 | - FrmAppHelper::kses_echo( $args['after_widget'], 'all' ); | |
| 32 | + echo $after_widget; | |
| 40 | 33 | } |
| 41 | 34 | |
| 42 | - /** | |
| 43 | - * @param array $new_instance New settings for this instance as input by the user via | |
| 44 | - * WP_Widget::form(). | |
| 45 | - * @param array $old_instance Old settings for this instance. | |
| 46 | - * | |
| 47 | - * @return array Settings to save or bool false to cancel saving. | |
| 48 | - */ | |
| 49 | - public function update( $new_instance, $old_instance ) { | |
| 35 | + function update( $new_instance, $old_instance ) { | |
| 50 | 36 | return $new_instance; |
| 51 | 37 | } |
| 52 | 38 | |
| 53 | - /** | |
| 54 | - * Outputs the settings update form. | |
| 55 | - * | |
| 56 | - * @param array $instance Current settings. | |
| 57 | - * | |
| 58 | - * @return string Default return is 'noform'. | |
| 59 | - */ | |
| 60 | - public function form( $instance ) { | |
| 61 | - $defaults = array( | |
| 62 | - 'title' => false, | |
| 63 | - 'form' => false, | |
| 64 | - 'description' => false, | |
| 65 | - ); | |
| 66 | - $instance = wp_parse_args( $instance, $defaults ); | |
| 67 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 68 | - ?> | |
| 69 | - <p> | |
| 70 | - <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"> | |
| 71 | - <?php esc_html_e( 'Title', 'formidable' ); ?>: | |
| 72 | - </label> | |
| 73 | - <br/> | |
| 74 | - <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" | |
| 75 | - name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" | |
| 76 | - value="<?php echo esc_attr( stripslashes( $instance['title'] ) ); ?>"/> | |
| 77 | - </p> | |
| 78 | - | |
| 79 | - <p> | |
| 80 | - <label for="<?php echo esc_attr( $this->get_field_id( 'form' ) ); ?>"> | |
| 81 | - <?php esc_html_e( 'Form', 'formidable' ); ?>: | |
| 82 | - </label><br/> | |
| 83 | - <?php | |
| 84 | - FrmFormsHelper::forms_dropdown( | |
| 85 | - $this->get_field_name( 'form' ), | |
| 86 | - $instance['form'], | |
| 87 | - array( | |
| 88 | - 'blank' => false, | |
| 89 | - 'field_id' => $this->get_field_id( 'form' ), | |
| 90 | - 'class' => 'widefat', | |
| 91 | - ) | |
| 92 | - ); | |
| 93 | - ?> | |
| 94 | - </p> | |
| 95 | - | |
| 96 | - <p> | |
| 97 | - <label for="<?php echo esc_attr( $this->get_field_id( 'description' ) ); ?>"> | |
| 98 | - <input class="checkbox" type="checkbox" <?php checked( $instance['description'], true ); ?> | |
| 99 | - id="<?php echo esc_attr( $this->get_field_id( 'description' ) ); ?>" | |
| 100 | - name="<?php echo esc_attr( $this->get_field_name( 'description' ) ); ?>" value="1" /> | |
| 101 | - <?php esc_html_e( 'Show Description', 'formidable' ); ?> | |
| 102 | - </label> | |
| 103 | - </p> | |
| 104 | - <?php | |
| 105 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 106 | - return ''; | |
| 39 | + function form( $instance ) { | |
| 40 | + //Defaults | |
| 41 | + $instance = wp_parse_args( (array) $instance, array('title' => false, 'form' => false, 'description' => false, 'size' => 20, 'select_width' => false) ); | |
| 42 | +?> | |
| 43 | + <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'formidable') ?>:</label> | |
| 44 | + <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( stripslashes($instance['title']) ); ?>" /></p> | |
| 45 | + | |
| 46 | + <p><label for="<?php echo $this->get_field_id('form'); ?>"><?php _e('Form', 'formidable') ?>:</label> | |
| 47 | + <?php FrmFormsHelper::forms_dropdown( $this->get_field_name('form'), $instance['form'], false, $this->get_field_id('form') )?> | |
| 48 | + </p> | |
| 49 | + | |
| 50 | + <p><label for="<?php echo $this->get_field_id('description'); ?>"><input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" value="1" /> | |
| 51 | + <?php _e('Show Description', 'formidable') ?></label></p> | |
| 52 | + | |
| 53 | + <p><label for="<?php echo $this->get_field_id('select_width'); ?>"><input class="checkbox" type="checkbox" <?php checked($instance['select_width'], true) ?> id="<?php echo $this->get_field_id('select_width'); ?>" name="<?php echo $this->get_field_name('select_width'); ?>" value="1" /> | |
| 54 | + <?php _e('Fit Select Boxes into SideBar', 'formidable') ?></label></p> | |
| 55 | + | |
| 56 | + <p><label class="checkbox" for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Field Size', 'formidable') ?>:</label> | |
| 57 | + | |
| 58 | + <input type="text" size="3" id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>" value="<?php echo esc_attr( $instance['size'] ); ?>" /> <span class="howto" style="display:inline;"><?php _e('characters wide', 'formidable') ?></span></p> | |
| 59 | + <p class="description"><?php _e('If your text fields are too big for your sidebar insert a size here.', 'formidable') ?></p> | |
| 60 | +<?php | |
| 107 | 61 | } |
| 108 | 62 | } |