コード例 #1
0
 /**
  * Appends AddThis button to post content.
  */
 function addthis_social_widget($content, $onSidebar = false, $url = null, $title = null)
 {
     addthis_set_addthis_settings();
     global $addthis_settings;
     global $addThisConfigs;
     global $cmsConnector;
     // add nothing to RSS feed or search results; control adding to static/archive/category pages
     if (!$onSidebar) {
         if ($addthis_settings['sidebar_only'] || is_feed() || is_search() || is_home() || is_page() || is_archive() || is_category()) {
             return $content;
         }
     }
     $pub = urlencode($addThisConfigs->getUsableProfileId());
     $link = !is_null($url) ? $url : ($onSidebar ? get_bloginfo('url') : get_permalink());
     $title = !is_null($title) ? $title : ($onSidebar ? get_bloginfo('title') : the_title('', '', false));
     $content .= '
         <!-- AddThis Button BEGIN -->
         <script data-cfasync="false" type="text/javascript">' . "\n//<!--\n" . "var addthis_product = '" . $cmsConnector->getProductVersion() . "';\n";
     if (strlen($addthis_settings['customization'])) {
         $content .= $addthis_settings['customization'] . "\n";
     }
     if ($addthis_settings['menu_type'] === 'dropdown') {
         $content .= '
             </script>
                 <div class="addthis_container">
                     <a
                         href="//www.addthis.com/bookmark.php?v=' . $atversion . '&amp;username='******'"
                         class="addthis_button"
                         ' . addthis_get_identifier($link, $title) . '
                     >
             ';
         $content .= ($addthis_settings['language'] == '' ? '' : addthis_get_button_img()) . '</a><script data-cfasync="false" type="text/javascript" src="//s7.addthis.com/js/' . $atversion . '/addthis_widget.js#username='******'"></script></div>';
     } else {
         if ($addthis_settings['menu_type'] === 'toolbox') {
             $content .= "\n//-->\n</script>\n";
             $content .= '
             <div
                 class="addthis_container addthis_toolbox addthis_default_style"
                 ' . addthis_get_identifier($link, $title) . '
             >
                 <a
                     href="//www.addthis.com/bookmark.php?v=' . $atversion . '&amp;username=$pub"
                     class="addthis_button_compact">
                     Share
                 </a>
                 <span class="addthis_separator">|</span>
                 <script data-cfasync="false" type="text/javascript" src="//s7.addthis.com/js/' . $atversion . '/addthis_widget.js#username='******'">
                 </script>
             </div>';
         } else {
             $link = urlencode($link);
             $title = urlencode($title);
             $content .= '//-->
             </script>
             <div class="addthis_container">
             <a
                 href="//www.addthis.com/bookmark.php?v=' . $atversion . '&amp;username=$pub"
                 onclick="window.open(\'//www.addthis.com/bookmark.php?v=' . $atversion . '&amp;username='******'&amp;url=' . $link . '&amp;title=' . $title . '\', \'ext_addthis\', \'scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no\'); return false;"
                 title="Bookmark using any bookmark manager!"
                 target="_blank"
             >
         ';
             $content .= addthis_get_button_img() . '</a></div>';
         }
     }
     $content .= "\n<!-- AddThis Button END -->";
     return $content;
 }
コード例 #2
0
/**
* Appends AddThis button to post content.
*/
function addthis_social_widget($content, $onSidebar = false, $url = null, $title = null)
{
    addthis_set_addthis_settings();
    global $addthis_settings;
    // add nothing to RSS feed or search results; control adding to static/archive/category pages
    if (!$onSidebar) {
        if ($addthis_settings['sidebar_only'] == 'true') {
            return $content;
        } else {
            if (is_feed()) {
                return $content;
            } else {
                if (is_search()) {
                    return $content;
                } else {
                    if (is_home() && !$addthis_settings['showonhome']) {
                        return $content;
                    } else {
                        if (is_page() && !$addthis_settings['showonpages']) {
                            return $content;
                        } else {
                            if (is_archive() && !$addthis_settings['showonarchives']) {
                                return $content;
                            } else {
                                if (is_category() && !$addthis_settings['showoncats']) {
                                    return $content;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $pub = $addthis_settings['username'];
    if (!$pub) {
        $pub = 'wp-' . cuid();
    }
    $pub = urlencode($pub);
    $link = !is_null($url) ? $url : ($onSidebar ? get_bloginfo('url') : get_permalink());
    $title = !is_null($title) ? $title : ($onSidebar ? get_bloginfo('title') : the_title('', '', false));
    $addthis_options = $addthis_settings['options'];
    $content .= "\n<!-- AddThis Button BEGIN -->\n" . '<script type="text/javascript">' . "\n//<!--\n" . "var addthis_product = '" . ADDTHIS_PRODUCT_VERSION . "';\n";
    if (strlen($addthis_settings['customization'])) {
        $content .= $addthis_settings['customization'] . "\n";
    }
    if ($addthis_settings['menu_type'] === 'dropdown') {
        if (strlen($addthis_options)) {
            $content .= "var addthis_options = '{$addthis_options}';\n";
        }
        $content .= <<<EOF
//-->
</script>
<div class="addthis_container"><a href="//www.addthis.com/bookmark.php?v='.{$atversion}.'&amp;username={$pub}" class="addthis_button" addthis:url="{$link}" addthis:title="{$title}">
EOF;
        $content .= ($addthis_settings['language'] == '' ? '' : addthis_get_button_img()) . '</a><script type="text/javascript" src="//s7.addthis.com/js/' . $atversion . '/addthis_widget.js#username='******'"></script></div>';
    } else {
        if ($addthis_settings['menu_type'] === 'toolbox') {
            $content .= "\n//-->\n</script>\n";
            $content .= <<<EOF
<div class="addthis_container addthis_toolbox addthis_default_style" addthis:url="{$link}" addthis:title="{$title}"><a href="//www.addthis.com/bookmark.php?v='.{$atversion}.'&amp;username={$pub}" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span>
EOF;
            if (!strlen($addthis_options)) {
                $addthis_options = 'email,favorites,print,facebook,twitter';
            }
            $addthis_options = split(',', $addthis_options);
            foreach ($addthis_options as $option) {
                $option = trim($option);
                if ($option != 'more') {
                    $content .= '<a class="addthis_button_' . $option . '"></a>';
                }
            }
            $content .= '<script type="text/javascript" src="//s7.addthis.com/js/' . $atversion . '/addthis_widget.js#username='******'"></script></div>';
        } else {
            $link = urlencode($link);
            $title = urlencode($title);
            $content .= <<<EOF
//-->
</script>
<div class="addthis_container"><a href="//www.addthis.com/bookmark.php?v='.{$atversion}.'&amp;username={$pub}" onclick="window.open('//www.addthis.com/bookmark.php?v='.{$atversion}.'&amp;username={$pub}&amp;url={$link}&amp;title={$title}', 'ext_addthis', 'scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no'); return false;" title="Bookmark using any bookmark manager!" target="_blank">
EOF;
            $content .= addthis_get_button_img() . '</a></div>';
        }
    }
    $content .= "\n<!-- AddThis Button END -->";
    return $content;
}