<?php
/*
 * $Header: /cvsroot/tikiwiki/tiki/lib/wiki-plugins/wikiplugin_box.php,v 1.3 2003/07/05 17:33:10 ohertel Exp $
 *
 * Tiki-Wiki BOX plugin.
 * 
 * Syntax:
 * 
 *  {BOX([title=>Title],[bg=color],[width=>num[%]])}
 *   Text inside box
 *  {BOX}
 * 
 */

function wikiplugin_loadpage_help() {
  return tra("Loads a complete WebPage into the Wiki page.<BR>Parameter: page=Page to load, replaceLink=add this URL to all Links, onlyBody='yes' search for body tag to diplay only body.");
}

  function replaceLinks($readBuf, $replacementURL)
  {
	$readBuf = Str_replace("action=\"", "target=\"_new\" action=\"$replacementURL", $readBuf);
	$readBuf = Str_replace("src=\"", "src=\"$replacementURL", $readBuf);
	$readBuf = Str_replace("href=\"", "target=\"_new\" href=\"$replacementURL", $readBuf);
	$readBuf = Str_replace("href=", "target=\"_new\" href=$replacementURL", $readBuf);
	
	return $readBuf;	
  }

  function escapeme($data)
  {
//	  $data = Str_replace("&", "&amp;", $data);
//	  $data = Str_replace("<", "&lt;", $data);
//	  $data = Str_replace(">", "&gt;", $data);
/*	  $data = Str_replace("ß", "&szlig;", $data);
	  $data = Str_replace("ä", "&auml;", $data);
	  $data = Str_replace("ö", "&ouml;", $data);
	  $data = Str_replace("ü", "&uuml;", $data);
	  $data = Str_replace("Ä", "&Auml;", $data);
	  $data = Str_replace("Ö", "&Ouml;", $data);
	  $data = Str_replace("Ü", "&Uuml;", $data);
	  $data = Str_replace("€", "&euro;", $data);
//	  $data = Str_replace("\"", "&quot;", $data);  	
  */	
  
//	  $data = Str_replace("?", "&quot;", $data);  	
	  return $data;
  }
function wikiplugin_loadpage($data,$params) {
  /* set default values for some args */
  $title="Message box";

  $data = Str_replace("\n", "<br>", $data);


  extract($params);

  if(!isset($page))
  	return "You have to specifie a 'page'";

  // Open the Source URL, to acquire all Data.
  $fp = fopen($page, "r");

  $readBuf = "";
  // Read all Data into readBuf.
  // I thought about Letting the script search for the start and later the end tag
  // while loading, but didn't knew if that would weight the performance.

  while(!feof($fp))
  {
	$readBuf .= fread($fp, 1);
  }
  // Close the Source.
  fclose($fp);

  if(isset($onlyBody))
  {
  	if($onlyBody == "yes")
  	{
  		$start_Pattern = "<body";
  		$end_Pattern = "</body>";
  		
	  	$start = strpos($readBuf, $start_Pattern);
		$end = strpos($readBuf, $end_Pattern, $start);
		$readBuf = substr($readBuf, $start, $end - $start + strlen($end_Pattern));	
		
			
		
  	}	
  }

  if(isset($replaceLink))
  {
	$readBuf = replaceLinks($readBuf, $replaceLink);
  }
 
 // $readBuf = escapeme($readBuf);

  return $readBuf;
  

}

?>
