Error: There was an error restoring your page. Please try again.';
if (@file_exists($pageurl)) {
function loadfile($url, $incpath, $inc)
{
global $message, $pagepath;
// read the file
$doc = fopen($url, "r");
$content = stream_get_contents($doc);
fclose($doc);
$reginclude = '/(?:include\b|include_once\b|require\b|require_once\b)(?:\s*\(*[^;\?>]*)(?:\"|\')([^\"\'<>]*)(?:(\"|\')\)*(;|[\s\t\r\n]*\?>))/i'; // php include regexp
if (!preg_match($reginclude, $content)) $reginclude = '/(?:)/i'; // SSI regexp
// read the backup
$pagename = (strstr($url, $_SERVER['DOCUMENT_ROOT'])) ? explode($_SERVER['DOCUMENT_ROOT'], $url) : explode('../../', $url);
$pagename = trim($pagename[1], '/');
$pagename = str_ireplace('/', '-', $pagename);
$pageext = explode('.', $pagename);
$pagename = preg_replace('/(\.php|\.asp|\.html|\.htm|\.phtml|\.shtml|\.cfm)/', '', $pagename);
$backup = dirname(__FILE__) . '/../backups/' . $pagename . '_Bak.' . $pageext[1];
if (@file_exists($backup)) {
$backdoc = fopen($backup, "r");
$backcontent = stream_get_contents($backdoc);
fclose($backdoc);
echo "File Found: $backup\n\n";
editfile($content, $backcontent, $url, $incpath, $inc);
}
if (preg_match($reginclude, $content)) {
preg_match_all($reginclude, $content, $includes);
foreach ($includes[1] as &$value) {
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . $value) && $value != '') {
$incfile = $_SERVER['DOCUMENT_ROOT'] . $value;
$incpath = false;
} elseif (!stristr($value, 'http://')) {
$incfile = "$pagepath/$value";
if ($incpath) {
$incpathreg = preg_replace('/\//', '\/', $incpath);
$incpathreg = '/(^' . $incpathreg . '\/|\/' . $incpathreg . '\/)/';
$incorigpath = preg_replace($incpathreg, '', $value, 1);
$newinc = "$pagepath/$incpath/$incorigpath";
$incfile = (@file_exists($newinc)) ? $newinc : $incfile;
$incpatharr = explode('/', $incorigpath);
array_pop($incpatharr);
$incpath = (sizeof($incpatharr) > 0) ? $incpath . implode('/', $incpatharr) : false;
} else {
$incpatharr = explode('/', $value);
array_pop($incpatharr);
$incpath = (sizeof($incpatharr) > 0) ? $incpath . implode('/', $incpatharr) : false;
}
} else $incpath = false;
if (!preg_match('/\/$/', $incfile)) loadfile($incfile, $incpath, true);
}
}
}
function editfile($content, $backcontent, $url, $incpath, $inc)
{
global $ftpconn, $ftpwd;
if ($content != $backcontent && ((!stristr($content, '[^<]+', $backcontent) || preg_match('/Error: neocms could not find this page: ' . $remotefile . '';
fclose($restdoc);
if (isset($restdocp)) unlink($restdocp);
} elseif (is_writable($url)) {
//restores file
$restdoc = fopen($url, "w");
fputs($restdoc, $backcontent);
fclose($restdoc);
} else $message = "Error: You do not have permission to edit this page.";
}
}
loadfile($pageurl, false, false);
$message = 'Your page was successfully restored.';
$script = '';
echo $script;
} else {
$message = 'Error: neocms could not find this page: ' . $url . '';
$script = '';
echo $script;
}
if ($ftpconn) ftp_close($ftpconn);
}
}
?>