<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Posthistory extends vB_Api { public function canViewPostHistory($nodeid) { $nodeid = intval($nodeid); $postedithistory = vB::getDatastore()->getOption('postedithistory'); $node = vB_Library::instance('node')->getNodeBare($nodeid); return (((bool)$postedithistory) AND vB_Library_Content::getContentLib($node['contenttypeid'])->getCanEdit($node)); } public function fetchHistory($nodeid, $id1 = 0, $id2 = 0) { $nodeid = intval($nodeid); $id1 = intval($id1); $id2 = intval($id2); if (!$this->canViewPostHistory($nodeid)) { throw new Exception('no_permission'); } if ($id1 AND $id2) { $conditions = array( 'nodeid' => $nodeid, 'postedithistoryid' => array($id1, $id2) ); } else { $conditions = array('nodeid' => $nodeid); } $_posthistory = vB::getDbAssertor()->assertQuery('vBForum:postedithistory', array( vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('postedithistoryid', 'reason', 'dateline', 'username', 'original'), vB_dB_Query::CONDITIONS_KEY => $conditions, ), array( 'field' => array('dateline'), 'direction' => array(vB_dB_Query::SORT_DESC) ) ); $posthistory = array(); foreach ($_posthistory AS $info) { $info['reason'] = $info['reason']; $posthistory[] = $info; } return $posthistory; } public function fetchHistoryComparison($nodeid, $oldpost, $newpost) { $nodeid = intval($nodeid); $oldpost = intval($oldpost); $newpost = intval($newpost); if (!$this->canViewPostHistory($nodeid)) { throw new vB_Exception_Api('no_permission'); } $_posthistory = vB::getDbAssertor()->getRows('vBForum:postedithistory', array( vB_dB_Query::CONDITIONS_KEY => array('nodeid' => $nodeid, 'postedithistoryid' => array($oldpost, $newpost)), vB_dB_Query::COLUMNS_KEY => array('postedithistoryid', 'reason', 'dateline', 'username', 'original', 'pagetext'), ), array('field' => 'postedithistoryid', 'direction' => vB_dB_Query::SORT_ASC) ); if (!$_posthistory) { return array(); } $posthistory = array(); $key = 1; foreach ($_posthistory AS $info) { $posthistory['post' . $key] = $info; $key++; } require_once(DIR . '/includes/class_diff.php'); if ($posthistory['post2']) { $textdiff_obj = new vB_Text_Diff($posthistory['post1']['pagetext'], $posthistory['post2']['pagetext']); } else { $textdiff_obj = new vB_Text_Diff($posthistory['post1']['pagetext'], $posthistory['post1']['pagetext']); } $results = array(); $diff = $textdiff_obj->fetch_diff(); foreach ($diff AS $diffrow) { $compare_show = array(); if ($diffrow->old_class == 'unchanged' AND $diffrow->new_class == 'unchanged') { $results[] = array( 'unchanged_olddata' => nl2br(vB_String::htmlSpecialCharsUni(implode("\n", $diffrow->fetch_data_old()))) ); } else { $results[] = array( 'changed_olddata' => nl2br(vB_String::htmlSpecialCharsUni(implode("\n", $diffrow->fetch_data_old()))), 'changed_newdata' => nl2br(vB_String::htmlSpecialCharsUni(implode("\n", $diffrow->fetch_data_new()))), ); } } return $results; } } 