<?php
/* +----------------------------------------------------------------------+
| Netautor Professional Application Server |
+----------------------------------------------------------------------+
| Copyright (C) 1998-2005 digiconcept GmbH. <www.digiconcept.net> |
+----------------------------------------------------------------------+
| This file is subject to license, that is bundled with this package |
| in the file LICENSE.TXT, and is available at through the |
| world-wide-web at http://www.netautor.com/license/ |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| hide@address.com so we can mail you a copy. |
+----------------------------------------------------------------------+
| Authors: Stefan Rottensteiner <hide@address.com> |
| Marek Kadziela <hide@address.com> |
| Gregor Wollner |
| Christian Unger |
| Helli Kleinhans |
+----------------------------------------------------------------------+*/
/**
* @version $Revision: 1.14 $
* @author Gergor Wollner
* @author Helmut Kleinhans
* @author Stefan Rottensteiner
*/
require_once('../../include/init.inc');
$pidFile = $GLOBALS['DC_ENV']->cachepath.'exporter.pid';
if ( file_exists( $pidFile) && (time() - filemtime ( $pidFile) > 60 ) )
@unlink( $pidFile);
if(!( intval($GLOBALS['USER']->ID) >= 99 || file_exists( $pidFile)) )
$GLOBALS['USER']->login_call();
error_reporting(E_ALL);
// --- include necessary functions
includeNaPro( 'array,string,web,file' );
ob_end_flush();
if (file_exists($pidFile))
@unlink($pidFile);
if(!empty($argv[0]) && !strstr($argv[0],'=')) $configfile = $argv[0];
if (!empty($configfile)) {
if (!file_exists($configfile.'.cfg')){
?><html>
<head><title>digiconcept/netautor/site export</title></head>
<body onLoad="window.focus();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center>
<font face="Arial,Helvetica" color="Red"><b>No config-file found '<?php echo($configfile.'.cfg');?>' !</b></font>
<a href='javascript:window.close();' style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" ><br><br><?php echo $LOCALE->dgettext('system','window_close'); ?>></a>
</center>
</body>
</html><?php
exit();
}
include_once ($configfile.'.cfg');
}
if(empty($dirs))
{//--- Wenn kein Exportverzeichnis angegeben wurde
?><html>
<head><title>digiconcept/netautor/site export</title></head>
<body onLoad="window.focus();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center>
<font face="Arial,Helvetica" color="Red"><b>No path to export given!</b></font>
<br><br>
<a href='javascript:window.close();' style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" ><?php echo $LOCALE->dgettext('system','window_close'); ?></a>
</center>
</body>
</html><?php
exit();
}
$params['LOAD_IMAGES'] = (!empty($load_images) && strtolower(trim(urldecode($load_images)))=='yes');
$params['LOAD_RESOURCES'] = (!empty($load_resources) && strtolower(trim(urldecode($load_resources)))=='yes');
$params['PATH_IMAGES'] = (empty($path_images) ? 'img/':trim(urldecode($path_images)));
$params['PATH_RESOURCES'] = (empty($path_resources) ? 'res/':trim(urldecode($path_images)));
$params['DEBUG'] = (!empty($debug) && (strtolower(trim(urldecode($debug)))=='true' || strtolower(trim(urldecode($debug)))=='yes'));
// if (empty($SERVER_NAME)) @$SERVER_NAME =$GLOBALS['HTTP_SERVER_VARS']['SERVER_NAME'];
if (empty($SERVER_NAME)) @$SERVER_NAME =$_SERVER['SERVER_NAME'];
if (empty($SERVER_PORT)) @$SERVER_PORT =$_SERVER['SERVER_PORT'];
$LayoutParser = 'http://'.$SERVER_NAME.':'.$SERVER_PORT.$GLOBALS['DC_ENV']->indexpath.'appl/na_professional/parse.php?npf_export=yes&npf_cache=no&mlay_id=';
$levels = empty($levels)?1:$levels;
$myarray = array();
$myarray = parse_post_get_array();
if (empty($resultaction))
{
$ResultAction = 4;
}
else
{
$resultaction = magicReplacer($resultaction,$myarray);
switch (strtolower(trim($resultaction)))
{
case 'redirect': $ResultAction = 1; break;
case 'content': $ResultAction = 2; break;
case 'info': $ResultAction = 3; break;
case 'quiet': $ResultAction = 4; break;
default: $ResultAction = 3; break;
}
}
unset($myarray['dirs']);
unset($myarray['mlay_ids']);
unset($myarray['urls']);
unset($myarray['levels']);
unset($myarray['load_images']);
unset($myarray['load_resources']);
unset($myarray['path_resources']);
unset($myarray['path_images']);
unset($myarray['source_params']);
if (!empty($source_params))
{
$source_params = magicReplacer(explode(',',urldecode($source_params)),$myarray);
}
else
{
$source_params[0] = parse_array_to_url2 ($myarray);
if (empty($source_params)) $source_params=array(0=>'');
}
$levels = magicReplacer(urldecode($levels),$myarray);
$dirs = magicReplacer(urldecode($dirs),$myarray);
$dir = explode(',',$dirs);
// Einfaches kopieren
if(!empty($parse) && strtolower($parse)=='no')
{
if(!empty($mlay_ids))
{
$id = explode(',',magicReplacer(urldecode($mlay_ids),$myarray));
$max_i = count($id);
for($i=0;$i<$max_i;$i++)
{
$url = 'http://'.$SERVER_NAME.':'.$SERVER_PORT.$DC_ENV->indexpath.'appl/na_professional/parse.php?mlay_id='.$id[$i];
if (!empty($source_params[$i])) $url.='&'.$source_params[$i];
$url.='&npf_cache=no&npf_debug=no';
$buffer = '';
$fp = fopen($url,'rb');
if ($fp)
{
while(!feof($fp)){$buffer.= fgets($fp, 4096);}
}
else
{
echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>digiconcept/netautor/site export</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onLoad="window.focus();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center>
<font color="Red" face="Arial, Helvetica, Courier"><b>Cannot open source file '."'".$url."'".' !</b></font>
<br>
<br>
<a href="javascript:window.close();" style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" >'.($LOCALE->dgettext('system','window_close') ).'</a>
</center>
</body></html>');
}
@fclose($fp);
if(!empty($dir[$i]))
{
@File_MkDirs(dirname($dir[$i]).'/');
if ($fp = fopen($dir[$i],'w')) {
fwrite($fp,$buffer);
}
else {
echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>digiconcept/netautor/site export</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onLoad="window.focus();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center>
<font color="Red" face="Arial, Helvetica, Courier"><b>Cannot open target file '."'".$dir[$i]."'".' !</b></font>
<br>
<br>
<a href="javascript:window.close();" style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" >'.($LOCALE->dgettext('system','window_close') ).'</a>
</center>
</body></html>');
}
@fclose($fp);
}
if ($params['DEBUG'])
{ /* Eine Quelle im DEBUG Modus ausgeben */
if ($i==0)
{
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>digiconcept/netautor/site export</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<style type="text/css">
<!--
.dummy {}
.exportdesc {font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;font-size : 10px;}
.exportcontent {font-family : "Courier New", Courier, monospace; font-size : 11px;
}
-->
</style>
<body onLoad="window.focus();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center><a href='javascript:window.close();' style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" ><?php echo $LOCALE->dgettext('system','window_close'); ?></a></center>
<br>
<?php
}
?>
<center>
<table border="1" cellspacing="0" cellpadding="2" align="center" width="95%">
<tr>
<td class="exportdesc">Source #<?php echo ($i+1); ?> : <a href="<?php echo $url; ?>" target="_blank"><?php echo $url; ?></a></td>
</tr>
<tr>
<td class="exportdesc">Target #<?php echo ($i+1); ?> : <?php echo $dir[$i]; ?></td>
</tr>
<tr>
<td >
<pre class="exportcontent"><?php echo htmlspecialchars($buffer);?></pre></td>
</tr>
</table>
</center>
<br>
<?
if (($i+1) == $max_i)
{
?>
<center><a href='javascript:window.close();' style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" ><?php echo $LOCALE->dgettext('system','window_close'); ?></a></center>
</body>
</html>
<?php
}
}
else
{
/* Eine Quelle im NORMAL Modus ausgeben */
if ($i==0) echo $buffer;
}
flush();
}
exit();
}
else if(!empty($urls))
{
$url = explode(',',magicReplacer(urldecode($urls),$myarray));
$web_base = new URL('http://'.$SERVER_NAME.':'.$SERVER_PORT.$DC_ENV->startindexpath);
for($i=0;$i<count($url);$i++)
{
echo $url[$i];
// Warum werden URL's nicht kopiert ?
}
}
}
else // Export von URLS oder MLAY_ID's
{
if(!empty($mlay_ids)) // MLAY_ID's exportieren
{
$time_start = time();
$id = explode(',',magicReplacer(urldecode($mlay_ids),$myarray));
for($i=0;$i<count($id);$i++)
{
if (empty($dir[$i])) $dir[$i]=$dir[max(0,$i-1)]; //-- Wenn aktuelles Dir leer, dann vorheriges verwenden
if (empty($source_params[$i])) $source_params[$i]=$source_params[max(0,$i-1)];
$web_world = new URL($LayoutParser.trim($id[$i]).'&'.trim($source_params[$i]).'&npf_cache=no&npf_debug=no');
$web_world->webCopyTo(trim($dir[$i]),$levels,$params);
if($i==0)
{
$web_clone = $web_world;
$redirect_path = trim($dir[0]);
}
}
$time_end=time();
}
else if(!empty($urls)) // URL's exportieren
{
$time_start =time();
$url = explode(',',magicReplacer(urldecode($urls),$myarray));
$web_base = new URL('http://'.$SERVER_NAME.':'.$SERVER_PORT.$DC_ENV->startindexpath);
for($i=0;$i<count($url);$i++)
{
if(!strstr($url[$i],'?')) $url[$i].='?';
if (empty($dir[$i])) $dir[$i]=$dir[max(0,$i-1)]; //-- Wenn aktuelles Dir leer, dann vorheriges verwenden
if (empty($source_params[$i])) $source_params[$i]=$source_params[max(0,$i-1)];
$web_world = new URL($url[$i].'&'.$source_params[$i]);
if (!$web_world->isAbsolute()) $web_world= $web_base->completeURL($url[$i].'&'.trim($source_params[$i]));
$web_world->webCopyTo(trim($dir[$i]),$levels,$params);
if ($i==0)
{
$web_clone = $web_world;
$redirect_path = trim($dir[0]);
}
}
$time_end = time();
}
}
if (isset($web_clone))
{
// Windows-Slashes korrigieren
$p = str_replace('//','/',str_replace("\\",'/',$redirect_path));
$q = str_replace("\\",'/',$GLOBALS['DC_ENV']->application_root);
// Das mit dem Redirect-Path funktionier natürlich nur, wenn der Export-Pfad
// ein bissal was mit der DOCUMENT_ROOT zu tun hat.
$redirect_path = '/'.chopleft($q,$p);
switch ($ResultAction)
{
case '1':
header('Location: '.trim($redirect_path));
exit();
break;
case '2':
echo($web_clone->getContent());
exit();
break;
case '4';
?>
<!--
Start:<?php echo(date('d.m.Y H:i:s',$time_start)); ?>
End: <?php echo(date('d.m.Y H:i:s',$time_end)); ?>
//-->
<?php
break;
default:
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<title>digiconcept/netautor/site export</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.dummy {}
.exportdesc {font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;font-size : 10px;}
.exportcontent {font-family : "Courier New", Courier, monospace; font-size : 11px; }
A {font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;font-size : 10px; color: Blue; text-decoration : underline;}
-->
</style>
<body class="exportdesc" onLoad="window.focus();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<div align="center" class="exportdesc" style="width: 100%;">
<center>
<b>Source(s) has/had been exported ..</b><br>
Start:<?php echo(date('d.m.Y H:i:s',$time_start)); ?><br>
End: <?php echo(date('d.m.Y H:i:s',$time_end)); ?><br>
Link to site<br><a href='<?php echo($redirect_path); ?>'><b><?php echo($redirect_path); ?></b></a>
<br>
<br>
<a href='javascript:window.close();' style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" ><?php echo $LOCALE->dgettext('system','window_close'); ?></a>
</center>
</div>
<script language='JavaScript'>window.focus();</script>
</body>
</html>
<?php
break;
}
}
else
{ ?>
<html>
<title>digiconcept/netautor/site export</title>
<body onLoad="window.focus();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center>
<font color="Red" face="Arial, Helvetica, Courier"><b>No valid sources given</b></font>
<center><a href='javascript:window.close();' style="font-size: 10px; font-style: normal; font-weight: normal; font-family: sans-serif;" ><?php echo $LOCALE->dgettext('system','window_close'); ?></a></center>
</font>
</center>
<script language='JavaScript'>document.forms[0].elements[0].focus();</script>
</body>
</html>
<?php
}
?>