PageRenderTime 60ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/libraries/joomla/linkedin/people.php

https://bitbucket.org/ke2083/transfans.co.uk-website
PHP | 387 lines | 209 code | 63 blank | 115 comment | 47 complexity | 58d51847577dde3059ecf28cadbecdd7 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Linkedin
  5. *
  6. * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die();
  10. /**
  11. * Linkedin API People class for the Joomla Platform.
  12. *
  13. * @since 3.2.0
  14. */
  15. class JLinkedinPeople extends JLinkedinObject
  16. {
  17. /**
  18. * Method to get a member's profile.
  19. *
  20. * @param string $id Member id of the profile you want.
  21. * @param string $url The public profile URL.
  22. * @param string $fields Request fields beyond the default ones.
  23. * @param string $type Choosing public or standard profile.
  24. * @param string $language A comma separated list of locales ordered from highest to lowest preference.
  25. *
  26. * @return array The decoded JSON response
  27. *
  28. * @since 3.2.0
  29. */
  30. public function getProfile($id = null, $url = null, $fields = null, $type = 'standard', $language = null)
  31. {
  32. $token = $this->oauth->getToken();
  33. // Set parameters.
  34. $parameters = array(
  35. 'oauth_token' => $token['key'],
  36. );
  37. // Set the API base
  38. $base = '/v1/people/';
  39. $data['format'] = 'json';
  40. // Check if a member id is specified.
  41. if ($id)
  42. {
  43. $base .= 'id=' . $id;
  44. }
  45. elseif (!$url)
  46. {
  47. $base .= '~';
  48. }
  49. // Check if profile url is specified.
  50. if ($url)
  51. {
  52. $base .= 'url=' . $this->oauth->safeEncode($url);
  53. // Choose public profile
  54. if (!strcmp($type, 'public'))
  55. {
  56. $base .= ':public';
  57. }
  58. }
  59. // Check if fields is specified.
  60. if ($fields)
  61. {
  62. $base .= ':' . $fields;
  63. }
  64. // Check if language is specified.
  65. $header = array();
  66. if ($language)
  67. {
  68. $header = array('Accept-Language' => $language);
  69. }
  70. // Build the request path.
  71. $path = $this->getOption('api.url') . $base;
  72. // Send the request.
  73. $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data, $header);
  74. return json_decode($response->body);
  75. }
  76. /**
  77. * Method to get a list of connections for a user who has granted access to his/her account.
  78. *
  79. * @param string $fields Request fields beyond the default ones.
  80. * @param integer $start Starting location within the result set for paginated returns.
  81. * @param integer $count The number of results returned.
  82. * @param string $modified Values are updated or new.
  83. * @param string $modified_since Value as a Unix time stamp of milliseconds since epoch.
  84. *
  85. * @return array The decoded JSON response
  86. *
  87. * @since 3.2.0
  88. */
  89. public function getConnections($fields = null, $start = 0, $count = 500, $modified = null, $modified_since = null)
  90. {
  91. $token = $this->oauth->getToken();
  92. // Set parameters.
  93. $parameters = array(
  94. 'oauth_token' => $token['key'],
  95. );
  96. // Set the API base
  97. $base = '/v1/people/~/connections';
  98. $data['format'] = 'json';
  99. // Check if fields is specified.
  100. if ($fields)
  101. {
  102. $base .= ':' . $fields;
  103. }
  104. // Check if start is specified.
  105. if ($start > 0)
  106. {
  107. $data['start'] = $start;
  108. }
  109. // Check if count is specified.
  110. if ($count != 500)
  111. {
  112. $data['count'] = $count;
  113. }
  114. // Check if modified is specified.
  115. if ($modified)
  116. {
  117. $data['modified'] = $modified;
  118. }
  119. // Check if modified_since is specified.
  120. if ($modified_since)
  121. {
  122. $data['modified-since'] = $modified_since;
  123. }
  124. // Build the request path.
  125. $path = $this->getOption('api.url') . $base;
  126. // Send the request.
  127. $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
  128. return json_decode($response->body);
  129. }
  130. /**
  131. * Method to get information about people.
  132. *
  133. * @param string $fields Request fields beyond the default ones. provide 'api-standard-profile-request'
  134. * field for out of network profiles.
  135. * @param string $keywords Members who have all the keywords anywhere in their profile.
  136. * @param string $first_name Members with a matching first name. Matches must be exact.
  137. * @param string $last_name Members with a matching last name. Matches must be exactly.
  138. * @param string $company_name Members who have a matching company name on their profile.
  139. * @param boolean $current_company A value of true matches members who currently work at the company specified in the company-name
  140. * parameter.
  141. * @param string $title Matches members with that title on their profile.
  142. * @param boolean $current_title A value of true matches members whose title is currently the one specified in the title-name parameter.
  143. * @param string $school_name Members who have a matching school name on their profile.
  144. * @param string $current_school A value of true matches members who currently attend the school specified in the school-name parameter.
  145. * @param string $country_code Matches members with a location in a specific country. Values are defined in by ISO 3166 standard.
  146. * Country codes must be in all lower case.
  147. * @param integer $postal_code Matches members centered around a Postal Code. Must be combined with the country-code parameter.
  148. * Not supported for all countries.
  149. * @param integer $distance Matches members within a distance from a central point. This is measured in miles.
  150. * @param string $facets Facet buckets to return, e.g. location.
  151. * @param array $facet Array of facet values to search over. Contains values for location, industry, network, language,
  152. * current-company, past-company and school, in exactly this order, null must be specified for an element if no value.
  153. * @param integer $start Starting location within the result set for paginated returns.
  154. * @param integer $count The number of results returned.
  155. * @param string $sort Controls the search result order. There are four options: connections, recommenders,
  156. * distance and relevance.
  157. *
  158. * @return array The decoded JSON response
  159. *
  160. * @since 3.2.0
  161. */
  162. public function search($fields = null, $keywords = null, $first_name = null, $last_name = null, $company_name = null,
  163. $current_company = null, $title = null, $current_title = null, $school_name = null, $current_school = null, $country_code = null,
  164. $postal_code = null, $distance = null, $facets = null, $facet = null, $start = 0, $count = 10, $sort = null)
  165. {
  166. $token = $this->oauth->getToken();
  167. // Set parameters.
  168. $parameters = array(
  169. 'oauth_token' => $token['key'],
  170. );
  171. // Set the API base
  172. $base = '/v1/people-search';
  173. $data['format'] = 'json';
  174. // Check if fields is specified.
  175. if ($fields)
  176. {
  177. $base .= ':' . $fields;
  178. }
  179. // Check if keywords is specified.
  180. if ($keywords)
  181. {
  182. $data['keywords'] = $keywords;
  183. }
  184. // Check if first_name is specified.
  185. if ($first_name)
  186. {
  187. $data['first-name'] = $first_name;
  188. }
  189. // Check if last_name is specified.
  190. if ($last_name)
  191. {
  192. $data['last-name'] = $last_name;
  193. }
  194. // Check if company-name is specified.
  195. if ($company_name)
  196. {
  197. $data['company-name'] = $company_name;
  198. }
  199. // Check if current_company is specified.
  200. if ($current_company)
  201. {
  202. $data['current-company'] = $current_company;
  203. }
  204. // Check if title is specified.
  205. if ($title)
  206. {
  207. $data['title'] = $title;
  208. }
  209. // Check if current_title is specified.
  210. if ($current_title)
  211. {
  212. $data['current-title'] = $current_title;
  213. }
  214. // Check if school_name is specified.
  215. if ($school_name)
  216. {
  217. $data['school-name'] = $school_name;
  218. }
  219. // Check if current_school is specified.
  220. if ($current_school)
  221. {
  222. $data['current-school'] = $current_school;
  223. }
  224. // Check if country_code is specified.
  225. if ($country_code)
  226. {
  227. $data['country-code'] = $country_code;
  228. }
  229. // Check if postal_code is specified.
  230. if ($postal_code)
  231. {
  232. $data['postal-code'] = $postal_code;
  233. }
  234. // Check if distance is specified.
  235. if ($distance)
  236. {
  237. $data['distance'] = $distance;
  238. }
  239. // Check if facets is specified.
  240. if ($facets)
  241. {
  242. $data['facets'] = $facets;
  243. }
  244. // Check if facet is specified.
  245. if ($facet)
  246. {
  247. $data['facet'] = array();
  248. for ($i = 0, $iMax = count($facet); $i < $iMax; $i++)
  249. {
  250. if ($facet[$i])
  251. {
  252. if ($i == 0)
  253. {
  254. $data['facet'][] = 'location,' . $facet[$i];
  255. }
  256. if ($i == 1)
  257. {
  258. $data['facet'][] = 'industry,' . $facet[$i];
  259. }
  260. if ($i == 2)
  261. {
  262. $data['facet'][] = 'network,' . $facet[$i];
  263. }
  264. if ($i == 3)
  265. {
  266. $data['facet'][] = 'language,' . $facet[$i];
  267. }
  268. if ($i == 4)
  269. {
  270. $data['facet'][] = 'current-company,' . $facet[$i];
  271. }
  272. if ($i == 5)
  273. {
  274. $data['facet'][] = 'past-company,' . $facet[$i];
  275. }
  276. if ($i == 6)
  277. {
  278. $data['facet'][] = 'school,' . $facet[$i];
  279. }
  280. }
  281. }
  282. }
  283. // Check if start is specified.
  284. if ($start > 0)
  285. {
  286. $data['start'] = $start;
  287. }
  288. // Check if count is specified.
  289. if ($count != 10)
  290. {
  291. $data['count'] = $count;
  292. }
  293. // Check if sort is specified.
  294. if ($sort)
  295. {
  296. $data['sort'] = $sort;
  297. }
  298. // Build the request path.
  299. $path = $this->getOption('api.url') . $base;
  300. // Send the request.
  301. $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
  302. if (strpos($fields, 'api-standard-profile-request') === false)
  303. {
  304. return json_decode($response->body);
  305. }
  306. // Get header name.
  307. $name = explode('"name": "', $response->body);
  308. $name = explode('"', $name[1]);
  309. $name = $name[0];
  310. // Get header value.
  311. $value = explode('"value": "', $response->body);
  312. $value = explode('"', $value[1]);
  313. $value = $value[0];
  314. // Get request url.
  315. $url = explode('"url": "', $response->body);
  316. $url = explode('"', $url[1]);
  317. $url = $url[0];
  318. // Build header for out of network profile.
  319. $header[$name] = $value;
  320. // Send the request.
  321. $response = $this->oauth->oauthRequest($url, 'GET', $parameters, $data, $header);
  322. return json_decode($response->body);
  323. }
  324. }