[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/fckeditor/ -> fckeditor.user.inc (source)

   1  <?php
   2  // $Id: fckeditor.user.inc,v 1.1.2.17 2009/10/24 09:48:27 jorrit Exp $
   3  /**
   4   * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   5   * Copyright (C) 2003-2008 Frederico Caldeira Knabben
   6   *
   7   * == BEGIN LICENSE ==
   8   *
   9   * Licensed under the terms of any of the following licenses at your
  10   * choice:
  11   *
  12   *  - GNU General Public License Version 2 or later (the "GPL")
  13   *    http://www.gnu.org/licenses/gpl.html
  14   *
  15   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  16   *    http://www.gnu.org/licenses/lgpl.html
  17   *
  18   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  19   *    http://www.mozilla.org/MPL/MPL-1.1.html
  20   *
  21   * == END LICENSE ==
  22   *
  23   * @file
  24   * FCKeditor Module for Drupal 6.x
  25   *
  26   * This module allows Drupal to replace textarea fields with FCKeditor.
  27   *
  28   * This HTML text editor brings to the web many of the powerful functionalities
  29   * of known desktop editors like Word. It's really  lightweight and doesn't
  30   * require any kind of installation on the client computer.
  31   */
  32  
  33  function fckeditor_user_delegate($type, $edit, &$user, $category = NULL) {
  34    if ($type == 'form' && $category == 'account' && user_access('access fckeditor')) {
  35      module_load_include('lib.inc', 'fckeditor');
  36  
  37      $profile = fckeditor_user_get_profile($user);
  38      $toolbar_options = fckeditor_load_toolbar_options();
  39      $skin_options = fckeditor_load_skin_options();
  40      $lang_options = fckeditor_load_lang_options();
  41  
  42      // because the settings are saved as strings we need to test for the string 'true'
  43      if ($profile->settings['allow_user_conf'] == 't') {
  44        $form['fckeditor'] = array(
  45          '#type' => 'fieldset',
  46          '#title' => t('Rich text editor settings'),
  47          '#weight' => 10,
  48          '#collapsible' => TRUE,
  49          '#collapsed' => TRUE
  50        );
  51  
  52        $form['fckeditor']['fckeditor_default'] = array(
  53          '#type' => 'radios',
  54          '#title' => t('Default state'),
  55          '#default_value' => isset($user->fckeditor_default) ? $user->fckeditor_default : (isset($profile->settings['default']) ? $profile->settings['default'] : 'f'),
  56          '#options' => array(
  57            't' => t('Enabled'),
  58            'f' => t('Disabled')
  59          ),
  60          '#description' => t('Should rich-text editing be enabled or disabled by default in textarea fields? If disabled, rich text editor may still be enabled using toggle or popup window.'),
  61        );
  62  
  63        $form['fckeditor']['fckeditor_show_toggle'] = array(
  64          '#type' => 'radios',
  65          '#title' => t('Show disable/enable rich text editor toggle'),
  66          '#default_value' => isset($user->fckeditor_show_toggle) ? $user->fckeditor_show_toggle : (isset($profile->settings['show_toggle']) ? $profile->settings['show_toggle'] : 't'),
  67          '#options' => array(
  68            't' => t('Yes'),
  69            'f' => t('No')
  70          ),
  71          '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. Works only if FCKeditor is not running in a popup window (see below).'),
  72        );
  73  
  74        if (user_access('administer fckeditor')) {
  75          $form['fckeditor']['fckeditor_show_fieldnamehint'] = array(
  76            '#type' => 'radios',
  77            '#title' => t('Show field name hint below each rich text editor'),
  78            '#default_value' => !empty($user->fckeditor_show_fieldnamehint) ? $user->fckeditor_show_fieldnamehint : 't',
  79            '#options' => array(
  80              't' => t('Yes'),
  81              'f' => t('No')
  82            ),
  83          );
  84        }
  85  
  86        $form['fckeditor']['fckeditor_popup'] = array(
  87          '#type' => 'radios',
  88          '#title' => t('Use FCKeditor in a popup window'),
  89          '#default_value' => isset($user->fckeditor_popup) ? $user->fckeditor_popup : (isset($profile->settings['popup']) ? $profile->settings['popup'] : 'f'),
  90          '#options' => array(
  91            'f' => t('No'),
  92            't' => t('Yes')
  93          ),
  94          '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'),
  95        );
  96  
  97        $form['fckeditor']['fckeditor_skin'] = array(
  98          '#type' => 'select',
  99          '#title' => t('Skin'),
 100          '#default_value' => isset($user->fckeditor_skin) ? $user->fckeditor_skin : (isset($profile->settings['skin']) ? $profile->settings['skin'] : 'default'),
 101          '#options' => $skin_options,
 102          '#description' => t('Choose a FCKeditor skin.'),
 103        );
 104  
 105        $form['fckeditor']['fckeditor_toolbar'] = array(
 106          '#type' => 'select',
 107          '#title' => t('Toolbar'),
 108          '#default_value' => isset($user->fckeditor_toolbar) ? $user->fckeditor_toolbar : (isset($profile->settings['toolbar']) ? $profile->settings['toolbar'] : 'default'),
 109          '#options' => $toolbar_options,
 110          '#description' => t('Choose a FCKeditor toolbar set.'),
 111        );
 112  
 113        $form['fckeditor']['fckeditor_expand'] = array(
 114          '#type' => 'select',
 115          '#title' => t('Start the toolbar expanded'),
 116          '#default_value' => isset($user->fckeditor_expand) ? $user->fckeditor_expand : (isset($profile->settings['expand']) ? $profile->settings['expand'] : 't'),
 117          '#options' => array(
 118            't' => t('Expanded'),
 119            'f' => t('Collapsed')
 120          ),
 121          '#description' => t('The toolbar start expanded or collapsed.'),
 122        );
 123  
 124        $form['fckeditor']['fckeditor_width'] = array(
 125          '#type' => 'textfield',
 126          '#title' => t('Width'),
 127          '#default_value' => isset($user->fckeditor_width) ? $user->fckeditor_width : (isset($profile->settings['width']) ? $profile->settings['width'] : '100%'),
 128          '#description' => t('Width in pixels or percent.') .' '. t('Example') .': 400 '. t('or') .' 100%.',
 129          '#size' => 40,
 130          '#maxlength' => 128,
 131        );
 132  
 133        $form['fckeditor']['fckeditor_lang'] = array(
 134          '#type' => 'select',
 135          '#title' => t('Language'),
 136          '#default_value' => isset($user->fckeditor_lang) ? $user->fckeditor_lang : (isset($profile->settings['lang']) ? $profile->settings['lang'] : 'en'),
 137          '#options' => $lang_options,
 138          '#description' => t('The language for the FCKeditor interface.')
 139        );
 140  
 141        $form['fckeditor']['fckeditor_auto_lang'] = array(
 142          '#type' => 'radios',
 143          '#title' => t('Auto-detect language'),
 144          '#default_value' => isset($user->fckeditor_auto_lang) ? $user->fckeditor_auto_lang : (isset($profile->settings['auto_lang']) ? $profile->settings['auto_lang'] : 't'),
 145          '#options' => array(
 146            't' => t('Yes'),
 147            'f' => t('No')
 148          ),
 149          '#description' => t('Use auto detect user language feature.')
 150        );
 151  
 152        return array('fckeditor' => $form);
 153      }
 154    }
 155  
 156    if ($type == 'validate') {
 157      if (isset($edit['fckeditor_default'], $edit['fckeditor_popup']) && $edit['fckeditor_default'] == 't' && $edit['fckeditor_popup'] == 't') {
 158        form_set_error('fckeditor_popup', t('If FCKeditor is enabled by default, popup window must be disabled.'));
 159      }
 160  
 161      if (isset($edit['fckeditor_show_toggle'], $edit['fckeditor_popup']) && $edit['fckeditor_show_toggle'] == 't' && $edit['fckeditor_popup'] == 't') {
 162        form_set_error('fckeditor_popup', t('If toggle is enabled, popup window must be disabled.'));
 163      }
 164  
 165      if (isset($edit['fckeditor_width']) && !preg_match('/^\d+%?$/', $edit['fckeditor_width'])) {
 166        form_set_error('width', t('Enter valid width.') .' '. t('Example') .': 400 '. t('or') .' 100%.');
 167      }
 168    }
 169  
 170    return NULL;
 171  }
 172  
 173  /**
 174   * This function wraps img_assist_loader
 175   */
 176  function fckeditor_wrapper_img_assist_loader() {
 177    if (module_exists('img_assist')) {
 178      $fckpath = drupal_get_path('module', 'fckeditor');
 179      $fckjs = $fckpath . '/img_assist_fckeditor.js';
 180      $iapath = drupal_get_path('module', 'img_assist');
 181  
 182      // find the version of img_assist by looking at the CVS Id version
 183      $cvsversion = -1;
 184      $iafp = fopen($iapath . '/img_assist.module', 'r');
 185      $cvsidlines = fread($iafp, 100); // the cvs version is probably in the first 100 bytes
 186      fclose($iafp);
 187      $matches = array();
 188      if (preg_match('# \d+\.(\d+)[\d\.]* #', $cvsidlines, $matches)) {
 189        $cvsversion = (int) $matches[1];
 190      }
 191      
 192      switch ($cvsversion) {
 193        case 75: // this branch is the branch for 6.x-2.x of img_assist
 194          // add img_assist js files before our own file to 
 195          drupal_add_js($iapath . '/img_assist_popup.js');
 196          drupal_add_js($iapath . '/img_assist_textarea.js');
 197          drupal_add_js($fckjs);
 198          img_assist_loader();
 199          break;
 200        
 201        case 72: // this branch is the branch for 6.x-1.x of img_assist
 202          ob_start();
 203          img_assist_loader();
 204          $text = ob_get_clean();
 205          
 206          $search = '<script type="text/javascript" src="'. base_path() . $iapath .'/img_assist_fckeditor.js"></script>';
 207          $new = '<script type="text/javascript" src="'. base_path() . $iapath .'/img_assist_textarea.js"></script>'."\n".
 208          '<script type="text/javascript" src="'. base_path() . $fckjs .'"></script>';
 209          
 210          if (strpos($text, $search) !== FALSE) {
 211            $text = str_replace($search, $new, $text);
 212            
 213            echo $text;
 214            break;
 215          }
 216          else {
 217            drupal_set_message(t('Image Assist output was not recognized'), 'error');
 218            return '';
 219          }
 220        
 221        default:
 222          drupal_set_message(t('This Image Assist version is not supported'), 'error');
 223          return '';
 224      }
 225    }
 226    else {
 227      drupal_not_found();
 228    }
 229  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7