Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds PHP.net CfP-Parser #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Command/ParseEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Cfp.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function toArray()
'latitude' => (float) $this->latitude,
'longitude' => (float) $this->longitude,
'timezone' => $this->timezone,
'image' => $this->iconUri,
);
}

Expand Down
102 changes: 102 additions & 0 deletions src/Parser/PhpNetCfpParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Callingallpapers\Parser;

use Callingallpapers\Entity\Cfp;
use Callingallpapers\Writer\WriterInterface;
use GuzzleHttp\Client;

class PhpNetCfpParser implements ParserInterface
{

public function parse(WriterInterface $writer)
{
$uri = 'http://php.net/archive/archive.xml';
$client = new Client();
$content = $client->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";
}
}
}
}