/[drupal]/contributions/modules/revisioning/revisioning_theme.inc
ViewVC logotype

Diff of /contributions/modules/revisioning/revisioning_theme.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.5, Thu Apr 30 03:26:48 2009 UTC revision 1.6, Fri May 1 06:02:57 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: revisioning_theme.inc,v 1.4 2009/04/21 00:43:22 rdeboer Exp $  // $Id: revisioning_theme.inc,v 1.5 2009/04/30 03:26:48 rdeboer Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 13  Line 13 
13   */   */
14  function revisioning_theme() {  function revisioning_theme() {
15    return array(    return array(
16        'revisioning_revisions_summary' => array(
17          'arguments' => array('form' => array()),
18        ),
19      'revision_submenu' => array(      'revision_submenu' => array(
20        'arguments' => array('submenu_links' => NULL),        'arguments' => array('submenu_links' => NULL),
21        'template' => 'revision-submenu', // revision-submenu.tpl.php        'template' => 'revision-submenu', // revision-submenu.tpl.php
# Line 29  function revisioning_theme() { Line 32  function revisioning_theme() {
32  }  }
33    
34  /**  /**
35   * Theme the revisions summary of the supplied node via the revisions_summary   * Theme the revisions summary of the supplied node.
  * template.  
  *  
  * Uses the following subthemes:  
  * o 'table_revisions', falling back to theme.inc/theme_table() if not defined  
  * o 'placeholder' (to display current revision status)  
  * o 'username'  
  * Uses the following style-classes (see revisiong.css)  
  * o 'revision-current'  
  * o 'revision-pending'  
  * o 'revision-old'  
36   *   *
37   * @param $node   * @param $node
38   *   Node whose revisions to display   *   Node whose revisions to display
# Line 48  function revisioning_theme() { Line 41  function revisioning_theme() {
41   *   *
42   * @ingroup themeable   * @ingroup themeable
43   */   */
44  function _theme_revisions_summary($node) {  function _theme_revisions_summary(&$node) {
45    $css_path = drupal_get_path('module', 'revisioning') .'/revisioning.css';    drupal_set_title(t('Revisions for %title', array('%title'=> $node->title)));
46    drupal_add_css($css_path, 'module', 'all', FALSE); // also loads /revisioning-rtl.css    return drupal_get_form('revisioning_revisions_summary', $node);
47    
48    drupal_set_title(t('Revisions of %title', array('%title' => $node->title)));  }
49    
50    /**
51     * Return revisions summary table data. If the Diff modules is enabled, the
52     * object returned includes a column of checkboxes allowing the user to select
53     * two revisions for side-by-side comparison.
54     *
55     * @param $form_state
56     * @param $node
57     * @return form containing all data to be themed
58     */
59    function revisioning_revisions_summary($form_state, &$node) {
60      $form = array();
61      // Note, all (plain) form fields must be in array('#value' => ) format.
62      // Store node id in hidden field, required in submit function.
63      $form['nid'] = array('#value' => $node->nid, '#type' => 'hidden');
64    
65    $show_taxonomy_terms = module_exists('taxonomy');    $show_taxonomy_terms = module_exists('taxonomy');
66    $revisions = _get_all_revisions_for_node($node->nid, $show_taxonomy_terms);    $revisions = _get_all_revisions_for_node($node->nid, $show_taxonomy_terms);
67    
68    drupal_set_message(format_plural(count($revisions),    drupal_set_message(format_plural(count($revisions),
69      'This content has only one revision',      'This content has only one revision',
70      'This content has @count revisions.'));      'This content has @count revisions.'));
71    
72    // Set up the header    $revision_ids = array();
   $header = array(t('Revision'));  
   if ($show_taxonomy_terms) {  
     $header[] = t('Term');  
   }  
   $header[] = t('Status');  
   
   $rows = array();  
73    foreach ($revisions as $revision) {    foreach ($revisions as $revision) {
74      $is_current = ($revision->vid == $node->vid);      $vid = $revision->vid;
75      $is_pending = ($revision->vid > $node->vid);      $revision_ids[$vid] = '';
76      $row = array();      $base_url = "node/$node->nid/revisions/$vid";
77      $base_url = "node/$node->nid/revisions/$revision->vid";  
78        // First column: saved date + author
79      $first_cell = t('Saved !date by !username',      $first_cell = t('Saved !date by !username',
80        array('!date' => l(format_date($revision->timestamp, 'small'), "$base_url/view"),        array('!date' => l(format_date($revision->timestamp, 'small'), "$base_url/view"),
81              '!username' => theme('username', $revision)))              '!username' => theme('username', $revision)))
82        . ($revision->log != '' ? '<p class="revision-log">'. filter_xss($revision->log) .'</p>' : '');        . (empty($revision->log) ? '' : '<p class="revision-log">'. filter_xss($revision->log) .'</p>');
83        $form['info'][$vid] = array('#value' => $first_cell);
84    
85        // Term
86        if ($show_taxonomy_terms) {
87          $form['term'][$vid] = array('#value' => $revision->term);
88        }
89      }
90      if (count($revisions) >= 2 && module_exists('diff')) {
91        $id1 = key($revision_ids);
92        next($revision_ids);
93        $id2 = key($revision_ids);
94        $form['tickbox'] = array(
95          '#type' => 'checkboxes',
96          '#options' => $revision_ids,
97          '#default_value' => array($id1, $id2)
98        );
99        $form['submit'] = array('#value' => t('Compare'), '#type' => 'submit', );
100      }
101      return $form;
102    }
103    
104    /**
105     * Validation for input form to select two revisions.
106     *
107     * @param $form
108     * @param $form_state
109     * @return void
110     */
111    function revisioning_revisions_summary_validate($form, &$form_state) {
112      // Strip out all unchecked boxes
113      foreach($form_state['values']['tickbox'] as $key => $value) {
114        if ($value == 0) {
115          unset($form_state['values']['tickbox'][$key]);
116            }
117      }
118      $count = count($form_state['values']['tickbox']);
119      if ($count != 2) {
120        form_set_error('tickbox', t('Please select 2 revisions rather than !count', array('!count' => $count)));
121      }
122    }
123    
124    /**
125     * Submit two selected revisions to Diff module.
126     *
127     * @param $form
128     * @param $form_state
129     * @return void
130     */
131    function revisioning_revisions_summary_submit($form, &$form_state) {
132      $selected_vids = $form_state['values']['tickbox'];
133      $vid1 = key($selected_vids);
134      next($selected_vids);
135      $vid2 = key($selected_vids);
136      drupal_get_messages(); // clear existing msgs
137      drupal_set_message(t('Comparing revision #!revision2 against revision #!revision1',
138                         array('!revision2' => $vid2, '!revision1' => $vid1)));
139      $nid = $form_state['values']['nid'];
140      $form_state['redirect'] = "node/$nid/revisions/view/$vid2/$vid1";
141    }
142    
143    /**
144     * Theme the supplied form.
145     *
146     * Uses the following subthemes:
147     * o 'table_revisions', falling back to theme.inc/theme_table() if not defined
148     * o 'placeholder' (to display current revision status)
149     * o 'username'
150     * Uses the following style-classes (see revisioning.css)
151     * o 'table-revisions'
152     * o 'revision-current'
153     * o 'revision-pending'
154     * @param $form
155     * @return unknown_type
156     */
157    function theme_revisioning_revisions_summary($form) {
158    
159      $node = node_load($form['nid']['#value']);
160    
161      $css_path = drupal_get_path('module', 'revisioning') .'/revisioning.css';
162      drupal_add_css($css_path, 'module', 'all', FALSE);
163    
164      $style_class = $is_current ? 'revision-current' : ($is_pending ? 'revision-pending' : 'revision-old');    // Set up the table rows
165      $rows = array();
166      $revision_ids = element_children($form['info']);
167    
168      // First column: saved date + author    $show_diff = count($revision_ids) >= 2 && module_exists('diff');
169      $row[] = array('data' => $first_cell, 'class' => $style_class);    $show_taxonomy_terms = module_exists('taxonomy');
170    
171      // Set up the table header
172      $header = array(t('Revision'));
173      if ($show_diff) {
174        $header[] = drupal_render($form['submit']);
175      }
176      if ($show_taxonomy_terms) {
177        $header[] = t('Term');
178      }
179      $header[] = t('Status');
180    
181      foreach ($revision_ids as $vid) {
182        $row = array();
183        // Revision info
184        $row[] = drupal_render($form['info'][$vid]);
185        // Compare checkbox
186        if ($show_diff) {
187          $row[] = array('data' => drupal_render($form['tickbox'][$vid]), 'style' => 'text-align:center');
188        }
189      // Term      // Term
190      if ($show_taxonomy_terms) {      if ($show_taxonomy_terms) {
191        $row[] = array('data' => $revision->term, 'class' => $style_class);        $row[] = drupal_render($form['term'][$vid]);
192      }      }
193        // Publication status
194      // Status      $is_current = ($vid == $node->vid);
195        $is_pending = ($vid > $node->vid);
196      if ($is_current) {      if ($is_current) {
197        $row[] = array('data' => theme('placeholder', $revision->status ? t('current revision (published)') : t('current revision (unpublished)')),        $row[] = array('data' => theme('placeholder', $node->status ? t('current revision (published)') : t('current revision (unpublished)')));
                      'class' => $style_class);  
198      }      }
199      else {      else {
200        $row[] = array('data' => $is_pending ? t('pending moderation') : t('old'),        $row[] = array('data' => $is_pending ? t('pending moderation') : t('old'));
                      'class' => $style_class);  
201      }      }
202      $rows[] = $row;  
203        $row_style = $is_current ? 'revision-current' : ($is_pending ? 'revision-pending' : NULL);
204        $rows[] = array('data' => $row, 'class' => $row_style);
205    }    }
206    $attributes = array('class' => 'table-revisions');    $attributes = array('class' => 'table-revisions');
207    $content = theme(array('table_revisions', 'table'), $header, $rows, $attributes, $caption = NULL);    $content = theme(array('table_revisions', 'table'), $header, $rows, $attributes, $caption = NULL);
208    $submenu_links = generate_node_links_according_to_permissions($node);    $submenu_links = generate_node_links_according_to_permissions($node);
209    return theme(array('revisions_summary'), $submenu_links, $content);    return theme(array('revisions_summary'), $submenu_links, $content) . drupal_render($form);
210  }  }
211    
212  /**  /**
# Line 115  function _theme_revisions_summary($node) Line 217  function _theme_revisions_summary($node)
217   *   *
218   * @param $header   * @param $header
219   * @param $rows   * @param $rows
220   * @return themed HTML, see for instance /includes/theme.inc/theme_table()   * @return themed HTML, see for instance /includes/theme.inc/theme_table() and
221     *         diff.module/theme_diff_table()
222   *   *
223   * @ingroup themeable   * @ingroup themeable
224   *   *
# Line 169  function _theme_content_menu(&$node) { Line 272  function _theme_content_menu(&$node) {
272    $submenu_links = generate_revision_links_according_to_permissions($node);    $submenu_links = generate_revision_links_according_to_permissions($node);
273    $node->body = theme(array('revision_submenu', 'submenu'), $submenu_links) . $node->body;    $node->body = theme(array('revision_submenu', 'submenu'), $submenu_links) . $node->body;
274  }  }
275    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.2