Commit 68344d70 authored by sun's avatar sun

#268838 by sun: Ported to Drupal 6.x.

parent addb35d1
......@@ -6,6 +6,7 @@ Wysiwyg x.x-x.x, xxxx-xx-xx
Wysiwyg 6.x-0.x, xxxx-xx-xx
---------------------------
#268838 by sun: Ported to Drupal 6.x.
#152046 by sun: Added hook_wysiwyg_plugin().
#268562 by sun: Code clean-up.
#60667 by sun: Fixed wrong editor profile is loaded when user is granted access
......
......@@ -8,18 +8,22 @@
*/
/**
* Controller for Wysiwyg Editor administrative settings.
* Callback handler for admin pages; menu callback.
*
* @todo Move into hook_menu(), resp. FAPI functions.
*/
function _wysiwyg_editor_admin($op = NULL) {
function wysiwyg_editor_admin($arg = '') {
$edit = $_POST;
$op = isset($_POST['op']) ? $_POST['op'] : '';
$op = ($arg && !$op ? $arg : $op);
switch ($op) {
case 'add':
$breadcrumb[] = array('path' => 'admin', 'title' => t('administer'));
$breadcrumb[] = array('path' => 'admin/settings/wysiwyg/profile', 'title' => t('Wysiwyg Editor'));
$breadcrumb[] = array('path' => 'admin/settings/wysiwyg/profile/add', 'title' => t('Add new Wysiwyg Editor profile'));
menu_set_location($breadcrumb);
$breadcrumb[] = l(t('Home'), NULL);
$breadcrumb[] = l(t('Administer'), 'admin');
$breadcrumb[] = l(t('Site configuration'), 'admin/settings');
$breadcrumb[] = l(t('Wysiwyg'), 'admin/settings/wysiwyg');
$breadcrumb[] = l(t('Wysiwyg Profiles'), 'admin/settings/wysiwyg/profile');
drupal_set_breadcrumb($breadcrumb);
$output = drupal_get_form('wysiwyg_editor_profile_form', $edit);
break;
......@@ -49,7 +53,7 @@ function _wysiwyg_editor_admin($op = NULL) {
/**
* Return an HTML form for profile configuration.
*/
function wysiwyg_editor_profile_form($edit) {
function wysiwyg_editor_profile_form($form_state, $edit) {
// Merge in defaults.
settype($edit, 'array');
$edit += array(
......@@ -395,35 +399,35 @@ function wysiwyg_editor_profile_form($edit) {
*
* @see wysiwyg_editor_profile_form_build()
*/
function wysiwyg_editor_profile_form_submit($form_id, &$form_values) {
function wysiwyg_editor_profile_form_submit($form, &$form_state) {
// Count enabled plugins for this profile.
$plugin_count = 0;
foreach ($form_values['buttons'] as $plugin => $buttons) {
$form_values['buttons'][$plugin] = array_filter($form_values['buttons'][$plugin]);
$plugin_count += count($form_values['buttons'][$plugin]);
foreach ($form_state['values']['buttons'] as $plugin => $buttons) {
$form_state['values']['buttons'][$plugin] = array_filter($form_state['values']['buttons'][$plugin]);
$plugin_count += count($form_state['values']['buttons'][$plugin]);
}
$form_values['buttons'] = array_filter($form_values['buttons']);
$form_state['values']['buttons'] = array_filter($form_state['values']['buttons']);
// Filter enabled roles for this profile.
$form_values['rids'] = array_filter($form_values['rids']);
$form_state['values']['rids'] = array_filter($form_state['values']['rids']);
// Delete existing profile(s) with the current profile name.
if (!empty($form_values['old_name'])) {
db_query("DELETE FROM {wysiwyg_editor_profile} WHERE name = '%s' OR name = '%s'", $form_values['name'], $form_values['old_name']);
db_query("DELETE FROM {wysiwyg_editor_role} WHERE name = '%s' OR name = '%s'", $form_values['name'], $form_values['old_name']);
if (!empty($form_state['values']['old_name'])) {
db_query("DELETE FROM {wysiwyg_editor_profile} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
db_query("DELETE FROM {wysiwyg_editor_role} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
}
// Remove FAPI values.
// @see system_settings_form_submit()
unset($form_values['submit'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
unset($form_state['values']['submit'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token']);
// Insert new profile data.
db_query("INSERT INTO {wysiwyg_editor_profile} (name, settings, plugin_count) VALUES ('%s', '%s', %d)", $form_values['name'], serialize($form_values), $plugin_count);
foreach ($form_values['rids'] as $rid => $value) {
db_query("INSERT INTO {wysiwyg_editor_role} (name, rid) VALUES ('%s', %d)", $form_values['name'], $rid);
db_query("INSERT INTO {wysiwyg_editor_profile} (name, settings, plugin_count) VALUES ('%s', '%s', %d)", $form_state['values']['name'], serialize($form_state['values']), $plugin_count);
foreach ($form_state['values']['rids'] as $rid => $value) {
db_query("INSERT INTO {wysiwyg_editor_role} (name, rid) VALUES ('%s', %d)", $form_state['values']['name'], $rid);
}
if (isset($form_values['old_name'])) {
if (isset($form_state['values']['old_name'])) {
drupal_set_message(t('Wysiwyg Editor profile has been updated.'));
}
else {
......@@ -477,7 +481,7 @@ function wysiwyg_editor_profile_overview() {
// Check if at least one role is granted access to Wysiwyg Editor.
$access_check = user_roles(FALSE, 'access wysiwyg editor');
if (!$access_check) {
drupal_set_message(t('You must <a href="!access-control-url">assign</a> at least one role with the \'access wysiwyg editor\' permission before creating a profile.', array('!access-control-url' => url('admin/user/access'))), 'error');
drupal_set_message(t('You must <a href="!access-control-url">assign</a> at least one role with the \'access wysiwyg editor\' permission before creating a profile.', array('!access-control-url' => url('admin/user/permissions'))), 'error');
$usable = FALSE;
}
if (!$usable) {
......
......@@ -2,3 +2,4 @@
name = Wysiwyg Editor
description = Allows users to edit contents with client-side editors.
package = User Interface
core = 6.x
......@@ -2,40 +2,61 @@
// $Id$
/**
* Implementation of hook_schema().
*/
function wysiwyg_editor_schema() {
$schema = array();
$schema['wysiwyg_editor_profile'] = array(
'description' => t('Stores Wysiwyg Editor profiles.'),
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'type' => 'text',
'size' => 'normal',
),
'plugin_count' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('name'),
);
$schema['wysiwyg_editor_role'] = array(
'description' => t('Stores user role access permissions for Wysiwyg Editor profiles.'),
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'rid' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('name', 'rid'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function wysiwyg_editor_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {wysiwyg_editor_profile} (
name varchar(128) NOT NULL default '',
settings text,
plugin_count tinyint NOT NULL default '0',
PRIMARY KEY (name)
) /*!40100 DEFAULT CHARACTER SET utf8 */");
db_query("CREATE TABLE {wysiwyg_editor_role} (
name varchar(128) NOT NULL default '',
rid tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (name,rid)
) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
db_query("CREATE TABLE {wysiwyg_editor_profile} (
name varchar(128) NOT NULL default '',
settings text,
plugin_count smallint NOT NULL default '0',
PRIMARY KEY (name)
)");
db_query("CREATE TABLE {wysiwyg_editor_role} (
name varchar(128) NOT NULL default '',
rid smallint NOT NULL default '0',
PRIMARY KEY (name,rid)
)");
break;
}
drupal_install_schema('wysiwyg_editor');
// Import data from old editor modules.
wysiwyg_editor_migrate_tinymce();
}
......@@ -44,8 +65,7 @@ function wysiwyg_editor_install() {
* Implementation of hook_uninstall()
*/
function wysiwyg_editor_uninstall() {
db_query('DROP TABLE {wysiwyg_editor_profile}');
db_query('DROP TABLE {wysiwyg_editor_role}');
drupal_uninstall_schema('wysiwyg_editor');
}
/**
......@@ -72,24 +92,6 @@ function wysiwyg_editor_migrate_tinymce() {
}
}
/**
* Add plugin_count to editor profiles.
*/
function wysiwyg_editor_update_5000() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {wysiwyg_editor_profile} ADD COLUMN plugin_count tinyint NOT NULL default '0'");
break;
case 'pgsql':
db_add_column($ret, 'wysiwyg_editor_profile', 'plugin_count', 'smallint', array('not null' => TRUE, 'default' => "'0'"));
break;
}
return $ret;
}
/**
* Convert buttons and plugins into associative array and fix plugin count for old profiles.
*
......
......@@ -10,28 +10,35 @@
/**
* Implementation of hook_menu().
*/
function wysiwyg_editor_menu($may_cache) {
function wysiwyg_editor_menu() {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/wysiwyg/profile',
'title' => t('Wysiwyg Editor'),
'callback' => 'wysiwyg_editor_admin',
'description' => t('Configure the rich editor.'),
'access' => user_access('administer site configuration'),
);
}
$items['admin/settings/wysiwyg/profile'] = array(
'title' => 'Wysiwyg Editor',
'page callback' => 'wysiwyg_editor_admin',
'description' => 'Configure the rich editor.',
'access arguments' => array('administer site configuration'),
'file' => 'wysiwyg_editor.admin.inc',
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function wysiwyg_editor_theme() {
return array(
'wysiwyg_editor_admin_button_table' => array('arguments' => array('form')),
);
}
/**
* Implementation of hook_help().
*/
function wysiwyg_editor_help($section) {
switch ($section) {
function wysiwyg_editor_help($path, $arg) {
switch ($path) {
case 'admin/settings/wysiwyg/profile':
case 'admin/help#wysiwyg_editor':
$output = '<p>'. t('Profiles can be defined based on user roles. A Wysiwyg Editor profile can define which pages receive this Wysiwyg Editor capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions. Lastly, only users with the %permission <a href="!url">user permission</a> are able to use Wysiwyg Editor.', array('%permission' => 'access wysiwyg editor', '!url' => url('admin/user/access'))) .'</p>';
$output = '<p>'. t('Profiles can be defined based on user roles. A Wysiwyg Editor profile can define which pages receive this Wysiwyg Editor capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions. Lastly, only users with the %permission <a href="!url">user permission</a> are able to use Wysiwyg Editor.', array('%permission' => 'access wysiwyg editor', '!url' => url('admin/user/permissions'))) .'</p>';
return $output;
}
}
......@@ -53,16 +60,6 @@ function wysiwyg_editor_perm() {
return $array;
}
/**
* Callback handler for admin pages; menu callback.
*/
function wysiwyg_editor_admin($arg = '') {
require_once drupal_get_path('module', 'wysiwyg_editor') .'/wysiwyg_editor.admin.inc';
$op = isset($_POST['op']) ? $_POST['op'] : '';
$op = ($arg && !$op ? $arg : $op);
return _wysiwyg_editor_admin($op);
}
/**
* Implementation of hook_elements().
*/
......@@ -70,11 +67,20 @@ function wysiwyg_editor_elements() {
$type = array();
if (user_access('access wysiwyg editor')) {
// Let Wysiwyg Editor potentially process each textarea.
$type['textarea'] = array('#process' => array('wysiwyg_editor_process_textarea' => array()), '#wysiwyg' => TRUE, '#wysiwyg_style' => 'advanced');
$type['textarea'] = array('#process' => array('wysiwyg_editor_process_textarea'), '#wysiwyg' => TRUE, '#wysiwyg_style' => 'advanced');
}
return $type;
}
/**
* Implementation of hook_form_alter().
*/
function wysiwyg_editor_form_alter(&$form, &$form_state) {
// Disable 'teaser' textarea.
unset($form['body_field']['teaser_js']);
$form['body_field']['teaser_include'] = array();
}
/**
* Load Wysiwyg Editor files and send configuration data.
*/
......@@ -106,14 +112,14 @@ function wysiwyg_editor_load() {
// TinyMCE Compressor >= 1.0.9
if (file_exists($path_editor .'/tiny_mce_gzip.js')) {
drupal_add_js($path_editor .'/tiny_mce_gzip.js');
drupal_add_js($path_editor .'/tiny_mce_gzip.js', 'module', 'header', FALSE, FALSE, FALSE);
}
// TinyMCE Compressor < 1.0.9
elseif (file_exists($path_editor .'/tiny_mce_gzip.php')) {
drupal_add_js($path_editor .'/tiny_mce_gzip.php');
drupal_add_js($path_editor .'/tiny_mce_gzip.php', 'module', 'header', FALSE, FALSE, FALSE);
}
else {
drupal_add_js($path_editor .'/tiny_mce.js');
drupal_add_js($path_editor .'/tiny_mce.js', 'module', 'header', FALSE, FALSE);
}
// Add wysiwyg_editor.js to the footer to ensure it's executed after the
// Drupal.settings array has been rendered and populated.
......@@ -230,15 +236,15 @@ function wysiwyg_editor_load_plugins() {
function wysiwyg_editor_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account' && user_access('access wysiwyg editor')) {
$profile = wysiwyg_editor_user_get_profile($user);
if ($profile->settings['user_choose']) {
if (isset($profile->settings['user_choose']) && $profile->settings['user_choose']) {
$form['wysiwyg'] = array(
'#type' => 'fieldset',
'#title' => t('Wysiwyg Editor rich-text settings'),
'#title' => t('Wysiwyg Editor settings'),
'#weight' => 10,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['wysiwyg']['wysiwyg_status'] = array(
$form['wysiwyg']['wysiwyg_editor_status'] = array(
'#type' => 'select',
'#title' => t('Default state'),
'#default_value' => isset($user->wysiwyg_editor_status) ? $user->wysiwyg_editor_status : (isset($profile->settings['default']) ? $profile->settings['default'] : FALSE),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment