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

/vendors/simple_linkedin/demo/network.php

https://github.com/ColdTrick/socialink
PHP | 712 lines | 478 code | 80 blank | 154 comment | 94 complexity | 25238f246273d9c2383f8d4c285a61d9 MD5 | raw file
Possible License(s): MIT
  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.1.1 - July 12, 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.1.1.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 PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  349. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  350. <head>
  351. <title>Simple-LinkedIn Demo &gt; Your Network</title>
  352. <meta name="author" content="Paul Mennega <paul@fiftymission.net>" />
  353. <meta name="copyright" content="Copyright 2010 - 2011, fiftyMission Inc." />
  354. <meta name="license" content="http://www.opensource.org/licenses/mit-license.php" />
  355. <meta name="description" content="A demonstration page for the Simple-LinkedIn PHP class." />
  356. <meta name="keywords" content="simple-linkedin,php,linkedin,api,class,library" />
  357. <meta name="medium" content="mult" />
  358. <meta name="viewport" content="width=device-width" />
  359. <meta http-equiv="Content-Language" content="en" />
  360. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  361. <style>
  362. body {font-family: Courier, monospace; font-size: 0.8em;}
  363. pre {font-family: Courier, monospace; font-size: 0.8em;}
  364. </style>
  365. </head>
  366. <body>
  367. <h1><a href="../demo.php ">Simple-LinkedIn Demo</a> &gt; <a href="<?php echo $_SERVER['PHP_SELF'];?>">Your Network</a></h1>
  368. <p>Copyright 2010 - 2011, Paul Mennega, fiftyMission Inc. &lt;paul@fiftymission.net&gt;</p>
  369. <p>Released under the MIT License - http://www.opensource.org/licenses/mit-license.php</p>
  370. <p>Full source code for both the Simple-LinkedIn class and this demo script can be found at:</p>
  371. <ul>
  372. <li><a href="http://code.google.com/p/simple-linkedinphp/">http://code.google.com/p/simple-linkedinphp/</a></li>
  373. </ul>
  374. <hr />
  375. <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>
  376. <ul>
  377. <li>Please note: The Simple-LinkedIn class requires PHP 5+</li>
  378. </ul>
  379. <hr />
  380. <?php
  381. $_SESSION['oauth']['linkedin']['authorized'] = (isset($_SESSION['oauth']['linkedin']['authorized'])) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE;
  382. if($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
  383. ?>
  384. <ul>
  385. <li><a href="#manage">Manage LinkedIn Authorization</a></li>
  386. <li><a href="demo.php#application">Application Information</a></li>
  387. <li><a href="demo.php#profile">Your Profile</a></li>
  388. <li><a href="#network">Your Network</a>
  389. <ul>
  390. <li><a href="#network_stats">Stats</a></li>
  391. <li><a href="#network_connections">Your Connections</a></li>
  392. <li><a href="#network_invite">Invite Others to Join your LinkedIn Network</a></li>
  393. <li><a href="#network_updates">Recent Connection Updates</a></li>
  394. <li><a href="#peopleSearch">People Search</a></li>
  395. </ul>
  396. </li>
  397. </ul>
  398. <?php
  399. } else {
  400. ?>
  401. <ul>
  402. <li><a href="#manage">Manage LinkedIn Authorization</a></li>
  403. </ul>
  404. <?php
  405. }
  406. ?>
  407. <hr />
  408. <h2 id="manage">Manage LinkedIn Authorization:</h2>
  409. <?php
  410. if($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
  411. // user is already connected
  412. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  413. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  414. ?>
  415. <form id="linkedin_revoke_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  416. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="revoke" />
  417. <input type="submit" value="Revoke Authorization" />
  418. </form>
  419. <hr />
  420. <h2 id="network">Your Network:</h2>
  421. <h3 id="network_stats">Stats:</h3>
  422. <?php
  423. $response = $OBJ_linkedin->statistics();
  424. if($response['success'] === TRUE) {
  425. $response['linkedin'] = new SimpleXMLElement($response['linkedin']);
  426. echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>";
  427. } else {
  428. // statistics retrieval failed
  429. echo "Error retrieving network statistics:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  430. }
  431. ?>
  432. <hr />
  433. <h3 id="network_connections">Your Connections:</h3>
  434. <?php
  435. $response = $OBJ_linkedin->connections('~/connections:(id,first-name,last-name,picture-url)?start=0&count=' . CONNECTION_COUNT);
  436. if($response['success'] === TRUE) {
  437. $connections = new SimpleXMLElement($response['linkedin']);
  438. if((int)$connections['total'] > 0) {
  439. ?>
  440. <p>First <?php echo CONNECTION_COUNT;?> of <?php echo $connections['total'];?> total connections being displayed:</p>
  441. <form id="linkedin_cmessage_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  442. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="message" />
  443. <?php
  444. foreach($connections->person as $connection) {
  445. ?>
  446. <div style="float: left; width: 150px; border: 1px solid #888; margin: 0.5em; text-align: center;">
  447. <?php
  448. if($connection->{'picture-url'}) {
  449. ?>
  450. <img src="<?php echo $connection->{'picture-url'};?>" alt="" title="" width="80" height="80" style="display: block; margin: 0 auto; padding: 0.25em;" />
  451. <?php
  452. } else {
  453. ?>
  454. <img src="../anonymous.png" alt="" title="" width="80" height="80" style="display: block; margin: 0 auto; padding: 0.25em;" />
  455. <?php
  456. }
  457. ?>
  458. <input type="checkbox" name="connections[]" id="connection_<?php echo $connection->id;?>" value="<?php echo $connection->id;?>" />
  459. <label for="connection_<?php echo $connection->id;?>"><?php echo $connection->{'first-name'};?></label>
  460. <div><?php echo $connection->id;?></div>
  461. </div>
  462. <?php
  463. }
  464. ?>
  465. <br style="clear: both;" />
  466. <h4 id="network_connections_message">Send a Message to the Checked Connections Above:</h4>
  467. <div style="font-weight: bold;">Subject:</div>
  468. <input type="text" name="message_subject" id="message_subject" length="255" maxlength="255" style="display: block; width: 400px;" />
  469. <div style="font-weight: bold;">Message:</div>
  470. <textarea name="message_body" id="message_body" rows="4" style="display: block; width: 400px;"></textarea>
  471. <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>
  472. <p>(Note, any HTML in the subject or message bodies will be stripped by the LinkedIn->message() method)</p>
  473. </form>
  474. <?php
  475. } else {
  476. // no connections
  477. echo '<div>You do not have any LinkedIn connections to display.</div>';
  478. }
  479. } else {
  480. // connections retrieval failed
  481. echo "Error retrieving connections:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  482. }
  483. ?>
  484. <hr />
  485. <h3 id="network_invite">Invite Others to Join your LinkedIn Network:</h3>
  486. <form id="linkedin_imessage_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  487. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="invite" />
  488. <div style="font-weight: bold;">By Email Address and Name:</div>
  489. <input type="text" name="invite_to_email" id="invite_to_email" length="255" maxlength="255" style="display: block; width: 400px;" value="Email" />
  490. <input type="text" name="invite_to_firstname" id="invite_to_firstname" length="255" maxlength="255" style="display: block; width: 400px;" value="First Name" />
  491. <input type="text" name="invite_to_lastname" id="invite_to_lastname" length="255" maxlength="255" style="display: block; width: 400px;" value="Last Name" />
  492. <div style="font-weight: bold;">Or By LinkedIn ID:</div>
  493. <input type="text" name="invite_to_id" id="invite_to_id" length="255" maxlength="255" style="display: block; width: 400px;" />
  494. <div style="font-weight: bold;">Subject:</div>
  495. <input type="text" name="invite_subject" id="invite_subject" length="255" maxlength="255" style="display: block; width: 400px;" value="<?php echo LINKEDIN::_INV_SUBJECT;?>" />
  496. <div style="font-weight: bold;">Message:</div>
  497. <textarea name="invite_body" id="invite_body" rows="4" style="display: block; width: 400px;"></textarea>
  498. <input type="submit" value="Send Invitation" />
  499. <p>(Note, any HTML in the subject or message bodies will be stripped by the LinkedIn->invite() method)</p>
  500. </form>
  501. <hr />
  502. <h3 id="network_updates">Recent Connection Updates: (last <?php echo UPDATE_COUNT;?>, shared content only)</h3>
  503. <?php
  504. $query = '?type=SHAR&count=' . UPDATE_COUNT;
  505. $response = $OBJ_linkedin->updates($query);
  506. if($response['success'] === TRUE) {
  507. $updates = new SimpleXMLElement($response['linkedin']);
  508. if((int)$updates['total'] > 0) {
  509. foreach($updates->update as $update) {
  510. $person = $update->{'update-content'}->person;
  511. $share = $update->{'update-content'}->person->{'current-share'};
  512. ?>
  513. <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>
  514. <?php
  515. if($share->content) {
  516. ?>
  517. <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>
  518. <div style="width: 400px; margin: 0.5em 0 0.5em 2em;"><?php echo $share->content->description;?></div>
  519. <div style="margin: 0.5em 0 0.5em 2em;"><span style="font-weight: bold;">Share this content with your network:</span>
  520. <form id="linkedin_reshare_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  521. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="reshare" />
  522. <input type="hidden" id="sid" name="sid" value="<?php echo $share->id;?>" />
  523. <textarea name="scomment" id="scomment_<?php echo $share->id;?>" rows="4" style="display: block; width: 400px;"></textarea>
  524. <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>
  525. </form>
  526. </div>
  527. <?php
  528. }
  529. ?>
  530. <div style="margin: 0.5em 0 0 2em;">
  531. <?php
  532. if($update->{'is-likable'} == 'true') {
  533. if($update->{'is-liked'} == 'true') {
  534. echo '<a href="' . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=unlike&amp;nKey=' . $update->{'update-key'} . '">Unlike</a> (' . $update->{'num-likes'} . ')';
  535. } else {
  536. echo '<a href="' . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=like&amp;nKey=' . $update->{'update-key'} . '">Like</a> (' . $update->{'num-likes'} . ')';
  537. }
  538. if($update->{'num-likes'} > 0) {
  539. $likes = $OBJ_linkedin->likes((string)$update->{'update-key'});
  540. if($likes['success'] === TRUE) {
  541. $likes['linkedin'] = new SimpleXMLElement($likes['linkedin']);
  542. echo "<pre>" . print_r($likes['linkedin'], TRUE) . "</pre>";
  543. } else {
  544. // likes retrieval failed
  545. echo "Error retrieving likes:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($likes) . "</pre>";
  546. }
  547. }
  548. }
  549. ?>
  550. </div>
  551. <div style="margin: 0.5em 0 0 2em;">
  552. <?php
  553. if($update->{'is-commentable'} == 'true') {
  554. if($update->{'update-comments'}) {
  555. // there are comments for this update
  556. echo $update->{'update-comments'}['total'] . ' Comment(s)';
  557. $comments = $OBJ_linkedin->comments((string)$update->{'update-key'});
  558. if($comments['success'] === TRUE) {
  559. $comments['linkedin'] = new SimpleXMLElement($comments['linkedin']);
  560. echo "<pre>" . print_r($comments['linkedin'], TRUE) . "</pre>";
  561. } else {
  562. // comments retrieval failed
  563. echo "Error retrieving comments:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($comments) . "</pre>";
  564. }
  565. } else {
  566. // no comments for this update
  567. echo 'No Comments';
  568. }
  569. ?>
  570. <div style="margin: 0 0 0 2em;">
  571. <form id="linkedin_comment_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  572. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="comment" />
  573. <input type="hidden" id="nkey" name="nkey" value="<?php echo $update->{'update-key'};?>" />
  574. <textarea name="scomment" id="scomment_<?php echo $share->id;?>" rows="4" style="display: block; width: 400px;"></textarea>
  575. <input type="submit" value="Post Comment" />
  576. </form>
  577. </div>
  578. <?php
  579. }
  580. ?>
  581. </div>
  582. <div style="border-bottom: 1px dashed #000; margin: 1em 0;"></div>
  583. <?php
  584. }
  585. } else {
  586. // no connection updates
  587. echo '<div>There are no recent connection updates to display.</div>';
  588. }
  589. } else {
  590. // update retrieval failed
  591. echo "Error retrieving updates:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  592. }
  593. ?>
  594. <hr />
  595. <h2 id="peopleSearch">People Search:</h2>
  596. <!-- <p>1st degree connections living in the San Francisco Bay Area (returned in JSON format):</p>-->
  597. <?php
  598. $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
  599. $keywords = (isset($_GET['keywords'])) ? $_GET['keywords'] : "Marketing";
  600. ?>
  601. <form action="<?php echo $_SERVER['PHP_SELF'];?>#peopleSearch" method="get">
  602. Search by Keywords: <input type="text" value="<?php echo $keywords?>" name="keywords" /><input type="submit" value="Search" />
  603. </form>
  604. <?php
  605. $query = '?keywords='.$keywords;
  606. $response = $OBJ_linkedin->searchPeople($query);
  607. if($response['success'] === TRUE) {
  608. echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>";
  609. } else {
  610. // people search retrieval failed
  611. echo "Error retrieving people search results:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  612. }
  613. } else {
  614. // user isn't connected
  615. ?>
  616. <form id="linkedin_connect_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  617. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="initiate" />
  618. <input type="submit" value="Connect to LinkedIn" />
  619. </form>
  620. <?php
  621. }
  622. ?>
  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. ?>