コード例 #1
0
 public function getAddThisPluginInfoJson()
 {
     if (!is_array($this->configs)) {
         $this->getConfigs();
     }
     $pluginInfo = array();
     $pluginInfo['info_status'] = 'enabled';
     $pluginInfo['cms_name'] = $this->cmsInterface->getCmsName();
     $pluginInfo['cms_version'] = $this->cmsInterface->getCmsVersion();
     $pluginInfo['plugin_name'] = $this->cmsInterface->plugin->getName();
     $pluginInfo['plugin_version'] = $this->cmsInterface->getPluginVersion();
     $pluginInfo['anonymous_profile_id'] = $this->getAnonymousProfileId();
     if (current_user_can('install_plugins')) {
         $pluginInfo['php_version'] = phpversion();
     }
     // including select configs
     if (isset($this->configs['addthis_plugin_controls'])) {
         $pluginInfo['plugin_mode'] = $this->configs['addthis_plugin_controls'];
     }
     if (isset($this->configs['addthis_per_post_enabled'])) {
         $pluginInfo['select_prefs']['addthis_per_post_enabled'] = $this->configs['addthis_per_post_enabled'];
     }
     if (isset($this->configs['addthis_above_enabled'])) {
         $pluginInfo['select_prefs']['addthis_above_enabled'] = $this->configs['addthis_above_enabled'];
     }
     if (isset($this->configs['addthis_below_enabled'])) {
         $pluginInfo['select_prefs']['addthis_below_enabled'] = $this->configs['addthis_below_enabled'];
     }
     if (isset($this->configs['addthis_sidebar_enabled'])) {
         $pluginInfo['select_prefs']['addthis_sidebar_enabled'] = $this->configs['addthis_sidebar_enabled'];
     }
     if (is_array($this->configs)) {
         foreach ($this->configs as $field => $value) {
             if (strpos($field, '_showon_') !== false) {
                 $pluginInfo['select_prefs'][$field] = $value;
             }
         }
     }
     // post specific stuff that requreis wp_query
     global $wp_query;
     if (isset($wp_query)) {
         $pluginInfo['page_info']['template'] = _addthis_determine_template_type();
         if (isset($wp_query->query_vars['post_type'])) {
             $pluginInfo['page_info']['post_type'] = $wp_query->query_vars['post_type'];
         }
     }
     // post specific meta box selection
     global $post;
     if (isset($post)) {
         $at_flag = get_post_meta($post->ID, '_at_widget', TRUE);
         if ($at_flag === '0') {
             $pluginInfo['select_prefs']['sharing_enabled_on_post_via_metabox'] = false;
         } else {
             $pluginInfo['select_prefs']['sharing_enabled_on_post_via_metabox'] = true;
         }
     }
     $json = json_encode($pluginInfo);
     return $json;
 }
コード例 #2
0
 function addthis_display_social_widget($content, $filtered = true, $excerpt = false)
 {
     global $addthis_styles, $addthis_new_styles, $post;
     global $addThisConfigs;
     $styles = array_merge($addthis_styles, $addthis_new_styles);
     $options = $addThisConfigs->getConfigs();
     $templateType = _addthis_determine_template_type();
     // get configs for this template type
     if (is_string($templateType)) {
         $fieldList = $addThisConfigs->getFieldsForContentTypeSharingLocations($templateType);
         foreach ($fieldList as $key => $field) {
             $fieldList[$field['location']] = $field;
             unset($fieldList[$key]);
         }
         $aboveFieldName = $fieldList['above']['fieldName'];
         $belowFieldName = $fieldList['below']['fieldName'];
         $displayAbove = !empty($options[$aboveFieldName]);
         $displayBelow = !empty($options[$belowFieldName]);
     } else {
         $displayAbove = false;
         $displayBelow = false;
     }
     if ($templateType === 'home') {
         $templateIsAnExcerpt = (bool) (strpos($post->post_content, '<!--more-->') != false);
         if ($templateIsAnExcerpt) {
             if ($displayAbove && !_addthis_excerpt_buttons_enabled_above()) {
                 $displayAbove = false;
             }
             if ($displayBelow && !_addthis_excerpt_buttons_enabled_below()) {
                 $displayBelow = false;
             }
         }
     }
     $custom_fields = get_post_custom($post->ID);
     if (isset($custom_fields['addthis_exclude']) && $custom_fields['addthis_exclude'][0] == 'true') {
         $displayAbove = false;
         $displayBelow = false;
     }
     $displayAbove = apply_filters('addthis_post_exclude', $displayAbove);
     $displayBelow = apply_filters('addthis_post_exclude', $displayBelow);
     $htmlComments = array();
     $htmlCommentLocations = array('above', 'below');
     foreach ($htmlCommentLocations as $location) {
         $htmlComments[$location] = array();
         $search = 'AddThis Sharing Buttons ' . $location;
         $comment = '<!-- ' . $search . ' -->';
         $htmlComments[$location]['search'] = $search;
         $htmlComments[$location]['comment'] = $comment;
     }
     remove_filter('wp_trim_excerpt', 'addthis_remove_tag', 9, 1);
     remove_filter('get_the_excerpt', 'addthis_late_widget');
     $identifier = addthis_get_identifier();
     // Still here?  Well let's add some social goodness
     if (isset($options['above']) && $options['above'] != 'none' && $options['above'] != 'disable' && $displayAbove && (!$excerpt || _addthis_excerpt_buttons_enabled_above()) && strpos($content, $htmlComments['above']['search']) === false) {
         $above = $htmlComments['above']['comment'];
         $above .= addthis_display_widget_above($styles, $options);
     } elseif ($displayAbove) {
         $above = '';
     } else {
         $above = '';
     }
     if (isset($options['below']) && $options['below'] != 'none' && $options['below'] != 'disable' && $displayBelow && (!$excerpt || _addthis_excerpt_buttons_enabled_below()) && strpos($content, $htmlComments['below']['search']) === false) {
         $below = $htmlComments['below']['comment'];
         $below .= addthis_display_widget_below($styles, $options);
     } elseif ($excerpt && $displayBelow && $options['below'] != 'none') {
         $below = '';
         if (_addthis_excerpt_buttons_enabled()) {
             add_filter('get_the_excerpt', 'addthis_late_widget', 14);
         }
     } else {
         $below = '';
     }
     $metaBoxFlag = get_post_meta($post->ID, '_at_widget', TRUE);
     if (!$options['addthis_per_post_enabled'] || $metaBoxFlag == '' || $metaBoxFlag == '1') {
         $metaBoxFlag = true;
     } else {
         $metaBoxFlag = false;
     }
     if ($metaBoxFlag) {
         if ($displayAbove && isset($above)) {
             $content = sprintf($above, $identifier) . $content;
         }
         if ($displayBelow && isset($below)) {
             $content = $content . sprintf($below, $identifier);
         }
     }
     if (($displayAbove || $displayBelow) && $filtered) {
         add_filter('wp_trim_excerpt', 'addthis_remove_tag', 11, 1);
     }
     return $content;
 }
コード例 #3
0
 function addthis_sidebar_script()
 {
     global $addThisConfigs;
     $options = $addThisConfigs->getConfigs();
     $return = '';
     if ($options['addthis_sidebar_enabled'] != true) {
         return $return;
     }
     $templateType = _addthis_determine_template_type();
     if (is_string($templateType)) {
         $fieldList = $addThisConfigs->getFieldsForContentTypeSharingLocations($templateType, 'sidebar');
         $fieldName = $fieldList[0]['fieldName'];
         $display = isset($options[$fieldName]) && $options[$fieldName] ? true : false;
     } else {
         $display = false;
     }
     if (!$display) {
         return $return;
     }
     $return .= "\n            (function() {\n                var at_interval = setInterval(function () {\n                    if(window.addthis) {\n                        clearInterval(at_interval);\n                        addthis.layers(\n                        {\n                            'theme' : '" . strtolower($options['addthis_sidebar_theme']) . "',\n                            'share' : {\n                                'position' : '" . $options['addthis_sidebar_position'] . "',\n                                'numPreferredServices' : " . $options['addthis_sidebar_count'] . "\n                            }\n                        }\n                        );\n                    }\n                },1000)\n            }());";
     return $return;
 }