[PlantUMLReleasesBridge] Bridge optimizations (#2459)

This commit is contained in:
Yaman Qalieh 2022-03-25 11:44:42 -04:00 committed by GitHub
parent 3187592dba
commit 105fbe9dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 36 deletions

View File

@ -5,62 +5,41 @@
* @author nicolas-delsaux
*
*/
class PlantUMLReleasesBridge extends BridgeAbstract
{
class PlantUMLReleasesBridge extends BridgeAbstract {
const MAINTAINER = 'Riduidel';
const NAME = 'PlantUML Releases';
const AUTHOR = 'PlantUML team';
// URI is no more valid, since we can address the whole gq galaxy
const URI = 'http://plantuml.com/fr/changes';
const URI = 'https://plantuml.com/changes';
const CACHE_TIMEOUT = 7200; // 2h
const DESCRIPTION = 'PlantUML releases bridge, showing for each release the changelog';
const ITEM_LIMIT = 10;
const DEFAULT_DOMAIN = 'plantuml.com';
const PARAMETERS = array( array(
));
const REPLACED_ATTRIBUTES = array(
'href' => 'href',
'src' => 'src',
'data-original' => 'src'
);
private function getDomain() {
$domain = $this->getInput('domain');
if (empty($domain))
$domain = self::DEFAULT_DOMAIN;
if (strpos($domain, '://') === false)
$domain = 'https://' . $domain;
return $domain;
}
public function getURI()
{
public function getURI() {
return self::URI;
}
public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI());
public function collectData() {
$html = defaultLinkTo(getSimpleHTMLDOM($this->getURI()), self::URI);
// Since GQ don't want simple class scrapping, let's do it the hard way and ... discover content !
$num_items = 0;
$main = $html->find('div[id=root]', 0);
foreach ($main->find('h2') as $release) {
// Limit to $ITEM_LIMIT number of results
if ($num_items++ >= self::ITEM_LIMIT) {
break;
}
$item = array();
$item['author'] = self::AUTHOR;
$release_text = $release->innertext;
if (preg_match('/(.+) \((.*)\)/', $release_text, $matches)) {
$item['title'] = $matches[1];
// And now, build the date from the date text
$item['timestamp'] = strtotime($matches[2]);
$item['timestamp'] = preg_replace('/(\d+) (\w{3})\w*, (\d+)/', '${1} ${2} ${3}', $matches[2]);
} else {
$item['title'] = $release_text;
}
$item['uri'] = $this->getURI();
$item['content'] = $release->next_sibling ();
$item['content'] = $release->next_sibling();
$this->items[] = $item;
}
}