summaryrefslogtreecommitdiff
path: root/bridges/WordPressPluginUpdateBridge.php
blob: 9101c4ee8f9e7844c16e41ad5cc0290b2f3046ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
class WordPressPluginUpdateBridge extends BridgeAbstract {

	const MAINTAINER = 'teromene';
	const NAME = 'WordPress Plugins Update Bridge';
	const URI = 'https://wordpress.org/plugins/';
	const CACHE_TIMEOUT = 86400; // 24h = 86400s
	const DESCRIPTION = 'Returns latest updates of WordPress.com plugins.';

	const PARAMETERS = array(
		array(
			'pluginUrl' => array(
				'name' => 'URL to the plugin',
				'required' => true
			)
		)
	);

	public function collectData(){

		$request = str_replace('/', '', $this->getInput('pluginUrl'));
		$page = self::URI . $request . '/changelog/';

		$html = getSimpleHTMLDOM($page)
			or returnServerError('No results for this query.');

		$content = $html->find('.block-content', 0);

		$item = array();
		$item['content'] = '';
		$version = null;

		foreach($content->children() as $element) {

			if($element->tag != 'h4') {

				$item['content'] .= $element;

			} else {

				if($version == null) {

					$version = $element;

				} else {

					$item['title'] = $version;
					$item['uri'] = 'https://downloads.wordpress.org/plugin/' . $request . '.' . strip_tags($version) . '.zip';
					$this->items[] = $item;

					$version = $element;
					$item = array();
					$item['content'] = '';

				}

			}

		}

		$item['uri'] = 'https://downloads.wordpress.org/plugin/' . $request . '.' . strip_tags($version) . '.zip';
		$item['title'] = $version;
		$this->items[] = $item;

	}

	public function getName(){
		if(!is_null($this->getInput('q'))) {
			return $this->getInput('q') . ' : ' . self::NAME;
		}

		return parent::getName();
	}
}