PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/berry/lib/service/lj.php

http://goodgirl.googlecode.com/
PHP | 106 lines | 61 code | 27 blank | 18 comment | 2 complexity | 2de5298e393716e1a0839f9deb279032 MD5 | raw file
  1. <?php /* `,
  2. ,\, #
  3. B E R R Y |/ ?
  4. <http://goodgirl.ru/berry> | ~ )\
  5. <http://goodgirl.ru/berry/license> /__/\ \____
  6. / \_/ \
  7. ???? zloy ? ???????? <http://lexa.cutenews.ru> / <_ ____,_-/\ __
  8. ---------------------------------------------------------/___/_____ \--'\|/----
  9. \/|*/
  10. class Service_LJ { protected $server = 'www.livejournal.com';
  11. ////////////////////////////////////////////////////////////////////////////////
  12. function __construct($username, $password, $journal = ''){
  13. $this->username = $username;
  14. $this->password = md5($password);
  15. $this->journal = ($journal ? $journal : $username);
  16. }
  17. ////////////////////////////////////////////////////////////////////////////////
  18. protected function _request($method, $params = array()){ $params = array_merge(array(
  19. 'username' => $this->username,
  20. 'hpassword' => $this->password,
  21. 'ver' => 1
  22. ), $params);
  23. $response = xmlrpc::request(
  24. $this->server,
  25. '/interface/xmlrpc',
  26. 'LJ.XMLRPC.'.$method,
  27. array(xmlrpc::prepare($params)),
  28. 'Putoberry' // ??????? ?? ???????????
  29. );
  30. unset($this->error);
  31. if ($response[0])
  32. return $response[1];
  33. $this->error = $response[1]['faultString'];
  34. }
  35. ////////////////////////////////////////////////////////////////////////////////
  36. function event($method, $params = array(), $timestamp = 0){ $timestamp = date::time($timestamp); $params = array_merge(array(
  37. 'itemid' => 0,
  38. 'lineendings' => 'unix',
  39. 'usejournal' => $this->journal,
  40. 'security' => 'public',
  41. 'year' => date('Y', $timestamp),
  42. 'mon' => date('m', $timestamp),
  43. 'day' => date('d', $timestamp),
  44. 'hour' => date('H', $timestamp),
  45. 'min' => date('i', $timestamp)
  46. ), $params);
  47. $params['subject'] = base64_encode($params['subject']);
  48. $params['subject type'] = 'base64';
  49. $params['event'] = base64_encode($params['event']);
  50. $params['event type'] = 'base64';
  51. if ($result = $this->_request($method.'event', $params))
  52. return $result;
  53. }
  54. ////////////////////////////////////////////////////////////////////////////////
  55. function postEvent($subject, $event, $timestamp = 0){
  56. return $this->event('post', compact('subject', 'event'), $timestamp);
  57. }
  58. ////////////////////////////////////////////////////////////////////////////////
  59. function editEvent($itemid, $subject, $event, $timestamp = 0){
  60. return $this->event('edit', compact('itemid', 'subject', 'event'), $timestamp);
  61. }
  62. ////////////////////////////////////////////////////////////////////////////////
  63. function getUserTags(){ $result = $this->_request('getUserTags', array('usejournal' => $this->journal));
  64. return $result['tags'];
  65. }
  66. ////////////////////////////////////////////////////////////////////////////////
  67. function getFriendOf(){ $result = $this->_request('friendof');
  68. return $result['friendofs'];
  69. }
  70. ////////////////////////////////////////////////////////////////////////////////
  71. function getFriendGroups(){ $result = $this->_request('getfriendgroups');
  72. return $result['friendgroups'];
  73. }
  74. ////////////////////////////////////////////////////////////////////////////////
  75. function getFriends(){ $result = $this->_request('getfriends');
  76. return $result['friends'];
  77. }
  78. ////////////////////////////////////////////////////////////////////////////////
  79. }