You are here

function fckeditor_admin in FCKeditor - WYSIWYG HTML editor 6

Same name and namespace in other branches
  1. 5.2 fckeditor.module \fckeditor_admin()
  2. 6.2 fckeditor.module \fckeditor_admin()

Controller for FCKeditor administrative settings.

1 string reference to 'fckeditor_admin'
fckeditor_menu in ./fckeditor.module
Add link to FCKeditor configuration in "Administer -> Site configuration" section

File

./fckeditor.module, line 532
FCKeditor - The text editor for Internet - http://www.fckeditor.net Copyright (C) 2003-2008 Frederico Caldeira Knabben

Code

function fckeditor_admin($arg = NULL) {
  $module_drupal_path = drupal_get_path('module', 'fckeditor');
  $fckconfig_file = $module_drupal_path . '/fckeditor/fckconfig.js';
  if (!file_exists($fckconfig_file)) {
    drupal_set_message(t('checking for %filename', array(
      '%filename' => $fckconfig_file,
    )));
    drupal_set_message(t('The FCKeditor component is not installed correctly. Please go to the !fckeditorlink to download the latest version. After that you must extract the files to %modulepath and make sure that the directory %modulesubdir and the file %modulefile exist. Refer to the !readme for more information.', array(
      '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'),
      '!readme' => l('readme.txt', 'admin/help/fckeditor'),
      '%modulepath' => base_path() . $module_drupal_path . '/fckeditor/',
      '%modulesubdir' => base_path() . $module_drupal_path . '/fckeditor/editor',
      '%modulefile' => base_path() . $module_drupal_path . '/fckeditor/fckeditor.js',
    )), 'error');
    return FALSE;
  }
  $edit = $_POST;
  $op = isset($_POST['op']) ? $_POST['op'] : "";
  $op = $arg && !$op ? $arg : $op;
  switch ($op) {
    case 'add':
      $output = fckeditor_profile_form($edit);
      break;
    case 'addg':
      $output = fckeditor_global_profile_form($edit);
      break;
    case 'edit':
      drupal_set_title(t('Edit FCKeditor profile'));
      $output = fckeditor_profile_form(fckeditor_profile_load(urldecode(arg(4))));
      break;
    case 'editg':
      drupal_set_title(t('Edit FCKeditor profile'));
      $output = fckeditor_global_profile_form(fckeditor_profile_load("FCKeditor Global Profile"));
      break;
    case 'deleteg':
      $output = fckeditor_ask_delete_confirmation(TRUE);
      break;
    case 'delete':
      $output = fckeditor_ask_delete_confirmation(FALSE, urldecode(arg(4)));
      break;
    case 'deleteconfirmed':
      fckeditor_profile_delete(urldecode(arg(4)));
      drupal_set_message(t('Deleted profile'));
      drupal_goto('admin/settings/fckeditor');
      break;
    case 'deletegconfirmed':
      fckeditor_profile_delete("FCKeditor Global Profile");
      drupal_set_message(t('Deleted Global profile'));
      drupal_goto('admin/settings/fckeditor');
      break;
    case t('Create profile'):
    case t('Update profile'):
      if (fckeditor_profile_validate($edit)) {
        fckeditor_profile_save($edit);
        !empty($edit['old_name']) ? drupal_set_message(t('Your FCKeditor profile has been updated.')) : drupal_set_message(t('Your FCKeditor profile has been created.'));
        drupal_goto('admin/settings/fckeditor');
      }
      else {
        $output = fckeditor_profile_form($edit);
      }
      break;
    case t('Create global profile'):
    case t('Update global profile'):
      if (fckeditor_global_profile_validate($edit)) {
        $edit['name'] = 'FCKeditor Global Profile';
        fckeditor_global_profile_save($edit);
        drupal_set_message(t('FCKeditor global profile has been saved.'));
        drupal_goto('admin/settings/fckeditor');
      }
      else {
        $output = fckeditor_global_profile_form($edit);
      }
      break;
    default:
      drupal_set_title(t('FCKeditor settings'));

      //Check if FCKeditor is installed.
      $fckeditor_loc = drupal_get_path('module', 'fckeditor') . '/fckeditor/';
      if (!is_dir($fckeditor_loc)) {
        drupal_set_message(t('Could not find the FCKeditor engine installed at <strong>!fckeditor-directory</strong>. Please !download, uncompress it and copy the folder into !fckeditor-path.', array(
          '!fckeditor-path' => drupal_get_path('module', 'fckeditor'),
          '!fckeditor-directory' => $fckeditor_loc,
          '!download' => l(t("download FCKeditor"), "http://www.fckeditor.net/download"),
        )), 'error');
      }
      $access_fckeditor_roles = user_roles(FALSE, 'access fckeditor');
      if (!$access_fckeditor_roles) {
        drupal_set_message(t('There is currently no role with the <strong>!access</strong> permission. Visit !acl administration section.', array(
          "!access" => t("access fckeditor"),
          "!acl" => l(t("Permissions"), "admin/user/permissions"),
        )), "warning");
      }
      else {
        $result = db_query_range("SELECT name FROM {fckeditor_settings} WHERE name<>'FCKeditor Global Profile'", 0, 1);
        $has_profiles = FALSE;

        //find profile other than Global
        if ($obj = db_fetch_object($result)) {
          $has_profiles = TRUE;
        }

        //find roles with profiles
        $result = db_query("SELECT rid FROM {fckeditor_role}");
        $rids = array();
        while ($obj = db_fetch_object($result)) {
          $rids[] = $obj->rid;
        }
        $rids = array_unique($rids);
        if (!$has_profiles) {
          drupal_set_message(t("No FCKeditor profiles found. At this moment, nobody is able to use FCKeditor. Create new profile below."), "error");
        }
        else {

          //not all roles with access fckeditor has their FCKeditor profile assigned
          $diff = array_diff(array_keys($access_fckeditor_roles), $rids);
          if ($diff) {
            $list = "<ul>";
            foreach ($diff as $rid) {
              $list .= "<li>" . $access_fckeditor_roles[$rid] . "</li>";
            }
            $list .= "</ul>";
            drupal_set_message(t("Not all roles with <strong>!access</strong> permission are associated with FCKeditor profiles. As a result, users having the following roles may be unable to use FCKeditor: !list Create new or edit FCKeditor profiles below and in the <strong>Basic setup</strong> section, check &quot;Roles allowed to use this profile&quot;.", array(
              "!access" => l(t("access fckeditor"), "admin/user/permissions"),
              "!list" => $list,
            )), "warning");
          }
        }
      }
      $output = fckeditor_profile_overview();
  }
  return $output;
}