WikiLeaksBridge.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. class WikiLeaksBridge extends BridgeAbstract {
  3. const NAME = 'WikiLeaks';
  4. const URI = 'https://wikileaks.org';
  5. const DESCRIPTION = 'Returns the latest news or articles from WikiLeaks';
  6. const MAINTAINER = 'logmanoriginal';
  7. const PARAMETERS = array(
  8. array(
  9. 'category' => array(
  10. 'name' => 'Category',
  11. 'type' => 'list',
  12. 'required' => true,
  13. 'title' => 'Select your category',
  14. 'values' => array(
  15. 'News' => '-News-',
  16. 'Leaks' => array(
  17. 'All' => '-Leaks-',
  18. 'Intelligence' => '+-Intelligence-+',
  19. 'Global Economy' => '+-Global-Economy-+',
  20. 'International Politics' => '+-International-Politics-+',
  21. 'Corporations' => '+-Corporations-+',
  22. 'Government' => '+-Government-+',
  23. 'War & Military' => '+-War-Military-+'
  24. )
  25. ),
  26. 'defaultValue' => 'news'
  27. ),
  28. 'teaser' => array(
  29. 'name' => 'Show teaser',
  30. 'type' => 'checkbox',
  31. 'required' => false,
  32. 'title' => 'If checked feeds will display the teaser',
  33. 'defaultValue' => true
  34. )
  35. )
  36. );
  37. public function collectData(){
  38. $html = getSimpleHTMLDOM($this->getURI());
  39. // News are presented differently
  40. switch($this->getInput('category')) {
  41. case '-News-':
  42. $this->loadNewsItems($html);
  43. break;
  44. default:
  45. $this->loadLeakItems($html);
  46. }
  47. }
  48. public function getURI(){
  49. if(!is_null($this->getInput('category'))) {
  50. return static::URI . '/' . $this->getInput('category') . '.html';
  51. }
  52. return parent::getURI();
  53. }
  54. public function getName(){
  55. if(!is_null($this->getInput('category'))) {
  56. $category = array_search(
  57. $this->getInput('category'),
  58. static::PARAMETERS[0]['category']['values']
  59. );
  60. if($category === false) {
  61. $category = array_search(
  62. $this->getInput('category'),
  63. static::PARAMETERS[0]['category']['values']['Leaks']
  64. );
  65. }
  66. return $category . ' - ' . static::NAME;
  67. }
  68. return parent::getName();
  69. }
  70. private function loadNewsItems($html){
  71. $articles = $html->find('div.news-articles ul li');
  72. if(is_null($articles) || count($articles) === 0) {
  73. return;
  74. }
  75. foreach($articles as $article) {
  76. $item = array();
  77. $item['title'] = $article->find('h3', 0)->plaintext;
  78. $item['uri'] = static::URI . $article->find('h3 a', 0)->href;
  79. $item['content'] = $article->find('div.introduction', 0)->plaintext;
  80. $item['timestamp'] = strtotime($article->find('div.timestamp', 0)->plaintext);
  81. $this->items[] = $item;
  82. }
  83. }
  84. private function loadLeakItems($html){
  85. $articles = $html->find('li.tile');
  86. if(is_null($articles) || count($articles) === 0) {
  87. return;
  88. }
  89. foreach($articles as $article) {
  90. $item = array();
  91. $item['title'] = $article->find('h2', 0)->plaintext;
  92. $item['uri'] = static::URI . $article->find('a', 0)->href;
  93. $teaser = static::URI . '/' . $article->find('div.teaser img', 0)->src;
  94. if($this->getInput('teaser')) {
  95. $item['content'] = '<img src="'
  96. . $teaser
  97. . '" /><p>'
  98. . $article->find('div.intro', 0)->plaintext
  99. . '</p>';
  100. } else {
  101. $item['content'] = $article->find('div.intro', 0)->plaintext;
  102. }
  103. $item['timestamp'] = strtotime($article->find('div.timestamp', 0)->plaintext);
  104. $item['enclosures'] = array($teaser);
  105. $this->items[] = $item;
  106. }
  107. }
  108. }