PageRenderTime 50ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 1ms

/Server/SWXPHP/2.00/php/services/Twitter.php

http://swx-format.googlecode.com/
PHP | 872 lines | 318 code | 123 blank | 431 comment | 15 complexity | 766902b7aa967396b8364cdcde1a29ff MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * SWX Twitter API v2
  5. *
  6. * You can call this API using SWX, Amfphp, JSON and XML-RPC.
  7. *
  8. * Updated 12/2008 by Folkert Hielema to include search functionality and to match updates to Twitter API.
  9. *
  10. * @author Aral Balkan
  11. * @copyright 2007-2009 Aral Balkan. All Rights Reserved.
  12. * @link http://aralbalkan.com
  13. * @link http://swxformat.org
  14. *
  15. **/
  16. // Require base service class
  17. require_once("../BaseService.php");
  18. /**
  19. * SWX Twitter API by Aral Balkan. You can call this API using SWX, Amfphp, JSON and XML-RPC.
  20. **/
  21. class Twitter extends BaseService
  22. {
  23. //////////////////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Official Twitter API methods: These implement the official twitter API.
  26. // See http://groups.google.com/group/twitter-development-talk/web/api-documentation
  27. // for the full official documentation.
  28. //
  29. //////////////////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Status methods.
  32. //
  33. /**
  34. * Returns the 20 most recent statuses from non-protected users who have set a custom user icon. Does not require authentication.
  35. * @return Array of statuses.
  36. * @author Aral Balkan
  37. **/
  38. function publicTimeline()
  39. {
  40. $url = 'twitter.com/statuses/public_timeline.json';
  41. $response = $this->_jsonCall($url, NULL, 'GET');
  42. return $response;
  43. }
  44. /**
  45. * Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user and that user's friends. It's also possible to request another user's friends_timeline via the id parameter.
  46. *
  47. * @param Your username.
  48. * @param Your password.
  49. * @param (optional) ID or screen name of the user for whom to return the friends_timeline.
  50. * @param (optional) Narrows the returned results to just those statuses created after the specified HTTP-formatted date.
  51. * @param (optional) The number of the page you want
  52. *
  53. * @return Array of statuses.
  54. * @author Aral Balkan
  55. **/
  56. function friendsTimeline($user, $pass, $id = NULL, $since = NULL, $count = 50,$page = 0)
  57. {
  58. $url = 'twitter.com/statuses/friends_timeline.json';
  59. $since = (empty($since)) ? NULL : $since;
  60. $vars = array('id' => $id, 'since' => $since, 'count' => $count, 'page' => $page);
  61. $response = $this->_jsonCall($url, $vars, 'GET', $user, $pass);
  62. return $response;
  63. }
  64. /**
  65. * Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user. It's also possible to request another user's timeline via the id parameter below.
  66. *
  67. *
  68. * @return 20 most recent statuses.
  69. * @author Aral Balkan
  70. **/
  71. function userTimeline($user, $pass, $id = NULL, $count = 50, $since = NULL)
  72. {
  73. $url = 'twitter.com/statuses/user_timeline.json';
  74. $since = (empty($since)) ? NULL : $since;
  75. $vars = array('id' => $id, 'count' => $count, 'since' => $since);
  76. $response = $this->_jsonCall($url, $vars, 'GET', $user, $pass);
  77. return $response;
  78. }
  79. /**
  80. * Returns a single status, specified by the id parameter below. The status's author will be returned inline.
  81. *
  82. * @param The numerical ID of the status you're trying to retrieve.
  83. *
  84. * @return A single status.
  85. * @author Aral Balkan
  86. **/
  87. function showStatus($id)
  88. {
  89. $url = "twitter.com/statuses/show/$id.json";
  90. $response = $this->_jsonCall($url, NULL, 'GET');
  91. return $response;
  92. }
  93. /**
  94. * Posts a twitter update.
  95. *
  96. * @param (str) Twitter update message
  97. * @param (str) Your user name
  98. * @param (str) Your password
  99. * @param (optional, str) Source string. If enabled by Twitter, this will appear in the "from" section of the update.
  100. * @param (optional) id for the message to reply to
  101. * @return (array) Success/failure message.
  102. *
  103. * @author Aral Balkan
  104. * @changed by Folkert Hielema, added optional $reply_id
  105. **/
  106. function update($update, $user, $pass, $source = NULL, $reply_id = NULL)
  107. {
  108. $url = 'twitter.com/statuses/update.json';
  109. $args = array('status' => $update, 'in_reply_to_status_id' => $reply_id);
  110. if ($source != NULL)
  111. {
  112. //error_log("source = ".$source);
  113. $args['source'] = $source;
  114. //error_log($args['status']);
  115. //error_log($args['source']);
  116. }
  117. $response = $this->_jsonCall($url, $args, 'POST', $user, $pass);
  118. return $response;
  119. }
  120. /**
  121. * Returns the 20 most recent replies (status updates prefixed with @username posted by users who are friends with the user being replied to) to the authenticating user. Replies are only available to the authenticating user; you can not request a list of replies to another user whether public or protected.
  122. *
  123. * @param (str) Your user name
  124. * @param (str) Your password
  125. * @param (optional, int) Page number
  126. *
  127. * @return 20 most recent replies
  128. * @author Aral Balkan
  129. **/
  130. function replies($user, $pass, $page = NULL)
  131. {
  132. $url = 'http://twitter.com/statuses/replies.json';
  133. $args = array('page' => $page);
  134. $response = $this->_jsonCall($url, $args, 'POST', $user, $pass);
  135. return $response;
  136. }
  137. /**
  138. * Destroys the status specified by the required ID parameter. The authenticating user must be the author of the specified status.
  139. *
  140. * @return void
  141. * @author Aral Balkan
  142. **/
  143. function destroy($id, $user, $pass)
  144. {
  145. $url = "http://twitter.com/statuses/destroy/$id.json";
  146. $args = array('id'=>$id);
  147. $response = $this->_jsonCall($url, $args, 'POST', $user, $pass);
  148. return $response;
  149. }
  150. //
  151. // User methods.
  152. //
  153. /**
  154. * Gets friends for the passed user.
  155. *
  156. * @param (str) Username.
  157. * @param (str) Password.
  158. * @param (optional) The ID or screen name of a user
  159. *
  160. * @return (array) List of friends.
  161. * @author Aral Balkan
  162. **/
  163. function friends($user, $pass, $id = NULL, $page = 1)
  164. {
  165. if($id !== NULL)
  166. $url = "twitter.com/statuses/friends/$id.json";
  167. else
  168. $url = "twitter.com/statuses/friends/$user.json";
  169. $vars = array('page' => $page);
  170. $response = $this->_jsonCall($url, $vars, 'GET', $user, $pass);
  171. return $response;
  172. }
  173. /**
  174. * User A Is friends with User B.
  175. *
  176. * @param (str) Username.
  177. * @param (str) Password.
  178. * @param (str) user A
  179. * @param (str) user B (Optional)
  180. * @return (array) List of friends.
  181. * @author Aral Balkan
  182. **/
  183. function isFriend($user, $pass, $userA, $userB)
  184. {
  185. $vars = array('user_a' => $userA, 'user_b' => $userB);
  186. $url = "twitter.com/friendships/exists.json";
  187. $response = $this->_jsonCall($url, $vars, 'GET');
  188. return $response;
  189. }
  190. /**
  191. * Gets followers for authenticated user.
  192. *
  193. * @param (str) Your username.
  194. * @param (str) Your password.
  195. *
  196. * @return (array) List of followers.
  197. * @author Aral Balkan
  198. **/
  199. function followers($user, $pass)
  200. {
  201. $url = 'twitter.com/statuses/followers.json';
  202. $response = $this->_jsonCall($url, NULL, 'GET', $user, $pass);
  203. return $response;
  204. }
  205. /**
  206. * Returns currently featured users on the site and their latest update.
  207. *
  208. * @return (array) List of featured users and their current update.
  209. * @author Aral Balkan
  210. **/
  211. function featured()
  212. {
  213. $url = 'twitter.com/statuses/featured.json';
  214. $response = $this->_jsonCall($url, NULL, 'GET');
  215. return $response;
  216. }
  217. /**
  218. * Returns extended information of a given user, specified by ID or screen name as per the required id parameter below. This information includes design settings, so third party developers can theme their widgets according to a given user's preferences.
  219. *
  220. * @param (str/int) The ID or screen name of a user.
  221. * @param (str) Your username.
  222. * @param (str) Your password.
  223. *
  224. * @return Information on user.
  225. * @author Aral Balkan
  226. **/
  227. function showUser($id, $user, $pass)
  228. {
  229. $url = "twitter.com/users/show/$id.json";
  230. $response = $this->_jsonCall($url, NULL, 'GET', $user, $pass);
  231. return $response;
  232. }
  233. //
  234. // Direct message methods.
  235. //
  236. /**
  237. * Returns the list of direct messages for the passed user.
  238. *
  239. * @param (str) Your user name
  240. * @param (str) Your password
  241. * @param (str) Since (optional)
  242. *
  243. * @return (array) List of direct messages
  244. *
  245. * @author Aral Balkan
  246. **/
  247. function directMessages($user, $pass, $since = NULL)
  248. {
  249. $url = 'twitter.com/direct_messages.json';
  250. $vars = array('since' => $since);
  251. $response = $this->_jsonCall($url, $vars, 'GET', $user, $pass);
  252. return $response;
  253. }
  254. /**
  255. * Returns a list of the 20 most recent direct messages sent by the authenticating user. Includes detailed information about the sending and recipient users.
  256. *
  257. * @param (str) Your user name
  258. * @param (str) Your password
  259. * @param (optional, int) Retrieves the 20 next most recent direct messages sent.
  260. * @param (optional, str) Narrows the resulting list of direct messages to just those sent after the specified HTTP-formatted date.
  261. * @param (optional, str) Returns only sent direct messages with an ID greater than (that is, more recent than) the specified ID.
  262. *
  263. * @return List of the 20 most recent direct messages.
  264. * @author Aral Balkan
  265. **/
  266. function sentDirectMessages($user, $pass, $page = NULL, $since = NULL, $since_id = NULL)
  267. {
  268. $url = 'http://twitter.com/direct_messages/sent.json';
  269. $vars = array('page' => $page, 'since' => $since, 'since_id' => $since_id);
  270. $response = $this->_jsonCall($url, $vars, 'POST', $user, $pass);
  271. return $response;
  272. }
  273. /**
  274. * Sends a direct message
  275. *
  276. * @param User name of recipient
  277. * @param Message to send
  278. * @param Your username
  279. * @param Your password
  280. *
  281. * @return The sent direct message.
  282. * @author Aral Balkan
  283. **/
  284. function newDirectMessage($recipient, $message, $user, $pass)
  285. {
  286. $url = 'twitter.com/direct_messages/new.json';
  287. $vars = array('user' => $recipient, 'text' => $message);
  288. $response = $this->_jsonCall($url, $vars, 'POST', $user, $pass);
  289. return $response;
  290. }
  291. /**
  292. * Destroys the direct message specified in the required ID parameter. The authenticating user must be the recipient of the specified direct message.
  293. *
  294. * @param (str) The ID of the direct message to destroy.
  295. * @param (str) Your username
  296. * @param (str) Your password
  297. *
  298. * @return Destroyed direct message.
  299. * @author Aral Balkan
  300. **/
  301. function destroyDirectMessage($id, $user, $pass)
  302. {
  303. $url = "http://twitter.com/direct_messages/destroy/$id.json";
  304. $args = array('id'=>$id);
  305. $response = $this->_jsonCall($url, $args, 'POST', $user, $pass);
  306. return $response;
  307. }
  308. //
  309. // Friendship methods.
  310. //
  311. /**
  312. * Befriends the user specified in the ID parameter as the authenticating user. Returns the befriended user in the requested format when successful. Returns a string describing the failure condition when unsuccessful.
  313. *
  314. * @param (str) The ID or screen name of the user to befriend.
  315. * @param (str) Your username
  316. * @param (str) Your password
  317. *
  318. * @return Befriended user or error string.
  319. * @author Aral Balkan
  320. **/
  321. function friendshipCreate($id, $user, $pass)
  322. {
  323. $url = "http://twitter.com/friendships/create/$id.json";
  324. $response = $this->_jsonCall($url, NULL, 'POST', $user, $pass);
  325. return $response;
  326. }
  327. /**
  328. * Discontinues friendship with the user specified in the ID parameter as the authenticating user. Returns the un-friended user in the requested format when successful. Returns a string describing the failure condition when unsuccessful.
  329. *
  330. * @param (str) The ID or screen name of the user with whom to discontinue friendship.
  331. * @param (str) Your username
  332. * @param (str) Your password
  333. *
  334. * @return Un-friended user or error string.
  335. * @author Aral Balkan
  336. **/
  337. function friendshipDestroy($id, $user, $pass)
  338. {
  339. $url = "http://twitter.com/friendships/destroy/$id.json";
  340. $response = $this->_jsonCall($url, NULL, 'POST', $user, $pass);
  341. return $response;
  342. }
  343. //
  344. // Account methods.
  345. //
  346. /**
  347. * Returns an HTTP 200 OK response code and a format-specific response if authentication was successful. Use this method to test if supplied user credentials are valid with minimal overhead.
  348. *
  349. * @return authorized = "true" on success. null on failure.
  350. * @author Aral Balkan
  351. **/
  352. function verifyCredentials($user, $pass)
  353. {
  354. $url = 'http://twitter.com/account/verify_credentials.json';
  355. $response = $this->_jsonCall($url, NULL, 'GET', $user, $pass);
  356. return $response;
  357. }
  358. /**
  359. * Ends the session of the authenticating user, returning a null cookie. Use this method to sign users out of client-facing applications like widgets.
  360. *
  361. * @return Response from Twitter.
  362. * @author Aral Balkan
  363. **/
  364. function endSession($user, $pass)
  365. {
  366. $url = 'http://twitter.com/account/end_session';
  367. $response = $this->_call($url, NULL, NULL, $user, $pass);
  368. return $response;
  369. }
  370. ////////////////////////////////////////////////////////////////////////////////
  371. //
  372. // Custom methods
  373. //
  374. // These are additional utility methods that are not part of the official
  375. // Twitter API. Some of these use screen-scraping techniques and may break
  376. // in future versions of the official Twitter API.
  377. //
  378. ////////////////////////////////////////////////////////////////////////////////
  379. //
  380. // Custom update methods.
  381. //
  382. /**
  383. * Returns the number of requested updates from the public timeline (max 20).
  384. *
  385. * @param (int) Number of updates to get (max 20)
  386. * @param (str) URL-encoded date
  387. *
  388. * @return array Updates
  389. *
  390. * @author Aral Balkan
  391. **/
  392. function getNumPublicTimelineUpdates($n = 20, $since = NULL)
  393. {
  394. $url = 'twitter.com/statuses/public_timeline.json';
  395. $vars = array('since' => $since);
  396. $response = (array) $this->_jsonCall($url, $vars, 'GET');
  397. // Error?
  398. if (isset($response['error']))
  399. {
  400. return $response;
  401. }
  402. if ($response === NULL)
  403. {
  404. if ($since === NULL)
  405. {
  406. // There was an error in the call.
  407. trigger_error("getNumPublicTimelineUpdates() - Twitter returned null", E_USER_ERROR);
  408. }
  409. else
  410. {
  411. // There just weren't any updates since the user last checked.
  412. $response = array();
  413. }
  414. }
  415. else
  416. {
  417. $response = array_slice($response, 0, $n);
  418. }
  419. // Error conditions:
  420. //return array(false);
  421. //syntax_error
  422. return $response;
  423. }
  424. /**
  425. * Alias for getNumPublicTimelineUpdates (which didn't fit on the moo card!) :)
  426. *
  427. * @param (int) Number of updates to get (max 20)
  428. * @param (str) URL-encoded date
  429. *
  430. * @return array Updates
  431. *
  432. * @author Aral Balkan
  433. **/
  434. function getPublicUpdates($n = 20, $since = NULL)
  435. {
  436. return $this->getNumPublicTimelineUpdates($n, $since);
  437. }
  438. /**
  439. * Returns the number of updates for the user and her friends (up to 20) for the passed user name (or email).
  440. *
  441. * Note that when calling this without the since parameter, the results appear to be affected
  442. * by the caching that Twitter has implemented and the results may not be the most recent.
  443. *
  444. * @param (str) User name (or email)
  445. * @param (int) Number of updates to get (max 20)
  446. * @param (str) (optional) URL-encoded date
  447. *
  448. * @return array Updates
  449. *
  450. * @author Aral Balkan
  451. **/
  452. function getNumFriendsUpdates($userName, $n = 20, $since = NULL)
  453. {
  454. if ($n === NULL) $n = 20;
  455. $url = "twitter.com/statuses/friends_timeline/$userName.json";
  456. $vars = array('since' => $since);
  457. $response = (array) $this->_jsonCall($url, $vars, 'GET');
  458. if (isset($response['error']))
  459. {
  460. return $response;
  461. }
  462. if ($response === NULL)
  463. {
  464. if ($since === NULL)
  465. {
  466. // There was an error in the call.
  467. trigger_error("getNumFriendsUpdates() - Twitter returned null; make sure that the user name you requested ('$userName') exists", E_USER_ERROR);
  468. }
  469. else
  470. {
  471. // There just weren't any updates since the user last checked.
  472. $response = array();
  473. }
  474. }
  475. else
  476. {
  477. $response = array_slice($response, 0, $n);
  478. }
  479. // Error conditions:
  480. //return array(false);
  481. //syntax_error
  482. return $response;
  483. }
  484. //
  485. // Custom friendship methods.
  486. //
  487. /**
  488. * Gets friends for the passed user name. Doesn't
  489. * require authentication but will not return friends
  490. * who have set themselves to private.
  491. *
  492. * @param (str) User name
  493. *
  494. * @return (array) List of friends.
  495. * @author Aral Balkan
  496. **/
  497. function friendsNoAuth($user)
  498. {
  499. $url = "twitter.com/statuses/friends/$userName.json";
  500. $response = $this->_jsonCall($url, NULL, 'GET');
  501. return $response;
  502. }
  503. /**
  504. * Returns followers who are not friends.
  505. *
  506. * @param (str) User name.
  507. * @param (str) Password.
  508. *
  509. * @return (array) List of followers that are not friends.
  510. * @author Aral Balkan
  511. **/
  512. function followersWhoAreNotFriends($user, $pass)
  513. {
  514. // Get list of followers and friends from Twitter
  515. // (this may take a while if you have lots of them!)
  516. $followers = $this->followers($user, $pass);
  517. $friends = $this->friends($user, $pass);
  518. // Create followers id-based hash
  519. $followerIds = array();
  520. $numFollowers = count($followers);
  521. for ($i = 0; $i < $numFollowers; $i++)
  522. {
  523. $follower = $followers[$i];
  524. $id = $follower->id;
  525. error_log('Followers screen_name = '.$id);
  526. $followerIds[$id] = $follower;
  527. }
  528. // Create friends id-based hash
  529. $friendIds = array();
  530. $numFriends = count($friends);
  531. for ($i = 0; $i < $numFriends; $i ++)
  532. {
  533. $friend = $friends[$i];
  534. $id = $friend->id;
  535. error_log('Friends ID = '.$id);
  536. $friendIds[$id] = $friend;
  537. }
  538. // Calculate the difference of the id arrays
  539. $followersWhoAreNotFriends = array();
  540. foreach ($followerIds as $followerId => $follower)
  541. {
  542. error_log("testing: " . $friendIds[$followerId]);
  543. if (!isset($friendIds[$followerId]))
  544. {
  545. error_log("Friend with id $followerId, does not exist.");
  546. array_push($followersWhoAreNotFriends, $follower);
  547. }
  548. else
  549. {
  550. error_log("Friend with id $followerId exists.");
  551. }
  552. }
  553. return $followersWhoAreNotFriends;
  554. }
  555. /**
  556. * Returns a list of your fans (people who have added you as friends but
  557. * whom you have not added as a friend.) This is an alias function for
  558. * followersWhoAreNotFriends().
  559. *
  560. * @return void
  561. * @author Aral Balkan
  562. **/
  563. function getFans($user, $pass)
  564. {
  565. return followersWhoAreNotFriends($user, $pass);
  566. }
  567. /**
  568. * Follows friend with passed friend ID and user name.
  569. *
  570. * You can also call notifications(true, ...)
  571. *
  572. * @param (int) Friend ID
  573. * @param (str) Friend's user name
  574. * @param (str) Your user name
  575. * @param (str) Your password
  576. *
  577. * @return (bool) Success (true/false).
  578. *
  579. * @author Aral Balkan
  580. **/
  581. function followFriend($friendId, $friendUserName, $yourUserName, $yourPassWord)
  582. {
  583. $url = "http://twitter.com/friends/follow/$friendId";
  584. $response = $this->_call($url, NULL, 'GET', $yourUserName, $yourPassWord, "http://twitter.com/$friendUserName");
  585. $success = (strpos($response, 'Notifications on') !== false);
  586. return $success;
  587. }
  588. /**
  589. * Leaves friend with passed friend ID and user name.
  590. *
  591. * You can also call notifications(false, ...)
  592. *
  593. * @param (int) Friend ID
  594. * @param (str) Friend's user name
  595. * @param (str) Your user name
  596. * @param (str) Your password
  597. *
  598. * @return (bool) Success (true/false).
  599. *
  600. * @author Aral Balkan
  601. **/
  602. function leaveFriend($friendId, $friendUserName, $yourUserName, $yourPassWord)
  603. {
  604. $url = "http://twitter.com/friends/leave/$friendId";
  605. $response = $this->_call($url, NULL, 'GET', $yourUserName, $yourPassWord, "http://twitter.com/$friendUserName");
  606. $success = (strpos($response, 'Notifications off') !== false);
  607. return $success;
  608. }
  609. /**
  610. * Turns notifications for a user on or off.
  611. *
  612. * @param (bool) True = turn notifications on, false = turn notifications off.
  613. * @param (str) Friend's ID.
  614. * @param (str) Friend's username.
  615. * @param (str) Your username.
  616. * @param (str) Your password.
  617. *
  618. * @return true/false based on success.
  619. * @author Aral Balkan
  620. **/
  621. function notifications($state, $friendId, $friendUserName, $user, $pass)
  622. {
  623. // TODO: Looks like bools are coming in as strings. Investigate why this is.
  624. if ($state == "true")
  625. {
  626. return $this->followFriend($friendId, $friendUserName, $user, $pass);
  627. }
  628. else
  629. {
  630. return $this->leaveFriend($friendId, $friendUserName, $user, $pass);
  631. }
  632. }
  633. //
  634. // Deprecated methods: Do not use. May be removed in future versions.
  635. //
  636. /**
  637. * Adds friend with passed friend ID and user name.
  638. *
  639. * DEPRECATED! Use the new friendshipCreate() method in the official Twitter API instead.
  640. *
  641. * Deprecated as of Beta 1.4.
  642. *
  643. * @param (int) Friend ID
  644. * @param (str) Friend's user name
  645. * @param (str) Your user name
  646. * @param (str) Your password
  647. *
  648. * @return (bool) Success (true/false).
  649. *
  650. * @author Aral Balkan
  651. **/
  652. function addFriend($friendId, $friendUserName, $yourUserName, $yourPassWord)
  653. {
  654. $url = "http://twitter.com/friendships/create/$friendId";
  655. $response = $this->_call($url, NULL, 'GET', $yourUserName, $yourPassWord, "http://twitter.com/$friendUserName");
  656. $checkString = "<strong>You follow ".$friendUserName."</strong>";
  657. $success = (strpos($response, $checkString ) !== false);
  658. return $success;
  659. }
  660. /**
  661. * Removes friend with passed friend ID and user name.
  662. *
  663. * DEPRECATED! Use the new friendshipDestroy() method in the official Twitter API instead.
  664. *
  665. * Deprecated as of Beta 1.4.
  666. *
  667. * @param (int) Friend ID
  668. * @param (str) Friend's user name
  669. * @param (str) Your user name
  670. * @param (str) Your password
  671. *
  672. * @return (bool) Success (true/false).
  673. *
  674. * @author Aral Balkan
  675. **/
  676. function removeFriend($friendId, $friendUserName, $yourUserName, $yourPassWord)
  677. {
  678. $url = "http://twitter.com/friendships/destroy/$friendId";
  679. $response = $this->_call($url, NULL, 'GET', $yourUserName, $yourPassWord, "http://twitter.com/$friendUserName");
  680. $success = (strpos($response, 'add</a>') !== false);
  681. return $success;
  682. }
  683. /**
  684. * Returns the remaining number of API requests available to the authenticating user before the API limit is reached for the current hour. Calls to rate_limit_status require authentication, but will not count against the rate limit.
  685. *
  686. * @param Your username.
  687. * @param Your password.
  688. *
  689. * @return Number of API requests.
  690. * @author Aral Balkan
  691. **/
  692. function rateLimitStatus( $user, $pass)
  693. {
  694. $url = 'twitter.com/account/rate_limit_status.json';
  695. $response = $this->_jsonCall($url, NULL, 'GET', $user, $pass);
  696. return $response;
  697. }
  698. /**
  699. * Updates the location attribute of the authenticated user, as displayed on de side of their profiles and returned in various API Methods.
  700. *
  701. * @param Users login name.
  702. * @param Users password.
  703. * @param Users location
  704. * @return The same object as with showUser, with info and last post
  705. * @author Folkert Hielema
  706. **/
  707. function update_location( $user, $pass, $location)
  708. {
  709. $url = 'twitter.com/account/update_location.json';
  710. $vars = array('location' => $location);
  711. $response = $this->_jsonCall($url, $vars, 'POST', $user, $pass);
  712. return $response;
  713. }
  714. /**
  715. * Sets which device Twitter delivers updates to for the authenticated user. Sending none as device parameter will disable IM or SMS updates.
  716. *
  717. * @param Users login name.
  718. * @param Users password.
  719. * @param (required) must be sms, im or none.
  720. * @return The same object as with showUser, with info and last post
  721. * @author Folkert Hielema
  722. **/
  723. function update_delivery_device( $user, $pass, $device)
  724. {
  725. $url = 'twitter.com/account/update_delivery_device.json';
  726. $vars = array('device' => $device);
  727. $response = $this->_jsonCall($url, $vars, 'POST', $user, $pass);
  728. return $response;
  729. }
  730. /**
  731. * Search twitter implementation from twitter.com
  732. * @param (str) SearchString
  733. * @param (str) (optional) Language short tag like 'en', 'nl' etc
  734. * @param (int) (optional) rpp - The number of tweets to return per page, max = 100
  735. * @param (str) (optional) since_id - return tweets with a status_id greater than the given
  736. * @param (str) (optional) geocode - return tweets within the given radius of the given latitude/longtitude. Location is taken from users twitter profile
  737. * @param (bool) (optional) show_user - When 'true', adds "<user>:" to the beginning of the tweet, useful for readers that do not display Atom's author field, default = false
  738. * @return (array) Messages found for searchString
  739. * @author Folkert Hielema
  740. **/
  741. function search( $searchString, $lang = NULL, $rpp = 20, $since_id = NULL, $geocode = NULL, $show_user = false )
  742. {
  743. $url = "search.twitter.com/search.json";
  744. $vars = array('q' => "$searchString", 'lang' => $lang, 'rpp' => $rpp, 'since_id' => $since_id, 'geocode' =>$geocode, 'show_user' =>$show_user);
  745. $response = $this->_jsonCall($url, $vars, 'GET');
  746. return $response;
  747. }
  748. }
  749. ?>