コード例 #1
0
 public function register_assets()
 {
     global $post, $essb_options;
     if ($this->general_options['reset_postdata']) {
         wp_reset_postdata();
     }
     if ($this->is_plugin_deactivated_on() || ESSBCoreHelper::is_module_deactivate_on('share')) {
         $this->deactivate_stored_filter_and_actions();
         return;
     }
     $this->register_locations();
     $essb_post_template = "";
     $essb_post_animations = "";
     $essb_post_content_position = "";
     $essb_post_button_position = array();
     $essb_post_native = "";
     $essb_post_native_skin = "";
     // @since 3.3 - this check will be done only if the option is not turned off
     if (isset($post) && !$this->advanced_visual_on_post_off) {
         // @since version 3.4 - code is moved to extender to allow running in light mode
         if (class_exists('ESSBCoreExtenderPostVisualOptions')) {
             $post_visual_options = ESSBCoreExtenderPostVisualOptions::get($post, $this->general_options['button_position']);
             foreach ($post_visual_options as $single_callback_option) {
                 $param_name = $single_callback_option['param'];
                 if ($single_callback_option['type'] == 'general_options') {
                     $this->general_options[$param_name] = $single_callback_option['value'];
                 } else {
                     if ($single_callback_option['type'] == 'design_options') {
                         $this->design_options[$param_name] = $single_callback_option['value'];
                     } else {
                         if ($single_callback_option['type'] == 'button_style') {
                             $this->button_style[$param_name] = $single_callback_option['value'];
                         } else {
                             if ($param_name == 'modified_locations') {
                                 if ($single_callback_option['value']) {
                                     $this->deactivate_stored_filters_and_actions_by_group('button_position');
                                     $this->reactivate_button_position_filters();
                                 }
                             } else {
                                 if ($param_name == 'post_template') {
                                     $essb_post_template = $single_callback_option['value'];
                                 } else {
                                     if ($param_name == 'post_animations') {
                                         $essb_post_animations = $single_callback_option['value'];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // end of on post visual options
     }
     // non cachable - required for generation of proper ajax requests
     essb_resource_builder()->add_js(ESSBResourceBuilderSnippets::js_build_admin_ajax_access_code(), false, 'essb-head-ajax', 'head');
     essb_resource_builder()->add_js(ESSBResourceBuilderSnippets::js_build_window_open_code(), true, 'essb-window-code');
     if (ESSBOptionValuesHelper::options_bool_value($this->options, 'activate_ga_tracking')) {
         essb_resource_builder()->add_js(ESSBResourceBuilderSnippets::js_build_ga_tracking_code(), true, 'essb-ga-tracking-code');
     }
     if (in_array('print', $this->network_options['networks']) && !ESSBOptionValuesHelper::options_bool_value($this->options, 'print_use_printfriendly')) {
         essb_resource_builder()->add_js(ESSBResourceBuilderSnippets::js_build_window_print_code(), true, 'essb-printing-code');
         $this->activated_resources['print'] = 'true';
     }
     // loading aminations
     $css_animations = ESSBOptionValuesHelper::options_value($this->options, 'css_animations');
     if (!empty($essb_post_animations)) {
         $css_animations = $essb_post_animations;
     }
     if ($css_animations != '' && $css_animations != "no") {
         //@since 3.5 - animations come from external css
         $animate_url = ESSB3_PLUGIN_URL . '/assets/css/essb-animations.min.css';
         essb_resource_builder()->add_static_resource($animate_url, 'easy-social-share-buttons-animations', 'css');
         $this->activated_resources['animations'] = 'true';
         //essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_animation_code($css_animations), 'essb-css-animations');
     }
     essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_counter_style(), 'essb-counter-style');
     essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_generate_column_width(), 'essb-column-width-style');
     essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_sidebar_options(), 'essb-sidebar-style');
     essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_compile_display_locations_code(), 'essb-locations-css');
     // activate the fixer for mobiles
     $mobile_sharebuttonsbar_fix = ESSBOptionValuesHelper::options_bool_value($this->options, 'mobile_sharebuttonsbar_fix');
     if ($mobile_sharebuttonsbar_fix) {
         essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_mobilesharebar_fix_code(), 'essb-mobilesharebar-fix-css');
     }
     $use_minifed_css = $this->general_options['use_minified_css'] ? ".min" : "";
     $use_minifed_js = $this->general_options['use_minified_js'] ? ".min" : "";
     $this->use_minified_css = $use_minifed_css;
     $this->use_minified_js = $use_minifed_js;
     // main theme CSS
     $template_id = $this->design_options['template'];
     $template_slug = ESSBCoreHelper::template_folder($template_id);
     if (!empty($essb_post_template)) {
         $template_slug = $essb_post_template;
         $this->design_options['template'] = $template_slug;
     }
     $this->design_options['template_slug'] = $template_slug;
     $template_url = ESSB3_PLUGIN_URL . '/assets/css/' . $template_slug . '/easy-social-share-buttons' . $use_minifed_css . '.css';
     essb_resource_builder()->add_static_resource($template_url, 'easy-social-share-buttons', 'css');
     // counter script
     if ($this->button_style['show_counter']) {
         if (!defined('ESSB3_COUNTER_LOADED') && !defined('ESSB3_CACHED_COUNTERS')) {
             $script_url = ESSB3_PLUGIN_URL . '/assets/js/easy-social-share-buttons' . $use_minifed_js . '.js';
             essb_resource_builder()->add_static_resource($script_url, 'easy-social-share-buttons', 'js');
             $this->activated_resources['counters'] = 'true';
             define('ESSB3_COUNTER_LOADED', true);
         }
     }
     $display_locations_script = false;
     // float from content top
     $content_postion = $this->general_options['content_position'];
     if (!empty($essb_post_content_position)) {
         $content_postion = $essb_post_content_position;
         $this->general_options['content_position'] = $content_postion;
     }
     if ($content_postion == "content_float" || $content_postion == "content_floatboth") {
         //$script_url = ESSB3_PLUGIN_URL .'/assets/js/essb-float'.$use_minifed_js.'.js';
         //essb_resource_builder()->add_static_resource($script_url, 'essb-float', 'js');
         $this->activated_resources['float'] = 'true';
         $display_locations_script = true;
     }
     // mobile CSS load
     if ($this->is_mobile_safecss() && (in_array('sharebar', $this->general_options['button_position']) || in_array('sharepoint', $this->general_options['button_position']) || in_array('sharebottom', $this->general_options['button_position']))) {
         $style_url = ESSB3_PLUGIN_URL . '/assets/css/essb-mobile' . $use_minifed_css . '.css';
         essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-mobile', 'css');
         $script_url = ESSB3_PLUGIN_URL . '/assets/js/essb-mobile' . $use_minifed_js . '.js';
         essb_resource_builder()->add_static_resource($script_url, 'essb-mobile', 'js');
         $this->activated_resources['mobile'] = 'true';
     }
     // post vertical float or sidebar
     // @since 3.5 - load styles from single file
     $display_locations_style = false;
     if (in_array('sidebar', $this->general_options['button_position']) || in_array('postfloat', $this->general_options['button_position'])) {
         //$style_url = ESSB3_PLUGIN_URL .'/assets/css/essb-sidebar'.$use_minifed_css.'.css';
         //essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-sidebar', 'css');
         $display_locations_style = true;
         $this->activated_resources['sidebar'] = 'true';
         if (in_array('postfloat', $this->general_options['button_position'])) {
             //$script_url = ESSB3_PLUGIN_URL .'/assets/js/essb-postfloat'.$use_minifed_js.'.js';
             //essb_resource_builder()->add_static_resource($script_url, 'essb-postfloat', 'js');
             $this->activated_resources['postfloat'] = 'true';
             $display_locations_script = true;
         }
     }
     if (in_array('topbar', $this->general_options['button_position']) || in_array('bottombar', $this->general_options['button_position'])) {
         //$style_url = ESSB3_PLUGIN_URL .'/assets/css/essb-topbottom-bar'.$use_minifed_css.'.css';
         //essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-topbottom-bar', 'css');
         $this->activated_resources['topbottombar'] = 'true';
         $display_locations_style = true;
     }
     if (in_array('popup', $this->general_options['button_position'])) {
         //$style_url = ESSB3_PLUGIN_URL .'/assets/css/essb-popup'.$use_minifed_css.'.css';
         //essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-popup', 'css');
         $script_url = ESSB3_PLUGIN_URL . '/assets/js/essb-popup' . $use_minifed_js . '.js';
         essb_resource_builder()->add_static_resource($script_url, 'essb-popup', 'js', true);
         $this->activated_resources['popup'] = 'true';
         $display_locations_style = true;
     }
     if (in_array('heroshare', $this->general_options['button_position'])) {
         //$style_url = ESSB3_PLUGIN_URL .'/assets/css/essb-heroshare'.$use_minifed_css.'.css';
         //essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-heroshare', 'css');
         $script_url = ESSB3_PLUGIN_URL . '/assets/js/essb-heroshare' . $use_minifed_js . '.js';
         essb_resource_builder()->add_static_resource($script_url, 'essb-heroshare', 'js', true);
         $this->activated_resources['heroshare'] = 'true';
         $display_locations_style = true;
     }
     // @since 3.5
     if (in_array('postbar', $this->general_options['button_position'])) {
         //$style_url = ESSB3_PLUGIN_URL .'/assets/css/essb-postbar'.$use_minifed_css.'.css';
         //essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-postbar', 'css');
         //$script_url = ESSB3_PLUGIN_URL .'/assets/js/essb-postbar'.$use_minifed_js.'.js';
         //essb_resource_builder()->add_static_resource($script_url, 'essb-postbar', 'js', true);
         if (!isset($this->activated_resources['postbar'])) {
             essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_postbar_customizations(), 'essb-postbar-custom-style');
         }
         $display_locations_style = true;
         $this->activated_resources['postbar'] = 'true';
         $display_locations_script = true;
     }
     if (in_array('flyin', $this->general_options['button_position'])) {
         //$style_url = ESSB3_PLUGIN_URL .'/assets/css/essb-flyin'.$use_minifed_css.'.css';
         //essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-flyin', 'css');
         $display_locations_style = true;
         $script_url = ESSB3_PLUGIN_URL . '/assets/js/essb-flyin' . $use_minifed_js . '.js';
         essb_resource_builder()->add_static_resource($script_url, 'essb-flyin', 'js');
         $this->activated_resources['flyin'] = 'true';
     }
     // @since 3.5
     // loading of display settings style
     if ($display_locations_style) {
         $style_url = ESSB3_PLUGIN_URL . '/assets/css/essb-display-methods' . $use_minifed_css . '.css';
         essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-display-methods', 'css');
         $this->activated_resources['display_positions_style'] = 'true';
     }
     if ($display_locations_script) {
         $script_url = ESSB3_PLUGIN_URL . '/assets/js/essb-display-methods' . $use_minifed_js . '.js';
         essb_resource_builder()->add_static_resource($script_url, 'essb-display-methods', 'js');
         $this->activated_resources['display_positions_script'] = 'true';
     }
     $this->general_options['included_mail'] = false;
     if (in_array('mail', $this->network_options['networks'])) {
         if ($this->network_options['mail_function'] == "form") {
             $this->general_options['included_mail'] = true;
             $style_url = ESSB3_PLUGIN_URL . '/assets/css/essb-mailform' . $use_minifed_css . '.css';
             essb_resource_builder()->add_static_resource($style_url, 'easy-social-share-buttons-mailform', 'css');
             $script_url = ESSB3_PLUGIN_URL . '/assets/js/essb-mailform.js';
             essb_resource_builder()->add_static_resource($script_url, 'essb-mailform', 'js', true);
             $this->activated_resources['mail'] = 'true';
         }
     }
 }