You are here

function demo_get_fileconfig in Demonstration site (Sandbox / Snapshot) 6

Same name and namespace in other branches
  1. 8 demo.module \demo_get_fileconfig()
  2. 5 demo.admin.inc \demo_get_fileconfig()
  3. 7 demo.admin.inc \demo_get_fileconfig()
12 calls to demo_get_fileconfig()
demo_admin_settings in ./demo.admin.inc
Form builder for Demo module settings.
demo_autocomplete in ./demo.admin.inc
Retrieve a pipe delimited string of autocomplete suggestions for existing snapshots.
demo_delete_confirm in ./demo.admin.inc
Form builder to confirm deletion of a snapshot.
demo_delete_confirm_submit in ./demo.admin.inc
Form submit handler for demo_delete_confirm().
demo_download in ./demo.admin.inc
Transfer (download) a snapshot file.

... See full list

File

./demo.admin.inc, line 326
Demonstration Site administrative pages

Code

function demo_get_fileconfig($filename = 'demo_site') {
  $fileconfig = array();

  // Build dump path.
  $fileconfig['path'] = variable_get('demo_dump_path', file_directory_path() . '/demo');
  $fileconfig['dumppath'] = $fileconfig['path'];

  // Append site name if it is not included in file_directory_path() and if not
  // storing files in sites/all/files.
  $fileconfig['site'] = str_replace('sites', '', conf_path());
  if (strpos($fileconfig['path'], conf_path()) === FALSE && strpos($fileconfig['path'], '/all/') === FALSE) {
    $fileconfig['dumppath'] .= $fileconfig['site'];
  }

  // Check if directory exists.
  file_check_directory($fileconfig['path'], FILE_CREATE_DIRECTORY, 'path');
  if (!file_check_directory($fileconfig['dumppath'], FILE_CREATE_DIRECTORY, 'path')) {
    return FALSE;
  }

  // Protect dump files.
  $htaccess = $fileconfig['path'] . "/.htaccess";
  if (!is_file($htaccess)) {
    $htaccess_lines = "# demo.module snapshots\n# Do not let the webserver serve anything under here!\n#\nDeny from all\n";
    if (($fp = fopen($htaccess, 'w')) && fputs($fp, $htaccess_lines)) {
      fclose($fp);
      if (function_exists('drupal_chmod')) {
        drupal_chmod($htaccess);
      }
      else {
        chmod($htaccess, 0664);
      }
    }
  }

  // Build SQL filename.
  $fileconfig['sql'] = $filename . '.sql';
  $fileconfig['sqlfile'] = $fileconfig['dumppath'] . '/' . $fileconfig['sql'];

  // Build info filename.
  $fileconfig['info'] = $filename . '.info';
  $fileconfig['infofile'] = $fileconfig['dumppath'] . '/' . $fileconfig['info'];
  return $fileconfig;
}