IdenticaBridge.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class IdenticaBridge extends BridgeAbstract{
  3. private $request;
  4. public function loadMetadatas() {
  5. $this->maintainer = "mitsukarenai";
  6. $this->name = "Identica Bridge";
  7. $this->uri = "https://identi.ca/";
  8. $this->description = "Returns user timelines";
  9. $this->update = "2014-05-25";
  10. $this->parameters[] =
  11. '[
  12. {
  13. "name" : "username",
  14. "identifier" : "u"
  15. }
  16. ]';
  17. }
  18. public function collectData(array $param){
  19. $html = '';
  20. if (isset($param['u'])) { /* user timeline mode */
  21. $this->request = $param['u'];
  22. $html = $this->file_get_html('https://identi.ca/'.urlencode($this->request)) or $this->returnError('Requested username can\'t be found.', 404);
  23. }
  24. else {
  25. $this->returnError('You must specify an Identica username (?u=...).', 400);
  26. }
  27. foreach($html->find('li.major') as $dent) {
  28. $item = new \Item();
  29. $item->uri = html_entity_decode($dent->find('a', 0)->href); // get dent link
  30. $item->timestamp = strtotime($dent->find('abbr.easydate', 0)->plaintext); // extract dent timestamp
  31. $item->content = trim($dent->find('div.activity-content', 0)->innertext); // extract dent text
  32. $item->title = $param['u'] . ' | ' . $item->content;
  33. $this->items[] = $item;
  34. }
  35. }
  36. public function getName(){
  37. return (!empty($this->request) ? $this->request .' - ' : '') .'Identica Bridge';
  38. }
  39. public function getURI(){
  40. return 'https://identica.com';
  41. }
  42. public function getCacheDuration(){
  43. return 300; // 5 minutes
  44. }
  45. }