Unverified Commit 92b3637c authored by Robert Mikołajuk's avatar Robert Mikołajuk
Browse files

Issue #2671806 by ron_s, vokiel: Add custom skin support

parent 6a197147
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
@@ -540,6 +540,78 @@ function ckeditor_plugins_path($mode = 'relative', $refresh = FALSE) {
  return $cke_static[$mode];
}

/**
 * Read the CKEditor skins path from the Global profile.
 *
 * @return string Path to CKEditor skins folder.
 */
function ckeditor_skins_path($mode = 'relative', $refresh = FALSE) {
  static $cke_static;

  if (!isset($cke_static)) {
    $cke_static = array();
  }

  if ($refresh || !isset($cke_static[$mode])) {
    $global_profile = ckeditor_profile_load('CKEditor Global Profile', $refresh);
    if (!$global_profile) {
      return '';
    }

    switch ($mode) {
      default:
      case 'relative':
        if (empty($global_profile->settings['ckeditor_skins_path'])) {
          return '';
        }

        $cke_skins_path = $global_profile->settings['ckeditor_skins_path'];
        $cke_skins_path = strtr($cke_skins_path, array("%b" => ckeditor_base_path('relative'), "%m" => ckeditor_module_path('relative'), "%l" => ckeditor_library_path('relative')));
        $cke_skins_path = str_replace('\\', '/', $cke_skins_path);
        $cke_skins_path = str_replace('//', '/', $cke_skins_path);
        $cke_skins_path = rtrim($cke_skins_path, ' \/');
        return $cke_static[$mode] = $cke_skins_path;

        break;

      case 'local':
        if (empty($global_profile->settings['ckeditor_skins_local_path']) && empty($global_profile->settings['ckeditor_skins_path'])) {
          return '';
        }

        if (!empty($global_profile->settings['ckeditor_skins_local_path'])) {
          return $cke_static[$mode] = $global_profile->settings['ckeditor_skins_local_path'];
        }

        if (!empty($global_profile->settings['ckeditor_skins_path'])) {
          $cke_skins_local_path = $global_profile->settings['ckeditor_skins_path'];
          $cke_skins_local_path = strtr($cke_skins_local_path, array("%b" => ckeditor_base_path('local'), "%m" => ckeditor_module_path('local'), "%l" => ckeditor_library_path('local')));
          return $cke_static[$mode] = $cke_skins_local_path;
        }

        break;

      case 'url':
        if (empty($global_profile->settings['ckeditor_skins_path'])) {
          return '';
        }

        $cke_skins_path = $global_profile->settings['ckeditor_skins_path'];
        $cke_skins_path = strtr($cke_skins_path, array("%m" => ckeditor_module_path('url'), "%l" => ckeditor_library_path('url')));
        $cke_skins_path = str_replace('\\', '/', $cke_skins_path);
        $cke_skins_path = str_replace('//', '/', $cke_skins_path);
        $cke_skins_path = rtrim($cke_skins_path, ' \/');
        //In D7 base path in URL mode is not needed, so we need to remove it with trailing slash (if exists)
        $cke_skins_path = str_replace(array("%b/", "%b"), '', $cke_skins_path);
        return $cke_static[$mode] = $cke_skins_path;

        break;
    }
  }

  return isset($cke_static[$mode]) ? $cke_static[$mode] : '';
}

/**
 * Read the CKFinder path from the Global profile.
 *
+121 −7
Original line number Diff line number Diff line
@@ -233,7 +233,16 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
  if ($current_path == '<URL>') {
    $current_path = ckeditor_path('url');
  }
  $form['ckeditor_advanced_settings']['ckeditor_path'] = array(

  $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',
@@ -267,7 +276,7 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
  if ($local_path == '<URL>') {
    $local_path = t('CKEditor is loaded from URL. Local path is not available.');
  }
  $form['ckeditor_advanced_settings']['ckeditor_local_path'] = array(
  $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'] : '',
@@ -285,7 +294,15 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
    )
  );

  $form['ckeditor_advanced_settings']['ckeditor_plugins_path'] = array(
  $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',
@@ -309,7 +326,7 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
    )
  );

  $form['ckeditor_advanced_settings']['ckeditor_plugins_local_path'] = array(
  $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'] : '',
@@ -327,7 +344,58 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
    )
  );

  $form['ckeditor_advanced_settings']['ckfinder_path'] = array(
  $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',
@@ -355,7 +423,7 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
    )
  );

  $form['ckeditor_advanced_settings']['ckfinder_local_path'] = array(
  $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'] : '',
@@ -387,7 +455,7 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
      ),
      '#required' => FALSE
    );
    $current_private_dir = !empty($profile->settings['private_dir']) ? $profile->settings['private_dir'] : '';

    $form['ckeditor_advanced_settings']['private_dir'] = array(
      '#type' => 'textfield',
      '#title' => t('Location of files uploaded with CKEditor to the private folder'),
@@ -458,7 +526,43 @@ function ckeditor_admin_global_profile_form($form, $form_state, $mode = 'add') {
 * Form validation for a global profile
 */
function ckeditor_admin_global_profile_form_validate($form, &$form_state) {
  $edit = & $form_state['values'];

  if (!empty($edit['skin'])) {
    if (preg_match('/^\/\/cdn\.ckeditor\.com\/(.*)\/(.*)$/', $edit['ckeditor_path'], $matches)) {
      // Assume a default skin is being used, then check if this is true.
      $default_skin = TRUE;
      $default_skin_string = '';
      // CKEditor v4.6 and above use "moono-lisa" as the default skin.
      if (version_compare($matches[1], '4.6', '>=')) {
        // Presets standard-all and full-all contains all default skins
        $defaults = (!empty($matches[2]) && substr($matches[2], -4) == '-all')
          ? ['moono-lisa', 'moono', 'kama']
          : ['moono-lisa'];

        if (!in_array($edit['skin'], $defaults)) {
          $default_skin = FALSE;
          $default_skin_string = 'Moono-lisa';
        }
      }
      // Below version 4.6, "moono" and "kama" are the default CKEditor skins.
      elseif (!in_array($edit['skin'], ['moono', 'kama'])) {
        $default_skin = FALSE;
        $default_skin_string = 'Moono or Kama';
      }

      $skin_js_local = ckeditor_skins_path('local') . '/' . $edit['skin'] . '/skin.js';
      if (!$default_skin && !file_exists($skin_js_local)) {
        $skin_js_relative = ckeditor_skins_path('relative') . '/' . $edit['skin'] . '/skin.js';
        $err_msg = t('When using the CKEditor CDN and a skin other than @skin_string, the <strong>skin.js</strong> file must be accessible locally. To fix this issue, download the skin from <a href="@url">CKEditor Addons</a>, extract skin.js, and place the file in the sub-directory named for the selected skin (for example: <em>@skin_js</em>).', array(
          '@skin_string' => $default_skin_string,
          '@url' => 'http://ckeditor.com/addons/skins/all',
          '@skin_js' => $skin_js_relative,
        ));
        form_set_error('ckeditor_skins_path', $err_msg);
      }
    }
  }
}

/**
@@ -513,6 +617,16 @@ function ckeditor_admin_global_profile_form_submit($form, &$form_state) {
  //no slash at the end
  $edit['ckeditor_plugins_path'] = trim(rtrim($edit['ckeditor_plugins_path'], "/"));

  //strip slash from the end
  $edit['ckeditor_skins_path'] = trim(rtrim(trim($edit['ckeditor_skins_path']), "/"));
  if ($edit['ckeditor_skins_path'] && 0 !== strpos($edit['ckeditor_skins_path'], "/") && 0 !== strpos($edit['ckeditor_skins_path'], "%")) {
    //ensure that slash is at the beginning
    $edit['ckeditor_skins_path'] = "/" . $edit['ckeditor_skins_path'];
  }

  //no slash at the end
  $edit['ckeditor_skins_local_path'] = trim(rtrimtrim(($edit['ckeditor_skins_local_path']), "/"));

  //strip slash from the end
  if (empty($edit['ckfinder_path'])) {
    $edit['ckfinder_path'] = '';
+32 −2
Original line number Diff line number Diff line
@@ -161,9 +161,10 @@ function ckeditor_load_toolbar_options() {
 */
function ckeditor_load_skin_options() {
  $arr = array();
  $editor_path = ckeditor_path('relative');
  $editor_local_path = ckeditor_path('local');
  $skin_dir = $editor_local_path . '/skins';
  if ($editor_local_path != '<URL>' && is_dir($skin_dir)) {
  $skin_dir = ckeditor_skins_path('local');
  if (is_dir($skin_dir) && ($editor_local_path != '<URL>' || ($editor_path == '<URL>' && $editor_local_path == '<URL>') ) ) {
    $dh = @opendir($skin_dir);
    if (FALSE !== $dh) {
      while (($file = readdir($dh)) !== FALSE) {
@@ -585,6 +586,8 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
  $module_drupal_local_path = ckeditor_module_path('local');
  $editor_path = ckeditor_path('relative');
  $editor_local_path = ckeditor_path('local');
  $skins_path = ckeditor_skins_path('relative');
  $skins_local_path = ckeditor_skins_path('local');

  $toolbar = $conf['toolbar'];

@@ -610,6 +613,33 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    isset($global_profile->settings['skin']) && $editor_local_path == '<URL>'
  ) {
    $settings['skin'] = $global_profile->settings['skin'];
    // Check if skin exists, if not select default one
    if (isset($global_profile->settings['skin'])) {
      // If the skin exists, check if local file is present
      if (file_exists($skins_local_path . '/' . $global_profile->settings['skin'])) {
        // If editor is local, set skin as profile value
        if ($editor_local_path != '<URL>') {
          $settings['skin'] = $global_profile->settings['skin'];
        }
        // If editor is remote, set skin as profile value plus local path
        // example: http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-skin
        else if ($editor_path == '<URL>' && $editor_local_path == '<URL>') {
          $settings['skin'] = $global_profile->settings['skin'] . ',' . $skins_path . '/' . $global_profile->settings['skin'] . '/';
        }
        else {
          $settings['skin'] = ckeditor_default_skin();
        }
      }
      else {
        // If no local skin file, check if editor is hosted remotely
        if ($editor_path == '<URL>' && $editor_local_path == '<URL>') {
          $settings['skin'] = $global_profile->settings['skin'];
        }
        else {
          $settings['skin'] = ckeditor_default_skin();
        }
      }
    }
  }
  else {
    $settings['skin'] = ckeditor_default_skin();