PageRenderTime 25ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/radio/class/lastfmapi/api/event.php

https://gitlab.com/matt-oakes/Online-Lastfm-Player
PHP | 294 lines | 201 code | 17 blank | 76 comment | 36 complexity | fbbcf87200eea3877ceed2a6936a55e1 MD5 | raw file
  1. <?php
  2. /**
  3. * File that stores api calls for event api calls
  4. * @package apicalls
  5. */
  6. /**
  7. * Allows access to the api requests relating to events
  8. * @package apicalls
  9. */
  10. class lastfmApiEvent extends lastfmApi {
  11. /**
  12. * Stores the config values set in the call
  13. * @access public
  14. * @var array
  15. */
  16. public $config;
  17. /**
  18. * Stores the auth variables used in all api calls
  19. * @access private
  20. * @var array
  21. */
  22. private $auth;
  23. /**
  24. * States if the user has full authentication to use api requests that modify data
  25. * @access private
  26. * @var boolean
  27. */
  28. private $fullAuth;
  29. /**
  30. * @param array $auth Passes the authentication variables
  31. * @param array $fullAuth A boolean value stating if the user has full authentication or not
  32. * @param array $config An array of config variables related to caching and other features
  33. */
  34. function __construct($auth, $fullAuth, $config) {
  35. $this->auth = $auth;
  36. $this->fullAuth = $fullAuth;
  37. $this->config = $config;
  38. }
  39. /**
  40. * Set a user's attendance status for an event. (Requires full auth)
  41. * @param array $methodVars An array with the following required values: <i>eventId</i>, <i>status (0=Attending, 1=Maybe attending, 2=Not attending)</i>
  42. * @return boolean
  43. */
  44. public function attend($methodVars) {
  45. // Only allow full authed calls
  46. if ( $this->fullAuth == TRUE ) {
  47. // Check for required variables
  48. if ( !empty($methodVars['event']) && !empty($methodVars['status']) ) {
  49. $vars = array(
  50. 'method' => 'event.attend',
  51. 'api_key' => $this->auth->apiKey,
  52. 'sk' => $this->auth->sessionKey
  53. );
  54. $vars = array_merge($vars, $methodVars);
  55. $sig = $this->apiSig($this->auth->secret, $vars);
  56. $vars['api_sig'] = $sig;
  57. if ( $call = $this->apiPostCall($vars) ) {
  58. return TRUE;
  59. }
  60. else {
  61. return FALSE;
  62. }
  63. }
  64. else {
  65. // Give a 91 error if incorrect variables are used
  66. $this->handleError(91, 'You must include eventId and status varialbes in the call for this method');
  67. return FALSE;
  68. }
  69. }
  70. else {
  71. // Give a 92 error if not fully authed
  72. $this->handleError(92, 'Method requires full auth. Call auth.getSession using lastfmApiAuth class');
  73. return FALSE;
  74. }
  75. }
  76. /**
  77. * Get a list of attendees for an event
  78. * @param array $methodVars An array with the following required values: <i>eventId</i>
  79. * @return array
  80. */
  81. public function getAttendees($methodVars) {
  82. // Check for required variables
  83. if ( !empty($methodVars['event']) ) {
  84. $vars = array(
  85. 'method' => 'event.getattendees',
  86. 'api_key' => $this->auth->apiKey
  87. );
  88. $vars = array_merge($vars, $methodVars);
  89. if ( $call = $this->apiGetCall($vars) ) {
  90. $attendees['id'] = (string) $call->attendees['event'];
  91. $attendees['total'] = (string) $call->attendees['total'];
  92. $i = 0;
  93. foreach ( $call->attendees->user as $user ) {
  94. $attendees['attendees'][$i]['name'] = (string) $user->name;
  95. $attendees['attendees'][$i]['realname'] = (string) $user->realname;
  96. $attendees['attendees'][$i]['images']['small'] = (string) $user->image[0];
  97. $attendees['attendees'][$i]['images']['medium'] = (string) $user->image[1];
  98. $attendees['attendees'][$i]['images']['large'] = (string) $user->image[2];
  99. $attendees['attendees'][$i]['url'] = (string) $user->url;
  100. $i++;
  101. }
  102. return $attendees;
  103. }
  104. else {
  105. return FALSE;
  106. }
  107. }
  108. else {
  109. // Give a 91 error if incorrect variables are used
  110. $this->handleError(91, 'You must include eventId and status varialbes in the call for this method');
  111. return FALSE;
  112. }
  113. }
  114. /**
  115. * Get the metadata for an event on Last.fm. Includes attendance and lineup information
  116. * @param array $methodVars An array with the following required values: <i>eventId</i>
  117. * @return array
  118. */
  119. public function getInfo($methodVars) {
  120. // Check for required variables
  121. if ( !empty($methodVars['event']) ) {
  122. $vars = array(
  123. 'method' => 'event.getinfo',
  124. 'api_key' => $this->auth->apiKey
  125. );
  126. $vars = array_merge($vars, $methodVars);
  127. if ( $call = $this->apiGetCall($vars) ) {
  128. $info['id'] = (string) $call->event->id;
  129. $info['title'] = (string) $call->event->title;
  130. $ii = 0;
  131. foreach ( $call->event->artists->artist as $artist ) {
  132. $info['artists'][$ii] = (string) $artist;
  133. $ii++;
  134. }
  135. $info['headliner'] = (string) $call->event->artists->headliner;
  136. $info['venue']['name'] = (string) $call->event->venue->name;
  137. $info['venue']['location']['city'] = (string) $call->event->venue->location->city;
  138. $info['venue']['location']['country'] = (string) $call->event->venue->location->country;
  139. $info['venue']['location']['street'] = (string) $call->event->venue->location->street;
  140. $info['venue']['location']['postcode'] = (string) $call->event->venue->location->postalcode;
  141. $geopoint = $call->event->venue->location->children('http://www.w3.org/2003/01/geo/wgs84_pos#');
  142. $info['venue']['location']['geopoint']['lat'] = (string) $geopoint->point->lat;
  143. $info['venue']['location']['geopoint']['long'] = (string) $geopoint->point->long;
  144. $info['venue']['location']['timezone'] = (string) $call->event->venue->location->timezone;
  145. $info['venue']['url'] = (string) $call->venue->url;
  146. $info['startdate'] = strtotime(trim((string) $call->event->startDate));
  147. $info['description'] = (string) $call->event->description;
  148. $info['image']['small'] = (string) $call->event->image[0];
  149. $info['image']['medium'] = (string) $call->event->image[1];
  150. $info['image']['large'] = (string) $call->event->image[2];
  151. $info['attendance'] = (string) $call->event->attendance;
  152. $info['reviews'] = (string) $call->event->reviews;
  153. $info['tag'] = (string) $call->event->tag;
  154. $info['url'] = (string) $call->event->url;
  155. return $info;
  156. }
  157. else {
  158. return FALSE;
  159. }
  160. }
  161. else {
  162. // Give a 91 error if incorrect variables are used
  163. $this->handleError(91, 'You must include eventId and status varialbes in the call for this method');
  164. return FALSE;
  165. }
  166. }
  167. /**
  168. * Get shouts for this event
  169. * @param array $methodVars An array with the following required values: <i>eventId</i>
  170. * @return array
  171. */
  172. public function getShouts($methodVars) {
  173. // Check for required variables
  174. if ( !empty($methodVars['event']) ) {
  175. $vars = array(
  176. 'method' => 'event.getshouts',
  177. 'api_key' => $this->auth->apiKey
  178. );
  179. $vars = array_merge($vars, $methodVars);
  180. if ( $call = $this->apiGetCall($vars) ) {
  181. $shouts['id'] = (string) $call->shouts['event'];
  182. $shouts['total'] = (string) $call->shouts['total'];
  183. $i = 0;
  184. foreach ( $call->shouts->shout as $shout ) {
  185. $shouts['shouts'][$i]['body'] = (string) $shout->body;
  186. $shouts['shouts'][$i]['author'] = (string) $shout->author;
  187. $shouts['shouts'][$i]['date'] = strtotime((string) $shout->date);
  188. $i++;
  189. }
  190. return $shouts;
  191. }
  192. else {
  193. return FALSE;
  194. }
  195. }
  196. else {
  197. // Give a 91 error if incorrect variables are used
  198. $this->handleError(91, 'You must include eventId and status varialbes in the call for this method');
  199. return FALSE;
  200. }
  201. }
  202. /**
  203. * Share an event with one or more Last.fm users or other friends. (Requires full auth)
  204. * @param array $methodVars An array with the following required values: <i>eventId</i>, <i>recipient</i> and option value: <i>message</i>
  205. * @return boolean
  206. */
  207. public function share($methodVars) {
  208. // Only allow full authed calls
  209. if ( $this->fullAuth == TRUE ) {
  210. // Check for required variables
  211. if ( !empty($methodVars['event']) && !empty($methodVars['recipient']) ) {
  212. $vars = array(
  213. 'method' => 'event.share',
  214. 'api_key' => $this->auth->apiKey,
  215. 'sk' => $this->auth->sessionKey
  216. );
  217. $vars = array_merge($vars, $methodVars);
  218. $sig = $this->apiSig($this->auth->secret, $vars);
  219. $vars['api_sig'] = $sig;
  220. if ( $call = $this->apiPostCall($vars) ) {
  221. return TRUE;
  222. }
  223. else {
  224. return FALSE;
  225. }
  226. }
  227. else {
  228. // Give a 91 error if incorrect variables are used
  229. $this->handleError(91, 'You must include eventId and recipient variables in the call for this method');
  230. return FALSE;
  231. }
  232. }
  233. else {
  234. // Give a 92 error if not fully authed
  235. $this->handleError(92, 'Method requires full auth. Call auth.getSession using lastfmApiAuth class');
  236. return FALSE;
  237. }
  238. }
  239. /**
  240. * Shout in this event's shoutbox (Requires full auth)
  241. * @param array $methodVars An array with the following required values: <i>eventId</i>, <i>message</i>
  242. * @return boolean
  243. */
  244. public function shout($methodVars) {
  245. // Only allow full authed calls
  246. if ( $this->fullAuth == TRUE ) {
  247. // Check for required variables
  248. if ( !empty($methodVars['event']) && !empty($methodVars['message']) ) {
  249. $vars = array(
  250. 'method' => 'event.shout',
  251. 'api_key' => $this->auth->apiKey,
  252. 'sk' => $this->auth->sessionKey
  253. );
  254. $vars = array_merge($vars, $methodVars);
  255. $sig = $this->apiSig($this->auth->secret, $vars);
  256. $vars['api_sig'] = $sig;
  257. if ( $call = $this->apiPostCall($vars) ) {
  258. return TRUE;
  259. }
  260. else {
  261. return FALSE;
  262. }
  263. }
  264. else {
  265. // Give a 91 error if incorrect variables are used
  266. $this->handleError(91, 'You must include eventId and message variables in the call for this method');
  267. return FALSE;
  268. }
  269. }
  270. else {
  271. // Give a 92 error if not fully authed
  272. $this->handleError(92, 'Method requires full auth. Call auth.getSession using lastfmApiAuth class');
  273. return FALSE;
  274. }
  275. }
  276. }
  277. ?>