PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/demo-linkedin/groups.php

https://bitbucket.org/insigngmbh/socialapi
PHP | 779 lines | 532 code | 97 blank | 150 comment | 115 complexity | 3f6f07ed038905a9db758f957c19bff0 MD5 | raw file
  1. <?php
  2. /**
  3. * This file is used in conjunction with the '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('DEMO_GROUP', '4010474');
  92. define('DEMO_GROUP_NAME', 'Simple LI Demo');
  93. define('PORT_HTTP', '80');
  94. define('PORT_HTTP_SSL', '443');
  95. define('UPDATE_COUNT', 10);
  96. // set index
  97. $_REQUEST[LINKEDIN::_GET_TYPE] = (isset($_REQUEST[LINKEDIN::_GET_TYPE])) ? $_REQUEST[LINKEDIN::_GET_TYPE] : '';
  98. switch($_REQUEST[LINKEDIN::_GET_TYPE]) {
  99. case 'initiate':
  100. /**
  101. * Handle user initiated LinkedIn connection, create the LinkedIn object.
  102. */
  103. // check for the correct http protocol (i.e. is this script being served via http or https)
  104. if($_SERVER['HTTPS'] == 'on') {
  105. $protocol = 'https';
  106. } else {
  107. $protocol = 'http';
  108. }
  109. // set the callback url
  110. $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';
  111. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  112. // check for response from LinkedIn
  113. $_GET[LINKEDIN::_GET_RESPONSE] = (isset($_GET[LINKEDIN::_GET_RESPONSE])) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
  114. if(!$_GET[LINKEDIN::_GET_RESPONSE]) {
  115. // LinkedIn hasn't sent us a response, the user is initiating the connection
  116. // send a request for a LinkedIn access token
  117. $response = $OBJ_linkedin->retrieveTokenRequest();
  118. if($response['success'] === TRUE) {
  119. // store the request token
  120. $_SESSION['oauth']['linkedin']['request'] = $response['linkedin'];
  121. // redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
  122. header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
  123. } else {
  124. // bad token request
  125. 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>";
  126. }
  127. } else {
  128. // 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
  129. $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
  130. if($response['success'] === TRUE) {
  131. // the request went through without an error, gather user's 'access' tokens
  132. $_SESSION['oauth']['linkedin']['access'] = $response['linkedin'];
  133. // set the user as authorized for future quick reference
  134. $_SESSION['oauth']['linkedin']['authorized'] = TRUE;
  135. // redirect the user back to the demo page
  136. header('Location: ' . $_SERVER['PHP_SELF']);
  137. } else {
  138. // bad token access
  139. 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>";
  140. }
  141. }
  142. break;
  143. case 'revoke':
  144. /**
  145. * Handle authorization revocation.
  146. */
  147. // check the session
  148. if(!oauth_session_exists()) {
  149. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  150. }
  151. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  152. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  153. $response = $OBJ_linkedin->revoke();
  154. if($response['success'] === TRUE) {
  155. // revocation successful, clear session
  156. session_unset();
  157. $_SESSION = array();
  158. if(session_destroy()) {
  159. // session destroyed
  160. header('Location: ' . $_SERVER['PHP_SELF']);
  161. } else {
  162. // session not destroyed
  163. echo "Error clearing user's session";
  164. }
  165. } else {
  166. // revocation failed
  167. 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>";
  168. }
  169. break;
  170. case 'createPost':
  171. /**
  172. * Handle create post requests.
  173. */
  174. // check the session
  175. if(!oauth_session_exists()) {
  176. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  177. }
  178. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  179. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  180. if(!empty($_POST['title'])) {
  181. $response = $OBJ_linkedin->createPost(DEMO_GROUP, $_POST['title'], (empty($_POST['summary']) ? '' : $_POST['summary']));
  182. if($response['success'] === TRUE) {
  183. header('Location: ' . $_SERVER['PHP_SELF']);
  184. } else {
  185. echo "Error creating post: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  186. }
  187. } else {
  188. echo "Error creating post: The title must be specified.";
  189. }
  190. break;
  191. case 'deletePost':
  192. /**
  193. * Handle delete post requests.
  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 ($_GET['nPostId'])) {
  202. $response = $OBJ_linkedin->deletePost($_GET['nPostId']);
  203. if($response['success'] === TRUE) {
  204. header('Location: ' . $_SERVER['PHP_SELF']);
  205. } else {
  206. echo "Error deleting/flagging post: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  207. }
  208. } else {
  209. echo "Error deleting/flagging post: The post id must be specified.";
  210. }
  211. break;
  212. case 'flagPost':
  213. /**
  214. * Handle flag post requests.
  215. */
  216. // check the session
  217. if(!oauth_session_exists()) {
  218. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  219. }
  220. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  221. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  222. if((!empty($_GET['nPostId'])) && (!empty($_GET['nType']))) {
  223. if($_GET['nType'] == 'job' || $_GET['nType'] == 'promotion') {
  224. $response = $OBJ_linkedin->flagPost($_GET['nPostId'], $_GET['nType']);
  225. if($response['success'] === TRUE) {
  226. header('Location: ' . $_SERVER['PHP_SELF']);
  227. } else {
  228. echo "Error flagging post: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  229. }
  230. } else {
  231. echo "Error flagging post: The given type must be one of: job, promotion.";
  232. }
  233. } else {
  234. echo "Error flagging post: The post id and flag type must be specified.";
  235. }
  236. break;
  237. case 'followPost':
  238. /**
  239. * Handle follow post requests.
  240. */
  241. // check the session
  242. if(!oauth_session_exists()) {
  243. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  244. }
  245. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  246. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  247. if(!empty($_GET['nPostId'])) {
  248. $response = $OBJ_linkedin->followPost($_GET['nPostId'], TRUE);
  249. if($response['success'] === TRUE) {
  250. header('Location: ' . $_SERVER['PHP_SELF']);
  251. } else {
  252. echo "Error following post: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  253. }
  254. } else {
  255. echo "Error following post: The post id must be specified.";
  256. }
  257. break;
  258. case 'joinGroup':
  259. /**
  260. * Handle group join requests.
  261. */
  262. // check the session
  263. if(!oauth_session_exists()) {
  264. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  265. }
  266. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  267. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  268. $response = $OBJ_linkedin->joinGroup($_GET['nGroupId']);
  269. if($response['success'] === TRUE) {
  270. header('Location: ' . $_SERVER['PHP_SELF']);
  271. } else {
  272. echo "Error joining group: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  273. }
  274. break;
  275. case 'leaveGroup':
  276. /**
  277. * Handle group leave requests.
  278. */
  279. // check the session
  280. if(!oauth_session_exists()) {
  281. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  282. }
  283. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  284. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  285. $response = $OBJ_linkedin->leaveGroup($_GET['nGroupId']);
  286. if($response['success'] === TRUE) {
  287. header('Location: ' . $_SERVER['PHP_SELF']);
  288. } else {
  289. echo "Error leaving group: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  290. }
  291. break;
  292. case 'likePost':
  293. /**
  294. * Handle like post requests.
  295. */
  296. // check the session
  297. if(!oauth_session_exists()) {
  298. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  299. }
  300. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  301. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  302. if(!empty($_GET['nPostId'])) {
  303. $response = $OBJ_linkedin->likePost($_GET['nPostId'], TRUE);
  304. if($response['success'] === TRUE) {
  305. header('Location: ' . $_SERVER['PHP_SELF']);
  306. } else {
  307. echo "Error liking post: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  308. }
  309. } else {
  310. echo "Error liking post: The post id must be specified.";
  311. }
  312. break;
  313. case 'removeSuggestedGroup':
  314. /**
  315. * Handle remove suggested group requests.
  316. */
  317. // check the session
  318. if(!oauth_session_exists()) {
  319. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  320. }
  321. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  322. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  323. if(!empty($_GET['nGroupId'])) {
  324. $response = $OBJ_linkedin->removeSuggestedGroup($_GET['nGroupId']);
  325. if($response['success'] === TRUE) {
  326. header('Location: ' . $_SERVER['PHP_SELF']);
  327. } else {
  328. echo "Error removing suggested group: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  329. }
  330. } else {
  331. echo "Error removing suggested group: The group id must be specified.";
  332. }
  333. break;
  334. case 'unlikePost':
  335. /**
  336. * Handle unlike post requests.
  337. */
  338. // check the session
  339. if(!oauth_session_exists()) {
  340. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  341. }
  342. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  343. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  344. if(!empty($_GET['nPostId'])) {
  345. $response = $OBJ_linkedin->likePost($_GET['nPostId'], FALSE);
  346. if($response['success'] === TRUE) {
  347. header('Location: ' . $_SERVER['PHP_SELF']);
  348. } else {
  349. echo "Error unliking post: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  350. }
  351. } else {
  352. echo "Error unliking post: The post id must be specified.";
  353. }
  354. break;
  355. case 'unfollowPost':
  356. /**
  357. * Handle unfollow post requests.
  358. */
  359. // check the session
  360. if(!oauth_session_exists()) {
  361. throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
  362. }
  363. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  364. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  365. if(!empty($_GET['nPostId'])) {
  366. $response = $OBJ_linkedin->followPost($_GET['nPostId'], FALSE);
  367. if($response['success'] === TRUE) {
  368. header('Location: ' . $_SERVER['PHP_SELF']);
  369. } else {
  370. echo "Error unfollowing post: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
  371. }
  372. } else {
  373. echo "Error unfollowing post: The post id must be specified.";
  374. }
  375. break;
  376. default:
  377. // nothing being passed back, display demo page
  378. // check PHP version
  379. if(version_compare(PHP_VERSION, '5.0.0', '<')) {
  380. throw new LinkedInException('You must be running version 5.x or greater of PHP to use this library.');
  381. }
  382. // check for cURL
  383. if(extension_loaded('curl')) {
  384. $curl_version = curl_version();
  385. $curl_version = $curl_version['version'];
  386. } else {
  387. throw new LinkedInException('You must load the cURL extension to use this library.');
  388. }
  389. ?>
  390. <!DOCTYPE html>
  391. <html lang="en">
  392. <head>
  393. <title>Simple-LinkedIn Demo &gt; Groups</title>
  394. <meta charset="utf-8" />
  395. <meta name="viewport" content="width=device-width" />
  396. <meta name="description" content="A demonstration page for the Simple-LinkedIn PHP class." />
  397. <meta name="keywords" content="simple-linkedin,php,linkedin,api,class,library" />
  398. <style>
  399. body {font-family: Courier, monospace; font-size: 0.8em;}
  400. footer {margin-top: 2em; text-align: center;}
  401. pre {font-family: Courier, monospace; font-size: 0.8em;}
  402. </style>
  403. </head>
  404. <body>
  405. <h1><a href="/demo.php">Simple-LinkedIn Demo</a> &gt; <a href="<?php echo $_SERVER['PHP_SELF'];?>">Groups</a></h1>
  406. <p>Copyright 2010 - 2011, Paul Mennega, fiftyMission Inc. &lt;paul@fiftymission.net&gt;</p>
  407. <p>Released under the MIT License - http://www.opensource.org/licenses/mit-license.php</p>
  408. <p>Full source code for both the Simple-LinkedIn class and this demo script can be found at:</p>
  409. <ul>
  410. <li><a href="http://code.google.com/p/simple-linkedinphp/">http://code.google.com/p/simple-linkedinphp/</a></li>
  411. </ul>
  412. <hr />
  413. <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>
  414. <ul>
  415. <li>Please note: The Simple-LinkedIn class requires PHP 5+</li>
  416. </ul>
  417. <hr />
  418. <?php
  419. $_SESSION['oauth']['linkedin']['authorized'] = (isset($_SESSION['oauth']['linkedin']['authorized'])) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE;
  420. if($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
  421. // user is already connected
  422. $OBJ_linkedin = new LinkedIn($API_CONFIG);
  423. $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
  424. $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML);
  425. // check if the viewer is a member of the test group
  426. $response = $OBJ_linkedin->group(DEMO_GROUP, ':(relation-to-viewer:(membership-state))');
  427. if($response['success'] === TRUE) {
  428. $result = new SimpleXMLElement($response['linkedin']);
  429. $membership = $result->{'relation-to-viewer'}->{'membership-state'}->code;
  430. $in_demo_group = (($membership == 'non-member') || ($membership == 'blocked')) ? FALSE : TRUE;
  431. ?>
  432. <ul>
  433. <li><a href="#manage">Manage LinkedIn Authorization</a></li>
  434. <li><a href="../demo.php#application">Application Information</a></li>
  435. <li><a href="../demo.php#profile">Your Profile</a></li>
  436. <li><a href="#groups">Groups API</a>
  437. <ul>
  438. <li><a href="#groupMemberships">Group Memberships</a></li>
  439. <li><a href="#groupsSuggested">Suggested Groups</a></li>
  440. <li><a href="#manageGroup">Manage '<?php echo DEMO_GROUP_NAME;?>' Group Membership</a></li>
  441. <?php
  442. if($in_demo_group) {
  443. ?>
  444. <li><a href="#groupSettings">Group Settings</a></li>
  445. <li><a href="#groupPosts">Group Posts</a></li>
  446. <li><a href="#createPost">Create a Group Post</a></li>
  447. <?php
  448. }
  449. ?>
  450. </ul>
  451. </li>
  452. </ul>
  453. <?php
  454. } else {
  455. echo "Error retrieving group membership information: <br /><br />RESPONSE:<br /><br /><pre>" . print_r ($response, TRUE) . "</pre>";
  456. }
  457. } else {
  458. ?>
  459. <ul>
  460. <li><a href="#manage">Manage LinkedIn Authorization</a></li>
  461. </ul>
  462. <?php
  463. }
  464. ?>
  465. <hr />
  466. <h2 id="manage">Manage LinkedIn Authorization:</h2>
  467. <?php
  468. if($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
  469. ?>
  470. <form id="linkedin_revoke_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  471. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="revoke" />
  472. <input type="submit" value="Revoke Authorization" />
  473. </form>
  474. <hr />
  475. <h2 id="groups">Groups API:</h2>
  476. <h3 id="groupMemberships">Groups Memberships:</h3>
  477. <p>Groups you are a member of:</p>
  478. <?php
  479. $response = $OBJ_linkedin->groupMemberships();
  480. if($response['success'] === TRUE) {
  481. $groups = new SimpleXMLElement($response['linkedin']);
  482. if((int)$groups['total'] > 0) {
  483. foreach($groups as $group) {
  484. $gid = $group->group->id;
  485. $group_name = $group->group->name;
  486. ?>
  487. <div style=""><span style="font-weight: bold;"><?php echo $group_name;?></span>
  488. <div style="margin: 0.5em 0 1em 2em;">
  489. <a href="<?php echo $_SERVER['PHP_SELF'];?>?<?php echo LINKEDIN::_GET_TYPE;?>=leaveGroup&amp;nGroupId=<?php echo $gid;?>#groupMemberships">Leave</a>
  490. </div>
  491. <?php
  492. }
  493. } else {
  494. // no group memberships
  495. echo '<div>You are not currently the member of any groups.</div>';
  496. }
  497. } else {
  498. // request failed
  499. echo "Error retrieving groups memberships: <br /><br />RESPONSE:<br /><br /><pre>" . print_r ($response, TRUE) . "</pre>";
  500. }
  501. ?>
  502. <hr />
  503. <h3 id="groupsSuggested">Suggested Groups:</h3>
  504. <p>Groups that LinkedIn thinks you might be interested in:</p>
  505. <?php
  506. $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML);
  507. $response = $OBJ_linkedin->suggestedGroups();
  508. if($response['success'] === TRUE) {
  509. $suggested = new SimpleXMLElement($response['linkedin']);
  510. $count = 1;
  511. foreach($suggested as $group) {
  512. $gid = (string)$group->id;
  513. $group_name = $group->name;
  514. $group_open = ($group->{'is-open-to-non-members'} == 'true') ? TRUE : FALSE;
  515. ?>
  516. <div><span style="font-weight: bold;"><?php echo $group_name . ' (' . (($group_open) ? '' : 'not') . ' open to non-members)';?></span></div>
  517. <?php
  518. if($count == 1) {
  519. $response = $OBJ_linkedin->group($gid, ':(id,name,short-description,relation-to-viewer:(membership-state,available-actions),is-open-to-non-members,category,contact-email)');
  520. if($response['success'] === TRUE) {
  521. echo '<h4>Group Details:</h4>
  522. <pre>' . print_r(new SimpleXMLElement($response['linkedin']), TRUE) . '</pre>';
  523. } else {
  524. // request failed
  525. echo "Error retrieving groups detailed information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, true) . "</pre>";
  526. }
  527. }
  528. ?>
  529. <div style="margin: 0.5em 0 1em 2em;">
  530. <a href="<?php echo $_SERVER['PHP_SELF'];?>?<?php echo LINKEDIN::_GET_TYPE;?>=joinGroup&amp;nGroupId=<?php echo $gid;?>#groupsSuggested">Join</a>
  531. <a href="<?php echo $_SERVER['PHP_SELF'];?>?<?php echo LINKEDIN::_GET_TYPE;?>=removeSuggestedGroup&amp;nGroupId=<?php echo $gid;?>#groupsSuggested">Remove</a>
  532. </div>
  533. <?php
  534. $count++;
  535. }
  536. } else {
  537. // request failed
  538. echo "Error retrieving groups suggestions: <br /><br />RESPONSE:<br /><br /><pre>" . print_r ($response, TRUE) . "</pre>";
  539. }
  540. ?>
  541. <hr />
  542. <h3 id="manageGroup">Manage '<?php echo DEMO_GROUP_NAME;?>' Group Membership</h3>
  543. <?php
  544. if($in_demo_group) {
  545. // viewer is a member of the test group
  546. ?>
  547. <form id="linkedin_connect_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  548. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="leaveGroup" />
  549. <input type="hidden" name="nGroupId" id="nGroupId" value="<php echo DEMO_GROUP;?>" />
  550. <input type="submit" value="Leave '<?php echo DEMO_GROUP_NAME;?>' Group" />
  551. </form>
  552. <hr />
  553. <h3 id="groupSettings">Group Settings for '<?php echo DEMO_GROUP_NAME;?>' Group</h3>
  554. <?php
  555. $response = $OBJ_linkedin->groupSettings(DEMO_GROUP, ':(show-group-logo-in-profile,contact-email,email-digest-frequency,email-announcements-from-managers,allow-messages-from-members,email-for-every-new-post)');
  556. if($response['success'] === TRUE) {
  557. $settings = new SimpleXMLElement($response['linkedin']);
  558. $show_logo = $settings->{'show-group-logo-in-profile'};
  559. $digest = $settings->{'email-digest-frequency'}->code;
  560. $announcements = $settings->{'email-announcements-from-managers'};
  561. $messages = $settings->{'allow-messages-from-members'};
  562. $new_post = $settings->{'email-for-every-new-post'};
  563. ?>
  564. <div>Show Logo in Profile: <?php echo $show_logo;?></div>
  565. <div>Email for Every New Post: <?php echo $new_post;?></div>
  566. <div>Email Announcements from Managers: <?php echo $announcements;?></div>
  567. <div>Allow messages from Group Members: <?php echo $messages;?></div>
  568. <div>Digest Email Frequency: <?php echo $digest;?></div>
  569. <?php
  570. } else {
  571. // request failed
  572. echo "Error retrieving group settings:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  573. }
  574. ?>
  575. <hr />
  576. <h3 id="groupPosts">'<?php echo DEMO_GROUP_NAME;?>' Group Discussions</h3>
  577. <?php
  578. $post_cats = array('discussion', 'job', 'promotion');
  579. foreach($post_cats as $post_cat) {
  580. echo '<h4>' . ucfirst($post_cat) . 's</h4>';
  581. $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML);
  582. $count = 1;
  583. $response = $OBJ_linkedin->groupPosts(DEMO_GROUP, ':(id,creator:(first-name,last-name),title,summary)?order=recency&category=' . $post_cat);
  584. if($response['success'] === TRUE){
  585. $posts = new SimpleXMLElement($response['linkedin']);
  586. if((int)$posts['total']) {
  587. echo '<ol>';
  588. foreach($posts as $post) {
  589. echo '<li>';
  590. $pid = (string)$post->id;
  591. $title = $post->title;
  592. $summary = $post->summary;
  593. $first_name = $post->creator->{'first-name'};
  594. $last_name = $post->creator->{'last-name'};
  595. $creator = $first_name . ' ' . $last_name;
  596. $response = $OBJ_linkedin->groupPost((string)$pid, ":(relation-to-viewer:(is-liked,is-following))");
  597. if($response['success'] === TRUE) {
  598. $post_info = new SimpleXMLElement($response['linkedin']);
  599. $like = ($post_info->{'relation-to-viewer'}->{'is-liked'} == 'true') ? TRUE : FALSE;
  600. $follow = ($post_info->{'relation-to-viewer'}->{'is-following'} == 'true') ? TRUE : FALSE;
  601. ?>
  602. <div><?php echo '<span style="font-weight: bold;">Title:</span> ' . $title;?></div>
  603. <div><?php echo '<span style="font-weight: bold;">Summary:</span> ' . $summary;?></div>
  604. <div><?php echo '<span style="font-weight: bold;">Creator:</span> ' . $creator;?></div>
  605. <div><?php echo '<span style="font-weight: bold;">Post ID:</span> ' . $pid;?></div>
  606. <?php
  607. if($count == 1) {
  608. $response = $OBJ_linkedin->groupPostComments($pid, ':(id,text,creator:(first-name,last-name))');
  609. if($response['success'] === TRUE) {
  610. echo '<h2>Comments:</h2><pre>' . print_r(new SimpleXMLElement($response['linkedin']), TRUE) . '</pre>';
  611. } else {
  612. echo "Error retrieving group post comments:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  613. }
  614. }
  615. ?>
  616. <div style="margin: 0.5em 0 1em 2em;">
  617. <a href="<?php echo $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=' . (($like) ? 'unlikePost' : 'likePost') . '&nPostId='.$pid;?>#groupPosts"><?php echo ($like) ? 'Unlike' : 'Like';?></a>
  618. <a href="<?php echo $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=' . (($follow) ? 'unfollowPost' : 'followPost') . '&nPostId='.$pid;?>#groupPosts"><?php echo ($follow) ? 'Unfollow' : 'Follow';?></a>
  619. <a href="<?php echo $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=flagPost&nType=job&nPostId=' . $pid;?>#groupPosts">Flag as Job</a>
  620. <a href="<?php echo $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=flagPost&nType=promotion&nPostId=' . $pid;?>#groupPosts">Flag as Promotion</a>
  621. <a href="<?php echo $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=deletePost&nPostId=' . $pid;?>#groupPosts">Delete/Flag as Inappropriate</a>
  622. </div>
  623. <?php
  624. } else {
  625. // request failed
  626. echo "Error retrieving additional post information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
  627. }
  628. $count++;
  629. echo '</li>';
  630. }
  631. echo '</ol>';
  632. } else {
  633. echo 'There are no ' . $post_cat . 's.';
  634. }
  635. }
  636. }
  637. ?>
  638. <hr />
  639. <h3 id="createPost">Create a Post in the '<?php echo DEMO_GROUP_NAME;?>' Group:</h3>
  640. <form id="create_post_form" action="<?php echo $_SERVER['PHP_SELF'];?>#createPost" method="post">
  641. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="createPost" />
  642. <div style="font-weight: bold;">Title:</div>
  643. <input type="text" name="title" id="title" length="255" maxlength="255" style="display: block; width: 400px;" />
  644. <div style="font-weight: bold;">Summary:</div>
  645. <textarea name="summary" id="summary" rows="4" style="display: block; width: 400px;"></textarea>
  646. <input type="submit" value="Create Post" />
  647. </form>
  648. <?php
  649. } else {
  650. // user isn't a member
  651. ?>
  652. <hr />
  653. <form id="linkedin_join_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  654. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="joinGroup" />
  655. <input type="submit" value="Join '<?php echo DEMO_GROUP_NAME;?>' Group" />
  656. </form>
  657. <?php
  658. }
  659. } else {
  660. // user isn't connected
  661. ?>
  662. <form id="linkedin_connect_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  663. <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE;?>" id="<?php echo LINKEDIN::_GET_TYPE;?>" value="initiate" />
  664. <input type="submit" value="Connect to LinkedIn" />
  665. </form>
  666. <?php
  667. }
  668. ?>
  669. <footer>
  670. <div>Copyright 2010 - 2011, fiftyMission Inc. (Paul Mennega &lt;<a href="mailto:paul@fiftymission.net">paul@fiftymission.net</a>&gt;)</div>
  671. <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>
  672. </footer>
  673. </body>
  674. </html>
  675. <?php
  676. break;
  677. }
  678. } catch(LinkedInException $e) {
  679. // exception raised by library call
  680. echo $e->getMessage();
  681. }
  682. ?>