/** * This function returns the value of a parameter from the configuration file * * WARNING - this function relies heavily on global variables $updateFromConfigFile * and $configFile, and also changes these globals. This can be rewritten. * * @param string $param the parameter of which the value is returned * @param string If we want to give the path rather than take it from POST * @return string the value of the parameter * @author Olivier Brouckaert * @author Reworked by Ivan Tcholakov, 2010 */ function get_config_param($param, $updatePath = '') { global $configFile, $updateFromConfigFile; // Look if we already have the queried parameter. if (is_array($configFile) && isset($configFile[$param])) { return $configFile[$param]; } if (empty($updatePath) && !empty($_POST['updatePath'])) { $updatePath = $_POST['updatePath']; } if (empty($updatePath)) { $updatePath = api_get_path(SYS_PATH); } $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath))); $updateFromInstalledVersionFile = ''; if (empty($updateFromConfigFile)) { // If update from previous install was requested, // try to recover old config file from dokeos 1.8.x. if (file_exists($updatePath.'main/inc/conf/configuration.php')) { $updateFromConfigFile = 'main/inc/conf/configuration.php'; } elseif (file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php')) { $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php'; } else { // Give up recovering. //error_log('Chamilo Notice: Could not find previous config file at '.$updatePath.'main/inc/conf/configuration.php nor at '.$updatePath.'claroline/inc/conf/claro_main.conf.php in get_config_param(). Will start new config (in '.__FILE__.', line '.__LINE__.')', 0); return null; } } if (file_exists($updatePath.$updateFromConfigFile) && !is_dir($updatePath.$updateFromConfigFile)) { // The parameter was not found among the global variables, so look into the old configuration file. // Make sure the installedVersion file is read first so it is overwritten // by the config file if the config file contains the version (from 1.8.4). $config_data_2 = array(); if (file_exists($updatePath.$updateFromInstalledVersionFile)) { $config_data_2 = file_to_array($updatePath.$updateFromInstalledVersionFile); } $configFile = array(); $config_data = file_to_array($updatePath.$updateFromConfigFile); $config_data = array_merge($config_data, $config_data_2); $val = ''; // Parse the configuration file, statement by statement (line by line, actually). foreach ($config_data as $php_statement) { if (strpos($php_statement, '=') !== false) { // Variable assignment statement have been detected (probably). // It is expected to be as follows: // $variable = 'some_value'; // A comment that is not mandatory. // Split the statement into its left and right sides. $php_statement = explode('=', $php_statement); $variable = trim($php_statement[0]); $value = $php_statement[1]; if (substr($variable, 0, 1) == '$') { // We have for sure a php variable assignment detected. // On the left side: Retrieve the pure variable's name $variable = trim(str_replace('$', '', $variable)); // On the right side: Remove the comment, if it exists. list($value) = explode(' //', $value); // Remove extra whitespace, if any. Remove the trailing semicolon (;). $value = substr(trim($value), 0, -1); // Remove surroundig quotes, restore escaped quotes. $value = str_replace('\"', '"', preg_replace('/^"|"$/', '', $value)); $value = str_replace('\'', '"', preg_replace('/^\'|\'$/', '', $value)); if (strtolower($value) == 'true') { // A boolean true value have been recognized. $value = 1; } elseif (strtolower($value) == 'false') { // A boolean false value have been recognized. $value = 0; } else { // Probably we have a string value, but also we have to check // possible string concatenations that may include string values // and other configuration variables. I this case we have to // get the calculated result of the concatenation. $implode_string = ' '; if (!strstr($value, '." ".') && strstr($value, '.$')) { // Yes, there is concatenation, insert a special separator string. $value = str_replace('.$', '." ".$', $value); $implode_string = ''; } // Split the concatenated values, if they are more than one. $sub_strings = explode('." ".', $value); // Seek for variables and retrieve their values. foreach ($sub_strings as $key => & $sub_string) { if (preg_match('/^\$[a-zA-Z_][a-zA-Z0-9_]*$/', $sub_string)) { // A variable has been detected, read it by recursive call. $sub_string = get_config_param(str_replace('$', '', $sub_string)); } } // Concatenate everything into the final, the calculated string value. $value = implode($implode_string, $sub_strings); } // Cache the result value. $configFile[$variable] = $value; $a = explode("'", $variable); $key_tmp = isset($a[1]) ? $a[1] : null; if ($key_tmp == $param) { $val = $value; } } } } } if($param == 'dbGlu' && empty($val)){ return '`.`'; } //Special treatment for dokeos_version parameter due to Dokeos 1.8.3 have the dokeos_version in the main/inc/installedVersion.inc.php file if ($param == 'dokeos_version') { //dokeos_version from configuration.php if empty $dokeos_version = $val; if (empty($dokeos_version)) { //checking the dokeos_version value exists in main/inc/installedVersion.inc.php if (file_exists($updatePath.'main/inc/installedVersion.inc.php')) { $updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php'; require ($updateFromInstalledVersionFile); //there are only 2 variables here: $stable & $dokeos_version $stable = false; } } return $dokeos_version; } else { if (file_exists($updatePath.$updateFromConfigFile)) { return $val; } else { error_log('Config array could not be found in get_config_param()', 0); return null; } } }
/** * examine() * * - Loads in the structure of a fresh SMF install via sql_to_array * - Looks at each table in the current installation and determines if it is a default table * and if so finds extra columns or indexes that should be removed. * * @return */ function examine() { global $smcFunc, $db_prefix, $extra, $table_prefix, $version; // will allow for this == THIS and thisVar == this_var on col / index names to avoid false positives, set to true for more hits $strict_case = false; $tables = sql_to_array(dirname(__FILE__) . '/sql' . $version . '.sql'); $mset = file_to_array(dirname(__FILE__) . '/modsettings' . $version . '.txt'); $real_prefix = preg_match('~^(`?)(.+?)\\1\\.(.*?)$~', $db_prefix, $match) === 1 ? $match[3] : $db_prefix; $extra = array(); // make sure this is gone for a clean run if (isset($_SESSION['db_cleaner'])) { unset($_SESSION['db_cleaner']); } // examine each table in this installation $current_tables = $smcFunc['db_list_tables'](); foreach ($current_tables as $table) { $table = preg_replace('~^' . $real_prefix . '~', '', $table); // Table itself does not exist in a fresh install if (!isset($tables[$table])) { $extra['tables'][] = $table; continue; } // It exists in a fresh install, lets check if there are any extra columns in it $current_columns = $smcFunc['db_list_columns']($table_prefix . $table, false); foreach ($current_columns as $column) { if (!isset($tables[$table]['columns'][$column]) && $strict_case) { $extra['columns'][$table][] = $column; } elseif (!$strict_case && !isset($tables[$table]['columns'][strtolower($column)])) { $extra['columns'][$table][] = $column; } } // or extra indexes taking up space $current_indexes = $smcFunc['db_list_indexes']($table_prefix . $table, true); foreach ($current_indexes as $key => $index) { if (!isset($tables[$table]['indexes'][$key])) { // keys don't match ... v1 to v2 upgrade appears to reuse old smf1 index names (upper or camel) .. if ($version == 2 && $key != 'PRIMARY' && !$strict_case) { // lets see if a lowercase or camelCase version of the key will work $tempkey = isset($tables[$table]['indexes'][strtolower($key)]) ? strtolower($key) : (isset($tables[$table]['indexes'][unCamelCase($key)]) ? unCamelCase($key) : ''); if (!empty($tempkey)) { // Probably found it, but are the index type and index cols exactly the same as well? if ($current_indexes[$key]['type'] != $tables[$table]['indexes'][$tempkey]['type'] || count(array_diff($current_indexes[$key]['columns'], $tables[$table]['indexes'][$tempkey]['columns'])) != 0) { unset($tempkey); } } if (empty($tempkey)) { $extra['indexes'][$table][] = $index; } } else { $extra['indexes'][$table][] = $index; } } } } // modSettings that are not from standard SMF $current_settings = array(); $request = $smcFunc['db_query']('', ' SELECT variable FROM {db_prefix}settings', array()); while ($row = $version == 1 ? mysql_fetch_row($request) : $smcFunc['db_fetch_row']($request)) { $current_settings[$row[0]] = $row[0]; } $version == 1 ? mysql_free_result($request) : $smcFunc['db_free_result']($request); // check what could be there vs what it ;) foreach ($current_settings as $mod) { if (!isset($mset[$mod])) { // check for a multi settings like bbc or integration tags $submod = explode('_', $mod); if (isset($mset[$submod[0] . '_']) && strpos($mod, $mset[$submod[0] . '_']) == 0) { continue; } $extra['settings'][] = $mod; } } }
/** * examine() * * - Loads in the structure of a fresh SMF install via sql_to_array * - Looks at each table in the current installation and determines if it is a default table * and if so finds extra columns or indexes that should be removed. * * @return */ function examine() { global $db_prefix, $extra, $table_prefix; $db = database(); $table_db = db_table(); // Will allow for this == THIS and thisVar == this_var on col / index names to avoid false positives, set to true for more hits $strict_case = false; // Load in our standards files $tables = sql_to_array(dirname(__FILE__) . '/install_sql.sql'); // Some tables are created not installed, others? $tables['log_search_words'] = array('indexes' => array('PRIMARY' => array('name' => 'PRIMARY', 'type' => 'primary', 'columns' => 'id_word, id_msg')), 'columns' => array('id_word' => array('name' => 'id_word'), 'id_msg' => array('name' => 'id_msg'))); // All of the known modSettings $mset = file_to_array(dirname(__FILE__) . '/modsettings.txt'); $real_prefix = preg_match('~^(`?)(.+?)\\1\\.(.*?)$~', $db_prefix, $match) === 1 ? $match[3] : $db_prefix; $extra = array(); // Make sure this is gone for a clean run if (isset($_SESSION['db_cleaner'])) { unset($_SESSION['db_cleaner']); } // Examine each table in this installation $current_tables = $db->db_list_tables(); foreach ($current_tables as $table) { $table = preg_replace('~^' . $real_prefix . '~', '', $table); // Table itself does not exist in a fresh install if (!isset($tables[$table])) { $extra['tables'][] = $table; continue; } // It exists in a fresh install, lets check if there are any extra columns in it $current_columns = $table_db->db_list_columns($table_prefix . $table, false); foreach ($current_columns as $column) { if (!isset($tables[$table]['columns'][$column]) && $strict_case) { $extra['columns'][$table][] = $column; } elseif (!$strict_case && !isset($tables[$table]['columns'][strtolower($column)])) { $extra['columns'][$table][] = $column; } } // Or extra indexes taking up space $current_indexes = $table_db->db_list_indexes($table_prefix . $table, true); foreach ($current_indexes as $key => $index) { if (!isset($tables[$table]['indexes'][$key])) { // keys don't match, upgrade issue? if ($key != 'PRIMARY' && !$strict_case) { // lets see if a lowercase or camelCase version of the key will work $tempkey = isset($tables[$table]['indexes'][strtolower($key)]) ? strtolower($key) : (isset($tables[$table]['indexes'][unCamelCase($key)]) ? unCamelCase($key) : ''); if (!empty($tempkey)) { // Probably found it, but are the index type and index cols exactly the same as well? if ($current_indexes[$key]['type'] != $tables[$table]['indexes'][$tempkey]['type'] || count(array_diff($current_indexes[$key]['columns'], $tables[$table]['indexes'][$tempkey]['columns'])) != 0) { unset($tempkey); } } if (empty($tempkey)) { $extra['indexes'][$table][] = $index; } } else { $extra['indexes'][$table][] = $index; } } } } // modSettings that are not from standard Elkarte $current_settings = array(); $request = $db->query('', ' SELECT variable FROM {db_prefix}settings', array()); while ($row = $db->fetch_row($request)) { $current_settings[$row[0]] = $row[0]; } $db->free_result($request); // Check what could be there vs what it ;) foreach ($current_settings as $mod) { if (!isset($mset[$mod])) { // check for a multi settings like bbc or integration tags $submod = explode('_', $mod); if (isset($mset[$submod[0] . '_']) && strpos($mod, $mset[$submod[0] . '_']) == 0) { continue; } $extra['settings'][] = $mod; } } }