Advertisement
Guest User

Untitled

a guest
Jun 18th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.00 KB | None | 0 0
  1. <?php
  2.  
  3. function strip_javascript($filter){
  4.    
  5.     // realign javascript href to onclick
  6.     $filter = preg_replace("/href=(['\"]).*?javascript:(.*)? \\1/i", "onclick=' $2 '", $filter);
  7.  
  8.     //remove javascript from tags
  9.     while( preg_match("/<(.*)?javascript.*?\(.*?((?>[^()]+) |(?R)).*?\)?\)(.*)?>/i", $filter))
  10.         $filter = preg_replace("/<(.*)?javascript.*?\(.*?((?> [^()]+)|(?R)).*?\)?\)(.*)?>/i", "<$1$3$4$5>", $filter);
  11.              
  12.     // dump expressions from contibuted content
  13.     if(0) $filter = preg_replace("/:expression\(.*?((?>[^(.*?)]+)|(?R)).*?\)\)/i", "", $filter);
  14.  
  15.     while( preg_match("/<(.*)?:expr.*?\(.*?((?>[^()]+)|(?R)).*?\)?\)(.*)?>/i", $filter))
  16.         $filter = preg_replace("/<(.*)?:expr.*?\(.*?((?>[^()]+)|(?R)).*?\)?\)(.*)?>/i", "<$1$3$4$5>", $filter);
  17.        
  18.     // remove all on* events    
  19.     while( preg_match("/<(.*)?\s?on.+?=?\s?.+?(['\"]).*?\\2\s?(.*)?>/i", $filter) )
  20.        $filter = preg_replace("/<(.*)?\s?on.+?=?\s?.+?(['\"]).*?\\2\s?(.*)?>/i", "<$1$3>", $filter);
  21.  
  22.     return $filter;
  23. }
  24.  
  25. $errors = array();
  26. if (isset($_POST['new_message'])) {
  27.  
  28.     $date = date("dhis");
  29.     $postdate = date('m-d-Y');
  30.  
  31.     $topic = $_POST['topic'];
  32.     $topic = strip_tags($topic);
  33.     $topic = trim($topic);
  34.     $topic = str_replace('&nbsp;',"",$topic);
  35.  
  36.     $message = $_POST['message'];
  37.     $message = strip_tags($message,"<pre>");
  38.     $message = nl2br($message);
  39.     $message = trim($message);
  40.     $message = strip_javascript($message);
  41.  
  42.     if($topic == ''){
  43.     $errors[] = '<b><font color=darkred>- Topic is blank.</font></b>';
  44.     }
  45.     if($message == ''){
  46.     $errors[] = '<b><font color=darkred>- Message is blank.</font></b>';
  47.     }
  48.    
  49.     if(count($errors) == 0){
  50.  
  51. $new_file = <<< EOF
  52. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  53. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
  54. <head>
  55. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  56. <title>$topic</title>
  57. <meta name="robots" content="index, follow" />
  58. <link rel="stylesheet" type="text/css"  href="main.css" />
  59. </head>
  60. <body>
  61.  
  62. <div id="mainbox">
  63.  
  64.     <div id="forum">
  65.    
  66.         <div class="bigtext-forum">&rsaquo; community pages</div>
  67.        
  68.         <p class="topic"><font color=darkred>TOPIC:</font> "$topic"</strong></p>
  69.         <div id="forum-message">$message</div>
  70.        
  71.         <div id="note">NOTE: Topic creators are anonymous. Only replies below require identification.</div>
  72.            
  73.         <!-- POST YOUR DISQUS CODE HERE -->
  74.            
  75.     </div>
  76. </div>
  77. </body>
  78. </html>
  79. EOF;
  80.  
  81.         // Create New Topic Page
  82.         $filename = "$date.php";
  83.         $fh = fopen($filename, 'w') or die("can't open file");
  84.         fwrite($fh, $new_file);
  85.         fclose($fh);
  86.        
  87.         // Add new page entry to topics.txt
  88.         $stringData = "<tr><td width='80px'><small><em>$postdate</em></small></td><td><a href='$date.php'><b>$topic</b></a></td></tr>\n\n";
  89.         $file = 'topics.txt';
  90.         $oldContents = file_get_contents($file);
  91.         $fr = fopen($file, 'w') or die("can't open file");
  92.         fwrite($fr, $stringData);
  93.         fwrite($fr, $oldContents);
  94.         fclose($fr);
  95.        
  96.         // Forward user to new topic page
  97.         header('Location: '.$filename);
  98.         die;
  99.    
  100.     }
  101.    
  102. }
  103. ?>
  104. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  105. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
  106. <head>
  107. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  108. <title>ZenForum</title>
  109. <meta name="robots" content="index, follow" />
  110. <link rel="stylesheet" type="text/css"  href="main.css" />
  111. </head>
  112. <body>
  113.  
  114. <div id="mainbox">
  115.  
  116.     <div id="forum">
  117.    
  118.         <div class="bigtext-forum">&rsaquo; community pages</div>  
  119.        
  120.         <p class="small"><b>Use this page to post a new community topic.</b></p>
  121.         <p class="small">&rsaquo; With the exception of "pre" code tags, HTML is not allowed in the topic or subject.</p>
  122.         <p class="small">&rsaquo; Any malicious activity will result in a permanent ban of your IP and account.</p><br />
  123.  
  124.         <div class="check_main">   
  125.         <?php
  126.         if(count(@$errors) > 0){
  127.             foreach($errors as $e){
  128.                 echo $e."<br /><br />";
  129.             }
  130.         }
  131.         ?>
  132.         </div>
  133.        
  134.         <form action="" method="post">
  135.         <fieldset>
  136.         <table><tbody>
  137.         <tr>
  138.             <td style="border-bottom: 0px;">
  139.                 <label for="topic"><b>Topic:</b> </label>
  140.             </td>
  141.             <td style="border-bottom: 0px;">
  142.                 <input type="text" size="65" name="topic" maxlength="64" value="<?php if(@$topic){echo $topic;} ?>">
  143.             </td>
  144.         </tr>
  145.         <tr>
  146.             <td style="border-bottom: 0px;">
  147.                 <label for="message"><b>Message:</b> </label>
  148.             </td>
  149.             <td style="border-bottom: 0px;">
  150.                 <textarea name="message" rows="9" cols="50" maxlength="5000"><?php if(@$message){echo $message;} ?></textarea>
  151.             </td>
  152.         </tr>          
  153.         <tr>
  154.             <td style="border-bottom: 0px;">
  155.             </td>
  156.             <td style="border-bottom: 0px; text-align: left">
  157.                 <input type="submit" name="new_message" value="Post New Topic &raquo; ">
  158.             </td>
  159.         </tr>      
  160.         </tbody></table>
  161.         </fieldset>    
  162.         </form>
  163.        
  164.     </div>
  165. </div>
  166. </body>
  167. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement