mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-02-16 23:29:56 +03:00
[WordPressPluginUpdate] fix: broken bridge (#2572)
I think they removed the changelog html page. Or maybe it was a redirect. Anyways, this change uses their json api to fetch plugin data.
This commit is contained in:
parent
bed20e9f28
commit
7b168a29f0
1 changed files with 49 additions and 61 deletions
|
@ -1,74 +1,62 @@
|
||||||
<?php
|
<?php
|
||||||
class WordPressPluginUpdateBridge extends BridgeAbstract {
|
|
||||||
|
|
||||||
const MAINTAINER = 'teromene';
|
final class WordPressPluginUpdateBridge extends BridgeAbstract {
|
||||||
|
const MAINTAINER = 'dvikan';
|
||||||
const NAME = 'WordPress Plugins Update Bridge';
|
const NAME = 'WordPress Plugins Update Bridge';
|
||||||
const URI = 'https://wordpress.org/plugins/';
|
const URI = 'https://wordpress.org/plugins/';
|
||||||
const CACHE_TIMEOUT = 86400; // 24h = 86400s
|
const DESCRIPTION = 'Returns latest updates of wordpress.org plugins.';
|
||||||
const DESCRIPTION = 'Returns latest updates of WordPress.com plugins.';
|
|
||||||
|
|
||||||
const PARAMETERS = array(
|
const PARAMETERS = [
|
||||||
array(
|
[
|
||||||
'pluginUrl' => array(
|
// The incorrectly named pluginUrl is kept for BC
|
||||||
'name' => 'URL to the plugin',
|
'pluginUrl' => [
|
||||||
'exampleValue' => 'https://wordpress.org/plugins/wp-rss-aggregator/',
|
'name' => 'Plugin slug',
|
||||||
'required' => true
|
'exampleValue' => 'akismet',
|
||||||
)
|
'required' => true,
|
||||||
)
|
'title' => 'Slug or url',
|
||||||
);
|
]
|
||||||
|
]
|
||||||
public function collectData(){
|
];
|
||||||
|
|
||||||
$request = str_replace('/', '', $this->getInput('pluginUrl'));
|
|
||||||
$page = self::URI . $request . '/changelog/';
|
|
||||||
|
|
||||||
$html = getSimpleHTMLDOM($page);
|
|
||||||
|
|
||||||
$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'] = '';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public function collectData() {
|
||||||
|
$input = trim($this->getInput('pluginUrl'));
|
||||||
|
if (preg_match('#https://wordpress\.org/plugins/([\w-]+)#', $input, $m)) {
|
||||||
|
$slug = $m[1];
|
||||||
|
} else {
|
||||||
|
$slug = str_replace(['/'], '', $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['uri'] = 'https://downloads.wordpress.org/plugin/' . $request . '.' . strip_tags($version) . '.zip';
|
$pluginData = self::fetchPluginData($slug);
|
||||||
$item['title'] = $version;
|
|
||||||
$this->items[] = $item;
|
|
||||||
|
|
||||||
|
if ($pluginData->versions === []) {
|
||||||
|
throw new \Exception('This plugin does not have versioning data');
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't need trunk. I think it's the latest commit.
|
||||||
|
unset($pluginData->versions->trunk);
|
||||||
|
|
||||||
|
foreach ($pluginData->versions as $version => $downloadUrl) {
|
||||||
|
$this->items[] = [
|
||||||
|
'title' => $version,
|
||||||
|
'uri' => sprintf('https://wordpress.org/plugins/%s/#developers', $slug),
|
||||||
|
'uid' => $downloadUrl,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
usort($this->items, function($a, $b) {
|
||||||
|
return version_compare($b['title'], $a['title']);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(){
|
/**
|
||||||
if(!is_null($this->getInput('q'))) {
|
* Fetch plugin data from wordpress.org json api
|
||||||
return $this->getInput('q') . ' : ' . self::NAME;
|
*
|
||||||
}
|
* https://codex.wordpress.org/WordPress.org_API#Plugins
|
||||||
|
* https://wordpress.org/support/topic/using-the-wordpress-org-api/
|
||||||
return parent::getName();
|
*/
|
||||||
|
private static function fetchPluginData(string $slug): \stdClass
|
||||||
|
{
|
||||||
|
$api = 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=%s';
|
||||||
|
return json_decode(getContents(sprintf($api, $slug)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue