/**
  * Display the widget.
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     $instance = $this->modify_instance($instance);
     $this->current_instance = $instance;
     $args = wp_parse_args($args, array('before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''));
     $style = $this->get_style_name($instance);
     // Add any missing default values to the instance
     $instance = $this->add_defaults($this->form_options, $instance);
     $upload_dir = wp_upload_dir();
     $this->clear_file_cache();
     if ($style !== false) {
         $hash = $this->get_style_hash($instance);
         $css_name = $this->id_base . '-' . $style . '-' . $hash;
         if (isset($instance['is_preview']) && $instance['is_preview'] || is_preview()) {
             siteorigin_widget_add_inline_css($this->get_instance_css($instance));
         } else {
             if (!file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css') || defined('SITEORIGIN_WIDGETS_DEBUG') && SITEORIGIN_WIDGETS_DEBUG) {
                 // Attempt to recreate the CSS
                 $this->save_css($instance);
             }
             if (file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css')) {
                 wp_enqueue_style($css_name, $upload_dir['baseurl'] . '/siteorigin-widgets/' . $css_name . '.css');
             } else {
                 // Fall back to using inline CSS if we can't find the cached CSS file.
                 siteorigin_widget_add_inline_css($this->get_instance_css($instance));
             }
         }
     } else {
         $css_name = $this->id_base . '-base';
     }
     $this->enqueue_frontend_scripts();
     extract($this->get_template_variables($instance, $args));
     // Storage hash allows
     $storage_hash = '';
     if (!empty($this->widget_options['instance_storage'])) {
         $stored_instance = $this->filter_stored_instance($instance);
         $storage_hash = substr(md5(serialize($stored_instance)), 0, 8);
         if (!empty($stored_instance) && empty($instance['is_preview'])) {
             // Store this if we have a non empty instance and are not previewing
             set_transient('sow_inst[' . $this->id_base . '][' . $storage_hash . ']', $stored_instance, 7 * 86400);
         }
     }
     echo $args['before_widget'];
     echo '<div class="so-widget-' . $this->id_base . ' so-widget-' . $css_name . '">';
     ob_start();
     @(include siteorigin_widget_get_plugin_dir_path($this->id_base) . '/' . $this->get_template_dir($instance) . '/' . $this->get_template_name($instance) . '.php');
     echo apply_filters('siteorigin_widget_template', ob_get_clean(), get_class($this), $instance, $this);
     echo '</div>';
     echo $args['after_widget'];
     $this->current_instance = false;
 }
 /**
  * Display the widget.
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     $instance = $this->modify_instance($instance);
     $args = wp_parse_args($args, array('before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''));
     $style = $this->get_style_name($instance);
     // Add any missing default values to the instance
     $instance = $this->add_defaults($this->form_options, $instance);
     $upload_dir = wp_upload_dir();
     $this->clear_file_cache();
     if ($style !== false) {
         $hash = $this->get_style_hash($instance);
         $css_name = $this->id_base . '-' . $style . '-' . $hash;
         if (isset($instance['is_preview']) && $instance['is_preview']) {
             siteorigin_widget_add_inline_css($this->get_instance_css($instance));
         } else {
             if (!file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css') || defined('SITEORIGIN_WIDGETS_DEBUG') && SITEORIGIN_WIDGETS_DEBUG) {
                 // Attempt to recreate the CSS
                 $this->save_css($instance);
             }
             if (file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css')) {
                 wp_enqueue_style($css_name, $upload_dir['baseurl'] . '/siteorigin-widgets/' . $css_name . '.css');
             } else {
                 // Fall back to using inline CSS if we can't find the cached CSS file.
                 siteorigin_widget_add_inline_css($this->get_instance_css($instance));
             }
         }
     } else {
         $css_name = $this->id_base . '-base';
     }
     $this->enqueue_frontend_scripts();
     echo $args['before_widget'];
     echo '<div class="so-widget-' . $this->id_base . ' so-widget-' . $css_name . '">';
     @(include siteorigin_widget_get_plugin_dir_path($this->id_base) . '/tpl/' . $this->get_template_name($instance) . '.php');
     echo '</div>';
     echo $args['after_widget'];
 }
 /**
  * Generate the CSS for this widget and display it in the appropriate way
  *
  * @param $instance The instance array
  *
  * @return string The CSS name
  */
 function generate_and_enqueue_instance_styles($instance)
 {
     $this->current_instance = $instance;
     $style = $this->get_style_name($instance);
     $upload_dir = wp_upload_dir();
     $this->clear_file_cache();
     if ($style !== false) {
         $hash = $this->get_style_hash($instance);
         $css_name = $this->id_base . '-' . $style . '-' . $hash;
         //Ensure styles aren't generated and enqueued more than once.
         $in_preview = is_preview() || $this->is_customize_preview();
         if (!in_array($css_name, $this->generated_css) || $in_preview) {
             if (isset($instance['is_preview']) && $instance['is_preview'] || $in_preview) {
                 siteorigin_widget_add_inline_css($this->get_instance_css($instance));
             } else {
                 if (!file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css') || defined('SITEORIGIN_WIDGETS_DEBUG') && SITEORIGIN_WIDGETS_DEBUG) {
                     // Attempt to recreate the CSS
                     $this->save_css($instance);
                 }
                 if (file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css')) {
                     if (!wp_style_is($css_name)) {
                         wp_enqueue_style($css_name, $upload_dir['baseurl'] . '/siteorigin-widgets/' . $css_name . '.css');
                     }
                 } else {
                     // Fall back to using inline CSS if we can't find the cached CSS file.
                     siteorigin_widget_add_inline_css($this->get_instance_css($instance));
                 }
             }
             $this->generated_css[] = $css_name;
         }
     } else {
         $css_name = $this->id_base . '-base';
     }
     $this->current_instance = false;
     return $css_name;
 }
 /**
  * Generate the CSS for this widget and display it in the appropriate way
  *
  * @param $instance The instance array
  *
  * @return string The CSS name
  */
 function generate_and_enqueue_instance_styles($instance)
 {
     if (empty($this->form_options)) {
         $this->form_options = $this->initialize_form();
     }
     // We'll assume empty instances don't have styles
     if (empty($instance)) {
         return;
     }
     // Make sure all the default values are in place
     $instance = $this->add_defaults($this->form_options, $instance);
     $this->current_instance = $instance;
     $style = $this->get_style_name($instance);
     $upload_dir = wp_upload_dir();
     $this->clear_file_cache();
     if (!empty($style)) {
         $hash = $this->get_style_hash($instance);
         $css_name = $this->id_base . '-' . $style . '-' . $hash;
         //Ensure styles aren't generated and enqueued more than once.
         $in_preview = $this->is_preview($instance);
         if (!in_array($css_name, $this->generated_css) || $in_preview) {
             if ($in_preview) {
                 siteorigin_widget_add_inline_css($this->get_instance_css($instance));
             } else {
                 if (!file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css') || defined('SITEORIGIN_WIDGETS_DEBUG') && SITEORIGIN_WIDGETS_DEBUG) {
                     // Attempt to recreate the CSS
                     $this->save_css($instance);
                 }
                 if (file_exists($upload_dir['basedir'] . '/siteorigin-widgets/' . $css_name . '.css')) {
                     if (!wp_style_is($css_name)) {
                         wp_enqueue_style($css_name, set_url_scheme($upload_dir['baseurl'] . '/siteorigin-widgets/' . $css_name . '.css'));
                     }
                 } else {
                     // Fall back to using inline CSS if we can't find the cached CSS file.
                     // Try get the cached value.
                     $css = wp_cache_get($css_name, 'siteorigin_widgets');
                     if (empty($css)) {
                         $css = $this->get_instance_css($instance);
                     }
                     siteorigin_widget_add_inline_css($css);
                 }
             }
             $this->generated_css[] = $css_name;
         }
     } else {
         $css_name = $this->id_base . '-base';
     }
     $this->current_instance = false;
     return $css_name;
 }