PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/versions/view.php

https://github.com/agnesrambaud/yacs
PHP | 188 lines | 90 code | 36 blank | 62 comment | 35 complexity | fa1b0e1af6fcf3e11d1eb536822f3fdf MD5 | raw file
  1. <?php
  2. /**
  3. * display one version
  4. *
  5. * If several versions have been posted to a single anchor, a navigation bar will be built to jump
  6. * directly to previous and next neighbours.
  7. * This is displayed as a sidebar box in the extra panel.
  8. *
  9. * The extra panel also features top popular referrals in a sidebar box, if applicable.
  10. *
  11. * Only anchor owners can proceed
  12. *
  13. * Accept following invocations:
  14. * - view.php/12
  15. * - view.php?id=12
  16. *
  17. * If the anchor for this item specifies a specific skin (option keyword '[code]skin_xyz[/code]'),
  18. * or a specific variant (option keyword '[code]variant_xyz[/code]'), they are used instead default values.
  19. *
  20. * @author Bernard Paques
  21. * @author GnapZ
  22. * @reference
  23. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  24. */
  25. // common definitions and initial processing
  26. include_once '../shared/global.php';
  27. include_once 'versions.php';
  28. // look for the id
  29. $id = NULL;
  30. if(isset($_REQUEST['id']))
  31. $id = $_REQUEST['id'];
  32. elseif(isset($context['arguments'][0]))
  33. $id = $context['arguments'][0];
  34. $id = strip_tags($id);
  35. // get the item from the database
  36. $item =& Versions::get($id);
  37. // get the related anchor, if any
  38. $anchor = NULL;
  39. if(isset($item['anchor']) && $item['anchor'])
  40. $anchor =& Anchors::get($item['anchor']);
  41. // you have to own the object to handle versions
  42. if(is_object($anchor) && $anchor->is_owned())
  43. $permitted = TRUE;
  44. // editors of parent anchor can do it also
  45. elseif(is_object($anchor) && ($anchor->get_type() == 'section') && Sections::is_owned(NULL, $anchor))
  46. $permitted = TRUE;
  47. // the default is to deny access
  48. else
  49. $permitted = FALSE;
  50. // load the skin, maybe with a variant
  51. load_skin('versions', $anchor);
  52. // clear the tab we are in, if any
  53. if(is_object($anchor))
  54. $context['current_focus'] = $anchor->get_focus();
  55. // the path to this page
  56. if(is_object($anchor) && $anchor->is_viewable())
  57. $context['path_bar'] = $anchor->get_path_bar();
  58. // page title
  59. if(is_object($anchor)) {
  60. $context['page_title'] = $anchor->get_title();
  61. // add revision date and author
  62. if(isset($item['edit_date']))
  63. $context['page_title'] .= ' ['.Skin::build_date($item['edit_date']).']';
  64. }
  65. // not found -- help web crawlers
  66. if(!isset($item['id'])) {
  67. include '../error.php';
  68. // permission denied
  69. } elseif(!$permitted) {
  70. // anonymous users are invited to log in or to register
  71. if(!Surfer::is_logged())
  72. Safe::redirect($context['url_to_home'].$context['url_to_root'].'users/login.php?url='.urlencode(Versions::get_url($item['id'])));
  73. // permission denied to authenticated user
  74. Safe::header('Status: 401 Forbidden', TRUE, 401);
  75. Logger::error(i18n::s('You are not allowed to perform this operation.'));
  76. // re-enforce the canonical link
  77. } elseif($context['self_url'] && ($canonical = $context['url_to_home'].$context['url_to_root'].Versions::get_url($item['id'])) && strncmp($context['self_url'], $canonical, strlen($canonical))) {
  78. Safe::header('Status: 301 Moved Permanently', TRUE, 301);
  79. Safe::header('Location: '.$canonical);
  80. Logger::error(Skin::build_link($canonical));
  81. // display the version
  82. } else {
  83. // display details for this version
  84. $context['text'] .= '<dl class="version">'."\n";
  85. if(($attributes = Safe::unserialize($item['content'])) && @count($attributes)) {
  86. $fields = array( 'title' => array(i18n::s('Title'), '', FALSE),
  87. 'introduction' => array('', '', TRUE),
  88. 'overlay' => array('', '', FALSE, i18n::s('Content of the overlay has changed')),
  89. 'description' => array('', '', TRUE),
  90. 'tags' => array(i18n::s('Tags'), '', TRUE),
  91. 'trailer' => array(i18n::s('Trailer'), BR, FALSE),
  92. 'extra' => array(i18n::s('Extra'), BR, FALSE) );
  93. foreach($fields as $name => $params) {
  94. if(isset($attributes[ $name ])) {
  95. $compared = $anchor->diff($name, $attributes[ $name ]);
  96. if($params[2] || strcmp($compared, $attributes[ $name ])) {
  97. // use a constant string instead of showing differences
  98. if(isset($params[3]))
  99. $compared = '<ins>'.$params[3].'</ins>';
  100. if($params[0])
  101. $context['text'] .= '<div style="margin-bottom: 1em;">'.sprintf(i18n::s('%s: %s'), $params[0], $params[1].$compared).'</div>';
  102. else
  103. $context['text'] .= '<div style="margin-bottom: 1em;">'.$params[1].$compared.'</div>';
  104. }
  105. }
  106. }
  107. // $rows = array();
  108. // foreach($attributes as $name => $value) {
  109. // if(is_string($value) && $value && preg_match('/(active|anchor|locked|rank|title)$/', $name))
  110. // $rows[] = array($name, $value);
  111. // }
  112. // if($rows)
  113. // $context['text'] .= Skin::table(NULL, $rows);
  114. }
  115. // back to the anchor page
  116. $links = array();
  117. if((is_object($anchor) && $anchor->is_assigned()))
  118. $links[] = Skin::build_link(Versions::get_url($anchor->get_reference(), 'list'), i18n::s('Versions'), 'button');
  119. if($item['id'] && (Surfer::is_associate()
  120. || (Surfer::is_member() && is_object($anchor) && $anchor->is_assigned())))
  121. $links[] = Skin::build_link(Versions::get_url($item['id'], 'restore'), i18n::s('Restore this version'), 'basic', i18n::s('Caution: restoration can not be reversed!'));
  122. $context['text'] .= Skin::finalize_list($links, 'assistant_bar');
  123. // page help
  124. $help = '';
  125. // information to members
  126. if(Surfer::is_member())
  127. $help .= '<p>'.sprintf(i18n::s('This has been posted by %s %s.'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date']))."</p>\n";
  128. $help .= '<p><ins>'.i18n::s('Text inserted since that version.').'</ins></p>'
  129. .'<p><del>'.i18n::s('Text suppressed from this version.').'</del></p>'
  130. .'<p>'.i18n::s('Caution: restoration can not be reversed!').'</p>';
  131. $context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help');
  132. //
  133. // the navigation sidebar
  134. //
  135. $text = '';
  136. // buttons to display previous and next pages, if any
  137. if(is_object($anchor)) {
  138. $neighbours = $anchor->get_neighbours('version', $item);
  139. $text .= Skin::neighbours($neighbours, 'sidebar');
  140. }
  141. // build a nice sidebar box
  142. if($text)
  143. $text =& Skin::build_box(i18n::s('Navigation'), $text, 'neighbours', 'neighbours');
  144. $context['components']['neighbours'] = $text;
  145. //
  146. // referrals, if any, in a sidebar
  147. //
  148. $context['components']['referrals'] =& Skin::build_referrals(Versions::get_url($item['id']));
  149. }
  150. // render the skin
  151. render_skin();
  152. ?>