function sw_check_registration_status() { // Fetch the User's Options Array $sw_user_options = sw_get_user_options(); // Fetch URL of the home page $homeURL = get_home_url(); // Create a Registration Code from the Domain Name $regCode = md5($homeURL); // IF the plugin thinks that it is already registered.... if (is_sw_registered()) { // Construct the request URL $url = 'https://warfareplugins.com/registration-api/?activity=check_registration&emailAddress=' . $sw_user_options['emailAddress'] . '&domain=' . $homeURL . '®istrationCode=' . md5($homeURL); // Send the link and load the response $response = sw_file_get_contents_curl($url); // If the response is negative, unregister the plugin.... if ($response == 'false') { // Set the premium code to null $sw_user_options['premiumCode'] = ''; // Update the options array with the premium code nulled update_option('socialWarfareOptions', $sw_user_options); } // If the codes didn't match, but a premium code does exist } elseif (isset($sw_user_options['premiumCode'])) { // Attemp to unregister this from the Warfare Plugins Server $url = 'https://warfareplugins.com/registration-api/?activity=unregister&emailAddress=' . $sw_user_options['emailAddress'] . '&premiumCode=' . $sw_user_options['premiumCode']; // Parse the response $response = sw_file_get_contents_curl($url); $response = json_decode($response, true); // If it unregistered, let's try to auto-reregister it.... if ($response['status'] == 'Success') { // Attempt to reregister it $url = 'https://warfareplugins.com/registration-api/?activity=register&emailAddress=' . $sw_user_options['emailAddress'] . '&domain=' . get_home_url() . '®istrationCode=' . $regCode; // Parse the response $response = sw_file_get_contents_curl($url); $response = json_decode($response, true); // IF the registration attempt was successful.... if ($response['status'] == 'Success') { // Save our updated options $sw_user_options['premiumCode'] == $response['premiumCode']; // Update the options storing in our new updated Premium Code update_option('socialWarfareOptions', $sw_user_options); return true; // IF the registration attempt was NOT successful } else { // Set the premium code to null $sw_user_options['premiumCode'] = ''; // Update the options array with the premium code nulled update_option('socialWarfareOptions', $sw_user_options); return false; } // IF it wasn't able to unregister } else { // Set the premium code to null $sw_user_options['premiumCode'] = ''; // Update the options array with the premium code nulled update_option('socialWarfareOptions', $sw_user_options); return false; } } }
function afsp_sw_google_analytics($array) { // Fetch the user options $options = sw_get_user_options(); $url = $array['url']; $network = $array['network']; // Disable Analytics forever on the quilt so that deep linking will work correctly if (is_page('digital-memory-quilt')) { $options['googleAnalytics'] = false; } // Check if Analytics have been enabled or not if ($options['googleAnalytics'] == true) { $url = $url . urlencode('?utm_source=' . $network . '&utm_medium=' . $options['analyticsMedium'] . '&utm_campaign=' . $options['analyticsCampaign'] . ''); return $url; } else { return $url; } }
function nc_register_meta_boxes($meta_boxes) { // Setup the prefix to avoid conflicts $prefix = 'nc_'; $options = sw_get_user_options(); $postTypes = sw_get_post_types(); foreach ($postTypes as $key => $value) { $postType[] = $key; } $postType[] = 'page'; $postType[] = 'post'; // Setup our meta box using an array $meta_boxes[0] = array('id' => 'socialWarfare', 'title' => 'Social Warfare Custom Options', 'pages' => $postType, 'context' => 'normal', 'priority' => 'high', 'fields' => array(array('name' => '<i class="fa fa-share-alt"></i> Social Media Image', 'desc' => 'Add an image that is optimized for maximum exposure on Facebook, Google+ and LinkedIn. We recommend 1280px by 720px.', 'id' => $prefix . 'ogImage', 'type' => 'image_advanced', 'clone' => false, 'max_file_uploads' => 1), array('name' => '<i class="fa fa-share-alt"></i> Social Media Title', 'desc' => 'Add a title that will populate the open graph meta tag which will be used when users share your content onto Facebook, LinkedIn, and Google+. If nothing is provided here, we will use the post title as a backup.', 'id' => $prefix . 'ogTitle', 'type' => 'textarea', 'clone' => false), array('name' => '<i class="fa fa-share-alt"></i> Social Media Description', 'desc' => 'Add a description that will populate the open graph meta tag which will be used when users share your content onto Facebook, LinkedIn, and Google Plus.', 'id' => $prefix . 'ogDescription', 'type' => 'textarea', 'clone' => false), array('name' => 'divider', 'id' => 'divider', 'type' => 'divider'), array('name' => '<i class="fa fa-pinterest"></i> Pinterest Image', 'desc' => 'Add an image that is optimized for maximum exposure on Pinterest. We recommend using an image that is formated in a 2:3 aspect ratio like 600x900 or 735x1100.', 'id' => $prefix . 'pinterestImage', 'type' => 'image_advanced', 'clone' => false, 'max_file_uploads' => 1), array('name' => '<i class="fa fa-pinterest"></i> Pinterest Description', 'desc' => 'Place a customized message that will be used when this post is shared on Pinterest. Leave this blank to use the title of the post.', 'id' => $prefix . 'pinterestDescription', 'type' => 'textarea', 'clone' => false), array('name' => '<i class="fa fa-twitter"></i> Custom Tweet', 'desc' => 'If this is left blank your post title will be used. ' . ($options['twitterID'] ? 'Based on your username (@' . $options['twitterID'] . '), <span class="tweetLinkSection">a link being added,</span> and the current content above' : '<span ="tweetLinkSection">Based on a link being added, and</span> the current content above') . ', your tweet has <span class="counterNumber">140</span> characters remaining.', 'id' => $prefix . 'customTweet', 'type' => 'textarea', 'clone' => false), array('name' => '<i class="fa fa-location-arrow"></i> Horizontal Buttons Location', 'desc' => 'Where would you like to have the share buttons displayed on this post? Leave this option on "default" to use the settings you have selected on the Social Warfare settings page.', 'id' => $prefix . 'postLocation', 'type' => 'select', 'options' => array('default' => 'Default', 'above' => 'Above the Content', 'below' => 'Below the Content', 'both' => 'Both Above and Below the Content', 'none' => 'None/Manual Placement'), 'clone' => false))); $meta_boxes[0]['fields'][] = array('name' => '<i class="fa fa-location-arrow"></i> Side Floating Buttons Location', 'desc' => 'Do you wish to have the floating sidebar buttons on this post?', 'id' => $prefix . 'floatLocation', 'type' => 'select', 'options' => array('on' => 'On', 'off' => 'Off'), 'clone' => false); $meta_boxes[0]['fields'][] = array('name' => 'divider2', 'id' => 'divider2', 'type' => 'divider'); // Twitter ID $meta_boxes[0]['fields'][] = array('name' => $options['twitterID'], 'id' => 'twitterID', 'type' => 'hidden', 'std' => $options['twitterID']); // Return the meta boxes return $meta_boxes; }
function form($instance) { // Check values if ($instance) { $title = esc_attr($instance['title']); $count = esc_attr($instance['count']); $timeframe = esc_textarea($instance['timeframe']); $network = esc_textarea($instance['network']); $showCount = esc_textarea($instance['showCount']); $countLabel = esc_textarea($instance['countLabel']); $style = esc_textarea($instance['style']); } else { $title = 'Popular Posts'; $count = '10'; $timeframe = '180'; $network = 'totes'; $showCount = 'true'; $countLabel = 'Total Shares'; $style = 'Default'; } $options = sw_get_user_options(); $availableNetworks = $options['newOrderOfIcons']; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Widget Title', 'wp_widget_plugin'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo $title; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('count'); ?> "><?php _e('How many posts would you like to display?', 'wp_widget_plugin'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('count'); ?> " name="<?php echo $this->get_field_name('count'); ?> " type="number" value="<?php echo $count; ?> " min="0" /> </p> <p style="display:none;"> <label for="<?php echo $this->get_field_id('timeframe'); ?> "><?php _e('What is maximum age of a post (in days) that you would like to include?', 'wp_widget_plugin'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('timeframe'); ?> " name="<?php echo $this->get_field_name('timeframe'); ?> " value="<?php echo $timeframe; ?> " type="number" min="0"> </p> <p> <label for="<?php echo $this->get_field_id('network'); ?> "><?php _e('Which network would you like to base your posts popularity on?', 'wp_widget_plugin'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('network'); ?> " name="<?php echo $this->get_field_name('network'); ?> "> <option value="totes" <?php if ($network == 'totes') { echo 'selected'; } ?> >All Networks</option> <?php foreach ($availableNetworks as $key => $value) { if ($options[$key]) { if ($network == $key . '_shares') { echo '<option value="' . $key . '_shares" selected>' . $value . '</option>'; } else { echo '<option value="' . $key . '_shares">' . $value . '</option>'; } } } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('showCount'); ?> "><?php _e('Would you like to show the count?', 'wp_widget_plugin'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('showCount'); ?> " name="<?php echo $this->get_field_name('showCount'); ?> "> <option value="true" <?php if ($showCount == 'true') { echo 'selected'; } ?> >Yes</option> <option value="false" <?php if ($showCount == 'false') { echo 'selected'; } ?> >No</option> </select> </p> <p> <label for="<?php echo $this->get_field_id('countLabel'); ?> "><?php _e('Count Number Label', 'wp_widget_plugin'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('countLabel'); ?> " name="<?php echo $this->get_field_name('countLabel'); ?> " type="text" value="<?php echo $countLabel; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('style'); ?> "><?php _e('Which visual style would you like to use?', 'wp_widget_plugin'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('style'); ?> " name="<?php echo $this->get_field_name('style'); ?> "> <!-- Begin the options for the visual Selector --> <option value="first_style" <?php if ($style == 'first_style') { echo 'selected'; } ?> >First Style</option> <option value="second_style" <?php if ($style == 'second_style') { echo 'selected'; } ?> >Second Style</option> <!-- End the options for the visual Selector --> </select> </p> <?php }
public function sw_background_color_footer() { $sw_user_options = sw_get_user_options(); ?> <style> .nc_wrapper { transition: background-color .2s ease; -moz-transition: background-color .2s ease; -webkit-transition: background-color .2s ease; } </style> <script> var iScrollPos = 0; jQuery(window).scroll(function() { if( ! jQuery('<?php echo $sw_user_options['floatFooterSelector']; ?> ') ) return; var iCurScrollPos = jQuery(this).scrollTop(); if (iCurScrollPos > iScrollPos) { // Scrolling Down if( jQuery(window).scrollTop() + jQuery(window).height() > jQuery(document).height() - jQuery('<?php echo $sw_user_options['floatFooterSelector']; ?> ').outerHeight() - jQuery( '.nc_wrapper' ).outerHeight() ){ jQuery( '.nc_wrapper' ).css('background-color', '<?php echo $sw_user_options['floatFooterBgColor']; ?> '); } } else { //Scrolling Up if( jQuery(window).scrollTop() + jQuery(window).height() < jQuery(document).height() - jQuery('<?php echo $sw_user_options['floatFooterSelector']; ?> ').outerHeight() ){ jQuery( '.nc_wrapper' ).css('background-color', '<?php echo $sw_user_options['floatBgColor']; ?> '); } } iScrollPos = iCurScrollPos; }); </script> <?php }
function social_warfare_buttons($array = array()) { // Setup the default Array parameters if (!isset($array['where'])) { $array['where'] = 'default'; } if (!isset($array['echo'])) { $array['echo'] = true; } if (!isset($array['content'])) { $array['content'] = false; } // Get the options...or create them if they don't exist if (isset($array['post_id'])) { $postID = $array['post_id']; } else { $postID = get_the_ID(); } $options = sw_get_user_options(); // Check to see if display location was specifically defined for this post $specWhere = get_post_meta($postID, 'nc_postLocation', true); if ($array['where'] == 'default') { if ($specWhere == 'default' || $specWhere == '') { if (is_singular('post')) { $array['where'] = $options['locationPost']; } elseif (is_singular('page')) { $array['where'] = $options['locationPage']; } elseif (is_singular()) { $postType = get_post_type($postID); if (isset($options['location' . $postType])) { $array['where'] = $options['location' . $postType]; } else { $array['where'] = 'none'; } } else { $postType = get_post_type($postID); if (isset($options['location' . $postType])) { $array['where'] = $options['location' . $postType]; } elseif ($postType == 'post' || $postType == 'page') { $array['where'] = $options['locationSite']; } else { $array['where'] = 'none'; } } } else { $array['where'] = $specWhere; } } // Disable the buttons on Buddy Press pages if (function_exists('is_buddypress') && is_buddypress()) { return $array['content']; // Disable the buttons if the location is set to "None / Manual" } elseif ($array['where'] == 'none' && !isset($array['devs'])) { return $array['content']; // Disable the button if we're not in the loop, unless there is no content which means the function was called by a developer. } elseif ((!is_main_query() || !in_the_loop()) && !isset($array['devs'])) { return $array['content']; // Don't do anything if we're in the admin section } elseif (is_admin()) { return $array['content']; // If all the checks pass, let's make us some buttons! } else { // Set the options for the horizontal floating bar if ($options['float'] && is_singular()) { $floatOption = 'float' . ucfirst($options['floatOption']); } else { $floatOption = 'floatNone'; } // Disable the plugin on feeds, search results, and non-published content if (!is_feed() && !is_search() && get_post_status($postID) == 'publish') { // Acquire the social stats from the networks if (isset($array['url'])) { $buttonsArray['url'] = $array['url']; } else { $buttonsArray['url'] = get_permalink($postID); } $language = array(); $language = apply_filters('sw_languages', $language); // Setup the buttons array to pass into the 'sw_network_buttons' hook $buttonsArray['shares'] = get_social_warfare_shares($postID); $buttonsArray['language'] = apply_filters('sw_languages', $language); $buttonsArray['count'] = 0; $buttonsArray['totes'] = 0; $buttonsArray['options'] = $options; if ($buttonsArray['options']['totes'] && $buttonsArray['shares']['totes'] >= $buttonsArray['options']['minTotes']) { ++$buttonsArray['count']; } $buttonsArray['resource'] = array(); $buttonsArray['postID'] = $postID; // Disable the subtitles plugin to avoid letting them inject their subtitle into our share titles if (is_plugin_active('subtitles/subtitles.php') && class_exists('Subtitles')) { remove_filter('the_title', array(Subtitles::getinstance(), 'the_subtitle'), 10, 2); } // This array will contain the HTML for all of the individual buttons $buttonsArray = apply_filters('sw_network_buttons', $buttonsArray); // Create the social panel $assets = '<div class="nc_socialPanel sw_' . $options['visualTheme'] . ' sw_d_' . $options['dColorSet'] . ' sw_i_' . $options['iColorSet'] . ' sw_o_' . $options['oColorSet'] . '" data-position="' . $options['locationPost'] . '" data-float="' . $floatOption . '" data-count="' . $buttonsArray['count'] . '" data-floatColor="' . $options['floatBgColor'] . '" data-scale="' . $options['buttonSize'] . '" data-align="' . $options['buttonFloat'] . '">'; // Setup the total shares count if it's on the left if ($options['totes'] && $options['swTotesFormat'] == 'totesAltLeft' && $buttonsArray['totes'] >= $options['minTotes']) { $assets .= '<div class="nc_tweetContainer totes totesalt" data-id="6" >'; $assets .= '<span class="sw_count">' . kilomega($buttonsArray['totes']) . ' <span class="sw_label">' . $language['total'] . '</span></span>'; $assets .= '</div>'; } // Sort the buttons according to the user's preferences if ($options['orderOfIconsSelect'] == 'manual') { foreach ($options['newOrderOfIcons'] as $thisIcon => $status) { if (isset($buttonsArray['resource'][$thisIcon])) { $assets .= $buttonsArray['resource'][$thisIcon]; } } } elseif ($options['orderOfIconsSelect'] == 'dynamicCount') { arsort($buttonsArray['shares']); foreach ($buttonsArray['shares'] as $thisIcon => $status) { if (isset($buttonsArray['resource'][$thisIcon])) { $assets .= $buttonsArray['resource'][$thisIcon]; } } } // Create the Total Shares Box if it's on the right if ($options['totes'] && $options['swTotesFormat'] != 'totesAltLeft' && $buttonsArray['totes'] >= $options['minTotes']) { if ($options['swTotesFormat'] == 'totes') { $assets .= '<div class="nc_tweetContainer totes" data-id="6" >'; $assets .= '<span class="sw_count">' . kilomega($buttonsArray['totes']) . ' <span class="sw_label">' . $language['total'] . '</span></span>'; $assets .= '</div>'; } else { $assets .= '<div class="nc_tweetContainer totes totesalt" data-id="6" >'; $assets .= '<span class="sw_count"><span class="sw_label">' . $language['total'] . '</span> ' . kilomega($buttonsArray['totes']) . '</span>'; $assets .= '</div>'; } } // Close the Social Panel $assets .= '</div>'; // Reset the cache timestamp if needed if (sw_is_cache_fresh($postID) == false) { delete_post_meta($postID, 'sw_cache_timestamp'); update_post_meta($postID, 'sw_cache_timestamp', floor(date('U') / 60 / 60)); } if ($array['echo'] == false && $array['where'] != 'none') { return $assets; } elseif ($array['content'] === false) { echo $assets; } elseif ($array['where'] == 'below') { $content = $array['content'] . '' . $assets; return $content; } elseif ($array['where'] == 'above') { $content = $assets . '' . $array['content']; return $content; } elseif ($array['where'] == 'both') { $content = $assets . '' . $array['content'] . '' . $assets; return $content; } elseif ($array['where'] == 'none') { return $array['content']; } } else { return $array['content']; } } }
function sw_get_single_option($key) { $option = sw_get_user_options(); return $option[$key]; }
function socialWarfareSideFloat() { $postID = get_the_ID(); $options = sw_get_user_options(); $postType = get_post_type($postID); if (is_singular('post')) { $visibility = $options['floatLocationPost']; } elseif (is_singular('page')) { $visibility = $options['floatlocationPage']; } elseif (is_singular()) { $postType = get_post_type($postID); if (isset($options['floatLocation' . $postType])) { $visilibity = $options['floatLocation' . $postType]; } else { $visibility = 'on'; } } else { $visibility = 'on'; } if (is_singular() && get_post_status($postID) == 'publish' && get_post_meta($postID, 'nc_floatLocation', true) != 'off' && $visibility == 'on' && !is_home()) { // Get the options...or create them if they don't exist wp_reset_query(); // Acquire the social stats from the networks // Acquire the social stats from the networks if (isset($array['url'])) { $buttonsArray['url'] = $array['url']; } else { $buttonsArray['url'] = get_permalink($postID); } if ($options['float'] && is_singular()) { $floatOption = 'float' . ucfirst($options['floatOption']); } else { $floatOption = 'floatNone'; } $language = array(); $language = apply_filters('sw_languages', $language); if ($options['floatStyleSource'] == true) { $options['sideDColorSet'] = $options['dColorSet']; $options['sideIColorSet'] = $options['iColorSet']; $options['sideOColorSet'] = $options['oColorSet']; } // Setup the buttons array to pass into the 'sw_network_buttons' hook $buttonsArray['shares'] = get_social_warfare_shares($postID); $buttonsArray['language'] = apply_filters('sw_languages', $language); $buttonsArray['count'] = 0; $buttonsArray['totes'] = 0; $buttonsArray['options'] = $options; if ($buttonsArray['options']['totes'] && $buttonsArray['shares']['totes'] >= $buttonsArray['options']['minTotes']) { ++$buttonsArray['count']; } $buttonsArray['resource'] = array(); $buttonsArray['postID'] = $postID; $buttonsArray = apply_filters('sw_network_buttons', $buttonsArray); // Create the social panel $assets = '<div class="nc_socialPanelSide nc_socialPanel sw_' . $options['floatStyle'] . ' sw_d_' . $options['sideDColorSet'] . ' sw_i_' . $options['sideIColorSet'] . ' sw_o_' . $options['sideOColorSet'] . '" data-position="' . $options['locationPost'] . '" data-float="' . $floatOption . '" data-count="' . $buttonsArray['count'] . '" data-floatColor="' . $options['floatBgColor'] . '" data-screen-width="' . $options['sw_float_scr_sz'] . '">'; // Display Total Shares if the Threshold has been met if ($options['totes'] && $buttonsArray['totes'] >= $options['minTotes']) { $assets .= '<div class="nc_tweetContainer totes totesalt" data-id="6" >'; $assets .= '<span class="sw_count">' . kilomega($buttonsArray['totes']) . '</span><span class="sw_label"> ' . $language['total'] . '</span>'; $assets .= '</div>'; } $i = 0; if ($options['orderOfIconsSelect'] == 'manual') { foreach ($options['newOrderOfIcons'] as $thisIcon => $status) { if (isset($buttonsArray['resource'][$thisIcon])) { $assets .= $buttonsArray['resource'][$thisIcon]; ++$i; } if ($i == 5) { break; } } } elseif ($options['orderOfIconsSelect'] == 'dynamicCount') { arsort($buttonsArray['shares']); foreach ($buttonsArray['shares'] as $thisIcon => $status) { if (isset($buttonsArray['resource'][$thisIcon])) { $assets .= $buttonsArray['resource'][$thisIcon]; ++$i; } if ($i == 5) { break; } } } // Close the Social Panel $assets .= '</div>'; echo $assets; } }
function get_social_warfare_shares($postID) { // Set the initial options $options = sw_get_user_options(); $url = get_permalink($postID); // $url = 'https://youtu.be/jjK1aUU2Dx4'; /***************************************************************** * * * Check the Cache * * * ******************************************************************/ $freshCache = sw_is_cache_fresh($postID); // $freshCache = false; /***************************************************************** * * * Setup the Networks Array that we'll loop through * * * ******************************************************************/ // Initiate the ShareCount class $shares['totes'] = 0; // Queue up the networks that are available $availableNetworks = $options['newOrderOfIcons']; $networks = array(); foreach ($availableNetworks as $key => $value) { if ($options[$key]) { $networks[] = $key; } } /***************************************************************** * * * Loop through the Networks * * * ******************************************************************/ // Loop through the networks and fetch their share counts foreach ($networks as $network) { // Check if this network is even activated if ($options[$network]) { // Check if we can used the cached share numbers if ($freshCache == true) { $shares[$network] = get_post_meta($postID, '_' . $network . '_shares', true); // If cache is expired, fetch new and update the cache } else { $old_shares[$network] = get_post_meta($postID, '_' . $network . '_shares', true); $share_links[$network] = call_user_func('sw_' . $network . '_request_link', $url); } } } // Recover Shares From Previously Used URL Patterns if ($options['recover_shares'] == true && $freshCache == false) { $alternateURL = sw_get_alternate_permalink($options['recovery_format'], $options['recovery_protocol'], $postID); foreach ($networks as $network) { // Check if this network is even activated if ($options[$network]) { $old_share_links[$network] = call_user_func('sw_' . $network . '_request_link', $alternateURL); } } } if ($freshCache == true) { $shares['totes'] = get_post_meta($postID, '_totes', true); } else { // Fetch all the share counts asyncrounously $raw_shares_array = sw_fetch_shares_via_curl_multi($share_links); if ($options['recover_shares'] == true) { $old_raw_shares_array = sw_fetch_shares_via_curl_multi($old_share_links); } foreach ($networks as $network) { // Check if this network is even activated if ($options[$network]) { if (!isset($raw_shares_array[$network])) { $raw_shares_array[$network] = 0; } if (!isset($old_raw_shares_array[$network])) { $old_raw_shares_array[$network] = 0; } $shares[$network] = call_user_func('sw_format_' . $network . '_response', $raw_shares_array[$network]); if ($options['recover_shares'] == true) { $recovered_shares[$network] = call_user_func('sw_format_' . $network . '_response', $old_raw_shares_array[$network]); if ($shares[$network] != $recovered_shares[$network]) { $shares[$network] = $shares[$network] + $recovered_shares[$network]; } } if ($shares[$network] <= $old_shares[$network]) { $shares[$network] = $old_shares[$network]; } else { delete_post_meta($postID, '_' . $network . '_shares'); update_post_meta($postID, '_' . $network . '_shares', $shares[$network]); } $shares['totes'] += $shares[$network]; } } } /***************************************************************** * * * Update the Cache and Return the Share Counts * * * ******************************************************************/ if ($freshCache != true) { // Clean out the previously used custom meta fields delete_post_meta($postID, '_totes'); // Add the new data to the custom meta fields update_post_meta($postID, '_totes', $shares['totes']); } // Return the share counts return $shares; }
function sw_make_bitly_url($url, $network, $login, $appkey) { // Fetch the user's options $options = sw_get_user_options(); $format = 'json'; $bitly_api = 'https://api-ssl.bitly.com/v3/shorten?login='******'&apiKey=' . $appkey . '&uri=' . urlencode($url) . '&format=' . $format; $data = sw_file_get_contents_curl($bitly_api); $data = json_decode($data); if (isset($data->data->url)) { return $data->data->url; } else { return false; } }
*/ // Add settings link on plugin page function sw_settings_link($links) { $settings_link = '<a href="admin.php?page=social-warfare">Settings</a>'; array_unshift($links, $settings_link); return $links; } $plugin = plugin_basename(__FILE__); add_filter("plugin_action_links_{$plugin}", 'sw_settings_link'); /***************************************************************** * * * ENQUEUE: SCRIPTS AND STYLES * * * ******************************************************************/ $sw_user_options = sw_get_user_options(); add_action('wp_enqueue_scripts', 'enqueueSocialWarfareScripts'); function enqueueSocialWarfareScripts() { global $sw_user_options; wp_enqueue_script('social_warfare_script', PLUGIN_DIR . '/script.min.js', array('jquery'), SW_VERSION); wp_register_style('social_warfare', PLUGIN_DIR . '/css/style.css', array(), SW_VERSION); wp_enqueue_style('social_warfare'); } // Enqueue admin and Click to Tweet Styles add_action('admin_enqueue_scripts', 'enqueueSocialWarfareAdminScripts'); function enqueueSocialWarfareAdminScripts() { wp_register_style('social_warfare', PLUGIN_DIR . '/css/style.css', array(), SW_VERSION); wp_enqueue_style('social_warfare'); wp_enqueue_script('social_warfare_script', PLUGIN_DIR . '/script.min.js', array('jquery'), SW_VERSION);
function sw_add_header_meta() { $info['postID'] = get_the_ID(); // Cache some resource for fewer queries on subsequent page loads if (sw_is_cache_fresh($info['postID']) == false) { // Check if an image ID has been provided $info['imageID'] = get_post_meta($info['postID'], 'nc_ogImage', true); if ($info['imageID']) { $info['imageURL'] = wp_get_attachment_url($info['imageID']); delete_post_meta($info['postID'], 'sw_open_graph_image_url'); update_post_meta($info['postID'], 'sw_open_graph_image_url', $info['imageURL']); } else { $info['imageURL'] = wp_get_attachment_url(get_post_thumbnail_id($info['postID'])); delete_post_meta($info['postID'], 'sw_open_thumbnail_url'); update_post_meta($info['postID'], 'sw_open_thumbnail_url', $info['imageURL']); delete_post_meta($info['postID'], 'sw_open_graph_image_url'); } $user_twitter_handle = get_the_author_meta('sw_twitter', sw_get_author($info['postID'])); if ($user_twitter_handle) { delete_post_meta($info['postID'], 'sw_twitter_username'); update_post_meta($info['postID'], 'sw_twitter_username', $user_twitter_handle); } else { delete_post_meta($info['postID'], 'sw_twitter_username'); } } else { // Check if we have a cached Open Graph Image URL $info['imageURL'] = get_post_meta($info['postID'], 'sw_open_graph_image_url', true); // If not, let's check to see if we have an ID to generate one if (!$info['imageURL']) { // Check for an Open Graph Image ID $info['imageID'] = get_post_meta($info['postID'], 'nc_ogImage', true); if ($info['imageID']) { // If we find one, let's convert it to a link and cache it for next time $info['imageURL'] = wp_get_attachment_url($info['imageID']); delete_post_meta($info['postID'], 'sw_open_graph_image_url'); update_post_meta($info['postID'], 'sw_open_graph_image_url', $info['imageURL']); } else { // If we don't find one, let's save the URL of the thumbnail in case we need it $thumbnail_image = get_post_meta($info['postID'], 'sw_open_thumbnail_url', true); } } $user_twitter_handle = get_post_meta($info['postID'], 'sw_twitter_username', true); } // Create the image Open Graph Meta Tag $info['postID'] = get_the_ID(); $info['title'] = htmlspecialchars(get_post_meta($info['postID'], 'nc_ogTitle', true)); $info['description'] = htmlspecialchars(get_post_meta($info['postID'], 'nc_ogDescription', true)); $info['sw_user_options'] = sw_get_user_options(); $info['user_twitter_handle'] = $user_twitter_handle; $info['header_output'] = ''; $info = apply_filters('sw_meta_tags', $info); if ($info['header_output']) { echo PHP_EOL . '<!-- Open Graph Meta Tags & Twitter Card generated by Social Warfare v' . SW_VERSION . ' http://warfareplugins.com -->'; echo $info['header_output']; echo PHP_EOL . '<!-- Open Graph Meta Tags & Twitter Card generated by Social Warfare v' . SW_VERSION . ' http://warfareplugins.com -->' . PHP_EOL . PHP_EOL; } }