Skip to content

Commit

Permalink
Adds PHP.net CfP-Parser
Browse files Browse the repository at this point in the history
This currently is a dummy-solution as not really a lot of information
can be retrieved from the PHP.net-Website as the infors there aren'T
really reliable or informative. Currently a location is missing as well
as an informartion to a CfP-End-time.
  • Loading branch information
heiglandreas committed Nov 9, 2016
1 parent 0aad1b9 commit aa66a23
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
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";
}
}
}
}

0 comments on commit aa66a23

Please sign in to comment.