You are here

function composer_manager_prepare_directory in Composer Manager 6

Same name and namespace in other branches
  1. 6.2 composer_manager.writer.inc \composer_manager_prepare_directory()
  2. 7.2 composer_manager.writer.inc \composer_manager_prepare_directory()
  3. 7 composer_manager.writer.inc \composer_manager_prepare_directory()

Ensures the directory is created and protected via .htaccess if necessary.

Parameters

string $directory: The URI or path to the directory being prepared.

Return value

bool

3 calls to composer_manager_prepare_directory()
composer_manager_file_dir in ./composer_manager.writer.inc
Returns the realpath to the Composer file directory.
composer_manager_put_file in ./composer_manager.writer.inc
Writes the composer.json file in the specified directory.
composer_manager_settings_form_validate in ./composer_manager.admin.inc
Form validation handler for composer_manager_settings_form().

File

./composer_manager.writer.inc, line 197
Functions related to the creation of the consolidated composer.json file.

Code

function composer_manager_prepare_directory($directory) {
  if (!file_check_directory($directory, FILE_CREATE_DIRECTORY)) {
    return FALSE;
  }
  if (0 === strpos($directory, file_directory_path())) {
    $htaccess_lines = "Deny from all\n\n" . file_htaccess_lines();
    if (($fp = fopen("{$directory}/.htaccess", 'w')) && fputs($fp, $htaccess_lines)) {
      fclose($fp);
      chmod($directory . '/.htaccess', 0664);
    }
    else {
      $variables = array(
        '%directory' => $directory,
        '!htaccess' => '<br />' . nl2br(check_plain($htaccess_lines)),
      );
      watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, WATCHDOG_ERROR);
    }
  }
  return TRUE;
}