/**
 * Check if cache time is expired and post must be refreshed
 * 
 * @global array $post
 * @return boolean 
 */
function mashsb_is_cache_refresh()
{
    global $post, $mashsb_options;
    // Debug mode or cache activated
    if (MASHSB_DEBUG || isset($mashsb_options['disable_cache'])) {
        MASHSB()->logger->info('mashsb_is_cache_refresh: MASHSB_DEBUG - refresh Cache');
        return true;
    }
    // if it's a crawl deactivate cache
    if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) {
        return false;
    }
    /*
    * Deactivate share count on:
    * - 404 pages
    * - search page
    * - empty url
    * - disabled permalinks
    * - admin pages
    * 
       Exit here to save cpu time
    */
    if (is_404() || is_search() || is_admin() || !mashsb_is_enabled_permalinks()) {
        return false;
    }
    // New cache on singular pages
    //
    // Refreshing cache on blog posts like categories will lead
    // to high load and multiple API requests so we only check
    // the main url on these other pages
    if (is_singular()) {
        // last updated timestamp
        $last_updated = get_post_meta($post->ID, 'mashsb_timestamp', true);
        if (!empty($last_updated)) {
            MASHSB()->logger->info('mashsb_is_cache_refresh - is_singular() url: ' . get_permalink($post->ID) . ' : last updated:' . date('Y-m-d H:i:s', $last_updated));
        }
    } else {
        if (mashsb_get_main_url()) {
            // Get transient timeout and calculate last update time
            $url = mashsb_get_main_url();
            $transient = '_transient_timeout_mashcount_' . md5(mashsb_get_main_url());
            $last_updated = get_option($transient) - mashsb_get_expiration();
            if (!empty($last_updated)) {
                MASHSB()->logger->info('mashsb_is_cache_refresh() mashsb_get_main_url() url: ' . $url . ' last updated:' . date('Y-m-d H:i:s', $last_updated));
            }
        } else {
            // No valid URL so do not refresh cache
            MASHSB()->logger->info('mashsb_is_cache_refresh: No valid URL - do not refresh cache');
            return false;
        }
    }
    // No timestamp so let's create cache for the first time
    if (empty($last_updated)) {
        MASHSB()->logger->info('mashsb_is_cache_refresh: No Timestamp. Refresh Cache');
        return true;
    }
    // The caching expiration
    $expiration = mashsb_get_expiration();
    $next_update = $last_updated + $expiration;
    MASHSB()->logger->info('mashsb_is_cache_refresh. Next update ' . date('Y-m-d H:i:s', $next_update) . ' current time: ' . date('Y-m-d H:i:s', time()));
    // Refresh Cache when last update plus expiration is older than current time
    if ($last_updated + $expiration <= time()) {
        MASHSB()->logger->info('mashsb_is_cache_refresh: Refresh Cache!');
        return true;
    }
}
Beispiel #2
0
/**
 * Admin Messages
 *
 * @since 2.2.3
 * @global $mashsb_options Array of all the MASHSB Options
 * @return void
 */
function mashsb_admin_messages()
{
    global $mashsb_options;
    if (!current_user_can('update_plugins')) {
        return;
    }
    // Rate Limit warning
    if (mashsb_is_admin_page() && mashsb_rate_limit_exceeded()) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('Your website exceeded the Facebook rate limit. Share count requests to Facebook will be delayed for 60min and the Facebook Share Count will not grow during this time. If you see this notice often consider to change <strong>MashShare Caching Method</strong> to <a href="%s">Refresh while Loading</a> and use a higher cache expiration. MashShare tries again to request shares in ' . mashsbGetRemainingRateLimitTime(), 'mashsb'), admin_url() . 'admin.php?page=mashsb-settings') . '</p>';
        echo '</div>';
    }
    //    // Access Token expired
    //    if( mashsb_is_access_token_expired() ) {
    //        echo '<div class="error">';
    //        echo '<p>' . sprintf(__('Your Facebook Access Token has been expired. You need to <a href="%s">generate a new one</a> or your MashShare Facebook Shares will not be refreshed', 'mashsb'), admin_url() . 'admin.php?page=mashsb-settings') . '</p>';
    //        echo '</div>';
    //    }
    // Cache warning
    if (mashsb_is_deactivated_cache()) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('Attention: The Mashshare Cache is deactivated. <a href="%s">Activate it</a> or share count requests to social networks will be rate limited.', 'mashsb'), admin_url() . 'admin.php?page=mashsb-settings#mashsb_settingsdebug_header') . '</p>';
        echo '</div>';
    }
    // Cache warning
    if (mashsb_is_deleted_cache()) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('Attention: The Mashshare Cache is permanetely purged. <a href="%s">Disable this</a> or share count requests to social networks will be rate limited.', 'mashsb'), admin_url() . 'admin.php?page=mashsb-settings#mashsb_settingsdebug_header') . '</p>';
        echo '</div>';
    }
    //mashsb_update_notice_101();
    if (mashsb_is_admin_page() && !function_exists('curl_init')) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('MashShare needs the PHP extension cURL which is not installed on your server. Please <a href="%s" target="_blank">install and activate</a> it to be able to collect share count of your posts.', 'mashsb'), 'https://www.google.com/search?btnG=1&pws=0&q=enable+curl+on+php') . '</p>';
        echo '</div>';
    }
    // notice no Networks enabled
    if (mashsb_is_admin_page() && !mashsb_check_active_networks()) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('No Social Networks enabled. Go to <a href="%s"> Mashshare->Settings->Social Networks</a> and enable at least one Social Network.', 'mashsb'), admin_url('admin.php?page=mashsb-settings&tab=networks#mashsb_settingsservices_header')) . '</p>';
        echo '</div>';
    }
    // Share bar add-on notice
    if (mashsb_is_admin_page() && mashsb_incorrect_sharebar_version()) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('Your Sharebar Add-On version is not using new short url mechanism of MashShare 3.X. Please <a href="%s" target="blank"> update the Sharebar Add-On</a> to at least version 1.2.5. if you want to make sure that twitter short urls will not stop working in one of the next updates. This requires a valid license of the Sharebar Add-On', 'mashsb'), 'https://www.mashshare.net/downloads/sticky-sharebar/?utm_source=insideplugin&utm_medium=userwebsite&utm_content=update_sharebar&utm_campaign=freeplugin') . '</p>';
        echo '</div>';
    }
    // Floating Sidebar add-on notice
    if (mashsb_is_admin_page() && mashsb_incorrect_sidebar_version()) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('Your Floating Sidebar Add-On version is not using new short url mechanism of MashShare 3.X. Please <a href="%s" target="blank"> update the Floating Sidebar Add-On</a> to at least version 1.2.6. if you want to make sure that twitter short urls will not stop working in one of the next updates. This requires a valid license of the Floating Sidebar Add-On', 'mashsb'), 'https://www.mashshare.net/downloads/floating-sidebar/?utm_source=insideplugin&utm_medium=userwebsite&utm_content=update_sharebar&utm_campaign=freeplugin') . '</p>';
        echo '</div>';
    }
    // Check google API key
    if (mashsb_is_admin_page() && (mashsb_check_google_apikey() && isset($mashsb_options['mashsu_methods']) && $mashsb_options['mashsu_methods'] === 'google')) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('Google API key is invalid. Go to <a href="%s"><i>Mashshare->Settings->Short URL Integration</i></a> and check the Google API key.', 'mashsb'), admin_url('admin.php?page=mashsb-settings#mashsb_settingsshorturl_header')) . '</p>';
        echo '</div>';
    }
    // Check Bitly API key
    if (mashsb_is_admin_page() && (false === mashsb_check_bitly_apikey() && isset($mashsb_options['mashsu_methods']) && $mashsb_options['mashsu_methods'] === 'bitly')) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('Bitly Access Token is invalid or bitly.com endpoint can not be reached. Go to <a href="%s"><i>Mashshare->Settings->Short URL Integration</i></a> and check the Bitly API key.', 'mashsb'), admin_url('admin.php?page=mashsb-settings#mashsb_settingsshorturl_header')) . '</p>';
        echo '</div>';
    }
    // Notice MashShare Open Graph Add-On installed and activated
    if (class_exists('MashshareOpenGraph')) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('<strong>Important:</strong> Deactivate the MashShare Open Graph Add-On. It is not longer needed and having it activated leads to duplicate open graph tags on your site. Go to <a href="%s"> Plugin Settings</a> ', 'mashsb'), admin_url('plugins.php')) . '</p>';
        echo '</div>';
    }
    // Notice MashShare ShortURL Add-On installed and activated
    if (class_exists('MashshareShorturls')) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('<strong>Important:</strong> Deactivate the MashShare Shorturls Add-On. It is not longer needed and already built in MashShare. Deactivate it from <a href="%s"> Plugin Settings</a> ', 'mashsb'), admin_url('plugins.php')) . '</p>';
        echo '</div>';
    }
    // Share count is deactivated when permalinks are not used
    if (mashsb_is_admin_page() && !mashsb_is_enabled_permalinks()) {
        echo '<div class="error">';
        echo '<p>' . sprintf(__('<strong>No Share Count aggregation possible!</strong> <a href="%s">Permalinks</a> must be enabled to count shares. Share count is deactivated until you have fixed this.', 'mashsb'), admin_url('options-permalink.php')) . '</p>';
        echo '</div>';
    }
    // Show save notice
    if (isset($_GET['mashsb-message'])) {
        switch ($_GET['mashsb-message']) {
            case 'settings-imported':
                echo '<div class="updated">';
                echo '<p>' . __('The settings have been imported', 'mashsb') . '</p>';
                echo '</div>';
                break;
        }
    }
    // Please rate us
    $install_date = get_option('mashsb_installDate');
    $display_date = date('Y-m-d h:i:s');
    $datetime1 = new DateTime($install_date);
    $datetime2 = new DateTime($display_date);
    $diff_intrval = round(($datetime2->format('U') - $datetime1->format('U')) / (60 * 60 * 24));
    if ($diff_intrval >= 7 && get_option('mashsb_RatingDiv') == "no") {
        echo '<div class="mashsb_fivestar update-nag" style="box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);">
    	<p>Awesome, you\'ve been using <strong>Mashshare Social Sharing Plugin</strong> for more than 1 week. <br> May i ask you to give it a <strong>5-star rating</strong> on Wordpress? </br>
        This will help to spread its popularity and to make this plugin a better one.
        <br><br>Your help is much appreciated. Thank you very much,<br> ~René Hermenau
        <ul>
            <li class="float:left"><a href="https://wordpress.org/support/plugin/mashsharer/reviews/?filter=5#new-post" class="thankyou button button-primary" target="_new" title=Yes, MashShare Increased My Shares" style="color: #ffffff;-webkit-box-shadow: 0 1px 0 #256e34;box-shadow: 0 1px 0 #256e34;font-weight: normal;float:left;margin-right:10px;">I Like MashShare - It Increased My Shares</a></li>
            <li><a href="javascript:void(0);" class="mashsbHideRating button" title="I already did" style="">I already rated it</a></li>
            <li><a href="javascript:void(0);" class="mashsbHideRating" title="No, not good enough" style="">No, not good enough, i do not like to rate it!</a></li>
        </ul>
    </div>
    <script>
    jQuery( document ).ready(function( $ ) {

    jQuery(\'.mashsbHideRating\').click(function(){
        var data={\'action\':\'hideRating\'}
             jQuery.ajax({
        
        url: "' . admin_url('admin-ajax.php') . '",
        type: "post",
        data: data,
        dataType: "json",
        async: !0,
        success: function(e) {
            if (e=="success") {
               jQuery(\'.mashsb_fivestar\').slideUp(\'fast\');
			   
            }
        }
         });
        })
    
    });
    </script>
    ';
    }
    // Disabled since 2.4.7
    //mashsb_update_notices();
}
/**
 * Render the sharecount template
 * 
 * @param string $customurl default empty
 * @param string alignment default left
 * @return string html
 */
function mashsb_render_sharecounts($customurl = '', $align = 'left')
{
    global $mashsb_options;
    if (isset($mashsb_options['disable_sharecount']) || !mashsb_curl_installed() || !mashsb_is_enabled_permalinks()) {
        return;
    }
    $url = empty($customurl) ? mashsb_get_url() : $customurl;
    $sharetitle = isset($mashsb_options['sharecount_title']) ? $mashsb_options['sharecount_title'] : __('SHARES', 'mashsb');
    $shares = getSharedcount($url);
    $sharecount = isset($mashsb_options['mashsharer_round']) ? roundshares($shares) : $shares;
    // do not show shares after x shares
    if (mashsb_hide_shares($shares)) {
        return;
    }
    // Get class names for buttons size
    $class_size = isset($mashsb_options['buttons_size']) ? ' ' . $mashsb_options['buttons_size'] : '';
    $html = '<div class="mashsb-count' . $class_size . '" style="float:' . $align . ';"><div class="counts mashsbcount">' . $sharecount . '</div><span class="mashsb-sharetext">' . $sharetitle . '</span></div>';
    return apply_filters('mashsb_share_count', $html);
}