/** * Include Facebook Class * * Handles to load facebook class * */ public function ppp_load_facebook() { if (!class_exists('Facebook')) { require_once PPP_PATH . '/includes/libs/facebook/facebook.php'; } ppp_set_social_tokens(); $this->facebook = new Facebook(array('appId' => PPP_FB_APP_ID, 'secret' => PPP_FB_APP_SECRET, 'cookie' => true)); return true; }
/** * Include Twitter Class * * Handles to load twitter class */ public function ppp_load_twitter() { if (!class_exists('TwitterOAuth')) { require_once PPP_PATH . '/includes/libs/twitter/twitteroauth.php'; } ppp_set_social_tokens(); if (!defined('PPP_TW_CONSUMER_KEY') || !defined('PPP_TW_CONSUMER_SECRET')) { return false; } $this->twitter = new TwitterOAuth(PPP_TW_CONSUMER_KEY, PPP_TW_CONSUMER_SECRET); return true; }
/** * Include Linkedin Class * * Handles to load linkedin class */ public function ppp_load_linkedin() { if (!class_exists('LinkedIn')) { require_once PPP_PATH . '/includes/libs/linkedin/linkedin_oAuth.php'; } ppp_set_social_tokens(); if (!defined('LINKEDIN_KEY') || !defined('LINKEDIN_SECRET')) { return false; } global $ppp_social_settings; $config = array('appKey' => LINKEDIN_KEY, 'appSecret' => LINKEDIN_SECRET); if (isset($ppp_social_settings['linkedin']->access_token)) { $config['accessToken'] = $ppp_social_settings['linkedin']->access_token; } if (!$this->linkedin) { $this->linkedin = new LinkedIn($config); } return true; }
/** * Include Twitter Class * * Handles to load twitter class */ public function ppp_load_bitly() { if (!class_exists('Bitly')) { require_once PPP_PATH . '/includes/libs/bitly/bitly.php'; } ppp_set_social_tokens(); if (!defined('bitly_clientid') || !defined('bitly_secret')) { return false; } global $ppp_social_settings; if (isset($ppp_social_settings['bitly'])) { if (!defined('bitly_accesstoken')) { define('bitly_accesstoken', $ppp_social_settings['bitly']['access_token']); } $this->bitly = new Bitly(bitly_clientid, bitly_secret, bitly_accesstoken); } else { $this->bitly = new Bitly(bitly_clientid, bitly_secret); } return true; }
/** * Auth a user with bit.ly * @return mixed 1 if successful, 0 if general error, 'INVALID_LOGIN' if failed creds */ function ppp_get_bitly_auth() { global $ppp_bitly_oauth; ppp_set_social_tokens(); $url = 'https://api-ssl.bitly.com/oauth/access_token'; $username = $_POST['username']; $password = $_POST['password']; $headers = array('Authorization' => 'Basic ' . base64_encode(bitly_clientid . ':' . bitly_secret)); $body = 'grant_type=password&username='******'&password='******'headers' => $headers, 'body' => $body)); $body = wp_remote_retrieve_body($result); $data = json_decode($body); if (isset($data->access_token)) { global $ppp_social_settings; $ppp_social_settings['bitly']['access_token'] = $data->access_token; $user_data = json_decode($ppp_bitly_oauth->ppp_bitly_user_info(), true); $ppp_social_settings['bitly']['login'] = $user_data['data']['login']; $ppp_social_settings['bitly']['avatar'] = $user_data['data']['profile_image']; update_option('ppp_social_settings', $ppp_social_settings); echo 1; } elseif ($body == 'INVALID_LOGIN') { echo 'INVALID_LOGIN'; } else { echo 0; } die; // this is required to return a proper result }
/** * Update the Post As field for Facebook * @return sends 1 when successfully updated */ function ppp_fb_update_page() { global $ppp_social_settings, $ppp_facebook_oauth; ppp_set_social_tokens(); $account = isset($_POST['account']) ? $_POST['account'] : false; if (!empty($account)) { $ppp_social_settings['facebook']->page = $account; update_option('ppp_social_settings', $ppp_social_settings); echo 1; } else { echo 0; } die; // this is required to return a proper result }