This repository was archived by the owner on Jan 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOPML_Extend.php
More file actions
executable file
·80 lines (69 loc) · 2.41 KB
/
OPML_Extend.php
File metadata and controls
executable file
·80 lines (69 loc) · 2.41 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
<?php
require 'OPML_Extend_Interface.php';
/**
* Description of OPML_Extend
*
* @author osmanorhan
*/
class OPML_Extend implements OPML_Extend_Interface {
private $oldOPML;
private $DOM;
public function setOPML($opml) {
$this->oldOPML = $opml;
return $this;
}
public function process() {
$this->DOM = new DOMDocument;
$this->DOM->loadXML($this->oldOPML);
return $this->setStatus()->removeInactive()->saveOPML();
}
public function setStatus() {
foreach ($this->DOM->getElementsByTagName('outline') as $oOutlineField) {
$aStatus = $this->feedStatus($oOutlineField->getAttribute('xmlUrl'));
$oOutlineField->setAttribute('status', $aStatus['status']);
if ('moved' === $aStatus['status']) {
$oOutlineField->setAttribute('xmlUrl', $aStatus['xmlUrl']);
}
}
$this->DOM->saveXML();
return $this;
}
public function feedStatus($xmlUrl) {
if ('' !== $xmlUrl) {
$header = get_headers($xmlUrl, 1);
$aReturn = array();
if (preg_match('/HTTP.+/', $header[0]) ? true : false) {
switch ($header[0]) {
case (preg_match('/HTTP\/1.* 200 OK/', $header[0]) ? true : false):
$aReturn['status'] = 'active';
break;
case (preg_match('/HTTP\/1.* 301 Moved Permanently/', $header[0]) ? true : false):
$aReturn['status'] = 'moved';
$aReturn['xmlUrl'] = is_array($header['Location']) ? $header['Location'][0] : $header['Location'];
break;
default:
$aReturn['status'] = 'inactive';
break;
}
} else {
$aReturn['status'] = 'inactive';
}
return $aReturn;
}
}
public function removeInactive() {
foreach ($this->DOM->getElementsByTagName('outline') as $feed) {
if ('inactive' === $feed->getAttribute('status')) {
$feed->parentNode->removeChild($feed);
}
}
$this->DOM->saveXML();
return $this;
}
public function saveOPML() {
$fileName = substr(md5(microtime()), 2, 6);
$this->DOM->save($fileName . ".xml");
return $fileName . '.xml';
}
}
?>