[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/diff/ -> diff.theme.inc (source)

   1  <?php
   2  // $Id: diff.theme.inc,v 1.1.2.3 2010/08/12 16:34:08 yhahn Exp $
   3  
   4  /**
   5   * @file
   6   * Themeable function callbacks for diff.module.
   7   */
   8  
   9  /**
  10   * Theme function to display the revisions formular with means to select
  11   * two revisions.
  12   */
  13  function theme_diff_node_revisions($form) {
  14    $output = '';
  15  
  16    // Overview table:
  17    $header = array(
  18      t('Revision'),
  19      array('data' => drupal_render($form['submit']), 'colspan' => 2),
  20      array('data' => t('Operations'), 'colspan' => 2)
  21    );
  22    if (isset($form['info']) && is_array($form['info'])) {
  23      foreach (element_children($form['info']) as $key) {
  24        $row = array();
  25        if (isset($form['operations'][$key][0])) {
  26          // Note: even if the commands for revert and delete are not permitted,
  27          // the array is not empty since we set a dummy in this case.
  28          $row[] = drupal_render($form['info'][$key]);
  29          $row[] = drupal_render($form['diff']['old'][$key]);
  30          $row[] = drupal_render($form['diff']['new'][$key]);
  31          $row[] = drupal_render($form['operations'][$key][0]);
  32          $row[] = drupal_render($form['operations'][$key][1]);
  33          $rows[] = $row;
  34        }
  35        else {
  36          // its the current revision (no commands to revert or delete)
  37          $row[] = array('data' => drupal_render($form['info'][$key]), 'class' => 'revision-current');
  38          $row[] = array('data' => drupal_render($form['diff']['old'][$key]), 'class' => 'revision-current');
  39          $row[] = array('data' => drupal_render($form['diff']['new'][$key]), 'class' => 'revision-current');
  40          $row[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => '2');
  41          $rows[] = array(
  42            'data' => $row,
  43            'class' => 'error',
  44          );
  45        }
  46      }
  47    }
  48    $output .= theme('table', $header, $rows);
  49    $output .= drupal_render($form);
  50    return $output;
  51  }
  52  
  53  /**
  54   * Theme functions
  55   */
  56  
  57  /**
  58   * Return a themed table. This is a modified version of theme_table, adding
  59   * colgroup tag and col tag options.
  60   *
  61   * @param $header
  62   *   An array containing the table headers. Each element of the array can be
  63   *   either a localized string or an associative array with the following keys:
  64   *   - "data": The localized title of the table column.
  65   *   - "field": The database field represented in the table column (required if
  66   *     user is to be able to sort on this column).
  67   *   - "sort": A default sort order for this column ("asc" or "desc").
  68   *   - Any HTML attributes, such as "colspan", to apply to the column header cell.
  69   * @param $rows
  70   *   An array of table rows. Every row is an array of cells, or an associative
  71   *   array with the following keys:
  72   *   - "data": an array of cells
  73   *   - Any HTML attributes, such as "class", to apply to the table row.
  74   *
  75   *   Each cell can be either a string or an associative array with the following keys:
  76   *   - "data": The string to display in the table cell.
  77   *   - "header": Indicates this cell is a header.
  78   *   - Any HTML attributes, such as "colspan", to apply to the table cell.
  79   *
  80   *   Here's an example for $rows:
  81   *   @verbatim
  82   *   $rows = array(
  83   *     // Simple row
  84   *     array(
  85   *       'Cell 1', 'Cell 2', 'Cell 3'
  86   *     ),
  87   *     // Row with attributes on the row and some of its cells.
  88   *     array(
  89   *       'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => 'funky'
  90   *     )
  91   *   );
  92   *   @endverbatim
  93   *
  94   * @param $attributes
  95   *   An array of HTML attributes to apply to the table tag.
  96   * @param $caption
  97   *   A localized string to use for the <caption> tag.
  98   * @param $cols
  99   *   An array of table colum groups. Every column group is an array of columns,
 100   *   or an associative array with the following keys:
 101   *   - "data": an array of cells
 102   *   - Any HTML attributes, such as "class", to apply to the table column group.
 103   *
 104   *   Each column can be either an empty array or associative array with the following keys:
 105   *   - Any HTML attributes, such as "class", to apply to the table column group.
 106   *
 107   *   Here's an example for $cols:
 108   *   @verbatim
 109   *   $cols = array(
 110   *     // Simple colgroup.
 111   *     array(),
 112   *     // Simple colgroup with attributes.
 113   *     array(
 114   *       'data'  => array(), 'colspan' => 2, 'style' => 'color: green;',
 115   *     ),
 116   *     // Simple colgroup with one col.
 117   *     array(
 118   *       array(),
 119   *     ),
 120   *     // Colgroup with attributes on the colgroup and some of its cols.
 121   *     array(
 122   *       'data'  => array(array('class' => 'diff-marker'), array('colspan' => 2)), 'class' => 'funky',
 123   *     ),
 124   *   );
 125   *   @endverbatim
 126   *
 127   *   The HTML will look as follows:
 128   *   @verbatim
 129   *   <table>
 130   *     <!-- Simple colgroup. -->
 131   *     <colgroup />
 132   *
 133   *     <!-- Simple colgroup with attributes. -->
 134   *     <colgroup colspan="2" style="color: green;" />
 135   *
 136   *     <!-- Simple colgroup with one col. -->
 137   *     <colgroup>
 138   *       <col />
 139   *     </colgroup>
 140   *
 141   *     <!-- Colgroup with attributes on the colgroup and some of its cols. -->
 142   *     <colgroup class="funky">
 143   *       <col class="diff-marker" />
 144   *       <col colspan="2" />
 145   *     </colgroup>
 146   *     ...
 147   *   </table>
 148   *   @endverbatim
 149   *
 150   * @return
 151   *   An HTML string representing the table.
 152   */
 153  function theme_diff_table($header, $rows, $attributes = array(), $caption = NULL, $cols = array()) {
 154    $output = '<table'. drupal_attributes($attributes) .">\n";
 155  
 156    if (isset($caption)) {
 157      $output .= '<caption>'. $caption ."</caption>\n";
 158    }
 159  
 160    // Format the table columns:
 161    if (count($cols)) {
 162      foreach ($cols as $number => $col) {
 163        $attributes = array();
 164  
 165        // Check if we're dealing with a simple or complex column
 166        if (isset($col['data'])) {
 167          foreach ($col as $key => $value) {
 168            if ($key == 'data') {
 169              $cells = $value;
 170            }
 171            else {
 172              $attributes[$key] = $value;
 173            }
 174          }
 175        }
 176        else {
 177          $cells = $col;
 178        }
 179  
 180        // Build colgroup
 181        if (is_array($cells) && count($cells)) {
 182          $output .= ' <colgroup'. drupal_attributes($attributes) .'>';
 183          $i = 0;
 184          foreach ($cells as $cell) {
 185            $output .= ' <col'. drupal_attributes($cell) .' />';
 186          }
 187          $output .= " </colgroup>\n";
 188        }
 189        else {
 190          $output .= ' <colgroup'. drupal_attributes($attributes) ." />\n";
 191        }
 192      }
 193    }
 194  
 195    // Format the table header:
 196    if (count($header)) {
 197      $ts = tablesort_init($header);
 198      $output .= ' <thead><tr>';
 199      foreach ($header as $cell) {
 200        $cell = tablesort_header($cell, $header, $ts);
 201        $output .= _theme_table_cell($cell, TRUE);
 202      }
 203      $output .= " </tr></thead>\n";
 204    }
 205  
 206    // Format the table rows:
 207    $output .= "<tbody>\n";
 208    if (count($rows)) {
 209      $flip = array('even' => 'odd', 'odd' => 'even');
 210      $class = 'even';
 211      foreach ($rows as $number => $row) {
 212        $attributes = array();
 213  
 214        // Check if we're dealing with a simple or complex row
 215        if (isset($row['data'])) {
 216          foreach ($row as $key => $value) {
 217            if ($key == 'data') {
 218              $cells = $value;
 219            }
 220            else {
 221              $attributes[$key] = $value;
 222            }
 223          }
 224        }
 225        else {
 226          $cells = $row;
 227        }
 228  
 229        // Add odd/even class
 230        $class = $flip[$class];
 231        if (isset($attributes['class'])) {
 232          $attributes['class'] .= ' '. $class;
 233        }
 234        else {
 235          $attributes['class'] = $class;
 236        }
 237  
 238        // Build row
 239        $output .= ' <tr'. drupal_attributes($attributes) .'>';
 240        $i = 0;
 241        foreach ($cells as $cell) {
 242          $cell = tablesort_cell($cell, $header, $ts, $i++);
 243          $output .= _theme_table_cell($cell);
 244        }
 245        $output .= " </tr>\n";
 246      }
 247    }
 248  
 249    $output .= "</tbody></table>\n";
 250    return $output;
 251  }
 252  
 253  /**
 254   * Theme function for a header line in the diff.
 255   */
 256  function theme_diff_header_line($lineno) {
 257    return '<strong>'. t('Line %lineno', array('%lineno' => $lineno)) .'</strong>';
 258  }
 259  
 260  /**
 261   * Theme function for a content line in the diff.
 262   */
 263  function theme_diff_content_line($line) {
 264    return '<div>'. $line .'</div>';
 265  }
 266  
 267  /**
 268   * Theme function for an empty line in the diff.
 269   */
 270  function theme_diff_empty_line($line) {
 271    return $line;
 272  }
 273  
 274  /**
 275   * Theme function for inline diff form.
 276   */
 277  function theme_diff_inline_form($form) {
 278    drupal_add_css(drupal_get_path('module', 'diff') .'/diff.css');
 279    return drupal_render($form);
 280  }
 281  
 282  /**
 283   * Display inline diff metadata.
 284   */
 285  function theme_diff_inline_metadata($node) {
 286    drupal_add_css(drupal_get_path('module', 'diff') .'/diff.css');
 287    $output = "<div class='diff-inline-metadata clear-block'>";
 288    $output .= "<div class='diff-inline-byline'>";
 289    $output .= t('Updated by !name on @date', array(
 290      '!name' => theme('username', $node),
 291      '@date' => format_date($node->revision_timestamp, 'small'),
 292    ));
 293    $output .= "</div>";
 294    $output .= "<div class='diff-inline-legend clear-block'>";
 295    $output .= "<label>". t('Legend') ."</label>";
 296    $output .= theme('diff_inline_chunk', t('Added'), 'add');
 297    $output .= theme('diff_inline_chunk', t('Changed'), 'change');
 298    $output .= theme('diff_inline_chunk', t('Deleted'), 'relete');
 299    $output .= "</div>";
 300    $output .= "</div>";
 301    return $output;
 302  }
 303  
 304  /**
 305   * Theme a span of changed text in an inline diff display.
 306   */
 307  function theme_diff_inline_chunk($text, $type = NULL) {
 308    switch ($type) {
 309      case 'add':
 310        return "<span class='diff-added'>{$text}</span>";
 311      case 'change':
 312        return "<span class='diff-changed'>{$text}</span>";
 313      case 'delete':
 314        return "<span class='diff-deleted'>{$text}</span>";
 315      default:
 316        return $text;
 317    }
 318  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7