t('YUI editor settings'), 'page callback' => 'yui_editor_profile_list', 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'description' => t("View/Modify YUI editor settings"), ); $items['admin/settings/yui_editor/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items['admin/settings/yui_editor/add'] = array( 'title' => 'Add profile', 'page callback' => 'drupal_get_form', 'page arguments' => array('yui_editor_profile'), 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, 'weight' => 1, ); $items['admin/settings/yui_editor/edit/%'] = array( 'title' => 'Edit profile', 'page callback' => 'drupal_get_form', 'page arguments' => array('yui_editor_profile'), 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, ); $items['admin/settings/yui_editor/delete/%/%'] = array( 'title' => 'Delete profile', 'page callback' => 'yui_editor_profile_delete', 'page arguments' => array(4, 5), 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, ); _yui_editor_plugin('menu', $items, $items); return $items; } /* * Implementation of hook_init(). */ function yui_editor_init() { if (!user_access('Access YUI editor')) { return; } global $user; $path = drupal_get_path_alias($_GET['q']); $profiles = variable_get('yui_editor_profiles', array()); $role_pass = false; foreach($profiles as $priority => $list) { foreach ($list as $pid => $profile) { $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($profile['include'], '/')) .')$/'; foreach ($user->roles as $rid => $name) { if ($profile['roles'][$rid] == $rid) { $role_pass = true; break; } } if ((empty($profile['include']) or preg_match($regexp, $path)) and $role_pass) { yui_render_editor($profile); break 2; } } } } /* * Implementation of hook_perm(). */ function yui_editor_perm() { $array = array('Access YUI editor'); return $array; } /* * The profile list page. */ function yui_editor_profile_list() { $header = array('Priority', 'Name', 'Roles', 'Action'); $rows = array(); $profiles = variable_get('yui_editor_profiles', array()); $roles = user_roles(); foreach($profiles as $priority => $list) { foreach($list as $pid => $profile) { $user_roles = ''; foreach ($profile['roles'] as $rid => $status) { if ($status == $rid) { $user_roles .= $roles[$rid]; } } $rows[] = array($priority, $profile['name'], $user_roles, l('Edit', 'admin/settings/yui_editor/edit/' . $pid) . ' | ' . l('Delete', 'admin/settings/yui_editor/delete/' . $priority . '/' . $pid)); } } return theme_table($header, $rows); } /* * Delete profile. */ function yui_editor_profile_delete($priority, $pid) { $profiles = variable_get('yui_editor_profiles', array()); unset($profiles[$priority][$pid]); variable_set('yui_editor_profiles', $profiles); drupal_set_message(t('Profile deleted')); drupal_goto('admin/settings/yui_editor'); } /* * Return a default profile configuration. */ function yui_editor_profile_default() { return array( 'name' => 'Default', 'weight' => 10, 'roles' => array(2 => 2), 'include' => '', 'ids' => '', 'title' => '', 'titlebar' => 0, 'height' => '250px', 'width' => '100%', 'markup' => 'xhtml', 'resize' => 0, 'plaintext' => 0, 'coder' => 0, 'collapse' => 0, 'draggable' => 0, 'dom' => 1, 'img_upload' => 0, 'flickr' => 0, 'flickr_api_key' => '', 'button_type' => 'simple', 'button_profile' => 'yui_editor_toolbar_default.js'); } /* * The profile add/edit page. */ function yui_editor_profile() { if (arg(3) == 'edit' and arg(4)) { $profiles = variable_get('yui_editor_profiles', array()); foreach ($profiles as $priority => $list) { foreach ($list as $pid => $profile) { if ($pid == arg(4)) { $form['old_weight'] = array( '#type' => 'hidden', '#value' => $profile['weight']); $form['id'] = array( '#type' => 'hidden', '#value' => arg(4)); break 2; } } } } if ($profile == null) { $profile = yui_editor_profile_default(); $profile['name'] = ''; } $form['name'] = array( '#type' => 'textfield', '#title' => t('Profile name'), '#required' => TRUE, '#default_value' => $profile['name'], '#description' => t('The name you want to give this profile')); $form['display'] = array( '#type' => 'fieldset', '#title' => t('Profile priority and configuration'), '#description' => t('Limit where the editor shows up based on role, path, and ID. NOTE: Only ONE profile will be applied per page. If the user has access to the YUI Editor, then the module looks at each profile in order based on the priority. For each profile it compares the user roles and the page path against the profile roles and paths. IDs are NOT used when selecting which profile to apply to a given page, but IDs are useful for specifying which textareas should be applied if the profile is a match (otherwise, it will just place the YUI Editor on the body field -- edit-body).'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['display']['weight'] = array( '#type' => 'weight', '#title' => 'Priority', '#default_value' => $profile['weight'], '#description' => t('Priority of this profile in relation to the others (i.e. the weight of this profile)')); $form['display']['roles'] = array( '#type' => 'checkboxes', '#title' => 'Roles', '#default_value' => $profile['roles'], '#options' => user_roles(), '#description' => t('Define which roles YUI should apply this profile. Note: A user only needs to be in one of the roles for this to apply.')); $form['display']['include'] = array( '#type' => 'textarea', '#title' => t('Paths'), '#default_value' => $profile['include'], '#description' => t('Define where should YUI replace the body textarea, each path on a new line. You can use wildcards (*). (Leave blank for every form)'), '#rows' => 5, '#cols' => 60); $form['display']['ids'] = array( '#type' => 'textarea', '#title' => t('IDs'), '#default_value' => $profile['ids'], '#description' => t('Define which textareas do you want the editor to replace, write the ID of each textarea on a seperate line. (if empty the editor will only replace the body textarea)'), '#rows' => 5, '#cols' => 20); $form['basic'] = array( '#type' => 'fieldset', '#title' => t('Basic editor settings'), '#description' => t('Basic settings for the editor displayed using this profile'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['basic']['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $profile['title'], '#description' => t('The title to give the editor')); $form['basic']['titlebar'] = array( '#type' => 'checkbox', '#title' => t('Show titlebar'), '#default_value' => $profile['titlebar'], '#description' => t('Toggle the YUI editor titlebar')); $form['basic']['height'] = array( '#type' => 'textfield', '#title' => t('Height'), '#default_value' => $profile['height'], '#description' => t('The height of the editor (i.e. 250px)')); $form['basic']['width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => $profile['width'], '#description' => t('The width of the editor (i.e. 100%)')); $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced editor settings'), '#description' => t('Advanced settings for the editor displayed using this profile'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['advanced']['markup'] = array( '#type' => 'textfield', '#title' => t('Markup'), '#default_value' => $profile['markup'], '#description' => t('Set the YUI editor markup')); $form['advanced']['collapse'] = array( '#type' => 'checkbox', '#title' => t('Collapsible titlebar'), '#default_value' => $profile['collapse'], '#description' => t('Allow user to collapse the titlebar')); $form['advanced']['draggable'] = array( '#type' => 'checkbox', '#title' => t('Draggable titlebar'), '#default_value' => $profile['draggable'], '#description' => t('Allow user to drag the titlebar')); $form['advanced']['dom'] = array( '#type' => 'checkbox', '#default_value' => $profile['dom'], '#title' => t('Show DOM'), '#description' => t('Toggle the YUI editor DOM display (at the bottom of the editor)')); $form['plugins'] = array( '#type' => 'fieldset', '#title' => t('Plugins'), '#description' => t('Plugins to apply/enable for editors using this profile'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['buttns'] = array( '#type' => 'fieldset', '#title' => t('Buttons'), '#description' => t('Configure which buttons are applied/enabled for this profile'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['buttns']['button_type'] = array( '#type' => 'select', '#title' => t('Button type'), '#default_value' => $profile['button_type'], '#options' => array('simple' => 'Simple', 'advanced' => 'Advanced'), '#description' => t('Select the appropriate button profile')); $form['buttns']['button_profile'] = array( '#type' => 'select', '#title' => t('Button profile'), '#default_value' => $profile['button_profile'], '#options' => array('yui_editor_toolbar_default.js' => 'Default', 'yui_editor_toolbar_no_style.js' => 'No Style Tags', '1' => 'Custom'), '#description' => t('Select the appropriate button profile. If you choose "Custom", then you will be able to build your own toolbar below.')); $form['buttns']['_custom_html'] = array( '#type' => 'hidden', '#default_value' => ''); $form['buttns']['custom'] = array( '#prefix' => ($profile['button_profile'] == 1 ? '
' . $profile['_custom_html'] . '
' : ' '), '#type' => 'hidden'); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save profile')); _yui_editor_plugin('settings', $form, $profile); drupal_add_js(drupal_get_path("module", "yui_editor")."/yui_editor_admin.js"); return $form; } function yui_editor_profile_submit($form, &$form_state) { $profiles = variable_get('yui_editor_profiles', array()); if (isset($form_state['values']['id'])) { drupal_set_message(t('The profile has been updated')); unset($profiles[$form_state['values']['old_weight']][$form_state['values']['id']]); } else { drupal_set_message(t('The profile has been created')); } $form_state['values']['form_token'] = time(); $profiles[$form_state['values']['weight']][$form_state['values']['form_token']] = $form_state['values']; ksort($profiles); ksort($profiles[$form_state['values']['weight']]); variable_set('yui_editor_profiles', $profiles); drupal_goto('admin/settings/yui_editor'); } /* * Add the javascript/CSS needed to render the editor */ function yui_render_editor($profile) { _yui_editor_plugin('render', $profile, $profile); $yui_source = variable_get('yui_source','http://yui.yahooapis.com/2.5.1'); yui_add_css('editor', $yui_source, '/build/menu/assets/skins/sam/menu.css'); yui_add_css('editor', $yui_source, '/build/button/assets/skins/sam/button.css'); yui_add_css('editor', $yui_source, '/build/fonts/fonts-min.css'); yui_add_css('editor', $yui_source, '/build/container/assets/skins/sam/container.css'); yui_add_css('editor', $yui_source, '/build/autocomplete/assets/skins/sam/autocomplete.css'); yui_add_css('editor', $yui_source, '/build/editor/assets/skins/sam/editor.css'); yui_add_css('editor', $yui_source, '/build/resize/assets/skins/sam/resize.css'); yui_add_js('editor', $yui_source, '/build/yahoo-dom-event/yahoo-dom-event.js'); yui_add_js('editor', $yui_source, '/build/utilities/utilities.js'); yui_add_js('editor', $yui_source, '/build/dragdrop/dragdrop-min.js'); yui_add_js('editor', $yui_source, '/build/animation/animation-min.js'); yui_add_js('editor', $yui_source, '/build/element/element-beta-min.js'); yui_add_js('editor', $yui_source, '/build/container/container-min.js'); yui_add_js('editor', $yui_source, '/build/menu/menu-min.js'); yui_add_js('editor', $yui_source, '/build/button/button-min.js'); yui_add_js('editor', $yui_source, '/build/resize/resize-beta-min.js'); yui_add_js('editor', $yui_source, '/build/autocomplete/autocomplete-min.js'); yui_add_js('editor', $yui_source, '/build/editor/editor-beta-min.js'); drupal_add_css(drupal_get_path("module", "yui_editor")."/yui_editor.css"); drupal_add_js(drupal_get_path("module", "yui_editor")."/yui_editor.js"); if ($profile['button_profile'] != 1) { drupal_add_js(drupal_get_path("module", "yui_editor")."/toolbars/".$profile['button_profile']); } else { $toolbar = "function yui_editor_toolbar() { this.toolbar = { titlebar: '', collapse: true, draggable: false, buttonType: 'advanced', buttons: [" . $profile['custom'] . "] }; }"; drupal_add_js($toolbar, 'inline', 'footer'); } $ids = $profile['ids']; $textareas = array(); if (!empty($ids)) { $textareas = explode("\r\n", $ids); } else { $textareas[] = 'edit-body'; } $settings = ''; unset($profile['custom']); unset($profile['_custom_html']); foreach ($profile as $s => $v) { $settings .= "$s: '$v', "; } foreach($textareas as $id) { drupal_add_js("YAHOO.Drupal.editors.push(new YAHOO.Drupal.yui_editor('$id', { $settings base_path: '".base_path()."'"."}));", 'inline', 'footer'); } drupal_add_js('YAHOO.Drupal.yui_editor_load.fire();', 'inline', 'footer'); } function _yui_editor_plugin($op, &$d1, &$d2) { static $plugins; if ($plugins == null) { $d = dir(drupal_get_path("module", "yui_editor")."/plugins"); while (false !== ($entry = $d->read())) { if ($entry != '.' and $entry != '..' and preg_match('/\.inc$/', $entry)) { require_once(drupal_get_path("module", "yui_editor")."/plugins/".$entry); $plugins[] = preg_replace('/\.inc$/', '', $entry); } } $d->close(); } foreach ($plugins as $plugin) { if (function_exists("yui_editor_${plugin}_$op")) { call_user_func_array("yui_editor_${plugin}_$op", array(&$d1, &$d2)); } } }