[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: functions_massmail.php 5828 2012-05-08 16:06:16Z Tomm $ 10 */ 11 12 /** 13 * Build the mass email SQL query for the specified conditions. 14 * 15 * @param array Array of conditions to match users against. 16 * @return string The generated search SQL 17 */ 18 function build_mass_mail_query($conditions) 19 { 20 global $db; 21 22 if(!is_array($conditions)) 23 { 24 return ''; 25 } 26 27 $search_sql = 'u.allownotices=1'; 28 29 // List of valid LIKE search fields 30 $user_like_fields = array("username", "email"); 31 foreach($user_like_fields as $search_field) 32 { 33 if($conditions[$search_field]) 34 { 35 $search_sql .= " AND u.{$search_field} LIKE '%".$db->escape_string_like($conditions[$search_field])."%'"; 36 } 37 } 38 39 // LESS THAN or GREATER THAN 40 $direction_fields = array("postnum"); 41 foreach($direction_fields as $search_field) 42 { 43 $direction_field = $search_field."_dir"; 44 if($conditions[$search_field] && $conditions[$direction_field]) 45 { 46 switch($conditions[$direction_field]) 47 { 48 case "greater_than": 49 $direction = ">"; 50 break; 51 case "less_than": 52 $direction = "<"; 53 break; 54 default: 55 $direction = "="; 56 } 57 $search_sql .= " AND u.{$search_field}{$direction}'".intval($conditions[$search_field])."'"; 58 } 59 } 60 61 // Usergroup based searching 62 if($conditions['usergroup']) 63 { 64 if(!is_array($conditions['usergroup'])) 65 { 66 $conditions['usergroup'] = array($conditions['usergroup']); 67 } 68 69 $conditions['usergroup'] = array_map('intval', $conditions['usergroup']); 70 71 foreach($conditions['usergroup'] as $usergroup) 72 { 73 switch($db->type) 74 { 75 case "pgsql": 76 case "sqlite": 77 $additional_sql .= " OR ','||additionalgroups||',' LIKE '%,{$usergroup},%'"; 78 break; 79 default: 80 $additional_sql .= " OR CONCAT(',',additionalgroups,',') LIKE '%,{$usergroup},%'"; 81 } 82 } 83 $search_sql .= " AND (u.usergroup IN (".implode(",", $conditions['usergroup']).") {$additional_sql})"; 84 } 85 86 return $search_sql; 87 } 88 89 /** 90 * Create a text based version of a HTML mass email. 91 * 92 * @param string The HTML version. 93 * @return string The generated text based version. 94 */ 95 function create_text_message($message) 96 { 97 // Cut out all current line breaks 98 // Makes links CONTENT (link) 99 $message = make_pretty_links($message); 100 $message = str_replace(array("\r\n", "\n"), "\n", $message); 101 $message = preg_replace("#</p>#i", "\n\n", $message); 102 $message = preg_replace("#<br( \/?)>#i", "\n", $message); 103 $message = preg_replace("#<p[^>]*?>#i", "", $message); 104 $message = preg_replace("#<hr[^>]*?>\s*#i", "-----------\n", $message); 105 $message = html_entity_decode($message); 106 $message = str_replace("\t", "", $message); 107 do 108 { 109 $message = str_replace(" ", " ", $message); 110 } 111 while(strpos($message, " ") !== false); 112 113 $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript 114 '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly 115 '@<title[^>]*?>.*?</title>@siU', // Strip title tags 116 '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags 117 '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA 118 ); 119 $message = preg_replace($search, '', $message); 120 $message = preg_replace("#\n\n+#", "\n\n", $message); 121 $message = preg_replace("#^\s+#is", "", $message); 122 return $message; 123 } 124 125 /** 126 * Generates friendly links for a text based version of a mass email from the HTML version. 127 * 128 * @param string The HTML version. 129 * @return string The version with the friendly links and all <a> tags stripped. 130 */ 131 function make_pretty_links($message_html) 132 { 133 do 134 { 135 $start = stripos($message_html, "<a", $offset); 136 if($start === false) 137 { 138 break; 139 } 140 $end = stripos($message_html, "</a>", $start); 141 if($end === false) 142 { 143 break; 144 } 145 146 $a_href = substr($message_html, $start, ($end-$start)); 147 148 preg_match("#href=\"?([^\"> ]+)\"?#i", $a_href, $href_matches); 149 if(!$href_matches[1]) 150 { 151 continue; 152 } 153 $link = $href_matches[1]; 154 155 $contents = strip_tags($a_href); 156 if(!$contents) 157 { 158 preg_match("#alt=\"?([^\">]+)\"?#i", $a_href, $matches2); 159 if($matches2[1]) 160 { 161 $contents = $matches2[1]; 162 } 163 if(!$contents) 164 { 165 preg_match("#title=\"?([^\">]+)\"?#i", $a_href, $matches2); 166 if($matches2[1]) 167 { 168 $contents = $matches2[1]; 169 } 170 } 171 } 172 173 $replaced_link = $contents." ({$link}) "; 174 175 $message_html = substr_replace($message_html, $replaced_link, $start, ($end-$start)); 176 } while(true); 177 return $message_html; 178 } 179 180 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |