diff --git a/.gitignore b/.gitignore
index 871d17b386..8298f5a894 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,12 @@
*~
+phpunit.xml
phpBB/cache/*.php
+phpBB/cache/queue.php.lock
phpBB/config.php
phpBB/files/*
+phpBB/images/avatars/gallery/*
phpBB/images/avatars/upload/*
phpBB/store/*
tests/phpbb_unit_tests.sqlite2
tests/test_config.php
+tests/utf/data/*.txt
diff --git a/README.md b/README.md
new file mode 100644
index 0000000000..6b94f898a3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+[](http://www.phpbb.com)
+
+## ABOUT
+
+phpBB is a free bulletin board written in PHP.
+
+## COMMUNITY
+
+Find support and lots more on [phpBB.com](http://www.phpbb.com)! Discuss the development on [area51](http://area51.phpbb.com/phpBB/index.php).
+
+## CONTRIBUTE
+
+1. [Create an account on phpBB.com](http://www.phpbb.com/community/ucp.php?mode=register)
+2. [Create a ticket (unless there already is one)](http://tracker.phpbb.com/secure/CreateIssue!default.jspa)
+3. [Read our Git Contribution Guidelines](http://wiki.phpbb.com/Git); if you're new to git, also read [the introduction guide](http://wiki.phpbb.com/display/DEV/Working+with+Git)
+4. Send us a pull request
+
+## LICENSE
+
+[GNU General Public License v2](http://opensource.org/licenses/gpl-2.0.php)
diff --git a/build/build.xml b/build/build.xml
index bf77d82f6c..78dbdd379c 100644
--- a/build/build.xml
+++ b/build/build.xml
@@ -2,9 +2,9 @@
-
-
-
+
+
+
@@ -12,7 +12,8 @@
-
+
+
@@ -42,12 +43,11 @@
-
-
+
@@ -64,6 +64,18 @@
-->
+
+
+
+
+
@@ -121,7 +133,7 @@
-->
@@ -129,8 +141,8 @@
-
-
+
+
diff --git a/build/build_helper.php b/build/build_helper.php
index 94fc0ff3b5..2d9b86b3c3 100644
--- a/build/build_helper.php
+++ b/build/build_helper.php
@@ -177,7 +177,7 @@ class build_package
}
// Is binary?
- if (preg_match('/^Binary files ' . $package_name . '\/(.*) and [a-z0-9_-]+\/\1 differ/i', $line, $match))
+ if (preg_match('/^Binary files ' . $package_name . '\/(.*) and [a-z0-9._-]+\/\1 differ/i', $line, $match))
{
$binary[] = trim($match[1]);
}
diff --git a/build/phpdoc-phpbb.ini b/build/phpdoc-phpbb.ini
new file mode 100644
index 0000000000..f1a7a4bee5
--- /dev/null
+++ b/build/phpdoc-phpbb.ini
@@ -0,0 +1,145 @@
+; Default configuration file for PHPDoctor
+
+; This config file will cause PHPDoctor to generate API documentation of
+; itself.
+
+
+; PHPDoctor settings
+; -----------------------------------------------------------------------------
+
+; Names of files to parse. This can be a single filename, or a comma separated
+; list of filenames. Wildcards are allowed.
+
+files = "*.php"
+
+; Names of files or directories to ignore. This can be a single filename, or a
+; comma separated list of filenames. Wildcards are NOT allowed.
+
+;ignore = "CVS, .svn, .git, _compiled"
+ignore = templates_c/,*HTML/default/*,spec/,*config.php*,*CVS/,test_chora.php,testupdate/,cache/,store/,*proSilver/,develop/,includes/utf/data/,includes/captcha/fonts/,install/update/,install/update.new/,files/,*phpinfo.php*,*update_script.php*,*upgrade.php*,*convert.php*,install/converter/,language/de/,script/,*swatch.php*,*test.php*,*test2.php*,*install.php*,*functions_diff.php*,*acp_update.php*,acm_xcache.php
+
+; The directory to look for files in, if not used the PHPDoctor will look in
+; the current directory (the directory it is run from).
+
+source_path = "../phpBB/"
+
+; If you do not want PHPDoctor to look in each sub directory for files
+; uncomment this line.
+
+;subdirs = off
+
+; Set how loud PHPDoctor is as it runs. Quiet mode suppresses all output other
+; than warnings and errors. Verbose mode outputs additional messages during
+; execution.
+
+quiet = on
+;verbose = on
+
+; Select the doclet to use for generating output.
+
+doclet = standard
+;doclet = debug
+
+; The directory to find the doclet in. Doclets control the HTML output of
+; phpDoctor and can be modified to suit your needs. They are expected to be
+; in a directory named after themselves at the location given.
+
+;doclet_path = ./doclets
+
+; Select the formatter to use for generating output.
+
+;formatter = htmlStandardFormatter
+
+; The directory to find the formatter in. Formatters convert textual markup
+; for use by the doclet.
+
+;formatter_path = ./formatters
+
+; The directory to find taglets in. Taglets allow you to make PHPDoctor handle
+; new tags and to alter the behavour of existing tags and their output.
+
+;taglet_path = ./taglets
+
+; If the code you are parsing does not use package tags or not all elements
+; have package tags, use this setting to place unbound elements into a
+; particular package.
+
+default_package = "phpBB"
+
+use_class_path_as_package = off
+
+ignore_package_tags = off
+
+; Specifies the name of a HTML file containing text for the overview
+; documentation to be placed on the overview page. The path is relative to
+; "source_path" unless an absolute path is given.
+
+overview = ../README.md
+
+; Package comments will be looked for in a file named package.html in the same
+; directory as the first source file parsed in that package or in the directory
+; given below. If package comments are placed in the directory given below then
+; they should be named ".html".
+
+package_comment_dir = ./
+
+; Parse out global variables and/or global constants?
+
+;globals = off
+;constants = off
+
+; Generate documentation for all class members
+
+;private = on
+
+; Generate documentation for public and protected class members
+
+;protected = on
+
+; Generate documentation for only public class members
+
+;public = on
+
+; Use the PEAR compatible handling of the docblock first sentence
+
+;pear_compat = on
+
+; Standard doclet settings
+; -----------------------------------------------------------------------------
+
+; The directory to place generated documentation in. If the given path is
+; relative to it will be relative to "source_path".
+
+d = "../build/api/"
+
+; Specifies the title to be placed in the HTML tag.
+
+windowtitle = "phpBB3"
+
+; Specifies the title to be placed near the top of the overview summary file.
+
+doctitle = "phpBB3 Sourcecode Documentation"
+
+; Specifies the header text to be placed at the top of each output file. The
+; header will be placed to the right of the upper navigation bar.
+
+header = "phpBB3"
+
+; Specifies the footer text to be placed at the bottom of each output file. The
+; footer will be placed to the right of the lower navigation bar.
+
+footer = "phpBB3"
+
+; Specifies the text to be placed at the bottom of each output file. The text
+; will be placed at the bottom of the page, below the lower navigation bar.
+
+;bottom = "This document was generated by PHPDoctor: The PHP Documentation Creator"
+
+; Create a class tree?
+
+;tree = off
+
+; Use GeSHi to include formatted source files in the documentation. PHPDoctor will look in the current doclet directory for a /geshi subdirectory. Unpack the GeSHi archive from http://qbnz.com/highlighter to get this directory - it will contain a php script and a subdirectory with formatting files.
+
+include_source = off
+
diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg
index a6777ff9c9..4f6ae71d4b 100755
--- a/git-tools/hooks/commit-msg
+++ b/git-tools/hooks/commit-msg
@@ -55,12 +55,24 @@ quit()
fi
}
-msg=$(grep -nE '.{81,}' "$1");
+# Check for empty commit message
+if ! grep -qv '^#' "$1"
+then
+ # Commit message is empty (or contains only comments).
+ # Let git handle this.
+ # It will abort with a message like so:
+ #
+ # Aborting commit due to empty commit message.
+ exit 0
+fi
+
+msg=$(grep -v '^#' "$1" |grep -nE '.{81,}')
if [ $? -eq 0 ]
then
- echo "The following lines are greater than 80 characters long:\n" >&2;
- echo $msg >&2;
+ echo "The following lines are greater than 80 characters long:" >&2;
+ echo >&2
+ echo "$msg" >&2;
quit $ERR_LENGTH;
fi
@@ -107,7 +119,19 @@ do
case $expect in
"header")
err=$ERR_HEADER;
- echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] [A-Z].+$"
+ echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] .+$"
+ result=$?
+ if ! echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] [A-Z].+$"
+ then
+ # Don't be too strict.
+ # Commits may be temporary, intended to be squashed later.
+ # Just issue a warning here.
+ echo "Warning: heading should be a sentence beginning with a capital letter." 1>&2
+ echo "You entered:" 1>&2
+ echo "$line" 1>&2
+ fi
+ # restore exit code
+ (exit $result)
;;
"empty")
err=$ERR_EMPTY;
@@ -128,6 +152,10 @@ do
# Should not end up here
false
;;
+ "possibly-eof")
+ # Allow empty and/or comment lines at the end
+ ! tail -n +"$i" "$1" |grep -qvE '^($|#)'
+ ;;
"comment")
echo "$line" | grep -Eq "^#";
;;
@@ -188,7 +216,7 @@ do
in_description=1;
;;
"footer")
- expecting="footer eof";
+ expecting="footer possibly-eof";
if [ "$tickets" = "" ]
then
tickets="$line";
@@ -199,6 +227,9 @@ do
"comment")
# Comments should expect the same thing again
;;
+ "possibly-eof")
+ expecting="eof";
+ ;;
*)
echo "Unrecognised token $expect" >&2;
quit 254;
diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg
index 2bf25e58a4..11d2b6b2f2 100755
--- a/git-tools/hooks/prepare-commit-msg
+++ b/git-tools/hooks/prepare-commit-msg
@@ -35,8 +35,8 @@ then
# Branch is prefixed with 'ticket/', append ticket ID to message
if [ "$branch" != "${branch##ticket/}" ];
then
- tail="\n\nPHPBB3-${branch##ticket/}";
+ tail="$(printf "\n\nPHPBB3-${branch##ticket/}")";
fi
- echo "[$branch]$tail $(cat "$1")" > "$1"
+ echo "[$branch] $tail$(cat "$1")" > "$1"
fi
diff --git a/git-tools/merge.php b/git-tools/merge.php
new file mode 100755
index 0000000000..cbd84b896f
--- /dev/null
+++ b/git-tools/merge.php
@@ -0,0 +1,175 @@
+#!/usr/bin/env php
+getMessage();
+ exit($e->getCode());
+}
+
+function work($pull_id, $remote)
+{
+ // Get some basic data
+ $pull = get_pull('phpbb', 'phpbb3', $pull_id);
+
+ if (!$pull_id)
+ {
+ show_usage();
+ }
+
+ if ($pull['state'] != 'open')
+ {
+ throw new RuntimeException(sprintf("Error: pull request is closed\n",
+ $target_branch), 5);
+ }
+
+ $pull_user = $pull['head'][0];
+ $pull_branch = $pull['head'][1];
+ $target_branch = $pull['base'][1];
+
+ switch ($target_branch)
+ {
+ case 'develop-olympus':
+ run("git checkout develop-olympus");
+ run("git pull $remote develop-olympus");
+
+ add_remote($pull_user, 'phpbb3');
+ run("git fetch $pull_user");
+ run("git merge --no-ff $pull_user/$pull_branch");
+ run("phpunit");
+
+ run("git checkout develop");
+ run("git pull $remote develop");
+ run("git merge --no-ff develop-olympus");
+ run("phpunit");
+ break;
+
+ case 'develop':
+ run("git checkout develop");
+ run("git pull $remote develop");
+
+ add_remote($pull_user, 'phpbb3');
+ run("git fetch $pull_user");
+ run("git merge --no-ff $pull_user/$pull_branch");
+ run("phpunit");
+ break;
+
+ default:
+ throw new RuntimeException(sprintf("Error: pull request target branch '%s' is not a main branch\n",
+ $target_branch), 5);
+ break;
+ }
+}
+
+function add_remote($username, $repository, $pushable = false)
+{
+ $url = get_repository_url($username, $repository, false);
+ run("git remote add $username $url", true);
+
+ if ($pushable)
+ {
+ $ssh_url = get_repository_url($username, $repository, true);
+ run("git remote set-url --push $username $ssh_url");
+ }
+}
+
+function get_repository_url($username, $repository, $ssh = false)
+{
+ $url_base = ($ssh) ? 'git@github.com:' : 'git://github.com/';
+
+ return $url_base . $username . '/' . $repository . '.git';
+}
+
+function api_request($query)
+{
+ $contents = file_get_contents("http://github.com/api/v2/json/$query");
+
+ if ($contents === false)
+ {
+ throw new RuntimeException("Error: failed to retrieve pull request data\n", 4);
+ }
+
+ return json_decode($contents);
+}
+
+function get_pull($username, $repository, $pull_id)
+{
+ $request = api_request("pulls/$username/$repository/$pull_id");
+
+ $pull = $request->pull;
+
+ $pull_data = array(
+ 'base' => array($pull->base->user->login, $pull->base->ref),
+ 'head' => array($pull->head->user->login, $pull->head->ref),
+ 'state' => $pull->state,
+ );
+
+ return $pull_data;
+}
+
+function get_arg($array, $index, $default)
+{
+ return isset($array[$index]) ? $array[$index] : $default;
+}
+
+function run($cmd, $ignore_fail = false)
+{
+ global $dry_run;
+
+ if (!empty($dry_run))
+ {
+ echo "$cmd\n";
+ }
+ else
+ {
+ passthru(escapeshellcmd($cmd), $status);
+
+ if ($status != 0 && !$ignore_fail)
+ {
+ throw new RuntimeException(sprintf("Error: command '%s' failed with status %s'\n",
+ $cmd, $status), 6);
+ }
+ }
+}
diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php
new file mode 100755
index 0000000000..e4e212eef6
--- /dev/null
+++ b/git-tools/setup_github_network.php
@@ -0,0 +1,248 @@
+#!/usr/bin/env php
+contributors as $contributor)
+ {
+ $usernames[$contributor->login] = $contributor->login;
+ }
+
+ return $usernames;
+}
+
+function get_organisation_members($username)
+{
+ $request = api_request("organizations/$username/public_members");
+ if ($request === false)
+ {
+ return false;
+ }
+
+ $usernames = array();
+ foreach ($request->users as $member)
+ {
+ $usernames[$member->login] = $member->login;
+ }
+
+ return $usernames;
+}
+
+function get_collaborators($username, $repository)
+{
+ $request = api_request("repos/show/$username/$repository/collaborators");
+ if ($request === false)
+ {
+ return false;
+ }
+
+ $usernames = array();
+ foreach ($request->collaborators as $collaborator)
+ {
+ $usernames[$collaborator] = $collaborator;
+ }
+
+ return $usernames;
+}
+
+function get_network($username, $repository)
+{
+ $request = api_request("repos/show/$username/$repository/network");
+ if ($request === false)
+ {
+ return false;
+ }
+
+ $usernames = array();
+ foreach ($request->network as $network)
+ {
+ $usernames[$network->owner] = array(
+ 'username' => $network->owner,
+ 'repository' => $network->name,
+ );
+ }
+
+ return $usernames;
+}
+
+function get_arg($array, $index, $default)
+{
+ return isset($array[$index]) ? $array[$index] : $default;
+}
+
+function run($cmd, $dry = false)
+{
+ static $dry_run;
+
+ if (is_null($cmd))
+ {
+ $dry_run = $dry;
+ }
+ else if (!empty($dry_run))
+ {
+ echo "$cmd\n";
+ }
+ else
+ {
+ passthru(escapeshellcmd($cmd));
+ }
+}
diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php
index 92bcf90039..bf4dc37044 100644
--- a/phpBB/adm/index.php
+++ b/phpBB/adm/index.php
@@ -237,7 +237,7 @@ function build_select($option_ary, $option_default = false)
/**
* Build radio fields in acp pages
*/
-function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false)
+function h_radio($name, $input_ary, $input_default = false, $id = false, $key = false, $separator = '')
{
global $user;
@@ -246,7 +246,7 @@ function h_radio($name, &$input_ary, $input_default = false, $id = false, $key =
foreach ($input_ary as $value => $title)
{
$selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
- $html .= '';
+ $html .= '' . $separator;
$id_assigned = true;
}
@@ -276,7 +276,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
$size = (int) $tpl_type[1];
$maxlength = (int) $tpl_type[2];
- $tpl = '';
+ $tpl = '';
break;
case 'dimension':
@@ -402,7 +402,7 @@ function validate_config_vars($config_vars, &$cfg_array, &$error)
switch ($validator[$type])
{
case 'string':
- $length = strlen($cfg_array[$config_name]);
+ $length = utf8_strlen($cfg_array[$config_name]);
// the column is a VARCHAR
$validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
@@ -573,7 +573,11 @@ function validate_range($value_ary, &$error)
'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1),
'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535),
'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff),
- 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff),
+ // Do not use (int) 0x80000000 - it evaluates to different
+ // values on 32-bit and 64-bit systems.
+ // Apparently -2147483648 is a float on 32-bit systems,
+ // despite fitting in an int, thus explicit cast is needed.
+ 'INT' => array('php_type' => 'int', 'min' => (int) -2147483648, 'max' => (int) 0x7fffffff),
'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127),
'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255),
@@ -596,7 +600,7 @@ function validate_range($value_ary, &$error)
{
case 'string' :
$max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max'];
- if (strlen($value['value']) > $max)
+ if (utf8_strlen($value['value']) > $max)
{
$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max);
}
diff --git a/phpBB/adm/style/acp_ban.html b/phpBB/adm/style/acp_ban.html
index cf44f4aaa7..0e2e71822e 100644
--- a/phpBB/adm/style/acp_ban.html
+++ b/phpBB/adm/style/acp_ban.html
@@ -33,7 +33,7 @@
{
document.getElementById('acp_unban').unbangivereason.innerHTML = ban_give_reason[option];
document.getElementById('acp_unban').unbanreason.innerHTML = ban_reason[option];
- document.getElementById('acp_unban').unbanlength.innerHTML = ban_length[option];
+ document.getElementById('acp_unban').unbanlength.value = ban_length[option];
}
// ]]>
diff --git a/phpBB/adm/style/acp_email.html b/phpBB/adm/style/acp_email.html
index 885809ffe2..ff52500dca 100644
--- a/phpBB/adm/style/acp_email.html
+++ b/phpBB/adm/style/acp_email.html
@@ -38,6 +38,10 @@
+
+
{L_MAIL_BANNED_EXPLAIN}
+
+
diff --git a/phpBB/adm/style/acp_forums.html b/phpBB/adm/style/acp_forums.html
index 9f9216a068..8577c08860 100644
--- a/phpBB/adm/style/acp_forums.html
+++ b/phpBB/adm/style/acp_forums.html
@@ -58,7 +58,7 @@
/**
* Init the wanted display functionality if javascript is enabled.
- * If javascript is not available, the user is still able to properly administrate.
+ * If javascript is not available, the user is still able to properly administer.
*/
onload = function()
{
@@ -140,6 +140,12 @@
@@ -77,7 +92,7 @@
/**
* Init the wanted display functionality if javascript is enabled.
- * If javascript is not available, the user is still able to properly administrate.
+ * If javascript is not available, the user is still able to properly administer.
*/
onload = function()
{
diff --git a/phpBB/adm/style/acp_users_overview.html b/phpBB/adm/style/acp_users_overview.html
index 911dcad293..9237e45daf 100644
--- a/phpBB/adm/style/acp_users_overview.html
+++ b/phpBB/adm/style/acp_users_overview.html
@@ -43,19 +43,19 @@
Some of these functions are only chosen over others because of personal preference and having no other benefit than to be consistant over the code.
+
Some of these functions are only chosen over others because of personal preference and having no other benefit than to be consistent over the code.
@@ -2369,7 +2374,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
-
This application is opensource software released under the GPL. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) 2000, 2002, 2005, 2007 phpBB Group, All Rights Reserved.
+
This application is opensource software released under the GPL. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.
diff --git a/phpBB/docs/hook_system.html b/phpBB/docs/hook_system.html
index 1bf4630a9f..a5fad0d530 100644
--- a/phpBB/docs/hook_system.html
+++ b/phpBB/docs/hook_system.html
@@ -8,7 +8,7 @@
-
+
phpBB3 • Hook System
@@ -380,6 +380,8 @@ a:active { color: #368AD2; }
$template->display($handle, $include_once = true); which is called directly before outputting the (not-yet-compiled) template. exit_handler(); which is called at the very end of phpBB3's execution.
+
Please note: The $template->display hook takes a third $template argument, which is the template instance being used, which should be used instead of the global.
+
There are also valid external constants you may want to use if you embed phpBB3 into your application:
@@ -865,7 +867,7 @@ function phpbb_hook_register(&$hook)
-
This application is opensource software released under the GPL. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) 2000, 2002, 2005, 2007 phpBB Group, All Rights Reserved.
+
This application is opensource software released under the GPL. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.
diff --git a/phpBB/docs/lighttpd.sample.conf b/phpBB/docs/lighttpd.sample.conf
new file mode 100644
index 0000000000..5873d1c945
--- /dev/null
+++ b/phpBB/docs/lighttpd.sample.conf
@@ -0,0 +1,60 @@
+# Sample lighttpd configuration file for phpBB.
+# Global settings have been removed, copy them
+# from your system's lighttpd.conf.
+# Tested with lighttpd 1.4.26
+
+# Load moules
+server.modules += (
+ "mod_access",
+ "mod_fastcgi",
+ "mod_accesslog"
+)
+
+# If you have domains with and without www prefix,
+# redirect one to the other.
+$HTTP["host"] =~ "^(myforums\.com)$" {
+ url.redirect = (
+ ".*" => "http://www.%1$0"
+ )
+}
+
+$HTTP["host"] == "www.myforums.com" {
+ server.name = "www.myforums.com"
+ server.document-root = "/path/to/phpbb"
+ server.dir-listing = "disable"
+
+ index-file.names = ( "index.php", "index.htm", "index.html" )
+ accesslog.filename = "/var/log/lighttpd/access-www.myforums.com.log"
+
+ # Deny access to internal phpbb files.
+ $HTTP["url"] =~ "^/(config\.php|common\.php|includes|cache|files|store|images/avatars/upload)" {
+ url.access-deny = ( "" )
+ }
+
+ # Deny access to version control system directories.
+ $HTTP["url"] =~ "/\.svn|/\.git" {
+ url.access-deny = ( "" )
+ }
+
+ # Deny access to apache configuration files.
+ $HTTP["url"] =~ "/\.htaccess|/\.htpasswd|/\.htgroups" {
+ url.access-deny = ( "" )
+ }
+
+ fastcgi.server = ( ".php" =>
+ ((
+ "bin-path" => "/usr/bin/php-cgi",
+ "socket" => "/tmp/php.socket",
+ "max-procs" => 4,
+ "idle-timeout" => 30,
+ "bin-environment" => (
+ "PHP_FCGI_CHILDREN" => "10",
+ "PHP_FCGI_MAX_REQUESTS" => "10000"
+ ),
+ "bin-copy-environment" => (
+ "PATH", "SHELL", "USER"
+ ),
+ "broken-scriptfilename" => "enable"
+ ))
+ )
+}
diff --git a/phpBB/docs/nginx.conf.sample b/phpBB/docs/nginx.sample.conf
similarity index 65%
rename from phpBB/docs/nginx.conf.sample
rename to phpBB/docs/nginx.sample.conf
index a22a126ff4..40b6ee76da 100644
--- a/phpBB/docs/nginx.conf.sample
+++ b/phpBB/docs/nginx.sample.conf
@@ -10,14 +10,23 @@ http {
gzip_vary on;
gzip_http_version 1.1;
gzip_min_length 700;
+
+ # Compression levels over 6 do not give an appreciable improvement
+ # in compression ratio, but take more resources.
gzip_comp_level 6;
- gzip_disable "MSIE [1-6]\.";
+
+ # IE 6 and lower do not support gzip with Vary correctly.
+ gzip_disable "msie6";
+ # Before nginx 0.7.63:
+ #gzip_disable "MSIE [1-6]\.";
# Catch-all server for requests to invalid hosts.
# Also catches vulnerability scanners probing IP addresses.
- # Should be first.
server {
- listen 80;
+ # default specifies that this block is to be used when
+ # no other block matches.
+ listen 80 default;
+
server_name bogus;
return 444;
root /var/empty;
@@ -26,14 +35,20 @@ http {
# If you have domains with and without www prefix,
# redirect one to the other.
server {
- listen 80;
+ # Default port is 80.
+ #listen 80;
+
server_name myforums.com;
- rewrite ^(.*)$ http://www.myforums.com$1 permanent;
+
+ # A trick from http://wiki.nginx.org/Pitfalls#Taxing_Rewrites:
+ rewrite ^ http://www.myforums.com$request_uri permanent;
+ # Equivalent to:
+ #rewrite ^(.*)$ http://www.myforums.com$1 permanent;
}
# The actual board domain.
server {
- listen 80;
+ #listen 80;
server_name www.myforums.com;
root /path/to/phpbb;
@@ -46,6 +61,9 @@ http {
# Deny access to internal phpbb files.
location ~ /(config\.php|common\.php|includes|cache|files|store|images/avatars/upload) {
deny all;
+ # deny was ignored before 0.8.40 for connections over IPv6.
+ # Use internal directive to prohibit access on older versions.
+ internal;
}
# Pass the php scripts to fastcgi server specified in upstream declaration.
@@ -60,6 +78,7 @@ http {
# Deny access to version control system directories.
location ~ /\.svn|/\.git {
deny all;
+ internal;
}
}
diff --git a/phpBB/download/file.php b/phpBB/download/file.php
index 5f45b88359..c17f0cf018 100644
--- a/phpBB/download/file.php
+++ b/phpBB/download/file.php
@@ -31,12 +31,7 @@ else if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'
if (isset($_GET['avatar']))
{
- if (!defined('E_DEPRECATED'))
- {
- define('E_DEPRECATED', 8192);
- }
- error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
-
+ require($phpbb_root_path . 'includes/startup.' . $phpEx);
require($phpbb_root_path . 'config.' . $phpEx);
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
@@ -64,7 +59,7 @@ if (isset($_GET['avatar']))
$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';
$config = $cache->obtain_config();
- $filename = $_GET['avatar'];
+ $filename = request_var('avatar', '');
$avatar_group = false;
$exit = false;
@@ -125,11 +120,13 @@ $user->setup('viewtopic');
if (!$download_id)
{
+ send_status_line(404, 'Not Found');
trigger_error('NO_ATTACHMENT_SELECTED');
}
if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
{
+ send_status_line(404, 'Not Found');
trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}
@@ -142,11 +139,13 @@ $db->sql_freeresult($result);
if (!$attachment)
{
+ send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
}
if ((!$attachment['in_message'] && !$config['allow_attachments']) || ($attachment['in_message'] && !$config['allow_pm_attach']))
{
+ send_status_line(404, 'Not Found');
trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}
@@ -159,6 +158,7 @@ if ($attachment['is_orphan'])
if (!$own_attachment || ($attachment['in_message'] && !$auth->acl_get('u_pm_download')) || (!$attachment['in_message'] && !$auth->acl_get('u_download')))
{
+ send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
}
@@ -191,6 +191,7 @@ else
}
else
{
+ send_status_line(403, 'Forbidden');
trigger_error('SORRY_AUTH_VIEW_ATTACH');
}
}
@@ -231,6 +232,7 @@ else
$extensions = array();
if (!extension_allowed($row['forum_id'], $attachment['extension'], $extensions))
{
+ send_status_line(404, 'Forbidden');
trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
}
}
@@ -253,6 +255,7 @@ $db->sql_freeresult($result);
if (!$attachment)
{
+ send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
}
@@ -295,6 +298,7 @@ else
// This presenting method should no longer be used
if (!@is_dir($phpbb_root_path . $config['upload_path']))
{
+ send_status_line(500, 'Internal Server Error');
trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
}
@@ -419,6 +423,7 @@ function send_file_to_browser($attachment, $upload_dir, $category)
if (!@file_exists($filename))
{
+ send_status_line(404, 'Not Found');
trigger_error($user->lang['ERROR_NO_ATTACHMENT'] . '
' . sprintf($user->lang['FILE_NOT_FOUND_404'], $filename));
}
@@ -445,9 +450,11 @@ function send_file_to_browser($attachment, $upload_dir, $category)
// PHP track_errors setting On?
if (!empty($php_errormsg))
{
+ send_status_line(500, 'Internal Server Error');
trigger_error($user->lang['UNABLE_TO_DELIVER_FILE'] . ' ' . sprintf($user->lang['TRACKED_PHP_ERROR'], $php_errormsg));
}
+ send_status_line(500, 'Internal Server Error');
trigger_error('UNABLE_TO_DELIVER_FILE');
}
diff --git a/phpBB/feed.php b/phpBB/feed.php
index c4b71f3a26..d737b8e10c 100644
--- a/phpBB/feed.php
+++ b/phpBB/feed.php
@@ -95,11 +95,13 @@ while ($row = $feed->get_item())
$title = (isset($row[$feed->get('title')]) && $row[$feed->get('title')] !== '') ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : '');
- $item_time = (int) $row[$feed->get('date')];
+ $published = ($feed->get('published') !== NULL) ? (int) $row[$feed->get('published')] : 0;
+ $updated = ($feed->get('updated') !== NULL) ? (int) $row[$feed->get('updated')] : 0;
$item_row = array(
'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '',
- 'pubdate' => feed_format_date($item_time),
+ 'published' => ($published > 0) ? feed_format_date($published) : '',
+ 'updated' => ($updated > 0) ? feed_format_date($updated) : '',
'link' => '',
'title' => censor_text($title),
'category' => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '',
@@ -113,7 +115,7 @@ while ($row = $feed->get_item())
$item_vars[] = $item_row;
- $feed_updated_time = max($feed_updated_time, $item_time);
+ $feed_updated_time = max($feed_updated_time, $published, $updated);
}
// If we do not have any items at all, sending the current time is better than sending no time.
@@ -192,7 +194,13 @@ foreach ($item_vars as $row)
echo '' . "\n";
}
- echo '' . $row['pubdate'] . '' . "\n";
+ echo '' . ((!empty($row['updated'])) ? $row['updated'] : $row['published']) . '' . "\n";
+
+ if (!empty($row['published']))
+ {
+ echo '' . $row['published'] . '' . "\n";
+ }
+
echo '' . $row['link'] . '' . "\n";
echo '' . "\n";
echo '' . "\n\n";
@@ -675,7 +683,8 @@ class phpbb_feed_post_base extends phpbb_feed_base
$this->set('author_id', 'user_id');
$this->set('creator', 'username');
- $this->set('date', 'post_time');
+ $this->set('published', 'post_time');
+ $this->set('updated', 'post_edit_time');
$this->set('text', 'post_text');
$this->set('bitfield', 'bbcode_bitfield');
@@ -695,7 +704,7 @@ class phpbb_feed_post_base extends phpbb_feed_base
if ($config['feed_item_statistics'])
{
$item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row)
- . ' ' . $this->separator_stats . ' ' . $user->format_date($row['post_time'])
+ . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')])
. (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : '');
}
}
@@ -717,7 +726,8 @@ class phpbb_feed_topic_base extends phpbb_feed_base
$this->set('author_id', 'topic_poster');
$this->set('creator', 'topic_first_poster_name');
- $this->set('date', 'topic_time');
+ $this->set('published', 'post_time');
+ $this->set('updated', 'post_edit_time');
$this->set('text', 'post_text');
$this->set('bitfield', 'bbcode_bitfield');
@@ -737,7 +747,7 @@ class phpbb_feed_topic_base extends phpbb_feed_base
if ($config['feed_item_statistics'])
{
$item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row)
- . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('date')])
+ . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')])
. ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'])
. ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']
. (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $user->lang['POSTS_UNAPPROVED'] : '');
@@ -800,7 +810,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
// Get the actual data
$this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, ' .
- 'p.post_id, p.topic_id, p.post_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
+ 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'u.username, u.user_id',
'FROM' => array(
USERS_TABLE => 'u',
@@ -932,7 +942,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base
}
$this->sql = array(
- 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
+ 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'u.username, u.user_id',
'FROM' => array(
POSTS_TABLE => 'p',
@@ -1097,7 +1107,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base
global $auth, $db;
$this->sql = array(
- 'SELECT' => 'p.post_id, p.post_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
+ 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'u.username, u.user_id',
'FROM' => array(
POSTS_TABLE => 'p',
@@ -1136,7 +1146,7 @@ class phpbb_feed_forums extends phpbb_feed_base
$this->set('text', 'forum_desc');
$this->set('bitfield', 'forum_desc_bitfield');
$this->set('bbcode_uid','forum_desc_uid');
- $this->set('date', 'forum_last_post_time');
+ $this->set('updated', 'forum_last_post_time');
$this->set('options', 'forum_desc_options');
}
@@ -1261,8 +1271,8 @@ class phpbb_feed_news extends phpbb_feed_topic_base
$this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name,
- t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time,
- p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
+ t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time,
+ p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
'FROM' => array(
TOPICS_TABLE => 't',
POSTS_TABLE => 'p',
@@ -1334,8 +1344,8 @@ class phpbb_feed_topics extends phpbb_feed_topic_base
$this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name,
- t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time,
- p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
+ t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time,
+ p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
'FROM' => array(
TOPICS_TABLE => 't',
POSTS_TABLE => 'p',
@@ -1381,8 +1391,6 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base
$this->set('author_id', 'topic_last_poster_id');
$this->set('creator', 'topic_last_poster_name');
- $this->set('date', 'topic_last_post_time');
- $this->set('text', 'post_text');
}
function get_sql()
@@ -1434,7 +1442,7 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base
'SELECT' => 'f.forum_id, f.forum_name,
t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_views,
t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time,
- p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
+ p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
'FROM' => array(
TOPICS_TABLE => 't',
POSTS_TABLE => 'p',
diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php
index 5c1876d006..524a28561e 100644
--- a/phpBB/includes/acm/acm_file.php
+++ b/phpBB/includes/acm/acm_file.php
@@ -88,11 +88,11 @@ class acm
if (!phpbb_is_writable($this->cache_dir))
{
// We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())
- die($this->cache_dir . ' is NOT writable.');
+ die('Fatal: ' . $this->cache_dir . ' is NOT writable.');
exit;
}
- die('Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx);
+ die('Fatal: Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx);
exit;
}
diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php
new file mode 100644
index 0000000000..41533eaacb
--- /dev/null
+++ b/phpBB/includes/acm/acm_redis.php
@@ -0,0 +1,145 @@
+redis = new Redis();
+ $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
+
+ if (defined('PHPBB_ACM_REDIS_PASSWORD'))
+ {
+ if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD))
+ {
+ global $acm_type;
+
+ trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR);
+ }
+ }
+
+ $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
+ $this->redis->setOption(Redis::OPT_PREFIX, $this->key_prefix);
+
+ if (defined('PHPBB_ACM_REDIS_DB'))
+ {
+ if (!$this->redis->select(PHPBB_ACM_REDIS_DB))
+ {
+ global $acm_type;
+
+ trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR);
+ }
+ }
+ }
+
+ /**
+ * Unload the cache resources
+ *
+ * @return void
+ */
+ function unload()
+ {
+ parent::unload();
+
+ $this->redis->close();
+ }
+
+ /**
+ * Purge cache data
+ *
+ * @return void
+ */
+ function purge()
+ {
+ $this->redis->flushDB();
+
+ parent::purge();
+ }
+
+ /**
+ * Fetch an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return mixed Cached data
+ */
+ function _read($var)
+ {
+ return $this->redis->get($var);
+ }
+
+ /**
+ * Store data in the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @param mixed $data Data to store
+ * @param int $ttl Time-to-live of cached data
+ * @return bool True if the operation succeeded
+ */
+ function _write($var, $data, $ttl = 2592000)
+ {
+ return $this->redis->setex($var, $ttl, $data);
+ }
+
+ /**
+ * Remove an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return bool True if the operation succeeded
+ */
+ function _delete($var)
+ {
+ if ($this->redis->delete($var) > 0)
+ {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/phpBB/includes/acm/acm_wincache.php b/phpBB/includes/acm/acm_wincache.php
new file mode 100644
index 0000000000..0501ab74c5
--- /dev/null
+++ b/phpBB/includes/acm/acm_wincache.php
@@ -0,0 +1,84 @@
+key_prefix . $var, $success);
+
+ return ($success) ? $result : false;
+ }
+
+ /**
+ * Store data in the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @param mixed $data Data to store
+ * @param int $ttl Time-to-live of cached data
+ * @return bool True if the operation succeeded
+ */
+ function _write($var, $data, $ttl = 2592000)
+ {
+ return wincache_ucache_set($this->key_prefix . $var, $data, $ttl);
+ }
+
+ /**
+ * Remove an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return bool True if the operation succeeded
+ */
+ function _delete($var)
+ {
+ return wincache_ucache_delete($this->key_prefix . $var);
+ }
+}
diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php
index 2b706394c4..0644b38eb1 100644
--- a/phpBB/includes/acp/acp_bbcodes.php
+++ b/phpBB/includes/acp/acp_bbcodes.php
@@ -213,7 +213,7 @@ class acp_bbcodes
$bbcode_id = NUM_CORE_BBCODES + 1;
}
- if ($bbcode_id > 1511)
+ if ($bbcode_id > BBCODE_LIMIT)
{
trigger_error($user->lang['TOO_MANY_BBCODES'] . adm_back_link($this->u_action), E_USER_WARNING);
}
diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php
index a5e80e1f6d..d8ab42ed2d 100644
--- a/phpBB/includes/acp/acp_board.php
+++ b/phpBB/includes/acp/acp_board.php
@@ -386,6 +386,9 @@ class acp_board
'pass_complex' => array('lang' => 'PASSWORD_TYPE', 'validate' => 'string', 'type' => 'select', 'method' => 'select_password_chars', 'explain' => true),
'chg_passforce' => array('lang' => 'FORCE_PASS_CHANGE', 'validate' => 'int:0', 'type' => 'text:3:3', 'explain' => true, 'append' => ' ' . $user->lang['DAYS']),
'max_login_attempts' => array('lang' => 'MAX_LOGIN_ATTEMPTS', 'validate' => 'int:0', 'type' => 'text:3:3', 'explain' => true),
+ 'ip_login_limit_max' => array('lang' => 'IP_LOGIN_LIMIT_MAX', 'validate' => 'int:0', 'type' => 'text:3:3', 'explain' => true),
+ 'ip_login_limit_time' => array('lang' => 'IP_LOGIN_LIMIT_TIME', 'validate' => 'int:0', 'type' => 'text:5:5', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']),
+ 'ip_login_limit_use_forwarded' => array('lang' => 'IP_LOGIN_LIMIT_USE_FORWARDED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'tpl_allow_php' => array('lang' => 'TPL_ALLOW_PHP', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'form_token_lifetime' => array('lang' => 'FORM_TIME_MAX', 'validate' => 'int:-1', 'type' => 'text:5:5', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']),
'form_token_sid_guests' => array('lang' => 'FORM_SID_GUESTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
@@ -769,13 +772,20 @@ class acp_board
{
global $user, $config;
- $radio_ary = array(USER_ACTIVATION_DISABLE => 'ACC_DISABLE', USER_ACTIVATION_NONE => 'ACC_NONE');
+ $radio_ary = array(
+ USER_ACTIVATION_DISABLE => 'ACC_DISABLE',
+ USER_ACTIVATION_NONE => 'ACC_NONE',
+ );
+
if ($config['email_enable'])
{
- $radio_ary += array(USER_ACTIVATION_SELF => 'ACC_USER', USER_ACTIVATION_ADMIN => 'ACC_ADMIN');
+ $radio_ary[USER_ACTIVATION_SELF] = 'ACC_USER';
+ $radio_ary[USER_ACTIVATION_ADMIN] = 'ACC_ADMIN';
}
- return h_radio('config[require_activation]', $radio_ary, $value, $key);
+ $radio_text = h_radio('config[require_activation]', $radio_ary, $value, 'require_activation', $key, ' ');
+
+ return $radio_text;
}
/**
diff --git a/phpBB/includes/acp/acp_disallow.php b/phpBB/includes/acp/acp_disallow.php
index 9549955cc8..e2176b7bcd 100644
--- a/phpBB/includes/acp/acp_disallow.php
+++ b/phpBB/includes/acp/acp_disallow.php
@@ -56,6 +56,18 @@ class acp_disallow
trigger_error($user->lang['NO_USERNAME_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
}
+ $sql = 'SELECT disallow_id
+ FROM ' . DISALLOW_TABLE . "
+ WHERE disallow_username = '" . $db->sql_escape($disallowed_user) . "'";
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ if ($row)
+ {
+ trigger_error($user->lang['DISALLOWED_ALREADY'] . adm_back_link($this->u_action), E_USER_WARNING);
+ }
+
$sql = 'INSERT INTO ' . DISALLOW_TABLE . ' ' . $db->sql_build_array('INSERT', array('disallow_username' => $disallowed_user));
$db->sql_query($sql);
diff --git a/phpBB/includes/acp/acp_email.php b/phpBB/includes/acp/acp_email.php
index 350693a630..133fe47e09 100644
--- a/phpBB/includes/acp/acp_email.php
+++ b/phpBB/includes/acp/acp_email.php
@@ -82,23 +82,48 @@ class acp_email
{
if ($group_id)
{
- $sql = 'SELECT u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type
- FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug
- WHERE ug.group_id = ' . $group_id . '
+ $sql_ary = array(
+ 'SELECT' => 'u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type',
+ 'FROM' => array(
+ USERS_TABLE => 'u',
+ USER_GROUP_TABLE => 'ug',
+ ),
+ 'WHERE' => 'ug.group_id = ' . $group_id . '
AND ug.user_pending = 0
AND u.user_id = ug.user_id
AND u.user_allow_massemail = 1
- AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')
- ORDER BY u.user_lang, u.user_notify_type';
+ AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')',
+ 'ORDER_BY' => 'u.user_lang, u.user_notify_type',
+ );
}
else
{
- $sql = 'SELECT username, username_clean, user_email, user_jabber, user_notify_type, user_lang
- FROM ' . USERS_TABLE . '
- WHERE user_allow_massemail = 1
- AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')
- ORDER BY user_lang, user_notify_type';
+ $sql_ary = array(
+ 'SELECT' => 'u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type',
+ 'FROM' => array(
+ USERS_TABLE => 'u',
+ ),
+ 'WHERE' => 'u.user_allow_massemail = 1
+ AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')',
+ 'ORDER_BY' => 'u.user_lang, u.user_notify_type',
+ );
}
+
+ // Mail banned or not
+ if (!isset($_REQUEST['mail_banned_flag']))
+ {
+ $sql_ary['WHERE'] .= ' AND (b.ban_id IS NULL
+ OR b.ban_exclude = 1)';
+ $sql_ary['LEFT_JOIN'] = array(
+ array(
+ 'FROM' => array(
+ BANLIST_TABLE => 'b',
+ ),
+ 'ON' => 'u.user_id = b.ban_userid',
+ ),
+ );
+ }
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
}
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php
index 3d64a2acda..24f6cbbcbf 100644
--- a/phpBB/includes/acp/acp_icons.php
+++ b/phpBB/includes/acp/acp_icons.php
@@ -394,6 +394,10 @@ class acp_icons
{
// skip images where add wasn't checked
}
+ else if (!file_exists($phpbb_root_path . $img_path . '/' . $image))
+ {
+ $errors[$image] = 'SMILIE_NO_FILE';
+ }
else
{
if ($image_width[$image] == 0 || $image_height[$image] == 0)
diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php
index c2cb2f9c11..598b390302 100644
--- a/phpBB/includes/acp/acp_language.php
+++ b/phpBB/includes/acp/acp_language.php
@@ -1055,14 +1055,14 @@ class acp_language
$iso_src .= htmlspecialchars_decode($row['lang_author']);
$compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt');
- // index.html files
- $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html');
- $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html');
- $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.html');
+ // index.htm files
+ $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.htm');
+ $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.htm');
+ $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.htm');
if (sizeof($mod_files))
{
- $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.html');
+ $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.htm');
}
$compress->close();
@@ -1217,7 +1217,7 @@ $lang = array_merge($lang, array(
';
// Language files in language root directory
- $this->main_files = array("common.$phpEx", "groups.$phpEx", "install.$phpEx", "mcp.$phpEx", "memberlist.$phpEx", "posting.$phpEx", "search.$phpEx", "ucp.$phpEx", "viewforum.$phpEx", "viewtopic.$phpEx", "help_bbcode.$phpEx", "help_faq.$phpEx");
+ $this->main_files = array("captcha_qa.$phpEx", "captcha_recaptcha.$phpEx", "common.$phpEx", "groups.$phpEx", "install.$phpEx", "mcp.$phpEx", "memberlist.$phpEx", "posting.$phpEx", "search.$phpEx", "ucp.$phpEx", "viewforum.$phpEx", "viewtopic.$phpEx", "help_bbcode.$phpEx", "help_faq.$phpEx");
}
/**
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index b8712b2a3d..60cebe3c08 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -529,7 +529,7 @@ class acp_main
);
$log_data = array();
- $log_count = 0;
+ $log_count = false;
if ($auth->acl_get('a_viewlogs'))
{
diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php
index 2288a0728b..2e43b0545a 100644
--- a/phpBB/includes/acp/acp_profile.php
+++ b/phpBB/includes/acp/acp_profile.php
@@ -512,7 +512,7 @@ class acp_profile
else if ($field_type == FIELD_INT && $key == 'field_default_value')
{
// Permit an empty string
- if (request_var('field_default_value', '') === '')
+ if ($action == 'create' && request_var('field_default_value', '') === '')
{
$var = '';
}
diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php
index 930c8d2a26..0cd67b1c34 100644
--- a/phpBB/includes/acp/acp_search.php
+++ b/phpBB/includes/acp/acp_search.php
@@ -392,7 +392,18 @@ class acp_search
AND post_id <= ' . (int) ($post_counter + $this->batch_size);
$result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ $buffer = $db->sql_buffer_nested_transactions();
+
+ if ($buffer)
+ {
+ $rows = $db->sql_fetchrowset($result);
+ $rows[] = false; // indicate end of array for while loop below
+
+ $db->sql_freeresult($result);
+ }
+
+ $i = 0;
+ while ($row = ($buffer ? $rows[$i++] : $db->sql_fetchrow($result)))
{
// Indexing enabled for this forum or global announcement?
// Global announcements get indexed by default.
@@ -402,7 +413,10 @@ class acp_search
}
$row_count++;
}
- $db->sql_freeresult($result);
+ if (!$buffer)
+ {
+ $db->sql_freeresult($result);
+ }
$post_counter += $this->batch_size;
}
diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php
index 2ccc728031..3bc8c86500 100644
--- a/phpBB/includes/acp/acp_styles.php
+++ b/phpBB/includes/acp/acp_styles.php
@@ -510,6 +510,7 @@ parse_css_file = {PARSE_CSS_FILE}
$db->sql_transaction('commit');
$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
+ $cache->destroy('imageset_site_logo_md5');
add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset_row['imageset_name']);
trigger_error($user->lang['IMAGESET_REFRESHED'] . adm_back_link($this->u_action));
@@ -716,7 +717,7 @@ parse_css_file = {PARSE_CSS_FILE}
$save_changes = (isset($_POST['save'])) ? true : false;
// make sure template_file path doesn't go upwards
- $template_file = str_replace('..', '.', $template_file);
+ $template_file = preg_replace('#\.{2,}#', '.', $template_file);
// Retrieve some information about the template
$sql = 'SELECT template_storedb, template_path, template_name
@@ -1587,23 +1588,23 @@ parse_css_file = {PARSE_CSS_FILE}
{
case 'style':
$sql_from = STYLES_TABLE;
- $sql_select = 'style_name';
+ $sql_select = 'style_id, style_name, template_id, theme_id, imageset_id';
$sql_where = 'AND style_active = 1';
break;
case 'template':
$sql_from = STYLES_TEMPLATE_TABLE;
- $sql_select = 'template_name, template_path, template_storedb';
+ $sql_select = 'template_id, template_name, template_path, template_storedb';
break;
case 'theme':
$sql_from = STYLES_THEME_TABLE;
- $sql_select = 'theme_name, theme_path, theme_storedb';
+ $sql_select = 'theme_id, theme_name, theme_path, theme_storedb';
break;
case 'imageset':
$sql_from = STYLES_IMAGESET_TABLE;
- $sql_select = 'imageset_name, imageset_path';
+ $sql_select = 'imageset_id, imageset_name, imageset_path';
break;
}
@@ -1633,37 +1634,14 @@ parse_css_file = {PARSE_CSS_FILE}
trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
}
- $sql = "SELECT {$mode}_id, {$mode}_name
- FROM $sql_from
- WHERE {$mode}_id <> $style_id
- $sql_where
- ORDER BY {$mode}_name ASC";
- $result = $db->sql_query($sql);
-
- $s_options = '';
-
- if ($row = $db->sql_fetchrow($result))
- {
- do
- {
- $s_options .= '';
- }
- while ($row = $db->sql_fetchrow($result));
- }
- else
- {
- trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
- }
- $db->sql_freeresult($result);
-
if ($update)
{
- $sql = "DELETE FROM $sql_from
- WHERE {$mode}_id = $style_id";
- $db->sql_query($sql);
-
if ($mode == 'style')
{
+ $sql = "DELETE FROM $sql_from
+ WHERE {$mode}_id = $style_id";
+ $db->sql_query($sql);
+
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_style = $new_id
WHERE user_style = $style_id";
@@ -1678,19 +1656,19 @@ parse_css_file = {PARSE_CSS_FILE}
{
set_config('default_style', $new_id);
}
+
+ // Remove the components
+ $components = array('template', 'theme', 'imageset');
+ foreach ($components as $component)
+ {
+ $new_id = request_var('new_' . $component . '_id', 0);
+ $component_id = $style_row[$component . '_id'];
+ $this->remove_component($component, $component_id, $new_id, $style_id);
+ }
}
else
{
- if ($mode == 'imageset')
- {
- $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . "
- WHERE imageset_id = $style_id";
- $db->sql_query($sql);
- }
- $sql = 'UPDATE ' . STYLES_TABLE . "
- SET {$mode}_id = $new_id
- WHERE {$mode}_id = $style_id";
- $db->sql_query($sql);
+ $this->remove_component($mode, $style_id, $new_id);
}
$cache->destroy('sql', STYLES_TABLE);
@@ -1700,11 +1678,12 @@ parse_css_file = {PARSE_CSS_FILE}
trigger_error($user->lang[$message] . adm_back_link($this->u_action));
}
+ $this->display_component_options($mode, $style_row[$mode . '_id'], $style_row);
+
$this->page_title = 'DELETE_' . $l_prefix;
$template->assign_vars(array(
'S_DELETE' => true,
- 'S_REPLACE_OPTIONS' => $s_options,
'L_TITLE' => $user->lang[$this->page_title],
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
@@ -1718,6 +1697,202 @@ parse_css_file = {PARSE_CSS_FILE}
'NAME' => $style_row[$mode . '_name'],
)
);
+
+ if ($mode == 'style')
+ {
+ $template->assign_vars(array(
+ 'S_DELETE_STYLE' => true,
+ ));
+ }
+ }
+
+ /**
+ * Remove template/theme/imageset entry from the database
+ */
+ function remove_component($component, $component_id, $new_id, $style_id = false)
+ {
+ global $db;
+
+ if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id))))
+ {
+ // We can not delete the template, as the user wants to keep the component or an other template is inheriting from this one.
+ return;
+ }
+
+ $component_in_use = array();
+ if ($component != 'style')
+ {
+ $component_in_use = $this->component_in_use($component, $component_id, $style_id);
+ }
+
+ if (($new_id == -1) && !empty($component_in_use))
+ {
+ // We can not delete the component, as it is still in use
+ return;
+ }
+
+ if ($component == 'imageset')
+ {
+ $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . "
+ WHERE imageset_id = $component_id";
+ $db->sql_query($sql);
+ }
+
+ switch ($component)
+ {
+ case 'template':
+ $sql_from = STYLES_TEMPLATE_TABLE;
+ break;
+
+ case 'theme':
+ $sql_from = STYLES_THEME_TABLE;
+ break;
+
+ case 'imageset':
+ $sql_from = STYLES_IMAGESET_TABLE;;
+ break;
+ }
+
+ $sql = "DELETE FROM $sql_from
+ WHERE {$component}_id = $component_id";
+ $db->sql_query($sql);
+
+ $sql = 'UPDATE ' . STYLES_TABLE . "
+ SET {$component}_id = $new_id
+ WHERE {$component}_id = $component_id";
+ $db->sql_query($sql);
+ }
+
+ /**
+ * Display the options which can be used to replace a style/template/theme/imageset
+ */
+ function display_component_options($component, $component_id, $style_row = false, $style_id = false)
+ {
+ global $db, $template, $user;
+
+ $component_in_use = array();
+ if ($component != 'style')
+ {
+ $component_in_use = $this->component_in_use($component, $component_id, $style_id);
+ }
+
+ $sql_where = '';
+ switch ($component)
+ {
+ case 'style':
+ $sql_from = STYLES_TABLE;
+ $sql_where = 'WHERE style_active = 1';
+ break;
+
+ case 'template':
+ $sql_from = STYLES_TEMPLATE_TABLE;
+ $sql_where = 'WHERE template_inherits_id <> ' . $component_id;
+ break;
+
+ case 'theme':
+ $sql_from = STYLES_THEME_TABLE;
+ break;
+
+ case 'imageset':
+ $sql_from = STYLES_IMAGESET_TABLE;
+ break;
+ }
+
+ $s_options = '';
+ if (($component != 'style') && empty($component_in_use))
+ {
+ $sql = "SELECT {$component}_id, {$component}_name
+ FROM $sql_from
+ WHERE {$component}_id = {$component_id}";
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $s_options .= '';
+ $s_options .= '';
+ }
+ else
+ {
+ $sql = "SELECT {$component}_id, {$component}_name
+ FROM $sql_from
+ $sql_where
+ ORDER BY {$component}_name ASC";
+ $result = $db->sql_query($sql);
+
+ $s_keep_option = $s_options = '';
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($row[$component . '_id'] != $component_id)
+ {
+ $s_options .= '';
+ }
+ else if ($component != 'style')
+ {
+ $s_keep_option = '';
+ }
+ }
+ $db->sql_freeresult($result);
+ $s_options = $s_keep_option . $s_options;
+ }
+
+ if (!$style_row)
+ {
+ $template->assign_var('S_REPLACE_' . strtoupper($component) . '_OPTIONS', $s_options);
+ }
+ else
+ {
+ $template->assign_var('S_REPLACE_OPTIONS', $s_options);
+ if ($component == 'style')
+ {
+ $components = array('template', 'theme', 'imageset');
+ foreach ($components as $component)
+ {
+ $this->display_component_options($component, $style_row[$component . '_id'], false, $component_id, true);
+ }
+ }
+ }
+ }
+
+ /**
+ * Check whether the component is still used by another style or component
+ */
+ function component_in_use($component, $component_id, $style_id = false)
+ {
+ global $db;
+
+ $component_in_use = array();
+
+ if ($style_id)
+ {
+ $sql = 'SELECT style_id, style_name
+ FROM ' . STYLES_TABLE . "
+ WHERE {$component}_id = {$component_id}
+ AND style_id <> {$style_id}
+ ORDER BY style_name ASC";
+ }
+ else
+ {
+ $sql = 'SELECT style_id, style_name
+ FROM ' . STYLES_TABLE . "
+ WHERE {$component}_id = {$component_id}
+ ORDER BY style_name ASC";
+ }
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $component_in_use[] = $row['style_name'];
+ }
+ $db->sql_freeresult($result);
+
+ if ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id)))
+ {
+ foreach ($conflicts as $temp_id => $conflict_data)
+ {
+ $component_in_use[] = $conflict_data['template_name'];
+ }
+ }
+
+ return $component_in_use;
}
/**
diff --git a/phpBB/includes/acp/acp_words.php b/phpBB/includes/acp/acp_words.php
index 1cb9545967..88c5bbe592 100644
--- a/phpBB/includes/acp/acp_words.php
+++ b/phpBB/includes/acp/acp_words.php
@@ -95,6 +95,9 @@ class acp_words
trigger_error($user->lang['ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
}
+ // Replace multiple consecutive asterisks with single one as those are not needed
+ $word = preg_replace('#\*{2,}#', '*', $word);
+
$sql_ary = array(
'word' => $word,
'replacement' => $replacement
diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth.php
index 02819f9e78..5564de2943 100644
--- a/phpBB/includes/auth.php
+++ b/phpBB/includes/auth.php
@@ -109,6 +109,7 @@ class auth
*/
function _fill_acl($user_permissions)
{
+ $seq_cache = array();
$this->acl = array();
$user_permissions = explode("\n", $user_permissions);
@@ -125,8 +126,17 @@ class auth
while ($subseq = substr($seq, $i, 6))
{
+ if (isset($seq_cache[$subseq]))
+ {
+ $converted = $seq_cache[$subseq];
+ }
+ else
+ {
+ $converted = $seq_cache[$subseq] = str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT);
+ }
+
// We put the original bitstring into the acl array
- $this->acl[$f] .= str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT);
+ $this->acl[$f] .= $converted;
$i += 6;
}
}
@@ -898,7 +908,7 @@ class auth
$method = 'login_' . $method;
if (function_exists($method))
{
- $login = $method($username, $password);
+ $login = $method($username, $password, $user->ip, $user->browser, $user->forwarded_for);
// If the auth module wants us to create an empty profile do so and then treat the status as LOGIN_SUCCESS
if ($login['status'] == LOGIN_SUCCESS_CREATE_PROFILE)
diff --git a/phpBB/includes/auth/auth_db.php b/phpBB/includes/auth/auth_db.php
index e04a6307e9..6ca69d9174 100644
--- a/phpBB/includes/auth/auth_db.php
+++ b/phpBB/includes/auth/auth_db.php
@@ -23,8 +23,21 @@ if (!defined('IN_PHPBB'))
/**
* Login function
+*
+* @param string $username
+* @param string $password
+* @param string $ip IP address the login is taking place from. Used to
+* limit the number of login attempts per IP address.
+* @param string $browser The user agent used to login
+* @param string $forwarded_for X_FORWARDED_FOR header sent with login request
+* @return array A associative array of the format
+* array(
+* 'status' => status constant
+* 'error_msg' => string
+* 'user_row' => array
+* )
*/
-function login_db(&$username, &$password)
+function login_db($username, $password, $ip = '', $browser = '', $forwarded_for = '')
{
global $db, $config;
@@ -47,13 +60,51 @@ function login_db(&$username, &$password)
);
}
+ $username_clean = utf8_clean_string($username);
+
$sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts
FROM ' . USERS_TABLE . "
- WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
+ WHERE username_clean = '" . $db->sql_escape($username_clean) . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
+ if (($ip && !$config['ip_login_limit_use_forwarded']) ||
+ ($forwarded_for && $config['ip_login_limit_use_forwarded']))
+ {
+ $sql = 'SELECT COUNT(*) AS attempts
+ FROM ' . LOGIN_ATTEMPT_TABLE . '
+ WHERE attempt_time > ' . (time() - (int) $config['ip_login_limit_time']);
+ if ($config['ip_login_limit_use_forwarded'])
+ {
+ $sql .= " AND attempt_forwarded_for = '" . $db->sql_escape($forwarded_for) . "'";
+ }
+ else
+ {
+ $sql .= " AND attempt_ip = '" . $db->sql_escape($ip) . "' ";
+ }
+
+ $result = $db->sql_query($sql);
+ $attempts = (int) $db->sql_fetchfield('attempts');
+ $db->sql_freeresult($result);
+
+ $attempt_data = array(
+ 'attempt_ip' => $ip,
+ 'attempt_browser' => trim(substr($browser, 0, 149)),
+ 'attempt_forwarded_for' => $forwarded_for,
+ 'attempt_time' => time(),
+ 'user_id' => ($row) ? (int) $row['user_id'] : 0,
+ 'username' => $username,
+ 'username_clean' => $username_clean,
+ );
+ $sql = 'INSERT INTO ' . LOGIN_ATTEMPT_TABLE . $db->sql_build_array('INSERT', $attempt_data);
+ $result = $db->sql_query($sql);
+ }
+ else
+ {
+ $attempts = 0;
+ }
+
if (!$row)
{
return array(
@@ -62,7 +113,9 @@ function login_db(&$username, &$password)
'user_row' => array('user_id' => ANONYMOUS),
);
}
- $show_captcha = $config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'];
+
+ $show_captcha = ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts']) ||
+ ($config['ip_login_limit_max'] && $attempts >= $config['ip_login_limit_max']);
// If there are too much login attempts, we need to check for an confirm image
// Every auth module is able to define what to do by itself...
@@ -90,7 +143,7 @@ function login_db(&$username, &$password)
{
$captcha->reset();
}
-
+
}
// If the password convert flag is set we need to convert it
@@ -165,6 +218,10 @@ function login_db(&$username, &$password)
$row['user_password'] = $hash;
}
+ $sql = 'DELETE FROM ' . LOGIN_ATTEMPT_TABLE . '
+ WHERE user_id = ' . $row['user_id'];
+ $db->sql_query($sql);
+
if ($row['user_login_attempts'] != 0)
{
// Successful, reset login attempts (the user passed all stages)
diff --git a/phpBB/includes/auth/auth_ldap.php b/phpBB/includes/auth/auth_ldap.php
index e8c957aaa3..5dfa74ddab 100644
--- a/phpBB/includes/auth/auth_ldap.php
+++ b/phpBB/includes/auth/auth_ldap.php
@@ -335,7 +335,7 @@ function acp_ldap(&$new)
' . $user->lang['LDAP_PASSWORD_EXPLAIN'] . '
-
+
';
diff --git a/phpBB/includes/cache.php b/phpBB/includes/cache.php
index b50fab4ca2..612adcca4f 100644
--- a/phpBB/includes/cache.php
+++ b/phpBB/includes/cache.php
@@ -82,26 +82,9 @@ class cache extends acm
$result = $db->sql_query($sql);
$censors = array();
- $unicode = ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false) ? true : false;
-
while ($row = $db->sql_fetchrow($result))
{
- if ($unicode)
- {
- // Unescape the asterisk to simplify further conversions
- $row['word'] = str_replace('\*', '*', preg_quote($row['word'], '#'));
-
- // Replace the asterisk inside the pattern, at the start and at the end of it with regexes
- $row['word'] = preg_replace(array('#(?<=[\p{Nd}\p{L}_])\*(?=[\p{Nd}\p{L}_])#iu', '#^\*#', '#\*$#'), array('([\x20]*?|[\p{Nd}\p{L}_-]*?)', '[\p{Nd}\p{L}_-]*?', '[\p{Nd}\p{L}_-]*?'), $row['word']);
-
- // Generate the final substitution
- $censors['match'][] = '#(?sql_freeresult($result);
diff --git a/phpBB/includes/captcha/captcha_gd.php b/phpBB/includes/captcha/captcha_gd.php
index 96e39af85b..ecdad43978 100644
--- a/phpBB/includes/captcha/captcha_gd.php
+++ b/phpBB/includes/captcha/captcha_gd.php
@@ -77,7 +77,7 @@ class captcha
{
$denom = ($code_len - $i);
$denom = max(1.3, $denom);
- $offset[$i] = mt_rand(0, (1.5 * $width_avail) / $denom);
+ $offset[$i] = phpbb_mt_rand(0, (int) round((1.5 * $width_avail) / $denom));
$width_avail -= $offset[$i];
}
@@ -112,7 +112,7 @@ class captcha
$noise_bitmaps = $this->captcha_noise_bg_bitmaps();
for ($i = 0; $i < $code_len; ++$i)
{
- $noise[$i] = new char_cube3d($noise_bitmaps, mt_rand(1, count($noise_bitmaps['data'])));
+ $noise[$i] = new char_cube3d($noise_bitmaps, mt_rand(1, sizeof($noise_bitmaps['data'])));
list($min, $max) = $noise[$i]->range();
//$box = $noise[$i]->dimensions($sizes[$i]);
@@ -1669,32 +1669,32 @@ class captcha
'height' => 15,
'data' => array(
- 'A' => $chars['A'][mt_rand(0, min(count($chars['A']), $config['captcha_gd_fonts']) -1)],
- 'B' => $chars['B'][mt_rand(0, min(count($chars['B']), $config['captcha_gd_fonts']) -1)],
- 'C' => $chars['C'][mt_rand(0, min(count($chars['C']), $config['captcha_gd_fonts']) -1)],
- 'D' => $chars['D'][mt_rand(0, min(count($chars['D']), $config['captcha_gd_fonts']) -1)],
- 'E' => $chars['E'][mt_rand(0, min(count($chars['E']), $config['captcha_gd_fonts']) -1)],
- 'F' => $chars['F'][mt_rand(0, min(count($chars['F']), $config['captcha_gd_fonts']) -1)],
- 'G' => $chars['G'][mt_rand(0, min(count($chars['G']), $config['captcha_gd_fonts']) -1)],
- 'H' => $chars['H'][mt_rand(0, min(count($chars['H']), $config['captcha_gd_fonts']) -1)],
- 'I' => $chars['I'][mt_rand(0, min(count($chars['I']), $config['captcha_gd_fonts']) -1)],
- 'J' => $chars['J'][mt_rand(0, min(count($chars['J']), $config['captcha_gd_fonts']) -1)],
- 'K' => $chars['K'][mt_rand(0, min(count($chars['K']), $config['captcha_gd_fonts']) -1)],
- 'L' => $chars['L'][mt_rand(0, min(count($chars['L']), $config['captcha_gd_fonts']) -1)],
- 'M' => $chars['M'][mt_rand(0, min(count($chars['M']), $config['captcha_gd_fonts']) -1)],
- 'N' => $chars['N'][mt_rand(0, min(count($chars['N']), $config['captcha_gd_fonts']) -1)],
- 'O' => $chars['O'][mt_rand(0, min(count($chars['O']), $config['captcha_gd_fonts']) -1)],
- 'P' => $chars['P'][mt_rand(0, min(count($chars['P']), $config['captcha_gd_fonts']) -1)],
- 'Q' => $chars['Q'][mt_rand(0, min(count($chars['Q']), $config['captcha_gd_fonts']) -1)],
- 'R' => $chars['R'][mt_rand(0, min(count($chars['R']), $config['captcha_gd_fonts']) -1)],
- 'S' => $chars['S'][mt_rand(0, min(count($chars['S']), $config['captcha_gd_fonts']) -1)],
- 'T' => $chars['T'][mt_rand(0, min(count($chars['T']), $config['captcha_gd_fonts']) -1)],
- 'U' => $chars['U'][mt_rand(0, min(count($chars['U']), $config['captcha_gd_fonts']) -1)],
- 'V' => $chars['V'][mt_rand(0, min(count($chars['V']), $config['captcha_gd_fonts']) -1)],
- 'W' => $chars['W'][mt_rand(0, min(count($chars['W']), $config['captcha_gd_fonts']) -1)],
- 'X' => $chars['X'][mt_rand(0, min(count($chars['X']), $config['captcha_gd_fonts']) -1)],
- 'Y' => $chars['Y'][mt_rand(0, min(count($chars['Y']), $config['captcha_gd_fonts']) -1)],
- 'Z' => $chars['Z'][mt_rand(0, min(count($chars['Z']), $config['captcha_gd_fonts']) -1)],
+ 'A' => $chars['A'][mt_rand(0, min(sizeof($chars['A']), $config['captcha_gd_fonts']) -1)],
+ 'B' => $chars['B'][mt_rand(0, min(sizeof($chars['B']), $config['captcha_gd_fonts']) -1)],
+ 'C' => $chars['C'][mt_rand(0, min(sizeof($chars['C']), $config['captcha_gd_fonts']) -1)],
+ 'D' => $chars['D'][mt_rand(0, min(sizeof($chars['D']), $config['captcha_gd_fonts']) -1)],
+ 'E' => $chars['E'][mt_rand(0, min(sizeof($chars['E']), $config['captcha_gd_fonts']) -1)],
+ 'F' => $chars['F'][mt_rand(0, min(sizeof($chars['F']), $config['captcha_gd_fonts']) -1)],
+ 'G' => $chars['G'][mt_rand(0, min(sizeof($chars['G']), $config['captcha_gd_fonts']) -1)],
+ 'H' => $chars['H'][mt_rand(0, min(sizeof($chars['H']), $config['captcha_gd_fonts']) -1)],
+ 'I' => $chars['I'][mt_rand(0, min(sizeof($chars['I']), $config['captcha_gd_fonts']) -1)],
+ 'J' => $chars['J'][mt_rand(0, min(sizeof($chars['J']), $config['captcha_gd_fonts']) -1)],
+ 'K' => $chars['K'][mt_rand(0, min(sizeof($chars['K']), $config['captcha_gd_fonts']) -1)],
+ 'L' => $chars['L'][mt_rand(0, min(sizeof($chars['L']), $config['captcha_gd_fonts']) -1)],
+ 'M' => $chars['M'][mt_rand(0, min(sizeof($chars['M']), $config['captcha_gd_fonts']) -1)],
+ 'N' => $chars['N'][mt_rand(0, min(sizeof($chars['N']), $config['captcha_gd_fonts']) -1)],
+ 'O' => $chars['O'][mt_rand(0, min(sizeof($chars['O']), $config['captcha_gd_fonts']) -1)],
+ 'P' => $chars['P'][mt_rand(0, min(sizeof($chars['P']), $config['captcha_gd_fonts']) -1)],
+ 'Q' => $chars['Q'][mt_rand(0, min(sizeof($chars['Q']), $config['captcha_gd_fonts']) -1)],
+ 'R' => $chars['R'][mt_rand(0, min(sizeof($chars['R']), $config['captcha_gd_fonts']) -1)],
+ 'S' => $chars['S'][mt_rand(0, min(sizeof($chars['S']), $config['captcha_gd_fonts']) -1)],
+ 'T' => $chars['T'][mt_rand(0, min(sizeof($chars['T']), $config['captcha_gd_fonts']) -1)],
+ 'U' => $chars['U'][mt_rand(0, min(sizeof($chars['U']), $config['captcha_gd_fonts']) -1)],
+ 'V' => $chars['V'][mt_rand(0, min(sizeof($chars['V']), $config['captcha_gd_fonts']) -1)],
+ 'W' => $chars['W'][mt_rand(0, min(sizeof($chars['W']), $config['captcha_gd_fonts']) -1)],
+ 'X' => $chars['X'][mt_rand(0, min(sizeof($chars['X']), $config['captcha_gd_fonts']) -1)],
+ 'Y' => $chars['Y'][mt_rand(0, min(sizeof($chars['Y']), $config['captcha_gd_fonts']) -1)],
+ 'Z' => $chars['Z'][mt_rand(0, min(sizeof($chars['Z']), $config['captcha_gd_fonts']) -1)],
'1' => array(
array(0,0,0,1,1,0,0,0,0),
diff --git a/phpBB/includes/captcha/captcha_gd_wave.php b/phpBB/includes/captcha/captcha_gd_wave.php
index f706c98d43..27422513d9 100644
--- a/phpBB/includes/captcha/captcha_gd_wave.php
+++ b/phpBB/includes/captcha/captcha_gd_wave.php
@@ -62,8 +62,8 @@ class captcha
'y' => mt_rand(10, 17)
),
'lower_left' => array(
- 'x' => mt_rand($img_x - 5, $img_x - 45),
- 'y' => mt_rand($img_y - 0, $img_y - 15)
+ 'x' => mt_rand($img_x - 45, $img_x - 5),
+ 'y' => mt_rand($img_y - 15, $img_y - 0),
),
);
diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
index 49a64b9339..45f76bd676 100644
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
@@ -319,7 +319,7 @@ class phpbb_captcha_qa
),
'PRIMARY_KEY' => 'question_id',
'KEYS' => array(
- 'lang_iso' => array('INDEX', 'lang_iso'),
+ 'lang' => array('INDEX', 'lang_iso'),
),
),
CAPTCHA_ANSWERS_TABLE => array (
@@ -328,7 +328,7 @@ class phpbb_captcha_qa
'answer_text' => array('STEXT_UNI', ''),
),
'KEYS' => array(
- 'question_id' => array('INDEX', 'question_id'),
+ 'qid' => array('INDEX', 'question_id'),
),
),
CAPTCHA_QA_CONFIRM_TABLE => array (
diff --git a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
index ea171dbe2c..0b0270f568 100644
--- a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
@@ -27,9 +27,14 @@ if (!class_exists('phpbb_default_captcha'))
*/
class phpbb_recaptcha extends phpbb_default_captcha
{
- var $recaptcha_server = 'http://api.recaptcha.net';
- var $recaptcha_server_secure = 'https://api-secure.recaptcha.net'; // class constants :(
- var $recaptcha_verify_server = 'api-verify.recaptcha.net';
+ var $recaptcha_server = 'http://www.google.com/recaptcha/api';
+ var $recaptcha_server_secure = 'https://www.google.com/recaptcha/api'; // class constants :(
+
+ // We are opening a socket to port 80 of this host and send
+ // the POST request asking for verification to the path specified here.
+ var $recaptcha_verify_server = 'www.google.com';
+ var $recaptcha_verify_path = '/recaptcha/api/verify';
+
var $challenge;
var $response;
@@ -296,7 +301,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
return $user->lang['RECAPTCHA_INCORRECT'];
}
- $response = $this->_recaptcha_http_post($this->recaptcha_verify_server, '/verify',
+ $response = $this->_recaptcha_http_post($this->recaptcha_verify_server, $this->recaptcha_verify_path,
array(
'privatekey' => $config['recaptcha_privkey'],
'remoteip' => $user->ip,
diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php
index af2a6ebd24..3940888216 100644
--- a/phpBB/includes/constants.php
+++ b/phpBB/includes/constants.php
@@ -25,7 +25,7 @@ if (!defined('IN_PHPBB'))
*/
// phpBB Version
-define('PHPBB_VERSION', '3.0.8');
+define('PHPBB_VERSION', '3.0.9');
// QA-related
// define('PHPBB_QA', 1);
@@ -173,6 +173,9 @@ define('BBCODE_UID_LEN', 8);
// Number of core BBCodes
define('NUM_CORE_BBCODES', 12);
+// BBCode hard limit
+define('BBCODE_LIMIT', 1511);
+
// Smiley hard limit
define('SMILEY_LIMIT', 1000);
@@ -233,6 +236,7 @@ define('GROUPS_TABLE', $table_prefix . 'groups');
define('ICONS_TABLE', $table_prefix . 'icons');
define('LANG_TABLE', $table_prefix . 'lang');
define('LOG_TABLE', $table_prefix . 'log');
+define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts');
define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache');
define('MODULES_TABLE', $table_prefix . 'modules');
define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options');
@@ -275,4 +279,4 @@ define('ZEBRA_TABLE', $table_prefix . 'zebra');
// Additional tables
-?>
\ No newline at end of file
+?>
diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php
index f4b181c6ad..50e308dea2 100644
--- a/phpBB/includes/db/db_tools.php
+++ b/phpBB/includes/db/db_tools.php
@@ -417,6 +417,11 @@ class phpbb_db_tools
// here lies an array, filled with information compiled on the column's data
$prepared_column = $this->sql_prepare_column_data($table_name, $column_name, $column_data);
+ if (isset($prepared_column['auto_increment']) && strlen($column_name) > 26) // "${column_name}_gen"
+ {
+ trigger_error("Index name '${column_name}_gen' on table '$table_name' is too long. The maximum auto increment column length is 26 characters.", E_USER_ERROR);
+ }
+
// here we add the definition of the new column to the list of columns
switch ($this->sql_layer)
{
@@ -538,7 +543,7 @@ class phpbb_db_tools
break;
case 'oracle':
- $table_sql .= "\n);";
+ $table_sql .= "\n)";
$statements[] = $table_sql;
// do we need to add a sequence and a tigger for auto incrementing columns?
@@ -556,7 +561,7 @@ class phpbb_db_tools
$trigger .= "BEGIN\n";
$trigger .= "\tSELECT {$table_name}_seq.nextval\n";
$trigger .= "\tINTO :new.{$create_sequence}\n";
- $trigger .= "\tFROM dual\n";
+ $trigger .= "\tFROM dual;\n";
$trigger .= "END;";
$statements[] = $trigger;
@@ -566,7 +571,13 @@ class phpbb_db_tools
case 'firebird':
if ($create_sequence)
{
- $statements[] = "CREATE SEQUENCE {$table_name}_seq;";
+ $statements[] = "CREATE GENERATOR {$table_name}_gen;";
+ $statements[] = "SET GENERATOR {$table_name}_gen TO 0;";
+
+ $trigger = "CREATE TRIGGER t_$table_name FOR $table_name\n";
+ $trigger .= "BEFORE INSERT\nAS\nBEGIN\n";
+ $trigger .= "\tNEW.{$create_sequence} = GEN_ID({$table_name}_gen, 1);\nEND;";
+ $statements[] = $trigger;
}
break;
}
@@ -638,6 +649,19 @@ class phpbb_db_tools
$sqlite = true;
}
+ // Add tables?
+ if (!empty($schema_changes['add_tables']))
+ {
+ foreach ($schema_changes['add_tables'] as $table => $table_data)
+ {
+ $result = $this->sql_create_table($table, $table_data);
+ if ($this->return_statements)
+ {
+ $statements = array_merge($statements, $result);
+ }
+ }
+ }
+
// Change columns?
if (!empty($schema_changes['change_columns']))
{
@@ -681,10 +705,12 @@ class phpbb_db_tools
{
foreach ($columns as $column_name => $column_data)
{
- // Only add the column if it does not exist yet, else change it (to be consistent)
+ // Only add the column if it does not exist yet
if ($column_exists = $this->sql_column_exists($table, $column_name))
{
- $result = $this->sql_column_change($table, $column_name, $column_data, true);
+ continue;
+ // This is commented out here because it can take tremendous time on updates
+// $result = $this->sql_column_change($table, $column_name, $column_data, true);
}
else
{
@@ -695,7 +721,8 @@ class phpbb_db_tools
{
if ($column_exists)
{
- $sqlite_data[$table]['change_columns'][] = $result;
+ continue;
+// $sqlite_data[$table]['change_columns'][] = $result;
}
else
{
@@ -717,6 +744,11 @@ class phpbb_db_tools
{
foreach ($indexes as $index_name)
{
+ if (!$this->sql_index_exists($table, $index_name))
+ {
+ continue;
+ }
+
$result = $this->sql_index_drop($table, $index_name);
if ($this->return_statements)
@@ -777,6 +809,11 @@ class phpbb_db_tools
{
foreach ($index_array as $index_name => $column)
{
+ if ($this->sql_unique_index_exists($table, $index_name))
+ {
+ continue;
+ }
+
$result = $this->sql_create_unique_index($table, $index_name, $column);
if ($this->return_statements)
@@ -794,6 +831,11 @@ class phpbb_db_tools
{
foreach ($index_array as $index_name => $column)
{
+ if ($this->sql_index_exists($table, $index_name))
+ {
+ continue;
+ }
+
$result = $this->sql_create_index($table, $index_name, $column);
if ($this->return_statements)
@@ -1102,6 +1144,236 @@ class phpbb_db_tools
}
}
+ /**
+ * Check if a specified index exists in table. Does not return PRIMARY KEY and UNIQUE indexes.
+ *
+ * @param string $table_name Table to check the index at
+ * @param string $index_name The index name to check
+ *
+ * @return bool True if index exists, else false
+ */
+ function sql_index_exists($table_name, $index_name)
+ {
+ if ($this->sql_layer == 'mssql' || $this->sql_layer == 'mssqlnative')
+ {
+ $sql = "EXEC sp_statistics '$table_name'";
+ $result = $this->db->sql_query($sql);
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if ($row['TYPE'] == 3)
+ {
+ if (strtolower($row['INDEX_NAME']) == strtolower($index_name))
+ {
+ $this->db->sql_freeresult($result);
+ return true;
+ }
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ return false;
+ }
+
+ switch ($this->sql_layer)
+ {
+ case 'firebird':
+ $sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
+ FROM RDB\$INDICES
+ WHERE RDB\$RELATION_NAME = '" . strtoupper($table_name) . "'
+ AND RDB\$UNIQUE_FLAG IS NULL
+ AND RDB\$FOREIGN_KEY IS NULL";
+ $col = 'index_name';
+ break;
+
+ case 'postgres':
+ $sql = "SELECT ic.relname as index_name
+ FROM pg_class bc, pg_class ic, pg_index i
+ WHERE (bc.oid = i.indrelid)
+ AND (ic.oid = i.indexrelid)
+ AND (bc.relname = '" . $table_name . "')
+ AND (i.indisunique != 't')
+ AND (i.indisprimary != 't')";
+ $col = 'index_name';
+ break;
+
+ case 'mysql_40':
+ case 'mysql_41':
+ $sql = 'SHOW KEYS
+ FROM ' . $table_name;
+ $col = 'Key_name';
+ break;
+
+ case 'oracle':
+ $sql = "SELECT index_name
+ FROM user_indexes
+ WHERE table_name = '" . strtoupper($table_name) . "'
+ AND generated = 'N'
+ AND uniqueness = 'NONUNIQUE'";
+ $col = 'index_name';
+ break;
+
+ case 'sqlite':
+ $sql = "PRAGMA index_list('" . $table_name . "');";
+ $col = 'name';
+ break;
+ }
+
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (($this->sql_layer == 'mysql_40' || $this->sql_layer == 'mysql_41') && !$row['Non_unique'])
+ {
+ continue;
+ }
+
+ // These DBMS prefix index name with the table name
+ switch ($this->sql_layer)
+ {
+ case 'firebird':
+ case 'oracle':
+ case 'postgres':
+ case 'sqlite':
+ $row[$col] = substr($row[$col], strlen($table_name) + 1);
+ break;
+ }
+
+ if (strtolower($row[$col]) == strtolower($index_name))
+ {
+ $this->db->sql_freeresult($result);
+ return true;
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ return false;
+ }
+
+ /**
+ * Check if a specified index exists in table. Does not return PRIMARY KEY and UNIQUE indexes.
+ *
+ * @param string $table_name Table to check the index at
+ * @param string $index_name The index name to check
+ *
+ * @return bool True if index exists, else false
+ */
+ function sql_unique_index_exists($table_name, $index_name)
+ {
+ if ($this->sql_layer == 'mssql' || $this->sql_layer == 'mssqlnative')
+ {
+ $sql = "EXEC sp_statistics '$table_name'";
+ $result = $this->db->sql_query($sql);
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ // Usually NON_UNIQUE is the column we want to check, but we allow for both
+ if ($row['TYPE'] == 3)
+ {
+ if (strtolower($row['INDEX_NAME']) == strtolower($index_name))
+ {
+ $this->db->sql_freeresult($result);
+ return true;
+ }
+ }
+ }
+ $this->db->sql_freeresult($result);
+ return false;
+ }
+
+ switch ($this->sql_layer)
+ {
+ case 'firebird':
+ $sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
+ FROM RDB\$INDICES
+ WHERE RDB\$RELATION_NAME = '" . strtoupper($table_name) . "'
+ AND RDB\$UNIQUE_FLAG IS NOT NULL
+ AND RDB\$FOREIGN_KEY IS NULL";
+ $col = 'index_name';
+ break;
+
+ case 'postgres':
+ $sql = "SELECT ic.relname as index_name, i.indisunique
+ FROM pg_class bc, pg_class ic, pg_index i
+ WHERE (bc.oid = i.indrelid)
+ AND (ic.oid = i.indexrelid)
+ AND (bc.relname = '" . $table_name . "')
+ AND (i.indisprimary != 't')";
+ $col = 'index_name';
+ break;
+
+ case 'mysql_40':
+ case 'mysql_41':
+ $sql = 'SHOW KEYS
+ FROM ' . $table_name;
+ $col = 'Key_name';
+ break;
+
+ case 'oracle':
+ $sql = "SELECT index_name, table_owner
+ FROM user_indexes
+ WHERE table_name = '" . strtoupper($table_name) . "'
+ AND generated = 'N'
+ AND uniqueness = 'UNIQUE'";
+ $col = 'index_name';
+ break;
+
+ case 'sqlite':
+ $sql = "PRAGMA index_list('" . $table_name . "');";
+ $col = 'name';
+ break;
+ }
+
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (($this->sql_layer == 'mysql_40' || $this->sql_layer == 'mysql_41') && ($row['Non_unique'] || $row[$col] == 'PRIMARY'))
+ {
+ continue;
+ }
+
+ if ($this->sql_layer == 'sqlite' && !$row['unique'])
+ {
+ continue;
+ }
+
+ if ($this->sql_layer == 'postgres' && $row['indisunique'] != 't')
+ {
+ continue;
+ }
+
+ // These DBMS prefix index name with the table name
+ switch ($this->sql_layer)
+ {
+ case 'oracle':
+ // Two cases here... prefixed with U_[table_owner] and not prefixed with table_name
+ if (strpos($row[$col], 'U_') === 0)
+ {
+ $row[$col] = substr($row[$col], strlen('U_' . $row['table_owner']) + 1);
+ }
+ else if (strpos($row[$col], strtoupper($table_name)) === 0)
+ {
+ $row[$col] = substr($row[$col], strlen($table_name) + 1);
+ }
+ break;
+
+ case 'firebird':
+ case 'postgres':
+ case 'sqlite':
+ $row[$col] = substr($row[$col], strlen($table_name) + 1);
+ break;
+ }
+
+ if (strtolower($row[$col]) == strtolower($index_name))
+ {
+ $this->db->sql_freeresult($result);
+ return true;
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ return false;
+ }
+
/**
* Private method for performing sql statements (either execute them or return them)
* @access private
@@ -1139,6 +1411,11 @@ class phpbb_db_tools
*/
function sql_prepare_column_data($table_name, $column_name, $column_data)
{
+ if (strlen($column_name) > 30)
+ {
+ trigger_error("Column name '$column_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR);
+ }
+
// Get type
if (strpos($column_data[0], ':') !== false)
{
@@ -1371,24 +1648,29 @@ class phpbb_db_tools
switch ($this->sql_layer)
{
case 'firebird':
+ // Does not support AFTER statement, only POSITION (and there you need the column position)
$statements[] = 'ALTER TABLE ' . $table_name . ' ADD "' . strtoupper($column_name) . '" ' . $column_data['column_type_sql'];
break;
case 'mssql':
case 'mssqlnative':
+ // Does not support AFTER, only through temporary table
$statements[] = 'ALTER TABLE [' . $table_name . '] ADD [' . $column_name . '] ' . $column_data['column_type_sql_default'];
break;
case 'mysql_40':
case 'mysql_41':
- $statements[] = 'ALTER TABLE `' . $table_name . '` ADD COLUMN `' . $column_name . '` ' . $column_data['column_type_sql'];
+ $after = (!empty($column_data['after'])) ? ' AFTER ' . $column_data['after'] : '';
+ $statements[] = 'ALTER TABLE `' . $table_name . '` ADD COLUMN `' . $column_name . '` ' . $column_data['column_type_sql'] . $after;
break;
case 'oracle':
+ // Does not support AFTER, only through temporary table
$statements[] = 'ALTER TABLE ' . $table_name . ' ADD ' . $column_name . ' ' . $column_data['column_type_sql'];
break;
case 'postgres':
+ // Does not support AFTER, only through temporary table
if (version_compare($this->db->sql_server_info(true), '8.0', '>='))
{
$statements[] = 'ALTER TABLE ' . $table_name . ' ADD COLUMN "' . $column_name . '" ' . $column_data['column_type_sql'];
@@ -1774,6 +2056,13 @@ class phpbb_db_tools
{
$statements = array();
+ $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
+ if (strlen($table_name . $index_name) - strlen($table_prefix) > 24)
+ {
+ $max_length = $table_prefix + 24;
+ trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is $max_length characters.", E_USER_ERROR);
+ }
+
switch ($this->sql_layer)
{
case 'firebird':
@@ -1804,6 +2093,13 @@ class phpbb_db_tools
{
$statements = array();
+ $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
+ if (strlen($table_name . $index_name) - strlen($table_prefix) > 24)
+ {
+ $max_length = $table_prefix + 24;
+ trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is $max_length characters.", E_USER_ERROR);
+ }
+
// remove index length unless MySQL4
if ('mysql_40' != $this->sql_layer)
{
@@ -1957,6 +2253,7 @@ class phpbb_db_tools
}
else
{
+ // TODO: try to change pkey without removing trigger, generator or constraints. ATM this query may fail.
$statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql_type'];
}
break;
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index eeddf1f41b..9b45c085a2 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -241,6 +241,16 @@ class dbal
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
}
+ /**
+ * Returns whether results of a query need to be buffered to run a transaction while iterating over them.
+ *
+ * @return bool Whether buffering is required.
+ */
+ function sql_buffer_nested_transactions()
+ {
+ return false;
+ }
+
/**
* SQL Transaction
* @access private
@@ -767,7 +777,7 @@ class dbal