2 require_once "localresource.php";
4 class PageCopy
extends LocalResource
12 function __construct($name, $origin, $root)
14 $this->date
= date("c");
15 $this->origin
= $origin;
16 $c = $root->get($name);
17 $this->file
= $c->get_file();
18 $this->url
= $c->get_url();
24 $timeout = 5; // set to zero for no timeout
25 curl_setopt ($ch, CURLOPT_URL
, $this->origin
);
26 curl_setopt ($ch, CURLOPT_RETURNTRANSFER
, 1);
27 curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT
, $timeout);
28 $file_contents = curl_exec($ch);
31 if ($content = $file_contents) {
33 if (eregi("<head>", $content)) {
34 $content = eregi_replace("<head>", "<head>". $this->startOfHEAD
, $content);
36 $content = eregi_replace("^", "<head>". $this->startOfHEAD
, $content);
38 if (eregi("</head>", $content)) {
39 $content = eregi_replace("</head>", $this->endOfHEAD
. "</head>", $content);
41 $content = eregi_replace("^", $this->endOfHEAD
. "</head>", $content);
43 if (eregi("</html>", $content)) {
44 $content = eregi_replace("</html>", $this->endOfHTML
. "</html>", $content);
46 $content = eregi_replace("$", $this->endOfHTML
. "</html>", $content);
48 $copy = fopen($this->file
, "w");
49 if (! fwrite($copy, $content)) {
50 throw new Exception("Err: Ecriture");
55 function add_to_html($s)
57 $this->endOfHTML
.= $s;
60 function add_to_head($s)
62 $this->endOfHEAD
.= $s;
65 function add_to_head_start($s)
67 $this->startOfHEAD
.= $s;
71 function url2fileName($url)
74 $forbidden = array('/',':','?','=','&','+','%');
75 $fileName = ereg_replace('^http://', '', $fileName); //remove http://
76 $fileName = ereg_replace('#.*$', '', $fileName); //remove fragment id
77 $fileName = str_replace($forbidden, '_', $fileName);