Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
communications.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Linkedin
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die();
11 
12 /**
13  * Linkedin API Social Communications class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Linkedin
17  * @since 13.1
18  */
20 {
21  /**
22  * Method used to invite people.
23  *
24  * @param string $email A string containing email of the recipient.
25  * @param string $first_name A string containing frist name of the recipient.
26  * @param string $last_name A string containing last name of the recipient.
27  * @param string $subject The subject of the message that will be sent to the recipient
28  * @param string $body A text of the message.
29  * @param string $connection Only connecting as a 'friend' is supported presently.
30  *
31  * @return array The decoded JSON response
32  *
33  * @since 13.1
34  */
35  public function inviteByEmail($email, $first_name, $last_name, $subject, $body, $connection = 'friend')
36  {
37  $token = $this->oauth->getToken();
38 
39  // Set parameters.
40  $parameters = array(
41  'oauth_token' => $token['key']
42  );
43 
44  // Set the success response code.
45  $this->oauth->setOption('success_code', 201);
46 
47  // Set the API base.
48  $base = '/v1/people/~/mailbox';
49 
50  // Build the xml.
51  $xml = '<mailbox-item>
52  <recipients>
53  <recipient>
54  <person path="/people/email=' . $email . '">
55  <first-name>' . $first_name . '</first-name>
56  <last-name>' . $last_name . '</last-name>
57  </person>
58  </recipient>
59  </recipients>
60  <subject>' . $subject . '</subject>
61  <body>' . $body . '</body>
62  <item-content>
63  <invitation-request>
64  <connect-type>' . $connection . '</connect-type>
65  </invitation-request>
66  </item-content>
67  </mailbox-item>';
68 
69  $header['Content-Type'] = 'text/xml';
70 
71  // Build the request path.
72  $path = $this->getOption('api.url') . $base;
73 
74  // Send the request.
75  $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
76 
77  return $response;
78  }
79 
80  /**
81  * Method used to invite people.
82  *
83  * @param string $id Member id.
84  * @param string $first_name A string containing frist name of the recipient.
85  * @param string $last_name A string containing last name of the recipient.
86  * @param string $subject The subject of the message that will be sent to the recipient
87  * @param string $body A text of the message.
88  * @param string $connection Only connecting as a 'friend' is supported presently.
89  *
90  * @return array The decoded JSON response
91  *
92  * @since 13.1
93  */
94  public function inviteById($id, $first_name, $last_name, $subject, $body, $connection = 'friend')
95  {
96  $token = $this->oauth->getToken();
97 
98  // Set parameters.
99  $parameters = array(
100  'oauth_token' => $token['key']
101  );
102 
103  // Set the API base for people search.
104  $base = '/v1/people-search:(people:(api-standard-profile-request))';
105 
106  $data['format'] = 'json';
107  $data['first-name'] = $first_name;
108  $data['last-name'] = $last_name;
109 
110  // Build the request path.
111  $path = $this->getOption('api.url') . $base;
112 
113  // Send the request.
114  $response = $this->oauth->oauthRequest($path, 'GET', $parameters, $data);
115 
116  if (strpos($response->body, 'apiStandardProfileRequest') === false)
117  {
118  throw new RuntimeException($response->body);
119  }
120 
121  // Get header value.
122  $value = explode('"value": "', $response->body);
123  $value = explode('"', $value[1]);
124  $value = $value[0];
125 
126  // Split on the colon character.
127  $value = explode(':', $value);
128  $name = $value[0];
129  $value = $value[1];
130 
131  // Set the success response code.
132  $this->oauth->setOption('success_code', 201);
133 
134  // Set the API base.
135  $base = '/v1/people/~/mailbox';
136 
137  // Build the xml.
138  $xml = '<mailbox-item>
139  <recipients>
140  <recipient>
141  <person path="/people/id=' . $id . '">
142  </person>
143  </recipient>
144  </recipients>
145  <subject>' . $subject . '</subject>
146  <body>' . $body . '</body>
147  <item-content>
148  <invitation-request>
149  <connect-type>' . $connection . '</connect-type>
150  <authorization>
151  <name>' . $name . '</name>
152  <value>' . $value . '</value>
153  </authorization>
154  </invitation-request>
155  </item-content>
156  </mailbox-item>';
157 
158  $header['Content-Type'] = 'text/xml';
159 
160  // Build the request path.
161  $path = $this->getOption('api.url') . $base;
162 
163  // Send the request.
164  $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
165 
166  return $response;
167  }
168 
169  /**
170  * Method used to send messages via LinkedIn between two or more individuals connected to the member sending the message..
171  *
172  * @param mixed $recipient A string containing the member id or an array of ids.
173  * @param string $subject The subject of the message that will be sent to the recipient
174  * @param string $body A text of the message.
175  *
176  * @return array The decoded JSON response
177  *
178  * @since 13.1
179  */
180  public function sendMessage($recipient, $subject, $body)
181  {
182  $token = $this->oauth->getToken();
183 
184  // Set parameters.
185  $parameters = array(
186  'oauth_token' => $token['key']
187  );
188 
189  // Set the success response code.
190  $this->oauth->setOption('success_code', 201);
191 
192  // Set the API base.
193  $base = '/v1/people/~/mailbox';
194 
195  // Build the xml.
196  $xml = '<mailbox-item>
197  <recipients>';
198 
199  if (is_array($recipient))
200  {
201  foreach ($recipient as $r)
202  {
203  $xml .= '<recipient>
204  <person path="/people/' . $r . '"/>
205  </recipient>';
206  }
207  }
208 
209  $xml .= '</recipients>
210  <subject>' . $subject . '</subject>
211  <body>' . $body . '</body>
212  </mailbox-item>';
213 
214  $header['Content-Type'] = 'text/xml';
215 
216  // Build the request path.
217  $path = $this->getOption('api.url') . $base;
218 
219  // Send the request.
220  $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
221 
222  return $response;
223  }
224 }