/** * Calculate the differences between two strings. * $a: Initial string * $b: Changed string * $min: (optional) minum match length * return: array of changes */ function phorum_diff($a, $b, $min = 3, $i = 0) { $diff = array(); if ($a == "" && $b == "") { return $diff; } $a = str_replace(array("\r\n", "\r"), "\n", $a); $b = str_replace(array("\r\n", "\r"), "\n", $b); if ($a == "") { array_push($diff, "{$i}+" . $b); return $diff; } if ($b == "") { array_push($diff, "{$i}-" . $a); return $diff; } $match = phorum_diff_match($a, $b); if (strlen($match) < $min) { array_push($diff, "{$i}-" . $a); array_push($diff, "{$i}+" . $b); return $diff; } $ap = strpos($a, $match); $bp = strpos($b, $match); $diff = phorum_diff(substr($a, 0, $ap), substr($b, 0, $bp), $min, $i); return array_merge($diff, phorum_diff(substr($a, $ap + strlen($match)), substr($b, $bp + strlen($match)), $min, $i + $bp + strlen($match))); }
$sort = PHORUM_SORT_DEFAULT; break; } $dbmessage["sort"] = $sort; } } else { // set some key fields to the same values as the first message in the thread $dbmessage["forum_id"] = $top_parent["forum_id"]; $dbmessage["sort"] = $top_parent["sort"]; } // Update the editing info in the meta data. $dbmessage["meta"]["show_signature"] = $message["show_signature"]; // we are doing the diffs here to know about changes for edit-counts // $origmessage loaded in check_permissions $diff_body = phorum_diff($origmessage["body"], $message["body"]); $diff_subject = phorum_diff($origmessage["subject"], $message["subject"]); if (!empty($diff_body) || !empty($diff_subject)) { $name = phorum_api_user_get_display_name($PHORUM["user"]["user_id"], NULL, PHORUM_FLAG_PLAINTEXT); $dbmessage["meta"]["edit_count"] = isset($message["meta"]["edit_count"]) ? $message["meta"]["edit_count"] + 1 : 1; $dbmessage["meta"]["edit_date"] = time(); $dbmessage["meta"]["edit_username"] = $name; $dbmessage["meta"]["edit_user_id"] = $PHORUM["user"]["user_id"]; // perform diff if edit tracking is enabled if (!empty($PHORUM["track_edits"])) { $edit_data = array("diff_body" => $diff_body, "diff_subject" => $diff_subject, "time" => $dbmessage["meta"]["edit_date"], "user_id" => $PHORUM["user"]["user_id"], "message_id" => $dbmessage['message_id']); phorum_db_add_message_edit($edit_data); } } // Update attachments in the meta data, link active attachments // to the message and delete stale attachments. $dbmessage["meta"]["attachments"] = array();