Project

General

Profile

Feature #24037 » 16369.diff

Administrator Admin, 2010-11-12 17:54

View differences:

t3lib/class.t3lib_install.php (working copy)
var $deletedPrefixKey = 'zzz_deleted_'; // Prefix used for tables/fields when deleted/renamed.
var $dbUpdateCheckboxPrefix = 'TYPO3_INSTALL[database_update]'; // Prefix for checkbox fields when updating database.
var $localconf_addLinesOnly = 0; // If this is set, modifications to localconf.php is done by adding new lines to the array only. If unset, existing values are recognized and changed.
var $localconf_editPointToken = 'INSTALL SCRIPT EDIT POINT TOKEN - all lines after this points may be changed by the install script!'; // If set and addLinesOnly is disabled, lines will be change only if they are after this token (on a single line!) in the file
// If set and addLinesOnly is disabled, lines will be change only if they are after this token (on a single line!) in the file
public $startToken = '## INSTALL SCRIPT EDIT POINT TOKEN - all lines after this points may be changed by the install script!';
// If set and addLinesOnly is disabled, lines will be change only if they are before this token (on a single line!) in the file
public $endToken = '## INSTALL SCRIPT EDIT END POINT TOKEN - all lines before this points may be changed by the install script!';
var $allowUpdateLocalConf = 0; // If true, this class will allow the user to update the localconf.php file. Is set true in the init.php file.
var $backPath = '../'; // Backpath (used for icons etc.)
......
/**
* This functions takes an array with lines from localconf.php, finds a variable and inserts the new value.
*
* @param array $line_array the localconf.php file exploded into an array by linebreaks. (see writeToLocalconf_control())
* @param array $lineArray the localconf.php file exploded into an array by linebreaks. (see writeToLocalconf_control())
* @param string $variable The variable name to find and substitute. This string must match the first part of a trimmed line in the line-array. Matching is done backwards so the last appearing line will be substituted.
* @param string $value Is the value to be insert for the variable
* @param boolean $quoteValue Whether the given value should be quoted before being written
* @return void
* @see writeToLocalconf_control()
*/
public function setValueInLocalconfFile(&$line_array, $variable, $value, $quoteValue = TRUE) {
if (!$this->checkForBadString($value)) return 0;
public function setValueInLocalconfFile(&$lineArray, $variable, $value, $quoteValue = TRUE) {
if (!$this->checkForBadString($value)) {
return 0;
}
// Initialize:
$found = 0;
$this->touchedLine = '';
$commentKey = '## ';
$inArray = in_array($commentKey.$this->localconf_editPointToken,$line_array);
$tokenSet = ($this->localconf_editPointToken && !$inArray); // Flag is set if the token should be set but is not yet...
$stopAtToken = ($this->localconf_editPointToken && $inArray);
$comment = ' Modified or inserted by '.$this->updateIdentity.'.';
$setToken = ($this->startToken && !in_array($this->startToken, $lineArray));
$noTokenExists = !(in_array($this->startToken, $lineArray) || in_array($this->endToken, $lineArray));
$comment = ' Modified or inserted by ' . $this->updateIdentity . '.';
$replace = array('["', '"]');
$search = array('[\'', '\']');
$varDoubleQuotes = str_replace($search, $replace, $variable);
// Search for variable name:
if (!$this->localconf_addLinesOnly && !$tokenSet) {
$line_array = array_reverse($line_array);
foreach($line_array as $k => $v) {
// Split lines into three parts: above, below and between the edit tokens
$splittedLines = $this->splitArrayByTokens($lineArray);
$lineArray = $splittedLines[1];
// Replace variable
if (!$this->localconf_addLinesOnly && !$setToken) {
$lineArray = array_reverse($lineArray);
foreach($lineArray as $k => $v) {
$v2 = trim($v);
if ($stopAtToken && !strcmp($v2,$commentKey.$this->localconf_editPointToken)) break; // If stopAtToken and token found, break out of the loop..
if (!strcmp(substr($v2,0,strlen($variable.' ')),$variable.' ')) {
$mainparts = explode($variable,$v,2);
if (count($mainparts)==2) { // should ALWAYS be....
$subparts = explode('//',$mainparts[1],2);
if ($quoteValue) {
$value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
}
$line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('//' . $comment . str_replace($comment, '', $subparts[1]));
$this->touchedLine = count($line_array)-$k-1;
if (!strcmp(substr($v2, 0, strlen($variable . ' ')), $variable . ' ')) {
$mainparts = explode($variable, $v, 2);
if (count($mainparts) == 2) { // should ALWAYS be....
$subparts = explode('//', $mainparts[1], 2);
$value = ($quoteValue) ? '\'' . $this->slashValueForSingleDashes($value) . '\'' : $value;
$lineArray[$k] = $mainparts[0] . $variable . ' = ' . $value . '; ' . ('//' . $comment . str_replace($comment, '', $subparts[1]));
$this->touchedLine = count($lineArray) - $k - 1;
$found = 1;
break;
}
......
$mainparts = explode($varDoubleQuotes, $v, 2);
if (count($mainparts) == 2) { // should ALWAYS be....
$subparts = explode('//', $mainparts[1], 2);
if ($quoteValue) {
$value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
}
$line_array[$k] = $mainparts[0] . $variable . " = " . $value . "; " . ('//' . $comment . str_replace($comment, '', $subparts[1]));
$this->touchedLine = count($line_array) - $k - 1;
$value = ($quoteValue) ? '\'' . $this->slashValueForSingleDashes($value) . '\'' : $value;
$lineArray[$k] = $mainparts[0] . $variable . ' = ' . $value . '; ' . ('//' . $comment . str_replace($comment, '', $subparts[1]));
$this->touchedLine = count($lineArray) - $k - 1;
$found = 1;
break;
}
}
}
$line_array = array_reverse($line_array);
$lineArray = array_reverse($lineArray);
}
if (!$found) {
if ($tokenSet) {
$line_array[] = $commentKey.$this->localconf_editPointToken;
$line_array[] = '';
// Add variable
if (!$found) {
if ($noTokenExists) {
$lineArray[] = $this->startToken;
$lineArray[] = '';
}
if ($quoteValue) {
$value = '\'' . $this->slashValueForSingleDashes($value) . '\'';
}
$line_array[] = $variable . " = " . $value . "; // " . $comment;
$value = ($quoteValue) ? '\'' . $this->slashValueForSingleDashes($value) . '\'' : $value;
$lineArray[] = $variable . ' = ' . $value . '; // ' . $comment;
$this->touchedLine = -1;
}
if ($variable == '$typo_db_password') {
$this->messages[] = 'Updated ' . $variable;
} else {
$this->messages[] = $variable . " = " . htmlspecialchars($value);
$this->messages[] = $variable . ' = ' . htmlspecialchars($value);
}
$this->setLocalconf = 1;
// Merge all fields
$lineArray = array_merge($splittedLines[0], $lineArray, $splittedLines[2]);
}
/**
......
$lines = explode(LF,str_replace(CR,'',trim(t3lib_div::getUrl($writeToLocalconf_dat['file']))));
$writeToLocalconf_dat['endLine'] = array_pop($lines); // Getting "? >" ending.
// Split lines into three parts: above, below and between the edit tokens
$splittedLines = $this->splitArrayByTokens($lines);
$lines = $splittedLines[1];
// Checking if "updated" line was set by this tool - if so remove old line.
$updatedLine = array_pop($lines);
$writeToLocalconf_dat['updatedText'] = '// Updated by '.$this->updateIdentity.' ';
......
}
if (is_array($inlines)) { // Setting a line and write:
$splittedInlines = $this->splitArrayByTokens($inlines);
// Setting configuration
$updatedLine = $writeToLocalconf_dat['updatedText'].date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' H:i:s');
array_push($inlines,$updatedLine);
array_push($inlines,$writeToLocalconf_dat['endLine']);
$updatedLine = $writeToLocalconf_dat['updatedText'] . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' H:i:s');
array_push($splittedInlines[1], $updatedLine);
// Add edit end token, if it does not yet exist
if (empty($splittedInlines[2])) {
$splittedInlines[2][] = $this->endToken;
}
$inlines = array_merge($splittedInlines[0], $splittedInlines[1], $splittedInlines[2]);
array_push($inlines, $writeToLocalconf_dat['endLine']);
if ($this->setLocalconf) {
$success = FALSE;
......
return 'nochange';
}
} else { // Return lines found in localconf.php
return $lines;
return array_merge($splittedLines[0], $lines, $splittedLines[2]);
}
}
/**
* Split array into three parts: fields above the edit token, below edit token and between
*
* @param array $fields Array to split
* @return array Two-dimensional array with the three parts
*/
public function splitArrayByTokens($fields = array()) {
$results = array();
$first = 0;
$total = count($fields);
$offset = $total;
$startTokenPos = array_search($this->startToken, $fields);
$endTokenPos = array_search($this->endToken, $fields);
// Find first field after edit start token
if ($startTokenPos !== FALSE) {
$first = $startTokenPos + 1;
}
// Calculate number of fields between start and end token
if ($endTokenPos !== FALSE) {
$offset = $endTokenPos - $first;
}
// Fields above the editable area
$results[] = array_slice($fields, 0, $first, TRUE);
// Fields in the editable area
$results[] = array_slice($fields, $first, $offset, TRUE);
// Fields below the editable area
if ($endTokenPos !== FALSE) {
$results[] = array_slice($fields, $endTokenPos, $total - $endTokenPos, TRUE);
} else {
// Compat if no end token
$results[] = array();
}
return $results;
}
/**
* Checking for linebreaks in the string
*
* @param string String to test
(1-1/2)