'POST', CURLOPT_POSTFIELDS => json_encode([ 'templateId' => self::TEMPLATE_ID, 'componentId' => self::COMPONENT_ID, 'page' => '1', 'amount' => 1, 'filter' => (object)[], 'tags' => null, 'sortType' => 'Newest', 'restrictionType' => 'Any' ]) ]; $headers = [ 'Accept: application/json, text/plain, */*', 'Content-Type: application/json;charset=UTF-8', ]; $json = getContents($url, $headers, $opts); $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, 'categories' => [$record->Topic], 'author' => join(', ', array_map(function ($author) { return $author->Name; }, $record->Authors)), 'timestamp' => DateTime::createFromFormat('jS F Y', $record->Date)->format('U'), 'content' => $content, 'enclosures' => $enclosures ]; } } private function getContents($uri) { $html = getSimpleHTMLDOMCached($uri); $body = $html->find('body', 0); $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')) { $args = $this->getRenderArguments($script_text); $result .= $args->Html; } elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.ImagePanel')) { $args = $this->getRenderArguments($script_text); $result .= '
'; } elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Intro')) { $args = $this->getRenderArguments($script_text); $result .= '

' . $args->Intro . '

'; } elseif (str_contains($script_text, 'ReactDOM.render(React.createElement(Components.Footnotes')) { $args = $this->getRenderArguments($script_text); $result .= '

' . $args->Content . '

'; } 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, $enclosures]; } private function getRenderArguments($script_text) { $matches = []; preg_match('/React\.createElement\(Components\.\w+, {(.*)}\),/', $script_text, $matches); return json_decode('{' . $matches[1] . '}'); } }