ScoopItBridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. class ScoopItBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "Pitchoule";
  5. $this->name = "ScoopIt";
  6. $this->uri = "http://www.scoop.it";
  7. $this->description = "Returns most recent results from ScoopIt.";
  8. $this->parameters[] = array(
  9. 'u'=>array(
  10. 'name'=>'keyword',
  11. 'required'=>true
  12. )
  13. );
  14. }
  15. public function collectData(array $param){
  16. $html = '';
  17. if ($param['u'] != '') {
  18. $this->request = $param['u'];
  19. $link = 'http://scoop.it/search?q=' .urlencode($this->request);
  20. $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request ScoopIt. for : ' . $link);
  21. foreach($html->find('div.post-view') as $element) {
  22. $item = array();
  23. $item['uri'] = $element->find('a', 0)->href;
  24. $item['title'] = preg_replace('~[[:cntrl:]]~', '', $element->find('div.tCustomization_post_title',0)->plaintext);
  25. $item['content'] = preg_replace('~[[:cntrl:]]~', '', $element->find('div.tCustomization_post_description', 0)->plaintext);
  26. $this->items[] = $item;
  27. }
  28. } else {
  29. $this->returnServerError('You must specify a keyword');
  30. }
  31. }
  32. public function getCacheDuration(){
  33. return 21600; // 6 hours
  34. }
  35. }