last update: Sat, 14 Jan 2012 11:26:07 +0000
  1. <?
  2. require_once('common.php');
  3. require_once('compare2.php');
  4. require_once('codehighlighter.php');
  5. require_once('code_css.php');
  6. //main template
  7. $smarty->assign('main_template', 'comparer.tpl');
  8. //title
  9. $pageTitle = 'Compare Code: Online Diff Tool';
  10. $additional_headers = array();
  11. $additional_headers[] = '<script>
  12. function update_a()
  13. {
  14. var a = document.getElementById("a");
  15. var b = document.getElementById("b");
  16. b.scrollTop = a.scrollTop;
  17. b.scrollLeft = a.scrollLeft;
  18. }
  19. function update_b()
  20. {
  21. var a = document.getElementById("a");
  22. var b = document.getElementById("b");
  23. a.scrollTop = b.scrollTop;
  24. a.scrollLeft = b.scrollLeft;
  25. }
  26. </script>';
  27. function strip_markup($s)
  28. {
  29. return str_replace('##', '', str_replace('', '', $s));
  30. }
  31. $s1 = null;
  32. $s2 = null;
  33. $default_lang1 = null;
  34. $default_lang2 = null;
  35. if ((isset($_GET['id1'])) && (isset($_GET['id2'])))
  36. {
  37. //echo code_css();
  38. $id1 = intval($_GET['id1']);
  39. $id2 = intval($_GET['id2']);
  40. $orderby = ($id1 > $id2) ? 'ORDER BY `id` DESC' : 'ORDER BY `id` ASC';
  41. $query = 'SELECT *
  42. FROM `mapping_nopaste_jass`
  43. WHERE `key` LIKE ""
  44. AND (`id` = "'.$id1.'" OR `id` = "'.$id2.'")
  45. '.$orderby.';';
  46. $data = mysql_query($query, $mysqlconnection);
  47. echo mysql_error();
  48. $row = mysql_fetch_array($data);
  49. $s1 = strip_markup($row['jass_code']);
  50. $default_lang1 = $row['codetype'];
  51. $row = mysql_fetch_array($data);
  52. $s2 = strip_markup($row['jass_code']);
  53. $default_lang2 = $row['codetype'];
  54. }
  55. else if ((isset($_POST['code1'])) && (isset($_POST['code2'])))
  56. {
  57. $s1 = $_POST['code1'];
  58. $s2 = $_POST['code2'];
  59. $default_lang1 = $default_lang2 = $_POST['lang'];
  60. if ($_POST['save'])
  61. {
  62. $query = 'SELECT `id` as x FROM `mapping_nopaste_jass` ORDER BY `id` DESC;';
  63. $count = mysql_fetch_array(mysql_query($query, $mysqlconnection));
  64. $id = $count['x'] + 1;
  65. $code_type = mysql_real_escape_string($_POST['lang']);
  66. //remember to check this value later
  67. //check value
  68. $query = 'SELECT name FROM languages WHERE `name` = "'.$code_type.'";';
  69. $row = mysql_fetch_array(mysql_query($query));
  70. if (isset($row['name']) && ($row['name'] != $code_type))
  71. {
  72. die('unbekannte Sprache.');
  73. }
  74. $code = unescape_string($s1);
  75. $code = str_replace("<", "<", $code);
  76. $code = str_replace(">", ">", $code);
  77. $query = 'INSERT INTO
  78. `mapping_nopaste_jass` (`id`, `jass_code`, `datum`, `userid`, `codetype` )
  79. VALUES ("'.$id.'", "'.escape_string($code).'", NOW(), "'.session_get_userid_secure().'", "'.$code_type.'")
  80. ';
  81. $temp = mysql_query($query, $mysqlconnection);
  82. echo mysql_error();
  83. $id++;
  84. $code = unescape_string($s2);
  85. $code = str_replace("<", "<", $code);
  86. $code = str_replace(">", ">", $code);
  87. $query = 'INSERT INTO
  88. `mapping_nopaste_jass` (`id`, `jass_code`, `datum`, `userid`, `codetype` )
  89. VALUES ("'.$id.'", "'.escape_string($code).'", NOW(), "'.session_get_userid_secure().'", "'.$code_type.'")
  90. ';
  91. $temp = mysql_query($query, $mysqlconnection);
  92. echo mysql_error();
  93. $additional_headers[] ='<script>document.location="comparer.php?id1='.($id-1).'&id2='.$id.'";</script>';
  94. $s1 = $s2 = null;
  95. $smarty->assign('id1', $id -1);
  96. $smarty->assign('id2', $id);
  97. }
  98. }
  99. else
  100. {
  101. $query = 'SELECT name FROM languages;';
  102. $data = mysql_query($query);
  103. $languages = array();
  104. while ($row = mysql_fetch_array($data))
  105. {
  106. $languages[] = $row['name'];
  107. }
  108. $smarty->assign('languages', $languages);
  109. }
  110. if (($s1) && ($s2))
  111. {
  112. $lines1 = fill_line_array($s1);
  113. $lines2 = fill_line_array($s2);
  114. $linearray_comparer = new linearraycomparer($lines1, $lines2);
  115. $Alines1 = $linearray_comparer->make_same_lines_same_height(0);
  116. $Alines2 = $linearray_comparer->make_same_lines_same_height(1);
  117. $Blines1 = array();
  118. $Blines1_pos = 0;
  119. $Blines2 = array();
  120. $Blines2_pos = 0;
  121. $lineComparerInvocations = 0;
  122. for ($i = 0; $i < max(sizeof($Alines1),sizeof($Alines2)); ++$i)
  123. {
  124. if (!isset($Alines1[$i])) $Alines1[$i] = "";
  125. if (!isset($Alines2[$i])) $Alines2[$i] = "";
  126. $line1 = unescape_string(($Alines1[$i]));
  127. $line2 = unescape_string(($Alines2[$i]));
  128. //$bg1 = ' bgcolor="#90ff60"';
  129. //$bg2 = ' bgcolor="#90ff60"';
  130. ++$Blines1_pos;
  131. ++$Blines2_pos;
  132. if ($line1 != $line2)
  133. {
  134. if ($line1 == "////////////////")
  135. {
  136. //$bg1 = ' bgcolor="#CCccCC"';
  137. --$Blines1_pos;
  138. if (!(isset($Blines1[$Blines1_pos]))) {
  139. if ($Blines1_pos > 0) {
  140. $Blines1[$Blines1_pos] = '';
  141. } else {
  142. // dirty hack, i hat me for doing it^^
  143. $Blines1[$Blines1_pos] = '!!!FIRSTLINE-SKIPTHIS!!!';
  144. }
  145. }
  146. $line1 = $Blines1[$Blines1_pos]."\n";
  147. $line2 = "##".$line2; // mark added line yellow
  148. //$Blines1[$Blines1_pos].="\n";
  149. }
  150. elseif ($line2 == "////////////////")
  151. {
  152. //$bg2 = ' bgcolor="#CCccCC"';
  153. --$Blines2_pos;
  154. if (!(isset($Blines2[$Blines2_pos]))) {
  155. if ($Blines2_pos > 0) {
  156. $Blines2[$Blines2_pos] = '';
  157. } else {
  158. // dirty hack, i hat me for doing it^^
  159. $Blines2[$Blines2_pos] = '!!!FIRSTLINE-SKIPTHIS!!!';
  160. }
  161. }
  162. $line2 = $Blines2[$Blines2_pos]."\n";
  163. $line1 = "##".$line1; // mark added line yellow
  164. //$Blines2[$Blines2_pos].="\n";
  165. }
  166. else
  167. {
  168. //$bg1 = ' bgcolor="#ffff66"';
  169. //$bg2 = ' bgcolor="#ffff66"';
  170. if ($lineComparerInvocations < 100) {
  171. $line_comparer = new linecomparer($line1, $line2);
  172. $line1 = "##".$line_comparer->markup_string_difference(0, "", "");
  173. $line2 = "##".$line_comparer->markup_string_difference(1, "", "");
  174. $lineComparerInvocations ++;
  175. } else {
  176. // TOO many differences, just highlight the lines
  177. $line1 = "##".$line1;
  178. $line2 = "##".$line2;
  179. }
  180. }
  181. }
  182. //if (!(($line1 == $line2) && ($line1 == "////////////////")))
  183. if (($line1 != $line2) || ($line1 != "////////////////"))
  184. {
  185. $Blines1[$Blines1_pos] = $line1;
  186. $Blines2[$Blines2_pos] = $line2;
  187. }
  188. }
  189. /*
  190. include('language_data_jass.php');
  191. $ld = new languagedata();
  192. $ld->load_array($language_data);
  193. include('style_data_html.php');
  194. $hs = new highlightstyle();
  195. $hs->load_array($style_data);
  196. $ch1 = new codehighlighter($Blines1);
  197. $ch2 = new codehighlighter($Blines2);
  198. $output_lines1 = $ch1->parse_code($ld, $hs);
  199. $output_lines2 = $ch2->parse_code($ld, $hs);
  200. */
  201. $ech1 = new easycodehighlighter($Blines1, $default_lang1);
  202. $ech2 = new easycodehighlighter($Blines2, $default_lang2);
  203. $additional_headers[] = $ech1->code_css;
  204. $output_lines1 = $ech1->output;
  205. $output_lines2 = $ech2->output;
  206. $output_lines1 = str_replace('class="codebox"', 'class="codebox" style="position:absolute;width:49%;left:0px;margin-left:5px;height:500px;" id="a" onscroll="update_a();"', $output_lines1);
  207. $output_lines2 = str_replace('class="codebox"', 'class="codebox" style="position:absolute;width:49%;right:0px;margin-right:5px;height:500px;" id="b" onscroll="update_b();"', $output_lines2);
  208. $smarty->assign('output_lines1', $output_lines1);
  209. $smarty->assign('output_lines2', $output_lines2);
  210. }
  211. finish($smarty, "comparer.tpl", $additional_headers)
  212. ?>

goto line:
Compare with:
text copy window edit this code post new code