home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (whizzywig.inc)

This example Drupal source code file (whizzywig.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, base, base_path, buttons, directory, editor, file, function, if, path, php, return, script, theme

The whizzywig.inc Drupal example source code

<?php
// $Id: whizzywig.inc,v 1.8 2010/11/13 18:31:21 sun Exp $

/**
 * @file
 * Editor integration functions for Whizzywig.
 */

/**
 * Plugin implementation of hook_editor().
 */
function wysiwyg_whizzywig_editor() {
  $editor['whizzywig'] = array(
    'title' => 'Whizzywig',
    'vendor url' => 'http://www.unverse.net',
    'download url' => 'http://www.unverse.net/whizzywig-download.html',
    'libraries' => array(
      '' => array(
        'title' => 'Default',
        'files' => array('whizzywig.js', 'xhtml.js'),
      ),
    ),
    'version callback' => 'wysiwyg_whizzywig_version',
    'settings callback' => 'wysiwyg_whizzywig_settings',
    'plugin callback' => 'wysiwyg_whizzywig_plugins',
    'versions' => array(
      '55' => array(
        'js files' => array('whizzywig.js'),
      ),
      '56' => array(
        'js files' => array('whizzywig-56.js'),
      ),
      '60' => array(
        'js files' => array('whizzywig-60.js'),
      ),
    ),
  );
  return $editor;
}

/**
 * Detect editor version.
 *
 * @param $editor
 *   An array containing editor properties as returned from hook_editor().
 *
 * @return
 *   The installed editor version.
 */
function wysiwyg_whizzywig_version($editor) {
  $script = $editor['library path'] . '/whizzywig.js';
  if (!file_exists($script)) {
    return;
  }
  $script = fopen($script, 'r');
  $line = fgets($script, 43);
  // 55: Whizzywig v55i
  // 60: Whizzywig 60
  if (preg_match('@Whizzywig v?([0-9]+)@', $line, $version)) {
    fclose($script);
    return $version[1];
  }
  fclose($script);
}

/**
 * Return runtime editor settings for a given wysiwyg profile.
 *
 * @param $editor
 *   A processed hook_editor() array of editor properties.
 * @param $config
 *   An array containing wysiwyg editor profile settings.
 * @param $theme
 *   The name of a theme/GUI/skin to use.
 *
 * @return
 *   A settings array to be populated in
 *   Drupal.settings.wysiwyg.configs.{editor}
 */
function wysiwyg_whizzywig_settings($editor, $config, $theme) {
  $settings = array();

  // Add path to button images, if available.
  if (is_dir($editor['library path'] . '/btn')) {
    $settings['buttonPath'] = base_path() . $editor['library path'] . '/btn/';
  }
  if (file_exists($editor['library path'] . '/WhizzywigToolbar.png')) {
    $settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/WhizzywigToolbar.png';
  }
  // Filename changed in version 60.
  elseif (file_exists($editor['library path'] . '/icons.png')) {
    $settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/icons.png';
  }

  // Add configured buttons or all available.
  $settings['buttons'] = array();
  if (!empty($config['buttons'])) {
    $buttons = array();
    foreach ($config['buttons'] as $plugin) {
      $buttons = array_merge($buttons, $plugin);
    }
    $settings['buttons'] = implode(' ', array_keys($buttons));
  }

  // Add editor content stylesheet.
  if (isset($config['css_setting'])) {
    if ($config['css_setting'] == 'theme') {
      $css = path_to_theme() . '/style.css';
      if (file_exists($css)) {
        $settings['externalCSS'] = base_path() . $css;
      }
    }
    else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
      $settings['externalCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
    }
  }

  return $settings;
}

/**
 * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
 */
function wysiwyg_whizzywig_plugins($editor) {
  return array(
    'default' => array(
      'buttons' => array(
        'formatblock' => t('HTML block format'), 'fontname' => t('Font'), 'fontsize' => t('Font size'),
        'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
        'left' => t('Align left'), 'center' => t('Align center'), 'right' => t('Align right'),
        'bullet' => t('Bullet list'), 'number' => t('Numbered list'),
        'outdent' => t('Outdent'), 'indent' => t('Indent'),
        'undo' => t('Undo'), 'redo' => t('Redo'),
        'image' => t('Image'),
        'color' => t('Forecolor'), 'hilite' => t('Backcolor'),
        'rule' => t('Horizontal rule'),
        'link' => t('Link'),
        'image' => t('Image'),
        'table' => t('Table'),
        'clean' => t('Clean-up'),
        'html' => t('Source code'),
        'spellcheck' => t('Spell check'),
      ),
      'internal' => TRUE,
    ),
  );
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal whizzywig.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.