diff --git a/src/Command/ParseEvents.php b/src/Command/ParseEvents.php index 29f3e15..eec93a6 100644 --- a/src/Command/ParseEvents.php +++ b/src/Command/ParseEvents.php @@ -32,6 +32,7 @@ use Callingallpapers\Parser\JoindinCfpParser; use Callingallpapers\Parser\Lanyrd\LanyrdCfpParser; use Callingallpapers\Service\TimezoneService; +use Callingallpapers\Parser\PhpNetCfpParser; use Callingallpapers\Writer\ApiCfpWriter; use GuzzleHttp\Client; use Symfony\Component\Console\Command\Command; @@ -79,6 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $parser = new LanyrdCfpParser(new TimezoneService(new Client(), $config['timezonedb_token'])); $parser->parse($writer); + + $parser = new PhpNetCfpParser(); + $parser->parse($writer); + $parser = new JoindinCfpParser(); $parser->parse($writer); } diff --git a/src/Entity/Cfp.php b/src/Entity/Cfp.php index cca8c97..a5c33b6 100644 --- a/src/Entity/Cfp.php +++ b/src/Entity/Cfp.php @@ -100,6 +100,7 @@ public function toArray() 'latitude' => (float) $this->latitude, 'longitude' => (float) $this->longitude, 'timezone' => $this->timezone, + 'image' => $this->iconUri, ); } diff --git a/src/Parser/PhpNetCfpParser.php b/src/Parser/PhpNetCfpParser.php new file mode 100644 index 0000000..291cc1e --- /dev/null +++ b/src/Parser/PhpNetCfpParser.php @@ -0,0 +1,102 @@ +get($uri)->getBody(); + + $contents = new \ArrayObject(); + $now = new \DateTimeImmutable(); + $then = $now->sub(new \DateInterval('P1Y')); + + $dom = new \DOMDocument('1.0', 'UTF-8'); + $dom->loadXML($content, LIBXML_NOBLANKS ^ LIBXML_XINCLUDE); + $dom->documentURI = $uri; + + $xpath = new \DOMXPath($dom); + $nodes = $xpath->query('//xi:include[@href]', $dom->parentNode); + + foreach ($nodes as $item) { + /** @var \DOMNode $item */ + $href = $item->attributes->getNamedItem('href'); + if (! preg_match('/\/([\d\-]{10})/', $href->textContent, $result)) { + continue; + } + + $date = new \DateTime($result[1]); + + if (! $date instanceof \DateTime) { + continue; + } + + if ($then > $date) { + $item->parentNode->removeChild($item); + continue; + } + } + + $dom->xinclude(); + $dom->normalizeDocument(); + + $xpath->registerNamespace('default', 'http://php.net/ns/news'); + $xpath->registerNamespace('f', 'http://www.w3.org/2005/Atom'); + + $items = $xpath->query('//f:category[@term="cfp"]'); + + foreach ($items as $node) { + try { + /** @var \DOMNode $node */ + $node = $node->parentNode; + $item = $xpath->query('default:finalTeaserDate', $node)->item(0); + $cfpDate = new \DateTime($item->textContent); + + if ($now > $cfpDate) { + continue; + } + + $item = $xpath->query('published', $node)->item(0); + $cfpStart = new \DateTime($item->textContent); + var_Dump($cfpStart); + + $info = new Cfp(); + + $nameNodes = $xpath->query('f:title', $node); + $info->conferenceName = $nameNodes->item(0)->textContent; + + $descNode = $xpath->query('f:content', $node)->item(0); + $info->description = $dom->saveXML($descNode); + + $info->dateEnd = $cfpDate; + $info->dateStart = $cfpStart; + $info->tags = ['PHP']; + + $cfpImageNode = $xpath->query('default:newsImage', $node)->item(0); + $info->uri = $cfpImageNode->attributes->getNamedItem('link')->textContent; + $info->conferenceUri = $cfpImageNode->attributes->getNamedItem('link')->textContent; + $info->iconUri = 'http://php.net/images/news/' . $cfpImageNode->textContent; + + var_Dump($info->toArray()); + // $writer->write($info, 'php.net'); + } catch (\Exception $e) { + echo $e->getMessage() . "\n"; + } + } + } +}