-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckRemoteImageCache.php
More file actions
44 lines (36 loc) · 1.06 KB
/
checkRemoteImageCache.php
File metadata and controls
44 lines (36 loc) · 1.06 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
<?php
include("vars.php");
include("functions.php");
class MyXML extends SimpleXMLElement {
public function find($xpath) {
$tmp = $this->xpath($xpath);
return isset($tmp[0])? $tmp[0]: null;
}
public function remove() {
$dom = dom_import_simplexml($this);
return $dom->parentNode->removeChild($dom);
}
}
$timestamp = time();
$todelete = array();
if (file_exists('prefs/remoteImageCache.xml')) {
$x = simplexml_load_file('prefs/remoteImageCache.xml');
foreach($x->images->image as $i => $elem) {
$t = $elem->stamp;
if ($timestamp - $t > 2592000) {
// Image has not been accessed for a long time (30 days). Get rid of it.
$id = $elem['id'];
debug_print("Removing element ".$id,"IMAGECACHE");
array_push($todelete, $id);
}
}
$foo = new MyXML($x->asXML());
foreach($todelete as $elem) {
$foo->find('//images/image[@id="'.$elem.'"]')->remove();
}
$fp = fopen('prefs/remoteImageCache.xml', 'w');
fwrite($fp, $foo->asXML());
fclose($fp);
}
?>
<html></html>