Changeset 607643
- Timestamp:
- 10/03/2012 08:25:59 PM (13 years ago)
- Location:
- lips/branches/dev-0.9
- Files:
-
- 4 added
- 5 edited
-
li_settings.php (added)
-
lips.php (modified) (14 diffs)
-
lips_oauth.php (modified) (7 diffs)
-
lips_settings_mgr.php (added)
-
php-oauth/OAuthRequester.php (modified) (2 diffs)
-
php-oauth/store/OAuthStoreLipsXing.php (added)
-
profilesync.php (modified) (1 diff)
-
tokenstore.php (modified) (1 diff)
-
xi_settings.php (added)
Legend:
- Unmodified
- Added
- Removed
-
lips/branches/dev-0.9/lips.php
r607204 r607643 4 4 Plugin URI: http://www.tenberge-ict.nl/tools/wordpress/lips/ 5 5 Description: Synchronizes your professional LinkedIn profile, updating WordPress Pages and - optionally - Posts. 6 Version: 0. 8.86 Version: 0.9.0 7 7 Author: Bas ten Berge 8 8 Author URI: http://www.tenberge-ict.nl/profiel … … 48 48 require_once('i18n.php'); 49 49 require_once('otherservice.php'); 50 require_once('lips_settings_mgr.php'); 50 51 if (! defined('GESHI_VERSION')) { 51 52 require_once('GeSHi/geshi.php'); … … 86 87 // The capability an user must have to view admin notices and so on 87 88 protected $capability = 'edit_published_pages'; 89 // The provider holding the professional profile (preparing this thing for 90 // Xing) 91 protected $default_network = 'linkedin'; 92 protected $network; 93 protected $network_settings = null; 94 protected $network_manager = null; 88 95 // Array of post ids which must not be shown 89 96 protected $posts_to_hide; … … 133 140 */ 134 141 public function __construct() { 135 $this->sections['li'] = __( ' LinkedIn Data Access and Profile Synchronization');142 $this->sections['li'] = __( 'Profile Data Access and Synchronization'); 136 143 $this->sections['ext'] = __( 'More Services'); 137 144 $this->sections['pot'] = __( 'Post Settings' ); … … 195 202 */ 196 203 public function prepare() { 197 $this->tokenstore = new WpUserMetaTokenStore(); 204 $settings = get_option(SETTINGS_ID); 205 $this->network = $settings['professional_network']; 206 if (empty($this->network)) { 207 $this->network = $this->default_network; 208 } 209 210 $network_manager = new LinkedInProfileSyncSettingsFactory($this->network); 211 $network_settings = $network_manager->getSettings(); 212 213 $this->network_manager = $network_manager; 214 $this->network_settings = $network_settings; 215 $this->tokenstore = $network_settings->getTokenStore(); 198 216 $this->current_user = wp_get_current_user(); 199 217 $this->has_fetched_profile = $this->hasSyncedProfile(); … … 210 228 'tokenstore' => $this->tokenstore, 211 229 ); 212 OAuthStore::instance( "LipsLinkedIn", $oauth_options);230 OAuthStore::instance($network_settings->getOAuthStoreInstanceName(), $oauth_options); 213 231 } 214 232 … … 318 336 case 'oalink': 319 337 try { 320 $tokenstore = new WpUserMetaTokenStore(); 338 $settings = $this->network_settings; 339 $oauth = $settings->getDataInterchangeHandler(false); 340 321 341 $oauth_options = array( 322 'tokenstore' => $ tokenstore,342 'tokenstore' => $settings->getTokenStore(), 323 343 ); 324 OAuthStore::instance( "LipsLinkedIn", $oauth_options);344 OAuthStore::instance($settings->getOAuthStoreInstanceName(), $oauth_options); 325 345 326 $oauth = LinkedInProfileSyncOAuth::fromTokenStore($tokenstore, false);327 346 $auth_request = null; 328 347 $auth_url = $oauth->getAuthorizationUrl($auth_request); … … 493 512 'target' => '', 494 513 'relates' => null, 514 'source' => $this, 495 515 ); 496 516 … … 514 534 'title' => $title, 515 535 'relates' => $relates, 536 'source' => $source, 516 537 ); 517 538 … … 772 793 $section = "li"; 773 794 $is_authorized = false; 795 796 // The content provider 797 $this->settings['professional_network'] = array( 798 'title' => __('Professional Network' ), 799 'desc' => __('Select the professional network'), 800 'std' => 0, 801 'type' => 'select', 802 'section' => $section, 803 'choices' => array( 804 'linkedin' => 'LinkedIn Corporation', 805 'xing' => 'XING AG', 806 ), 807 'std' => 'linkedin', 808 ); 774 809 775 810 try { 776 $oauth = LinkedInProfileSyncOAuth::fromTokenStore($this->tokenstore,false);811 $oauth = $this->network_manager->getSettings()->getDataInterchangeHandler(false); 777 812 $this->jquery_oauth_initialized = true; 778 813 … … 890 925 } 891 926 892 $this->settings['profile_lang'] = array( 893 'title' => __('Preferred Profile Language'), 894 'desc' => __('Select the <strong>preferred</strong> profile language. Gets the standard profile when a profile in the selected language does not exist'), 895 'type' => 'select', 896 'section' => $section, 897 'choices' => LinkedInI18N::getLanguages(), 898 'section' => $section, 899 'depends' => 'update_profile', 900 ); 927 $specific_settings = $this->network_settings->getMainSettings(); 928 if (is_array($specific_settings) && !empty($specific_settings)) { 929 $this->settings += $specific_settings; 930 } 931 901 932 } 902 933 catch (IdentificationMissingException $e) { 903 $this->settings['oauth_key'] = array( 904 'title' => __( 'OAuth Token' ), 905 'desc' => sprintf("%s %s, %s", __( 'Visit the'), '<a href="https://www.linkedin.com/secure/developer" class="lips-ext-ref" target="linkedindeveloper" onclick="window.open(\'https://www.linkedin.com/secure/developer\', \'LinkedIn\', \'status=1,location=1,resizable=1,width=800,height=600\'); return false">LinkedIn developer page</a>', __('provide details and paste the API Key here.')), 906 'type' => 'text', 907 'std' => '', 908 'section' => $section, 909 'required'=> true, 910 ); 911 912 $this->settings['oauth_secret'] = array( 913 'title' => __( 'OAuth Secret' ), 914 'desc' => __( 'Paste the Secret Key here.' ), 915 'type' => 'password', 916 'std' => '', 917 'section' => $section, 918 'required'=> true, 919 ); 934 $specific_settings = $this->network_settings->getIdentifyingSettings(); 935 if (is_array($specific_settings) && !empty($specific_settings)) { 936 $this->settings += $specific_settings; 937 } 920 938 } 921 939 … … 1420 1438 $validated[$key] = array_key_exists($key, $input) && "1" == $input[$key] ? 1 : 0; 1421 1439 1422 // Check authorization 1423 if (array_key_exists("oauth_key", $input) && array_key_exists("oauth_secret", $input)) { 1424 try { 1425 $id = new OAuthIdentificationToken($input["oauth_key"], $input["oauth_secret"]); 1426 $this->tokenstore->set($id, true); 1427 } 1428 catch (OAuthTokenExceptionBase $e) { 1429 add_settings_error("oauth_key", "invalid_value_0", __("Unable to identify application") . ": " . $e->getMessage()); 1430 $errcount++; 1431 } 1432 } 1433 1434 if (array_key_exists('pin', $input) && trim($input['pin']) != "") { 1435 // The thing is attempted to be authenticated, so it needs a Identification or 1436 // another auth_req thing. 1437 $oauth = LinkedInProfileSyncOAuth::fromTokenStore($this->tokenstore, false); 1438 if (! $oauth->authorize(trim($input["pin"]), array($this, "setOAuthError"), array("pin" => $input["pin"], "oauth" => $oauth, "class" => "auth"))) { 1439 $errcount++; 1440 } 1441 } 1442 1443 $this->handlePreTemplateCleanup(); 1444 1445 if ($do_profile_update) { 1446 if ($validated["profile_page"] == $this->jquery_no_page_selected["page"]) { 1447 $errcount++; 1448 add_settings_error("profile_page", "profile_page_1", __("The profile page was not yet selected. Select a profile page from the <em>" . $this->sections[$this->settings["profile_page"]["section"]] . "</em> tab")); 1449 } 1450 } 1451 1452 // See which template to use. Assume installed ones have been validated 1453 $templates = array(); 1454 if (array_key_exists('have_posts', $input) && 1 == $input['have_posts'] && 'post_use_summary' != $input['post_template']) { 1455 $templates[] = array("template" => LinkedInProfileSyncConvenience::getPostTemplate($input), "required" => true, "callback_arg" => "post", "element" => $this->settings["custom_post_template"]); 1456 } 1457 $templates[] = array("template" => LinkedInProfileSyncConvenience::getPageTemplate($input), "required" => $do_profile_update, "callback_arg" => "page", "element" => $this->settings["custom_page_template"]); 1458 $templates[] = array("template" => $input["title_template"], "required" => false, "callback_arg" => "title", "element" => $this->settings["title_template"]); 1459 1460 foreach ($templates as $validator) { 1461 if (empty($validator["template"])) { 1462 if ($validator["required"]) { 1463 $title = $validator["element"]["title"]; 1464 add_settings_error($title, "template_validation_1", "A value for <em>" . $this->sections[$validator["element"]["section"]] . " -> " . $title . "</em> is required."); 1440 // Check to see if the Professional Network has changed 1441 $network_changed = $validated['professional_network'] != $this->network; 1442 1443 if ($network_changed) { 1444 add_settings_error("network_manager", "manager_switched", __("Switched professional network"), "updated"); 1445 } 1446 else { 1447 if (array_key_exists("oauth_key", $input) && array_key_exists("oauth_secret", $input)) { 1448 try { 1449 $id = new OAuthIdentificationToken($input["oauth_key"], $input["oauth_secret"]); 1450 $this->tokenstore->set($id, true); 1451 } 1452 catch (OAuthTokenExceptionBase $e) { 1453 add_settings_error("oauth_key", "invalid_value_0", __("Unable to identify application") . ": " . $e->getMessage()); 1465 1454 $errcount++; 1466 1455 } 1467 1456 } 1457 1458 // Check authorization 1459 if (array_key_exists('pin', $input) && trim($input['pin']) != "") { 1460 // The thing is attempted to be authenticated, so it needs a Identification or 1461 // another auth_req thing. 1462 try { 1463 $oauth = $this->network_settings->getDataInterchangeHandler(false); //LinkedInProfileSyncOAuth::fromTokenStore($this->tokenstore, false); 1464 if (! $oauth->authorize(trim($input["pin"]), array($this, "setOAuthError"), array("pin" => $input["pin"], "oauth" => $oauth, "class" => "auth"))) { 1465 $errcount++; 1466 } 1467 } 1468 catch (OAuthException $e) { 1469 $errcount++; 1470 } 1471 } 1472 1473 $this->handlePreTemplateCleanup(); 1474 1475 if ($do_profile_update) { 1476 if ($validated["profile_page"] == $this->jquery_no_page_selected["page"]) { 1477 $errcount++; 1478 add_settings_error("profile_page", "profile_page_1", __("The profile page was not yet selected. Select a profile page from the <em>" . $this->sections[$this->settings["profile_page"]["section"]] . "</em> tab")); 1479 } 1480 } 1481 1482 // See which template to use. Assume installed ones have been validated 1483 $templates = array(); 1484 if (array_key_exists('have_posts', $input) && 1 == $input['have_posts'] && 'post_use_summary' != $input['post_template']) { 1485 $templates[] = array("template" => LinkedInProfileSyncConvenience::getPostTemplate($input), "required" => true, "callback_arg" => "post", "element" => $this->settings["custom_post_template"]); 1486 } 1487 $templates[] = array("template" => LinkedInProfileSyncConvenience::getPageTemplate($input), "required" => $do_profile_update, "callback_arg" => "page", "element" => $this->settings["custom_page_template"]); 1488 $templates[] = array("template" => $input["title_template"], "required" => false, "callback_arg" => "title", "element" => $this->settings["title_template"]); 1489 1490 foreach ($templates as $validator) { 1491 if (empty($validator["template"])) { 1492 if ($validator["required"]) { 1493 $title = $validator["element"]["title"]; 1494 add_settings_error($title, "template_validation_1", "A value for <em>" . $this->sections[$validator["element"]["section"]] . " -> " . $title . "</em> is required."); 1495 $errcount++; 1496 } 1497 } 1498 else { 1499 // Not empty validate content 1500 $smarty = new LinkedInProfileSyncSmarty(array('is_validation' => true)); 1501 if (! $smarty->try_fetch($validator["template"], array($this, "setSmartyError"), $validator["callback_arg"])) { 1502 unset($validated[$validator["callback_arg"] . "_template"]); 1503 $errcount++; 1504 } 1505 } 1506 } 1507 1508 if (!empty($input["post_category"])) { 1509 unset($validated["post_category"]); // Overwrite with the category id 1510 $validated["post_category"] = array_map('trim', explode(",", $input["post_category"])); 1511 foreach ($validated["post_category"] as $cat) { 1512 wp_create_category($cat); 1513 } 1514 } 1515 1516 if (1 == $validated["enable_profile_data_debug"]) { 1517 // Now this page title must not match the profile page... 1518 if ($validated["profile_debug_data_page"] == $validated["profile_page"]) { 1519 $errcount++; 1520 add_settings_error("profile_debug_data_page", "debug_1", sprintf("Cannot use page %s for Debug Data-On-a-Page because this is your Profile page. Disable Debug Data On-a-Page or select another page to continue", get_the_title($validated["profile_debug_data_page"]))); 1521 unset($validated["profile_debug_data_page"]); 1522 } 1523 else if ($validated["profile_debug_data_page"] == $this->jquery_no_page_selected["dbg"]) { 1524 $errcount++; 1525 add_settings_error("profile_debug_data_page", "debug_2", __("The Debug Data-On-a-Page was not yet selected. Select a page from the <em>" . $this->sections[$this->settings["profile_debug_data_page"]["section"]] ."</em> tab")); 1526 } 1527 else { 1528 add_filter(LIPS_PROFILE_PRE_TEMPLATE_FILTER, array($this, 'saveFormattedDebugPostFilter'), 42); 1529 } 1530 } 1531 1532 if (1 == $validated["reset_hidden_notification"]) { 1533 delete_user_meta($this->current_user->ID, LIPS_USER_META_IGNORE); 1534 unset($validated["reset_hidden_notification"]); 1535 } 1536 1537 if (1 == $validated["keep_local_copy"]) { 1538 if ('li_profile' == $validated["profile_source"]) { 1539 add_filter(LIPS_PROFILE_PRE_TEMPLATE_FILTER, array($this, 'saveLocalProfileContentFilter'), 41, 2); 1540 } 1541 } 1468 1542 else { 1469 // Not empty validate content 1470 $smarty = new LinkedInProfileSyncSmarty(array('is_validation' => true)); 1471 if (! $smarty->try_fetch($validator["template"], array($this, "setSmartyError"), $validator["callback_arg"])) { 1472 unset($validated[$validator["callback_arg"] . "_template"]); 1473 $errcount++; 1474 } 1475 } 1476 } 1477 1478 if (!empty($input["post_category"])) { 1479 unset($validated["post_category"]); // Overwrite with the category id 1480 $validated["post_category"] = array_map('trim', explode(",", $input["post_category"])); 1481 foreach ($validated["post_category"] as $cat) { 1482 wp_create_category($cat); 1483 } 1484 } 1485 1486 if (1 == $validated["enable_profile_data_debug"]) { 1487 // Now this page title must not match the profile page... 1488 if ($validated["profile_debug_data_page"] == $validated["profile_page"]) { 1489 $errcount++; 1490 add_settings_error("profile_debug_data_page", "debug_1", sprintf("Cannot use page %s for Debug Data-On-a-Page because this is your Profile page. Disable Debug Data On-a-Page or select another page to continue", get_the_title($validated["profile_debug_data_page"]))); 1491 unset($validated["profile_debug_data_page"]); 1492 } 1493 else if ($validated["profile_debug_data_page"] == $this->jquery_no_page_selected["dbg"]) { 1494 $errcount++; 1495 add_settings_error("profile_debug_data_page", "debug_2", __("The Debug Data-On-a-Page was not yet selected. Select a page from the <em>" . $this->sections[$this->settings["profile_debug_data_page"]["section"]] ."</em> tab")); 1496 } 1497 else { 1498 add_filter(LIPS_PROFILE_PRE_TEMPLATE_FILTER, array($this, 'saveFormattedDebugPostFilter'), 42); 1499 } 1500 } 1501 1502 if (1 == $validated["reset_hidden_notification"]) { 1503 delete_user_meta($this->current_user->ID, LIPS_USER_META_IGNORE); 1504 unset($validated["reset_hidden_notification"]); 1505 } 1506 1507 if (1 == $validated["keep_local_copy"]) { 1508 if ('li_profile' == $validated["profile_source"]) { 1509 add_filter(LIPS_PROFILE_PRE_TEMPLATE_FILTER, array($this, 'saveLocalProfileContentFilter'), 41, 2); 1510 } 1511 } 1512 else { 1513 // Option is not present when the thing is disabled -- or when the thing has no value. 1514 delete_user_meta($this->current_user->ID, LIPS_USER_META_PROFILE); 1515 } 1516 1517 if (array_key_exists('stackexchange_site', $validated) && $this->jquery_service_type != $validated['stackexchange_site']) { 1518 if (array_key_exists('stackexchange_login', $validated)) { 1519 $user = trim($validated['stackexchange_login']); 1520 if (empty($user)) { 1521 unset($validated['stackexchange_login']); 1522 } 1523 else { 1524 $validated['stackexchange_login'] = $user; 1525 add_filter(LIPS_PROFILE_FETCHED_FILTER, array($this, 'addStackExchangeUserDetails'), 43); 1526 } 1527 } 1528 } 1529 1530 if ($do_profile_update && 0 == $errcount) { 1531 // Remove the article author from this thing when the user is not admin 1532 $this->validated_settings = $validated; 1533 $this->performProfileUpdate(); 1534 if ('li_profile' == $validated["profile_source"]) { 1535 $oauth = LinkedInProfileSyncOAuth::fromTokenStore($this->tokenstore, false); 1536 $oauth->revoke(); 1537 } 1538 } 1539 1540 $this->tokenstore->expire(false, true); 1543 // Option is not present when the thing is disabled -- or when the thing has no value. 1544 delete_user_meta($this->current_user->ID, LIPS_USER_META_PROFILE); 1545 } 1546 1547 if (array_key_exists('stackexchange_site', $validated) && $this->jquery_service_type != $validated['stackexchange_site']) { 1548 if (array_key_exists('stackexchange_login', $validated)) { 1549 $user = trim($validated['stackexchange_login']); 1550 if (empty($user)) { 1551 unset($validated['stackexchange_login']); 1552 } 1553 else { 1554 $validated['stackexchange_login'] = $user; 1555 add_filter(LIPS_PROFILE_FETCHED_FILTER, array($this, 'addStackExchangeUserDetails'), 43); 1556 } 1557 } 1558 } 1559 1560 if ($do_profile_update && 0 == $errcount) { 1561 // Remove the article author from this thing when the user is not admin 1562 $this->validated_settings = $validated; 1563 $this->performProfileUpdate(); 1564 if ('li_profile' == $validated["profile_source"]) { 1565 $oauth = LinkedInProfileSyncOAuth::fromTokenStore($this->tokenstore, false); 1566 $oauth->revoke(); 1567 } 1568 } 1569 1570 $this->tokenstore->expire(false, true); 1571 } 1541 1572 1542 1573 return $validated; … … 1558 1589 $profile_source = $this->validated_settings["profile_source"]; 1559 1590 if ($profile_source == "li_profile") { 1560 $sync = new LinkedInProfileSyncer($this->validated_settings, $this->tokenstore); 1591 $oauth = $this->network_settings->getDataInterchangeHandler(true, $this->tokenstore); 1592 $sync = new LinkedInProfileSyncer($config, $oauth); 1561 1593 } 1562 1594 else if ($profile_source == "local_profile") { … … 1674 1706 protected function getToolUrl() { 1675 1707 return LIPS_PARENT_PAGE . "?" . "page=" . urlencode(LIPS_OPTIONS_PAGE); 1708 } 1709 1710 /** 1711 * Reads a stored profile for the currently selected network from the 1712 * usermeta. 1713 * 1714 * @return array Network profile details 1715 * @return null Found nothing for this profile 1716 */ 1717 protected function getStoredProfile() { 1718 $profile = get_user_meta($this->current_user->ID, LIPS_USER_META_PROFILE, true); 1719 $network_profile = null; 1720 1721 if (!empty($profile) && is_array($profile)) { 1722 if (array_key_exists($this->network, $profile)) { 1723 $network_profile = $profile[$this->network]; 1724 } 1725 } 1726 1727 return $network_profile; 1676 1728 } 1677 1729 -
lips/branches/dev-0.9/lips_oauth.php
r607204 r607643 39 39 40 40 class LipsOAuth { 41 public function getRequestToken($consumer_key, $ca_info = null ) {41 public function getRequestToken($consumer_key, $ca_info = null, $api_specific_params = null) { 42 42 $instance = OAuthStore::instance(); 43 43 $curl_options = array(); … … 45 45 $curl_options[CURLOPT_CAINFO] = $ca_info; 46 46 } 47 return OAuthRequester::requestRequestToken($consumer_key, 0, null, 'POST', array(), $curl_options);47 return OAuthRequester::requestRequestToken($consumer_key, 0, $api_specific_params, 'POST', array(), $curl_options); 48 48 } 49 49 … … 127 127 return $o; 128 128 } 129 130 /** 131 * Returns the url on which the application can be maintained. This url is hosted by 132 * the content provider 133 * 134 */ 135 public static function getContentProviderUrl() { 136 throw new LogicException("getContentProviderUrl must be overridden"); 137 } 129 138 } 130 139 140 define('LINKEDIN_BASE_URL', "https://api.linkedin.com"); 141 define('LINKEDIN_OAUTH_URL', LINKEDIN_BASE_URL . "/uas/oauth"); 131 142 /** 132 143 * This class handles the LinkedInProfileSync specific oauth integration 133 144 */ 134 145 class LinkedInProfileSyncOAuth extends WordPressIntegratedOAuth { 146 protected $base_url = LINKEDIN_BASE_URL; 147 protected $oauth_base_url = LINKEDIN_OAUTH_URL; 135 148 static protected $picture_sizes = array("original", "40x40"); 136 149 /** … … 285 298 286 299 return $this->defaultFetch( 287 "https://api.linkedin.com/v1/people/~:(id,picture-urls::(" . $picture_sizes . "),num-connections,main-address,first-name,last-name,formatted-name,date-of-birth,twitter-accounts,last-modified-timestamp,headline,industry,summary,specialties,honors,associations,interests,publications,patents,skills:(skill:(name),proficiency:(level,name),years:(id,name)),certifications:(name,authority:(name),number,start-date,end-date),educations,courses,volunteer,recommendations-received,num-recommenders,public-profile-url,positions,location:(name),languages:(language:(name),proficiency:(level,name)))",300 $this->base_url . "/v1/people/~:(id,picture-urls::(" . $picture_sizes . "),num-connections,main-address,first-name,last-name,formatted-name,date-of-birth,twitter-accounts,last-modified-timestamp,headline,industry,summary,specialties,honors,associations,interests,publications,patents,skills:(skill:(name),proficiency:(level,name),years:(id,name)),certifications:(name,authority:(name),number,start-date,end-date),educations,courses,volunteer,recommendations-received,num-recommenders,public-profile-url,positions,location:(name),languages:(language:(name),proficiency:(level,name)))", 288 301 $failure_callback, 289 302 $failure_callback_param, … … 301 314 public function fetchCompanyDetails($company_ids, $failure_callback = '', $failure_callback_param = null) { 302 315 return $this->defaultFetch( 303 sprintf(" https://api.linkedin.com/v1/companies::(%s):(company-type,name,universal-name,website-url,status)", implode(",", $company_ids)),316 sprintf("%s/v1/companies::(%s):(company-type,name,universal-name,website-url,status)", $this->base_url, implode(",", $company_ids)), 304 317 $failure_callback, 305 318 $failure_callback_param … … 314 327 public function fetchUserProfile($id, $failure_callback = '', $failure_callback_param = null) { 315 328 return $this->defaultFetch( 316 sprintf(" https://api.linkedin.com/v1/people/%s:(public-profile-url)", $id),329 sprintf("%s/v1/people/%s:(public-profile-url)", $this->base_url, $id), 317 330 $failure_callback, 318 331 $failure_callback_param … … 355 368 return self::$picture_sizes; 356 369 } 370 371 /** 372 * Returns the url to the LinkedIn developer website 373 * 374 */ 375 public static function getContentProviderUrl() { 376 return "https://www.linkedin.com/secure/developer"; 377 } 378 379 } 380 381 /** 382 * This class handles the LinkedInProfileSync specific oauth integration 383 */ 384 class XingProfileSyncOAuth extends WordPressIntegratedOAuth { 385 protected $url_base = "https://api.xing.com"; 386 /** 387 * Creates a new instance 388 */ 389 protected function getAuthorizationToken($failure_callback = '', $failure_callback_param = null) { 390 $id_token = $this->provider->getIdentificationToken(true); 391 $params = array( 392 "oauth_callback" => "oob", 393 ); 394 395 // try { 396 return $this->getRequestToken($id_token['token'], XingProfileSyncOAuth::getCAInfo(), $params); 397 // } 398 // catch (OAuthException2 $e) { 399 // if (!$this->sslChecks || !$this->permit_disable_ssl_checks) { 400 // $this->handleFailureCallback($failure_callback, $failure_callback_param, $e, true); 401 // } 402 // $this->disableSSLChecks(); 403 // return $this->getAuthorizationToken(); 404 // } 405 } 406 407 /** 408 * Calls the setupCAChecking method from the parent class and attempts to see 409 * if CA checking is disabled. Installs the ca chain when CA checking is not 410 * disabled. 411 * 412 */ 413 public function setupCAChecking() { 414 parent::setupCAChecking(); 415 if ($this->sslChecks) { 416 $cainfo = self::getCAInfo(); 417 $this->setCAPath(null, $cainfo); 418 } 419 } 420 421 /** 422 * Returns the authorization url to use for this application. 423 */ 424 public function getAuthorizationUrl(&$request_token, $failure_callback = '', $failure_callback_param = null) { 425 // Get authentication key, and create an url for it. Raise an exception when this 426 // cannot be done. 427 // Only when the thing has not expired yet 428 $this->getAuthorizationToken($failure_callback, $failure_callback_param); 429 $config = OAuthStore::instance(); 430 $server = $config->getServer("", 0); 431 return $server["authorize_uri"]; 432 } 433 434 /** 435 * Authorizes the app for LinkedIn. 436 * 437 * @return true: The app was succesfully authorized. 438 * @return false: Unable to authorize app. 439 */ 440 public function authorize($pin, $failure_callback = '', $failure_callback_param = null) { 441 $is_authorized = false; 442 443 // Get consumer token 444 $id_token = $this->provider->getIdentificationToken(true); 445 446 // Instantiate this thing using the stored access request thing. 447 $req = $this->provider->getAuthenticationRequestToken(true); 448 449 try { 450 $this->getAccessToken($id_token['token'], $pin, XingProfileSyncOAuth::getCAInfo()); 451 $is_authorized = true; 452 } 453 catch (OAuthException2 $e) { 454 if (!$this->sslChecks || !$this->permit_disable_ssl_checks) 455 $this->handleFailureCallback($failure_callback, $failure_callback_param, $e); 456 else { 457 $this->disableSSLChecks(); 458 return $this->authorize($pin, $failure_callback, $failure_callback_param); 459 } 460 } 461 462 return $is_authorized; 463 } 464 465 /** 466 * Revokes an earlier granted token 467 * 468 */ 469 public function revoke() { 470 // $this->fetch("https://api.linkedin.com/uas/oauth/invalidateToken", null, "GET"); 471 error_log("revoking your token"); 472 } 473 474 /** 475 * Fetches data from $url, returning contents to the caller. 476 * 477 * @param string $url The url to fetch. 478 * @param array | string $failure_callback Method or function being called upon failure. 479 * The interface of a callback is *()($failure_callback_param, $exception detail) 480 * @param * $failure_callback_param Argument being passed to the $failure_callback. 481 * 482 * @return null Unable to fetch the url. 483 * 484 */ 485 protected function defaultFetch($url, $failure_callback = '', $failure_callback_param = null, $lang = null) { 486 $headers = array('x-li-format' => 'json'); 487 if (null != $lang) { 488 $headers["Accept-Language"] = $lang; 489 } 490 491 try { 492 $result = 493 $this->fetch( 494 $url, 495 null, 496 OAUTH_HTTP_METHOD_GET, 497 $headers 498 ); 499 } 500 catch (OAuthException $e) { 501 if (!$this->sslChecks || !$this->permit_disable_ssl_checks) { 502 $this->handleFailureCallback($failure_callback, $failure_callback_param, $e); 503 $result = null; 504 } 505 else { 506 $this->disableSSLChecks(); 507 return $this->defaultFetch($url, $failure_callback, $failure_callback_param); 508 } 509 } 510 511 return $result; 512 } 513 514 /** 515 * Fetches the profile from LinkedIn, optionally calling $failure_callback 516 * method upon failure. 517 * 518 * @return associated array. 519 * 520 * @param array | string $failure_callback: Either an array containing a object 521 * method pair, or a string, which is called on failure. 522 * @param * $failure_callback_param: Optional parameter for the $failure_callback. 523 * Ignored when $failure_callback is not provided. 524 * @param bool $public_profile: True downloads the public profile (respecting 525 * restrictions applied by the profile owner), False fetches the private 526 * profile. 527 */ 528 public function fetchProfile($profile_lang, $public_profile = false, $failure_callback = '', $failure_callback_param = null) { 529 // $picture_sizes = implode(",", LinkedInProfileSyncOAuth::getProfilePictureSizes()); 530 531 return $this->defaultFetch( 532 "https://api.xing.com/v1/users/me?fields=id,display_name,gender", 533 $failure_callback, 534 $failure_callback_param, 535 $profile_lang 536 ); 537 } 538 539 /** 540 * Fetchs company details, such as the URL, the organization type, etc. 541 * 542 * @param array $company_ids: A list of company id's. 543 * @attention: Provide an array, even when only one company is requested. 544 * 545 */ 546 public function fetchCompanyDetails($company_ids, $failure_callback = '', $failure_callback_param = null) { 547 return ""; 548 } 549 550 /** 551 * Fetches people details for a user identified by id $id. Used primarly for recommendation 552 * resolving. 553 * 554 */ 555 public function fetchUserProfile($id, $failure_callback = '', $failure_callback_param = null) { 556 // return $this->defaultFetch( 557 // sprintf("https://api.linkedin.com/v1/people/%s:(public-profile-url)", $id), 558 // $failure_callback, 559 // $failure_callback_param 560 // ); 561 } 562 563 /** 564 * Returns a new object of this class 565 * 566 */ 567 protected static function handleObjectCreation($key, $secret) { 568 try { 569 return new self($key, $secret); 570 } 571 catch (OAuthException $e) { 572 throw new UnableToInitializeInstanceException($e); 573 } 574 } 575 576 /** 577 * This is a wrapper for fromTokenStore, defined in the base class. This method exists only 578 * because PHP static classes used in conjunction with an abstract class behaves rather weird. 579 * 580 */ 581 public static function fromTokenStore($tokenstore, $authorized_only = true) { 582 return self::fromTokenStoreByCallback($tokenstore, array(get_class(), 'handleObjectCreation'), false); 583 } 584 585 /** 586 * Returns the filename containing the linkedin CA chain 587 */ 588 public static function getCAInfo() { 589 return str_replace('\\', '/', dirname(__FILE__) . "/data/api.xing.pem"); 590 } 591 592 /** 593 * Returns an array with the sizes of the profile pictures being requested 594 */ 595 public static function getProfilePictureSizes() { 596 return self::$picture_sizes; 597 } 598 599 /** 600 * Returns the url to the LinkedIn developer website 601 * 602 */ 603 public static function getContentProviderUrl() { 604 return "https://dev.xing.com/applications"; 605 } 606 357 607 } 358 608 -
lips/branches/dev-0.9/php-oauth/OAuthRequester.php
r606642 r607643 165 165 } 166 166 $data = $oauth->curl_parse($text); 167 if ($data['code'] != 200) 167 // bastb -- Xing reports a HTTP 201 code (Created), which actually seems pretty reasonable. 168 if (! in_array($data['code'], array(200, 201))) 168 169 { 169 170 throw new OAuthException2('Unexpected result from the server "'.$uri.'" ('.$data['code'].') while requesting a request token'); … … 253 254 } 254 255 $data = $oauth->curl_parse($text); 255 256 if ($data['code'] != 200) 256 257 // bastb -- Xing returns HTTP 201 when a new access token is created, which sound pretty reasonable 258 if (! in_array($data['code'], array(200, 201))) 257 259 { 258 260 throw new OAuthException2('Unexpected result from the server "'.$uri.'" ('.$data['code'].') while requesting an access token'); -
lips/branches/dev-0.9/profilesync.php
r566644 r607643 71 71 * stored configuration when there is one 72 72 */ 73 public function __construct($newconfig = null, $ tokenstore= null) {74 if ($ tokenstore) {75 $this->oauth = LinkedInProfileSyncOAuth::fromTokenStore($tokenstore);73 public function __construct($newconfig = null, $oauth = null) { 74 if ($oauth) { 75 $this->oauth = $oauth; 76 76 $this->through_oauth = true; 77 77 } -
lips/branches/dev-0.9/tokenstore.php
r559512 r607643 316 316 } 317 317 318 class WpUserMetaLinkedInTokenStore extends WpUserMetaTokenStore { 319 public function __construct($uid = null) { 320 parent::__construct($uid, WpUserMetaTokenStore::getDefaultMetaKey()); 321 } 322 } 323 324 class WpUserMetaXingTokenStore extends WpUserMetaTokenStore { 325 public function __construct($uid = null) { 326 parent::__construct($uid, 'xing:oauth'); 327 } 328 } 329 330 318 331 class OAuthTokenExceptionBase extends LipsException { } 319 332 class OAuthTokenOrSecretCannotBeEmptyException extends OAuthTokenExceptionBase { }
Note: See TracChangeset
for help on using the changeset viewer.