You are here

function _ckeditor_requirements_ckfinder_config_check in CKEditor - WYSIWYG HTML editor 7

Same name and namespace in other branches
  1. 6 ckeditor.install \_ckeditor_requirements_ckfinder_config_check()

Executed when the built-in file browser is enabled. Returns FALSE if no errors are found in the config.php file, otherwise it returns an error message.

Return value

string|boolean

1 call to _ckeditor_requirements_ckfinder_config_check()
ckeditor_requirements in ./ckeditor.install
Implementation of hook_requirements().

File

./ckeditor.install, line 318

Code

function _ckeditor_requirements_ckfinder_config_check($profile_name) {
  global $base_url;
  module_load_include('module', 'ckeditor');
  $config_path = ckfinder_path('local') . '/config.php';
  if (!file_exists($config_path)) {
    return t('!ckfinder is not installed correctly: <code>!config</code> not found. Make sure that you uploaded all files and did not accidentally remove the configuration file. If you installed CKFinder in other location (e.g. in the libraries folder), make sure to update the path to CKFinder in !global.', array(
      '!config' => $config_path,
      '!ckfinder' => '<a href="http://cksource.com/ckfinder">CKFinder</a>',
      '!global' => l(t('CKEditor Global Profile'), 'admin/config/content/ckeditor/editg'),
    ));
  }
  if (!is_readable($config_path)) {
    return t('CKEditor needs read permission to the <code>!config</code> file.', array(
      '!config' => $config_path,
    ));
  }
  $config_contents = file($config_path);

  //not a 100% valid check, but well... let's have at least some error checking
  $require_once_found = FALSE;
  $require_once_line = 0;
  $userfiles_absolute_path_line = 0;
  $force_single_extension_line = 0;
  if ($config_contents) {
    foreach ($config_contents as $line_num => $line) {

      //make sure it doesn't start with a comment, unfortunately we're not protected if code is commented with /* */
      if (!$require_once_found && strpos($line, "filemanager.config.php") !== FALSE && !preg_match(",^(?://|\\#|\\*|/\\*),", trim($line))) {
        $require_once_found = TRUE;
        $require_once_line = $line_num;
      }

      /**
       * @todo Finish this
       */
      if (!$userfiles_absolute_path_line && strpos($line, '$Config[\'UserFilesAbsolutePath\']') !== FALSE && !preg_match(",^(?://|\\#|\\*|/\\*),", trim($line))) {
        $userfiles_absolute_path_line = $line_num;
      }
      if (!$force_single_extension_line && strpos($line, '$Config[\'ForceSingleExtension\']') !== FALSE && !preg_match(",^(?://|\\#|\\*|/\\*),", trim($line))) {
        $force_single_extension_line = $line_num;
      }
    }
  }
  if (!$require_once_found) {
    return t('You are using a feature that requires manual integration in the <code>config.php</code> file. Please read the "Installing CKFinder" section in the <code>!readme</code> file carefully and add a <code>require_once ...</code> statement to the <code>%ckfconfig</code> file.', array(
      '%ckfconfig' => $config_path,
      '!readme' => l(t('README.txt'), $base_url . '/' . drupal_get_path('module', 'ckeditor') . '/README.txt', array(
        'absolute' => TRUE,
      )),
    ));
  }
  if ($userfiles_absolute_path_line && $force_single_extension_line && ($require_once_line < $userfiles_absolute_path_line || $require_once_line > $force_single_extension_line)) {
    return t('You are using a feature that requires manual integration in the <code>config.php</code> file. You have added a <code>require_once ...</code> statement to the <code>%ckfconfig</code> file, but in the wrong line.', array(
      '%ckfconfig' => $config_path,
    ));
  }
  return FALSE;
}