/** * Load Scripts * * Enqueues the required scripts. * * @since 1.0 * @global $mashsb_options * @global $post * @return void * @param string $hook Page hook */ function mashsb_load_scripts($hook) { global $mashsb_options, $post, $mashsb_sharecount; if (!apply_filters('mashsb_load_scripts', mashsbGetActiveStatus(), $hook)) { mashdebug()->info("mashsb_load_script not active"); return; } $url = mashsb_get_url(); $title = urlencode(html_entity_decode(the_title_attribute('echo=0'), ENT_COMPAT, 'UTF-8')); $title = str_replace('#', '%23', $title); $titleclean = esc_html($title); $image = ""; $desc = ""; if (isset($post->ID)) { $image = mashsb_get_image($post->ID); $desc = mashsb_get_excerpt_by_id($post->ID); } // Rest API Not used any longer //$restapi = mashsb_allow_rest_api() ? "1" : "0"; /* Load hashshags */ $hashtag = !empty($mashsb_options['mashsharer_hashtag']) ? $mashsb_options['mashsharer_hashtag'] : ''; $js_dir = MASHSB_PLUGIN_URL . 'assets/js/'; // Use minified libraries if Mashshare debug mode is turned off $suffix = mashsbIsDebugMode() ? '' : '.min'; isset($mashsb_options['load_scripts_footer']) ? $in_footer = true : ($in_footer = false); wp_enqueue_script('mashsb', $js_dir . 'mashsb' . $suffix . '.js', array('jquery'), MASHSB_VERSION, $in_footer); //wp_enqueue_script( 'element-queries', $js_dir . 'ElementQueries' . '.js', array('jquery'), MASHSB_VERSION, $in_footer ); //wp_enqueue_script( 'resize-sensor', $js_dir . 'ResizeSensor' . '.js', array('jquery'), MASHSB_VERSION, $in_footer ); !isset($mashsb_options['disable_sharecount']) ? $shareresult = getSharedcount($url) : ($shareresult = 0); wp_localize_script('mashsb', 'mashsb', array('shares' => $shareresult, 'round_shares' => isset($mashsb_options['mashsharer_round']), 'animate_shares' => isset($mashsb_options['animate_shares']) && is_singular() ? 1 : 0, 'dynamic_buttons' => isset($mashsb_options['dynamic_button_resize']) ? 1 : 0, 'share_url' => $url, 'title' => $titleclean, 'image' => $image, 'desc' => $desc, 'hashtag' => $hashtag, 'subscribe' => !empty($mashsb_options['subscribe_behavior']) && $mashsb_options['subscribe_behavior'] === 'content' ? 'content' : 'link', 'subscribe_url' => isset($mashsb_options['subscribe_link']) ? $mashsb_options['subscribe_link'] : '', 'activestatus' => mashsbGetActiveStatus(), 'singular' => is_singular() ? 1 : 0, 'twitter_popup' => isset($mashsb_options['twitter_popup']) ? 0 : 1, 'refresh' => mashsb_is_cache_refresh() ? 1 : 0)); }
/** * Load Scripts * * Enqueues the required scripts. * * @since 1.0 * @global $mashsb_options * @global $post * @return void * @param string $hook Page hook */ function mashsb_load_scripts($hook) { global $wp; if (!apply_filters('mashsb_load_scripts', mashsbGetActiveStatus(), $hook)) { mashdebug()->info("mashsb_load_script not active"); return; } global $mashsb_options, $post; $url = get_permalink($post->ID); $title = urlencode(html_entity_decode(the_title_attribute('echo=0'), ENT_COMPAT, 'UTF-8')); $title = str_replace('#', '%23', $title); $titleclean = esc_html($title); $image = mashsb_get_image($post->ID); $desc = mashsb_get_excerpt_by_id($post->ID); /* Load hashshags */ $hashtag = !empty($mashsb_options['mashsharer_hashtag']) ? $mashsb_options['mashsharer_hashtag'] : ''; $js_dir = MASHSB_PLUGIN_URL . 'assets/js/'; // Use minified libraries if SCRIPT_DEBUG is turned off $suffix = mashsbIsDebugMode() ? '' : '.min'; //$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; isset($mashsb_options['load_scripts_footer']) ? $in_footer = true : ($in_footer = false); wp_enqueue_script('mashsb', $js_dir . 'mashsb' . $suffix . '.js', array('jquery'), MASHSB_VERSION, $in_footer); !isset($mashsb_options['disable_sharecount']) ? $shareresult = getSharedcount($url) : ($shareresult = 0); wp_localize_script('mashsb', 'mashsb', array('shares' => $shareresult, 'round_shares' => isset($mashsb_options['mashsharer_round']), 'animate_shares' => isset($mashsb_options['animate_shares']) && is_singular() ? 1 : 0, 'share_url' => $url, 'title' => $titleclean, 'image' => $image, 'desc' => $desc, 'hashtag' => $hashtag, 'subscribe' => !empty($mashsb_options['subscribe_behavior']) && $mashsb_options['subscribe_behavior'] === 'content' ? 'content' : 'link', 'subscribe_url' => isset($mashsb_options['subscribe_link']) ? $mashsb_options['subscribe_link'] : '', 'activestatus' => mashsbGetActiveStatus(), 'singular' => is_singular() ? 1 : 0, 'twitter_popup' => isset($mashsb_options['twitter_popup']) ? 0 : 1)); }
/** * Determines whether the current admin page is an MASHSB admin page. * * Only works after the `wp_loaded` hook, & most effective * starting on `admin_menu` hook. * * @since 1.9.6 * @return bool True if MASHSB admin page. */ function mashsb_is_admin_page() { $currentpage = isset($_GET['page']) ? $_GET['page'] : ''; if (!is_admin() || !did_action('wp_loaded')) { return false; } global $mashsb_parent_page, $pagenow, $typenow, $mashsb_settings_page, $mashsb_add_ons_page, $mashsb_tools_page; if ('mashsb-settings' == $currentpage || 'mashsb-addons' == $currentpage || 'mashsb-tools' == $currentpage) { mashdebug()->info("mashsb_is_admin_page() = true"); return true; } //$mashsb_admin_pages = apply_filters( 'mashsb_admin_pages', array( $mashsb_parent_page, $mashsb_settings_page, $mashsb_add_ons_page, ) ); /*if ( in_array( $currentpage, $mashsb_admin_pages ) ) { mashdebug()->info("mashsb_is_admin_page() = true"); return true; } else { return false; mashdebug()->info("mashsb_is_admin_page() = false"); } * */ }
/** * Get excerpt for Facebook Share * * @since 1.0 * @param int $postID * @return string */ function mashsb_get_excerpt_by_id($post_id) { mashdebug()->timer('mashsb_get_exerpt'); $the_post = get_post($post_id); //Gets post ID $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt $excerpt_length = 35; //Sets excerpt length by word count $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images $words = explode(' ', $the_excerpt, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '…'); $the_excerpt = implode(' ', $words); } $the_excerpt = '<p>' . $the_excerpt . '</p>'; return wp_strip_all_tags($the_excerpt); mashdebug()->timer('mashsb_get_exerpt', true); }
function getCount($data, $url, $request_info, $service, $time) { global $mashsb_error; $count = 0; $error = ''; if ($data) { switch ($service[0]) { // not used any longer. Keep it here for compatibility reasons and return share count case "facebook_likes": $data = json_decode($data, true); $count = isset($data['share']['share_count']) || array_key_exists('share_count', $data) ? $data['share']['share_count'] : 0; if (isset($data['error'])) { // Probably rate limit exceed $this->setRateLimitTransient(); } break; case "facebook_shares": $data = json_decode($data, true); // return assoc array $count = isset($data['share']['share_count']) || array_key_exists('share_count', $data) ? $data['share']['share_count'] : 0; if (isset($data['error'])) { // Probably rate limit exceed $this->setRateLimitTransient(); } break; case "facebook_total": $data = json_decode($data, true); $share_count = isset($data['share']['share_count']) || array_key_exists('share_count', $data) ? $data['share']['share_count'] : 0; $comment_count = isset($data['share']['comment_count']) || array_key_exists('comment_count', $data) ? $data['share']['comment_count'] : 0; $count = $share_count + $comment_count; if (isset($data['error'])) { // Probably rate limit exceed $error = array('facebook_error' => $data['error']); $this->setRateLimitTransient(); } break; case "google": //preg_match( '/window\.__SSR = {c: ([\d]+)TEST/', $data, $matches ); preg_match("#window\\.__SSR = {c: ([\\d]+)#", $data, $matches); if (isset($matches[0])) { $count = str_replace('window.__SSR = {c: ', '', $matches[0]); } break; case "pinterest": $data = substr($data, 13, -1); case "linkedin": case "twitter": $data = json_decode($data); $count = isset($data->count) ? $data->count : 0; break; case "stumbleupon": $data = json_decode($data); isset($data->result->views) ? $count = $data->result->views : ($count = 0); break; case "delicious": $data = json_decode($data); $count = !empty($data) ? $data[0]->total_posts : 0; break; case "reddit": $data = json_decode($data); $ups = 0; $downs = 0; foreach ($data->data->children as $child) { $ups += (int) $child->data->ups; $downs += (int) $child->data->downs; } $count = $ups - $downs; break; case "buffer": $data = json_decode($data); $count = !empty($data) ? $data->shares : 0; //$count = $data->shares; break; case "vk": $data = preg_match('/^VK.Share.count\\(\\d+,\\s+(\\d+)\\);$/i', $data, $matches); $count = $matches[1]; break; default: // nothing here } $count = (int) $count; /* $this->data->shares->total += $count; $this->data->shares->$service[0] = $count; * */ $this->data->error = $error; $this->data->total += $count; $this->data->{$service[0]} = $count; MASHSB()->logger->info('MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count); mashdebug()->info('MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count); //echo 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count . '<br>'; $this->debug_notices[] = 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count . '<br>'; $mashsb_error[] = 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count; add_action('wp_footer', array($this, 'outputDebug'), 100); } return; }
function get_sharedcount() { mashdebug()->info("Share URL: " . $this->url); global $mashsb_options; if (empty($mashsb_options['mashsharer_apikey'])) { return 0; //quit early if there's no API key. } $apikey = trim($mashsb_options['mashsharer_apikey']); $domain = trim($mashsb_options['mashsharer_sharecount_domain']); if (!isset($domain) || empty($domain)) { $domain = "free.sharedcount.com"; $this->update_sharedcount_domain($apikey, $domain); } try { $counts = $this->_curl('http://' . $domain . "/?url=" . $this->url . "&apikey=" . $apikey); if (isset($counts["Error"]) && isset($counts['Domain']) && $counts["Type"] === "domain_apikey_mismatch") { $this->update_sharedcount_domain($apikey, $counts['Domain']); return 0; } else { if (isset($counts["Error"]) && isset($counts['Type']) && $counts['Type'] === 'invalid_api_key') { $this->update_sharedcount_domain($apikey); return 0; } } mashdebug()->info("Twitter count: " . isset($counts['Twitter'])); MASHSB()->logger->info("URL: " . urldecode($this->url) . " API Key:" . $apikey . " sharedcount.com FB total_count: " . $counts['Facebook']['total_count'] . " FB share_count:" . $counts['Facebook']['share_count'] . " TW: " . $counts['Twitter'] . " G+:" . $counts['GooglePlusOne'] . " Linkedin:" . $counts['LinkedIn'] . " Stumble: " . $counts['StumbleUpon'] . " Pinterest: " . $counts['Pinterest']); return $counts; } catch (Exception $e) { mashdebug()->error("error: " . $counts); MASHSB()->logger->info('ERROR: Curl()' . $counts); return 0; } mashdebug()->error("error2: " . $counts); MASHSB()->logger->info('ERROR 2: Curl()' . $counts); return 0; }
/** * Check if buttons are excluded from a specific post id * * @return true if post is excluded */ function mashsb_is_excluded() { global $post, $mashsb_options; if (!isset($post)) { return false; } $excluded = isset($mashsb_options['excluded_from']) ? $mashsb_options['excluded_from'] : null; // Load scripts when page is not excluded if (strpos($excluded, ',') !== false) { $excluded = explode(',', $excluded); if (in_array($post->ID, $excluded)) { mashdebug()->info("is excluded"); return true; } } if ($post->ID == $excluded) { mashdebug()->info("is single excluded"); return true; } return false; }