[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/text_resize/ -> text_resize.module (source)

   1  <?php
   2  // $Id: text_resize.module,v 1.1.2.7 2009/05/31 04:10:01 attheshow Exp $
   3  
   4  /**
   5   * @file
   6   * Creates a small block with jQuery links that resize text within the BODY tag.
   7   */
   8  
   9  /**
  10   * Implementation of hook_menu().
  11   */
  12  function text_resize_menu() {
  13    $items = array();
  14    $items['admin/settings/text_resize'] = array(
  15      'title' => 'Text Resize',
  16      'description' => 'Settings for your Text Resize block.',
  17      'access arguments' => array('administer site configuration'),
  18      'page callback' => 'drupal_get_form',
  19      'page arguments' => array('_text_resize_admin_settings'),
  20      'type' => MENU_NORMAL_ITEM
  21    );
  22    return $items;
  23  }
  24  
  25  /**
  26   * Builder function for admin settings form.
  27   */
  28  function _text_resize_admin_settings() {
  29    $form = array();
  30  
  31    $form['text_resize_scope'] = array(
  32      '#type' => 'textfield',
  33      '#title' => 'Text Resize Scope',
  34      '#default_value' => _text_resize_scope(),
  35      '#description' => t('Which portion of the body would you like to be resized by the Text Resize block? You may enter either the CSS class attribute, the CSS id attribute, or an HTML tag.<br />For example, if you want all text within &lt;div id="my-container"&gt; to be resized, enter the ID <strong>my-container</strong>.<br />If, on the other hand, you would like all text within the BODY tag to be resized, enter <strong>body</strong>.'),
  36      '#required' => TRUE,
  37    );
  38    $form['text_resize_minimum'] = array(
  39      '#type' => 'textfield',
  40      '#title' => 'Minimum Text Size',
  41      '#maxlength' => 2,
  42      '#default_value' => _text_resize_minimum(),
  43      '#description' => 'What is the smallest font size (in pixels) that your text can be resized to by users?',
  44      '#required' => TRUE,
  45    );
  46    $form['text_resize_maximum'] = array(
  47      '#type' => 'textfield',
  48      '#title' => 'Maximum Text Size',
  49      '#maxlength' => 2,
  50      '#default_value' => _text_resize_maximum(),
  51      '#description' => 'What is the largest font size (in pixels) that your text can be resized to by users?',
  52      '#required' => TRUE,
  53    );
  54    $form['text_resize_reset_button'] = array(
  55      '#type' => 'checkbox',
  56      '#title' => 'Add Reset Button',
  57      '#default_value' => _text_resize_reset_button(),
  58      '#description' => 'Do you want to add an extra button to the block to allow the font size to be reset to normal?',
  59    );
  60    $form['text_resize_line_height_allow'] = array(
  61      '#type' => 'checkbox',
  62      '#title' => 'Allow Line-Height Adjustment',
  63      '#default_value' => _text_resize_line_height_allow(),
  64      '#description' => 'Do you want to allow Text Resize to change the spacing between the lines of text?',
  65    );
  66    $form['text_resize_line_height_min'] = array(
  67      '#type' => 'textfield',
  68      '#title' => 'Minimum Line-Height',
  69      '#maxlength' => 2,
  70      '#default_value' => _text_resize_line_height_min(),
  71      '#description' => 'What is the smallest line-height (in pixels) that your text can be resized to by users?',
  72    );
  73    $form['text_resize_line_height_max'] = array(
  74      '#type' => 'textfield',
  75      '#title' => 'Maximum Line-Height',
  76      '#maxlength' => 2,
  77      '#default_value' => _text_resize_line_height_max(),
  78      '#description' => 'What is the largest line-height (in pixels) that your text can be resized to by users?',
  79    );
  80    $form = system_settings_form($form);
  81    // Rebuild the menu after updating the settings.
  82    $form['#submit'][] = 'menu_rebuild';
  83    return $form;
  84  }
  85  
  86  function _text_resize_scope($value = NULL) {
  87    if (is_null($value)) {
  88      return _get_text_resize_scope();
  89    }
  90    variable_set('text_resize_scope', $value);
  91  }
  92  
  93  // Get the scope specified by the admin
  94  function _get_text_resize_scope() {
  95    $text_resize_scope = variable_get('text_resize_scope', 'content-inner');
  96    return $text_resize_scope;
  97  }
  98  
  99  function _text_resize_minimum($value = NULL) {
 100    if (is_null($value)) {
 101      return _get_text_resize_minimum();
 102    }
 103    variable_set('text_resize_minimum', $value);
 104  }
 105  
 106  // Get the minimum size specified by the admin
 107  function _get_text_resize_minimum() {
 108    $text_resize_minimum = variable_get('text_resize_minimum', '12');
 109    return $text_resize_minimum;
 110  }
 111  
 112  function _text_resize_maximum($value = NULL) {
 113    if (is_null($value)) {
 114      return _get_text_resize_maximum();
 115    }
 116    variable_set('text_resize_maximum', $value);
 117  }
 118  
 119  // Get the maximum size specified by the admin
 120  function _get_text_resize_maximum() {
 121    $text_resize_maximum = variable_get('text_resize_maximum', '25');
 122    return $text_resize_maximum;
 123  }
 124  
 125  function _text_resize_reset_button($value = NULL) {
 126    if (is_null($value)) {
 127      return _get_text_resize_reset_button();
 128    }
 129    variable_set('text_resize_reset_button', $value);
 130  }
 131  
 132  // Get the reset button preference specified by the admin
 133  function _get_text_resize_reset_button() {
 134    $text_resize_reset_button = variable_get('text_resize_reset_button', FALSE);
 135    return $text_resize_reset_button;
 136  }
 137  
 138  function _text_resize_line_height_allow($value = NULL) {
 139    if (is_null($value)) {
 140      return _get_text_resize_line_height_allow();
 141    }
 142    variable_set('text_resize_line_height_allow', $value);
 143  }
 144  
 145  // Get the line height preference specified by the admin
 146  function _get_text_resize_line_height_allow() {
 147    $text_resize_line_height_allow = variable_get('text_resize_line_height_allow', FALSE);
 148    return $text_resize_line_height_allow;
 149  }
 150  
 151  function _text_resize_line_height_min($value = NULL) {
 152    if (is_null($value)) {
 153      return _get_text_resize_line_height_min();
 154    }
 155    variable_set('text_resize_line_height_min', $value);
 156  }
 157  
 158  // Get the minimum line height preference specified by the admin
 159  function _get_text_resize_line_height_min() {
 160    $text_resize_line_height_min = variable_get('text_resize_line_height_min', 16);
 161    return $text_resize_line_height_min;
 162  }
 163  
 164  function _text_resize_line_height_max($value = NULL) {
 165    if (is_null($value)) {
 166      return _get_text_resize_line_height_max();
 167    }
 168    variable_set('text_resize_line_height_max', $value);
 169  }
 170  
 171  // Get the maximum line height preference specified by the admin
 172  function _get_text_resize_line_height_max() {
 173    $text_resize_line_height_max = variable_get('text_resize_line_height_max', 36);
 174    return $text_resize_line_height_max;
 175  }
 176  
 177  /**
 178   * Implementation of hook_block().
 179   */
 180  function text_resize_block($op = 'list', $delta = 0, $edit = array()) {
 181    global $user;
 182    switch ($op) {
 183      case 'list': // Makes it show up on /admin/build/block page.
 184        $blocks[0]['info'] = t('Text Resize');
 185        return $blocks;
 186      case 'view':
 187        // Show the block.
 188        $block['subject'] = t('Text Resize');
 189        $block['content'] = theme('text_resize_block');
 190        return $block;
 191    }
 192  }
 193  
 194  /**
 195   * Implementation of hook_init().
 196   */
 197  function text_resize_init() {
 198    drupal_add_css(drupal_get_path('module', 'text_resize') .'/text_resize.css');
 199    drupal_add_js(drupal_get_path('module', 'text_resize') .'/jquery.cookie.js', 'file');
 200    drupal_add_js("var text_resize_scope = ". drupal_to_js(_get_text_resize_scope()) .";
 201      var text_resize_minimum = ". drupal_to_js(_get_text_resize_minimum()) .";
 202      var text_resize_maximum = ". drupal_to_js(_get_text_resize_maximum()) .";
 203      var text_resize_line_height_allow = ". drupal_to_js(_get_text_resize_line_height_allow()) .";
 204      var text_resize_line_height_min = ". drupal_to_js(_get_text_resize_line_height_min()) .";
 205      var text_resize_line_height_max = ". drupal_to_js(_get_text_resize_line_height_max()) .";", 'inline');
 206    drupal_add_js(drupal_get_path('module', 'text_resize') .'/text_resize.js', 'file');
 207  }
 208  
 209  /**
 210   * Implementation of hook_theme().
 211   */
 212  function text_resize_theme() {
 213    return array(
 214      'text_resize_block' => array(),
 215    );
 216  }
 217  // Create a theme function that can be overridden by other theme developers.
 218  function theme_text_resize_block() {
 219    if (_get_text_resize_reset_button() == TRUE) {
 220      $output = t('<a href="javascript:;" class="changer" id="text_resize_decrease"><sup>-</sup>A</a> <a href="javascript:;" class="changer" id="text_resize_reset">A</a> <a href="javascript:;" class="changer" id="text_resize_increase"><sup>+</sup>A</a><div id="text_resize_clear"></div>');
 221    }
 222    else {
 223      $output = t('<a href="javascript:;" class="changer" id="text_resize_decrease"><sup>-</sup>A</a> <a href="javascript:;" class="changer" id="text_resize_increase"><sup>+</sup>A</a><div id="text_resize_clear"></div>');
 224    }
 225    return $output;
 226  }
 227  
 228  /**
 229   * Implementation of hook_help().
 230   */
 231  function text_resize_help($path, $arg) {
 232    switch ($path) {
 233      case 'admin/help#text_resize':
 234        $output = '<p>'. t('The Text Resize module creates a block on the page that can be used by your site visitors to quickly and easily adjust the sizing of text as it displays for them.  In order to enable the functionality of the Text Resize module, you will need to make sure that you have enabled the Text Resize block on the <a href="admin/build/block">blocks page</a>. You will also probably want to configure the behavior of the module at the administration pages listed at the bottom of this page.') .'</p>';
 235        $output .= '<h2>'. t('Changing How Text Resize Looks') .'</h2>';
 236        $output .= '<h3>'. t('Method 1: Just CSS') .'</h3>';
 237        $output .= '<p>'. t('Text Resize creates two stylized hyperlinks on the page (and a third if you enable the reset button option). You can add new styles to your own theme\'s stylesheet that will override the default CSS styles produced by Text Resize. The ids you\'ll want to add and modify in your stylesheet are:') .'</p>';
 238        $output .= '<ul><li>#text_resize_increase</li>';
 239        $output .= '<li>#text_resize_decrease</li>';
 240        $output .= '<li>#text_resize_reset '. t('(if you\'ve chosen to use the reset button option)') .'</li></ul>';
 241        $output .= '<h3>'. t('Method 2: A Theme Function') .'</h3>';
 242        $output .= '<p>'. t('If you need to change the HTML that is produced by Text Resize in some way, you can create a small function in your theme\'s template.php file. An example is below:') .'</p>';
 243        $output .= '<p><code>function YOUR_THEME_NAME_text_resize_block() {<br />&nbsp;&nbsp;$output = t(\'&lt;a href="javascript:;" class="changer" id="text_resize_decrease"&gt;&lt;sup&gt;-&lt;/sup&gt;A&lt;/a&gt; &lt;a href="javascript:;" class="changer" id="text_resize_increase"&gt;&lt;sup&gt;+&lt;/sup&gt;A&lt;/a&gt; &lt;a href="/contact"&gt;Contact&lt;/a&gt; | &lt;a href="/pages/site-map"&gt;Site Map&lt;/a&gt;&lt;div id="text_resize_clear"&gt;&lt;/div&gt;\');<br />&nbsp;&nbsp;return $output;<br />}</code></p>';
 244        $output .= '<p>'. t('In the example above, the HTML output code is just modified so that two new hyperlinks are added into the original block code.') .'</p>';
 245        return $output;
 246      case 'admin/settings/modules#description':
 247        return t('Creates a block that allows your users to resize text on the page.');
 248    }
 249  }


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