PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/demo-linkedin/network.php

https://bitbucket.org/insigngmbh/socialapi
PHP | 714 lines | 478 code | 82 blank | 154 comment | 94 complexity | 77e327e2a7cfb29d2ac4c4c001f49237 MD5 | raw file
  1. <?php
  2. /**
  3. * This file is used in conjunction with the 'Simple-LinkedIn' class, demonstrating
  4. * the basic functionality and usage of the library.
  5. *
  6. * COPYRIGHT:
  7. *
  8. * Copyright (C) 2011, fiftyMission Inc.
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a
  11. * copy of this software and associated documentation files (the "Software"),
  12. * to deal in the Software without restriction, including without limitation
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14. * and/or sell copies of the Software, and to permit persons to whom the
  15. * Software is furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  26. * IN THE SOFTWARE.
  27. *
  28. * SOURCE CODE LOCATION:
  29. *
  30. * http://code.google.com/p/simple-linkedinphp/
  31. *
  32. * REQUIREMENTS:
  33. *
  34. * 1. You must have cURL installed on the server and available to PHP.
  35. * 2. You must be running PHP 5+.
  36. *
  37. * QUICK START:
  38. *
  39. * There are two files needed to enable LinkedIn API functionality from PHP; the
  40. * stand-alone OAuth library, and the Simple-LinkedIn library. The latest
  41. * version of the stand-alone OAuth library can be found on Google Code:
  42. *
  43. * http://code.google.com/p/oauth/
  44. *
  45. * The latest versions of the Simple-LinkedIn library and this demonstation
  46. * script can be found here:
  47. *
  48. * http://code.google.com/p/simple-linkedinphp/
  49. *
  50. * Install these two files on your server in a location that is accessible to
  51. * this demo script. Make sure to change the file permissions such that your
  52. * web server can read the files.
  53. *
  54. * Next, make sure the path to the LinkedIn class below is correct.
  55. *
  56. * Finally, read and follow the 'Quick Start' guidelines located in the comments
  57. * of the Simple-LinkedIn library file.
  58. *
  59. * @version 3.2.0 - November 8, 2011
  60. * @author Paul Mennega <paul@fiftymission.net>
  61. * @copyright Copyright 2011, fiftyMission Inc.
  62. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  63. */
  64. /**
  65. * Session existance check.
  66. *
  67. * Helper function that checks to see that we have a 'set' $_SESSION that we can
  68. * use for the demo.
  69. */
  70. function oauth_session_exists() {
  71. if((is_array($_SESSION)) && (array_key_exists('oauth', $_SESSION))) {
  72. return TRUE;
  73. } else {
  74. return FALSE;
  75. }
  76. }
  77. try {
  78. // include the LinkedIn class
  79. require_once('../linkedin_3.2.0.class.php');
  80. // start the session
  81. if(!session_start()) {
  82. throw new LinkedInException('This script requires session support, which appears to be disabled according to session_start().');
  83. }
  84. // display constants
  85. $API_CONFIG = array(
  86. 'appKey' => '<your application key here>',
  87. 'appSecret' => '<your application secret here>',
  88. 'callbackUrl' => NULL
  89. );
  90. define('CONNECTION_COUNT', 20);
  91. define('PORT_HTTP', '80');
  92. define('PORT_HTTP_SSL', '443');
  93. define('UPDATE_COUNT', 10);
  94. // set index
  95. $_REQUEST[LINKEDIN::_GET_TYPE] = (isset($_REQUEST[LINKEDIN::_GET_TYPE])) ? $_REQUEST[LINKEDIN::_GET_TYPE] : '';
  96. switch($_REQUEST[LINKEDIN::_GET_TYPE]) {
  97. case 'comment':
  98. /**
  99. * Handle comment requests.
  100. */
  101. // check the session
  102. if(!oauth_session_exists()) {
  103. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  104. }
  105. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  106. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  107. if(!empty($_POST['nkey'])) {
  108. $response = $OBJ_linkedin->comment($_POST['nkey'], $_POST['scomment']);
  109. if($response['success'] === TRUE) {
  110. // comment posted
  111. header('Location: ' . $_SERVER['PHP_SELF']);
  112. } else {
  113. // problem with comment
  114. echo "Error commenting on update:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  115. }
  116. } else {
  117. echo "You must supply a network update key to comment on an update.";
  118. }
  119. break;
  120. case 'initiate':
  121. /**
  122. * Handle user initiated LinkedIn connection, create the LinkedIn object.
  123. */
  124. // check for the correct http protocol (i.e. is this script being served via http or https)
  125. if($_SERVER['HTTPS'] == 'on') {
  126. $protocol = 'https';
  127. } else {
  128. $protocol = 'http';
  129. }
  130. // set the callback url
  131. $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ((($_SERVER['SERVER_PORT'] != PORT_HTTP) || ($_SERVER['SERVER_PORT'] != PORT_HTTP_SSL)) ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
  132. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  133. // check for response from LinkedIn
  134. $_GET[LINKEDIN::_GET_RESPONSE] = (isset($_GET[LINKEDIN::_GET_RESPONSE])) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
  135. if(!$_GET[LINKEDIN::_GET_RESPONSE]) {
  136. // LinkedIn hasn't sent us a response, the user is initiating the connection
  137. // send a request for a LinkedIn access token
  138. $response = $OBJ_linkedin->retrieveTokenRequest();
  139. if($response['success'] === TRUE) {
  140. // store the request token
  141. $_SESSION['oauth']['linkedin']['request'] = $response['linkedin'];
  142. // redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
  143. header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
  144. } else {
  145. // bad token request
  146. echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  147. }
  148. } else {
  149. // LinkedIn has sent a response, user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key
  150. $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
  151. if($response['success'] === TRUE) {
  152. // the request went through without an error, gather user's 'access' tokens
  153. $_SESSION['oauth']['linkedin']['access'] = $response['linkedin'];
  154. // set the user as authorized for future quick reference
  155. $_SESSION['oauth']['linkedin']['authorized'] = TRUE;
  156. // redirect the user back to the demo page
  157. header('Location: ' . $_SERVER['PHP_SELF']);
  158. } else {
  159. // bad token access
  160. echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  161. }
  162. }
  163. break;
  164. case 'revoke':
  165. /**
  166. * Handle authorization revocation.
  167. */
  168. // check the session
  169. if(!oauth_session_exists()) {
  170. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  171. }
  172. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  173. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  174. $response = $OBJ_linkedin->revoke();
  175. if($response['success'] === TRUE) {
  176. // revocation successful, clear session
  177. session_unset();
  178. $_SESSION = array();
  179. if(session_destroy()) {
  180. // session destroyed
  181. header('Location: ' . $_SERVER['PHP_SELF']);
  182. } else {
  183. // session not destroyed
  184. echo "Error clearing user's session";
  185. }
  186. } else {
  187. // revocation failed
  188. echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  189. }
  190. break;
  191. case 'invite':
  192. /**
  193. * Handle invitation messaging.
  194. */
  195. // check the session
  196. if(!oauth_session_exists()) {
  197. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  198. }
  199. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  200. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  201. if(!empty($_POST['invite_to_id'])) {
  202. // send invite via LinkedIn ID
  203. $response = $OBJ_linkedin->invite('id', $_POST['invite_to_id'], $_POST['invite_subject'], $_POST['invite_body']);
  204. if($response['success'] === TRUE) {
  205. // message has been sent
  206. header('Location: ' . $_SERVER['PHP_SELF']);
  207. } else {
  208. // an error occured
  209. echo "Error sending invite:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  210. }
  211. } elseif(!empty($_POST['invite_to_email'])) {
  212. // send invite via email
  213. $recipient = array('email' => $_POST['invite_to_email'], 'first-name' => $_POST['invite_to_firstname'], 'last-name' => $_POST['invite_to_lastname']);
  214. $response = $OBJ_linkedin->invite('email', $recipient, $_POST['invite_subject'], $_POST['invite_body']);
  215. if($response['success'] === TRUE) {
  216. // message has been sent
  217. header('Location: ' . $_SERVER['PHP_SELF']);
  218. } else {
  219. // an error occured
  220. echo "Error sending invite:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  221. }
  222. } else {
  223. // no email or id supplied
  224. echo "You must supply an email address or LinkedIn ID to send out the invitation to connect.";
  225. }
  226. break;
  227. case 'like':
  228. /**
  229. * Handle 'likes'.
  230. */
  231. // check the session
  232. if(!oauth_session_exists()) {
  233. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  234. }
  235. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  236. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  237. if(!empty($_GET['nKey'])) {
  238. $response = $OBJ_linkedin->like($_GET['nKey']);
  239. if($response['success'] === TRUE) {
  240. // update 'liked'
  241. header('Location: ' . $_SERVER['PHP_SELF']);
  242. } else {
  243. // problem with 'like'
  244. echo "Error 'liking' update:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  245. }
  246. } else {
  247. echo "You must supply a network update key to 'like' an update.";
  248. }
  249. break;
  250. case 'message':
  251. /**
  252. * Handle connection messaging.
  253. */
  254. if(!empty($_POST['connections'])) {
  255. // check the session
  256. if(!oauth_session_exists()) {
  257. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  258. }
  259. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  260. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  261. if(!empty($_POST['message_copy'])) {
  262. $copy = TRUE;
  263. } else {
  264. $copy = FALSE;
  265. }
  266. $response = $OBJ_linkedin->message($_POST['connections'], $_POST['message_subject'], $_POST['message_body'], $copy);
  267. if($response['success'] === TRUE) {
  268. // message has been sent
  269. header('Location: ' . $_SERVER['PHP_SELF']);
  270. } else {
  271. // an error occured
  272. echo "Error sending message:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  273. }
  274. } else {
  275. echo "You must select at least one recipient.";
  276. }
  277. break;
  278. case 'reshare':
  279. /**
  280. * Handle re-shares.
  281. */
  282. // check the session
  283. if(!oauth_session_exists()) {
  284. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  285. }
  286. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  287. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  288. // prepare content for sharing
  289. $content = array();
  290. if(!empty($_POST['scomment'])) {
  291. $content['comment'] = $_POST['scomment'];
  292. }
  293. if(!empty($_POST['sid'])) {
  294. $content['id'] = $_POST['sid'];
  295. }
  296. if(!empty($_POST['sprivate'])) {
  297. $private = TRUE;
  298. } else {
  299. $private = FALSE;
  300. }
  301. // re-share content
  302. $response = $OBJ_linkedin->share('reshare', $content, $private);
  303. if($response['success'] === TRUE) {
  304. // status has been updated
  305. header('Location: ' . $_SERVER['PHP_SELF']);
  306. } else {
  307. // an error occured
  308. echo "Error re-sharing content:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  309. }
  310. break;
  311. case 'unlike':
  312. /**
  313. * Handle 'unlikes'.
  314. */
  315. // check the session
  316. if(!oauth_session_exists()) {
  317. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  318. }
  319. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  320. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  321. if(!empty($_GET['nKey'])) {
  322. $response = $OBJ_linkedin->unlike($_GET['nKey']);
  323. if($response['success'] === TRUE) {
  324. // update 'unliked'
  325. header('Location: ' . $_SERVER['PHP_SELF']);
  326. } else {
  327. // problem with 'unlike'
  328. echo "Error 'unliking' update:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
  329. }
  330. } else {
  331. echo "You must supply a network update key to 'unlike' an update.";
  332. }
  333. break;
  334. default:
  335. // nothing being passed back, display demo page
  336. // check PHP version
  337. if(version_compare(PHP_VERSION, '5.0.0', '<')) {
  338. throw new LinkedInException('You must be running version 5.x or greater of PHP to use this library.');
  339. }
  340. // check for cURL
  341. if(extension_loaded('curl')) {
  342. $curl_version = curl_version();
  343. $curl_version = $curl_version['version'];
  344. } else {
  345. throw new LinkedInException('You must load the cURL extension to use this library.');
  346. }
  347. ?>
  348. <!DOCTYPE html>
  349. <html lang="en">
  350. <head>
  351. <title>Simple-LinkedIn Demo &gt; Your Network</title>
  352. <meta charset="utf-8" />
  353. <meta name="viewport" content="width=device-width" />
  354. <meta name="description" content="A demonstration page for the Simple-LinkedIn PHP class." />
  355. <meta name="keywords" content="simple-linkedin,php,linkedin,api,class,library" />
  356. <style>
  357. body {font-family: Courier, monospace; font-size: 0.8em;}
  358. footer {margin-top: 2em; text-align: center;}
  359. pre {font-family: Courier, monospace; font-size: 0.8em;}
  360. </style>
  361. </head>
  362. <body>
  363. <h1><a href="/demo.php">Simple-LinkedIn Demo</a> &gt; <a href="<?php echo $_SERVER['PHP_SELF'];?>">Your Network</a></h1>
  364. <p>Copyright 2010 - 2011, Paul Mennega, fiftyMission Inc. &lt;paul@fiftymission.net&gt;</p>
  365. <p>Released under the MIT License - http://www.opensource.org/licenses/mit-license.php</p>
  366. <p>Full source code for both the Simple-LinkedIn class and this demo script can be found at:</p>
  367. <ul>
  368. <li><a href="http://code.google.com/p/simple-linkedinphp/">http://code.google.com/p/simple-linkedinphp/</a></li>
  369. </ul>
  370. <hr />
  371. <p style="font-weight: bold;">Demo using: Simple-LinkedIn v<?php echo LINKEDIN::_VERSION;?>, cURL v<?php echo $curl_version;?>, PHP v<?php echo phpversion();?></p>
  372. <ul>
  373. <li>Please note: The Simple-LinkedIn class requires PHP 5+</li>
  374. </ul>
  375. <hr />
  376. <?php
  377. $_SESSION['oauth']['linkedin']['authorized'] = (isset($_SESSION['oauth']['linkedin']['authorized'])) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE;
  378. if($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
  379. ?>
  380. <ul>
  381. <li><a href="#manage">Manage LinkedIn Authorization</a></li>
  382. <li><a href="../demo.php#application">Application Information</a></li>
  383. <li><a href="../demo.php#profile">Your Profile</a></li>
  384. <li><a href="#network">Your Network</a>
  385. <ul>
  386. <li><a href="#networkStats">Stats</a></li>
  387. <li><a href="#networkConnections">Your Connections</a></li>
  388. <li><a href="#networkInvite">Invite Others to Join your LinkedIn Network</a></li>
  389. <li><a href="#networkUpdates">Recent Connection Updates</a></li>
  390. <li><a href="#peopleSearch">People Search</a></li>
  391. </ul>
  392. </li>
  393. </ul>
  394. <?php
  395. } else {
  396. ?>
  397. <ul>
  398. <li><a href="#manage">Manage LinkedIn Authorization</a></li>
  399. </ul>
  400. <?php
  401. }
  402. ?>
  403. <hr />
  404. <h2 id="manage">Manage LinkedIn Authorization:</h2>
  405. <?php
  406. if($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
  407. // user is already connected
  408. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  409. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  410. ?>
  411. <form id="linkedin_revoke_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  412. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="revoke" />
  413. <input type="submit" value="Revoke Authorization" />
  414. </form>
  415. <hr />
  416. <h2 id="network">Your Network:</h2>
  417. <h3 id="networkStats">Stats:</h3>
  418. <?php
  419. $response = $OBJ_linkedin->statistics();
  420. if($response['success'] === TRUE) {
  421. $response['linkedin'] = new SimpleXMLElement($response['linkedin']);
  422. echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>";
  423. } else {
  424. // request failed
  425. echo "Error retrieving network statistics:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  426. }
  427. ?>
  428. <hr />
  429. <h3 id="networkConnections">Your Connections:</h3>
  430. <?php
  431. $response = $OBJ_linkedin->connections('~/connections:(id,first-name,last-name,picture-url)?start=0&count=' . CONNECTION_COUNT);
  432. if($response['success'] === TRUE) {
  433. $connections = new SimpleXMLElement($response['linkedin']);
  434. if((int)$connections['total'] > 0) {
  435. ?>
  436. <p>First <?php echo CONNECTION_COUNT;?> of <?php echo $connections['total'];?> total connections being displayed:</p>
  437. <form id="linkedin_cmessage_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  438. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="message" />
  439. <?php
  440. foreach($connections->person as $connection) {
  441. ?>
  442. <div style="float: left; width: 150px; border: 1px solid #888; margin: 0.5em; text-align: center;">
  443. <?php
  444. if($connection->{'picture-url'}) {
  445. ?>
  446. <img src="<?php echo $connection->{'picture-url'};?>" alt="" title="" width="80" height="80" style="display: block; margin: 0 auto; padding: 0.25em;" />
  447. <?php
  448. } else {
  449. ?>
  450. <img src="../anonymous.png" alt="" title="" width="80" height="80" style="display: block; margin: 0 auto; padding: 0.25em;" />
  451. <?php
  452. }
  453. ?>
  454. <input type="checkbox" name="connections[]" id="connection_<?php echo $connection->id;?>" value="<?php echo $connection->id;?>" />
  455. <label for="connection_<?php echo $connection->id;?>"><?php echo $connection->{'first-name'};?></label>
  456. <div><?php echo $connection->id;?></div>
  457. </div>
  458. <?php
  459. }
  460. ?>
  461. <br style="clear: both;" />
  462. <h4 id="network_connections_message">Send a Message to the Checked Connections Above:</h4>
  463. <div style="font-weight: bold;">Subject:</div>
  464. <input type="text" name="message_subject" id="message_subject" length="255" maxlength="255" style="display: block; width: 400px;" />
  465. <div style="font-weight: bold;">Message:</div>
  466. <textarea name="message_body" id="message_body" rows="4" style="display: block; width: 400px;"></textarea>
  467. <input type="submit" value="Send Message" /><input type="checkbox" value="1" name="message_copy" id="message_copy" checked="checked" /><label for="message_copy">copy self on message</label>
  468. <p>(Note, any HTML in the subject or message bodies will be stripped by the LinkedIn->message() method)</p>
  469. </form>
  470. <?php
  471. } else {
  472. // no connections
  473. echo '<div>You do not have any LinkedIn connections to display.</div>';
  474. }
  475. } else {
  476. // request failed
  477. echo "Error retrieving connections:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  478. }
  479. ?>
  480. <hr />
  481. <h3 id="networkInvite">Invite Others to Join your LinkedIn Network:</h3>
  482. <form id="linkedin_imessage_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  483. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="invite" />
  484. <div style="font-weight: bold;">By Email Address and Name:</div>
  485. <input type="text" name="invite_to_email" id="invite_to_email" length="255" maxlength="255" style="display: block; width: 400px;" value="Email" />
  486. <input type="text" name="invite_to_firstname" id="invite_to_firstname" length="255" maxlength="255" style="display: block; width: 400px;" value="First Name" />
  487. <input type="text" name="invite_to_lastname" id="invite_to_lastname" length="255" maxlength="255" style="display: block; width: 400px;" value="Last Name" />
  488. <div style="font-weight: bold;">Or By LinkedIn ID:</div>
  489. <input type="text" name="invite_to_id" id="invite_to_id" length="255" maxlength="255" style="display: block; width: 400px;" />
  490. <div style="font-weight: bold;">Subject:</div>
  491. <input type="text" name="invite_subject" id="invite_subject" length="255" maxlength="255" style="display: block; width: 400px;" value="<?php echo LINKEDIN::_INV_SUBJECT;?>" />
  492. <div style="font-weight: bold;">Message:</div>
  493. <textarea name="invite_body" id="invite_body" rows="4" style="display: block; width: 400px;"></textarea>
  494. <input type="submit" value="Send Invitation" />
  495. <p>(Note, any HTML in the subject or message bodies will be stripped by the LinkedIn->invite() method)</p>
  496. </form>
  497. <hr />
  498. <h3 id="networkUpdates">Recent Connection Updates: (last <?php echo UPDATE_COUNT;?>, shared content only)</h3>
  499. <?php
  500. $query = '?type=SHAR&count=' . UPDATE_COUNT;
  501. $response = $OBJ_linkedin->updates($query);
  502. if($response['success'] === TRUE) {
  503. $updates = new SimpleXMLElement($response['linkedin']);
  504. if((int)$updates['total'] > 0) {
  505. foreach($updates->update as $update) {
  506. $person = $update->{'update-content'}->person;
  507. $share = $update->{'update-content'}->person->{'current-share'};
  508. ?>
  509. <div style=""><span style="font-weight: bold;"><a href="<?php echo $person->{'site-standard-profile-request'}->url;?>"><?php echo $person->{'first-name'} . ' ' . $person->{'last-name'} . '</a></span> ' . $share->comment;?></div>
  510. <?php
  511. if($share->content) {
  512. ?>
  513. <div style="width: 400px; margin: 0.5em 0 0.5em 2em;"><a href="<?php echo $share->content->{'submitted-url'};?>"><?php echo $share->content->title;?></a></div>
  514. <div style="width: 400px; margin: 0.5em 0 0.5em 2em;"><?php echo $share->content->description;?></div>
  515. <div style="margin: 0.5em 0 0.5em 2em;"><span style="font-weight: bold;">Share this content with your network:</span>
  516. <form id="linkedin_reshare_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  517. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="reshare" />
  518. <input type="hidden" id="sid" name="sid" value="<?php echo $share->id;?>" />
  519. <textarea name="scomment" id="scomment_<?php echo $share->id;?>" rows="4" style="display: block; width: 400px;"></textarea>
  520. <input type="submit" value="Re-Share Content" /><input type="checkbox" value="1" name="sprivate" id="sprivate_<?php echo $share->id;?>" checked="checked" /><label for="rsprivate">re-share with your connections only</label>
  521. </form>
  522. </div>
  523. <?php
  524. }
  525. ?>
  526. <div style="margin: 0.5em 0 0 2em;">
  527. <?php
  528. if($update->{'is-likable'} == 'true') {
  529. if($update->{'is-liked'} == 'true') {
  530. echo '<a href="' . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=unlike&amp;nKey=' . $update->{'update-key'} . '">Unlike</a> (' . $update->{'num-likes'} . ')';
  531. } else {
  532. echo '<a href="' . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=like&amp;nKey=' . $update->{'update-key'} . '">Like</a> (' . $update->{'num-likes'} . ')';
  533. }
  534. if($update->{'num-likes'} > 0) {
  535. $likes = $OBJ_linkedin->likes((string)$update->{'update-key'});
  536. if($likes['success'] === TRUE) {
  537. $likes['linkedin'] = new SimpleXMLElement($likes['linkedin']);
  538. echo "<pre>" . print_r($likes['linkedin'], TRUE) . "</pre>";
  539. } else {
  540. // request failed
  541. echo "Error retrieving likes:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($likes) . "</pre>";
  542. }
  543. }
  544. }
  545. ?>
  546. </div>
  547. <div style="margin: 0.5em 0 0 2em;">
  548. <?php
  549. if($update->{'is-commentable'} == 'true') {
  550. if($update->{'update-comments'}) {
  551. // there are comments for this update
  552. echo $update->{'update-comments'}['total'] . ' Comment(s)';
  553. $comments = $OBJ_linkedin->comments((string)$update->{'update-key'});
  554. if($comments['success'] === TRUE) {
  555. $comments['linkedin'] = new SimpleXMLElement($comments['linkedin']);
  556. echo "<pre>" . print_r($comments['linkedin'], TRUE) . "</pre>";
  557. } else {
  558. // request failed
  559. echo "Error retrieving comments:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($comments) . "</pre>";
  560. }
  561. } else {
  562. // no comments for this update
  563. echo 'No Comments';
  564. }
  565. ?>
  566. <div style="margin: 0 0 0 2em;">
  567. <form id="linkedin_comment_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  568. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="comment" />
  569. <input type="hidden" id="nkey" name="nkey" value="<?php echo $update->{'update-key'};?>" />
  570. <textarea name="scomment" id="scomment_<?php echo $share->id;?>" rows="4" style="display: block; width: 400px;"></textarea>
  571. <input type="submit" value="Post Comment" />
  572. </form>
  573. </div>
  574. <?php
  575. }
  576. ?>
  577. </div>
  578. <div style="border-bottom: 1px dashed #000; margin: 1em 0;"></div>
  579. <?php
  580. }
  581. } else {
  582. // no connection updates
  583. echo '<div>There are no recent connection updates to display.</div>';
  584. }
  585. } else {
  586. // request failed
  587. echo "Error retrieving updates:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  588. }
  589. ?>
  590. <hr />
  591. <h2 id="peopleSearch">People Search:</h2>
  592. <!-- <p>1st degree connections living in the San Francisco Bay Area (returned in JSON format):</p>-->
  593. <?php
  594. $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
  595. $keywords = (isset($_GET['keywords'])) ? $_GET['keywords'] : "Marketing";
  596. ?>
  597. <form action="<?php echo $_SERVER['PHP_SELF'];?>#peopleSearch" method="get">
  598. Search by Keywords: <input type="text" value="<?php echo $keywords?>" name="keywords" /><input type="submit" value="Search" />
  599. </form>
  600. <?php
  601. $query = '?keywords='.$keywords;
  602. $response = $OBJ_linkedin->searchPeople($query);
  603. if($response['success'] === TRUE) {
  604. echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>";
  605. } else {
  606. // request failed
  607. echo "Error retrieving people search results:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  608. }
  609. } else {
  610. // user isn't connected
  611. ?>
  612. <form id="linkedin_connect_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  613. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="initiate" />
  614. <input type="submit" value="Connect to LinkedIn" />
  615. </form>
  616. <?php
  617. }
  618. ?>
  619. <footer>
  620. <div>Copyright 2010 - 2011, fiftyMission Inc. (Paul Mennega &lt;<a href="mailto:paul@fiftymission.net">paul@fiftymission.net</a>&gt;)</div>
  621. <div>Released under the MIT License - <a href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a></div>
  622. </footer>
  623. </body>
  624. </html>
  625. <?php
  626. break;
  627. }
  628. } catch(LinkedInException $e) {
  629. // exception raised by library call
  630. echo $e->getMessage();
  631. }
  632. ?>