on( 'google_page' ); if ( ! preg_match( '/^(\d{20,22})$/', $page ) ) { $page = '+' . $page; } return array( 'link' => 'https://plus.google.com/' . $page, 'title' => Better_Social_Counter::get_option( 'google_title' ), 'title_join' => Better_Social_Counter::get_option( 'google_title_join' ), 'name' => Better_Social_Counter::get_option( 'google_name' ), ); } /** * Used for retrieving data for Youtube * * @param string $user_name * * @return bool|mixed */ private function get_youtube_full_data( $id = 'youtube' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $user_name = Better_Social_Counter::get_option( 'youtube_username' ); $subscriber = 0; $type = ''; $request = BetterFramework_Oculus::request( 'get-youtube-subscriber', array( 'data' => array( 'id' => $user_name ), 'group' => 'social-counter', 'use_wp_error' => FALSE ) ); if ( isset( $request->subscriber ) ) { $subscriber = &$request->subscriber; } if ( isset( $request->type ) ) { $type = &$request->type; } // Final result $final_result = array( 'link' => '#', 'count' => $this->format_number( $subscriber ), 'title' => Better_Social_Counter::get_option( 'youtube_title' ), 'title_join' => Better_Social_Counter::get_option( 'youtube_title_join' ), 'button' => Better_Social_Counter::get_option( 'youtube_button' ), 'name' => Better_Social_Counter::get_option( 'youtube_name' ) ); if ( $type == 'channel' ) { $final_result['link'] = 'https://youtube.com/channel/' . $user_name; } elseif ( $type == 'user' ) { $final_result['link'] = 'https://youtube.com/user/' . $user_name; } $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Youtube * * @param string $id * * @return array|bool */ private function get_youtube_short_data( $id = 'youtube' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return $this->get_youtube_full_data( $id ); } /** * Used for retrieving data for Dribbble * * @param string $id * * @return bool|mixed */ private function get_dribbble_full_data( $id = 'dribbble' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $username = Better_Social_Counter::get_option( 'dribbble_username' ); $followers_count = 0; $request = BetterFramework_Oculus::request( 'get-dribbble-followers-count', array( 'data' => compact( 'username' ), 'group' => 'social-counter', 'use_wp_error' => FALSE ) ); if ( isset( $request->followers_count ) ) { $followers_count = &$request->followers_count; } // Final result $final_result = array( 'link' => 'https://dribbble.com/' . $username, 'count' => $this->format_number( $followers_count ), 'title' => Better_Social_Counter::get_option( 'dribbble_title' ), 'title_join' => Better_Social_Counter::get_option( 'dribbble_title_join' ), 'button' => Better_Social_Counter::get_option( 'dribbble_button' ), 'name' => Better_Social_Counter::get_option( 'dribbble_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Dribbble * * @param string $id * * @return array|bool */ private function get_dribbble_short_data( $id = 'dribbble' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => 'https://dribbble.com/' . Better_Social_Counter::get_option( 'dribbble_username' ), 'title' => Better_Social_Counter::get_option( 'dribbble_title' ), 'title_join' => Better_Social_Counter::get_option( 'dribbble_title_join' ), 'name' => Better_Social_Counter::get_option( 'dribbble_name' ), ); } /** * Used for retrieving data for Vimeo * * @param string $id * * @return bool|mixed */ private function get_vimeo_full_data( $id = 'vimeo' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $vimeo_type = Better_Social_Counter::get_option( 'vimeo_type' ); $data = array(); if ( $vimeo_type === 'user' ) { $data['username'] = Better_Social_Counter::get_option( 'vimeo_username' ); } else { $data['channel'] = Better_Social_Counter::get_option( 'vimeo_username' ); } $data['field'] = Better_Social_Counter::get_option( 'vimeo_data' ); $request = BetterFramework_Oculus::request( 'get-vimeo-info', array( 'data' => $data, 'group' => 'social-counter', 'use_wp_error' => FALSE ) ); if ( isset( $request->total ) ) { $count = $request->total; } else { $count = 0; } $link = 'https://vimeo.com/'; if ( $vimeo_type == 'channel' ) { $link .= 'channels/' . $data['channel']; } else { $link .= $data['username']; } // Final result $final_result = array( 'link' => $link, 'count' => $this->format_number( $count ), 'title' => Better_Social_Counter::get_option( 'vimeo_title' ), 'title_join' => Better_Social_Counter::get_option( 'vimeo_title_join' ), 'button' => Better_Social_Counter::get_option( 'vimeo_button' ), 'name' => Better_Social_Counter::get_option( 'vimeo_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Vimeo * * @param string $id * * @return array */ private function get_vimeo_short_data( $id = 'vimeo' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } $vimeo_username = Better_Social_Counter::get_option( 'vimeo_username' ); $vimeo_type = Better_Social_Counter::get_option( 'vimeo_type' ); $link = 'https://vimeo.com/'; if ( $vimeo_type == 'channel' ) { $link .= 'channels/' . $vimeo_username; } else { $link .= $vimeo_username; } return array( 'link' => $link, 'title' => Better_Social_Counter::get_option( 'vimeo_title' ), 'title_join' => Better_Social_Counter::get_option( 'vimeo_title_join' ), 'name' => Better_Social_Counter::get_option( 'vimeo_name' ), ); } /** * Used for retrieving data for Delicious * * @param string $id * * @return bool|mixed */ private function get_delicious_full_data( $id = 'delicious' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $delicious_username = Better_Social_Counter::get_option( 'delicious_username' ); try { $data = $this->remote_get( "http://feeds.del.icio.us/v2/json/userinfo/" . $delicious_username ); $result = (int) $data[2]['n']; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://del.icio.us/" . $delicious_username, 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'delicious_title' ), 'title_join' => Better_Social_Counter::get_option( 'delicious_title_join' ), 'button' => Better_Social_Counter::get_option( 'delicious_button' ), 'name' => Better_Social_Counter::get_option( 'delicious_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Delicious * * @param string $id * * @return array|bool */ private function get_delicious_short_data( $id = 'delicious' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://del.icio.us/" . Better_Social_Counter::get_option( 'delicious_username' ), 'title' => Better_Social_Counter::get_option( 'delicious_title' ), 'title_join' => Better_Social_Counter::get_option( 'delicious_title_join' ), 'name' => Better_Social_Counter::get_option( 'delicious_name' ), ); } /** * Used for retrieving data for SoundCloud * * @param string $id * * @return bool|mixed */ private function get_soundcloud_full_data( $id = 'soundcloud' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $soundcloud_username = Better_Social_Counter::get_option( 'soundcloud_username' ); try { $data = $this->remote_get( "http://api.soundcloud.com/users/" . $soundcloud_username . ".json?consumer_key=" . Better_Social_Counter::get_option( 'soundcloud_api_key' ) ); $result = (int) $data['followers_count']; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://soundcloud.com/" . $soundcloud_username, 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'soundcloud_title' ), 'title_join' => Better_Social_Counter::get_option( 'soundcloud_title_join' ), 'button' => Better_Social_Counter::get_option( 'soundcloud_button' ), 'name' => Better_Social_Counter::get_option( 'soundcloud_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for SoundCloud * * @param string $id * * @return array|bool */ private function get_soundcloud_short_data( $id = 'soundcloud' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://soundcloud.com/" . Better_Social_Counter::get_option( 'soundcloud_username' ), 'title' => Better_Social_Counter::get_option( 'soundcloud_title' ), 'title_join' => Better_Social_Counter::get_option( 'soundcloud_title_join' ), 'name' => Better_Social_Counter::get_option( 'soundcloud_name' ), ); } /** * Used for retrieving data for Github * TODO: add git hub repositories count * * @param string $id * * @return bool|mixed */ private function get_github_full_data( $id = 'github' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $github_username = Better_Social_Counter::get_option( 'github_username' ); try { $data = $this->remote_get( "https://api.github.com/users/" . $github_username ); $result = (int) $data['followers']; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://github.com/" . $github_username, 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'github_title' ), 'title_join' => Better_Social_Counter::get_option( 'github_title_join' ), 'button' => Better_Social_Counter::get_option( 'github_button' ), 'name' => Better_Social_Counter::get_option( 'github_name' ) ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Github * TODO: add git hub repositories count * * @param string $id * * @return array|bool */ private function get_github_short_data( $id = 'github' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://github.com/" . Better_Social_Counter::get_option( 'github_username' ), 'title' => Better_Social_Counter::get_option( 'github_title' ), 'title_join' => Better_Social_Counter::get_option( 'github_title_join' ), 'name' => Better_Social_Counter::get_option( 'github_name' ) ); } /** * Used for retrieving data for behance * * @param string $id * * @return bool|mixed */ private function get_behance_full_data( $id = 'behance' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $username = Better_Social_Counter::get_option( 'behance_username' ); $followers_count = 0; $request = BetterFramework_Oculus::request( 'get-behance-followers-count', array( 'data' => compact( 'username' ), 'group' => 'social-counter', 'use_wp_error' => FALSE ) ); if ( isset( $request->followers_count ) ) { $followers_count = &$request->followers_count; } // Final result $final_result = array( 'link' => "https://www.behance.net/" . $username, 'count' => $this->format_number( $followers_count ), 'title' => Better_Social_Counter::get_option( 'behance_title' ), 'title_join' => Better_Social_Counter::get_option( 'behance_title_join' ), 'button' => Better_Social_Counter::get_option( 'behance_button' ), 'name' => Better_Social_Counter::get_option( 'behance_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for behance * * @param string $id * * @return array|bool */ private function get_behance_short_data( $id = 'behance' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://www.behance.net/" . Better_Social_Counter::get_option( 'behance_username' ), 'title' => Better_Social_Counter::get_option( 'behance_title' ), 'title_join' => Better_Social_Counter::get_option( 'behance_title_join' ), 'name' => Better_Social_Counter::get_option( 'behance_name' ), ); } /** * Used for retrieving data for VK * * @param string $id * * @return bool|mixed */ private function get_vk_full_data( $id = 'vk' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $vk_username = Better_Social_Counter::get_option( 'vk_username' ); try { $data = $this->remote_get( "http://api.vk.com/method/groups.getById?gid=" . $vk_username . "&fields=members_count" ); $result = (int) $data['response'][0]['members_count']; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://vk.com/" . $vk_username, 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'vk_title' ), 'title_join' => Better_Social_Counter::get_option( 'vk_title_join' ), 'button' => Better_Social_Counter::get_option( 'vk_button' ), 'name' => Better_Social_Counter::get_option( 'vk_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for VK * * @param string $id * * @return array|bool */ private function get_vk_short_data( $id = 'vk' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://vk.com/" . Better_Social_Counter::get_option( 'vk_username' ), 'title' => Better_Social_Counter::get_option( 'vk_title' ), 'title_join' => Better_Social_Counter::get_option( 'vk_title_join' ), 'name' => Better_Social_Counter::get_option( 'vk_name' ), ); } /** * Used for retrieving data for Vine * * @param string $id * * @return bool|mixed */ private function get_vine_full_data( $id = 'vine' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } try { if ( ! class_exists( 'BSC_Vine' ) ) { require_once Better_Social_Counter()->dir_path() . 'includes/libs/class-bsc-vine.php'; } $vine = new BF_Vine( Better_Social_Counter::get_option( 'vine_email' ), Better_Social_Counter::get_option( 'vine_pass' ) ); $result = $vine->me(); $result = $result['followerCount']; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://vine.com/" . Better_Social_Counter::get_option( 'vine_profile' ), 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'vine_title' ), 'title_join' => Better_Social_Counter::get_option( 'vine_title_join' ), 'button' => Better_Social_Counter::get_option( 'vine_button' ), 'name' => Better_Social_Counter::get_option( 'vine_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Vine * * @param string $id * * @return array|bool */ private function get_vine_short_data( $id = 'vine' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "http://vine.com/" . Better_Social_Counter::get_option( 'vine_profile' ), 'title' => Better_Social_Counter::get_option( 'vine_title' ), 'title_join' => Better_Social_Counter::get_option( 'vine_title_join' ), 'name' => Better_Social_Counter::get_option( 'vine_name' ), ); } /** * Used for retrieving data for Pinterest * * @param string $id * * @return bool|mixed */ private function get_pinterest_full_data( $id = 'pinterest' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $pinterest_username = Better_Social_Counter::get_option( 'pinterest_username' ); try { $prev = libxml_use_internal_errors( TRUE ); $html = $this->remote_get( "http://www.pinterest.com/" . $pinterest_username, FALSE ); if ( class_exists( 'DOMDocument' ) && $html ) { $doc = new DOMDocument(); @$doc->loadHTML( $html ); libxml_use_internal_errors( $prev ); $metas = $doc->getElementsByTagName( 'meta' ); for ( $i = 0; $i < $metas->length; $i ++ ) { $meta = $metas->item( $i ); if ( $meta->getAttribute( 'name' ) == 'pinterestapp:followers' ) { $result = $meta->getAttribute( 'content' ); break; } } } else { $result = 0; } } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://www.pinterest.com/" . $pinterest_username, 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'pinterest_title' ), 'title_join' => Better_Social_Counter::get_option( 'pinterest_title_join' ), 'button' => Better_Social_Counter::get_option( 'pinterest_button' ), 'name' => Better_Social_Counter::get_option( 'pinterest_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Pinterest * * @param string $id * * @return array|bool */ private function get_pinterest_short_data( $id = 'pinterest' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://www.pinterest.com/" . Better_Social_Counter::get_option( 'pinterest_username' ), 'title' => Better_Social_Counter::get_option( 'pinterest_title' ), 'title_join' => Better_Social_Counter::get_option( 'pinterest_title_join' ), 'name' => Better_Social_Counter::get_option( 'pinterest_name' ), ); } /** * Used for retrieving data for Flickr * * @param string $id * * @return bool|mixed */ private function get_flickr_full_data( $id = 'flickr' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $group_slug = Better_Social_Counter::get_option( 'flickr_group' ); $members = 0; $request = BetterFramework_Oculus::request( 'get-flickr-group-members', array( 'data' => compact( 'group_slug' ), 'group' => 'social-counter', 'use_wp_error' => FALSE ) ); if ( isset( $request->group_members ) ) { $members = &$request->group_members; } // final result $final_result = array( 'link' => "https://www.flickr.com/groups/$group_slug", 'count' => $this->format_number( $members ), 'title' => Better_Social_Counter::get_option( 'flickr_title' ), 'title_join' => Better_Social_Counter::get_option( 'flickr_title_join' ), 'button' => Better_Social_Counter::get_option( 'flickr_button' ), 'name' => Better_Social_Counter::get_option( 'flickr_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Flickr * * @param string $id * * @return array|bool */ private function get_flickr_short_data( $id = 'flickr' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://www.flickr.com/groups/" . Better_Social_Counter::get_option( 'flickr_group' ), 'title' => Better_Social_Counter::get_option( 'flickr_title' ), 'title_join' => Better_Social_Counter::get_option( 'flickr_title_join' ), 'name' => Better_Social_Counter::get_option( 'flickr_name' ), ); } /** * Used for retrieving data for Steam * * @param string $id * * @return bool|mixed */ private function get_steam_full_data( $id = 'steam' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $steam_group = Better_Social_Counter::get_option( 'steam_group' ); try { $prev = libxml_use_internal_errors( TRUE ); $data = $this->remote_get( "http://steamcommunity.com/groups/$steam_group/memberslistxml", FALSE ); if ( class_exists( 'SimpleXmlElement' ) ) { $data = @new SimpleXmlElement( $data ); $result = (int) $data->groupDetails->memberCount; } else { $result = 0; } libxml_use_internal_errors( $prev ); libxml_clear_errors(); } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://steamcommunity.com/groups/$steam_group", 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'steam_title' ), 'title_join' => Better_Social_Counter::get_option( 'steam_title_join' ), 'button' => Better_Social_Counter::get_option( 'steam_button' ), 'name' => Better_Social_Counter::get_option( 'steam_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Steam * * @param string $id * * @return array|bool */ private function get_steam_short_data( $id = 'steam' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://steamcommunity.com/groups/" . Better_Social_Counter::get_option( 'steam_group' ), 'title' => Better_Social_Counter::get_option( 'steam_title' ), 'title_join' => Better_Social_Counter::get_option( 'steam_title_join' ), 'name' => Better_Social_Counter::get_option( 'steam_name' ), ); } /** * Used for retrieving data for Instagram * * @param string $id * * @return bool|mixed */ private function get_instagram_full_data( $id = 'instagram' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $instagram_username = Better_Social_Counter::get_option( 'instagram_username' ); try { $data = $this->remote_get( "http://instagram.com/{$instagram_username}#", FALSE ); $pattern = "/\"followed_by\":[ ]*{\"count\":(.*?)}/"; preg_match( $pattern, $data, $matches ); if ( ! empty( $matches[1] ) ) { $result = (int) $matches[1]; } else { $result = 0; } } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // Final result $final_result = array( 'link' => "https://instagram.com/$instagram_username", 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'instagram_title' ), 'title_join' => Better_Social_Counter::get_option( 'instagram_title_join' ), 'button' => Better_Social_Counter::get_option( 'instagram_button' ), 'name' => Better_Social_Counter::get_option( 'instagram_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Instagram * * @param string $id * * @return array|bool */ private function get_instagram_short_data( $id = 'instagram' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://instagram.com/" . Better_Social_Counter::get_option( 'instagram_username' ), 'title' => Better_Social_Counter::get_option( 'instagram_title' ), 'title_join' => Better_Social_Counter::get_option( 'instagram_title_join' ), 'name' => Better_Social_Counter::get_option( 'instagram_name' ), ); } /** * Used for retrieving data for Forrst * * @param string $id * * @return bool|mixed */ private function get_forrst_full_data( $id = 'forrst' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $forrst_username = Better_Social_Counter::get_option( 'forrst_username' ); try { $data = $this->remote_get( "http://forrst.com/api/v2/users/info?username=" . $forrst_username ); $result = (int) $data['resp']['typecast_followers']; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // final result $final_result = array( 'link' => "https://zurb.com/forrst/people/" . $forrst_username, 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'forrst_title' ), 'title_join' => Better_Social_Counter::get_option( 'forrst_title_join' ), 'button' => Better_Social_Counter::get_option( 'forrst_button' ), 'name' => Better_Social_Counter::get_option( 'forrst_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Forrst * * @param string $id * * @return array|bool */ private function get_forrst_short_data( $id = 'forrst' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => "https://zurb.com/forrst/people/" . Better_Social_Counter::get_option( 'forrst_username' ), 'title' => Better_Social_Counter::get_option( 'forrst_title' ), 'title_join' => Better_Social_Counter::get_option( 'forrst_title_join' ), 'name' => Better_Social_Counter::get_option( 'forrst_name' ), ); } /** * Used for retrieving data for Mailchimp * * @param string $id * * @return bool|mixed */ private function get_mailchimp_full_data( $id = 'mailchimp' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } try { // Mail chimp API wrapper require_once Better_Social_Counter()->dir_path() . 'includes/libs/mailchimp/class-mcapi.php'; $mc_list_id = Better_Social_Counter::get_option( 'mailchimp_list_id' ); $mc_api_key = Better_Social_Counter::get_option( 'mailchimp_api_key' ); $mc_api = new MCAPI( $mc_api_key ); $lists = $mc_api->lists(); $result = 0; if ( isset( $lists['data'] ) ) { foreach ( (array) $lists['data'] as $list ) { if ( $list['id'] == $mc_list_id ) { $result = $list['stats']['member_count']; break; } } } } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // final result $final_result = array( 'link' => Better_Social_Counter::get_option( 'mailchimp_list_url' ), 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'mailchimp_title' ), 'title_join' => Better_Social_Counter::get_option( 'mailchimp_title_join' ), 'button' => Better_Social_Counter::get_option( 'mailchimp_button' ), 'name' => Better_Social_Counter::get_option( 'mailchimp_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Mailchimp * * @param string $id * * @return array|bool */ private function get_mailchimp_short_data( $id = 'mailchimp' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'link' => Better_Social_Counter::get_option( 'mailchimp_list_url' ), 'title' => Better_Social_Counter::get_option( 'mailchimp_title' ), 'title_join' => Better_Social_Counter::get_option( 'mailchimp_title_join' ), 'name' => Better_Social_Counter::get_option( 'mailchimp_name' ), ); } /** * Used for retrieving data for Envato * * @param string $id * * @return bool|mixed */ private function get_envato_full_data( $id = 'envato' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $envato_username = Better_Social_Counter()->get_option( 'envato_username' ); $envato_marketplace = Better_Social_Counter()->get_option( 'envato_marketplace' ); if ( empty( $envato_marketplace ) ) { $envato_marketplace = 'themeforest'; } try { $data = $this->remote_get( "http://marketplace.envato.com/api/edge/user:$envato_username.json" ); if ( isset( $data['user']['followers'] ) ) { $result = (int) $data['user']['followers']; } } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // final result $final_result = array( 'link' => 'https://' . $envato_marketplace . '.net/user/' . $envato_username . '?ref=' . $envato_username, 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'envato_title' ), 'title_join' => Better_Social_Counter::get_option( 'envato_title_join' ), 'button' => Better_Social_Counter::get_option( 'envato_button' ), 'name' => Better_Social_Counter::get_option( 'envato_' . $envato_marketplace . '_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving data for Envato * * @param string $id * * @return array|bool */ private function get_envato_short_data( $id = 'envato' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } $envato_username = Better_Social_Counter()->get_option( 'envato_username' ); $envato_marketplace = Better_Social_Counter()->get_option( 'envato_marketplace' ); if ( empty( $envato_marketplace ) ) { $envato_marketplace = 'themeforest'; } $final_result = array( 'link' => 'https://' . $envato_marketplace . '.net/user/' . $envato_username . '?ref=' . $envato_username, 'title' => Better_Social_Counter::get_option( 'envato_title' ), 'title_join' => Better_Social_Counter::get_option( 'envato_title_join' ), 'name' => Better_Social_Counter::get_option( 'envato_' . $envato_marketplace . '_name' ), ); return $final_result; } /** * Used for retrieving posts data * * @param string $id * * @return bool|mixed */ private function get_posts_full_data( $id = 'posts' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } try { $count_posts = wp_count_posts(); $result = $count_posts->publish; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // final result $final_result = array( 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'posts_title' ), 'title_join' => Better_Social_Counter::get_option( 'posts_title_join' ), 'name' => Better_Social_Counter::get_option( 'posts_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving posts data * * @param string $id * * @return array|bool */ private function get_posts_short_data( $id = 'posts' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'title' => Better_Social_Counter::get_option( 'posts_title' ), 'title_join' => Better_Social_Counter::get_option( 'posts_title_join' ), 'name' => Better_Social_Counter::get_option( 'posts_name' ), ); } /** * Used for retrieving comments data * * @param string $id * * @return bool|mixed */ private function get_comments_full_data( $id = 'comments' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } try { $comments_count = wp_count_comments(); $result = $comments_count->approved; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // final result $final_result = array( 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'comments_title' ), 'title_join' => Better_Social_Counter::get_option( 'comments_title_join' ), 'name' => Better_Social_Counter::get_option( 'comments_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving comments data * * @param string $id * * @return array|bool */ private function get_comments_short_data( $id = 'comments' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'title' => Better_Social_Counter::get_option( 'comments_title' ), 'title_join' => Better_Social_Counter::get_option( 'comments_title_join' ), 'name' => Better_Social_Counter::get_option( 'comments_name' ), ); } /** * Used for retrieving members data * * @param string $id * * @return bool|mixed */ private function get_members_full_data( $id = 'members' ) { if ( ! $this->is_active( $id ) ) { return FALSE; } if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } try { $members_count = count_users(); $result = $members_count['total_users']; } catch( Exception $e ) { $result = 0; } if ( ! isset( $result ) ) { $result = 0; } // final result $final_result = array( 'count' => $this->format_number( $result ), 'title' => Better_Social_Counter::get_option( 'members_title' ), 'title_join' => Better_Social_Counter::get_option( 'members_title_join' ), 'name' => Better_Social_Counter::get_option( 'members_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving members data * * @param string $id * * @return array|bool */ private function get_members_short_data( $id = 'members' ) { if ( ! $this->is_min_active( $id ) ) { return FALSE; } return array( 'title' => Better_Social_Counter::get_option( 'members_title' ), 'title_join' => Better_Social_Counter::get_option( 'members_title_join' ), 'name' => Better_Social_Counter::get_option( 'members_name' ), ); } /** * Used for retrieving RSS data * * @param string $id * * @return bool|mixed */ private function get_rss_full_data( $id = 'rss' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $type = Better_Social_Counter::get_option( 'rss_type' ); $link = ''; if ( $type === 'custom_link' ) { $link = Better_Social_Counter::get_option( 'rss_type_custom' ); } elseif ( $type === 'category' ) { if ( $cat = Better_Social_Counter::get_option( 'rss_type_category' ) ) { $link = get_category_feed_link( $cat ); } } if ( empty( $link ) ) { $link = get_bloginfo( 'rss_url' ); } // final result $final_result = array( 'link' => $link, 'count' => 'RSS', 'title' => Better_Social_Counter::get_option( 'rss_title' ), 'title_join' => Better_Social_Counter::get_option( 'rss_title_join' ), 'button' => Better_Social_Counter::get_option( 'rss_button' ), 'name' => Better_Social_Counter::get_option( 'rss_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving RSS data * * @param string $id * * @return array|bool */ private function get_rss_short_data( $id = 'rss' ) { return $this->get_rss_full_data( $id ); } /** * Used for retrieving Telegram data * * @param string $id * * @return bool|mixed */ private function get_telegram_full_data( $id = 'telegram' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'telegram_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'telegram_title' ), 'title_join' => Better_Social_Counter::get_option( 'telegram_title_join' ), 'button' => Better_Social_Counter::get_option( 'telegram_button' ), 'name' => Better_Social_Counter::get_option( 'telegram_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving Telegram data * * @param string $id * * @return array|bool */ private function get_telegram_short_data( $id = 'telegram' ) { return $this->get_telegram_full_data( $id ); } /** * Used for retrieving linkedin data * * @param string $id * * @return bool|mixed */ private function get_linkedin_full_data( $id = 'linkedin' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'linkedin_link' ); if ( Better_Social_Counter::get_option( 'linkedin_title' ) ) { $count = Better_Social_Counter::get_option( 'linkedin_title' ); $title = Better_Social_Counter::get_option( 'linkedin_name' ); $button = Better_Social_Counter::get_option( 'linkedin_title_join' ); } else { $count = ''; $title = Better_Social_Counter::get_option( 'linkedin_name' ); $button = Better_Social_Counter::get_option( 'linkedin_title_join' ); } // final result $final_result = array( 'link' => $link, 'count' => $count, 'title' => $title, 'title_join' => Better_Social_Counter::get_option( 'linkedin_title_join' ), 'button' => $button, 'name' => Better_Social_Counter::get_option( 'linkedin_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving linkedin data * * @param string $id * * @return array|bool */ private function get_linkedin_short_data( $id = 'linkedin' ) { return $this->get_linkedin_full_data( $id ); } /** * Used for retrieving tumblr data * * @param string $id * * @return bool|mixed */ private function get_tumblr_full_data( $id = 'tumblr' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'tumblr_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'tumblr_title' ), 'title_join' => Better_Social_Counter::get_option( 'tumblr_title_join' ), 'button' => Better_Social_Counter::get_option( 'tumblr_button' ), 'name' => Better_Social_Counter::get_option( 'tumblr_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving tumblr data * * @param string $id * * @return array|bool */ private function get_tumblr_short_data( $id = 'tumblr' ) { return $this->get_tumblr_full_data( $id ); } /** * Used for retrieving ok.ru data * * @param string $id * * @return bool|mixed */ private function get_ok_ru_full_data( $id = 'ok_ru' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'ok_ru_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'ok_ru_title' ), 'title_join' => Better_Social_Counter::get_option( 'ok_ru_title_join' ), 'button' => Better_Social_Counter::get_option( 'ok_ru_button' ), 'name' => Better_Social_Counter::get_option( 'ok_ru_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving ok.ru data * * @param string $id * * @return array|bool */ private function get_ok_ru_short_data( $id = 'ok_ru' ) { return $this->get_ok_ru_full_data( $id ); } /** * Used for retrieving Line data * * @param string $id * * @return bool|mixed */ private function get_line_full_data( $id = 'line' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'line_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'line_title' ), 'title_join' => Better_Social_Counter::get_option( 'line_title_join' ), 'button' => Better_Social_Counter::get_option( 'line_button' ), 'name' => Better_Social_Counter::get_option( 'line_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving Line data * * @param string $id * * @return array|bool */ private function get_line_short_data( $id = 'line' ) { return $this->get_line_full_data( $id ); } /** * Used for retrieving Viber data * * @param string $id * * @return bool|mixed */ private function get_viber_full_data( $id = 'viber' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'viber_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'viber_title' ), 'title_join' => Better_Social_Counter::get_option( 'viber_title_join' ), 'button' => Better_Social_Counter::get_option( 'viber_button' ), 'name' => Better_Social_Counter::get_option( 'viber_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving Viber data * * @param string $id * * @return array|bool */ private function get_viber_short_data( $id = 'viber' ) { return $this->get_viber_full_data( $id ); } /** * Used for retrieving snapchat data * * @param string $id * * @return bool|mixed */ private function get_snapchat_full_data( $id = 'snapchat' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'snapchat_link' ); if ( Better_Social_Counter::get_option( 'snapchat_title' ) ) { $count = Better_Social_Counter::get_option( 'snapchat_title' ); $title = Better_Social_Counter::get_option( 'snapchat_name' ); $button = Better_Social_Counter::get_option( 'snapchat_title_join' ); } else { $count = ''; $title = Better_Social_Counter::get_option( 'snapchat_name' ); $button = Better_Social_Counter::get_option( 'snapchat_title_join' ); } // final result $final_result = array( 'link' => $link, 'count' => $count, 'title' => $title, 'title_join' => Better_Social_Counter::get_option( 'snapchat_title_join' ), 'button' => $button, 'name' => Better_Social_Counter::get_option( 'snapchat_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving snapchat data * * @param string $id * * @return array|bool */ private function get_snapchat_short_data( $id = 'snapchat' ) { return $this->get_snapchat_full_data( $id ); } /** * Used for retrieving BlackBerry data * * @param string $id * * @return bool|mixed */ private function get_bbm_full_data( $id = 'bbm' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'bbm_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'bbm_title' ), 'title_join' => Better_Social_Counter::get_option( 'bbm_title_join' ), 'button' => Better_Social_Counter::get_option( 'bbm_button' ), 'name' => Better_Social_Counter::get_option( 'bbm_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving BlackBerry data * * @param string $id * * @return array|bool */ private function get_bbm_short_data( $id = 'bbm' ) { return $this->get_bbm_full_data( $id ); } /** * Used for retrieving AppStore data * * @param string $id * * @return bool|mixed */ private function get_appstore_full_data( $id = 'appstore' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'appstore_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'appstore_title' ), 'title_join' => Better_Social_Counter::get_option( 'appstore_title_join' ), 'button' => Better_Social_Counter::get_option( 'appstore_button' ), 'name' => Better_Social_Counter::get_option( 'appstore_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving AppStore data * * @param string $id * * @return array|bool */ private function get_appstore_short_data( $id = 'appstore' ) { return $this->get_appstore_full_data( $id ); } /** * Used for retrieving Google Play data * * @param string $id * * @return bool|mixed */ private function get_android_full_data( $id = 'android' ) { if ( ( $cached = $this->get_transient( $id ) ) !== FALSE ) { return $cached; } $link = Better_Social_Counter::get_option( 'android_link' ); // final result $final_result = array( 'link' => $link, 'count' => '', 'title' => Better_Social_Counter::get_option( 'android_title' ), 'title_join' => Better_Social_Counter::get_option( 'android_title_join' ), 'button' => Better_Social_Counter::get_option( 'android_button' ), 'name' => Better_Social_Counter::get_option( 'android_name' ), ); $this->set_transient( $id, $final_result ); return $final_result; } /** * Used for retrieving Google Play data * * @param string $id * * @return array|bool */ private function get_android_short_data( $id = 'android' ) { return $this->get_android_full_data( $id ); } } CIDISS - Part 292