Guest User

filter_php_script

a guest
Feb 18th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php
  2. // change your db connection information below
  3. $db_connection = mysql_pconnect('host', 'user', 'pass') or die ("nope");
  4. mysql_select_db('database') or die("Unable to select database");
  5.  
  6. function words_match ($haystack, $needle_string, $all) {
  7. // $all means whether to find all needles or just one
  8.  
  9.     $needles = explode(" ", $needle_string);
  10.     $total_needles = count ($needles);
  11.     $matches = 0;
  12.     foreach ($needles as $needle) {
  13.         $pos=stripos($haystack, $needle);
  14.         if ($pos!==false) {
  15.             $matches = $matches+1;
  16.         }
  17.     }
  18.     if ($matches == $total_needles &&  $all == true ) {
  19.     // if all words have to be found and they have been found -> return true
  20.         return true;
  21.     }
  22.     elseif ($matches > 0 && $all == false) {
  23.     // if some words have to be found and some have -> return true
  24.         return true;
  25.     }
  26.     else return false;
  27. }
  28.  
  29.  
  30. if ($_POST) {
  31.     // get all filters
  32.     $query = "SELECT * from filter";
  33.     $result = mysql_query($query);
  34.  
  35.     // get relevant POST vars
  36.     $from = $_POST['from'];
  37.     $plain_text = $_POST['plain_text'];
  38.     $subject = $_POST['subject'];
  39.    
  40.     while ($row = mysql_fetch_array($result)) {
  41.     // determine wether a rule applies
  42.         $a='';
  43.         $b='';
  44.         $c='';
  45.         $d='';
  46.         if ($row['in_from']!='') {
  47.             if ($row['in_from'] == $from) {
  48.                 $a='x';
  49.             } else { $a='-'; }
  50.         }          
  51.         if ($row['in_subject']!='') {
  52.             if (words_match($subject, $row['in_subject'], true)) {
  53.                 $b='x';
  54.             } else { $b='-'; }
  55.         }
  56.         if ($row['in_haswords']!='') {
  57.             if (words_match($plain_text, $row['in_haswords'], true)) {
  58.                 $c='x';
  59.             } else { $c='-'; }
  60.         }
  61.         if ($row['in_doesnt_have']!='') {
  62.             if (words_match($plain_text, $row['in_doesnt_have'], false)) {
  63.                 $d='x';
  64.             } else { $d='-'; }
  65.         }
  66.         if ($a!='-' && $b!='-' && $c!='-' && $d!='x') {
  67.         // success: a valid rule has been found, now do something with it
  68.             $out_subject = $subject;
  69.             if ($row['out_desc']!='') {
  70.                 $out_subject = $row['out_desc'];
  71.             }
  72.             if ($row['out_due_date']!='') {
  73.                 $out_subject .= ' ^'.$row['out_due_date'];
  74.             }
  75.             if ($row['out_prio']!='') {
  76.                 $out_subject .= ' !'.$row['out_prio'];
  77.             }
  78.             if ($row['out_list_tags']!='') {
  79.                 $tags = explode(" ",$row['out_list_tags']);
  80.                 foreach ($tags as $tag) {
  81.                     $out_subject .= ' #'.$tag;
  82.                 }
  83.             }
  84.             if ($row['out_estimate']!='') {
  85.                 $out_subject .= ' ='.$row['out_estimate'];
  86.             }
  87.             if ($row['out_location']!='') {
  88.                 $out_subject .= ' @'.$row['out_location'];
  89.             }
  90.             // forward email to RMilk with enriched subject
  91.             echo $out_subject;
  92. //change your email below
  93.             mail('[email protected]', $out_subject, $plain_text, $headers);
  94.         }
  95.        
  96.     }
  97. }
  98. // the form below allows you to manually experiment with the script
  99. echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>\n";
  100. echo "from:<input type='text' name='from' value=". $_POST['from'] ." size='25' align='left'><br>\n";
  101. echo "to:<input type='text' name='to' value=". $_POST['to'] ." size='25' align='left'><br>\n";
  102. echo "subject:<input type='text' name='subject' value=". $_POST['subject'] ." size='25' align='left'><br>\n";
  103. echo "plain_text:<input type='text' name='plain_text' value=". $_POST['plain_text'] ." size='25' align='left'><br>\n";
  104. echo "<input type='submit' name='submitted' value='submit'>\n";
  105. echo "</form>\n";
  106.  
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment