1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Zend Framework (http://framework.zend.com/) |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/zendframework/zf2 for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
7
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Callingallpapers\Parser; |
11
|
|
|
|
12
|
|
|
use Callingallpapers\Entity\Cfp; |
13
|
|
|
use Callingallpapers\Writer\WriterInterface; |
14
|
|
|
use GuzzleHttp\Client; |
15
|
|
|
|
16
|
|
|
class PhpNetCfpParser implements ParserInterface |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function parse(WriterInterface $writer) |
20
|
|
|
{ |
21
|
|
|
$uri = 'http://php.net/archive/archive.xml'; |
22
|
|
|
$client = new Client(); |
23
|
|
|
$content = $client->get($uri)->getBody(); |
24
|
|
|
|
25
|
|
|
$contents = new \ArrayObject(); |
|
|
|
|
26
|
|
|
$now = new \DateTimeImmutable(); |
27
|
|
|
$then = $now->sub(new \DateInterval('P1Y')); |
28
|
|
|
|
29
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
30
|
|
|
$dom->loadXML($content, LIBXML_NOBLANKS ^ LIBXML_XINCLUDE); |
31
|
|
|
$dom->documentURI = $uri; |
32
|
|
|
|
33
|
|
|
$xpath = new \DOMXPath($dom); |
34
|
|
|
$nodes = $xpath->query('//xi:include[@href]', $dom->parentNode); |
35
|
|
|
|
36
|
|
|
foreach ($nodes as $item) { |
37
|
|
|
/** @var \DOMNode $item */ |
38
|
|
|
$href = $item->attributes->getNamedItem('href'); |
39
|
|
|
if (! preg_match('/\/([\d\-]{10})/', $href->textContent, $result)) { |
40
|
|
|
continue; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$date = new \DateTime($result[1]); |
44
|
|
|
|
45
|
|
|
if (! $date instanceof \DateTime) { |
46
|
|
|
continue; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ($then > $date) { |
50
|
|
|
$item->parentNode->removeChild($item); |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$dom->xinclude(); |
56
|
|
|
$dom->normalizeDocument(); |
57
|
|
|
|
58
|
|
|
$xpath->registerNamespace('default', 'http://php.net/ns/news'); |
59
|
|
|
$xpath->registerNamespace('f', 'http://www.w3.org/2005/Atom'); |
60
|
|
|
|
61
|
|
|
$items = $xpath->query('//f:category[@term="cfp"]'); |
62
|
|
|
|
63
|
|
|
foreach ($items as $node) { |
64
|
|
|
try { |
65
|
|
|
/** @var \DOMNode $node */ |
66
|
|
|
$node = $node->parentNode; |
67
|
|
|
$item = $xpath->query('default:finalTeaserDate', $node)->item(0); |
68
|
|
|
$cfpDate = new \DateTime($item->textContent); |
69
|
|
|
|
70
|
|
|
if ($now > $cfpDate) { |
71
|
|
|
continue; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$item = $xpath->query('published', $node)->item(0); |
75
|
|
|
$cfpStart = new \DateTime($item->textContent); |
76
|
|
|
var_Dump($cfpStart); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$info = new Cfp(); |
79
|
|
|
|
80
|
|
|
$nameNodes = $xpath->query('f:title', $node); |
81
|
|
|
$info->conferenceName = $nameNodes->item(0)->textContent; |
82
|
|
|
|
83
|
|
|
$descNode = $xpath->query('f:content', $node)->item(0); |
84
|
|
|
$info->description = $dom->saveXML($descNode); |
85
|
|
|
|
86
|
|
|
$info->dateEnd = $cfpDate; |
87
|
|
|
$info->dateStart = $cfpStart; |
88
|
|
|
$info->tags = ['PHP']; |
89
|
|
|
|
90
|
|
|
$cfpImageNode = $xpath->query('default:newsImage', $node)->item(0); |
91
|
|
|
$info->uri = $cfpImageNode->attributes->getNamedItem('link')->textContent; |
92
|
|
|
$info->conferenceUri = $cfpImageNode->attributes->getNamedItem('link')->textContent; |
93
|
|
|
$info->iconUri = 'http://php.net/images/news/' . $cfpImageNode->textContent; |
94
|
|
|
|
95
|
|
|
var_Dump($info->toArray()); |
96
|
|
|
// $writer->write($info, 'php.net'); |
|
|
|
|
97
|
|
|
} catch (\Exception $e) { |
98
|
|
|
echo $e->getMessage() . "\n"; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.