topic_id); $edit_history=$bbdb->get_results("SELECT * FROM bb_edit_history WHERE post_id = $post_id ORDER BY time DESC LIMIT 999"); bb_send_headers(); bb_get_header(); ?>

» topic_id ); ?> » post_position; ?> »

  1. > "; if (is_array($edit_history)) { foreach ($edit_history as $edit) { $diff=unserialize(stripslashes($edit->diff)); $newer=$bb_post->post_text; $bb_post->post_text=edit_history_undo($bb_post->post_text,$diff); ?>
  2. >

    user_id); // user_profile_link($id) ?>
     time), $link); ?> 
    post_text, $newer), $bb_post->post_id)); ?>
    time), $link); ?>
  3. "; } bb_get_footer(); exit(); } } } function edit_history_link($link) { global $edit_history; if ( bb_current_user_can($edit_history['view_level']) ) { echo " " . __('History') ." "; } return $link; } function edit_history_update_post($post_id) { global $bbdb, $bb_post; if ($post_id) {$new = $bbdb->get_var("SELECT post_text FROM $bbdb->posts WHERE post_id = $post_id LIMIT 1");} $old=$bb_post->post_text; if ($post_id && $post_id==$bb_post->post_id && $new && $old != $new) { $old=edit_history_split($old); $new=edit_history_split($new); $time=time(); $user_ip=$_SERVER["REMOTE_ADDR"]; $user_id=bb_get_current_user_info( 'id' ); $diff=addslashes(serialize(edit_history_trim_diff(edit_history_diff($old,$new)))); // looks so simple eh? not! @$bbdb->query("INSERT INTO bb_edit_history ( `time` , `post_id` , `user_id`, `user_ip`, `diff` ) VALUES ('$time', '$post_id' , '$user_id' , inet_aton('$user_ip') , '$diff')"); } } function edit_history_split($words) {return preg_split ("/(?!<<[^>]+)\s+(?![^<]+>)/", $words);} function edit_history_undo($new,$diff) { $old=edit_history_split($new); $offset=-1; foreach ($diff as $key=>$value) { $d=edit_history_split($diff[$key]); $icount=$d[0]; unset($d[0]); array_splice ( $old , $key+$offset , $icount , $d ); $offset+=count($d) -1; } return implode(" ",$old); } function edit_history_trim_diff($diff) { foreach ($diff as $key=>$value) { if (!is_array($value)) {unset($diff[$key]);} else { if ($diff[$key]['d']==$diff[$key]['i']) {unset($diff[$key]);} else {$diff[$key]=trim(count($diff[$key]['i'])." ".implode(' ',$diff[$key]['d']));} } } return $diff; } function edit_history_diff($old, $new) { foreach($old as $oindex => $ovalue){ $nkeys = array_keys($new, $ovalue); foreach($nkeys as $nindex){ $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1; if($matrix[$oindex][$nindex] > $maxlen){ $maxlen = $matrix[$oindex][$nindex]; $omax = $oindex + 1 - $maxlen; $nmax = $nindex + 1 - $maxlen; } } } if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new)); return array_merge( edit_history_diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), edit_history_diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); } function edit_history_visual($old, $new) { $diff = edit_history_diff(edit_history_split($old),edit_history_split($new)); // if (bb_current_user_can('administrate')) {echo ""; print_r($diff); echo "";} foreach($diff as $k){ if (is_array($k)) { $d=(!empty($k['d'])?implode(' ',$k['d']):''); $i=(!empty($k['i'])?implode(' ',$k['i']):''); if ($d && $i && str_replace("

    ","",$d)==str_replace("

    ","",$k['i'][0])) {$ret.=$k['i'][0]; unset($d); unset($k['i'][0]); $i=implode(' ',$k['i']);} if ($d && $i && substr($d,-6)=="
    " && substr($i,-6)=="
    ") {$d=substr($d,0,-6);} // to do: strip end tags in $d that have no start tags as they will be in $i - also for ending bbcode tags // if ($d && $i) {$d=force_balance_tags(post_text($d));} $ret .= (!empty($d)?"".str_replace("

    ","

    ",$d)." ":''). (!empty($i)?"".str_replace("

    ","

    ",$i)." ":''); } else { $ret .= $k . ' ';} } return $ret; } function edit_history_create_table() { global $bbdb; $bbdb->query("CREATE TABLE IF NOT EXISTS `bb_edit_history` ( `time` int(10) UNSIGNED NOT NULL default '0', `post_id` int(10) UNSIGNED NOT NULL default '0', `user_id` int(10) UNSIGNED NOT NULL default '0', `user_ip` int(10) UNSIGNED NOT NULL default '0', `diff` text NOT NULL default '', INDEX (`post_id`) )"); } ?>