PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/versions.inc.php

https://github.com/adamfranco/segue-1.x
PHP | 535 lines | 351 code | 109 blank | 75 comment | 82 complexity | 29735cd1f0224596b3c06b8d0b4fa701 MD5 | raw file
  1. <? /* $Id$ */
  2. if ($_REQUEST['action'] == 'viewsite')
  3. $action = 'viewsite';
  4. else
  5. $action = 'site';
  6. $siteObj =& new site($_REQUEST[site]);
  7. $sectionObj =& new section($_REQUEST[site],$_REQUEST[section], $siteObj);
  8. $pageObj =& new page($_REQUEST[site],$_REQUEST[section],$_REQUEST[page], $sectionObj);
  9. $storyObj =& new story($_REQUEST[site],$_REQUEST[section],$_REQUEST[page],$_REQUEST[story], $pageObj);
  10. $getinfo = "site=".$siteObj->name."&amp;section=".$sectionObj->id."&amp;page=".$pageObj->id."&amp;story=".$storyObj->id."&amp;detail=".$storyObj->id;
  11. $getinfo2 = "site=".$siteObj->name."&amp;section=".$sectionObj->id."&amp;page=".$pageObj->id;
  12. $editsettingsurl = "&amp;site=".$siteObj->name."&amp;section=".$sectionObj->id."&amp;page=".$pageObj->id."&amp;action=edit_story&amp;edit_story=".$storyObj->id."&amp;detail=".$storyObj->id."&amp;step=4&amp;goback=discuss&amp;link=1";
  13. $storyObj->fetchFromDB();
  14. $storyObj->owningSiteObj->fetchFromDB();
  15. //$site_owner=slot::getOwner($story->owningSiteObj->name);
  16. $site_owner=$storyObj->owningSiteObj->owner;
  17. //print_r($story->owningSiteObj);
  18. //print $site_owner;
  19. // get the correct shorttext
  20. if ($storyObj->getField("type") == 'story') {
  21. $smalltext = convertTagsToInteralLinks($siteObj->name, $storyObj->getField("shorttext"));
  22. $fulltext = convertTagsToInteralLinks($siteObj->name, $storyObj->getField("longertext"));
  23. $smalltext = stripslashes($smalltext);
  24. $fulltext = stripslashes($fulltext);
  25. if ($storyObj->getField("texttype") == 'text') $fulltext = htmlbr($fulltext);
  26. if ($storyObj->getField("texttype") == 'text') $smalltext = htmlbr($smalltext);
  27. }
  28. if ($storyObj->getField("type") == 'image') {
  29. $filename = urldecode(db_get_value("media","media_tag","media_id='".addslashes($storyObj->getField("longertext"))."'"));
  30. $dir = db_get_value("media INNER JOIN slot ON media.FK_site = slot.FK_site","slot_name","media_id='".addslashes($storyObj->getField("longertext"))."'");
  31. $imagepath = "$uploadurl/$dir/$filename";
  32. $fulltext = "\n<div style='text-align: center'><br /><img src='$imagepath' border='0' /></div>";
  33. /* if ($story->getField("title")) $fulltext .= "<tr><td align='center'><b>".spchars($story->getField("title"))."</b></td></tr>"; */
  34. if ($storyObj->getField("shorttext")) {
  35. $captiontext = $st = convertTagsToInteralLinks($site, $storyObj->getField("shorttext"));
  36. $captiontext = "<br />".stripslashes($captiontext);
  37. }
  38. $fulltext .= "";
  39. }
  40. if ($storyObj->getField("type") == 'file') {
  41. $fulltext = "<br />";
  42. $fulltext .= makedownloadbar($storyObj);
  43. }
  44. /******************************************************************************
  45. * print out shory and discussion (if any)
  46. ******************************************************************************/
  47. printc("\n<table width='100%' id='maintable' cellspacing='1'>");
  48. printc($pagePagination);
  49. /******************************************************************************
  50. * print out title and options
  51. ******************************************************************************/
  52. printc("<tr><td align='left' class='title'>");
  53. printc("<a href='index.php?action=".$action."&amp;".$getinfo2."'>".spchars($pageObj->getField('title'))."</a>");
  54. if ($storyObj->getField('title')) {
  55. printc(" > ".spchars($storyObj->getField('title')));
  56. }
  57. /******************************************************************************
  58. * if request is to revert, then create new version based on revert version number
  59. ******************************************************************************/
  60. if ($_REQUEST['revert']) {
  61. $version = get_versions($storyObj->id, $_REQUEST['revert']);
  62. $version_num = $version[0]['version_order'];
  63. $version_short = stripslashes(urldecode($version[0]['version_text_short']));
  64. $version_long = stripslashes(urldecode($version[0]['version_text_long']));
  65. $story_id = $_REQUEST['story'];
  66. $version_comments = "reverted to revision ".$_REQUEST['revert'];
  67. // printpre($version_short);
  68. // exit;
  69. save_version ($version_short, $version_long, $story_id, $version_comments);
  70. }
  71. if ($_REQUEST['oldversion'] && $_REQUEST['newversion']) {
  72. if (!isset($_SESSION['oldversion']) || !is_array($_SESSION['oldversion']))
  73. $_SESSION['oldversion'] = array();
  74. if (!isset($_SESSION['newversion']) || !is_array($_SESSION['newversion']))
  75. $_SESSION['newversion'] = array();
  76. $_SESSION['oldversion'][$_REQUEST['story']] = $_REQUEST['oldversion'];
  77. $_SESSION['newversion'][$_REQUEST['story']] = $_REQUEST['newversion'];
  78. printc(" > <a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;versioning=".$_REQUEST['story']."'>All Versions</a>");
  79. printc(" > Selected Versions");
  80. } else if ($_REQUEST['versioning']) {
  81. printc(" > All Versions");
  82. /******************************************************************************
  83. * if particular version then get version details
  84. ******************************************************************************/
  85. } else if ($_REQUEST['version']) {
  86. $version = get_versions($storyObj->id, $_REQUEST['version']);
  87. $version_id = $version[0]['version_id'];
  88. $version_num = $version[0]['version_order'];
  89. $version_date = $version[0]['version_created_tstamp'];
  90. $version_author = $version[0]['FK_createdby'];
  91. //convert internal links
  92. $smalltext = convertTagsToInteralLinks($siteObj->name, stripslashes(urldecode($version[0]['version_text_short'])));
  93. $fulltext = convertTagsToInteralLinks($siteObj->name, stripslashes(urldecode($version[0]['version_text_long'])));
  94. $smalltext = urldecode($smalltext);
  95. $fulltext = urldecode($fulltext);
  96. printc(" > <a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;versioning=".$_REQUEST['story']."'>All Versions</a>");
  97. printc(" > Selected Versions");
  98. printc("<tr><td>");
  99. printc("<br /><table width='100%' cellspacing='0'><tr><td class='list'>");
  100. printc("<strong>Revision ".$version_num."</strong> (".$version_date." - ".$version_author.")");
  101. printc("</td><td align='right'>");
  102. // revert to this version link (top)
  103. if ($storyObj->hasPermission("edit")) {
  104. printc("<a class='btnlink2' href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;revert=".$version_num."&amp;versioning=".$_REQUEST['story']."&amp;comingFrom=viewsite'>Revert to this Version</a>\n");
  105. }
  106. printc("</td></td></table><br />");
  107. printc("</td></tr>\n");
  108. printc("<tr><td width='100%' valign='top' style='border: 1px dotted #CCCCCC;'>$smalltext</td></tr>\n");
  109. printc("<tr><td width='100%' valign='top' style='border: 1px dotted #CCCCCC;'>$fulltext</td></tr>\n");
  110. } else {
  111. printc(" > in depth");
  112. }
  113. printc("</td></tr>\n");
  114. // printpre($_REQUEST);
  115. /******************************************************************************
  116. * if selected versions request, then print out selected versions to compare
  117. ******************************************************************************/
  118. if ($_REQUEST['oldversion'] && $_REQUEST['newversion']) {
  119. define('USE_ASSERTS', false);
  120. require_once('DiffEngine.php');
  121. $formatter =& new SegueTableDiffFormatter;
  122. $version01 = get_versions($_REQUEST['story'], $_REQUEST['oldversion']);
  123. $version01_num = $version01[0]['version_order'];
  124. $version02 = get_versions($_REQUEST['story'], $_REQUEST['newversion']);
  125. $version02_num = $version02[0]['version_order'];
  126. $smalltext01 = convertTagsToInteralLinks($siteObj->name, stripslashes(urldecode($version01[0]['version_text_short'])));
  127. $smalltext02 = convertTagsToInteralLinks($siteObj->name, stripslashes(urldecode($version02[0]['version_text_short'])));
  128. $fulltext01 = convertTagsToInteralLinks($siteObj->name, stripslashes(urldecode($version01[0]['version_text_long'])));
  129. $fulltext02 = convertTagsToInteralLinks($siteObj->name, stripslashes(urldecode($version02[0]['version_text_long'])));
  130. // printpre($version01);
  131. //printpre($version02);
  132. printc("<tr><td style='padding-bottom: 15px; font-size: 12px'>");
  133. ob_start();
  134. print "\n<tr>";
  135. print "\n\t<th>";
  136. print "<a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;version=".$version01_num."'>Revision ".$version01_num."</a> ";
  137. print "<span class='timestamp'>";
  138. print "(".$version01[0]['version_created_tstamp']." - ".$version01[0]['FK_createdby'].")\n";
  139. print "</span>";
  140. print "</th>";
  141. print "\n\t<th>";
  142. print "<a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;version=".$version02_num."'>Revision ".$version02_num."</a> ";
  143. print "<span class='timestamp'>";
  144. print "(".$version02[0]['version_created_tstamp']." - ".$version02[0]['FK_createdby'].")\n";
  145. print "</span>";
  146. print "</th>";
  147. print "\n</tr>\n";
  148. $revisionHeadings = ob_get_clean();
  149. /*********************************************************
  150. * Shorttext
  151. *********************************************************/
  152. if (trim($fulltext01) || trim($fulltext02)) {
  153. // printc("\n\n<hr/ style='margin-top: 20px;'>");
  154. printc("\n<h2>Short Content</h2>");
  155. }
  156. printc("\n\n<table cellpadding='3' class='version_table'>");
  157. printc("\n<thead>");
  158. printc($revisionHeadings);
  159. printc("\n</thead>");
  160. printc("\n<tbody>");
  161. printc("<tr>\n");
  162. printc("<td>".$smalltext01."</td>\n");
  163. printc("<td>".$smalltext02."</td>\n");
  164. printc("</tr>\n");
  165. printc("\n</tbody>");
  166. printc("\n</table>");
  167. // Diffs
  168. printc("\n<table cellspacing='0' class='diff_table'>");
  169. printc("\n<thead>");
  170. printc("\n\t<tr><th colspan='4'>Changes</th></tr>\n");
  171. printc("\n</thead>");
  172. printc("\n<tbody>");
  173. $diff = & new Diff (explode("\n", $smalltext01), explode("\n", $smalltext02));
  174. printc($formatter->format($diff));
  175. printc("\n</tbody>");
  176. printc("\n</table>");
  177. /*********************************************************
  178. * Fulltext
  179. *********************************************************/
  180. if (trim($fulltext01) || trim($fulltext02)) {
  181. printc("\n\n<hr/ style='margin-top: 20px;'>");
  182. printc("\n<h2>Extended Content</h2>");
  183. printc("\n\n<table cellpadding='3' class='version_table'>");
  184. printc("\n<thead>");
  185. printc($revisionHeadings);
  186. printc("\n</thead>");
  187. printc("\n<tbody>");
  188. printc("\n<tr>");
  189. printc("\n\t<td class='version'>".$fulltext01."</td>");
  190. printc("\n<td class='version'>".$fulltext02."</td>");
  191. printc("\n</tr>");
  192. printc("\n</tbody>");
  193. printc("\n</table>");
  194. printc("\n<table cellspacing='0' class='diff_table'>");
  195. printc("\n<thead>");
  196. printc("<tr><th colspan='4' style='border-bottom: 1px dotted #CCC;'>Changes</th></tr>\n");
  197. printc("\n</thead>");
  198. printc("\n<tbody>");
  199. $diff = & new Diff (explode("\n", $fulltext01), explode("\n", $fulltext02));
  200. printc($formatter->format($diff));
  201. printc("\n</tbody>");
  202. printc("\n</table>");
  203. }
  204. printc("</td>");
  205. printc("</tr>\n");
  206. /******************************************************************************
  207. * if versioning then then show list of versions with date, version author
  208. ******************************************************************************/
  209. } else if ($_REQUEST['versioning']) {
  210. printc("\n<tr>\n\t<td>\n\t\t");
  211. $u = "$PHP_SELF?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;versioning=1";
  212. printc("<form action='$u' method='post'>\n");
  213. ob_start();
  214. print<<<END
  215. <script type='text/javascript'>
  216. // <![CDATA[
  217. if (!Array.prototype.push) {
  218. /**
  219. * IE 5.01 does not implement the push method, so it needs to be
  220. * added
  221. *
  222. * @param mixed element
  223. * @return int
  224. * @access public
  225. * @since 1/31/07
  226. */
  227. Array.prototype.push = function ( element ) {
  228. var key = this.length;
  229. this[key] = element;
  230. return key;
  231. }
  232. }
  233. /**
  234. * Update the radio buttons checked if needed to preven un-allowed situations:
  235. * - comparing a version to itself
  236. * - mixing up new and old versions
  237. *
  238. * @param object RadioButton button
  239. * @return void
  240. * @access public
  241. * @since 2/2/07
  242. */
  243. function updateVersionSelection (button) {
  244. var oldButtons = new Array();
  245. oldButtons.push(null);
  246. var newButtons = new Array();
  247. for (var i = 0; i < button.form.elements.length; i++) {
  248. // Sort the elements into old and new arrays and record
  249. // what row in each is selected
  250. var element = button.form.elements[i];
  251. if (element.name == 'oldversion') {
  252. oldButtons.push(element);
  253. if (element.checked)
  254. var oldRow = oldButtons.length - 1;
  255. } else if (element.name == 'newversion') {
  256. newButtons.push(element);
  257. if (element.checked)
  258. var newRow = newButtons.length - 1;
  259. }
  260. }
  261. // If a new version was selected make sure that the old version is older
  262. if (button.name == 'newversion') {
  263. if (oldRow <= newRow) {
  264. oldButtons[oldRow].checked = '';
  265. oldButtons[newRow + 1].checked = 'checked';
  266. }
  267. for (var i = 1; i < oldButtons.length; i++) {
  268. if (i <= newRow)
  269. oldButtons[i].style.visibility = 'hidden';
  270. else
  271. oldButtons[i].style.visibility = 'visible';
  272. }
  273. }
  274. // If an old version was selected make sure that the new version is newer
  275. else {
  276. if (newRow >= oldRow) {
  277. newButtons[newRow].checked = '';
  278. newButtons[oldRow - 1].checked = 'checked';
  279. }
  280. for (var i = 1; i < newButtons.length; i++) {
  281. if (i >= oldRow)
  282. newButtons[i].style.visibility = 'hidden';
  283. else
  284. newButtons[i].style.visibility = 'visible';
  285. }
  286. }
  287. }
  288. // ]]>
  289. </script>
  290. END;
  291. printc(ob_get_clean());
  292. // compare selected versions button (top)
  293. printc("<table cellspacing='3' width='100%'>\n\t<tr>");
  294. if ($action == "viewsite") {
  295. printc("\n\t<td align='left'><a class='btnlink2' href='index.php?$sid&amp;action=edit_story&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;edit_story=".$_REQUEST['story']."&amp;comingFrom=viewsite'>Edit current version</a></td>\n");
  296. }
  297. printc("\n\t<td align='right'><button type='submit' class='button' value='compare' onclick=\"window.location='$u'\">Compare selected revisions &gt;&gt;</button></td>");
  298. printc("\n\t</tr>\n</table>");
  299. printc("\n<table cellspacing='3' width='100%'>\n");
  300. $versions = get_versions($storyObj->id);
  301. //printpre($versions);
  302. printc("<thead><tr><th colspan='2'>Select</th><th>Revision</th><th>Revision Date</th><th>Revision Author</th><th>Revision Comment</th></tr></thead>\n");
  303. printc("\n<tbody style='vertical-align: top;'>\n");
  304. $shadeStyle = ' versionborders ';
  305. $shade = 0;
  306. $i = 0;
  307. $hideOld = true;
  308. $hideNew = false;
  309. $currentversion = true;
  310. foreach ($versions as $version) {
  311. $version_id = $version['version_id'];
  312. $version_num = $version['version_order'];
  313. printc("<tr>\n");
  314. printc("<td align='right' class='");
  315. printc($shadeStyle);
  316. printc("'>");
  317. if ($i > 0) {
  318. printc("<input type='radio' name='oldversion' value='".$version_num."' ");
  319. if (isset($_SESSION['oldversion'][$_REQUEST['story']])) {
  320. if ($_SESSION['oldversion'][$_REQUEST['story']] == $version_num) {
  321. printc(" checked='checked'");
  322. $hideNew = true;
  323. }
  324. } else {
  325. if ($i == 1) {
  326. printc(" checked='checked'");
  327. $hideNew = true;
  328. }
  329. }
  330. if ($hideOld)
  331. printc(" style='visibility: hidden;'");
  332. printc(" onclick=\"updateVersionSelection(this);\"");
  333. printc(" />");
  334. }
  335. printc("</td>\n<td align='left' class='");
  336. printc($shadeStyle);
  337. printc("'>");
  338. if ($i < count($versions) - 1) {
  339. printc("<input type='radio' name='newversion' value='".$version_num."' ");
  340. if (isset($_SESSION['newversion'][$_REQUEST['story']])) {
  341. if ($_SESSION['newversion'][$_REQUEST['story']] == $version_num) {
  342. printc(" checked='checked'");
  343. $hideOld = false;
  344. }
  345. } else {
  346. if (!$i) {
  347. printc(" checked='checked'");
  348. $hideOld = false;
  349. }
  350. }
  351. if ($hideNew)
  352. printc(" style='visibility: hidden;'");
  353. printc(" onclick=\"updateVersionSelection(this);\"");
  354. printc(" />");
  355. }
  356. printc("</td>");
  357. if ($currentversion) {
  358. printc("<td class='");
  359. printc($shadeStyle);
  360. printc("'>");
  361. printc("<a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;detail=".$_REQUEST['story']."'>Revision ".$version_num."</a> (current)</td>");
  362. } else {
  363. printc("<td class='");
  364. printc($shadeStyle);
  365. printc("'>");
  366. printc("<a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;version=".$version_num."'>Revision ".$version_num."</a></td>");
  367. }
  368. printc("<td class='");
  369. printc($shadeStyle);
  370. printc("' style='white-space: nowrap;'>");
  371. printc($version['version_created_tstamp']."</td>");
  372. printc("<td class='");
  373. printc($shadeStyle);
  374. printc("' style='white-space: nowrap;'>");
  375. printc($version['FK_createdby']."</td>\n");
  376. printc("<td class='");
  377. printc($shadeStyle);
  378. printc("' style='font-size: smaller;'>");
  379. printc($version['version_comments']."</td>\n");
  380. printc("</tr>\n");
  381. $shade = 1-$shade;
  382. $currentversion = false;
  383. $i++;
  384. }
  385. printc("\n</tbody>\n");
  386. printc("</table>\n");
  387. // compare selected versions button (bottom)
  388. printc("\n<table cellspacing='3' width='100%'>\n\t<tr>");
  389. printc("\n\t<td align='right'><button type='submit' class='button' value='compare' onclick=\"window.location='$u'\">Compare selected revisions &gt;&gt;</button></td>");
  390. // printc("<td align='right'><button type='submit' class='button' value='compare' onclick=\"window.location='$u'\">Edit this version</button></td>");
  391. printc("\n\t</tr>\n</table>");
  392. // printc("<br /><button type='submit' class='button' value='compare'>Compare selected revisions</button><br /><br /> ");
  393. printc("\n\t\t</form>");
  394. printc("\n\t</td>\n</tr>");
  395. }
  396. // Revert to this version link (bottom location)
  397. if ($_REQUEST['version'] && $storyObj->hasPermission("edit")) {
  398. printc("\n\t<tr><td align='center'><br />");
  399. printc("<a class='btnlink2' href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;revert=".$version_num."&amp;versioning=".$_REQUEST['story']."&amp;comingFrom=viewsite'>Revert to this Version</a>\n");
  400. printc("</td></tr>\n");
  401. }
  402. /******************************************************************************
  403. * print out title and options
  404. ******************************************************************************/
  405. printc("<tr><td align='left'>");
  406. printc("<a href='index.php?action=".$action."&amp;".$getinfo2."'>".spchars($pageObj->getField('title'))."</a>");
  407. if ($storyObj->getField('title')) {
  408. printc(" > ".spchars($storyObj->getField('title')));
  409. }
  410. if ($_REQUEST['oldversion'] && $_REQUEST['newversion']) {
  411. printc(" > <a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;versioning=".$_REQUEST['story']."'>All Versions</a>");
  412. printc(" > Selected Versions");
  413. } else if ($_REQUEST['versioning']) {
  414. printc(" > All Versions");
  415. /******************************************************************************
  416. * if particular version then get version details
  417. ******************************************************************************/
  418. } else if ($_REQUEST['version']) {
  419. printc(" > <a href='index.php?$sid&amp;action=".$action."&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;versioning=".$_REQUEST['story']."'>All Versions</a>");
  420. printc(" > Revision ".$version_num);
  421. } else {
  422. printc(" > in depth");
  423. }
  424. printc("</td></tr>\n");
  425. printc("</table>\n");
  426. ?>