mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-10 17:08:47 +00:00
[InternationalInstituteForStrategicStudiesBridge] Repair and improve bridge (#3338)
* [InternationalInstituteForStrategicStudiesBridge] Repair and improve bridge * [InternationalInstituteForStrategicStudiesBridge] Fix lint
This commit is contained in:
parent
8486c0f8ca
commit
1ed7bdcddf
@ -9,23 +9,23 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
|
|||||||
const CACHE_TIMEOUT = 3600; // 1 hour
|
const CACHE_TIMEOUT = 3600; // 1 hour
|
||||||
const DESCRIPTION = 'Returns the latest blog posts from the IISS';
|
const DESCRIPTION = 'Returns the latest blog posts from the IISS';
|
||||||
|
|
||||||
const TEMPLATE_ID = '{6BCFD2C9-4F0B-4ACE-95D7-D14C8B60CD4D}';
|
const TEMPLATE_ID = ['BlogArticlePage', 'BlogPage'];
|
||||||
const COMPONENT_ID = '{E9850380-3707-43C9-994F-75ECE8048E04}';
|
const COMPONENT_ID = '9b0c6919-c78b-4910-9be9-d73e6ee40e50';
|
||||||
|
|
||||||
public function collectData()
|
public function collectData()
|
||||||
{
|
{
|
||||||
$url = 'https://www.iiss.org/api/filter';
|
$url = 'https://www.iiss.org/api/filteredlist/filter';
|
||||||
$opts = [
|
$opts = [
|
||||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||||
CURLOPT_POSTFIELDS => json_encode([
|
CURLOPT_POSTFIELDS => json_encode([
|
||||||
'templateId' => [self::TEMPLATE_ID],
|
'templateId' => self::TEMPLATE_ID,
|
||||||
'componentId' => self::COMPONENT_ID,
|
'componentId' => self::COMPONENT_ID,
|
||||||
'page' => '1',
|
'page' => '1',
|
||||||
'amount' => 10,
|
'amount' => 1,
|
||||||
'filter' => (object)[],
|
'filter' => (object)[],
|
||||||
'tags' => null,
|
'tags' => null,
|
||||||
'sortType' => 'DateDesc',
|
'sortType' => 'Newest',
|
||||||
'restrictionType' => 'None'
|
'restrictionType' => 'Any'
|
||||||
])
|
])
|
||||||
];
|
];
|
||||||
$headers = [
|
$headers = [
|
||||||
@ -36,6 +36,7 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
|
|||||||
$data = json_decode($json);
|
$data = json_decode($json);
|
||||||
|
|
||||||
foreach ($data->model->Results as $record) {
|
foreach ($data->model->Results as $record) {
|
||||||
|
[$content, $enclosures] = $this->getContents(self::URI . $record->Link);
|
||||||
$this->items[] = [
|
$this->items[] = [
|
||||||
'uri' => self::URI . $record->Link,
|
'uri' => self::URI . $record->Link,
|
||||||
'title' => $record->Heading,
|
'title' => $record->Heading,
|
||||||
@ -44,7 +45,8 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
|
|||||||
return $author->Name;
|
return $author->Name;
|
||||||
}, $record->Authors)),
|
}, $record->Authors)),
|
||||||
'timestamp' => DateTime::createFromFormat('jS F Y', $record->Date)->format('U'),
|
'timestamp' => DateTime::createFromFormat('jS F Y', $record->Date)->format('U'),
|
||||||
'content' => $this->getContents(self::URI . $record->Link)
|
'content' => $content,
|
||||||
|
'enclosures' => $enclosures
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,6 +58,8 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
|
|||||||
$scripts = $body->find('script');
|
$scripts = $body->find('script');
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
|
$enclosures = [];
|
||||||
|
|
||||||
foreach ($scripts as $script) {
|
foreach ($scripts as $script) {
|
||||||
$script_text = $script->innertext;
|
$script_text = $script->innertext;
|
||||||
if (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Reading')) {
|
if (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Reading')) {
|
||||||
@ -63,14 +67,26 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
|
|||||||
$result .= $args->Html;
|
$result .= $args->Html;
|
||||||
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.ImagePanel')) {
|
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.ImagePanel')) {
|
||||||
$args = $this->getRenderArguments($script_text);
|
$args = $this->getRenderArguments($script_text);
|
||||||
$image_tag = str_replace('src="/-', 'src="' . self::URI . '/-', $args->Image);
|
$result .= '<figure><img src="' . self::URI . $args->Image . '"></img></figure>';
|
||||||
$result .= '<figure>' . $image_tag . '</figure>';
|
|
||||||
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Intro')) {
|
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Intro')) {
|
||||||
$args = $this->getRenderArguments($script_text);
|
$args = $this->getRenderArguments($script_text);
|
||||||
$result .= '<p>' . $args->Intro . '</p>';
|
$result .= '<p>' . $args->Intro . '</p>';
|
||||||
|
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Footnotes')) {
|
||||||
|
$args = $this->getRenderArguments($script_text);
|
||||||
|
$result .= '<p>' . $args->Content . '</p>';
|
||||||
|
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.List')) {
|
||||||
|
$args = $this->getRenderArguments($script_text);
|
||||||
|
foreach ($args->Items as $item) {
|
||||||
|
if ($item->Url != null) {
|
||||||
|
$match = preg_match('/\\"(.*)\\"/', $item->Url, $matches);
|
||||||
|
if ($match > 0) {
|
||||||
|
array_push($enclosures, self::URI . $matches[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [$result, $enclosures];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRenderArguments($script_text)
|
private function getRenderArguments($script_text)
|
||||||
|
Loading…
Reference in New Issue
Block a user