[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

   1  <?php
   2  // $Id: yui_editor.module,v 1.5.2.17.2.9 2008/11/21 23:05:28 jeffcd Exp $
   3  
   4  /**
   5   * @file
   6   * Replace textareas with the YUI rich text editor.
   7   */
   8  
   9  /**
  10   * Implementation of hook_menu().
  11   */
  12  function yui_editor_menu() {
  13    $items['admin/settings/yui_editor'] = array(
  14      'title' => t('YUI editor settings'),
  15      'page callback' => 'yui_editor_profile_list',
  16      'access callback' => 'user_access',
  17      'access arguments' => array('administer site configuration'),
  18      'description' => t('View/modify YUI editor settings'),
  19      'file' => 'yui_editor.admin.inc',
  20    );
  21    $items['admin/settings/yui_editor/list'] = array(
  22      'title' => 'List',
  23      'file' => 'yui_editor.admin.inc',
  24      'type' => MENU_DEFAULT_LOCAL_TASK,
  25    );
  26    $items['admin/settings/yui_editor/add'] = array(
  27      'title' => 'Add profile',
  28      'page callback' => 'drupal_get_form',
  29      'page arguments' => array('yui_editor_profile'),
  30      'access arguments' => array('administer site configuration'),
  31      'file' => 'yui_editor.admin.inc',
  32      'type' => MENU_LOCAL_TASK,
  33      'weight' => 1,
  34    );
  35    $items['admin/settings/yui_editor/edit/%'] = array(
  36      'title' => 'Edit profile',
  37      'page callback' => 'drupal_get_form',
  38      'page arguments' => array('yui_editor_profile'),
  39      'access arguments' => array('administer site configuration'),
  40      'file' => 'yui_editor.admin.inc',
  41      'type' => MENU_CALLBACK,
  42    );
  43    $items['admin/settings/yui_editor/delete/%/%'] = array(
  44      'title' => 'Delete profile',
  45      'page callback' => 'yui_editor_profile_delete',
  46      'page arguments' => array(4, 5),
  47      'access arguments' => array('administer site configuration'),
  48      'file' => 'yui_editor.admin.inc',
  49      'type' => MENU_CALLBACK,
  50    );
  51  
  52    _yui_editor_plugin('menu', $items, $items);
  53  
  54    return $items;
  55  }
  56  
  57  /**
  58   * implementation of hook_perm().
  59   */
  60  function yui_editor_perm() {
  61    return array('access yui editor');
  62  }
  63  
  64  /**
  65   * Implementation of hook_init().
  66   */
  67  function yui_editor_init() {
  68    if (!user_access('access yui editor')) {
  69      return;
  70    }
  71  
  72    global $user;
  73    $path = drupal_get_path_alias($_GET['q']);
  74    $profiles = variable_get('yui_editor_profiles', array());
  75    $role_pass = FALSE;
  76  
  77    foreach ($profiles as $priority => $list) {
  78      foreach ($list as $pid => $profile) {
  79        $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($profile['include'], '/')) .')$/';
  80  
  81        foreach ($user->roles as $rid => $name) {
  82          if ($profile['roles'][$rid] == $rid) {
  83            $role_pass = TRUE;
  84            break;
  85          }
  86        }
  87        if ((empty($profile['include']) or preg_match($regexp, $path)) and $role_pass) {
  88          if (!empty($profile['type'])) {
  89  
  90            // This profile specifies a list of content-types to match
  91  
  92            $matches = array();
  93            if (preg_match('/^(node\/add\/(.*)|node\/(\d*)\/edit)$/',$path,$matches)) {
  94  
  95              // Only check against node/add/* and node/*/edit pages
  96  
  97              if (!empty($matches[2])) {
  98                // For node/add/* pages, the content-type is in the path
  99                $type = $matches[2];
 100              }
 101              elseif (!empty($matches[3])) {
 102                // For node/*/edit pages, the nid is in the path
 103                $type = db_result(db_query('select type from {node} where nid=%d',$matches[3]));
 104              }
 105              else {
 106                // Shouldn't get here...
 107                watchdog('error','Something is wrong with the content-type patch to yui_editor_init()');
 108                continue;
 109              }
 110              if (!in_array($type,preg_split('/[\r\n]+/',$profile['type']))) {
 111                //                       If the type of the current page isn't in the list, try the next profile.
 112                continue;
 113              }
 114            }
 115          }
 116          $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($profile['type'], '/')) .')$/';
 117          unset($profile['include']);
 118          unset($profile['type']);
 119          yui_render_editor($profile);
 120          break 2;
 121        }
 122      }
 123    }
 124  }
 125  
 126  /**
 127   * Add the javascript/CSS needed to render the editor
 128   */
 129  function yui_render_editor($profile) {
 130    _yui_editor_plugin('render', $profile, $profile);
 131  
 132    yui_editor_load_libs();
 133    drupal_add_css(drupal_get_path('module', 'yui_editor') .'/yui_editor.css');
 134    drupal_add_js(drupal_get_path('module', 'yui_editor') .'/yui_editor.js');
 135  
 136    if ($profile['button_profile'] != 1) {
 137      drupal_add_js(drupal_get_path('module', 'yui_editor') .'/toolbars/'. $profile['button_profile']);
 138    }
 139    else {
 140      $toolbar = "function yui_editor_toolbar() { this.toolbar = { titlebar: '', collapse: true, draggable: false, buttonType: 'advanced', buttons: [". $profile['custom'] ."] }; }";
 141      drupal_add_js($toolbar, 'inline', 'footer');
 142    }
 143  
 144    $ids = $profile['ids'];
 145    $ids = str_replace(array("\r\n", "\n\r", "\r"), "\n", $ids);
 146  
 147    $textareas = array();
 148    if (!empty($ids)) {
 149      $textareas = explode("\n", $ids);
 150    }
 151    else {
 152      $textareas[] = 'edit-body';
 153    }
 154  
 155    $settings = '';
 156    unset($profile['custom']);
 157    unset($profile['_custom_html']);
 158    $profile['base_path'] = base_path();
 159    $settings = drupal_to_js($profile);
 160    $editors = '';
 161    foreach ($textareas as $id) {
 162      $editors .= "YAHOO.Drupal.editors.push(new YAHOO.Drupal.yui_editor('$id', $settings));\n";
 163    }
 164  
 165    drupal_add_js("YAHOO.util.Event.onDOMReady(function () { $editors YAHOO.Drupal.yui_editor_load.fire();\n });", 'inline', 'footer');
 166  }
 167  
 168  function yui_editor_load_libs() {
 169    // TODO: only load CSS/JS based on the settings...
 170    $yui_source = variable_get('yui_source', 'http://yui.yahooapis.com/2.6.0');
 171    yui_add_css('editor', $yui_source, '/build/menu/assets/skins/sam/menu.css');
 172    yui_add_css('editor', $yui_source, '/build/button/assets/skins/sam/button.css');
 173    yui_add_css('editor', $yui_source, '/build/fonts/fonts-min.css');
 174    yui_add_css('editor', $yui_source, '/build/container/assets/skins/sam/container.css');
 175    yui_add_css('editor', $yui_source, '/build/autocomplete/assets/skins/sam/autocomplete.css');
 176    yui_add_css('editor', $yui_source, '/build/editor/assets/skins/sam/editor.css');
 177    yui_add_css('editor', $yui_source, '/build/resize/assets/skins/sam/resize.css');
 178    yui_add_js('editor', $yui_source, '/build/yahoo-dom-event/yahoo-dom-event.js');
 179    yui_add_js('editor', $yui_source, '/build/utilities/utilities.js');
 180    yui_add_js('editor', $yui_source, '/build/dragdrop/dragdrop-min.js');
 181    yui_add_js('editor', $yui_source, '/build/animation/animation-min.js');
 182    if (preg_match('/2.6.[0-9]$/iU', $yui_source)) {
 183      yui_add_js('editor', $yui_source, '/build/element/element-min.js');
 184    }
 185    else {
 186      yui_add_js('editor', $yui_source, '/build/element/element-beta-min.js');
 187    }
 188    yui_add_js('editor', $yui_source, '/build/container/container-min.js');
 189    yui_add_js('editor', $yui_source, '/build/menu/menu-min.js');
 190    yui_add_js('editor', $yui_source, '/build/button/button-min.js');
 191    if (preg_match('/2.6.[0-9]$/iU', $yui_source)) {
 192      yui_add_js('editor', $yui_source, '/build/resize/resize-min.js');
 193      yui_add_js('editor', $yui_source, '/build/datasource/datasource-min.js');
 194      yui_add_js('editor', $yui_source, '/build/autocomplete/autocomplete-min.js');
 195      yui_add_js('editor', $yui_source, '/build/editor/editor-min.js');
 196    }
 197    else {
 198      yui_add_js('editor', $yui_source, '/build/resize/resize-beta-min.js');
 199      yui_add_js('editor', $yui_source, '/build/autocomplete/autocomplete-min.js');
 200      yui_add_js('editor', $yui_source, '/build/editor/editor-beta-min.js');
 201    }
 202  }
 203  
 204  function _yui_editor_plugin($op, &$d1, &$d2) {
 205    static $plugins;
 206  
 207    if ($plugins == NULL) {
 208      $d = dir(drupal_get_path('module', 'yui_editor') .'/plugins');
 209      while (false !== ($entry = $d->read())) {
 210        if ($entry != '.' && $entry != '..' && preg_match('/\.inc$/', $entry)) {
 211          require_once(drupal_get_path('module', 'yui_editor') .'/plugins/'. $entry);
 212          $plugins[] = preg_replace('/\.inc$/', '', $entry);
 213        }
 214      }
 215      $d->close();
 216    }
 217  
 218    foreach ($plugins as $plugin) {
 219      if (function_exists("yui_editor_$plugin}_$op")) {
 220        call_user_func_array("yui_editor_$plugin}_$op", array(&$d1, &$d2));
 221      }
 222    }
 223  }


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