daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest May 26th, 2018 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head><title>KoL Documentation v2</title></head>
  3. <body>
  4. <?php
  5.  
  6. set_magic_quotes_runtime(0);
  7.  
  8. $dbuser="mydom_chris22";
  9. $dbname="mydomains_koldocs";
  10. $dbhost="localhost";
  11. $dbpass="xxx";
  12.  
  13. // INITIALIZE DATABASE
  14. mysql_connect ("$dbhost:3306", "$dbuser", "$dbpass");
  15. mysql_select_db ("$dbname");
  16.  
  17. function grab($tablename, $keyval, $rkey, $thekey = "ID") {
  18.  
  19.     if($rkey=="*") $query2 = "SELECT * FROM `$tablename` WHERE `$thekey`=\"$keyval\"";
  20.     else $query2 = "SELECT `$rkey` FROM `$tablename` WHERE `$thekey`=\"$keyval\"";
  21.     //echo "<!-- QUERY: $query2 -->\n";
  22.     $qrh2 = mysql_query ($query2);
  23.     $row2 = mysql_fetch_array ($qrh2);
  24.     $nor = mysql_num_rows ($qrh2);
  25.     if ($nor==0) {
  26.         // echo "<!-- Found no rows for query: $query2 -->\n";
  27.         return -1;
  28.     } else {
  29.         if ($rkey!="*") {
  30.             $picked = $row2[0];
  31.             return $picked;
  32.         } else {
  33.             $picked=$row2;
  34.             return $picked;
  35.         }
  36.     }
  37. }
  38.  
  39. if(!$page) {
  40.     // Show TOC
  41.     echo "<h2>Kingdom of Loathing Documentation</h2><p>\n";
  42.  
  43.     echo "<font size=2><ul>\n";
  44.  
  45.     $query="SELECT * FROM `docpages` WHERE parent=0 ORDER BY sequence,title";
  46.     $qrh=mysql_query($query);
  47.     while($row=mysql_fetch_array($qrh)) {
  48.         $thelit=$row["title"];
  49.         $thepage=$row["reftag"];
  50.         echo "<li><a href=$PHP_SELF?page=$thepage>$thelit</a></li>\n";
  51.     }
  52.  
  53.     echo "</ul></font>\n";
  54.  
  55.  
  56. } else {
  57.     // Show requested page, or error message
  58.  
  59.     $theid=grab("docpages",$page,"ID","reftag");
  60.     $thetitle=grab("docpages",$page,"title","reftag");
  61.     $thedad=grab("docpages",$page,"parent","reftag");
  62.     $theseq=grab("docpages",$page,"sequence","reftag");
  63.     if($thetitle=="-1") $thetitle="I AM ERROR";
  64.  
  65.     $prev="";
  66.     $next="";
  67.  
  68.     // 1 - Lowest child of the previous sibling, or previous sibling
  69.     $query3="SELECT * FROM `docpages` WHERE parent=$thedad AND sequence<$theseq ORDER BY sequence DESC LIMIT 1";
  70.     $qrh3=mysql_query($query3);
  71.     if($row=mysql_fetch_array($qrh3)) {
  72.         $previd=$row["ID"];
  73.         $prevref=$row["reftag"];
  74.         $prevname=$row["title"];
  75.  
  76.         $query4="SELECT * FROM `docpages` WHERE parent=$previd ORDER BY sequence DESC LIMIT 1";
  77.         $qrh4=mysql_query($query4);
  78.         if($row4=mysql_fetch_array($qrh4)) {
  79.             $previd=$row4["ID"];
  80.             $prevref=$row4["reftag"];
  81.             $prevname=$row4["title"];
  82.         }
  83.  
  84.         $prev="<a href=$PHP_SELF?page=$prevref title=\"$prevname\"><img src=leftarrow.gif></a> ";
  85.     }
  86.  
  87.     // 2 - Dad
  88.     if($prev=="") {
  89.         $query3="SELECT * FROM `docpages` WHERE ID=$thedad LIMIT 1";
  90.         $qrh3=mysql_query($query3);
  91.         if($row=mysql_fetch_array($qrh3)) {
  92.             $prevref=$row["reftag"];
  93.             $prevname=$row["title"];
  94.             $prev="<a href=$PHP_SELF?page=$prevref title=\"$prevname\"><img src=leftarrow.gif></a> ";
  95.         }
  96.     }
  97.  
  98.  
  99.     // 1 - Lowest-sequence child
  100.     $query3="SELECT * FROM `docpages` WHERE parent=$theid ORDER BY sequence LIMIT 1";
  101.     $qrh3=mysql_query($query3);
  102.     if($row=mysql_fetch_array($qrh3)) {
  103.         $nextref=$row["reftag"];
  104.         $nextname=$row["title"];
  105.         $next=" <a href=$PHP_SELF?page=$nextref title=\"$nextname\"><img src=rightarrow.gif></a>";
  106.     }
  107.  
  108.  
  109.     // 2 - Next sibling
  110.     if($next=="") {
  111.         $query3="SELECT * FROM `docpages` WHERE parent=$thedad AND sequence>$theseq ORDER BY sequence LIMIT 1";
  112.         $qrh3=mysql_query($query3);
  113.         if($row=mysql_fetch_array($qrh3)) {
  114.             $nextref=$row["reftag"];
  115.             $nextname=$row["title"];
  116.             $next=" <a href=$PHP_SELF?page=$nextref title=\"$nextname\"><img src=rightarrow.gif></a>";
  117.         }
  118.     }
  119.  
  120.     // 3 - Next sibling for Dad
  121.     if($next=="") {
  122.         $daddad=grab("docpages",$thedad,"parent");
  123.         $dadseq=grab("docpages",$thedad,"sequence");
  124.         //echo "<!-- Curr doc is $theid -- thedad is $thedad -- daddad is $daddad -- dadseq is $dadseq -->\n";
  125.         $query3="SELECT * FROM `docpages` WHERE parent=$daddad AND sequence>$dadseq ORDER BY sequence LIMIT 1";
  126.         //echo "<!-- $query3 -->\n";
  127.         $qrh3=mysql_query($query3);
  128.         if($row=mysql_fetch_array($qrh3)) {
  129.             $nextid=$row["ID"];
  130.             $nextref=$row["reftag"];
  131.             $nextname=$row["title"];
  132.             //echo "<!-- nextid is $nextid and nextref is $nextref -->\n";
  133.             $next=" <a href=$PHP_SELF?page=$nextref title=\"$nextname\"><img src=rightarrow.gif></a>";
  134.         }
  135.     }
  136.  
  137.  
  138.     echo "<font size=2><b>\n";
  139.     $finished=0;
  140.     $currdad=$thedad;
  141.     $trail="";
  142.     while(!$finished) {
  143.         $dadtitle=grab("docpages",$currdad,"title");
  144.         $dadref=grab("docpages",$currdad,"reftag");
  145.         if($dadtitle=="-1") {
  146.             $trail="<a href=$PHP_SELF>Documentation Home</a> >> ".$trail;
  147.             $finished=1;
  148.         } else {
  149.             $trail="<a href=$PHP_SELF?page=$dadref>$dadtitle</a> >> ".$trail;
  150.             $daddad=grab("docpages",$currdad,"parent");
  151.             $currdad=$daddad;
  152.         }
  153.     }
  154.  
  155.     echo "$prev $next<br>\n";
  156.     echo $trail;
  157.     echo "</b>\n";
  158.     echo "<ul>\n";
  159.  
  160.     $query6="SELECT * FROM `docpages` WHERE parent=$thedad ORDER BY sequence, title";
  161.     $qrh6=mysql_query($query6);
  162.     while($row6=mysql_fetch_array($qrh6)) {
  163.         $theref=$row6["reftag"];
  164.         $thetit=$row6["title"];
  165.         echo "<li>";
  166.         if($theref==$page) echo "<b>";
  167.             else echo "<a href=$PHP_SELF?page=$theref>";
  168.         echo $thetit;
  169.         if($theref==$page) echo "</b>";
  170.             else echo "</a>";
  171.         echo "</li>\n";
  172.         if($theref==$page) {
  173.             // Next level down
  174.             $query2="SELECT * FROM `docpages` WHERE parent=$theid ORDER BY sequence,title";
  175.             $qrh2=mysql_query($query2);
  176.             $nor2=mysql_num_rows($qrh2);
  177.             if($nor2>0) {
  178.                 echo "<ul>\n";
  179.                 while($row2=mysql_fetch_array($qrh2)) {
  180.                     $thelit=$row2["title"];
  181.                     $thepage=$row2["reftag"];
  182.                     echo "<li><a href=$PHP_SELF?page=$thepage>$thelit</a></li>\n";
  183.                 }
  184.                 echo "</ul>\n";
  185.             }
  186.  
  187.         }
  188.  
  189.     }
  190.  
  191.     echo "</ul></font><hr>\n";
  192.  
  193.  
  194.     echo "<b>$thetitle</b> :: [ <a href=admin.php?action=edit&pageid=$theid>Edit Me</a> ]<p>\n";
  195.  
  196.     $thetext=grab("docpages",$page,"contents","reftag");
  197.     if($thetext=="-1") $thetext="Sorry, but page '$page' doesn't seem to exist.";
  198.  
  199.     $thetext=str_replace("[[","<a href=$PHP_SELF?page=",$thetext);
  200.     $thetext=str_replace("|",">",$thetext);
  201.     $thetext=str_replace("]]","</a>",$thetext);
  202.  
  203.     echo "$thetext<p>\n";
  204.  
  205.     echo "<center><a href=index.php>Back to TOC</a></center>\n";
  206. }
  207.  
  208. // Search
  209.  
  210. echo "<form action=$PHP_SELF method=post>\n";
  211. echo "<b>Search:</b><br>\n";
  212. echo "<input name=searchme type=text value=\"$searchme\"><input type=submit value=Search></form>\n";
  213.  
  214. if($searchme) {
  215.     echo "<hr>\n";
  216.     echo "<b>Search Results:</b><p>\n";
  217.  
  218.     $found=0;
  219.     echo "<ul>\n";
  220.     $query="SELECT * FROM `docpages` WHERE title LIKE '%$searchme%'";
  221.     $qrh=mysql_query($query);
  222.     while($row=mysql_fetch_array($qrh)) {
  223.         $found=1;
  224.         $rowref=$row["reftag"];
  225.         $rowname=$row["title"];
  226.         echo "<li><a href=$PHP_SELF?page=$rowref>$rowname</a></li>\n";
  227.     }
  228.     $query="SELECT * FROM `docpages` WHERE contents LIKE '%$searchme%'";
  229.     $qrh=mysql_query($query);
  230.     while($row=mysql_fetch_array($qrh)) {
  231.         $found=1;
  232.         $rowref=$row["reftag"];
  233.         $rowname=$row["title"];
  234.         echo "<li><a href=$PHP_SELF?page=$rowref&searchme=$searchme>$rowname</a></li>\n";
  235.     }
  236.     if(!$found) echo "<li>No results found.</li>\n";
  237.     echo "</ul><p>\n";
  238.  
  239. }
  240.  
  241. ?>
  242. </body>
  243. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top