/[drupal]/contributions/modules/tables/tables.module
ViewVC logotype

Diff of /contributions/modules/tables/tables.module

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

revision 1.13, Thu Sep 10 05:56:53 2009 UTC revision 1.14, Thu Sep 10 06:10:27 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: tables.module,v 1.12 2009/06/18 11:17:22 realityloop Exp $  // $Id$
3    
4  /**  /**
5   * @file   * @file
# Line 12  Line 12 
12   */   */
13    
14    
15  function tables_help($section) {  function tables_help($path, $arg) {
16    switch ($section) {    switch ($path) {
17      case 'admin/help#tables':      case 'admin/help#tables':
18        return t('<p>This filter module makes it easy and safe insert tables into the text of a node. '.        return t('<p>This filter module makes it easy and safe insert tables into the text of a node. '.
19                 '<p>A table always starts with "[table".  To set a custom class for the table next put in "=class" '.                 '<p>A table always starts with "[table".  To set a custom class for the table next put in "=class" '.
# Line 49  function _tables_prepare($intext) { Line 49  function _tables_prepare($intext) {
49    while (isset($matches[1][$i])) {    while (isset($matches[1][$i])) {
50      $out[0][$i] = $matches[0][$i];      $out[0][$i] = $matches[0][$i];
51      $tablein = $matches[1][$i];      $tablein = $matches[1][$i];
52      $rowspan=$colspan=array();      $rowspan=$colspan=array();
   
   
53      if ($tablein[0] == '=') {  //class is set      if ($tablein[0] == '=') {  //class is set
54        preg_match('/^=([a-zA-Z0-9-]*)/',$tablein, $cmatches);        preg_match('/^=([a-zA-Z0-9-]*)/',$tablein, $cmatches);
55        $classlen = strlen($cmatches[0]);        $classlen = strlen($cmatches[0]);
# Line 77  function _tables_prepare($intext) { Line 75  function _tables_prepare($intext) {
75      }      }
76      for ($j=$num_rows-1; $j>=0; $j--) {   // find any cols rows that span  row=j, col=k      for ($j=$num_rows-1; $j>=0; $j--) {   // find any cols rows that span  row=j, col=k
77        for ($k=$num_cols-1; $k>=0; $k--) {        for ($k=$num_cols-1; $k>=0; $k--) {
78          if ($cells[$j][$k]=='&') {          if ($cells[$j][$k]=='{') {
79            if (isset($colspan[$j][$k]) && $k>0) {            if (isset($colspan[$j][$k]) && $k>0) {
80              $colspan[$j][$k-1] = $colspan[$j][$k]+1;              $colspan[$j][$k-1] = $colspan[$j][$k]+1;
81            }            }
# Line 119  function _tables_prepare($intext) { Line 117  function _tables_prepare($intext) {
117              $cell_type='td';              $cell_type='td';
118            }            }
119    
120            if ($cells[$j][$k]!='^' && $cells[$j][$k]!='&') {            if ($cells[$j][$k]!='^' && $cells[$j][$k]!='{') {
121              $outtext.="<$cell_type";              $outtext.="<$cell_type";
122              if (isset($rowspan[$j][$k])) $outtext .= ' ROWSPAN='.$rowspan[$j][$k];              if (isset($rowspan[$j][$k])) $outtext .= ' ROWSPAN='.$rowspan[$j][$k];
123              if (isset($colspan[$j][$k])) $outtext .= ' COLSPAN='.$colspan[$j][$k];              if (isset($colspan[$j][$k])) $outtext .= ' COLSPAN='.$colspan[$j][$k];
# Line 140  function _tables_prepare($intext) { Line 138  function _tables_prepare($intext) {
138    return $out;    return $out;
139  }  }
140    
141    /**
142     *  Implementation of hook_filter
143     */
144    
145  function tables_filter($op, $delta = 0, $format = -1, $text = '') {  function tables_filter($op, $delta = 0, $format = -1, $text = '') {
146    switch ($op) {    switch ($op) {
# Line 163  function tables_filter($op, $delta = 0, Line 164  function tables_filter($op, $delta = 0,
164    
165      case 'prepare':      case 'prepare':
166        return $text;        return $text;
167    
168        case 'settings':
169          return tables_filter_settings_form();
170    
171    }    }
172  }  }
173    
# Line 170  function tables_filter_tips($delta, $for Line 175  function tables_filter_tips($delta, $for
175    return t('Insert an html table from [table | cell 2 ...]. Use "|" between cells and a new line between rows.');    return t('Insert an html table from [table | cell 2 ...]. Use "|" between cells and a new line between rows.');
176  }  }
177    
178  function tables_menu($may_cache) {  
179    $items = array();  function tables_init() {
180      $css = variable_get('tables_css', drupal_get_path('module','tables').'/tables.css');
181    if (!$may_cache) {    drupal_add_css($css);
     drupal_add_css(variable_get('tables_css', drupal_get_path('module','tables'). '/tables.css'));  
   
     $items[] = array(  
       'path' => 'admin/settings/tables',  
       'title' => t('Tables Filter'),  
       'description' => t('Filter to allow insertion of a table'),  
       'callback' => 'drupal_get_form',  
       'callback arguments' => array('tables_admin_settings'),  
       'access' => user_access('administer site configuration'),  
      );  
   }  
   
   return $items;  
182  }  }
183    
 function tables_admin_settings() {  
   if (!file_check_location(variable_get('tables_css', drupal_get_path('module','tables').'/tables.css'))) {  
     $error['tables_css'] = theme('error', t('File does not exist, or is not readable.'));  
   }  
   $form['tables_css'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Style Sheet'),  
     '#default_value' => variable_get('tables_css', drupal_get_path('module','tables').'/tables.css'),  
     '#size' => 70,  
     '#maxlength' => 255,  
     '#description' => t('Specify the relative path to your tables style sheet.  The style sheet specified here will be used to style tables you insert. If you prefer to style your tables in your theme, you can leave this field blank.'),  
   );  
184    
185    $form['tables_default_style'] = array(  
186    
187    function tables_filter_settings_form() {
188    
189      $form['tables_filter'] = array(
190        '#type' => 'fieldset',
191        '#title' => t('Tables filter'),
192        '#collapsible' => TRUE,
193      );
194      $form['tables_filter']['tables_default_style'] = array(
195      '#type' => 'textfield',      '#type' => 'textfield',
196      '#title' => t('Default style'),      '#title' => t('Default style'),
197      '#default_value' => variable_get('tables_default_style', 'tables-elegant'),      '#default_value' => variable_get('tables_default_style', 'tables-elegant'),
198      '#size' => 70,      '#size' => 70,
199      '#maxlength' => 255,      '#maxlength' => 255,
200      '#description' => t('Set the default style sheet to use if no style sheet is set in the specific table.'),      '#description' => t("Set the default style sheet to use if no style sheet is set in the specific table. "),
201    );    );
202      return $form;
   return system_settings_form($form);  
203  }  }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.2