コード例 #1
0
ファイル: company.php プロジェクト: rgummadi/ScriptOverflow
              <input type="submit" value="Revoke Authorization" />
            </form>
            
            <hr />
      
            <h2 id="company">Company API:</h2>
            
            <hr />
            
            <h3 id="companySpecific">Specific Company:</h3>

            <p>All about LinkedIn via the Company API:</p>
            
            <?php 
                $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML);
                $response = $OBJ_linkedin->company('1337:(id,name,ticker,description,logo-url,locations:(address,is-headquarters))');
                if ($response['success'] === TRUE) {
                    $company = new SimpleXMLElement($response['linkedin']);
                    ?>
              <div style=""><span style="font-weight: bold;"><?php 
                    echo $company->name;
                    ?>
 (<?php 
                    echo $company->ticker;
                    ?>
)</span>&nbsp;<img src="<?php 
                    echo $company->{'logo-url'};
                    ?>
" alt="<?php 
                    echo $company->name;
                    ?>
コード例 #2
0
 function update_linkedin_count()
 {
     // print "open linked IN update";
     if (!empty($this->transient['linkedin'])) {
         $result = $this->transient['linkedin'];
         // print "1";
     } elseif (empty($this->transient['linkedin']) && !empty($this->data) && !empty($this->options['data']['linkedin'])) {
         $result = $this->options['data']['linkedin'];
         // print "2";
     } else {
         if (!class_exists('LinkedIn')) {
             require_once ESSB_PLUGIN_ROOT . 'lib/external/linkedin/linkedin.php';
         }
         if (!class_exists('OAuthServer')) {
             require_once ESSB_PLUGIN_ROOT . 'lib/external/OAuth/OAuth.php';
         }
         $app_key = $this->options['social']['linkedin']['api'];
         $app_secret = $this->options['social']['linkedin']['apps'];
         $company_id = $this->options['social']['linkedin']['id'];
         $result = 0;
         // print "calling LinkedIn";
         $opt = array('appKey' => $app_key, 'appSecret' => $app_secret, 'callbackUrl' => '');
         $api = new LinkedIn($opt);
         $response = $api->company(trim('universal-name=' . $company_id . ':(num-followers)'));
         // print "parsing";
         // print_r($response);
         if (false !== $response['success']) {
             // print "get company";
             $company = new SimpleXMLElement($response['linkedin']);
             if (isset($company->{'num-followers'})) {
                 $result = current($company->{'num-followers'});
             }
         }
         if (!empty($result)) {
             // To update the stored data
             $this->updating_data['linkedin'] = $result;
         }
         if (empty($result) && !empty($this->options['data']['linkedin'])) {
             // Get
             // the
             // stored
             // data
             $result = $this->options['data']['linkedin'];
         }
     }
     return $result;
 }
コード例 #3
0
 public function us_fan_counts()
 {
     header('content-type: application/json');
     $ajax_debug = UltimateSocialDeux::opt('us_ajax_debug', false);
     if (wp_verify_nonce($_REQUEST['nonce'], 'us_nonce') || $ajax_debug) {
         if (!class_exists('Requests')) {
             require_once plugin_dir_path(__FILE__) . '/includes/Requests.php';
             Requests::register_autoloader();
         }
         $args = $_REQUEST['args'] ? $_REQUEST['args'] : die('Args not set');
         $args = urldecode(stripslashes($args));
         $args = json_decode($args, true);
         $option = maybe_unserialize(get_option('us_fan_counts', array()));
         $json = array();
         $networks = explode(',', $args['networks']);
         $networks = array_keys(array_flip($networks));
         $timestamp = time();
         foreach ($networks as $key => $network) {
             $option[$network]['count'] = isset($option[$network]['count']) ? $option[$network]['count'] : 0;
             $json[$network]['count'] = $option[$network]['count'];
             $option[$network]['timestamp'] = $timestamp;
             $id = '';
             $key = '';
             $secret = '';
             $api = '';
             $app = '';
             $user = '';
             $name = '';
             $username = '';
             switch ($network) {
                 case 'facebook':
                     $app_token = UltimateSocialDeux::opt('us_facebook_token');
                     $fb_token = $app_token ? "?access_token=" . $app_token : '';
                     $id = UltimateSocialDeux::opt('us_facebook_id');
                     if ($id) {
                         $requests[$network] = array('url' => "https://graph.facebook.com/" . $id . $fb_token);
                     }
                     break;
                 case 'twitter':
                     $id = UltimateSocialDeux::opt('us_twitter_id');
                     $key = UltimateSocialDeux::opt('us_twitter_key');
                     $secret = UltimateSocialDeux::opt('us_twitter_secret');
                     if ($id && $key && $secret) {
                         $token = get_option('us_fan_count_twitter_token');
                         if (!$token) {
                             $credentials = $key . ':' . $secret;
                             $encode = base64_encode($credentials);
                             $args = array('method' => 'POST', 'httpversion' => '1.1', 'blocking' => true, 'headers' => array('Authorization' => 'Basic ' . $encode, 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'), 'body' => array('grant_type' => 'client_credentials'));
                             add_filter('https_ssl_verify', '__return_false');
                             $response = wp_remote_post('https://api.twitter.com/oauth2/token', $args);
                             $keys = json_decode(wp_remote_retrieve_body($response));
                             if (!isset($keys->errors) && $keys) {
                                 update_option('us_fan_count_twitter_token', $keys->access_token);
                                 $token = $keys->access_token;
                             }
                         }
                         $requests[$network] = array('url' => 'https://api.twitter.com/1.1/users/show.json?screen_name=' . $id, 'headers' => array('Authorization' => "Bearer {$token}"));
                     }
                     break;
                 case 'google':
                     $id = UltimateSocialDeux::opt('us_google_id');
                     $key = UltimateSocialDeux::opt('us_google_key');
                     if ($key && $id) {
                         $requests[$network] = array('url' => "https://www.googleapis.com/plus/v1/people/" . $id . "?key=" . $key);
                     }
                     break;
                 case 'behance':
                     $id = UltimateSocialDeux::opt('us_behance_id');
                     $api = UltimateSocialDeux::opt('us_behance_api');
                     if ($id && $api) {
                         $requests[$network] = array('url' => "http://www.behance.net/v2/users/" . $id . "?api_key=" . $api);
                     }
                     break;
                 case 'delicious':
                     $id = UltimateSocialDeux::opt('us_delicious_id');
                     if ($id) {
                         $requests[$network] = array('url' => "http://feeds.delicious.com/v2/json/userinfo/" . $id);
                     }
                     break;
                 case 'linkedin':
                     $id = UltimateSocialDeux::opt('us_linkedin_id');
                     $app = UltimateSocialDeux::opt('us_linkedin_app');
                     $api = UltimateSocialDeux::opt('us_linkedin_api');
                     if (!class_exists('LinkedIn')) {
                         require_once plugin_dir_path(__FILE__) . 'includes/linkedin/linkedin.php';
                     }
                     if (!class_exists('OAuthServer')) {
                         require_once plugin_dir_path(__FILE__) . 'includes/OAuth/OAuth.php';
                     }
                     if ($id && $api && $id) {
                         $count = 0;
                         $opt = array('appKey' => $app, 'appSecret' => $api, 'callbackUrl' => '');
                         $api_call = new LinkedIn($opt);
                         $response = $api_call->company(trim('universal-name=' . $id . ':(num-followers)'));
                         if ($ajax_debug) {
                             print_r($response);
                         }
                         if (false !== $response['success']) {
                             $company = new SimpleXMLElement($response['linkedin']);
                             if (isset($company->{'num-followers'})) {
                                 $count = intval(current($company->{'num-followers'}));
                             }
                         }
                         $option[$network]['count'] = $count;
                         $json[$network]['count'] = $count;
                     }
                     break;
                 case 'youtube':
                     $id = UltimateSocialDeux::opt('us_youtube_id');
                     if ($id) {
                         $requests[$network] = array('url' => "http://gdata.youtube.com/feeds/api/users/" . $id . "?alt=json");
                     }
                     break;
                 case 'soundcloud':
                     $id = UltimateSocialDeux::opt('us_soundcloud_id');
                     $user = UltimateSocialDeux::opt('us_soundcloud_username');
                     if ($id && $user) {
                         $requests[$network] = array('url' => 'http://api.soundcloud.com/users/' . $user . '.json?client_id=' . $id);
                     }
                     break;
                 case 'vimeo':
                     $id = UltimateSocialDeux::opt('us_vimeo_id');
                     if ($id) {
                         $requests[$network] = array('url' => "http://vimeo.com/api/v2/channel/" . $id . "/info.json");
                     }
                     break;
                 case 'dribbble':
                     $id = UltimateSocialDeux::opt('us_dribbble_id');
                     if ($id) {
                         $requests[$network] = array('url' => "http://api.dribbble.com/" . $id);
                     }
                     break;
                 case 'github':
                     $id = UltimateSocialDeux::opt('us_github_id');
                     if ($id) {
                         $requests[$network] = array('url' => "https://api.github.com/users/" . $id);
                     }
                     break;
                 case 'envato':
                     $id = UltimateSocialDeux::opt('us_envato_id');
                     if ($id) {
                         $requests[$network] = array('url' => "http://marketplace.envato.com/api/edge/user:"******".json");
                     }
                     break;
                 case 'instagram':
                     $api = UltimateSocialDeux::opt('us_instagram_api');
                     $id = explode(".", $api);
                     if ($api && $id) {
                         $requests[$network] = array('url' => "https://api.instagram.com/v1/users/" . $id[0] . "/?access_token=" . $api);
                     }
                     break;
                 case 'mailchimp':
                     $name = UltimateSocialDeux::opt('us_mailchimp_name');
                     $api = UltimateSocialDeux::opt('us_mailchimp_api');
                     $count = 0;
                     if ($name && $api) {
                         if (!class_exists('MCAPI')) {
                             require_once plugin_dir_path(__FILE__) . 'includes/MCAPI.class.php';
                         }
                         $api = new MCAPI($api);
                         $retval = $api->lists();
                         if ($ajax_debug) {
                             print_r($retval);
                         }
                         if (count($retval['data']) > 0) {
                             foreach ($retval['data'] as $list) {
                                 if ($list['name'] == $name) {
                                     $count = intval($list['stats']['member_count']);
                                     break;
                                 }
                             }
                         }
                     }
                     $option[$network]['count'] = intval($count);
                     $json[$network]['count'] = intval($count);
                     break;
                 case 'vkontakte':
                     $id = UltimateSocialDeux::opt('us_vkontakte_id');
                     if ($id) {
                         $requests[$network] = array('url' => "http://api.vk.com/method/groups.getById?gid=" . $id . "&fields=members_count");
                     }
                     break;
                 case 'pinterest':
                     $username = UltimateSocialDeux::opt('us_pinterest_username');
                     if ($username) {
                         $requests[$network] = array('url' => 'http://www.pinterest.com/' . $username . '/');
                     }
                     break;
                 case 'flickr':
                     $id = UltimateSocialDeux::opt('us_flickr_id');
                     $api = UltimateSocialDeux::opt('us_flickr_api');
                     if ($id && $api) {
                         $requests[$network] = array('url' => "https://api.flickr.com/services/rest/?method=flickr.groups.getInfo&api_key=" . $api . "&group_id=" . $id . "&format=json&nojsoncallback=1");
                     }
                     break;
                 case 'feedpress':
                     $manual = intval(UltimateSocialDeux::opt('us_feedpress_manual', 0));
                     $url = UltimateSocialDeux::opt('us_feedpress_url');
                     if (filter_var($url, FILTER_VALIDATE_URL)) {
                         $requests[$network] = array('url' => $url);
                     }
                     if ($manual) {
                         $option[$network]['count'] = $manual;
                         $json[$network]['count'] = $manual;
                     }
                     break;
                 default:
                     unset($option[$network]);
                     unset($json[$network]);
                     break;
             }
         }
         $responses = !empty($requests) ? Requests::request_multiple($requests) : die('No requests sent.');
         foreach ($responses as $network => $data) {
             switch ($network) {
                 case 'facebook':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['likes']);
                         $json[$network]['count'] = intval($content['likes']);
                     }
                     break;
                 case 'twitter':
                 case 'soundcloud':
                 case 'dribbble':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['followers_count']);
                         $json[$network]['count'] = intval($content['followers_count']);
                     }
                     break;
                 case 'google':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['circledByCount']);
                         $json[$network]['count'] = intval($content['circledByCount']);
                     }
                     break;
                 case 'behance':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['user']['stats']['followers']);
                         $json[$network]['count'] = intval($content['user']['stats']['followers']);
                     }
                     break;
                 case 'delicious':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content[2]['n']);
                         $json[$network]['count'] = intval($content[2]['n']);
                     }
                     break;
                 case 'youtube':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['entry']['yt$statistics']['subscriberCount']);
                         $json[$network]['count'] = intval($content['entry']['yt$statistics']['subscriberCount']);
                     }
                     break;
                 case 'vimeo':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['total_subscribers']);
                         $json[$network]['count'] = intval($content['total_subscribers']);
                     }
                     break;
                 case 'github':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['followers']);
                         $json[$network]['count'] = intval($content['followers']);
                     }
                     break;
                 case 'envato':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['user']['followers']);
                         $json[$network]['count'] = intval($content['user']['followers']);
                     }
                     break;
                 case 'instagram':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['data']['counts']['followed_by']);
                         $json[$network]['count'] = intval($content['data']['counts']['followed_by']);
                     }
                     break;
                 case 'vkontakte':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['response'][0]['members_count']);
                         $json[$network]['count'] = intval($content['response'][0]['members_count']);
                     }
                     break;
                 case 'pinterest':
                     if (isset($responses[$network]->body)) {
                         $html = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($html);
                         }
                         $doc = new DOMDocument();
                         @$doc->loadHTML($html);
                         $metas = $doc->getElementsByTagName('meta');
                         for ($i = 0; $i < $metas->length; $i++) {
                             $meta = $metas->item($i);
                             if ($meta->getAttribute('name') == 'pinterestapp:followers') {
                                 $count = intval($meta->getAttribute('content'));
                                 break;
                             }
                         }
                         $option[$network]['count'] = $count;
                         $json[$network]['count'] = $count;
                     }
                     break;
                 case 'flickr':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['group']['members']['_content']);
                         $json[$network]['count'] = intval($content['group']['members']['_content']);
                     }
                     break;
                 case 'feedpress':
                     if (isset($responses[$network]->body)) {
                         $content = $responses[$network]->body;
                         if ($ajax_debug) {
                             print_r($content);
                         }
                         $content = json_decode($content, true);
                         $option[$network]['count'] = intval($content['subscribers']) + $manuel;
                         $json[$network]['count'] = intval($content['subscribers']) + $manuel;
                     }
                     break;
             }
         }
         maybe_serialize(update_option('us_fan_counts', $option));
         echo str_replace('\\/', '/', json_encode($json));
     } else {
         die('Nonce not verified');
     }
     die;
 }
コード例 #4
0
 public static function linkedin_old()
 {
     $id = ESSBSocialFansCounterHelper::get_option('linkedin.id');
     $account_type = ESSBSocialFansCounterHelper::get_option('linkedin.account_type', 'company');
     $app_key = ESSBSocialFansCounterHelper::get_option('linkedin.app_key');
     $app_secret = ESSBSocialFansCounterHelper::get_option('linkedin.app_secret');
     $oauth_token = ESSBSocialFansCounterHelper::get_option('linkedin.oauth_token');
     $oauth_token_secret = ESSBSocialFansCounterHelper::get_option('linkedin.oauth_token_secret');
     if (empty($id) || empty($app_secret) || empty($app_key) || $account_type == 'profile' && (empty($oauth_token) || empty($oauth_token_secret))) {
         return 0;
     }
     $opt = array('appKey' => $app_key, 'appSecret' => $app_secret, 'callbackUrl' => '');
     $api = new LinkedIn($opt);
     if ($account_type == 'company') {
         $response = $api->company(trim('universal-name=' . $id . ':(num-followers)'));
     } elseif ($account_type == 'group') {
         $response = $api->group($id, ':(num-members)');
     } else {
         $api->setTokenAccess(array('oauth_token' => $oauth_token, 'oauth_token_secret' => $oauth_token_secret));
         $response = $api->statistics($id);
     }
     if (false == $response['success']) {
         return false;
     }
     $xml = new SimpleXMLElement($response['linkedin']);
     $count = 0;
     if ($account_type == 'company') {
         if (isset($xml->{'num-followers'})) {
             $count = current($xml->{'num-followers'});
         }
     }
     if ($account_type == 'group') {
         if (isset($xml->{'num-members'})) {
             $count = current($xml->{'num-members'});
         }
     }
     if ($account_type == 'profile') {
         if (isset($xml->property)) {
             $count = (string) $xml->property[0];
         }
     }
     return $count;
 }