diff --git a/app/admin/getUsers.php b/app/admin/getUsers.php index 35e4f40..5c08c45 100644 --- a/app/admin/getUsers.php +++ b/app/admin/getUsers.php @@ -1,5 +1,5 @@ ['prop1' => 'val', ..], ..] getLoggedMemberID() -- returns memberID of logged member. If no login, returns anonymous memberID getLoggedGroupID() -- returns groupID of logged member, or anonymous groupID @@ -76,6 +76,8 @@ guessMySQLDateTime($dt) -- if $dt is not already a mysql date/datetime, use mysql_datetime() to convert then return mysql date/datetime. Returns false if $dt invalid or couldn't be detected. pkGivenLookupText($val, $tn, $lookupField, $falseIfNotFound) -- returns corresponding PK value for given $val which is the textual lookup value for given $lookupField in given $tn table. If $val has no corresponding PK value, $val is returned as-is, unless $falseIfNotFound is set to true, in which case false is returned. userCanImport() -- returns true if user (or his group) can import CSV files (through the permission set in the group page in the admin area). + bgStyleToClass($html) -- replaces bg color 'style' attr with a class to prevent style loss on xss cleanup. + assocArrFilter($arr, $func) -- filters provided array using provided callback function. The callback receives 2 params ($key, $value) and should return a boolean. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ ######################################################################## @@ -1633,14 +1635,50 @@ public static function show($options = []) { } } ######################################################### + function addMailRecipients(&$pm, $recipients, $type = 'to') { + if(empty($recipients)) return; + + switch(strtolower($type)) { + case 'cc': + $func = [$pm, 'addCC']; + break; + case 'bcc': + $func = [$pm, 'addBCC']; + break; + case 'to': + $func = [$pm, 'addAddress']; + break; + } + + // if recipients is a str, arrayify it! + if(is_string($recipients)) $recipients = [[$recipients]]; + if(!is_array($recipients)) return; + + // if recipients is an array, loop thru and add emails/names + foreach ($recipients as $rcpt) { + // if rcpt is string, add as email + if(is_string($rcpt) && isEmail($rcpt)) + call_user_func_array($func, [$rcpt]); + + // else if rcpt is array [email, name], or just [email] + elseif(is_array($rcpt) && isEmail($rcpt[0])) + call_user_func_array($func, [$rcpt[0], empty($rcpt[1]) ? '' : $rcpt[1]]); + } + } + ######################################################### function sendmail($mail) { - if(!isset($mail['to'])) return 'No recipient defined'; - if(!isEmail($mail['to'])) return 'Invalid recipient email'; + if(empty($mail['to'])) return 'No recipient defined'; + + // convert legacy 'to' and 'name' to new format [[to, name]] + if(is_string($mail['to'])) + $mail['to'] = [ + [ + $mail['to'], + empty($mail['name']) ? '' : $mail['name'] + ] + ]; - $mail['subject'] = isset($mail['subject']) ? $mail['subject'] : ''; - $mail['message'] = isset($mail['message']) ? $mail['message'] : ''; - $mail['name'] = isset($mail['name']) ? $mail['name'] : ''; - $mail['debug'] = isset($mail['debug']) ? min(4, max(0, intval($mail['debug']))) : 0; + if(!isEmail($mail['to'][0][0])) return 'Invalid recipient email'; $cfg = config('adminConfig'); $smtp = ($cfg['mail_function'] == 'smtp'); @@ -1656,7 +1694,7 @@ function sendmail($mail) { if($smtp) { $pm->isSMTP(); - $pm->SMTPDebug = $mail['debug']; + $pm->SMTPDebug = isset($mail['debug']) ? min(4, max(0, intval($mail['debug']))) : 0; $pm->Debugoutput = 'html'; $pm->Host = $cfg['smtp_server']; $pm->Port = $cfg['smtp_port']; @@ -1667,15 +1705,26 @@ function sendmail($mail) { } $pm->setFrom($cfg['senderEmail'], $cfg['senderName']); - $pm->addAddress($mail['to'], $mail['name']); - $pm->Subject = $mail['subject']; + $pm->Subject = isset($mail['subject']) ? $mail['subject'] : ''; + + // handle recipients + addMailRecipients($pm, $mail['to']); + if(!empty($mail['cc'])) addMailRecipients($pm, $mail['cc'], 'cc'); + if(!empty($mail['bcc'])) addMailRecipients($pm, $mail['bcc'], 'bcc'); /* if message already contains html tags, don't apply nl2br */ + $mail['message'] = isset($mail['message']) ? $mail['message'] : ''; if($mail['message'] == strip_tags($mail['message'])) $mail['message'] = nl2br($mail['message']); $pm->msgHTML($mail['message'], realpath("{$curr_dir}/..")); + /* + * pass 'tag' as-is if provided in $mail .. + * this is useful for passing any desired values to sendmail_handler + */ + if(!empty($mail['tag'])) $pm->tag = $mail['tag']; + /* if sendmail_handler(&$pm) is defined (in hooks/__global.php) */ if(function_exists('sendmail_handler')) sendmail_handler($pm); @@ -1684,13 +1733,12 @@ function sendmail($mail) { return true; } ######################################################### - function safe_html($str) { + function safe_html($str, $noBr = false) { /* if $str has no HTML tags, apply nl2br */ - if($str == strip_tags($str)) return nl2br($str); + if($str == strip_tags($str)) return $noBr ? $str : nl2br($str); $hc = new CI_Input(datalist_db_encoding); - - return $hc->xss_clean($str); + return $hc->xss_clean(bgStyleToClass($str)); } ######################################################### function getLoggedGroupID() { @@ -2436,3 +2484,23 @@ function getUploadDir($dir) { return rtrim($dir, '\\/') . '/'; } + ######################################################### + function bgStyleToClass($html) { + return preg_replace( + '/ style="background-color: rgb\((\d+), (\d+), (\d+)\);"/', + ' class="nicedit-bg" data-nicedit_r="$1" data-nicedit_g="$2" data-nicedit_b="$3"', + $html + ); + } + ######################################################### + function assocArrFilter($arr, $func) { + if(!is_array($arr) || !count($arr)) return $arr; + if(!is_callable($func)) return false; + + $filtered = []; + foreach ($arr as $key => $value) + if(call_user_func_array($func, [$key, $value]) === true) + $filtered[$key] = $value; + + return $filtered; + } diff --git a/app/admin/pageRebuildFields.php b/app/admin/pageRebuildFields.php index c72a70b..92bffa9 100644 --- a/app/admin/pageRebuildFields.php +++ b/app/admin/pageRebuildFields.php @@ -28,6 +28,9 @@ function prepare_def($def) { /* make sure there is always a space before mysql words */ $def = preg_replace('/(\S)(unsigned|not null|binary|zerofill|auto_increment|default)/i', '$1 $2', $def); + /* ignore 'not null' for auto_increment fields */ + $def = preg_replace('/\s+not\s+null\s+(.*?)\s+auto_increment/i', ' $1 auto_increment', $def); + /* treat 0.000.. same as 0 */ $def = preg_replace('/([0-9])*\.0+/', '$1', $def); @@ -179,7 +182,7 @@ function fix_field($fix_table, $fix_field, $schema, &$qry) { $fields) { ?> -

" , $tn , $Translation['table name title']) ; ?>">

+

" , $tn , $Translation['table name title']) ; ?>">

$fd) { ?> @@ -190,9 +193,9 @@ function fix_field($fix_table, $fix_field, $schema, &$qry) { {$fd['db']}", $Translation['does not exist']); ?> - + - + @@ -204,7 +207,7 @@ function fix_field($fix_table, $fix_field, $schema, &$qry) {