You are here

function ckeditor_admin_global_profile_form in CKEditor - WYSIWYG HTML editor 7

Same name and namespace in other branches
  1. 6 includes/ckeditor.admin.inc \ckeditor_admin_global_profile_form()

Form builder for a global profile

1 string reference to 'ckeditor_admin_global_profile_form'
ckeditor_menu in ./ckeditor.module
Implementation of hook_menu().

File

includes/ckeditor.admin.inc, line 167
CKEditor - The text editor for the Internet - http://ckeditor.com Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.

Code

function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  if ($mode == 'edit') {
    $profile = ckeditor_profile_load('CKEditor Global Profile');
    $form['_profile'] = array(
      '#type' => 'value',
      '#value' => $profile,
    );
  }
  else {
    $profile = new stdClass();
  }
  if ($mode == 'add') {
    $data = ckeditor_profile_load('CKEditor Global Profile');
    if (!empty($data)) {
      drupal_set_message(t('The global profile already exists. Only one global profile is allowed.'), 'error');
      drupal_not_found();
    }
    $btn = t('Create a global profile');
  }
  else {
    $btn = t('Update the global profile');
  }
  $orig_formats = filter_formats();
  $formats = array();
  foreach ($orig_formats as $format) {
    $formats[$format->format] = $format->name;
  }
  $drupal_base_path = ckeditor_base_path('relative');
  $drupal_library_path = ckeditor_library_path('relative');
  $module_drupal_path = ckeditor_module_path('relative');
  $skin_options = ckeditor_load_skin_options();
  $form['appearance'] = array(
    '#type' => 'fieldset',
    '#title' => t('Editor appearance'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  //if skin is not set or not exists select default skin (moono or skin) or first on the skin list
  if (empty($profile->settings['skin']) || !empty($profile->settings['skin']) && !array_key_exists($profile->settings['skin'], $skin_options)) {
    $profile->settings['skin'] = ckeditor_default_skin();
  }
  $form['appearance']['skin'] = array(
    '#type' => 'select',
    '#title' => t('Skin'),
    '#default_value' => $profile->settings['skin'],
    '#options' => $skin_options,
    '#description' => t('Choose a CKEditor skin.'),
  );
  $form['ckeditor_advanced_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $current_path = ckeditor_path('relative');
  if ($current_path == '<URL>') {
    $current_path = ckeditor_path('url');
  }
  $form['ckeditor_advanced_settings']['cke_path'] = array(
    '#type' => 'fieldset',
    '#title' => t('CKEditor path'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => FALSE,
  );
  $form['ckeditor_advanced_settings']['cke_path']['ckeditor_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to CKEditor'),
    '#default_value' => !empty($profile->settings['ckeditor_path']) ? $profile->settings['ckeditor_path'] : '%m/ckeditor',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('The path to CKEditor (the WYSIWYG rich text editor downloaded from !ckeditorcom). Provide a path relative to the document root, unless CKEditor is located on an external URL. In such case enter the full URL to a folder with CKEditor.<br />The simplest way to have the editor running is to use CDN, to use it set: !cdn', array(
      '!ckeditorcom' => l(t('ckeditor.com'), 'http://ckeditor.com/download'),
      '!cdn' => '<strong>//cdn.ckeditor.com/' . CKEDITOR_LATEST . '/full-all</strong>',
    )) . '<br /><br /> ' . t('Available placeholders:!b &ndash; path of the Drupal installation (!base) !m &ndash; path where the CKEditor module is stored (!module).!l &ndash; path to the libraries directory (!library).', array(
      '!b' => '<br /><code>%b</code>',
      '!m' => '<br /><code>%m</code>',
      '!l' => '<br /><code>%l</code>',
      '!base' => '<code>' . $drupal_base_path . '</code>',
      '!module' => '<code>' . $module_drupal_path . '</code>',
      '!library' => '<code>' . $drupal_library_path . '</code>',
    )) . '<br /> ' . t('Current path: !path', array(
      '!path' => '<code>' . $current_path . '</code>',
    )),
    '#required' => TRUE,
  );
  $local_path = ckeditor_path('local');
  if ($local_path == '<URL>') {
    $local_path = t('CKEditor is loaded from URL. Local path is not available.');
  }
  $form['ckeditor_advanced_settings']['cke_path']['ckeditor_local_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Local path to CKEditor'),
    '#default_value' => isset($profile->settings['ckeditor_local_path']) ? $profile->settings['ckeditor_local_path'] : '',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('The path to the local directory (on the server) that points to the path defined above. Enter either an absolute server path or a path relative to the !indexphp file. If left empty, the CKEditor module will try to find the right path.', array(
      '!indexphp' => '<code>index.php</code>',
    )) . '<br /> ' . t('Current path: !path', array(
      '!path' => '<code>' . $local_path . '</code>',
    )),
  );
  $form['ckeditor_advanced_settings']['plugins_path'] = array(
    '#type' => 'fieldset',
    '#title' => t('CKEditor plugins'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => FALSE,
  );
  $form['ckeditor_advanced_settings']['plugins_path']['ckeditor_plugins_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to the CKEditor plugins directory'),
    '#default_value' => !empty($profile->settings['ckeditor_plugins_path']) ? $profile->settings['ckeditor_plugins_path'] : '%m/plugins',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('Path to the CKEditor plugins directory relative to the document root.') . '<br />' . t('Available placeholders:!b &ndash; path of the Drupal installation (!base) !m &ndash; the base URL path where the CKEditor module is stored (!module).!l &ndash; the base URL path to the libraries directory (!library)', array(
      '!b' => '<br /><code>%b</code>',
      '!m' => '<br /><code>%m</code>',
      '!l' => '<br /><code>%l</code>',
      '!base' => '<code>' . $drupal_base_path . '</code>',
      '!module' => '<code>' . $module_drupal_path . '</code>',
      '!library' => '<code>' . $drupal_library_path . '</code>',
    )) . '<br /> ' . t('Current path: !path', array(
      '!path' => '<code>' . ckeditor_plugins_path('relative') . '</code>',
    )),
  );
  $form['ckeditor_advanced_settings']['plugins_path']['ckeditor_plugins_local_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Local path to the CKEditor plugins directory'),
    '#default_value' => isset($profile->settings['ckeditor_plugins_local_path']) ? $profile->settings['ckeditor_plugins_local_path'] : '',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('The path to the local directory (on the server) that points to the path defined above. Enter either an absolute server path or a path relative to the !indexphp file. If left empty, the CKEditor module will try to find the right path.', array(
      '!indexphp' => '<code>index.php</code>',
    )) . '<br /> ' . t('Current path: !path', array(
      '!path' => '<code>' . ckeditor_plugins_path('local') . '</code>',
    )),
  );
  $form['ckeditor_advanced_settings']['skins_path'] = array(
    '#type' => 'fieldset',
    '#title' => t('CKEditor skins'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => FALSE,
  );
  $form['ckeditor_advanced_settings']['skins_path']['ckeditor_skins_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to the CKEditor skins directory'),
    '#default_value' => !empty($profile->settings['ckeditor_skins_path']) ? $profile->settings['ckeditor_skins_path'] : '',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('Path to the CKEditor skins directory relative to the document root.') . '<br />' . t('Available placeholders:<br /><code>%b</code> &ndash; path of the Drupal installation (<code>@base</code>) <br /><code>%m</code> &ndash; the base URL path where the CKEditor module is stored (<code>@module</code>).<br /><code>%l</code> &ndash; the base URL path to the libraries directory (<code>@library</code>)', array(
      '@base' => $drupal_base_path,
      '@module' => $module_drupal_path,
      '@library' => $drupal_library_path,
    )) . '<br /> ' . t('Current path: <code>@path</code>', array(
      '@path' => ckeditor_skins_path('relative'),
    )),
  );
  $form['ckeditor_advanced_settings']['skins_path']['ckeditor_skins_local_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Local path to the CKEditor skins directory'),
    '#default_value' => isset($profile->settings['ckeditor_skins_local_path']) ? $profile->settings['ckeditor_skins_local_path'] : '',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('The path to the local directory (on the server) that points to the path defined above. Enter either an absolute server path or a path relative to the <code>index.php</code> file. If left empty, the CKEditor module will try to find the right path.') . '<br /> ' . t('Current path: <code>@path</code>', array(
      '@path' => ckeditor_skins_path('local'),
    )),
  );
  $form['ckeditor_advanced_settings']['ckf_path'] = array(
    '#type' => 'fieldset',
    '#title' => t('CKFinder path'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => FALSE,
  );
  $form['ckeditor_advanced_settings']['ckf_path']['ckfinder_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to CKFinder'),
    '#default_value' => !empty($profile->settings['ckfinder_path']) ? $profile->settings['ckfinder_path'] : '%m/ckfinder',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('The path to CKFinder (AJAX based file manager downloaded from !ckfindercom) relative to the document root.', array(
      '!ckfindercom' => l(t('ckfinder.com'), 'http://cksource.com/ckfinder'),
    )) . '<br />' . t('Available placeholders:!b &ndash; path of the Drupal installation (!base) !m &ndash; path where the CKEditor module is stored (!module).!l &ndash; path to the libraries directory (!library)', array(
      '!b' => '<br /><code>%b</code>',
      '!m' => '<br /><code>%m</code>',
      '!l' => '<br /><code>%l</code>',
      '!base' => '<code>' . $drupal_base_path . '</code>',
      '!module' => '<code>' . $module_drupal_path . '</code>',
      '!library' => '<code>' . $drupal_library_path . '</code>',
    )) . '<br /> ' . t('Current path: !path', array(
      '!path' => '<code>' . ckfinder_path('relative') . '</code>',
    )),
  );
  $form['ckeditor_advanced_settings']['ckf_path']['ckfinder_local_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Local path to CKFinder'),
    '#default_value' => isset($profile->settings['ckfinder_local_path']) ? $profile->settings['ckfinder_local_path'] : '',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('The path to the local directory (on the server) that points to the path defined above. Enter either an absolute server path or a path relative to the !indexphp file. If left empty, the CKEditor module will try to find the right path.', array(
      '!indexphp' => '<code>index.php</code>',
    )) . '<br /> ' . t('Current path: !path', array(
      '!path' => '<code>' . ckfinder_path('local') . '</code>',
    )),
  );

  //@todo DOWNLOAD API
  if (variable_get('file_default_scheme', '') == 'private') {
    $form['ckeditor_advanced_settings']['ckeditor_allow_download_private_files'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable access to files located in the private folder'),
      '#default_value' => !empty($profile->settings['ckeditor_allow_download_private_files']),
      '#return_value' => 't',
      '#description' => t('<strong>Use this option with care.</strong> If checked, CKEditor will allow anyone knowing the URL to view a file located inside of the private path (!private_path), but only if there is no information about the file in the Drupal database. If the path below is specified, anyone will have access only to that location.', array(
        '!private_path' => '<code>' . variable_get('file_private_path', '') . '</code>',
      )),
      '#required' => FALSE,
    );
    $form['ckeditor_advanced_settings']['private_dir'] = array(
      '#type' => 'textfield',
      '#title' => t('Location of files uploaded with CKEditor to the private folder'),
      '#default_value' => !empty($profile->settings['private_dir']) ? $profile->settings['private_dir'] : '',
      '#size' => 40,
      '#maxlength' => 255,
      '#description' => t('The path relative to the location of the private directory where CKEditor should store uploaded files.') . '<br />' . t('Available wildcard characters:!u &ndash; User ID.!n &ndash; Username', array(
        '!u' => '<br/><code>%u</code>',
        '!n' => '<br /><code>%n</code>',
      )) . '<br />' . t('System path to the private folder is: !system_path.', array(
        '!system_path' => '<code>' . realpath(variable_get('file_private_path', conf_path() . '/files')) . DIRECTORY_SEPARATOR . '</code>',
      )),
    );
  }
  if (function_exists('linktocontent_node_menu') && function_exists('pathfilter_filter')) {
    $form['ckeditor_advanced_settings']['linktoc'] = array(
      '#type' => 'select',
      '#options' => array(
        'p' => t('Link to paths only'),
        'n' => t('Link using internal: links'),
        'pn' => t('Allow the user to select between paths and internal links'),
      ),
      '#title' => t('Path Filter & Link To Content integration'),
      '#default_value' => empty($profile->settings['linktoc']) ? 'p' : $profile->settings['linktoc'],
      '#description' => t('With the !plink extension it is possible to use internal: links. By default the !link extension is linking to nodes using paths.', array(
        '!plink' => l(t('Path Filter'), 'http://drupal.org/project/pathfilter'),
        '!link' => l(t('Link To Content'), 'http://drupal.org/project/linktocontent'),
      )),
    );
  }
  $form['ckeditor_advanced_settings']['ckeditor_aggregate'] = array(
    '#type' => 'radios',
    '#title' => t('Aggregate <code>ckeditor.js</code>'),
    '#default_value' => !empty($profile->settings['ckeditor_aggregate']) ? $profile->settings['ckeditor_aggregate'] : 'f',
    '#options' => array(
      't' => t('Enabled'),
      'f' => t('Disabled'),
    ),
    '#description' => t('When enabled, <code>ckeditor.js</code> will be aggregated if JavaScript aggregation is enabled. <strong>Not recommended</strong>.'),
  );
  $form['ckeditor_advanced_settings']['toolbar_wizard'] = array(
    '#type' => 'radios',
    '#title' => t('Use toolbar Drag&Drop feature'),
    '#default_value' => !empty($profile->settings['toolbar_wizard']) ? $profile->settings['toolbar_wizard'] : 't',
    '#options' => array(
      't' => t('Enabled'),
      'f' => t('Disabled'),
    ),
    '#description' => t('When enabled, the toolbar can be built by using the drag-and-drop feature. Otherwise you will need to enter the toolbar configuration manually to the text box.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $btn,
  );
  return $form;
}