getMessage()); } $db->query("SET NAMES utf8"); $db->query("SET NAMES utf8"); if (!$lineMode) { $string = file_get_contents($fileName); // change \r\n to fix windows issues $string = str_replace("\r\n", "\n", $string); //get rid of comments starting with # and -- $string = preg_replace("/^#[^\n]*$/m", "\n", $string); $string = preg_replace("/^(--[^-]).*/m", "\n", $string); $queries = preg_split('/;\s*$/m', $string); foreach ($queries as $query) { $query = trim($query); if (!empty($query)) { $res = &$db->query($query); if (PEAR::isError($res)) { print_r($res); die("Cannot execute $query: " . $res->getMessage()); } } } } else { $fd = fopen($fileName, "r"); while ($string = fgets($fd)) { $string = preg_replace("/^#[^\n]*$/m", "\n", $string); $string = preg_replace("/^(--[^-]).*/m", "\n", $string); $string = trim($string); if (!empty($string)) { $res = &$db->query($string); if (PEAR::isError($res)) { die("Cannot execute $string: " . $res->getMessage()); } } } } } /** * @param $config * * @return string */ function civicrm_config(&$config) { global $crmPath, $comPath; global $compileDir; global $tplPath, $installType; $params = array( 'crmRoot' => $crmPath, 'templateCompileDir' => $compileDir, 'frontEnd' => 0, 'dbUser' => addslashes($config['mysql']['username']), 'dbPass' => addslashes($config['mysql']['password']), 'dbHost' => $config['mysql']['server'], 'dbName' => addslashes($config['mysql']['database']), ); $params['baseURL'] = isset($config['base_url']) ? $config['base_url'] : civicrm_cms_base(); if ($installType == 'drupal') { if (version_compare(VERSION, '7.0-rc1') >= 0) { $params['cms'] = 'Drupal'; $params['CMSdbUser'] = addslashes($config['drupal']['username']); $params['CMSdbPass'] = addslashes($config['drupal']['password']); $params['CMSdbHost'] = $config['drupal']['server']; $params['CMSdbName'] = addslashes($config['drupal']['database']); } elseif (version_compare(VERSION, '6.0') >= 0) { $params['cms'] = 'Drupal6'; $params['CMSdbUser'] = addslashes($config['drupal']['username']); $params['CMSdbPass'] = addslashes($config['drupal']['password']); $params['CMSdbHost'] = $config['drupal']['server']; $params['CMSdbName'] = addslashes($config['drupal']['database']); } } else { $params['cms'] = 'WordPress'; $params['CMSdbUser'] = addslashes(DB_USER); $params['CMSdbPass'] = addslashes(DB_PASSWORD); $params['CMSdbHost'] = DB_HOST; $params['CMSdbName'] = addslashes(DB_NAME); // CRM-12386 $params['crmRoot'] = addslashes($params['crmRoot']); } $params['siteKey'] = md5(uniqid('', TRUE) . $params['baseURL']); $str = file_get_contents($tplPath . 'civicrm.settings.php.template'); foreach ($params as $key => $value) { $str = str_replace('%%' . $key . '%%', $value, $str); } return trim($str); } /** * @return string */ function civicrm_cms_base() { global $installType; // for drupal $numPrevious = 6; if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off' ) { $url = 'https://' . $_SERVER['HTTP_HOST']; } else { $url = 'http://' . $_SERVER['HTTP_HOST']; } $baseURL = $_SERVER['SCRIPT_NAME']; if ($installType == 'drupal') { //don't assume 6 dir levels, as civicrm //may or may not be in sites/all/modules/ //lets allow to install in custom dir. CRM-6840 global $cmsPath; $crmDirLevels = str_replace($cmsPath, '', str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME'])); $baseURL = str_replace($crmDirLevels, '', str_replace('\\', '/', $baseURL)); } elseif ($installType == 'wordpress') { $baseURL = str_replace($url, '', site_url()); } else { for ($i = 1; $i <= $numPrevious; $i++) { $baseURL = dirname($baseURL); } } // remove the last directory separator string from the directory if (substr($baseURL, -1, 1) == DIRECTORY_SEPARATOR) { $baseURL = substr($baseURL, 0, -1); } // also convert all DIRECTORY_SEPARATOR to the forward slash for windoze $baseURL = str_replace(DIRECTORY_SEPARATOR, '/', $baseURL); if ($baseURL != '/') { $baseURL .= '/'; } return $url . $baseURL; } /** * @return string */ function civicrm_home_url() { $drupalURL = civicrm_cms_base(); return $drupalURL . 'index.php?q=civicrm'; }