You are here

function _fckeditor_requirements_filemanager_config_check in FCKeditor - WYSIWYG HTML editor 6.2

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

Return value

string|boolean

1 call to _fckeditor_requirements_filemanager_config_check()
fckeditor_requirements in ./fckeditor.install
Implementation of hook_requirements().

File

./fckeditor.install, line 317

Code

function _fckeditor_requirements_filemanager_config_check($profile_name) {
  module_load_include('module', 'fckeditor');
  $editor_path = fckeditor_path(TRUE);
  $config_path = $editor_path . '/editor/filemanager/connectors/php/config.php';
  if (!file_exists($config_path)) {
    return t('!config not found. Make sure that you have uploaded all files or didn\'t remove that file accidentally.', array(
      '!config' => 'editor/filemanager/connectors/php/config.php',
    ));
  }
  if (!is_readable($config_path)) {
    return t('FCKeditor needs read permission to !config.', array(
      '!config' => 'editor/filemanager/connectors/php/config.php',
    ));
  }
  $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;
      }
      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 into config.php (either built-in filebrowser or quick uploads are enabled in the !profile profile). Read instructions about enabling built-in file browser and add "require_once ..." statement in editor/filemanager/connectors/php/config.php.', array(
      '!profile' => l($profile_name, 'admin/settings/fckeditor/edit/' . urlencode($profile_name)),
    ));
  }
  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 into config.php (either built-in filebrowser or quick uploads are enabled in the !profile profile). You have added "require_once ..." statement in editor/filemanager/connectors/php/config.php, but in the wrong line.', array(
      '!profile' => l($profile_name, 'admin/settings/fckeditor/edit/' . urlencode($profile_name)),
    ));
  }
  return FALSE;
}