home *** CD-ROM | disk | FTP | other *** search
/ Neil's C++ Stuff / 2002-11-php_neilstuff_com.zip / index.php < prev    next >
Text File  |  2002-06-03  |  16KB  |  562 lines

  1. <?include('_base.php');
  2.  
  3. $p = (int)@$HTTP_GET_VARS['p'];
  4. $map = @$HTTP_GET_VARS['map'];
  5. $uq = @$HTTP_GET_VARS['uq'];
  6.  
  7. /*****************************************************************************
  8.  
  9.     Declare Data Types and Functions
  10.  
  11. *****************************************************************************/
  12.  
  13. class Item
  14. {
  15.     var $name, $id, $level, $par, $child;
  16.     var $doc;
  17.     var $dir;
  18.  
  19.     function Item()
  20.     {
  21.         $this->doc = array();
  22.         $this->dir = array();
  23.     }
  24. }
  25.  
  26. class Map
  27. {
  28.     function Map()
  29.     {
  30.         $this->map = array();
  31.         $this->len = 0;
  32.         $this->level = 0;
  33.         $this->par = -1;
  34.     }
  35.  
  36.     function In(&$name, &$attrs)
  37.     {
  38.         $this->map[$this->len] = new Item;
  39.         $m =& $this->map[$this->len];
  40.         $m->par = $this->par;
  41.         if ($this->par >= 0)
  42.             $this->map[$this->par]->child++;
  43.         $m->level = $this->level;
  44.         $m->child = 0;
  45.         $keys = array_keys($attrs);
  46.         for ($i = 0; $i < count($keys); $i++)
  47.         {
  48.             $m->{strtolower($keys[$i])} = $attrs[$keys[$i]];
  49.         }
  50.         unset($m);
  51.         $this->par = $this->len;
  52.         $this->level++;
  53.         $this->len++;
  54.     }
  55.  
  56.     function Out()
  57.     {
  58.         $this->par = $this->map[$this->par]->par;
  59.         $this->level--;
  60.     }
  61. }
  62.  
  63. function me($i = -1)
  64. {
  65.     global $p;
  66.     if ($i < 0)
  67.         return 'index.php?p=' . $p;
  68.     return 'index.php?p=' . $i;
  69. }
  70.  
  71. function meu($u)
  72. {
  73.     global $map;
  74.     for ($i = 0; $i < $map->len; $i++)
  75.     {
  76.         if (isset($map->map[$i]->u) && $map->map[$i]->u == $u)
  77.             return 'index.php?p=' . $i;
  78.     }
  79.     return 'index.php?p=0';
  80. }
  81.  
  82. // random icon (16x16) link
  83. function rndilnk()
  84. {
  85.     return '<A HREF="http://www.gibdon.com/"><IMG SRC="gfx/icon/gm.gif" WIDTH=16 HEIGHT=16 BORDER=0></A>';
  86. /*
  87.     $url = 'http://free.be.com/';
  88.     $ico = 'icon.os/be.gif';
  89.  
  90.     switch (mt_rand(0,1))
  91.     {
  92.         case 0:
  93.             $url = 'http://free.be.com/';
  94.             $ico = 'icon.os/be.gif';
  95.             break;
  96.         case 1:
  97.             $url = 'http://www.textpad.com/';
  98.             $ico = 'icon/textpad.gif';
  99.             break;
  100.     }
  101.  
  102.     return '<A HREF="' . $url . '"><IMG SRC="gfx/' . $ico . '" WIDTH=16 HEIGHT=16 BORDER=0></A>';
  103. */
  104. }
  105.  
  106. /*****************************************************************************
  107.  
  108.     Load SiteMap
  109.  
  110. *****************************************************************************/
  111.  
  112. $map = new Map;
  113.  
  114. function startElement($parser, $name, $attrs){$GLOBALS['map']->In(&$name, &$attrs);}
  115.  
  116. function endElement($parser, $name){$GLOBALS['map']->Out();}
  117.  
  118. $xml_parser = xml_parser_create();
  119. xml_set_element_handler($xml_parser, "startElement", "endElement");
  120. if (!($fp = fopen("sitemap.xml", "r"))) {
  121.     die("Could not open sitemap.xml");
  122. }
  123.  
  124. while ($data = fread($fp, 4096)) {
  125.     if (!xml_parse($xml_parser, $data, feof($fp))) {
  126.         die(sprintf("XML error: %s at line %d",
  127.                 xml_error_string(xml_get_error_code($xml_parser)),
  128.                 xml_get_current_line_number($xml_parser)));
  129.     }
  130. }
  131.  
  132. xml_parser_free($xml_parser);
  133.  
  134. /*****************************************************************************
  135.  
  136.     Globals
  137.  
  138. *****************************************************************************/
  139.  
  140. //_[check out unique]_________________________________________________________
  141. //
  142. //
  143. if (isset($uq))
  144. {
  145.     for ($i = 0; $i < $map->len; $i++)
  146.     {
  147.         if (isset($map->map[$i]->u) && $map->map[$i]->u == $uq)
  148.         {
  149.             $p = $i;
  150.             break;
  151.         }
  152.     }
  153. }
  154. //_[check out direct url]_____________________________________________________
  155. //
  156. // This takes a relative url (../folder/doc.htm) and tries to find it in the
  157. // sitemap, based on the page where the relative url was at.
  158. //
  159. else if (isset($du))
  160. {
  161.     if ($du[0] != '#')
  162.     {
  163.         $refl = array();
  164.         $refc = 0;
  165.  
  166.         //-[seperate folders of url]------------------------------------------
  167.         while (($si = strpos($du, '/')) != false)
  168.         {
  169.             $si++;
  170.             $refl[$refc] = substr($du, 0, $si);
  171.             $refc++;
  172.             $du = substr($du, $si);
  173.         }
  174.         $refl[$refc] = $du;
  175.         $refc++;
  176.  
  177.         $found = true;
  178.  
  179.         //-[start at the page's "container"]----------------------------------
  180.         if ($map->map[$p]->child <= 0)
  181.             $p = $map->map[$p]->par;
  182.  
  183.         //-[move up containers based on '../']--------------------------------
  184.         for ($si = 0; $si < $refc; $si++)
  185.         {
  186.             if ($refl[$si] == '../')
  187.             {
  188.                 $p = $map->map[$p]->par;
  189.                 if ($p < 0)
  190.                     $p = 0;
  191.             }
  192.             else if ($refl[$si] == './' || $refl[$si] == '')
  193.             {
  194.             }
  195.             else
  196.             {
  197.                 break;
  198.             }
  199.         }
  200.  
  201.         //-[find container based on first folder name]------------------------
  202.         //
  203.         // This tries to find the first folder (../folder/doc.htm) as a
  204.         // container in the sitemap.  If it can't, then it moves to the second
  205.         // (if any) and on and on.  The start location for the search for the
  206.         // document will be in the container found.  If none are found then
  207.         // the search will start on the original container.
  208.         //
  209.         if ($si < $refc-1) for ( ; $p != -1; $p = $map->map[$p]->par)
  210.         {
  211.             for ($i = $map->map[$p]->par; $i >= 0 && $i < $map->len; $i++)
  212.             {
  213.                 if ($map->map[$i]->id == $refl[$si] &&
  214.                     $map->map[$i]->par == $p)
  215.                 {
  216.                     $p = $i;
  217.                     break;
  218.                 }
  219.             }
  220.  
  221.             if ($i < $map->len)
  222.                 break;
  223.         }
  224.         else
  225.         {
  226.             $si--;
  227.         }
  228.  
  229.         //-[search for document in this ($p) container]-----------------------
  230.         if ($p != -1) for ($si++; $si < $refc; $si++)
  231.         {
  232.             if ($refl[$si] == '')
  233.                 continue;
  234.  
  235.             for ($i = $p; $i < $map->len; $i++)
  236.             {
  237.                 if ($map->map[$i]->id == $refl[$si] &&
  238.                     ($map->map[$i]->par == $p ||
  239.                     $map->map[$i]->par == $map->map[$i]->par))
  240.                 {
  241.                     $p = $i;
  242.                     break;
  243.                 }
  244.             }
  245.         }
  246.         $du = '';
  247.  
  248.         if ($p == -1)
  249.             $p = 0;
  250.     }
  251. }
  252.  
  253. $page =& $map->map[$p];
  254.  
  255. if (!isset($page->name))
  256.     $page->name = 'Untitled';
  257.  
  258. if (!isset($page->title))
  259.     $page->title = $page->name;
  260.  
  261. if (!isset($page->quote))
  262.     $page->quote = '               ';
  263.  
  264. $menufont = "Lucida Console,Courier New";
  265. $contentfont = 'Verdana,Arial Narrow,Arial,Times New Roman';
  266.  
  267. if (!isset($page->desc))
  268.     $page->desc = ' ';
  269.  
  270. $styles =
  271.     "<STYLE TYPE=\"text/css\"><!--\n" .
  272.         "A:hover {text-decoration:underline; color:7F7FFF}\n" .
  273.         ".button { font-size:8pt;border-style:solid;border-width:1;width:300px;height:30px; }\n" .
  274.     "--></STYLE>";
  275.  
  276. $metatags =
  277.     '<META NAME="GENERATOR" CONTENT="TextPad (www.textpad.com) and PHP (www.php.net)">' .
  278.     '<META NAME="AUTHOR" CONTENT="Neil C. Obremski">' .
  279.     '<META NAME="DESCRIPTION" CONTENT="This is my personal dedication to bringing you as much valid information about C++ as I am able; represented by links, tutorials, articles, newsletters, and example source code.">' .
  280.     '<META NAME="KEYWORDS" CONTENT="free, c++, tutorials, examples, source, code, articles">';
  281. /*
  282. if ( (!isset($page->u) || $page->u != 'admin') &&
  283.         isset($_SERVER['REMOTE_PORT']) )
  284. {
  285.     if ($p == 0)
  286.         $valid = 'indexpage';
  287.     else
  288.         $valid = 'sub' . $p;
  289.  
  290.     $banner2 = '<!-- BEGIN LINKEXCHANGE CODE --><iframe src="http://leader.linkexchange.com/1/X866573/showiframe?" width=468 height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no><a href="http://leader.linkexchange.com/1/X866573/clickle" target="_top"><img width=468 height=60 border=0 ismap alt="" src="http://leader.linkexchange.com/1/X866573/showle?"></a></iframe><br><a href="http://leader.linkexchange.com/1/X866573/clicklogo" target="_top"><img src="http://leader.linkexchange.com/1/X866573/showlogo?" width=468 height=16 border=0 ismap alt=""></a><br><!-- END LINKEXCHANGE CODE -->';
  291.  
  292.     $banner1 =
  293.         "<!-- VC active -->" .
  294.         "<SCRIPT LANGUAGE=\"JavaScript\">\n" .
  295.         "<!--\n" .
  296.         "// ValueParameters\n" .
  297.         "ValueBgColor = \"#C0C0C0\";\n" .
  298.         "ValueLinkColor = \"#007F00\";\n" .
  299.         "ValueAlinkColor = \"#7F7FFF\";\n" .
  300.         "ValueVlinkColor = \"#7F0000\";\n" .
  301.         "ValueHost = \"hs0040699\"\n;" .
  302.         "ValueLoaded = false;\n" .
  303.         "ValueID = \"valueid\";\n" .
  304.         "ValueVersion = \"1.1\";\n" .
  305.         "ValueWidth = 468;\n" .
  306.         "ValueHeight = 60;\n" .
  307.         "//-->\n" .
  308.         "</SCRIPT>" .
  309.         "<SCRIPT LANGUAGE=\"Javascript\" SRC=\"http://oz.valueclick.com/jsmaster\"></SCRIPT>" .
  310.         "<SCRIPT LANGUAGE=\"JavaScript\">\n" .
  311.         "<!--\n" .
  312.         "if (ValueLoaded) ValueShowAd();\n" .
  313.         "//-->\n" .
  314.         "</SCRIPT>" .
  315.         "<NOSCRIPT>" .
  316.         "<A HREF=\"http://kansas.valueclick.com/redirect?host=hs0040699&size=468x60&b={$valid}&v=0\" TARGET=\"_top\"><IMG BORDER=\"0\" WIDTH=\"468\" HEIGHT=\"60\" ALT=\"Click here to visit our sponsor\" SRC=\"http://kansas.valueclick.com/cycle?host=hs0040699&size=468x60&b={$valid}&noscript=1\"></A>" .
  317.         "</NOSCRIPT>" .
  318.         "<!-- vc active -->";
  319. }
  320. else*/
  321. {
  322.     $banner1 = '';
  323.     $banner2 = '';
  324. }
  325.  
  326. /*****************************************************************************
  327.  
  328.     Generate Header
  329.  
  330. *****************************************************************************/
  331.  
  332. $header =
  333.     '<HTML>' .
  334.     '<HEAD>' .
  335.         '<TITLE>' . $page->title . ' (Neil Stuff)</TITLE>' .
  336.     $styles .
  337.     $metatags .
  338.     '</HEAD>' .
  339.     '<BODY BGCOLOR="EEEEEE" TEXT="000000" LINK="007F00" VLINK="7F0000" ALINK="7F7FFF" MARGINHEIGHT=0 MARGINWIDTH=0 TOPMARGIN=0 LEFTMARGIN=0 BOTTOMMARGIN=0 RIGHTMARGIN=0>' .
  340.  
  341.     '<TABLE WIDTH=100% BORDER=2 CELLPADDING=0 CELLSPACING=0 BGCOLOR=C0C0C0><TD>' .
  342.         '<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>' .
  343.         '<TR><TD ALIGN=CENTER COLSPAN=2>' .
  344.             $banner1 .
  345.         '</TD></TR>' .
  346.         '<TR><TD ALIGN=LEFT WIDTH=50%>' .
  347.             '<FONT SIZE=+3 FACE="Arial"><B>' .
  348.             $page->title .
  349.             '</B></FONT><BR>' .
  350.         '</TD>' .
  351.         '<TD ALIGN=RIGHT WIDTH=50%><FONT SIZE=-1 FACE="Arial Narrow"><B>' .
  352.             $page->desc .
  353.         '</B></FONT></TD></TR>' .
  354.         '<TR><TD ALIGN=LEFT COLSPAN=2><FONT FACE="' . $menufont .'" SIZE=-1>[ </FONT>';
  355.  
  356. $dirlist = '<FONT FACE="' . $menufont .'" SIZE=-1><A HREF="' . me() . '">' . $page->name . '</A></FONT>' . (($page->child>0)?'<FONT FACE="Arial,Sans Serif" SIZE=-1> / </FONT>':' ') . ']</FONT>';
  357. $srcfile = $page->id;
  358. $srcdir = '';
  359.  
  360. if ($page->par != -1)
  361. {
  362.     for ($i = $page->par; $map->map[$i]->par != -1; $i = $map->map[$i]->par)
  363.     {
  364.         $dirlist = ('<FONT FACE="' . $menufont . '" SIZE=-1><A HREF="' . me($i) . '">' . $map->map[$i]->name . '</A></FONT><FONT FACE="Arial,Sans Serif" SIZE=-1> / </FONT>' . $dirlist);
  365.         $srcfile = ($map->map[$i]->id . $srcfile);
  366.         $srcdir = ($map->map[$i]->id . $srcdir);
  367.     }
  368.  
  369.     $dirlist = ('<FONT FACE="' . $menufont . '" SIZE=-1><A HREF="' . me(0) . '">' . $map->map[0]->name . '</A></FONT><FONT FACE="Arial,Sans Serif" SIZE=-1> / </FONT>' . $dirlist);
  370. }
  371.  
  372. $srcfile = ($base . '/' .$srcfile);
  373.  
  374. $header .= (
  375.     $dirlist .
  376.     '</TD></TR>' .
  377.     '</TABLE></TD></TABLE>'
  378. );
  379.  
  380. /*****************************************************************************
  381.  
  382.     Generate Content Shell
  383.  
  384. *****************************************************************************/
  385.  
  386. //_[header html of menu]______________________________________________________
  387. $content =
  388.     '<TABLE WIDTH=100% BORDER=0 CELLBORDER=0 CELLSPACING=0 CELLPADDING=5>' .
  389.     '<TR><TD VALIGN=TOP ALIGN=CENTER>' .
  390.     '<TABLE ALIGN=LEFT BGCOLOR=C0C0C0 BORDER=2 CELLSPACING=0 CELLPADDING=2>' .
  391.     '<TR><TD COLSPAN=3 BGCOLOR=7F7FFF ALIGN=CENTER><FONT FACE="Primer Print" COLOR=000000 SIZE=+3><B>Menu</B></FONT></TD></TR>' .
  392.     '<TR><TD BGCOLOR=C0C0C0 COLSPAN=3 ALIGN=LEFT>';
  393.  
  394. //_[decide who the owner of the menu is]______________________________________
  395. if ($page->child > 0)
  396.     $o = $p;
  397. else
  398.     $o = $page->par;
  399. $owner =& $map->map[$o];
  400.  
  401. //_[write out menu]___________________________________________________________
  402. for ($i = $o; $i < $map->len; $i++)
  403. {
  404.     $m =& $map->map[$i];
  405.     if ($m->par == $o)
  406.     {
  407.         if ($m->t == '-')
  408.         {
  409.             $content .= '<HR>';
  410.             unset($m);
  411.             continue;
  412.         }
  413.  
  414.         if (isset($m->ico))
  415.             $icon = $m->ico;
  416.         else if ($m->child > 0)
  417.             $icon = 'icon/folder.gif';
  418.         else
  419.             $icon = 'icon.map/' . $m->t . '.gif';
  420.  
  421.         $content .=
  422.             '<A HREF="' . me($i) . '"><IMG SRC="gfx/' . $icon . '" WIDTH=16 HEIGHT=16 BORDER=0></A><FONT FACE="Arial,Sans Serif" SIZE=-1> <A HREF="' . me($i) . '">' . str_replace(' ', ' ', $map->map[$i]->name) . '</A></FONT><BR>';
  423.     }
  424.     unset($m);
  425. }
  426.  
  427. //_[back page is always the parent of the menu owner]_________________________
  428. //
  429. // Neil don't be stupid and try to change this ... it's RIGHT this time!
  430. //
  431. $back = $map->map[$o]->par;
  432.  
  433. if ($back >= 0)
  434. {
  435.     if (isset($map->map[$back]->ico))
  436.         $icon = $map->map[$back]->ico;
  437.     else
  438.         $icon = 'icon/back.gif';
  439.  
  440.     $content .= (
  441.         '<HR>' .
  442.         '<A HREF="' . me($back) . '"><IMG SRC="gfx/' . $icon . '" WIDTH=16 HEIGHT=16 BORDER=0></A><FONT FACE="Arial,Sans Serif" SIZE=-1> <A HREF="' . me($back) . '">Back to ' . str_replace(' ', ' ', $map->map[$back]->name) . '</A></FONT>'
  443.     );
  444. }
  445.  
  446. //_[footer html of menu]______________________________________________________
  447. $content .= (
  448.  
  449.     '</TD></TR>' .
  450.     '<TR><TD ALIGN=LEFT VALIGN=BOTTOM BGCOLOR=C0C0C0>' . rndilnk() . '</TD><TD ALIGN=LEFT BGCOLOR=C0C0C0><FONT FACE="MS Sans Serif, Arial" SIZE=-2>' .
  451.         str_replace(' ', ' ', $page->quote) .
  452.     '</FONT></TD><TD ALIGN=RIGHT VALIGN=BOTTOM BGCOLOR=C0C0C0><IMG WIDTH=16 HEIGHT=16 SRC="gfx/table/cornpull.gif"></TD></TR>' .
  453.     '</TABLE></TD><TD VALIGN=TOP ALIGN=LEFT WIDTH=100%><FONT FACE="' . $contentfont . '">'
  454. );
  455.  
  456. /*****************************************************************************
  457.  
  458.     Generate Footer
  459.  
  460. *****************************************************************************/
  461.  
  462. $footer =
  463.     '</FONT></TD></TR></TABLE>'    .'<TABLE WIDTH=100% BORDER=2 CELLPADDING=0 CELLSPACING=0 BGCOLOR=C0C0C0><TD>' .
  464.     '<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>' .
  465.         '<TR><TD ALIGN=CENTER>' .
  466.         '<FONT SIZE=-1 FACE="Arial Narrow"><B>' .
  467.             '©opyright 1998, 1999, 2000, 2001++ by Neil C. Obremski' .
  468.         '</B></FONT>' .
  469.         '<BR>' .
  470.         '<I><FONT SIZE=-2 FACE="Arial">Any unauthorized distribution of this site, and/or it\'s content, in any form is strictly prohibited.</FONT></I>' .
  471.         '</TD></TR>' .
  472.         '<TR><TD ALIGN=CENTER>' .
  473.             $banner2 .
  474.         '</TD></TR>' .
  475.     '</TABLE></TD></TABLE>' .
  476.     '</BODY>' .
  477.     '</HTML>'
  478. ;
  479.  
  480. /*****************************************************************************
  481.  
  482.     Output
  483.  
  484. *****************************************************************************/
  485.  
  486. mt_srand ((double) microtime() * 1000000);
  487. echo($header . $content);
  488.  
  489. if ($page->child > 0 && @is_file($srcfile) == false)
  490. {
  491.     $srcfile .= '_desc.';
  492.     $srcfile .= $page->t;
  493. }
  494.  
  495. if (isset($du) && $du != '')
  496. {
  497.     if (@is_file($srcfile))
  498.     {
  499.         echo('Click the link below to view or download the file.<BR><BR><A HREF="' . $srcdir . $du . '">' . $du . '</A>');
  500.     }
  501.     else
  502.     {
  503.         echo('Couldn\'t find "' . $srcdir . $du . '".  Sorry.');
  504.     }
  505. }
  506. else if (@is_file($srcfile) == false)
  507. {
  508.     // file not found
  509. }
  510. else switch ($page->t)
  511. {
  512.     case 'in':
  513.     {
  514.         $inp = implode('', file($srcfile));
  515.         $inp = str_replace('@rndilnk@', rndilnk(), $inp);
  516.  
  517.         while (($stof = strpos($inp, '"@')) != false)
  518.         {
  519.             $stof ++;
  520.             $endof = strpos($inp, '@"') + 1;
  521.             $uniq = substr($inp, $stof+1, $endof - $stof - 2);
  522.  
  523.             for ($i = 0; $i < $map->len; $i++)
  524.             {
  525.                 if (isset($map->map[$i]->u) && $map->map[$i]->u == $uniq)
  526.                 {
  527.                     break;
  528.                 }
  529.             }
  530.             if ($i >= $map->len)
  531.                 $i = 0;
  532.  
  533.             $inp = substr_replace($inp, me($i), $stof, $endof - $stof);
  534.         }
  535.  
  536.         echo($inp);
  537.  
  538.     }    break;
  539.     case 'exe':
  540.     case 'bat':
  541.     case 'zip':
  542.     {
  543.         $fsz = filesize($srcfile) / 1024;
  544.         $fsz *= 10;
  545.         $fsz = (int)$fsz;
  546.         $fsz /= 10;
  547.         echo('<A HREF="' . $srcdir . $page->id . '">Download ' . $page->name . '</A> (' . $fsz . 'k)');
  548.     }    break;
  549.     case 'php':
  550.     {
  551.         include($srcfile);
  552.     }    break;
  553.     default:
  554.     {
  555.         include('_' . $page->t . '.php');
  556.         break;
  557.     }
  558. }
  559.  
  560. echo($footer);
  561.  
  562. ?>