WordPressPluginUpdateBridge.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class WordPressPluginUpdateBridge extends BridgeAbstract {
  3. const MAINTAINER = 'teromene';
  4. const NAME = 'WordPress Plugins Update Bridge';
  5. const URI = 'https://wordpress.org/plugins/';
  6. const CACHE_TIMEOUT = 86400; // 24h = 86400s
  7. const DESCRIPTION = 'Returns latest updates of WordPress.com plugins.';
  8. const PARAMETERS = array(
  9. array(
  10. 'pluginUrl' => array(
  11. 'name' => 'URL to the plugin',
  12. 'required' => true
  13. )
  14. )
  15. );
  16. public function collectData(){
  17. $request = str_replace('/', '', $this->getInput('pluginUrl'));
  18. $page = self::URI . $request . '/changelog/';
  19. $html = getSimpleHTMLDOM($page)
  20. or returnServerError('No results for this query.');
  21. $content = $html->find('.block-content', 0);
  22. $item = array();
  23. $item['content'] = '';
  24. $version = null;
  25. foreach($content->children() as $element) {
  26. if($element->tag != 'h4') {
  27. $item['content'] .= $element;
  28. } else {
  29. if($version == null) {
  30. $version = $element;
  31. } else {
  32. $item['title'] = $version;
  33. $item['uri'] = 'https://downloads.wordpress.org/plugin/' . $request . '.' . strip_tags($version) . '.zip';
  34. $this->items[] = $item;
  35. $version = $element;
  36. $item = array();
  37. $item['content'] = '';
  38. }
  39. }
  40. }
  41. $item['uri'] = 'https://downloads.wordpress.org/plugin/' . $request . '.' . strip_tags($version) . '.zip';
  42. $item['title'] = $version;
  43. $this->items[] = $item;
  44. }
  45. public function getName(){
  46. if(!is_null($this->getInput('q'))) {
  47. return $this->getInput('q') . ' : ' . self::NAME;
  48. }
  49. return parent::getName();
  50. }
  51. private function getCachedDate($url){
  52. debugMessage('getting pubdate from url ' . $url . '');
  53. // Initialize cache
  54. $cache = Cache::create('FileCache');
  55. $cache->setPath(CACHE_DIR . '/pages');
  56. $params = [$url];
  57. $cache->setParameters($params);
  58. // Get cachefile timestamp
  59. $time = $cache->getTime();
  60. return ($time !== false ? $time : time());
  61. }
  62. }