[InternationalInstituteForStrategicStudiesBridge] Repair and improve bridge (#3338)

* [InternationalInstituteForStrategicStudiesBridge] Repair and improve bridge

* [InternationalInstituteForStrategicStudiesBridge] Fix lint
This commit is contained in:
Korytov Pavel 2023-04-08 23:09:07 +03:00 committed by GitHub
parent 8486c0f8ca
commit 1ed7bdcddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 11 deletions

View File

@ -9,23 +9,23 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
const CACHE_TIMEOUT = 3600; // 1 hour
const DESCRIPTION = 'Returns the latest blog posts from the IISS';
const TEMPLATE_ID = '{6BCFD2C9-4F0B-4ACE-95D7-D14C8B60CD4D}';
const COMPONENT_ID = '{E9850380-3707-43C9-994F-75ECE8048E04}';
const TEMPLATE_ID = ['BlogArticlePage', 'BlogPage'];
const COMPONENT_ID = '9b0c6919-c78b-4910-9be9-d73e6ee40e50';
public function collectData()
{
$url = 'https://www.iiss.org/api/filter';
$url = 'https://www.iiss.org/api/filteredlist/filter';
$opts = [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'templateId' => [self::TEMPLATE_ID],
'templateId' => self::TEMPLATE_ID,
'componentId' => self::COMPONENT_ID,
'page' => '1',
'amount' => 10,
'amount' => 1,
'filter' => (object)[],
'tags' => null,
'sortType' => 'DateDesc',
'restrictionType' => 'None'
'sortType' => 'Newest',
'restrictionType' => 'Any'
])
];
$headers = [
@ -36,6 +36,7 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
$data = json_decode($json);
foreach ($data->model->Results as $record) {
[$content, $enclosures] = $this->getContents(self::URI . $record->Link);
$this->items[] = [
'uri' => self::URI . $record->Link,
'title' => $record->Heading,
@ -44,7 +45,8 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
return $author->Name;
}, $record->Authors)),
'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');
$result = '';
$enclosures = [];
foreach ($scripts as $script) {
$script_text = $script->innertext;
if (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Reading')) {
@ -63,14 +67,26 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
$result .= $args->Html;
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.ImagePanel')) {
$args = $this->getRenderArguments($script_text);
$image_tag = str_replace('src="/-', 'src="' . self::URI . '/-', $args->Image);
$result .= '<figure>' . $image_tag . '</figure>';
$result .= '<figure><img src="' . self::URI . $args->Image . '"></img></figure>';
} elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Intro')) {
$args = $this->getRenderArguments($script_text);
$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)