Index: fckeditor.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fckeditor/fckeditor.install,v retrieving revision 1.1.4.21 diff -b -u -p -r1.1.4.21 fckeditor.install --- fckeditor.install 4 Dec 2008 16:41:24 -0000 1.1.4.21 +++ fckeditor.install 20 Jan 2009 11:30:36 -0000 @@ -41,6 +41,12 @@ function fckeditor_install() { PRIMARY KEY (name) ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + db_query("CREATE TABLE {fckeditor_node_type} ( + name varchar(128) NOT NULL default '', + type varchar(32) NOT NULL default '', + PRIMARY KEY (name,type) + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + db_query("CREATE TABLE {fckeditor_role} ( name varchar(128) NOT NULL default '', rid tinyint(3) unsigned NOT NULL default '0', @@ -55,6 +61,12 @@ function fckeditor_install() { PRIMARY KEY (name) );"); + db_query("CREATE TABLE {fckeditor_node_type} ( + name varchar(128) NOT NULL default '', + type varchar(32) NOT NULL default '', + PRIMARY KEY (name,type) + );"); + db_query("CREATE TABLE {fckeditor_role} ( name varchar(128) NOT NULL default '', rid smallint NOT NULL default '0', @@ -369,10 +381,36 @@ function fckeditor_update_5() { return $ret; } +function fckeditor_update_6() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {fckeditor_node_type} ( + name varchar(128) NOT NULL default '', + type varchar(32) NOT NULL default '', + PRIMARY KEY (name,type) + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {fckeditor_node_type} ( + name varchar(128) NOT NULL default '', + type varchar(32) NOT NULL default '', + PRIMARY KEY (name,type) + );"); + break; + } + + return $ret; +} + /** * Implementation of hook_uninstall() */ function fckeditor_uninstall() { db_query('DROP TABLE {fckeditor_settings}'); db_query('DROP TABLE {fckeditor_role}'); + db_query('DROP TABLE {fckeditor_node_type}'); } Index: fckeditor.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fckeditor/fckeditor.module,v retrieving revision 1.19.2.6.2.69 diff -b -u -p -r1.19.2.6.2.69 fckeditor.module --- fckeditor.module 20 Jan 2009 10:14:21 -0000 1.19.2.6.2.69 +++ fckeditor.module 20 Jan 2009 11:30:45 -0000 @@ -1,5 +1,5 @@ $value) { + db_query("INSERT INTO {fckeditor_node_type} (name, type) VALUES ('%s', '%s')", $edit['name'], $type); + } + } // if users can't set their own defaults, make sure to remove $user->fckeditor_status so their default doesn't override the main default if ($edit['user_choose'] == 'false') { global $user; @@ -765,6 +771,14 @@ function fckeditor_profile_load($name = } $data->rids = $role; + // get fckeditor node types + $result3 = db_query("SELECT type FROM {fckeditor_node_type} WHERE name = '%s'", $data->name); + $type = array(); + while ($r = db_fetch_object($result3)) { + $type[$r->type] = $types[$r->type]; + } + $data->types = $type; + $profiles[$data->name] = $data; } } @@ -1623,6 +1637,7 @@ function fckeditor_profile_form_build($e // profile per role. $orig_roles = user_roles(FALSE, 'access fckeditor'); $roles = $orig_roles; + $types = node_get_types('names'); if ($edit->rids && !user_roles(false, 'access fckeditor')) { drupal_set_message(t('You haven\'t assigned !access1 !permissions yet.
It is recommended to assign the !access1 !permissions before updating FCKeditor profiles.', @@ -1679,6 +1694,15 @@ function fckeditor_profile_form_build($e '#required' => TRUE ); + $form['basic']['types'] = array( + '#type' => 'checkboxes', + '#title' => t('Content types that can use this profile'), + '#default_value' => array_keys((array) $edit->types), + '#options' => $types, +# '#description' => t(''), + '#required' => TRUE + ); + $form['basic']['allow_user_conf'] = array( '#type' => 'select', '#title' => t('Allow users to customize FCKeditor appearance'), @@ -2190,28 +2214,68 @@ function fckeditor_user_get_setting($use function fckeditor_user_get_profile($user) { static $profile_name; + $page_node_type = null; + if ('node' == arg(0)) { + if ('add' == arg(1)) { + $page_node_type = strtr(arg(2),'-','_'); + } // end if add + else if ('edit' == arg(2)) { + $nid = arg(1); + $node = node_load($nid); + $page_node_type = $node->type; + } // end if edit + } // end if node + // Since fckeditor_profile_load() makes a db hit, only call it when we're pretty sure // we're gonna render fckeditor. - if (!isset($profile_name[$user->uid])) { + if (!isset($profile_name[$page_node_type][$user->uid])) { $sorted_roles = fckeditor_sorted_roles(); - foreach ($sorted_roles as $rid => $name) { - if (isset($user->roles[$rid])) { - break; - } - } - - if (isset($user->roles[$rid])) { - $profile_name[$user->uid] = db_result(db_query("SELECT s.name FROM {fckeditor_settings} s INNER JOIN {fckeditor_role} r ON r.name = s.name WHERE r.rid='%s'", $rid)); - } - else if ($user->uid == "1") { - $profile_name[$user->uid] = db_result(db_query_range("SELECT s.name FROM {fckeditor_settings} s INNER JOIN {fckeditor_role} r ON r.name = s.name ORDER BY r.rid DESC", 1)); - } - } + if (!empty($sorted_roles)) { + $select_nt_type = $join_fckeditor_role = $and_nt_type = ''; + if (isset($page_node_type)) { + $select_nt_type = 'nt.type, '; + $join_fckeditor_role = 'INNER JOIN {fckeditor_node_type} nt ON nt.name = s.name '; + $and_nt_type = "AND nt.type = '%s' "; + } + $sql = "SELECT r.rid, " . + $select_nt_type . + "s.name FROM {fckeditor_settings} s " . + "INNER JOIN {fckeditor_role} r ON r.name = s.name " . + $join_fckeditor_role . + "WHERE r.rid IN (" . implode(', ', array_fill(0, count($sorted_roles), '%d')) .") " . + $and_nt_type; + $res = db_query($sql, array_merge(array_keys($sorted_roles), array($page_node_type))); + + $profiles = array(); + while ($row = db_fetch_array($res)) { + $profiles[] = $row; + } // end while rows - if (isset($profile_name[$user->uid]) && $profile_name[$user->uid]) { - $profile = fckeditor_profile_load($profile_name[$user->uid]); + $sorted_profiles = array(); + foreach ($sorted_roles as $rid => $name) { + foreach ($profiles as $key => $row) { + if ($rid == $row['rid']) { + $sorted_profiles[] = $row; + unset($profiles[$key]); + break; + } // end if found rid + } // end foreach $row + } // end foreach $rid + + $preferred_profile = current($sorted_profiles); + $profile_name[$page_node_type][$user->uid] = $preferred_profile['name']; + } // end if $sorted_roles + } // end if no profile + + if (isset($profile_name[$page_node_type][$user->uid]) + && $profile_name[$page_node_type][$user->uid]) { + $profile = fckeditor_profile_load($profile_name[$page_node_type][$user->uid]); + if (!isset($page_node_type) + || in_array($page_node_type, array_keys($profile->types))) + { return $profile; - } + } // end if no page node type or valid node type + } // end if valid profile name for user return FALSE; }