-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPhpNetCfpParser.php
More file actions
102 lines (79 loc) · 3.42 KB
/
PhpNetCfpParser.php
File metadata and controls
102 lines (79 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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";
}
}
}
}