Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/modules/NS-Wiki/stdlib.inc.php
<?php 
global $serverName;
if (!empty($serverName)) {
    if (file_exists("parameters/".$serverName."/configWIKI.inc.php")) {
        include("parameters/".$serverName."/configWIKI.inc.php");
    } else {
        include("modules/NS-Wiki/configWIKI.inc.php");
    }
} else {
    include("modules/NS-Wiki/configWIKI.inc.php");
}


// rcs_id('$Id: stdlib.inc.php,v 1.9 2001/11/12 16:08:10 mouzaia Exp $');

   /*
      Standard functions for Wiki functionality
         PNExitWiki($errormsg)
         PNLinkURL($url, $linktext)
         PNLinkImage($url, $alt)
         PNCookSpaces($pagearray) 
         class PNStack (push(), pop(), cnt(), top())
         PNSetHTMLOutputMode($newmode, $depth)
         PNParseAndLink($bracketlink)
   */


   function PNExitWiki($errormsg)
   {
      static $exitwiki = 0;
      if($exitwiki)		// just in case CloseDataBase calls us
         exit();
      $exitwiki = 1;

      if($errormsg <> '') {
         print "<P><hr noshade><h2>" . gettext("WikiFatalError") . "</h2>\n";
         print $errormsg;
         print "\n</BODY></HTML>";
      }
      exit;
   }

   function PNLinkURL($url, $linktext='', $autreFenetre=false ) {
      if(ereg("[<>\"]", $url)) {
         return "<b><u>BAD URL -- remove all of &lt;, &gt;, &quot;</u></b>";
      }
      if(empty($linktext))
         $linktext = htmlspecialchars($url);

	  if ($autreFenetre) {
	  	 $target = " target=\"sb\"";
      } else {
	  	 $target = "";
		 }	 
      return "<a href=\"$url\"". $target.">$linktext</a>";
   }



   function PNLinkImage($url, $alt='' ) {
      global $PNlExtlinkNewWindow,$PNlIntlinkNewWindow; 

      if(ereg('[<>]', $url)) {
         return "<b><u>BAD URL -- remove all of &lt;, &gt;, &quot;</u></b>";
     }
	$link = '';

	$chaine = substr ($alt, 0, strpos($alt, '+'));
	if (!(empty($chaine)))
		{ 
		$link = substr ($alt, strpos($alt, '+') + 1);
		$alt =  substr ($alt, 0, strpos($alt, '+'));
		}


	$cRetour  = "\n";
	$cRetour .= "<!-- inclusion de la photo de l'article. -->\n";
	$cRetour .= "<table cellspacing=0 cellpadding=5 border=0 align=left>\n";
	$cRetour .= "<tr><td valign=top justify>\n";
	
	if (!(empty($link)))
		{
		$cRetour .= "<a href=".$link ;
		if (strstr("http://",$link) and $PNlExtlinkNewWindow )
			{ $cRetour .= " target='_blank' "; } 
		elseif ( ($PNlIntlinkNewWindow) )
			{ $cRetour .= " target='_blank' "; } 
		

		$cRetour .= ">" ;
		}
	$cRetour .= "<img src=$url ALT=\"$alt\" border=0>\n";
	if (!(empty($link)))
		{
		$cRetour .= "</a>" ;
		}
	$cRetour .= "</td></tr></table>\n";
	$cRetour .= "<!-- fin de l'inclusion de la photo de l'article. -->\n";
	return $cRetour;
   }

   // converts spaces to tabs
   function PNCookSpaces($pagearray) {
      return preg_replace("/ {3,8}/", "\t", $pagearray);
   }


   class PNStack {
      var $items = array();
      var $size = 0;

      function push($item) {
         $this->items[$this->size] = $item;
         $this->size++;
         return true;
      }  
   
      function pop() {
         if ($this->size == 0) {
            return false; // stack is empty
         }  
         $this->size--;
         return $this->items[$this->size];
      }  
   
      function cnt() {
         return $this->size;
      }  

      function top() {
         if($this->size)
            return $this->items[$this->size - 1];
         else
            return '';
      }  

   }  
   // end class definition


   // I couldn't move this to lib/config.php because it wasn't declared yet.

// globalize it here cause pninclude_once.
   global $PNstack;
   $PNstack = new PNStack;

   /* 
      Wiki HTML output can, at any given time, be in only one mode.
      It will be something like Unordered List, Preformatted Text,
      plain text etc. When we change modes we have to issue close tags
      for one mode and start tags for another.

      $tag ... HTML tag to insert
      $tagtype ... ZERO_LEVEL - close all open tags before inserting $tag
		   NESTED_LEVEL - close tags until depths match
      $level ... nesting level (depth) of $tag
		 nesting is arbitrary limited to 10 levels
   */

   function PNSetHTMLOutputMode($tag, $tagtype, $level)
   {

	  global $PNstack;
      $retvar = '';

      if ($tagtype == ZERO_LEVEL) {
         // empty the stack until $level == 0;
         if ($tag == $PNstack->top()) {
            return; // same tag? -> nothing to do
         }
         while ($PNstack->cnt() > 0) {
            $closetag = $PNstack->pop();
            $retvar .= "</$closetag>\n";
         }
   
         if ($tag) {
            $retvar .= "<$tag>\n";
            $PNstack->push($tag);
         }


      } elseif ($tagtype == NESTED_LEVEL) {
         if ($level < $PNstack->cnt()) {
            // $tag has fewer nestings (old: tabs) than stack,
		    // reduce stack to that tab count
            while ($PNstack->cnt() > $level) {
               $closetag = $PNstack->pop();
               if ($closetag == false) {
                  //echo "bounds error in tag stack";
                  break;
               }
               $retvar .= "</$closetag>\n";
            }

	    // if list type isn't the same,
	    // back up one more and push new tag
	    if ($tag != $PNstack->top()) {
	       $closetag = $PNstack->pop();
	       $retvar .= "</$closetag><$tag>\n";
	       $PNstack->push($tag);
	    }
   
         } elseif ($level > $PNstack->cnt()) {
            // we add the diff to the stack
            // stack might be zero
            while ($PNstack->cnt() < $level) {
               $retvar .= "<$tag>\n";
               $PNstack->push($tag);
               if ($PNstack->cnt() > 10) {
                  // arbitrarily limit tag nesting
                  PNExitWiki(gettext ("Stack bounds exceeded in SetHTMLOutputMode"));
               }
            }
   
         } else { // $level == $PNstack->cnt()
            if ($tag == $PNstack->top()) {
               return; // same tag? -> nothing to do
            } else {
	       // different tag - close old one, add new one
               $closetag = $PNstack->pop();
               $retvar .= "</$closetag>\n";
               $retvar .= "<$tag>\n";
               $PNstack->push($tag);
            }
         }

   
      } else { // unknown $tagtype
         ExitWiki ("Passed bad tag type value in SetHTMLOutputMode");
      }

      return $retvar;
   }
   // end SetHTMLOutputMode



   function PNParseAndLink($bracketlink) {

      global $PNAllowedProtocols, $PNInlineImages;
      global $PNlExtlinkNewWindow, $PNlIntlinkNewWindow;

      // $bracketlink will start and end with brackets; in between
      // will be either a page name, a URL or both separated by a pipe.
	  // ou bien du texte, si bbcode.

      // strip brackets and leading space
      preg_match("/(\[\s*)(.+?)(\s*\])/", $bracketlink, $match);

	  if ( isset($match[3]) and ($match[3]==']') and ( ($match[2]=='b') or ($match[2]=='i') or ($match[2]=='/b') or ($match[2]=='/i') )  )
		{

		  	$link[type] = "bbcode";
		  	$link[link] = "<".$match[2].">";
			
		}	
		else
		{
			// match the contents 
	      	preg_match("/([^|]+)(\|)?([^|]+)?/", $match[2], $matches);

    		if (isset($matches[3])) {
         		// named link of the form  "[some link name | http://blippy.com/]"
		         $URL = trim($matches[3]);
		         $linkname = htmlspecialchars(trim($matches[1]));
				 $linktype = 'named';
		      } else {
		         // unnamed link of the form "[http://blippy.com/] or [wiki page]"
		         $URL = trim($matches[1]);
				 $linkname = '';
				 $linktype = 'simple';
		      }
		   	if (preg_match("#^($PNAllowedProtocols):#", $URL)) {
		       	// if it's an image, embed it; otherwise, it's a regular link
		         if (preg_match("/($PNInlineImages)$/i", $URL )) {
				    $link['type'] = "image-$linktype";
		            $link['link'] = PNLinkImage($URL, $linkname);
		         } else {
				    $link['type'] = "url-$linktype";
		            $link['link'] = PNLinkURL($URL, $linkname, $PNlExtlinkNewWindow ); }
			} elseif (preg_match("#^picture:(.*)#", $URL, $match)) {
				$link['type'] = "image-$linktype";
				$link['link'] = PNLinkImage("\"$match[1]\"",$linkname);
			} elseif (preg_match("#^photo:(.*)#", $URL, $match)) {
				$link['type'] = "image-$linktype";
				$link['link'] = PNLinkImage("\"$match[1]\"",$linkname);
			} elseif (preg_match("#^phpwiki:(.*)#", $URL, $match)) {
				$link['type'] = "url-wiki-$linktype";
				if(empty($linkname))
				    { $linkname = htmlspecialchars($URL); }
				$link['link'] = "<a href=\"$match[1]\">$linkname</a>";
			} elseif (preg_match("#^\d+$#", $URL)) {
		        $link['type'] = "reference-$linktype";
				$link['link'] = $URL;
			} else {
			    $link['type'] = "url-$linktype";
				$link['link'] = PNLinkURL($URL, $linkname, $PNlIntlinkNewWindow );
			}
		}		
	return $link;
}


   
?>
Return current item: ProNuke. Postnuke To Oracle