This repository was archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbackup.php
More file actions
executable file
·207 lines (172 loc) · 8.35 KB
/
backup.php
File metadata and controls
executable file
·207 lines (172 loc) · 8.35 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
set_time_limit(0);
if(!$_REQUEST['url']) {
?>
<h2>Backup your hAtom or XOXO Blog Format Blog</h2>
<form method="get"><div>
URL: <input type="text" name="url" />
<input type="submit" value="Go" />
</div></form>
<?php
exit;
}//end if ! url
require_once 'OutlineClasses/OutlineFromXOXO.php';
require_once 'OutlineClasses/OutlineFromHATOM.php';
require_once 'xn-app://singpolymaplay/getTidy.php';
$page = getTidy($_REQUEST['url']);
$archives = new OutlineFromXOXO($page,array('classes' => array('archive-list')));
if(!$archives || !$archives->getNode(0)) {
preg_match('/<div id="ArchiveList">([^\f]*?<\/div>)/',$page,$archives);
$archives = str_replace('</option>','</a></li>',str_replace('<option value','<li><a href',str_replace('</select>','</ul>',str_replace('<select','<ul',$archives[1]))));
$archives = new OutlineFromXOXO($archives,array('classes' => array()));
}//end if ! $archives
$urls = array();
foreach($archives->getNodes() as $node) {
if($node->getField('href#1'))
$urls[] = $node->getField('href#1');
else if($node->getField('href'))
$urls[] = $node->getField('href');
}//end foreach as node
$site = array();
$struct = array();
foreach($urls as $url) {
$data = getTidy($url);
$xoxo = new OutlineFromXOXO($data,array('classes' => array('xoxo','posts')));
$hatom = new OutlineFromHATOM($data,array('resolve' => $_GET['url']));
$raw = new OutlineFromXOXO($data,array('classes' => array()));
if(in_array('home',explode(' ',$xoxo->getNode(0)->getField('rel')))) {$site = $xoxo->getNode(0)->toArray();$xoxo->unsetNode(0);$xoxo->reindexNodes();}
if(in_array('home',explode(' ',$hatom->getNode(0)->getField('rel')))) {$site = $hatom->getNode(0)->toArray();$hatom->unsetNode(0);$hatom->reindexNodes();}
if(in_array('home',explode(' ',$raw->getNode(0)->getField('rel')))) {$site = $raw->getNode(0)->toArray();$raw->unsetNode(0);$raw->reindexNodes();}
if($xoxo->getNumNodes() && $hatom->getNumNodes()) {//fill in XOXO with hAtom
for($i = 0; $i < $xoxo->getNumNodes(); $i++) {
$node = $xoxo->getNode($i);
foreach($node->getFields() as $name => $value)
$hatom->_subnodes[$i]->setField($name,$value);
}//end for
$xoxo = $hatom;
} else if($xoxo->getNumNodes()) {
} else if($hatom->getNumNodes()) {
$xoxo = $hatom;
} else {
$xoxo = $raw;
}//end if-elses
if($xoxo->getNumNodes()) {
foreach($xoxo->toArray() as $item) {
if($item['title']) $struct[$item['title']] = $item;
else $struct[] = $item;
}//end foreach
}//end if numnodes
}//end foreach $urls
krsort($struct);
$struct = new Outline($struct);
header('Content-type: application/xhtml+xml; charset=utf-8');
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
echo '<html>'."\n\n";
echo '<head>'."\n";
echo ' <title>Backup';
if($site && $site['text'])
echo ' of '.str_replace("\n",' ',str_replace("\r",' ',htmlentities($site['text'])));
echo ' - '.htmlentities(date('c',time())).'</title>'."\n";
if($site && $site['href#1'])
echo ' <link rel="alternate" type="application/xml" title="Posts Feed" href="'.htmlentities($site['href#1']).'" />'."\n";
echo ' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />'."\n";
echo '</head>'."\n\n";
echo '<body>'."\n\n";
echo '<ul class="xoxo posts hfeed">'."\n\n";
if($site) {
echo ' <li id="home">'."\n";
echo ' <a class="feed-title" rel="home bookmark"';
if($site['href'])
echo ' href="'.htmlentities($site['href']).'"';
if($site['title'])
echo ' title="'.htmlentities($site['title']).'"';
echo '>'.str_replace("\n",' ',str_replace("\r",' ',htmlentities($site['text']))).'</a>'."\n";
if(in_array('alternate',explode(' ',$site['rel#1'])))
echo ' <a rel="alternate" href="'.htmlentities($site['href#1']).'">[site post feed]</a>'."\n";
echo ' </li>'."\n\n";
}//end if site
foreach($struct->getNodes() as $node) {
if($node->getField('title'))
$node->setField('title',(int)((($node->getField('title')/1000000000) < 1000) ? $node->getField('title') : ($node->getField('title')/1000000000)));
echo ' <li class="hentry"';
if($node->getField('title'))
echo ' id="post-'.htmlentities($node->getField('title')).'"';
echo '>'."\n";
echo ' <a class="entry-title" rel="bookmark"';
if($node->getField('href'))
echo ' href="'.htmlentities($node->getField('href')).'"';
if($node->getField('title'))
echo ' title="'.htmlentities($node->getField('title')).'"';
echo '>'.htmlentities(str_replace("\n",' ',str_replace("\r",' ',$node->getField('text')))).'</a>';
if($node->getField('title')) {
if(date('H',$node->getField('title')) || date('i',$node->getField('title')))
$design_pattern_stamp = date('c',$node->getField('title'));
else
$design_pattern_stamp = date('Y-m-d',$node->getField('title'));
} else $design_pattern_stamp = '';
$commentsdone = false; $authordone = false; $archivedone = false; $commentsalternatedone = false;
foreach($node->getFields() as $name => $value) {
$nameparts = explode('#',$name);
if(!$nameparts[1] || $nameparts[0] != 'rel') continue;
$value = explode(' ',$value);
if(in_array('comments',$value) && !in_array('alternate',$value) && !$commentsdone) {
$commentsdone = true;
echo "\n".' <a rel="comments"';
if($node->getField('href#'.$nameparts[1])) echo ' href="'.htmlentities($node->getField('href#'.$nameparts[1])).'"';
echo '>';
echo (int)$node->getField('text#'.$nameparts[1]);
echo '</a>';
}//end if rel=comments
if(in_array('author',$value) && !$authordone) {
$authordone = true;
echo "\n".' <address class="author vcard">';
echo "\n".' <a rel="author"';
if($node->getField('href#'.$nameparts[1])) echo ' class="url fn" href="'.htmlentities($node->getField('href#'.$nameparts[1])).'"';
else echo ' class="fn"';
echo '>';
echo htmlentities($node->getField('text#'.$nameparts[1]));
echo '</a>'."\n";
echo ' </address>';
}//end if rel=author
if(in_array('archive',$value) && !$archivedone) {
$archivedone = true;
echo "\n".' <a rel="archive" class="published updated"';
if($node->getField('href#'.$nameparts[1])) echo ' href="'.htmlentities($node->getField('href#'.$nameparts[1])).'"';
echo '>';
echo htmlentities($design_pattern_stamp);
echo '</a>';
}//end if rel=archive
if(in_array('comments',$value) && in_array('alternate',$value) && !$commentsalternatedone) {
$commentsalternatedone = true;
echo "\n".' <a rel="comments alternate"';
if($node->getField('href#'.$nameparts[1])) echo ' href="'.htmlentities($node->getField('href#'.$nameparts[1])).'"';
echo '>';
echo '[post comment feed]';
echo '</a>';
}//end if rel=archive
}//end foreach rel=alternate comments
if(!$archivedone) echo "\n".' <a rel="archive" class="published updated">'.htmlentities($design_pattern_stamp).'</a>';
if($node->getField('body')) {
echo "\n".' <dl>'."\n";
echo ' <dt>body</dt>'."\n";
echo ' <dd class="entry-content">'.str_replace("\n",' ',str_replace("\r",' ',$node->getField('body')));
if(!preg_match('/rel="?[^\f]*?tag[^\f]*?"?/',$node->getField('body')) && $node->getField('tags')) {
echo ' <ul class="tags">';
$tags = $node->getField('tags');
$tags = $tags->toArray();
foreach($tags as $tag) echo ' <li><a rel="tag" href="http://www.technorati.com/tag/'.urlencode($tag['text']).'">'.htmlentities($tag['text']).'</a></li> ';
echo '</ul> ';
}//end if ! rel=tag in body
echo '</dd>'."\n";
echo ' </dl>';
}//end if body
if($node->getNumNodes()) {
$comments = new Outline($node->getNodes());
echo "\n".$comments->toXOXO(array('classes' => array('xoxo','comments')));
}
echo "\n".' </li>'."\n\n";
}//end foreach
echo '</ul>'."\n\n";
echo '</body>'."\n\n";
echo '</html>';
?>