コード例 #1
0
function arrNetworks($name)
{
    global $mashsb_options, $post, $mashsb_custom_url, $mashsb_custom_text;
    $singular = isset($mashsb_options['singular']) ? $singular = true : ($singular = false);
    $url = $mashsb_custom_url ? $mashsb_custom_url : mashsb_get_url();
    $twitter_url = $mashsb_custom_url ? $mashsb_custom_url : mashsb_get_twitter_url();
    $title = $mashsb_custom_text ? $mashsb_custom_text : mashsb_get_title();
    $twitter_title = $mashsb_custom_text ? $mashsb_custom_text : mashsb_get_twitter_title();
    !empty($mashsb_options['mashsharer_hashtag']) ? $via = '&via=' . $mashsb_options['mashsharer_hashtag'] : ($via = '');
    $networks = apply_filters('mashsb_array_networks', array('facebook' => 'http://www.facebook.com/sharer.php?u=' . $url, 'twitter' => 'https://twitter.com/intent/tweet?text=' . $twitter_title . $via . '&url=' . $twitter_url, 'subscribe' => '#', 'url' => $url, 'title' => mashsb_get_title()));
    return isset($networks[$name]) ? $networks[$name] : '';
}
コード例 #2
0
function mashsb_getNetworks($is_shortcode = false, $services = 0)
{
    global $mashsb_options, $mashsb_custom_url, $enablednetworks, $mashsb_twitter_url;
    // define globals
    if ($is_shortcode) {
        $mashsb_twitter_url = !empty($mashsb_custom_url) ? mashsb_get_shorturl($mashsb_custom_url) : mashsb_get_twitter_url();
    } else {
        $mashsb_twitter_url = mashsb_get_twitter_url();
    }
    // Get class names for buttons size
    $class_size = isset($mashsb_options['buttons_size']) ? ' ' . $mashsb_options['buttons_size'] : '';
    // Get class names for buttons margin
    $class_margin = isset($mashsb_options['button_margin']) ? '' : ' mash-nomargin';
    // Get class names for center align
    $class_center = isset($mashsb_options['text_align_center']) ? ' mash-center' : '';
    // Get class names for button style
    $class_style = isset($mashsb_options['mash_style']) && $mashsb_options['mash_style'] === 'shadow' ? ' mashsb-shadow' : '';
    $output = '';
    $startsecondaryshares = '';
    $endsecondaryshares = '';
    /* content of 'more services' button */
    $onoffswitch = '';
    /* counter for 'Visible Services' */
    $startcounter = 1;
    $maxcounter = isset($mashsb_options['visible_services']) ? $mashsb_options['visible_services'] : 0;
    $maxcounter = $maxcounter === 'all' ? 'all' : $maxcounter + 1;
    // plus 1 to get networks correct counted (array's starting counting from zero)
    $maxcounter = apply_filters('mashsb_visible_services', $maxcounter);
    /* Overwrite maxcounter with shortcode attribute */
    $maxcounter = $services === 0 ? $maxcounter : $services;
    /* our list of available services, includes the disabled ones! 
     * We have to clean this array first!
     */
    $getnetworks = isset($mashsb_options['networks']) ? $mashsb_options['networks'] : '';
    //echo '<pre>'.var_dump($getnetworks) . '</pre>';
    /* Delete disabled services from array. Use callback function here. Do this only once because array_filter is slow! 
     * Use the newly created array and bypass the callback function
     */
    if (is_array($getnetworks)) {
        if (!is_array($enablednetworks)) {
            $enablednetworks = array_filter($getnetworks, 'isStatus');
        } else {
            $enablednetworks = $enablednetworks;
        }
    } else {
        $enablednetworks = $getnetworks;
    }
    // Start Primary Buttons
    //$output .= '<div class="mashsb-primary-shares">';
    if (!empty($enablednetworks)) {
        foreach ($enablednetworks as $key => $network) {
            if ($maxcounter !== 'all' && $maxcounter < count($enablednetworks)) {
                // $maxcounter + 1 for correct comparision with count()
                if ($startcounter == $maxcounter) {
                    $onoffswitch = onOffSwitch();
                    // Start More Button
                    //$startsecondaryshares = '</div>'; // End Primary Buttons
                    $startsecondaryshares .= '<div class="secondary-shares" style="display:none;">';
                    // Start secondary-shares
                } else {
                    $onoffswitch = '';
                    $onoffswitch2 = '';
                    $startsecondaryshares = '';
                }
                if ($startcounter === count($enablednetworks)) {
                    $endsecondaryshares = '</div>';
                } else {
                    $endsecondaryshares = '';
                }
            }
            //if( $enablednetworks[$key]['name'] != '' ) {
            if (isset($enablednetworks[$key]['name']) && !empty($enablednetworks[$key]['name'])) {
                /* replace all spaces with $nbsp; This prevents error in css style content: text-intend */
                $name = preg_replace('/\\040{1,}/', '&nbsp;', $enablednetworks[$key]['name']);
                // The custom share label
            } else {
                $name = ucfirst($enablednetworks[$key]['id']);
                // Use the id as share label. Capitalize it!
            }
            $enablednetworks[$key]['id'] == 'whatsapp' ? $display = 'style="display:none;"' : ($display = '');
            // Whatsapp button is made visible via js when opened on mobile devices
            // Lets use the data attribute to prevent that pininit.js is overwriting our pinterest button - PR: https://secure.helpscout.net/conversation/257066283/954/?folderId=924740
            if ('pinterest' === $enablednetworks[$key]['id'] && !mashsb_is_amp_page()) {
                $output .= '<a ' . $display . ' class="mashicon-' . $enablednetworks[$key]['id'] . $class_size . $class_margin . $class_center . $class_style . '" href="#" data-mashsb-url="' . arrNetworks($enablednetworks[$key]['id'], $is_shortcode) . '" target="_blank" rel="nofollow"><span class="icon"></span><span class="text">' . $name . '</span></a>';
            } else {
                $output .= '<a ' . $display . ' class="mashicon-' . $enablednetworks[$key]['id'] . $class_size . $class_margin . $class_center . $class_style . '" href="' . arrNetworks($enablednetworks[$key]['id'], $is_shortcode) . '" target="_blank" rel="nofollow"><span class="icon"></span><span class="text">' . $name . '</span></a>';
            }
            $output .= $onoffswitch;
            $output .= $startsecondaryshares;
            $startcounter++;
        }
        $output .= onOffSwitch2();
        $output .= $endsecondaryshares;
    }
    return apply_filters('return_networks', $output);
}