1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[feature/sphinx-fulltext-search] fix comments

PHPBB3-10946
This commit is contained in:
Dhruv Goel
2012-07-10 05:51:52 +05:30
committed by Dhruv
parent 537a16220e
commit fdb7e64e29
3 changed files with 53 additions and 39 deletions

View File

@@ -49,7 +49,7 @@ class phpbb_search_sphinx_config
{
for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++)
{
// make sure this is really a section object and not a comment
// Make sure this is really a section object and not a comment
if (($this->sections[$i] instanceof phpbb_search_sphinx_config_section) && $this->sections[$i]->get_name() == $name)
{
return $this->sections[$i];
@@ -76,7 +76,7 @@ class phpbb_search_sphinx_config
*/
function read($filename)
{
// split the file into lines, we'll process it line by line
// Split the file into lines, we'll process it line by line
$config_file = file($filename);
$this->sections = array();
@@ -87,8 +87,8 @@ class phpbb_search_sphinx_config
foreach ($config_file as $i => $line)
{
// if the value of a variable continues to the next line because the line break was escaped
// then we don't trim leading space but treat it as a part of the value
/* If the value of a variable continues to the next line because the line
break was escaped then we don't trim leading space but treat it as a part of the value */
if ($in_value)
{
$line = rtrim($line);
@@ -98,11 +98,11 @@ class phpbb_search_sphinx_config
$line = trim($line);
}
// if we're not inside a section look for one
// If we're not inside a section look for one
if (!$section)
{
// add empty lines and comments as comment objects to the section list
// that way they're not deleted when reassembling the file from the sections
/* add empty lines and comments as comment objects to the section list
that way they're not deleted when reassembling the file from the sections*/
if (!$line || $line[0] == '#')
{
$this->sections[] = new phpbb_search_sphinx_config_comment($config_file[$i]);
@@ -110,8 +110,8 @@ class phpbb_search_sphinx_config
}
else
{
// otherwise we scan the line reading the section name until we find
// an opening curly bracket or a comment
/* otherwise we scan the line reading the section name until we find
an opening curly bracket or a comment */
$section_name = '';
$section_name_comment = '';
$found_opening_bracket = false;
@@ -137,28 +137,29 @@ class phpbb_search_sphinx_config
$section_name .= $line[$j];
}
// and then we create the new section object
// And then we create the new section object
$section_name = trim($section_name);
$section = new phpbb_search_sphinx_config_section($section_name, $section_name_comment);
}
}
else // if we're looking for variables inside a section
else
{
// If we're looking for variables inside a section
$skip_first = false;
// if we're not in a value continuing over the line feed
// If we're not in a value continuing over the line feed
if (!$in_value)
{
// then add empty lines and comments as comment objects to the variable list
// of this section so they're not deleted on reassembly
/* then add empty lines and comments as comment objects to the variable list
of this section so they're not deleted on reassembly */
if (!$line || $line[0] == '#')
{
$section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i]));
continue;
}
// as long as we haven't yet actually found an opening bracket for this section
// we treat everything as comments so it's not deleted either
/* As long as we haven't yet actually found an opening bracket for this section
we treat everything as comments so it's not deleted either */
if (!$found_opening_bracket)
{
if ($line[0] == '{')
@@ -175,7 +176,8 @@ class phpbb_search_sphinx_config
}
}
// if we did not find a comment in this line or still add to the previous line's value ...
/* If we did not find a comment in this line or still add to the previous
line's value ... */
if ($line || $in_value)
{
if (!$in_value)
@@ -226,21 +228,24 @@ class phpbb_search_sphinx_config
{
$value .= "\n";
$in_value = true;
continue 2; // go to the next line and keep processing the value in there
// Go to the next line and keep processing the value in there
continue 2;
}
$value .= $line[$j];
}
}
// if a name and an equal sign were found then we have append a new variable object to the section
/* If a name and an equal sign were found then we have append a
new variable object to the section */
if ($name && $found_assignment)
{
$section->add_variable(new phpbb_search_sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment));
continue;
}
// if we found a closing curly bracket this section has been completed and we can append it to the section list
// and continue with looking for the next section
/* if we found a closing curly bracket this section has been completed
and we can append it to the section list and continue with looking for
the next section */
if ($end_section)
{
$section->set_end_comment($comment);
@@ -250,13 +255,14 @@ class phpbb_search_sphinx_config
}
}
// if we did not find anything meaningful up to here, then just treat it as a comment
/* If we did not find anything meaningful up to here, then just treat it
as a comment */
$comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i];
$section->add_variable(new phpbb_search_sphinx_config_comment($comment));
}
}
// keep the filename for later use
// Keep the filename for later use
$this->loaded = $filename;
}

View File

@@ -79,7 +79,7 @@ class phpbb_search_sphinx_config_section
{
for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)
{
// make sure this is a variable object and not a comment
// Make sure this is a variable object and not a comment
if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name)
{
return $this->variables[$i];
@@ -96,7 +96,7 @@ class phpbb_search_sphinx_config_section
{
for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)
{
// make sure this is a variable object and not a comment
// Make sure this is a variable object and not a comment
if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name)
{
array_splice($this->variables, $i, 1);
@@ -127,7 +127,7 @@ class phpbb_search_sphinx_config_section
{
$content = $this->name . ' ' . $this->comment . "\n{\n";
// make sure we don't get too many newlines after the opening bracket
// Make sure we don't get too many newlines after the opening bracket
while (trim($this->variables[0]->to_string()) == '')
{
array_shift($this->variables);