You are here

function demo_set_info in Demonstration site (Sandbox / Snapshot) 6

Same name and namespace in other branches
  1. 8 demo.module \demo_set_info()
  2. 5 demo.admin.inc \demo_set_info()
  3. 7 demo.admin.inc \demo_set_info()
1 call to demo_set_info()
_demo_dump in ./demo.admin.inc
Create a new snapshot.

File

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

Code

function demo_set_info($values = NULL) {
  if (isset($values['filename']) && is_array($values)) {

    // Check for valid filename
    if (!preg_match('/^[-_\\.a-zA-Z0-9]+$/', $values['filename'])) {
      drupal_set_message(t('Dump filename %title must contain alphanumeric characters, dots, dashes and underscores only. Other characters, including blanks (spaces), are not allowed.', array(
        '%title' => $values['filename'],
      )), 'error');
      return FALSE;
    }
    if (!empty($values['description'])) {

      // parse_ini_file() doesn't allow certain characters in description
      $s = array(
        "\r\n",
        "\r",
        "\n",
        '"',
      );
      $r = array(
        ' ',
        ' ',
        ' ',
        "'",
      );
      $values['description'] = str_replace($s, $r, $values['description']);
    }
    else {

      // If new description is empty, try to use previous description.
      $old_file = demo_get_fileconfig($values['filename']);
      $old_description = demo_get_info($old_file['infofile'], 'description');
      if (!empty($old_description)) {
        $values['description'] = $old_description;
      }
    }

    // Set values
    $infos = array();
    $infos['filename'] = $values['filename'];
    $infos['description'] = '"' . $values['description'] . '"';
    $infos['modules'] = implode(' ', module_list());
    $infos['version'] = DEMO_DUMP_VERSION;

    // Write information to .info file
    $fileconfig = demo_get_fileconfig($values['filename']);
    $infofile = fopen($fileconfig['infofile'], 'w');
    foreach ($infos as $key => $info) {
      fwrite($infofile, $key . ' = ' . $info . "\n");
    }
    fclose($infofile);
    return $infos;
  }
}