コード例 #1
0
ファイル: action_edit.php プロジェクト: samuell/Core
    // has the sorting order been changed?
    if ($dbmessage['sort'] !== $origmessage['sort']) {
        // too much to calculate here to avoid the full refresh
        $PHORUM['DB']->update_forum_stats(true);
    }
} 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_api_diff($origmessage["body"], $message["body"]);
$diff_subject = phorum_api_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();
コード例 #2
0
ファイル: diff.php プロジェクト: netovs/Core
/**
 * Calculate the differences between two strings.
 *
 * This will return an array of strings containing differences
 * between the initial_string and the changed_string. Each element
 * of the diff array begins with an index and a - or +, meaning:
 *
 *   - This section has been removed.
 *   + This section has been added.
 *
 * The optional minimum_match parameter will keep diff from matching
 * up short sequences of letters.  Examples of minimum_match:
 *
 *   diff("Sam", "Bart", 1) = ("0-S", "0+B","2-m", "2+rt")
 *   diff("Sam", "Bart", 2) = ("0-Sam", "0+Bart")
 *
 * @param string $a
 *     The initial string.
 *
 * @param string $b
 *     The changed strings.
 *
 * @param integer $min
 *     Optional: the minimum match length. When omitted, the default
 *     minimum match length will be 3.
 * 
 * @return array
 *     An array, describing the differences between the initial
 *     and the changed string.
 */
function phorum_api_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_api_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_api_diff(substr($a, 0, $ap), substr($b, 0, $bp), $min, $i);
    return array_merge($diff, phorum_api_diff(substr($a, $ap + strlen($match)), substr($b, $bp + strlen($match)), $min, $i + $bp + strlen($match)));
}