diff --git a/.gitignore b/.gitignore index c757210654..06b13923f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *~ /phpunit.xml +/phpBB/cache/twig/* /phpBB/cache/*.html /phpBB/cache/*.php /phpBB/cache/*.lock diff --git a/build/build.xml b/build/build.xml index 02518ac441..5b4cf8b496 100644 --- a/build/build.xml +++ b/build/build.xml @@ -169,26 +169,42 @@ command="git archive ${revision} | tar -xf - -C ../${dir}" checkreturn="true" /> - + + outputProperty='composer-has-dependencies' /> - + + - - + outputProperty='composer-ls-tree-output' /> + + + + + + + + + + + + + + + + + diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 03babe47cd..06ba15c7fa 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -33,9 +33,7 @@ else against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi -error=0 errors="" - if ! which "$PHP_BIN" >/dev/null 2>&1 then echo "PHP Syntax check failed:" @@ -73,63 +71,18 @@ do # check the staged file content for syntax errors # using php -l (lint) - # note: if display_errors=stderr in php.ini, - # parse errors are printed on stderr; otherwise - # they are printed on stdout. - # we filter everything other than parse errors - # with a grep below, therefore it should be safe - # to combine stdout and stderr in all circumstances - result=$(git cat-file -p $sha | "$PHP_BIN" -l 2>&1) + result=$(git cat-file -p $sha | "$PHP_BIN" -n -l -ddisplay_errors\=1 -derror_reporting\=E_ALL -dlog_errrors\=0 2>&1) if [ $? -ne 0 ] then - error=1 # Swap back in correct filenames - errors=$(echo "$errors"; echo "$result" |sed -e "s@in - on@in $filename on@g") + errors=$(echo "$errors"; echo "$result" | grep ':' | sed -e "s@in - on@in $filename on@g") fi done unset IFS -if [ $error -eq 1 ] +if [ -n "$errors" ] then - echo "PHP Syntax check failed:" - # php "display errors" (display_errors php.ini value) - # and "log errors" (log_errors php.ini value). - # these are independent settings - see main/main.c in php source. - # the "log errors" setting produces output which - # starts with "PHP Parse error:"; the "display errors" - # setting produces output starting with "Parse error:". - # if both are turned on php dumps the parse error twice. - # therefore here we try to grep for one version and - # if that yields no results grep for the other version. - # - # other fun php facts: - # - # 1. in cli, display_errors and log_errors have different - # destinations by default. display_errors prints to - # standard output and log_errors prints to standard error. - # whether these destinations make sense is left - # as an exercise for the reader. - # 2. as mentioned above, with all output turned on - # php will print parse errors twice, one time on stdout - # and one time on stderr. - # 3. it is possible to set both display_errors and log_errors - # to off. if this is done php will print the text - # "Errors parsing " but will not say what - # the errors are. useful behavior, this. - # 4. on my system display_errors defaults to on and - # log_errors defaults to off, therefore providing - # by default one copy of messages. your mileage may vary. - # 5. by setting display_errors=stderr and log_errors=on, - # both sets of messages will be printed on stderr. - # 6. php-cgi binary, given display_errors=stderr and - # log_errors=on, still prints both sets of messages - # on stderr, but formats one set as an html fragment. - # 7. your entry here? ;) - $echo_e "$errors" | grep "^Parse error:" - if [ $? -ne 0 ] - then - # match failed - $echo_e "$errors" | grep "^PHP Parse error:" - fi + echo "PHP Syntax check failed: " + $echo_e "$errors" exit 1 fi diff --git a/git-tools/merge.php b/git-tools/merge.php index 41a96c0890..f6142095fb 100755 --- a/git-tools/merge.php +++ b/git-tools/merge.php @@ -124,19 +124,34 @@ function get_repository_url($username, $repository, $ssh = false) function api_request($query) { - $contents = file_get_contents("http://github.com/api/v2/json/$query"); + return api_url_request("https://api.github.com/$query?per_page=100"); +} + +function api_url_request($url) +{ + $contents = file_get_contents($url, false, stream_context_create(array( + 'http' => array( + 'header' => "User-Agent: phpBB/1.0\r\n", + ), + ))); if ($contents === false) { throw new RuntimeException("Error: failed to retrieve pull request data\n", 4); } + $contents = json_decode($contents); - return json_decode($contents); + if (isset($contents->message) && strpos($contents->message, 'API Rate Limit') === 0) + { + throw new RuntimeException('Reached github API Rate Limit. Please try again later' . "\n", 4); + } + + return $contents; } function get_pull($username, $repository, $pull_id) { - $request = api_request("pulls/$username/$repository/$pull_id"); + $request = api_request("repos/$username/$repository/pulls/$pull_id"); $pull = $request->pull; diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 5f2e1609a7..4e144edae6 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -15,14 +15,14 @@ function show_usage() echo "$filename adds repositories of a github network as remotes to a local git repository.\n"; echo "\n"; - echo "Usage: [php] $filename -s collaborators|organisation|contributors|network [OPTIONS]\n"; + echo "Usage: [php] $filename -s collaborators|organisation|contributors|forks [OPTIONS]\n"; echo "\n"; echo "Scopes:\n"; echo " collaborators Repositories of people who have push access to the specified repository\n"; echo " contributors Repositories of people who have contributed to the specified repository\n"; echo " organisation Repositories of members of the organisation at github\n"; - echo " network All repositories of the whole github network\n"; + echo " forks All repositories of the whole github network\n"; echo "\n"; echo "Options:\n"; @@ -55,31 +55,31 @@ exit(work($scope, $username, $repository, $developer)); function work($scope, $username, $repository, $developer) { // Get some basic data - $network = get_network($username, $repository); + $forks = get_forks($username, $repository); $collaborators = get_collaborators($username, $repository); - if ($network === false || $collaborators === false) + if ($forks === false || $collaborators === false) { - echo "Error: failed to retrieve network or collaborators\n"; + echo "Error: failed to retrieve forks or collaborators\n"; return 1; } switch ($scope) { case 'collaborators': - $remotes = array_intersect_key($network, $collaborators); + $remotes = array_intersect_key($forks, $collaborators); break; case 'organisation': - $remotes = array_intersect_key($network, get_organisation_members($username)); + $remotes = array_intersect_key($forks, get_organisation_members($username)); break; case 'contributors': - $remotes = array_intersect_key($network, get_contributors($username, $repository)); + $remotes = array_intersect_key($forks, get_contributors($username, $repository)); break; - case 'network': - $remotes = $network; + case 'forks': + $remotes = $forks; break; default: @@ -145,26 +145,66 @@ function get_repository_url($username, $repository, $ssh = false) function api_request($query) { - $contents = file_get_contents("http://github.com/api/v2/json/$query"); + return api_url_request("https://api.github.com/$query?per_page=100"); +} + +function api_url_request($url) +{ + $contents = file_get_contents($url, false, stream_context_create(array( + 'http' => array( + 'header' => "User-Agent: phpBB/1.0\r\n", + ), + ))); + + $sub_request_result = array(); + // Check headers for pagination links + if (!empty($http_response_header)) + { + foreach ($http_response_header as $header_element) + { + // Find Link Header which gives us a link to the next page + if (strpos($header_element, 'Link: ') === 0) + { + list($head, $header_content) = explode(': ', $header_element); + foreach (explode(', ', $header_content) as $links) + { + list($url, $rel) = explode('; ', $links); + if ($rel == 'rel="next"') + { + // Found a next link, follow it and merge the results + $sub_request_result = api_url_request(substr($url, 1, -1)); + } + } + } + } + } + if ($contents === false) { return false; } - return json_decode($contents); + $contents = json_decode($contents); + + if (isset($contents->message) && strpos($contents->message, 'API Rate Limit') === 0) + { + throw new RuntimeException('Reached github API Rate Limit. Please try again later' . "\n", 4); + } + + return ($sub_request_result) ? array_merge($sub_request_result, $contents) : $contents; } function get_contributors($username, $repository) { - $request = api_request("repos/show/$username/$repository/contributors"); + $request = api_request("repos/$username/$repository/stats/contributors"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->contributors as $contributor) + foreach ($request as $contribution) { - $usernames[$contributor->login] = $contributor->login; + $usernames[$contribution->author->login] = $contribution->author->login; } return $usernames; @@ -172,14 +212,14 @@ function get_contributors($username, $repository) function get_organisation_members($username) { - $request = api_request("organizations/$username/public_members"); + $request = api_request("orgs/$username/public_members"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->users as $member) + foreach ($request as $member) { $usernames[$member->login] = $member->login; } @@ -189,35 +229,35 @@ function get_organisation_members($username) function get_collaborators($username, $repository) { - $request = api_request("repos/show/$username/$repository/collaborators"); + $request = api_request("repos/$username/$repository/collaborators"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->collaborators as $collaborator) + foreach ($request as $collaborator) { - $usernames[$collaborator] = $collaborator; + $usernames[$collaborator->login] = $collaborator->login; } return $usernames; } -function get_network($username, $repository) +function get_forks($username, $repository) { - $request = api_request("repos/show/$username/$repository/network"); + $request = api_request("repos/$username/$repository/forks"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->network as $network) + foreach ($request as $fork) { - $usernames[$network->owner] = array( - 'username' => $network->owner, - 'repository' => $network->name, + $usernames[$fork->owner->login] = array( + 'username' => $fork->owner->login, + 'repository' => $fork->name, ); } diff --git a/phpBB/adm/style/acp_board.html b/phpBB/adm/style/acp_board.html index 6b8ceb3ef6..1a09c4eee6 100644 --- a/phpBB/adm/style/acp_board.html +++ b/phpBB/adm/style/acp_board.html @@ -34,7 +34,7 @@ - {auth_tpl.TPL} + diff --git a/phpBB/adm/style/acp_forums.html b/phpBB/adm/style/acp_forums.html index 38369ee207..7b1466cfbd 100644 --- a/phpBB/adm/style/acp_forums.html +++ b/phpBB/adm/style/acp_forums.html @@ -437,7 +437,7 @@ -

{NAVIGATION} [{L_EDIT} | {L_DELETE} | {L_RESYNC}]

+

{NAVIGATION} [{L_EDIT} | {L_DELETE} | {L_RESYNC}]

diff --git a/phpBB/adm/style/acp_icons.html b/phpBB/adm/style/acp_icons.html index 373a7b890c..eca02d2798 100644 --- a/phpBB/adm/style/acp_icons.html +++ b/phpBB/adm/style/acp_icons.html @@ -243,8 +243,8 @@ diff --git a/phpBB/adm/style/auth_provider_ldap.html b/phpBB/adm/style/auth_provider_ldap.html new file mode 100644 index 0000000000..81afa44373 --- /dev/null +++ b/phpBB/adm/style/auth_provider_ldap.html @@ -0,0 +1,32 @@ +
+

{L_LDAP_SERVER_EXPLAIN}
+
+
+
+

{L_LDAP_PORT_EXPLAIN}
+
+
+
+

{L_LDAP_DN_EXPLAIN}
+
+
+
+

{L_LDAP_UID_EXPLAIN}
+
+
+
+

{L_LDAP_USER_FILTER_EXPLAIN}
+
+
+
+

{L_LDAP_EMAIL_EXPLAIN}
+
+
+
+

{L_LDAP_USER_EXPLAIN}
+
+
+
+

{L_LDAP_PASSWORD_EXPLAIN}
+
+
diff --git a/phpBB/adm/style/overall_footer.html b/phpBB/adm/style/overall_footer.html index 54ed4dcc9e..9202cec06b 100644 --- a/phpBB/adm/style/overall_footer.html +++ b/phpBB/adm/style/overall_footer.html @@ -38,7 +38,7 @@ -{SCRIPTS} +{$SCRIPTS} diff --git a/phpBB/adm/style/permission_roles_mask.html b/phpBB/adm/style/permission_roles_mask.html index 277310edbf..42a7fc3e4e 100644 --- a/phpBB/adm/style/permission_roles_mask.html +++ b/phpBB/adm/style/permission_roles_mask.html @@ -25,7 +25,7 @@ {role_mask.groups.GROUP_NAME} :: {L_GROUPS_NOT_ASSIGNED} - + diff --git a/phpBB/common.php b/phpBB/common.php index f6f109c3de..962a1f951f 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -46,7 +46,7 @@ if (!defined('PHPBB_INSTALLED')) $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path); // Eliminate . and .. from the path - require($phpbb_root_path . 'includes/filesystem.' . $phpEx); + require($phpbb_root_path . 'phpbb/filesystem.' . $phpEx); $phpbb_filesystem = new phpbb_filesystem(); $script_path = $phpbb_filesystem->clean_path($script_path); @@ -71,7 +71,7 @@ $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relati $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path; // Include files -require($phpbb_root_path . 'includes/class_loader.' . $phpEx); +require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); @@ -85,7 +85,7 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); // Setup class loader first -$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", $phpEx); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); diff --git a/phpBB/composer.json b/phpBB/composer.json index abc1df57b7..bf693d1950 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -6,11 +6,13 @@ "symfony/event-dispatcher": "2.1.*", "symfony/http-kernel": "2.1.*", "symfony/routing": "2.1.*", - "symfony/yaml": "2.1.*" + "symfony/yaml": "2.1.*", + "twig/twig": "1.13.*" }, "require-dev": { "fabpot/goutte": "v0.1.0", "phpunit/dbunit": "1.2.*", - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "3.7.*", + "phing/phing": "2.4.*" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index e3b564fb1a..1ba6cb6f83 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -3,21 +3,21 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "3792dc25490f24210ece3b40789c5b98", + "hash": "6e6125b88160e28568edcb9fd007abed", "packages": [ { "name": "symfony/config", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/Config", "source": { "type": "git", "url": "https://github.com/symfony/Config.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/Config/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -45,21 +45,21 @@ ], "description": "Symfony Config Component", "homepage": "http://symfony.com", - "time": "2013-04-22 04:28:40" + "time": "2013-05-09 15:22:40" }, { "name": "symfony/dependency-injection", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/DependencyInjection", "source": { "type": "git", "url": "https://github.com/symfony/DependencyInjection.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -99,17 +99,17 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -148,17 +148,17 @@ }, { "name": "symfony/http-foundation", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/HttpFoundation", "source": { "type": "git", "url": "https://github.com/symfony/HttpFoundation.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -187,21 +187,21 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "http://symfony.com", - "time": "2013-04-30 17:01:33" + "time": "2013-05-26 18:42:07" }, { "name": "symfony/http-kernel", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/HttpKernel", "source": { "type": "git", "url": "https://github.com/symfony/HttpKernel.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -249,21 +249,21 @@ ], "description": "Symfony HttpKernel Component", "homepage": "http://symfony.com", - "time": "2013-05-06 11:01:51" + "time": "2013-06-02 12:29:05" }, { "name": "symfony/routing", - "version": "v2.1.9", + "version": "v2.1.11", "target-dir": "Symfony/Component/Routing", "source": { "type": "git", "url": "https://github.com/symfony/Routing.git", - "reference": "v2.1.9" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Routing/zipball/v2.1.9", - "reference": "v2.1.9", + "url": "https://api.github.com/repos/symfony/Routing/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -302,21 +302,21 @@ ], "description": "Symfony Routing Component", "homepage": "http://symfony.com", - "time": "2013-03-23 07:47:35" + "time": "2013-05-06 10:48:41" }, { "name": "symfony/yaml", - "version": "v2.1.9", + "version": "v2.1.11", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "v2.1.9" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/v2.1.9", - "reference": "v2.1.9", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -344,7 +344,56 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2013-03-23 01:54:33" + "time": "2013-05-10 00:09:46" + }, + { + "name": "twig/twig", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Twig.git", + "reference": "v1.13.1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fabpot/Twig/zipball/v1.13.1", + "reference": "v1.13.1", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ], + "time": "2013-06-06 06:06:01" } ], "packages-dev": [ @@ -492,6 +541,58 @@ ], "time": "2012-12-19 23:06:35" }, + { + "name": "phing/phing", + "version": "2.4.14", + "source": { + "type": "git", + "url": "https://github.com/phingofficial/phing", + "reference": "2.4.14" + }, + "dist": { + "type": "zip", + "url": "https://github.com/phingofficial/phing/archive/2.4.14.zip", + "reference": "2.4.14", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "bin": [ + "bin/phing" + ], + "type": "library", + "autoload": { + "classmap": [ + "classes/phing/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "classes" + ], + "license": [ + "LGPL3" + ], + "authors": [ + { + "name": "Michiel Rook", + "email": "mrook@php.net" + }, + { + "name": "Phing Community", + "homepage": "http://www.phing.info/trac/wiki/Development/Contributors" + } + ], + "description": "PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.", + "homepage": "http://www.phing.info/", + "keywords": [ + "build", + "task", + "tool" + ], + "time": "2012-11-29 21:23:47" + }, { "name": "phpunit/dbunit", "version": "1.2.3", @@ -552,16 +653,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "1.2.9", + "version": "1.2.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "1.2.9" + "reference": "1.2.12" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1.2.9", - "reference": "1.2.9", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1.2.12", + "reference": "1.2.12", "shasum": "" }, "require": { @@ -570,11 +671,19 @@ "phpunit/php-text-template": ">=1.1.1@stable", "phpunit/php-token-stream": ">=1.1.3@stable" }, + "require-dev": { + "phpunit/phpunit": "3.7.*@dev" + }, "suggest": { "ext-dom": "*", "ext-xdebug": ">=2.0.5" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, "autoload": { "classmap": [ "PHP/" @@ -601,7 +710,7 @@ "testing", "xunit" ], - "time": "2013-02-26 18:55:56" + "time": "2013-07-06 06:26:16" }, { "name": "phpunit/php-file-iterator", @@ -783,16 +892,16 @@ }, { "name": "phpunit/phpunit", - "version": "3.7.19", + "version": "3.7.22", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3.7.19" + "reference": "3.7.22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3.7.19", - "reference": "3.7.19", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3.7.22", + "reference": "3.7.22", "shasum": "" }, "require": { @@ -801,12 +910,12 @@ "ext-reflection": "*", "ext-spl": "*", "php": ">=5.3.3", - "phpunit/php-code-coverage": ">=1.2.1,<1.3.0", + "phpunit/php-code-coverage": "~1.2.1", "phpunit/php-file-iterator": ">=1.3.1", "phpunit/php-text-template": ">=1.1.1", - "phpunit/php-timer": ">=1.0.2,<1.1.0", - "phpunit/phpunit-mock-objects": ">=1.2.0,<1.3.0", - "symfony/yaml": ">=2.0.0,<2.3.0" + "phpunit/php-timer": "~1.0.2", + "phpunit/phpunit-mock-objects": "~1.2.0", + "symfony/yaml": "~2.0" }, "require-dev": { "pear-pear/pear": "1.9.4" @@ -853,7 +962,7 @@ "testing", "xunit" ], - "time": "2013-03-25 11:45:06" + "time": "2013-07-06 06:29:15" }, { "name": "phpunit/phpunit-mock-objects", @@ -906,17 +1015,17 @@ }, { "name": "symfony/browser-kit", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/BrowserKit", "source": { "type": "git", "url": "https://github.com/symfony/BrowserKit.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/BrowserKit/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/BrowserKit/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -956,17 +1065,17 @@ }, { "name": "symfony/css-selector", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/CssSelector", "source": { "type": "git", "url": "https://github.com/symfony/CssSelector.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/CssSelector/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/CssSelector/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -994,21 +1103,21 @@ ], "description": "Symfony CssSelector Component", "homepage": "http://symfony.com", - "time": "2013-01-09 08:51:07" + "time": "2013-05-17 00:31:34" }, { "name": "symfony/dom-crawler", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/DomCrawler", "source": { "type": "git", "url": "https://github.com/symfony/DomCrawler.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/DomCrawler/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/DomCrawler/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -1042,21 +1151,21 @@ ], "description": "Symfony DomCrawler Component", "homepage": "http://symfony.com", - "time": "2013-03-27 17:13:16" + "time": "2013-05-16 00:06:15" }, { "name": "symfony/finder", - "version": "v2.1.10", + "version": "v2.1.11", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", "url": "https://github.com/symfony/Finder.git", - "reference": "v2.1.10" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/v2.1.10", - "reference": "v2.1.10", + "url": "https://api.github.com/repos/symfony/Finder/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -1084,21 +1193,21 @@ ], "description": "Symfony Finder Component", "homepage": "http://symfony.com", - "time": "2013-03-06 19:26:55" + "time": "2013-05-25 15:47:15" }, { "name": "symfony/process", - "version": "v2.1.9", + "version": "v2.1.11", "target-dir": "Symfony/Component/Process", "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "v2.1.9" + "reference": "v2.1.11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/v2.1.9", - "reference": "v2.1.9", + "url": "https://api.github.com/repos/symfony/Process/zipball/v2.1.11", + "reference": "v2.1.11", "shasum": "" }, "require": { @@ -1126,7 +1235,7 @@ ], "description": "Symfony Process Component", "homepage": "http://symfony.com", - "time": "2013-03-23 07:44:01" + "time": "2013-05-06 10:21:56" } ], "aliases": [ diff --git a/phpBB/config/auth_providers.yml b/phpBB/config/auth_providers.yml new file mode 100644 index 0000000000..bcc448e4d7 --- /dev/null +++ b/phpBB/config/auth_providers.yml @@ -0,0 +1,37 @@ +services: + auth.provider_collection: + class: phpbb_di_service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: auth.provider } + auth.provider.db: + class: phpbb_auth_provider_db + arguments: + - @dbal.conn + - @config + - @request + - @user + - %core.root_path% + - %core.php_ext% + tags: + - { name: auth.provider } + auth.provider.apache: + class: phpbb_auth_provider_apache + arguments: + - @dbal.conn + - @config + - @request + - @user + - %core.root_path% + - %core.php_ext% + tags: + - { name: auth.provider } + auth.provider.ldap: + class: phpbb_auth_provider_ldap + arguments: + - @dbal.conn + - @config + - @user + tags: + - { name: auth.provider } diff --git a/phpBB/config/feed.yml b/phpBB/config/feed.yml index 59eeafd458..5a4cdae815 100644 --- a/phpBB/config/feed.yml +++ b/phpBB/config/feed.yml @@ -23,6 +23,7 @@ services: - @cache.driver - @user - @auth + - @content.visibility - %core.php_ext% feed.forums: @@ -35,6 +36,7 @@ services: - @cache.driver - @user - @auth + - @content.visibility - %core.php_ext% feed.news: @@ -47,6 +49,7 @@ services: - @cache.driver - @user - @auth + - @content.visibility - %core.php_ext% feed.overall: @@ -59,6 +62,7 @@ services: - @cache.driver - @user - @auth + - @content.visibility - %core.php_ext% feed.topic: @@ -71,6 +75,7 @@ services: - @cache.driver - @user - @auth + - @content.visibility - %core.php_ext% feed.topics: @@ -83,6 +88,7 @@ services: - @cache.driver - @user - @auth + - @content.visibility - %core.php_ext% feed.topics_active: @@ -95,4 +101,5 @@ services: - @cache.driver - @user - @auth + - @content.visibility - %core.php_ext% diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index bb96953bcf..c1579cfb57 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -5,6 +5,7 @@ imports: - { resource: migrator.yml } - { resource: avatars.yml } - { resource: feed.yml } + - { resource: auth_providers.yml } services: auth: @@ -65,6 +66,19 @@ services: - @dbal.conn - %tables.config_text% + content.visibility: + class: phpbb_content_visibility + arguments: + - @auth + - @dbal.conn + - @user + - %core.root_path% + - %core.php_ext% + - %tables.forums% + - %tables.posts% + - %tables.topics% + - %tables.users% + controller.helper: class: phpbb_controller_helper arguments: @@ -78,7 +92,7 @@ services: arguments: - @user - @service_container - - @ext.finder + - @style cron.task_collection: class: phpbb_di_service_collection @@ -112,7 +126,6 @@ services: - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] dbal.tools: - file: %core.root_path%includes/db/db_tools.%core.php_ext% class: phpbb_db_tools arguments: - @dbal.conn @@ -254,15 +267,15 @@ services: class: phpbb_style_path_provider template: - class: phpbb_template + class: phpbb_template_twig arguments: - %core.root_path% - %core.php_ext% - @config - @user - - @style.resource_locator - @template_context - @ext.manager + - %core.adm_relative_path% template_context: class: phpbb_template_context diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml index ec5fec23ad..fdb448f4e0 100644 --- a/phpBB/config/tables.yml +++ b/phpBB/config/tables.yml @@ -2,10 +2,13 @@ parameters: tables.config: %core.table_prefix%config tables.config_text: %core.table_prefix%config_text tables.ext: %core.table_prefix%ext + tables.forums: %core.table_prefix%forums tables.log: %core.table_prefix%log tables.migrations: %core.table_prefix%migrations tables.modules: %core.table_prefix%modules tables.notification_types: %core.table_prefix%notification_types tables.notifications: %core.table_prefix%notifications + tables.posts: %core.table_prefix%posts + tables.topics: %core.table_prefix%topics tables.user_notifications: %core.table_prefix%user_notifications tables.users: %core.table_prefix%users diff --git a/phpBB/develop/benchmark.php b/phpBB/develop/benchmark.php index c867b9262e..c653fdaa24 100644 --- a/phpBB/develop/benchmark.php +++ b/phpBB/develop/benchmark.php @@ -192,13 +192,13 @@ function get_topic_count($forum_id) { global $db; - $sql = "SELECT forum_topics + $sql = "SELECT forum_topics_approved FROM " . FORUMS_TABLE . " WHERE (forum_id = $forum_id)"; if($result = $db->sql_query($sql)) { $row = $db->sql_fetchrow($result); - $topic_count = $row['forum_topics']; + $topic_count = $row['forum_topics_approved']; unset($result); unset($row); @@ -263,7 +263,7 @@ function make_post($new_topic_id, $forum_id, $user_id, $post_username, $text, $m $post_message = prepare_message($text, $html_on, $bbcode_on, $smilies_on, $bbcode_uid); - $sql = "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, attach_id, icon_id, post_username, post_time, poster_ip, post_approved, bbcode_uid, enable_bbcode, enable_html, enable_smilies, enable_sig, post_subject, post_text) + $sql = "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, attach_id, icon_id, post_username, post_time, poster_ip, post_visibility, bbcode_uid, enable_bbcode, enable_html, enable_smilies, enable_sig, post_subject, post_text) VALUES ($new_topic_id, $forum_id, $user_id, 0, 0, '$post_username', $current_time, '$user_ip', 1, '$bbcode_uid', $bbcode_on, $html_on, $smilies_on, $attach_sig, '$post_subject', '$post_message')"; $result = $db->sql_query($sql); @@ -282,10 +282,10 @@ function make_post($new_topic_id, $forum_id, $user_id, $post_username, $text, $m if($db->sql_query($sql)) { $sql = "UPDATE " . FORUMS_TABLE . " - SET forum_last_post_id = $new_post_id, forum_posts = forum_posts + 1"; + SET forum_last_post_id = $new_post_id, forum_posts_approved = forum_posts_approved + 1"; if($mode == "newtopic") { - $sql .= ", forum_topics = forum_topics + 1"; + $sql .= ", forum_topics_approved = forum_topics_approved + 1"; } $sql .= " WHERE forum_id = $forum_id"; diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 0fd1a722ca..316fbe19e6 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1104,9 +1104,12 @@ function get_schema_struct() 'forum_topics_per_page' => array('TINT:4', 0), 'forum_type' => array('TINT:4', 0), 'forum_status' => array('TINT:4', 0), - 'forum_posts' => array('UINT', 0), - 'forum_topics' => array('UINT', 0), - 'forum_topics_real' => array('UINT', 0), + 'forum_posts_approved' => array('UINT', 0), + 'forum_posts_unapproved' => array('UINT', 0), + 'forum_posts_softdeleted' => array('UINT', 0), + 'forum_topics_approved' => array('UINT', 0), + 'forum_topics_unapproved' => array('UINT', 0), + 'forum_topics_softdeleted' => array('UINT', 0), 'forum_last_post_id' => array('UINT', 0), 'forum_last_poster_id' => array('UINT', 0), 'forum_last_post_subject' => array('STEXT_UNI', ''), @@ -1381,7 +1384,7 @@ function get_schema_struct() 'icon_id' => array('UINT', 0), 'poster_ip' => array('VCHAR:40', ''), 'post_time' => array('TIMESTAMP', 0), - 'post_approved' => array('BOOL', 1), + 'post_visibility' => array('TINT:3', 0), 'post_reported' => array('BOOL', 0), 'enable_bbcode' => array('BOOL', 1), 'enable_smilies' => array('BOOL', 1), @@ -1400,6 +1403,9 @@ function get_schema_struct() 'post_edit_user' => array('UINT', 0), 'post_edit_count' => array('USINT', 0), 'post_edit_locked' => array('BOOL', 0), + 'post_delete_time' => array('TIMESTAMP', 0), + 'post_delete_reason' => array('STEXT_UNI', ''), + 'post_delete_user' => array('UINT', 0), ), 'PRIMARY_KEY' => 'post_id', 'KEYS' => array( @@ -1407,7 +1413,7 @@ function get_schema_struct() 'topic_id' => array('INDEX', 'topic_id'), 'poster_ip' => array('INDEX', 'poster_ip'), 'poster_id' => array('INDEX', 'poster_id'), - 'post_approved' => array('INDEX', 'post_approved'), + 'post_visibility' => array('INDEX', 'post_visibility'), 'post_username' => array('INDEX', 'post_username'), 'tid_post_time' => array('INDEX', array('topic_id', 'post_time')), ), @@ -1739,15 +1745,16 @@ function get_schema_struct() 'forum_id' => array('UINT', 0), 'icon_id' => array('UINT', 0), 'topic_attachment' => array('BOOL', 0), - 'topic_approved' => array('BOOL', 1), + 'topic_visibility' => array('TINT:3', 0), 'topic_reported' => array('BOOL', 0), 'topic_title' => array('STEXT_UNI', '', 'true_sort'), 'topic_poster' => array('UINT', 0), 'topic_time' => array('TIMESTAMP', 0), 'topic_time_limit' => array('TIMESTAMP', 0), 'topic_views' => array('UINT', 0), - 'topic_replies' => array('UINT', 0), - 'topic_replies_real' => array('UINT', 0), + 'topic_posts_approved' => array('UINT', 0), + 'topic_posts_unapproved' => array('UINT', 0), + 'topic_posts_softdeleted' => array('UINT', 0), 'topic_status' => array('TINT:3', 0), 'topic_type' => array('TINT:3', 0), 'topic_first_post_id' => array('UINT', 0), @@ -1769,14 +1776,17 @@ function get_schema_struct() 'poll_max_options' => array('TINT:4', 1), 'poll_last_vote' => array('TIMESTAMP', 0), 'poll_vote_change' => array('BOOL', 0), + 'topic_delete_time' => array('TIMESTAMP', 0), + 'topic_delete_reason' => array('STEXT_UNI', ''), + 'topic_delete_user' => array('UINT', 0), ), 'PRIMARY_KEY' => 'topic_id', 'KEYS' => array( 'forum_id' => array('INDEX', 'forum_id'), 'forum_id_type' => array('INDEX', array('forum_id', 'topic_type')), 'last_post_time' => array('INDEX', 'topic_last_post_time'), - 'topic_approved' => array('INDEX', 'topic_approved'), - 'forum_appr_last' => array('INDEX', array('forum_id', 'topic_approved', 'topic_last_post_id')), + 'topic_visibility' => array('INDEX', 'topic_visibility'), + 'forum_appr_last' => array('INDEX', array('forum_id', 'topic_visibility', 'topic_last_post_id')), 'fid_time_moved' => array('INDEX', array('forum_id', 'topic_last_post_time', 'topic_moved_id')), ), ); diff --git a/phpBB/develop/fill.php b/phpBB/develop/fill.php index e3b986e163..696b1e31c0 100644 --- a/phpBB/develop/fill.php +++ b/phpBB/develop/fill.php @@ -86,7 +86,7 @@ switch ($mode) $topic_rows[] = "($topic_id, $forum_id, '$forum_id-$topic_id', " . (($topic_id % 34) ? '0' : '1') . ')'; - $sql = 'INSERT IGNORE INTO ' . POSTS_TABLE . ' (topic_id, forum_id, poster_id, post_subject, post_text, post_username, post_approved, post_time, post_reported) + $sql = 'INSERT IGNORE INTO ' . POSTS_TABLE . ' (topic_id, forum_id, poster_id, post_subject, post_text, post_username, post_visibility, post_time, post_reported) VALUES '; $rows = array(); diff --git a/phpBB/develop/merge_post_tables.php b/phpBB/develop/merge_post_tables.php index 8edc330a0a..d687a292f2 100644 --- a/phpBB/develop/merge_post_tables.php +++ b/phpBB/develop/merge_post_tables.php @@ -50,7 +50,7 @@ switch ($db->sql_layer) ADD PRIMARY KEY (post_id), ADD INDEX topic_id (topic_id), ADD INDEX poster_ip (poster_ip), - ADD INDEX post_approved (post_approved), + ADD INDEX post_visibility (post_visibility), MODIFY COLUMN post_id mediumint(8) UNSIGNED NOT NULL auto_increment, ADD COLUMN post_encoding varchar(11) DEFAULT \'iso-8859-15\' NOT NULL'; break; @@ -162,7 +162,7 @@ while ($row = $db->sql_fetchrow($result)) $forum_id = $row['forum_id']; $sql_ary[] = "UPDATE " . $table_prefix . "forums - SET forum_last_poster_id = " . ((!empty($row['user_id']) && $row['user_id'] != ANONYMOUS) ? $row['user_id'] : ANONYMOUS) . ", forum_last_poster_name = '" . ((!empty($row['user_id']) && $row['user_id'] != ANONYMOUS) ? addslashes($row['username']) : addslashes($row['post_username'])) . "', forum_last_post_time = " . $row['post_time'] . ", forum_posts = " . (($post_count[$forum_id]) ? $post_count[$forum_id] : 0) . ", forum_topics = " . (($topic_count[$forum_id]) ? $topic_count[$forum_id] : 0) . " + SET forum_last_poster_id = " . ((!empty($row['user_id']) && $row['user_id'] != ANONYMOUS) ? $row['user_id'] : ANONYMOUS) . ", forum_last_poster_name = '" . ((!empty($row['user_id']) && $row['user_id'] != ANONYMOUS) ? addslashes($row['username']) : addslashes($row['post_username'])) . "', forum_last_post_time = " . $row['post_time'] . ", forum_posts_approved = " . (($post_count[$forum_id]) ? $post_count[$forum_id] : 0) . ", forum_topics_approved = " . (($topic_count[$forum_id]) ? $topic_count[$forum_id] : 0) . " WHERE forum_id = $forum_id"; $sql = "SELECT t.topic_id, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time diff --git a/phpBB/develop/mysql_upgrader.php b/phpBB/develop/mysql_upgrader.php index 7f82ebfeab..597dd5e932 100644 --- a/phpBB/develop/mysql_upgrader.php +++ b/phpBB/develop/mysql_upgrader.php @@ -552,9 +552,12 @@ function get_schema_struct() 'forum_topics_per_page' => array('TINT:4', 0), 'forum_type' => array('TINT:4', 0), 'forum_status' => array('TINT:4', 0), - 'forum_posts' => array('UINT', 0), - 'forum_topics' => array('UINT', 0), - 'forum_topics_real' => array('UINT', 0), + 'forum_posts_approved' => array('UINT', 0), + 'forum_posts_unapproved' => array('UINT', 0), + 'forum_posts_softdeleted' => array('UINT', 0), + 'forum_topics_approved' => array('UINT', 0), + 'forum_topics_unapproved' => array('UINT', 0), + 'forum_topics_softdeleted' => array('UINT', 0), 'forum_last_post_id' => array('UINT', 0), 'forum_last_poster_id' => array('UINT', 0), 'forum_last_post_subject' => array('STEXT_UNI', ''), @@ -768,7 +771,7 @@ function get_schema_struct() 'icon_id' => array('UINT', 0), 'poster_ip' => array('VCHAR:40', ''), 'post_time' => array('TIMESTAMP', 0), - 'post_approved' => array('BOOL', 1), + 'post_visibility' => array('TINT:3', 0), 'post_reported' => array('BOOL', 0), 'enable_bbcode' => array('BOOL', 1), 'enable_smilies' => array('BOOL', 1), @@ -794,7 +797,7 @@ function get_schema_struct() 'topic_id' => array('INDEX', 'topic_id'), 'poster_ip' => array('INDEX', 'poster_ip'), 'poster_id' => array('INDEX', 'poster_id'), - 'post_approved' => array('INDEX', 'post_approved'), + 'post_visibility' => array('INDEX', 'post_visibility'), 'post_username' => array('INDEX', 'post_username'), 'tid_post_time' => array('INDEX', array('topic_id', 'post_time')), ), @@ -1107,15 +1110,16 @@ function get_schema_struct() 'forum_id' => array('UINT', 0), 'icon_id' => array('UINT', 0), 'topic_attachment' => array('BOOL', 0), - 'topic_approved' => array('BOOL', 1), + 'topic_visibility' => array('TINT:3', 0), 'topic_reported' => array('BOOL', 0), 'topic_title' => array('STEXT_UNI', '', 'true_sort'), 'topic_poster' => array('UINT', 0), 'topic_time' => array('TIMESTAMP', 0), 'topic_time_limit' => array('TIMESTAMP', 0), 'topic_views' => array('UINT', 0), - 'topic_replies' => array('UINT', 0), - 'topic_replies_real' => array('UINT', 0), + 'topic_posts_approved' => array('UINT', 0), + 'topic_posts_unapproved' => array('UINT', 0), + 'topic_posts_softdeleted' => array('UINT', 0), 'topic_status' => array('TINT:3', 0), 'topic_type' => array('TINT:3', 0), 'topic_first_post_id' => array('UINT', 0), @@ -1143,8 +1147,8 @@ function get_schema_struct() 'forum_id' => array('INDEX', 'forum_id'), 'forum_id_type' => array('INDEX', array('forum_id', 'topic_type')), 'last_post_time' => array('INDEX', 'topic_last_post_time'), - 'topic_approved' => array('INDEX', 'topic_approved'), - 'forum_appr_last' => array('INDEX', array('forum_id', 'topic_approved', 'topic_last_post_id')), + 'topic_visibility' => array('INDEX', 'topic_visibility'), + 'forum_appr_last' => array('INDEX', array('forum_id', 'topic_visibility', 'topic_last_post_id')), 'fid_time_moved' => array('INDEX', array('forum_id', 'topic_last_post_time', 'topic_moved_id')), ), ); diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 942912a593..97f8c40383 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -46,6 +46,7 @@
  1. Changelog
      +
    1. Changes since 3.0.11
    2. Changes since 3.0.10
    3. Changes since 3.0.9
    4. Changes since 3.0.8
    5. @@ -85,7 +86,154 @@
      -

      1.i. Changes since 3.0.10

      +

      1.i. Changes since 3.0.11

      + +

      Bug

      +
        +
      • [PHPBB3-6723] - Empty message in deleted messages in PM history
      • +
      • [PHPBB3-7262] - Clarify docs about is_dynamic not being updated by set_config()
      • +
      • [PHPBB3-8319] - LOCAL_URL not enforced in bbcodes
      • +
      • [PHPBB3-9551] - Mysql fulltext index creation fails due to partial collation change
      • +
      • [PHPBB3-9975] - Hard coded language in sessions.php
      • +
      • [PHPBB3-10184] - Bots can be sent private messages
      • +
      • [PHPBB3-10491] - Fatal error in functional tests when server returns 404
      • +
      • [PHPBB3-10568] - Modify the trigger language when you edit a PM
      • +
      • [PHPBB3-10602] - A bug in mail queue processing
      • +
      • [PHPBB3-10661] - UCP > PM > Compose > enumerated recipients > BCC group misses a &nbsp; (prosilver)
      • +
      • [PHPBB3-10678] - Provide Firebird, Oracle, and increased MSSQL support in unit tests
      • +
      • [PHPBB3-10772] - trigger_error is using the default style
      • +
      • [PHPBB3-10789] - PM print template (prosilver) with unnecessary variables
      • +
      • [PHPBB3-10820] - Display images directly in IE9 and 10 instead of download
      • +
      • [PHPBB3-10828] - PostgreSQL dbal tests try to connect to the database named as user specified in configuration
      • +
      • [PHPBB3-10838] - Functional tests are not mentioned in RUNNING_TESTS.txt
      • +
      • [PHPBB3-10840] - If you add a member to a group, the form_token can be set to 0 if the creation_time is 0 too. Maybe even if creation_time is unchanged.
      • +
      • [PHPBB3-10848] - Wrong redirect to installer from acp
      • +
      • [PHPBB3-10850] - create_schema_files.php is not creating the oracle or postgres' schema file properly
      • +
      • [PHPBB3-10879] - prosilver: attachment-link will be displayed wrong, when filename is too long
      • +
      • [PHPBB3-10880] - m_approve should not imply f_noapprove
      • +
      • [PHPBB3-10896] - board_email & board_contact are not validated as email addresses in ACP
      • +
      • [PHPBB3-10897] - Bot Definitions are outdated
      • +
      • [PHPBB3-10918] - docs/INSTALL.html claims there are tar.gz packages
      • +
      • [PHPBB3-10943] - Search Box should display keywords entered by the user
      • +
      • [PHPBB3-10967] - PHPBB_USE_BOARD_URL_PATH not implemented in posting_gen_topic_icons
      • +
      • [PHPBB3-10986] - Invalid email message ids because config variable server_name is used even when force server URL settings is disabled
      • +
      • [PHPBB3-10995] - Return value of $db->sql_fetchrow() on empty tables is not consistent on mssqlnative
      • +
      • [PHPBB3-10996] - Travis tests fail on Postgres because database does not exist
      • +
      • [PHPBB3-11034] - The functional test case framework does not install a full board each time
      • +
      • [PHPBB3-11066] - MSSQLnative driver contains debug code error_reporting(E_ALL)
      • +
      • [PHPBB3-11069] - missing closing span in subsilver2 simple_footer.html
      • +
      • [PHPBB3-11081] - Duplicated /TD in styles/subsilver2/template/catpcha_qa.html
      • +
      • [PHPBB3-11093] - acp_users_overview.html has a wrongly placed </dd>
      • +
      • [PHPBB3-11094] - prosilver: searching for users: no textbox for Jabber
      • +
      • [PHPBB3-11105] - Missing mandatory space in meta http-equiv=refresh
      • +
      • [PHPBB3-11112] - phpBB Footer Link should be SSL
      • +
      • [PHPBB3-11122] - Update docs/AUTHORS for 3.0.12-RC1
      • +
      • [PHPBB3-11144] - {FORUM_NAME} is not filled in login mask when logging into a password protected forum
      • +
      • [PHPBB3-11145] - ATTACHED_IMAGE_NOT_IMAGE thrown because of file limit in php.ini
      • +
      • [PHPBB3-11158] - modules table lacks acl_u_sig for signature module
      • +
      • [PHPBB3-11159] - Coding guidelines: static public
      • +
      • [PHPBB3-11164] - Composer not finding symfony/config in PHP 5.3.3
      • +
      • [PHPBB3-11178] - database_update.php should not set error_reporting to E_ALL
      • +
      • [PHPBB3-11186] - Database unit tests fail on windows using sqlite2
      • +
      • [PHPBB3-11190] - Functional tests do not clear the cache between each test
      • +
      • [PHPBB3-11196] - /includes/session.php sends 401 HTTP status with "Not authorized" instead of "Unauthorized"
      • +
      • [PHPBB3-11219] - Database sequences are not updated for tests using fixtures with auto_incremented columns
      • +
      • [PHPBB3-11227] - @return void -> @return null
      • +
      • [PHPBB3-11233] - Anonymous can be selected as a PM recipient
      • +
      • [PHPBB3-11248] - CRLF line endings
      • +
      • [PHPBB3-11262] - .lock files are not in .gitignore
      • +
      • [PHPBB3-11265] - Functional tests do not assert that board installation succeeded
      • +
      • [PHPBB3-11269] - Travis functional test case errors
      • +
      • [PHPBB3-11278] - Firebird tables are not removed correctly on 3.0.9-rc1 update
      • +
      • [PHPBB3-11288] - Search fooled by hyphens
      • +
      • [PHPBB3-11291] - "Could not open input file: ../composer.phar" error during phing's create-package
      • +
      • [PHPBB3-11292] - Newlines removed in display of PM reports, no clickable links in PM reports
      • +
      • [PHPBB3-11301] - "String offset cast occured" error on PHP 5.4
      • +
      • [PHPBB3-11304] - check_form_key breaks in tests when form is submitted in the same second it is retrieved
      • +
      • [PHPBB3-11343] - Loose string comparison during new password activation
      • +
      • [PHPBB3-11355] - Incorrect error message when no user selected for action on group membership management page
      • +
      • [PHPBB3-11358] - Success message even withot selecting a user and performing a group operation
      • +
      • [PHPBB3-11361] - "Array to string conversion" error in $user->format_date()
      • +
      • [PHPBB3-11493] - Functional tests should fail if any debug output is made
      • +
      • [PHPBB3-11517] - Numbering is wrong in coding guidelines
      • +
      • [PHPBB3-11536] - Installer incorrectly removes /install from script_path
      • +
      • [PHPBB3-11537] - UCP group manage page's error box differs heavily from the rest of the UCP
      • +
      • [PHPBB3-11538] - SQL error on UCP groups manage page caused by setting color to 7 characters long string
      • +
      • [PHPBB3-11544] - Add admin_login() to 3.0 functional test case
      • +
      • [PHPBB3-11545] - is_absolute() should not depend on DIRECTORY_SEPARATOR
      • +
      • [PHPBB3-11546] - is_absolute() throws E_NOTICE for empty string
      • +
      • [PHPBB3-11547] - Test fixtures do not support utf8 characters
      • +
      • [PHPBB3-11548] - Untranslated TOO_SHORT in UCP "Manage Groups"
      • +
      • [PHPBB3-11566] - Reporting a post should require a captcha to be solved by guests
      • +
      • [PHPBB3-11568] - Functional tests fail with retrieving install pages using file_get_contents
      • +
      • [PHPBB3-11575] - phpbb_dbal_order_lower_test::test_cross_join should be called test_order_lower
      • +
      • [PHPBB3-11578] - Missing underscore after function prefix in validate_data()
      • +
      • [PHPBB3-11579] - Add unit tests for validate_data()
      • +
      • [PHPBB3-11580] - Avoid API Limit from composer downloads on github
      • +
      • [PHPBB3-11588] - install/install_update.php should use version.phpbb.com instead of www
      • +
      • [PHPBB3-11590] - Close database connections from tests whenever possible
      • +
      • [PHPBB3-11601] - Allow manual resync of database columns in unit tests not only on fixture load
      • +
      • [PHPBB3-11603] - git-tools use invalid api urls
      • +
      • [PHPBB3-11604] - Functional tests fail when phpBB can not create the config file
      • +
      • [PHPBB3-11617] - Missing U_ACTION in acp_captcha.php
      • +
      • [PHPBB3-11618] - Template tests fail on some systems due to a PHP error in glob()
      • +
      • [PHPBB3-11619] - get_remote_file() should use HTTP 1.0
      • +
      • [PHPBB3-11630] - Improvements to the PHP lint pre-commit hook
      • +
      • [PHPBB3-11644] - Skip phpbb_dbal_order_lower_test on MySQL 5.6
      • +
      • [PHPBB3-11662] - "occured" should be "occurred"
      • +
      • [PHPBB3-11670] - Replace trademark ™ with ® on "Welcome to phpBB" install page
      • +
      • [PHPBB3-11674] - Do not include vendor folder if there are no dependencies.
      • +
      +

      Improvement

      +
        +
      • [PHPBB3-8743] - New topic / reply notifications do not contain author's name.
      • +
      • [PHPBB3-10050] - subsilver2: Do not show "Mark topics as read" when there are no topics
      • +
      • [PHPBB3-10205] - More informative reporting of errors when database connection fails (MySQL and others)
      • +
      • [PHPBB3-10716] - PHP-parse all php files as part of the test suite
      • +
      • [PHPBB3-10841] - Disable style and language selectors if there's only one installed.
      • +
      • [PHPBB3-10854] - sql server drop default constraint when dropping column
      • +
      • [PHPBB3-10865] - Updated and Added to docs/INSTALL.html
      • +
      • [PHPBB3-10873] - Change language entry for deleted PMs
      • +
      • [PHPBB3-10981] - Upgrade Goutte and use Composer for Installation
      • +
      • [PHPBB3-11131] - Phrasing & semantics of Board settings
      • +
      • [PHPBB3-11162] - Get rid of $db->sql_return_on_error(true) trickery when splitting/merging topics
      • +
      • [PHPBB3-11192] - Add Tebibyte to get_formatted_filesize()
      • +
      • [PHPBB3-11202] - Add response status checks to functional tests
      • +
      • [PHPBB3-11220] - Improve tooltip explaining the [list=] - BBcode
      • +
      • [PHPBB3-11238] - Specify goutte version
      • +
      • [PHPBB3-11285] - Use more granularity in dependency checks in compress test
      • +
      • [PHPBB3-11293] - Prefer mysqli over mysql due to php 5.5 alpha 2 deprecating mysql
      • +
      • [PHPBB3-11294] - Update extension list in running tests doc
      • +
      • [PHPBB3-11368] - Latest pm reports row count
      • +
      • [PHPBB3-11583] - InnoDB supports FULLTEXT index since MySQL 5.6.4.
      • +
      +

      Sub-task

      +
        +
      • [PHPBB3-10974] - Move tests/mock_user.php to tests/mock/user.php
      • +
      • [PHPBB3-11009] - Backport phing build.xml from develop to develop-olympus so it uses composer.
      • +
      • [PHPBB3-11540] - Add unit tests for (phpbb_)is_absolute()
      • +
      • [PHPBB3-11541] - Add unit tests for style_select() in functions.php
      • +
      • [PHPBB3-11542] - Add unit tests for language_select() in functions.php
      • +
      • [PHPBB3-11543] - Add unit tests for obtain online functions in functions.php
      • +
      +

      Task

      +
        +
      • [PHPBB3-10877] - Have bamboo generate and publish a phpBB package for every build.
      • +
      • [PHPBB3-11045] - Add unit tests for the compress class
      • +
      • [PHPBB3-11059] - Fix README logo
      • +
      • [PHPBB3-11060] - Fix travis.yml pyrus config
      • +
      • [PHPBB3-11240] - Turn on PHPUnit's verbose mode on Travis
      • +
      • [PHPBB3-11324] - Add PHP 5.5 environment on Travis-CI
      • +
      • [PHPBB3-11337] - Run functional tests on Travis CI
      • +
      • [PHPBB3-11513] - Install PHPUnit via Composer's require-dev to simplify test running (no need for pear)
      • +
      • [PHPBB3-11526] - Increase composer minimum-stability from beta to stable
      • +
      • [PHPBB3-11527] - Upgrade composer.phar to 1.0.0-alpha7
      • +
      • [PHPBB3-11529] - Rename RUNNING_TESTS file to .md file to render it on GitHub
      • +
      • [PHPBB3-11576] - Make phpBB Test Suite MySQL behave at least as strict as phpBB MySQL driver
      • +
      • [PHPBB3-11671] - Add phing/phing to composer.json
      • +
      + +

      1.ii. Changes since 3.0.10

      Bug

        @@ -210,7 +358,7 @@
      • [PHPBB3-10909] - Update Travis Test Configuration: Travis no longer supports PHP 5.3.2
      -

      1.ii. Changes since 3.0.9

      +

      1.iii. Changes since 3.0.9

      Bug

        @@ -346,7 +494,7 @@
      • [PHPBB3-10480] - Automate changelog building
      -

      1.iii. Changes since 3.0.8

      +

      1.iv. Changes since 3.0.8

      Bug

      @@ -714,7 +862,7 @@ -

      1.iv. Changes since 3.0.7-PL1

      +

      1.v. Changes since 3.0.7-PL1

      Security

        @@ -1172,13 +1320,13 @@
      -

      1.iv. Changes since 3.0.7

      +

      1.vi. Changes since 3.0.7

      • [Sec] Do not expose forum content of forums with ACL entries but no actual permission in ATOM Feeds. (Bug #58595)
      -

      1.vi. Changes since 3.0.6

      +

      1.vii. Changes since 3.0.6

      • [Fix] Allow ban reason and length to be selected and copied in ACP and subsilver2 MCP. (Bug #51095)
      • @@ -1282,7 +1430,7 @@
      -

      1.vii. Changes since 3.0.5

      +

      1.viii. Changes since 3.0.5

      • [Fix] Allow whitespaces in avatar gallery names. (Bug #44955)
      • @@ -1504,7 +1652,7 @@
      • [Feature] Send anonymous statistical information to phpBB on installation and update (optional).
      -

      1.viii. Changes since 3.0.4

      +

      1.ix. Changes since 3.0.4

      • [Fix] Delete user entry from ban list table upon user deletion (Bug #40015 - Patch by TerraFrost)
      • @@ -1593,7 +1741,7 @@
      • [Sec] Only use forum id supplied for posting if global announcement detected. (Reported by nickvergessen)
      -

      1.ix. Changes since 3.0.3

      +

      1.x. Changes since 3.0.3

      • [Fix] Allow mixed-case template directories to be inherited (Bug #36725)
      • @@ -1625,7 +1773,7 @@
      • [Sec] Ask for forum password if post within passworded forum quoted in private message. (Reported by nickvergessen)
      -

      1.x. Changes since 3.0.2

      +

      1.xi. Changes since 3.0.2

      • [Fix] Correctly set topic starter if first post in topic removed (Bug #30575 - Patch by blueray2048)
      • @@ -1724,7 +1872,7 @@
      • [Sec Precaution] Stricter validation of the HTTP_HOST header (Thanks to Techie-Micheal et al for pointing out possible issues in derived code)
      -

      1.xi. Changes since 3.0.1

      +

      1.xii. Changes since 3.0.1

      • [Fix] Ability to set permissions on non-mysql dbms (Bug #24955)
      • @@ -1772,7 +1920,7 @@
      • [Sec] Only allow urls gone through redirect() being used within login_box(). (thanks nookieman)
      -

      1.xii Changes since 3.0.0

      +

      1.xiii Changes since 3.0.0

      • [Change] Validate birthdays (Bug #15004)
      • @@ -1843,7 +1991,7 @@
      • [Fix] Find and display colliding usernames correctly when converting from one database to another (Bug #23925)
      -

      1.xiii. Changes since 3.0.RC8

      +

      1.xiv. Changes since 3.0.RC8

      • [Fix] Cleaned usernames contain only single spaces, so "a_name" and "a__name" are treated as the same name (Bug #15634)
      • @@ -1852,7 +2000,7 @@
      • [Fix] Call garbage_collection() within database updater to correctly close connections (affects Oracle for example)
      -

      1.xiv. Changes since 3.0.RC7

      +

      1.xv. Changes since 3.0.RC7

      • [Fix] Fixed MSSQL related bug in the update system
      • @@ -1887,7 +2035,7 @@
      • [Fix] No duplication of active topics (Bug #15474)
      -

      1.xv. Changes since 3.0.RC6

      +

      1.xvi. Changes since 3.0.RC6

      • [Fix] Submitting language changes using acp_language (Bug #14736)
      • @@ -1897,7 +2045,7 @@
      • [Fix] Able to request new password (Bug #14743)
      -

      1.xvi. Changes since 3.0.RC5

      +

      1.xvii. Changes since 3.0.RC5

      • [Feature] Removing constant PHPBB_EMBEDDED in favor of using an exit_handler(); the constant was meant to achive this more or less.
      • @@ -1960,7 +2108,7 @@
      • [Sec] New password hashing mechanism for storing passwords (#i42)
      -

      1.xvii. Changes since 3.0.RC4

      +

      1.xviii. Changes since 3.0.RC4

      • [Fix] MySQL, PostgreSQL and SQLite related database fixes (Bug #13862)
      • @@ -2011,7 +2159,7 @@
      • [Fix] odbc_autocommit causing existing result sets to be dropped (Bug #14182)
      -

      1.xviii. Changes since 3.0.RC3

      +

      1.xix. Changes since 3.0.RC3

      • [Fix] Fixing some subsilver2 and prosilver style issues
      • @@ -2120,7 +2268,7 @@
      -

      1.xviv. Changes since 3.0.RC2

      +

      1.xx. Changes since 3.0.RC2

      • [Fix] Re-allow searching within the memberlist
      • @@ -2166,7 +2314,7 @@
      -

      1.xx. Changes since 3.0.RC1

      +

      1.xxi. Changes since 3.0.RC1

      • [Fix] (X)HTML issues within the templates (Bug #11255, #11255)
      • @@ -2301,7 +2449,7 @@
        -

        This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.

        +

        This application is opensource software released under the GNU General Public License v2. 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/FAQ.html b/phpBB/docs/FAQ.html index ebc5d06189..a76b6be72a 100644 --- a/phpBB/docs/FAQ.html +++ b/phpBB/docs/FAQ.html @@ -82,7 +82,7 @@

        There are people, companies (unrelated to your hosting provider), etc. that will install your forum, either for free or for a payment. We do not recommend you make use of these offers. Unless the service is provided by your hosting company you will have to divulge passwords and other sensitive details. If you did not know how to use an ATM would you give a passer-by your bank card and PIN and ask them to show you what to do? No, probably not! The same applies to your hosting account details!

        -

        We think a better solution is for you to carefully read the enclosed documentation, read through our knowledge base at www.phpbb.com and if necessary ask for help on any thing you get stuck on. However, the decision is yours but please note we may not offer support if we believe you have had the board installed by a third party. In such cases you should direct your questions to that company or person/s.

        +

        We think a better solution is for you to carefully read the enclosed documentation, read through our knowledge base at www.phpbb.com and if necessary ask for help on any thing you get stuck on. However, the decision is yours but please note we may not offer support if we believe you have had the board installed by a third party. In such cases you should direct your questions to that company or person/s.

      @@ -143,7 +143,7 @@ I want to sue you because i think you host an illegal board!
      -

      This error will occur if phpBB cannot send mail. phpBB can send email two ways; using the PHP mail() function or directly via SMTP. Some hosting providers limit the mail() function to prevent its use in spamming, others may rename it or limit its functionality. If the mail() function got renamed, you are able to enter the correct name within the administration control panel. In either case you may need to make use of SMTP. This requires that you have access to such a facility, e.g. your hosting provider may provide one (perhaps requiring specific written authorisation), etc. Please see www.phpbb.com for additional help on this matter.

      +

      This error will occur if phpBB cannot send mail. phpBB can send email two ways; using the PHP mail() function or directly via SMTP. Some hosting providers limit the mail() function to prevent its use in spamming, others may rename it or limit its functionality. If the mail() function got renamed, you are able to enter the correct name within the administration control panel. In either case you may need to make use of SMTP. This requires that you have access to such a facility, e.g. your hosting provider may provide one (perhaps requiring specific written authorisation), etc. Please see www.phpbb.com for additional help on this matter.

      If you do require SMTP services please do not ask (on our forums or elsewhere) for someone to provide you with one. Open relays are now things of the past thanks to the unthinking spammers out there. Therefore you are unlikely to find someone willing to offer you (free) services.

      @@ -243,7 +243,7 @@ I want to sue you because i think you host an illegal board!
      -

      Please read the paragraph about permissions in our extensive online documentation.

      +

      Please read the paragraph about permissions in our extensive online documentation.

      @@ -299,11 +299,11 @@ I want to sue you because i think you host an illegal board!
      -

      Please read our extensive user documentation first, it may just explain what you want to know.

      +

      Please read our extensive user documentation first, it may just explain what you want to know.

      Feel free to search our community forum for the information you require. PLEASE DO NOT post your question without having first used search, chances are someone has already asked and answered your question. You can find our board here:

      -

      www.phpbb.com

      +

      www.phpbb.com

      @@ -321,7 +321,7 @@ I want to sue you because i think you host an illegal board!
      -

      This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.

      +

      This application is opensource software released under the GNU General Public License v2. 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/INSTALL.html b/phpBB/docs/INSTALL.html index 58aeb904c7..937568cf10 100644 --- a/phpBB/docs/INSTALL.html +++ b/phpBB/docs/INSTALL.html @@ -39,7 +39,7 @@

      This document will walk you through the basics on installing, updating and converting the forum software.

      -

      A basic overview of running phpBB3 can be found in the accompanying README file. Please ensure you read that document in addition to this! For more detailed information on using, installing, updating and converting phpBB3 you should read the documentation available online.

      +

      A basic overview of running phpBB3 can be found in the accompanying README file. Please ensure you read that document in addition to this! For more detailed information on using, installing, updating and converting phpBB3 you should read the documentation available online.

      Install

      @@ -220,7 +220,7 @@

      Administrator details

      -

      Now you have to create your administration user. This user will have full administration access and he/she will be the first user on your forum. All fields on this page are required. You can also set the default language of your forum on this page. In a vanilla phpBB3 installation, we only include British English. You can download further languages from www.phpbb.com, and add them before installing or later.

      +

      Now you have to create your administration user. This user will have full administration access and he/she will be the first user on your forum. All fields on this page are required. You can also set the default language of your forum on this page. In a vanilla phpBB3 installation, we only include British English. You can download further languages from www.phpbb.com, and add them before installing or later.

      Configuration file

      @@ -299,7 +299,7 @@

      To perform the update, either follow the instructions from the Administration Control Panel->System Tab - this should point out that you are running an outdated version and will guide you through the update - or follow the instructions listed below.

        -
      • Go to the downloads page and download the latest update package listed there, matching your current version.
      • +
      • Go to the downloads page and download the latest update package listed there, matching your current version.
      • Upload the uncompressed archive contents to your phpBB installation - only the install folder is required. Upload the whole install folder, retaining the file structure.
      • After the install folder is present, phpBB3 will go offline automatically.
      • Point your browser to the install directory, for example http://www.example.com/phpBB3/install/
      • @@ -346,7 +346,7 @@

        As with install, the conversion is automated. Your previous 2.0.x database tables will not be changed and the original 2.0.x files will remain unaltered. The conversion is actually only filling your phpBB3 database tables and copying additional data over to your phpBB3 installation. This has the benefit that if something goes wrong, you are able to either re-run the conversion or continue a conversion, while your old board is still accessible. We really recommend that you disable your old installation while converting, else you may have inconsistent data after the conversion.

        -

        Please note that this conversion process may take quite some time and depending on your hosting provider this may result in it failing (due to web server resource limits or other timeout issues). If this is the case, you should ask your provider if they are willing to allow the convert script to temporarily exceed their limits (be nice and they will probably be quite helpful). If your host is unwilling to increase the limits to run the convertor, please see this article for performing the conversion on your local machine: Knowledge Base - Offline Conversions

        +

        Please note that this conversion process may take quite some time and depending on your hosting provider this may result in it failing (due to web server resource limits or other timeout issues). If this is the case, you should ask your provider if they are willing to allow the convert script to temporarily exceed their limits (be nice and they will probably be quite helpful). If your host is unwilling to increase the limits to run the convertor, please see this article for performing the conversion on your local machine: Knowledge Base - Offline Conversions

        Once completed, your board should be immediately available. If you encountered errors, you should report the problems to our bug tracker or seek help via our forums (see README for details).

        @@ -430,7 +430,7 @@
        -

        Like any online site that allows user input, your board could be subject to unwanted posts; often referred to as forum spam. The vast majority of these attacks will be from automated computer programs known as spambots. The attacks, generally, are not personal as the spammers are just trying to find accessible targets. phpBB has a number of anti-spam measures built in, including a range of CAPTCHAs. However, administrators are strongly urged to read and follow the advice for Preventing Spam in phpBB as soon as possible after completing the installation of your board.

        +

        Like any online site that allows user input, your board could be subject to unwanted posts; often referred to as forum spam. The vast majority of these attacks will be from automated computer programs known as spambots. The attacks, generally, are not personal as the spammers are just trying to find accessible targets. phpBB has a number of anti-spam measures built in, including a range of CAPTCHAs. However, administrators are strongly urged to read and follow the advice for Preventing Spam in phpBB as soon as possible after completing the installation of your board.

        @@ -447,7 +447,7 @@
        -

        This application is opensource software released under the GNU General Public License v2. Please see the source code and docs/ directory for more details. This package and its contents are Copyright © phpBB Group, All Rights Reserved.

        +

        This application is opensource software released under the GNU General Public License v2. Please see the source code and docs/ directory for more details. This package and its contents are Copyright © phpBB Group, All Rights Reserved.

        diff --git a/phpBB/docs/README.html b/phpBB/docs/README.html index 164c4a2f55..899ca64fb5 100644 --- a/phpBB/docs/README.html +++ b/phpBB/docs/README.html @@ -34,7 +34,7 @@ -

        Thank you for downloading phpBB3. This README will guide through the basics of installation and operation of phpBB3. Please ensure you read this and the accompanying documentation fully before proceeding with the installation.

        +

        Thank you for downloading phpBB3. This README will guide you through the basics of installation and operation of phpBB3. Please ensure you read this and the accompanying documentation fully before proceeding with the installation.

        Readme

        @@ -61,7 +61,7 @@
  2. Status of this version
  3. -
  4. Reporting Bugs +
  5. Reporting bugs
    1. Security related bugs
    @@ -84,12 +84,11 @@
    - -

    Installation, update and conversion instructions can be found in the INSTALL document contained in this distribution. If you are intending to convert from a previous phpBB 2.0.x or 3.0.x installation we highly recommend you backup any existing data before proceeding!

    +

    Installation, update and conversion instructions can be found in the INSTALL document in this directory. If you are intending on converting from a phpBB 2.0.x or 3.0.x installation we highly recommend that you backup any existing data before proceeding!

    Users of phpBB 3.0 and 3.1 Beta versions cannot directly update.

    -

    Please note that we won't support the following installation types:

    +

    Please note that we don't support the following installation types:

    • Updates from phpBB 3.0 Beta versions to phpBB 3.0 RC1 and higher
    • Updates from phpBB 3.1 Beta versions to phpBB 3.1 RC1 and higher
    • @@ -103,8 +102,8 @@
    • Updates from phpBB 3.0 RC1 and 3.1 RC1 to the latest version
    • Note: if using the Automatic Update Package, updates are supported from phpBB 3.0.2 onward. To update a pre-3.0.2 installation, first update to 3.0.2 and then update to the current version.
    • Conversions from phpBB 2.0.x to the latest version
    • -
    • New installations of phpBB 3.0.x - always only the latest released version
    • -
    • New installations of phpBB 3.1.x - always only the latest released version
    • +
    • New installations of phpBB 3.0.x - only the latest released version
    • +
    • New installations of phpBB 3.1.x - only the latest released version
    @@ -127,21 +126,21 @@

    2.i. Languages (Internationalisation - i18n)

    -

    A number of language packs with included style localisations are available. You can find them listed in the Language Packs pages of our downloads section or from the Language Packs section of the Customisation Database.

    +

    A number of language packs with included style localisations are available. You can find them listed in the Language Packs pages of our downloads section or from the Language Packs section of the Customisation Database.

    -

    For more information about language packs, please see: http://www.phpbb.com/languages/

    +

    For more information about language packs, please see: https://www.phpbb.com/languages/

    -

    This is the official location for all supported language sets. If you download a package from a 3rd party site you do so with the understanding that we cannot offer support. So please, do not ask for help in these cases!

    +

    This is the official location for all supported language sets. If you download a package from a 3rd party site you do so with the understanding that we cannot offer support. Please do not ask for support if you download a language pack from a 3rd party site.

    -

    Installation of these packages is straightforward: simply download the required language pack, uncompress (unzip) it and via FTP transfer the included language and styles folders to the root of your board installation. The language can then be installed via the Administration Control Panel of your board: System tab -> General Tasks -> Language packs. A more detailed description of the process is in the Knowledge Base article, How to Install a Language Pack.

    +

    Installation of these packages is straightforward: simply download the required language pack, uncompress (unzip) it and via FTP transfer the included language and styles folders to the root of your board installation. The language can then be installed via the Administration Control Panel of your board: System tab -> General Tasks -> Language packs. A more detailed description of the process is in the Knowledge Base article, How to Install a Language Pack.

    -

    If your language is not available, please visit our [3.0.x] Translations forum where you will find topics on translations in progress. Should you wish to volunteer to translate a language not currently available or assist in maintaining an existing language pack, you can Apply to become a translator.

    +

    If your language is not available, please visit our [3.0.x] Translations forum where you will find topics on translations in progress. Should you wish to volunteer to translate a language not currently available or assist in maintaining an existing language pack, you can Apply to become a translator.

    2.ii. Styles

    -

    Although the phpBB Group is rather proud of the included styles, we realise that they may not be to everyone's taste. Therefore, phpBB3 allows styles to be switched with relative ease. First, you need to locate and download a style you like. You can find them listed in the Styles section of our Customisation Database.

    +

    Although the phpBB Group is rather proud of the included styles, we realise that they may not be to everyone's taste. Therefore, phpBB3 allows styles to be switched with relative ease. First, you need to locate and download a style you like. You can find them listed in the Styles section of our Customisation Database.

    -

    For more information about styles, please see: http://www.phpbb.com/styles/

    +

    For more information about styles, please see: https://www.phpbb.com/styles/

    Please note that 3rd party styles downloaded for versions of phpBB2 will not work in phpBB3. It is also important to ensure that the style is updated to match the current version of the phpBB software you are using.

    @@ -151,9 +150,9 @@

    2.iii. Modifications

    -

    Although not officially supported by the phpBB Group, phpBB has a thriving modification scene. These third party modifications to the standard phpBB software, known as MODs, extend its capabilities still further. You can browse through many of the MODs in the Modifications section of our Customisation Database.

    +

    Although not officially supported by the phpBB Group, phpBB has a thriving modification scene. These third party modifications to the standard phpBB software, known as MODs, extend its capabilities still further. You can browse through many of the MODs in the Modifications section of our Customisation Database.

    -

    For more information about MODs, please see: http://www.phpbb.com/mods/

    +

    For more information about MODs, please see: https://www.phpbb.com/mods/

    Please remember that any bugs or other issues that occur after you have added any modification should NOT be reported to the bug tracker (see below). First remove the MOD and see if the problem is resolved. Any support for a MOD should only be sought in the "Discussion/Support" forum for that MOD.

    @@ -175,35 +174,35 @@
    -

    phpBB3 can seem a little daunting to new users in places, particularly with regard the permission system. The first thing you should do is check the FAQ which covers a few basic getting started questions. If you need additional help there are several places you should look.

    +

    phpBB3 can sometimes seem a little daunting to new users, particularly with regards to the permission system. The first thing you should do is check the FAQ, which covers a few basic getting started questions. If you need additional help there are several places you can find it.

    3.i. phpBB3 Documentation

    -

    A comprehensive documentation is now available online and can be accessed from the following location:

    +

    Comprehensive documentation is now available on the phpBB website:

    -

    http://www.phpbb.com/support/documentation/3.0/

    +

    https://www.phpbb.com/support/documentation/3.0/

    -

    This covers everything from installation through setting permissions and managing users.

    +

    This covers everything from installation to setting permissions and managing users.

    3.ii. Knowledge Base

    The Knowledge Base consists of a number of detailed articles on some common issues phpBB users may encounter while using the product. The Knowledge Base can be found at:

    -

    http://www.phpbb.com/kb/

    +

    https://www.phpbb.com/kb/

    3.iii. Community Forums

    The phpBB Group maintains a thriving community where a number of people have generously decided to donate their time to help support users. This site can be found at:

    -

    http://www.phpbb.com/community/

    +

    https://www.phpbb.com/community/

    -

    If you do seek help via our forums please be sure to do a Search before posting. This may well save both you and us time and allow the developer, moderator and support groups to spend more time responding to people with unknown issues and problems. Please also remember that phpBB is an entirely volunteer effort, no one receives any compensation for the time they give, this includes moderators as well as developers. So please be respectful and mindful when awaiting responses.

    +

    If you do seek help via our forums please be sure to do a search before posting; if someone has experienced the issue before, then you may find that your question has already been answered. Please remember that phpBB is entirely staffed by volunteers, no one receives any compensation for the time they give, including moderators as well as developers; please be respectful and mindful when awaiting responses and receiving support.

    3.iv Internet Relay Chat

    Another place you may find help is our IRC channel. This operates on the Freenode IRC network, irc.freenode.net and the channel is #phpbb and can be accessed by any decent IRC client such as mIRC, XChat, etc. Again, please do not abuse this service and be respectful of other users.

    -

    There are other IRC channels available, please see http://www.phpbb.com/support/irc/ for the complete list.

    +

    There are other IRC channels available, please see https://www.phpbb.com/support/irc/ for the complete list.

    @@ -268,7 +267,7 @@

    The relevant database type/version is listed within the administration control panel.

    -

    Please also be as detailed as you can in your report, if possible list the steps required to duplicate the problem. If you have a patch that fixes the issue, please attach it to the ticket or submit a pull request on GitHub.

    +

    Please be as detailed as you can in your report, and if possible, list the steps required to duplicate the problem. If you have a patch that fixes the issue, please attach it to the ticket or submit a pull request to our repository on GitHub.

    If you create a patch, it is very much appreciated (but not required) if you follow the phpBB coding guidelines. Please note that the coding guidelines are somewhat different between different versions of phpBB. For phpBB 3.1.x the coding guidelines may be found here: http://area51.phpbb.com/docs/31x/coding-guidelines.html

    @@ -278,7 +277,7 @@

    If you find a potential security related vulnerability in phpBB please DO NOT post it to the bug tracker, public forums, etc.! Doing so may allow unscrupulous users to take advantage of it before we have time to put a fix in place. All security related bugs should be sent to our security tracker:

    -

    http://www.phpbb.com/security/

    +

    https://www.phpbb.com/security/

    @@ -299,8 +298,8 @@

    This list is not complete but does represent those bugs which may affect users on a wider scale. Other bugs listed in the tracker have typically been shown to be limited to certain setups or methods of installation, updating and/or conversions.

      -
    • Conversions may fail to complete on large boards under some hosts
    • -
    • Updates may fail to complete on large update sets under some hosts
    • +
    • Conversions may fail to complete on large boards under some hosts.
    • +
    • Updates may fail to complete on large update sets under some hosts.
    • Smilies placed directly after bbcode tags will not get parsed. Smilies always need to be separated by spaces.
    @@ -322,7 +321,7 @@

    phpBB 3.1.x takes advantage of new features added in PHP 5.3. We recommend that you upgrade to the latest stable release of PHP5 to run phpBB. The minimum version required is PHP 5.3.3.

    -

    Please remember that running any application on a developmental version of PHP can lead to strange/unexpected results which may appear to be bugs in the application (which may not be true). Therefore we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a developmental version of PHP please check any bugs you find on a system running a stable release before submitting.

    +

    Please remember that running any application on a development (unstable, e.g. a beta release) version of PHP can lead to strange/unexpected results which may appear to be bugs in the application. Therefore, we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a development version of PHP please check any bugs you find on a system running a stable release before submitting.

    This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 8.x, Oracle 8, SQLite 2 and Firebird. Versions of PHP used range from 5.3.x to 5.4.x without problem.

    @@ -346,7 +345,7 @@
    -

    This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright © phpBB Group, All Rights Reserved.

    +

    This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright © phpBB Group, All Rights Reserved.

    diff --git a/phpBB/docs/auth_api.html b/phpBB/docs/auth_api.html index 249ceebfbc..f45ea5e5c8 100644 --- a/phpBB/docs/auth_api.html +++ b/phpBB/docs/auth_api.html @@ -268,7 +268,7 @@ $auth_admin = new auth_admin();
    -

    This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.

    +

    This application is opensource software released under the GNU General Public License v2. 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/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index e73c563d5b..7c588a4905 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -1315,7 +1315,7 @@ parent = prosilver <!-- INCLUDEPHP somefile.php --> -

    it will be included and executed inline.

    A note, it is very much encouraged that template designers do not include PHP. The ability to include raw PHP was introduced primarily to allow end users to include banner code, etc. without modifying multiple files (as with 2.0.x). It was not intended for general use ... hence www.phpbb.com will not make available template sets which include PHP. And by default templates will have PHP disabled (the admin will need to specifically activate PHP for a template).

    +

    it will be included and executed inline.

    A note, it is very much encouraged that template designers do not include PHP. The ability to include raw PHP was introduced primarily to allow end users to include banner code, etc. without modifying multiple files (as with 2.0.x). It was not intended for general use ... hence www.phpbb.com will not make available template sets which include PHP. And by default templates will have PHP disabled (the admin will need to specifically activate PHP for a template).

    Conditionals/Control structures

    The most significant addition to 3.x are conditions or control structures, "if something then do this else do that". The system deployed is very similar to Smarty. This may confuse some people at first but it offers great potential and great flexibility with a little imagination. In their most simple form these constructs take the form:

    @@ -2499,7 +2499,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
    -

    This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.

    +

    This application is opensource software released under the GNU General Public License v2. 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 6dd84bfc23..3f209b8a34 100644 --- a/phpBB/docs/hook_system.html +++ b/phpBB/docs/hook_system.html @@ -861,7 +861,7 @@ function phpbb_hook_register(&$hook)
    -

    This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.

    +

    This application is opensource software released under the GNU General Public License v2. 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/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index d1b98d6cbc..620ec25761 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -15,6 +15,7 @@ source source_phpbb_{SPHINX_ID}_main p.forum_id, \ p.topic_id, \ p.poster_id, \ + p.post_visibility, \ CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, \ p.post_time, \ p.post_subject, \ @@ -32,6 +33,7 @@ source source_phpbb_{SPHINX_ID}_main sql_attr_uint = forum_id sql_attr_uint = topic_id sql_attr_uint = poster_id + sql_attr_uint = post_visibility sql_attr_bool = topic_first_post sql_attr_bool = deleted sql_attr_timestamp = post_time @@ -48,6 +50,7 @@ source source_phpbb_{SPHINX_ID}_delta : source_phpbb_{SPHINX_ID}_main p.forum_id, \ p.topic_id, \ p.poster_id, \ + p.post_visibility, \ CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, \ p.post_time, \ p.post_subject, \ diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index e537d7a8b9..9c430b5a0b 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -112,8 +112,8 @@ class acp_bbcodes { $template->assign_block_vars('token', array( 'TOKEN' => '{' . $token . '}', - 'EXPLAIN' => $token_explain) - ); + 'EXPLAIN' => ($token === 'LOCAL_URL') ? sprintf($token_explain, generate_board_url() . '/') : $token_explain, + )); } return; @@ -347,6 +347,9 @@ class acp_bbcodes 'LOCAL_URL' => array( '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')" ), + 'RELATIVE_URL' => array( + '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')" + ), 'EMAIL' => array( '!(' . get_preg_expression('email') . ')!ie' => "\$this->bbcode_specialchars('$1')" ), @@ -373,6 +376,7 @@ class acp_bbcodes $sp_tokens = array( 'URL' => '(?i)((?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))(?-i)', 'LOCAL_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)', + 'RELATIVE_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)', 'EMAIL' => '(' . get_preg_expression('email') . ')', 'TEXT' => '(.*?)', 'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)', @@ -429,7 +433,11 @@ class acp_bbcodes $fp_replace = str_replace($token, $replace, $fp_replace); $sp_match = str_replace(preg_quote($token, '!'), $sp_tokens[$token_type], $sp_match); - $sp_replace = str_replace($token, '${' . ($n + 1) . '}', $sp_replace); + + // Prepend the board url to local relative links + $replace_prepend = ($token_type === 'LOCAL_URL') ? generate_board_url() . '/' : ''; + + $sp_replace = str_replace($token, $replace_prepend . '${' . ($n + 1) . '}', $sp_replace); } $fp_match = '!' . $fp_match . '!' . $modifiers; diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 6881e03fdb..12e2a1bf72 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -522,84 +522,54 @@ class acp_board if ($mode == 'auth') { // Retrieve a list of auth plugins and check their config values - $auth_plugins = array(); - - $dp = @opendir($phpbb_root_path . 'includes/auth'); - - if ($dp) - { - while (($file = readdir($dp)) !== false) - { - if (preg_match('#^auth_(.*?)\.' . $phpEx . '$#', $file)) - { - $auth_plugins[] = basename(preg_replace('#^auth_(.*?)\.' . $phpEx . '$#', '\1', $file)); - } - } - closedir($dp); - - sort($auth_plugins); - } + $auth_providers = $phpbb_container->get('auth.provider_collection'); $updated_auth_settings = false; $old_auth_config = array(); - foreach ($auth_plugins as $method) + foreach ($auth_providers as $provider) { - if ($method && file_exists($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx)) + if ($fields = $provider->acp()) { - include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); - - $method = 'acp_' . $method; - if (function_exists($method)) + // Check if we need to create config fields for this plugin and save config when submit was pressed + foreach ($fields as $field) { - if ($fields = $method($this->new_config)) + if (!isset($config[$field])) { - // Check if we need to create config fields for this plugin and save config when submit was pressed - foreach ($fields['config'] as $field) - { - if (!isset($config[$field])) - { - set_config($field, ''); - } - - if (!isset($cfg_array[$field]) || strpos($field, 'legend') !== false) - { - continue; - } - - $old_auth_config[$field] = $this->new_config[$field]; - $config_value = $cfg_array[$field]; - $this->new_config[$field] = $config_value; - - if ($submit) - { - $updated_auth_settings = true; - set_config($field, $config_value); - } - } + set_config($field, ''); + } + + if (!isset($cfg_array[$field]) || strpos($field, 'legend') !== false) + { + continue; + } + + $old_auth_config[$field] = $this->new_config[$field]; + $config_value = $cfg_array[$field]; + $this->new_config[$field] = $config_value; + + if ($submit) + { + $updated_auth_settings = true; + set_config($field, $config_value); } - unset($fields); } } + unset($fields); } if ($submit && (($cfg_array['auth_method'] != $this->new_config['auth_method']) || $updated_auth_settings)) { $method = basename($cfg_array['auth_method']); - if ($method && in_array($method, $auth_plugins)) + if (array_key_exists('auth.provider.' . $method, $auth_providers)) { - include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); - - $method = 'init_' . $method; - if (function_exists($method)) + $provider = $auth_providers['auth.provider.' . $method]; + if ($error = $provider->init()) { - if ($error = $method()) + foreach ($old_auth_config as $config_name => $config_value) { - foreach ($old_auth_config as $config_name => $config_value) - { - set_config($config_name, $config_value); - } - trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING); + set_config($config_name, $config_value); } + trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING); } set_config('auth_method', basename($cfg_array['auth_method'])); } @@ -683,23 +653,15 @@ class acp_board { $template->assign_var('S_AUTH', true); - foreach ($auth_plugins as $method) + foreach ($auth_providers as $provider) { - if ($method && file_exists($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx)) + $auth_tpl = $provider->get_acp_template($this->new_config); + if ($auth_tpl) { - $method = 'acp_' . $method; - if (function_exists($method)) - { - $fields = $method($this->new_config); - - if ($fields['tpl']) - { - $template->assign_block_vars('auth_tpl', array( - 'TPL' => $fields['tpl']) - ); - } - unset($fields); - } + $template->assign_vars($auth_tpl['TEMPLATE_VARS']); + $template->assign_block_vars('auth_tpl', array( + 'TEMPLATE_FILE' => $auth_tpl['TEMPLATE_FILE'], + )); } } } @@ -710,25 +672,19 @@ class acp_board */ function select_auth_method($selected_method, $key = '') { - global $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpEx, $phpbb_container; $auth_plugins = array(); + $auth_providers = $phpbb_container->get('auth.provider_collection'); - $dp = @opendir($phpbb_root_path . 'includes/auth'); - - if (!$dp) + foreach ($auth_providers as $key => $value) { - return ''; - } - - while (($file = readdir($dp)) !== false) - { - if (preg_match('#^auth_(.*?)\.' . $phpEx . '$#', $file)) + if (!($value instanceof phpbb_auth_provider_interface)) { - $auth_plugins[] = preg_replace('#^auth_(.*?)\.' . $phpEx . '$#', '\1', $file); + continue; } + $auth_plugins[] = str_replace('auth.provider.', '', $key); } - closedir($dp); sort($auth_plugins); diff --git a/phpBB/includes/acp/acp_captcha.php b/phpBB/includes/acp/acp_captcha.php index c7c64ae56b..1a083c20ac 100644 --- a/phpBB/includes/acp/acp_captcha.php +++ b/phpBB/includes/acp/acp_captcha.php @@ -124,6 +124,8 @@ class acp_captcha 'CAPTCHA_PREVIEW_TPL' => $demo_captcha->get_demo_template($id), 'S_CAPTCHA_HAS_CONFIG' => $demo_captcha->has_config(), 'CAPTCHA_SELECT' => $captcha_select, + + 'U_ACTION' => $this->u_action, )); } } diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index ebcbd28a87..5d191b3d0f 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -28,10 +28,6 @@ class acp_database global $cache, $db, $user, $auth, $template, $table_prefix; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - if (!class_exists('phpbb_db_tools')) - { - require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); - } $this->db_tools = new phpbb_db_tools($db); $user->add_lang('acp/database'); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 7e8d5d8388..970b033995 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -283,7 +283,7 @@ class acp_forums @set_time_limit(0); - $sql = 'SELECT forum_name, forum_topics_real + $sql = 'SELECT forum_name, (forum_topics_approved + forum_topics_unapproved + forum_topics_softdeleted) AS total_topics FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; $result = $db->sql_query($sql); @@ -295,7 +295,7 @@ class acp_forums trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } - if ($row['forum_topics_real']) + if ($row['total_topics']) { $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id FROM ' . TOPICS_TABLE . ' @@ -314,7 +314,6 @@ class acp_forums $end = $start + $batch_size; // Sync all topics in batch mode... - sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false); sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true); if ($end < $row2['max_topic_id']) @@ -330,15 +329,15 @@ class acp_forums $start += $batch_size; - $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync&start=$start&topics_done=$topics_done&total={$row['forum_topics_real']}"; + $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync&start=$start&topics_done=$topics_done&total={$row['total_topics']}"; meta_refresh(0, $url); $template->assign_vars(array( - 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}", - 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}"), + 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['total_topics']}", + 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['total_topics']}"), 'S_CONTINUE_SYNC' => true, - 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real'])) + 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['total_topics'])) ); return; @@ -352,7 +351,7 @@ class acp_forums 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar', 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), 'S_CONTINUE_SYNC' => true, - 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real'])) + 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['total_topics'])) ); return; @@ -857,8 +856,8 @@ class acp_forums 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '', 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), - 'FORUM_TOPICS' => $row['forum_topics'], - 'FORUM_POSTS' => $row['forum_posts'], + 'FORUM_TOPICS' => $row['forum_topics_approved'], + 'FORUM_POSTS' => $row['forum_posts_approved'], 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false, 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false, @@ -1144,7 +1143,8 @@ class acp_forums return array($user->lang['NO_FORUM_ACTION']); } - $forum_data_sql['forum_posts'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_real'] = $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0; + $forum_data_sql['forum_posts_approved'] = $forum_data_sql['forum_posts_unapproved'] = $forum_data_sql['forum_posts_softdeleted'] = $forum_data_sql['forum_topics_approved'] = $forum_data_sql['forum_topics_unapproved'] = $forum_data_sql['forum_topics_softdeleted'] = 0; + $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0; $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = ''; } else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK) @@ -1264,9 +1264,12 @@ class acp_forums else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST) { // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum) - $forum_data_sql['forum_posts'] = 0; - $forum_data_sql['forum_topics'] = 0; - $forum_data_sql['forum_topics_real'] = 0; + $forum_data_sql['forum_posts_approved'] = 0; + $forum_data_sql['forum_posts_unapproved'] = 0; + $forum_data_sql['forum_posts_softdeleted'] = 0; + $forum_data_sql['forum_topics_approved'] = 0; + $forum_data_sql['forum_topics_unapproved'] = 0; + $forum_data_sql['forum_topics_softdeleted'] = 0; $forum_data_sql['forum_last_post_id'] = 0; $forum_data_sql['forum_last_post_subject'] = ''; $forum_data_sql['forum_last_post_time'] = 0; @@ -1793,7 +1796,7 @@ class acp_forums FROM ' . POSTS_TABLE . ' WHERE forum_id = ' . $forum_id . ' AND post_postcount = 1 - AND post_approved = 1'; + AND post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $post_counts = array(); @@ -1931,7 +1934,7 @@ class acp_forums // Make sure the overall post/topic count is correct... $sql = 'SELECT COUNT(post_id) AS stat FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1'; + WHERE post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1940,7 +1943,7 @@ class acp_forums $sql = 'SELECT COUNT(topic_id) AS stat FROM ' . TOPICS_TABLE . ' - WHERE topic_approved = 1'; + WHERE topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index c79699d465..e6a36c97a8 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -410,7 +410,7 @@ class acp_groups if ($validation_error = validate_data($submit_ary, $validation_checks)) { // Replace "error" string with its real, localised form - $error = array_merge($error, array_map(array(&$user, 'lang'), $validation_error)); + $error = array_merge($error, $validation_error); } if (!sizeof($error)) @@ -507,6 +507,7 @@ class acp_groups if (sizeof($error)) { + $error = array_map(array(&$user, 'lang'), $error); $group_rank = $submit_ary['rank']; $group_desc_data = array( diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index c44bc1b8a6..eecd8c72dc 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -63,9 +63,7 @@ class acp_main if ($action === 'admlogout') { $user->unset_admin(); - $redirect_url = append_sid("{$phpbb_root_path}index.$phpEx"); - meta_refresh(3, $redirect_url); - trigger_error($user->lang['ADM_LOGGED_OUT'] . '

    ' . sprintf($user->lang['RETURN_INDEX'], '', '')); + redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } if (!confirm_box(true)) @@ -144,14 +142,14 @@ class acp_main $sql = 'SELECT COUNT(post_id) AS stat FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1'; + WHERE post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); set_config('num_posts', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); $sql = 'SELECT COUNT(topic_id) AS stat FROM ' . TOPICS_TABLE . ' - WHERE topic_approved = 1'; + WHERE topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); set_config('num_topics', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); @@ -232,7 +230,7 @@ class acp_main $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id FROM ' . POSTS_TABLE . ' WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' - AND post_postcount = 1 AND post_approved = 1 + AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . ' GROUP BY poster_id'; $result = $db->sql_query($sql); @@ -430,7 +428,7 @@ class acp_main { $template->assign_vars(array( 'S_PHP_VERSION_OLD' => true, - 'L_PHP_VERSION_OLD' => sprintf($user->lang['PHP_VERSION_OLD'], '', ''), + 'L_PHP_VERSION_OLD' => sprintf($user->lang['PHP_VERSION_OLD'], '', ''), )); } diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index ab416fb406..a1e681b29c 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -575,13 +575,20 @@ class acp_modules // format. phpbb_acp_info_acp_foo needs to be turned into // acp_foo_info and the respective file has to be included // manually because it does not support auto loading - if (!class_exists($info_class)) + $old_info_class_file = str_replace("phpbb_{$module_class}_info_", '', $cur_module); + $old_info_class = $old_info_class_file . '_info'; + + if (class_exists($old_info_class)) { - $info_class_file = str_replace("phpbb_{$module_class}_info_", '', $cur_module); - $info_class = $info_class_file . '_info'; - if (!class_exists($info_class) && file_exists($directory . $info_class_file . '.' . $phpEx)) + $info_class = $old_info_class; + } + else if (!class_exists($info_class)) + { + $info_class = $old_info_class; + // need to check class exists again because previous checks triggered autoloading + if (!class_exists($info_class) && file_exists($directory . $old_info_class_file . '.' . $phpEx)) { - include($directory . $info_class_file . '.' . $phpEx); + include($directory . $old_info_class_file . '.' . $phpEx); } } diff --git a/phpBB/includes/acp/acp_permission_roles.php b/phpBB/includes/acp/acp_permission_roles.php index 004187af84..e830479389 100644 --- a/phpBB/includes/acp/acp_permission_roles.php +++ b/phpBB/includes/acp/acp_permission_roles.php @@ -21,6 +21,7 @@ if (!defined('IN_PHPBB')) class acp_permission_roles { var $u_action; + protected $auth_admin; function main($id, $mode) { @@ -30,7 +31,7 @@ class acp_permission_roles include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx); include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); - $auth_admin = new auth_admin(); + $this->auth_admin = new auth_admin(); $user->add_lang('acp/permissions'); add_permission_language(); @@ -210,7 +211,7 @@ class acp_permission_roles } // Now add the auth settings - $auth_admin->acl_set_role($role_id, $auth_settings); + $this->auth_admin->acl_set_role($role_id, $auth_settings); $role_name = (!empty($user->lang[$role_name])) ? $user->lang[$role_name] : $role_name; add_log('admin', 'LOG_' . strtoupper($permission_type) . 'ROLE_' . strtoupper($action), $role_name); @@ -343,7 +344,7 @@ class acp_permission_roles // Get users/groups/forums using this preset... if ($action == 'edit') { - $hold_ary = $auth_admin->get_role_mask($role_id); + $hold_ary = $this->auth_admin->get_role_mask($role_id); if (sizeof($hold_ary)) { @@ -354,7 +355,7 @@ class acp_permission_roles 'L_ROLE_ASSIGNED_TO' => sprintf($user->lang['ROLE_ASSIGNED_TO'], $role_name)) ); - $auth_admin->display_role_mask($hold_ary); + $this->auth_admin->display_role_mask($hold_ary); } } @@ -445,8 +446,8 @@ class acp_permission_roles 'S_DISPLAY_ROLE_MASK' => true) ); - $hold_ary = $auth_admin->get_role_mask($display_item); - $auth_admin->display_role_mask($hold_ary); + $hold_ary = $this->auth_admin->get_role_mask($display_item); + $this->auth_admin->display_role_mask($hold_ary); } } @@ -462,7 +463,7 @@ class acp_permission_roles $auth_options = array(0 => $auth_options); // Making use of auth_admin method here (we do not really want to change two similar code fragments) - auth_admin::build_permission_array($auth_options, $content_array, $categories, $key_sort_array); + $this->auth_admin->build_permission_array($auth_options, $content_array, $categories, $key_sort_array); $content_array = $content_array[0]; @@ -500,8 +501,6 @@ class acp_permission_roles { global $db; - $auth_admin = new auth_admin(); - // Get complete auth array $sql = 'SELECT auth_option, auth_option_id FROM ' . ACL_OPTIONS_TABLE . " @@ -529,19 +528,19 @@ class acp_permission_roles $db->sql_freeresult($result); // Get role assignments - $hold_ary = $auth_admin->get_role_mask($role_id); + $hold_ary = $this->auth_admin->get_role_mask($role_id); // Re-assign permissions foreach ($hold_ary as $forum_id => $forum_ary) { if (isset($forum_ary['users'])) { - $auth_admin->acl_set('user', $forum_id, $forum_ary['users'], $auth_settings, 0, false); + $this->auth_admin->acl_set('user', $forum_id, $forum_ary['users'], $auth_settings, 0, false); } if (isset($forum_ary['groups'])) { - $auth_admin->acl_set('group', $forum_id, $forum_ary['groups'], $auth_settings, 0, false); + $this->auth_admin->acl_set('group', $forum_id, $forum_ary['groups'], $auth_settings, 0, false); } } @@ -563,6 +562,6 @@ class acp_permission_roles WHERE role_id = ' . $role_id; $db->sql_query($sql); - $auth_admin->acl_clear_prefetch(); + $this->auth_admin->acl_clear_prefetch(); } } diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 6618e2c3f9..11a2511aee 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -560,7 +560,7 @@ class acp_search return $finder ->extension_suffix('_backend') ->extension_directory('/search') - ->core_path('includes/search/') + ->core_path('phpbb/search/') ->get_classes(); } diff --git a/phpBB/includes/acp/acp_send_statistics.php b/phpBB/includes/acp/acp_send_statistics.php index 4421fbef18..39140b8da4 100644 --- a/phpBB/includes/acp/acp_send_statistics.php +++ b/phpBB/includes/acp/acp_send_statistics.php @@ -28,7 +28,7 @@ class acp_send_statistics include($phpbb_root_path . 'includes/questionnaire/questionnaire.' . $phpEx); - $collect_url = "http://www.phpbb.com/stats/receive_stats.php"; + $collect_url = "https://www.phpbb.com/stats/receive_stats.php"; $this->tpl_name = 'acp_send_statistics'; $this->page_title = 'ACP_SEND_STATISTICS'; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index c8542ddbe7..cbfd578d87 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -624,29 +624,31 @@ class acp_users $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array(); $forum_id_ary = array($new_forum_id); - $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts + $sql = 'SELECT topic_id, post_visibility, COUNT(post_id) AS total_posts FROM ' . POSTS_TABLE . " WHERE poster_id = $user_id AND forum_id <> $new_forum_id - GROUP BY topic_id"; + GROUP BY topic_id, post_visibility"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $topic_id_ary[$row['topic_id']] = $row['total_posts']; + $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts']; } $db->sql_freeresult($result); if (sizeof($topic_id_ary)) { - $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment + $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) + if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts_approved'] + && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved'] + && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted']) { $move_topic_ary[] = $row['topic_id']; } @@ -679,7 +681,7 @@ class acp_users 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, - 'topic_approved' => 1, + 'topic_visibility' => ITEM_APPROVED, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, @@ -1036,7 +1038,7 @@ class acp_users $sql = 'SELECT COUNT(post_id) as posts_in_queue FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $user_id . ' - AND post_approved = 0'; + AND post_visibility = ' . ITEM_UNAPPROVED; $result = $db->sql_query($sql); $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue'); $db->sql_freeresult($result); diff --git a/phpBB/includes/auth/auth_apache.php b/phpBB/includes/auth/auth_apache.php deleted file mode 100644 index 10b288aa09..0000000000 --- a/phpBB/includes/auth/auth_apache.php +++ /dev/null @@ -1,247 +0,0 @@ -is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER) || $user->data['username'] !== htmlspecialchars_decode($request->server('PHP_AUTH_USER'))) - { - return $user->lang['APACHE_SETUP_BEFORE_USE']; - } - return false; -} - -/** -* Login function -*/ -function login_apache(&$username, &$password) -{ - global $db, $request; - - // do not allow empty password - if (!$password) - { - return array( - 'status' => LOGIN_ERROR_PASSWORD, - 'error_msg' => 'NO_PASSWORD_SUPPLIED', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - if (!$username) - { - return array( - 'status' => LOGIN_ERROR_USERNAME, - 'error_msg' => 'LOGIN_ERROR_USERNAME', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - if (!$request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) - { - return array( - 'status' => LOGIN_ERROR_EXTERNAL_AUTH, - 'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - $php_auth_user = htmlspecialchars_decode($request->server('PHP_AUTH_USER')); - $php_auth_pw = htmlspecialchars_decode($request->server('PHP_AUTH_PW')); - - if (!empty($php_auth_user) && !empty($php_auth_pw)) - { - if ($php_auth_user !== $username) - { - return array( - 'status' => LOGIN_ERROR_USERNAME, - 'error_msg' => 'LOGIN_ERROR_USERNAME', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type - FROM ' . USERS_TABLE . " - WHERE username = '" . $db->sql_escape($php_auth_user) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - // User inactive... - if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) - { - return array( - 'status' => LOGIN_ERROR_ACTIVE, - 'error_msg' => 'ACTIVE_ERROR', - 'user_row' => $row, - ); - } - - // Successful login... - return array( - 'status' => LOGIN_SUCCESS, - 'error_msg' => false, - 'user_row' => $row, - ); - } - - // this is the user's first login so create an empty profile - return array( - 'status' => LOGIN_SUCCESS_CREATE_PROFILE, - 'error_msg' => false, - 'user_row' => user_row_apache($php_auth_user, $php_auth_pw), - ); - } - - // Not logged into apache - return array( - 'status' => LOGIN_ERROR_EXTERNAL_AUTH, - 'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE', - 'user_row' => array('user_id' => ANONYMOUS), - ); -} - -/** -* Autologin function -* -* @return array containing the user row or empty if no auto login should take place -*/ -function autologin_apache() -{ - global $db, $request; - - if (!$request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) - { - return array(); - } - - $php_auth_user = htmlspecialchars_decode($request->server('PHP_AUTH_USER')); - $php_auth_pw = htmlspecialchars_decode($request->server('PHP_AUTH_PW')); - - if (!empty($php_auth_user) && !empty($php_auth_pw)) - { - set_var($php_auth_user, $php_auth_user, 'string', true); - set_var($php_auth_pw, $php_auth_pw, 'string', true); - - $sql = 'SELECT * - FROM ' . USERS_TABLE . " - WHERE username = '" . $db->sql_escape($php_auth_user) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - return ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) ? array() : $row; - } - - if (!function_exists('user_add')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - - // create the user if he does not exist yet - user_add(user_row_apache($php_auth_user, $php_auth_pw)); - - $sql = 'SELECT * - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($php_auth_user)) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - return $row; - } - } - - return array(); -} - -/** -* This function generates an array which can be passed to the user_add function in order to create a user -*/ -function user_row_apache($username, $password) -{ - global $db, $config, $user; - // first retrieve default group id - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = '" . $db->sql_escape('REGISTERED') . "' - AND group_type = " . GROUP_SPECIAL; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - trigger_error('NO_GROUP'); - } - - // generate user account data - return array( - 'username' => $username, - 'user_password' => phpbb_hash($password), - 'user_email' => '', - 'group_id' => (int) $row['group_id'], - 'user_type' => USER_NORMAL, - 'user_ip' => $user->ip, - 'user_new' => ($config['new_member_post_limit']) ? 1 : 0, - ); -} - -/** -* The session validation function checks whether the user is still logged in -* -* @return boolean true if the given user is authenticated or false if the session should be closed -*/ -function validate_session_apache(&$user) -{ - global $request; - - // Check if PHP_AUTH_USER is set and handle this case - if ($request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) - { - $php_auth_user = $request->server('PHP_AUTH_USER'); - - return ($php_auth_user === $user['username']) ? true : false; - } - - // PHP_AUTH_USER is not set. A valid session is now determined by the user type (anonymous/bot or not) - if ($user['user_type'] == USER_IGNORE) - { - return true; - } - - return false; -} diff --git a/phpBB/includes/auth/auth_db.php b/phpBB/includes/auth/auth_db.php deleted file mode 100644 index ac944532a5..0000000000 --- a/phpBB/includes/auth/auth_db.php +++ /dev/null @@ -1,289 +0,0 @@ - status constant -* 'error_msg' => string -* 'user_row' => array -* ) -*/ -function login_db($username, $password, $ip = '', $browser = '', $forwarded_for = '') -{ - global $db, $config; - global $request; - - // Auth plugins get the password untrimmed. - // For compatibility we trim() here. - $password = trim($password); - - // do not allow empty password - if (!$password) - { - return array( - 'status' => LOGIN_ERROR_PASSWORD, - 'error_msg' => 'NO_PASSWORD_SUPPLIED', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - if (!$username) - { - return array( - 'status' => LOGIN_ERROR_USERNAME, - 'error_msg' => 'LOGIN_ERROR_USERNAME', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - $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($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) - { - if ($config['ip_login_limit_max'] && $attempts >= $config['ip_login_limit_max']) - { - return array( - 'status' => LOGIN_ERROR_ATTEMPTS, - 'error_msg' => 'LOGIN_ERROR_ATTEMPTS', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - return array( - 'status' => LOGIN_ERROR_USERNAME, - 'error_msg' => 'LOGIN_ERROR_USERNAME', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - $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... - if ($show_captcha) - { - // Visual Confirmation handling - if (!class_exists('phpbb_captcha_factory', false)) - { - global $phpbb_root_path, $phpEx; - include ($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx); - } - - $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']); - $captcha->init(CONFIRM_LOGIN); - $vc_response = $captcha->validate($row); - if ($vc_response) - { - return array( - 'status' => LOGIN_ERROR_ATTEMPTS, - 'error_msg' => 'LOGIN_ERROR_ATTEMPTS', - 'user_row' => $row, - ); - } - else - { - $captcha->reset(); - } - - } - - // If the password convert flag is set we need to convert it - if ($row['user_pass_convert']) - { - // enable super globals to get literal value - // this is needed to prevent unicode normalization - $super_globals_disabled = $request->super_globals_disabled(); - if ($super_globals_disabled) - { - $request->enable_super_globals(); - } - - // in phpBB2 passwords were used exactly as they were sent, with addslashes applied - $password_old_format = isset($_REQUEST['password']) ? (string) $_REQUEST['password'] : ''; - $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format; - $password_new_format = $request->variable('password', '', true); - - if ($super_globals_disabled) - { - $request->disable_super_globals(); - } - - if ($password == $password_new_format) - { - if (!function_exists('utf8_to_cp1252')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx); - } - - // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding - // plain md5 support left in for conversions from other systems. - if ((strlen($row['user_password']) == 34 && (phpbb_check_hash(md5($password_old_format), $row['user_password']) || phpbb_check_hash(md5(utf8_to_cp1252($password_old_format)), $row['user_password']))) - || (strlen($row['user_password']) == 32 && (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password']))) - { - $hash = phpbb_hash($password_new_format); - - // Update the password in the users table to the new format and remove user_pass_convert flag - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_password = \'' . $db->sql_escape($hash) . '\', - user_pass_convert = 0 - WHERE user_id = ' . $row['user_id']; - $db->sql_query($sql); - - $row['user_pass_convert'] = 0; - $row['user_password'] = $hash; - } - else - { - // Although we weren't able to convert this password we have to - // increase login attempt count to make sure this cannot be exploited - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_login_attempts = user_login_attempts + 1 - WHERE user_id = ' . (int) $row['user_id'] . ' - AND user_login_attempts < ' . LOGIN_ATTEMPTS_MAX; - $db->sql_query($sql); - - return array( - 'status' => LOGIN_ERROR_PASSWORD_CONVERT, - 'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT', - 'user_row' => $row, - ); - } - } - } - - // Check password ... - if (!$row['user_pass_convert'] && phpbb_check_hash($password, $row['user_password'])) - { - // Check for old password hash... - if (strlen($row['user_password']) == 32) - { - $hash = phpbb_hash($password); - - // Update the password in the users table to the new format - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_password = '" . $db->sql_escape($hash) . "', - user_pass_convert = 0 - WHERE user_id = {$row['user_id']}"; - $db->sql_query($sql); - - $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) - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_login_attempts = 0 - WHERE user_id = ' . $row['user_id']; - $db->sql_query($sql); - } - - // User inactive... - if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) - { - return array( - 'status' => LOGIN_ERROR_ACTIVE, - 'error_msg' => 'ACTIVE_ERROR', - 'user_row' => $row, - ); - } - - // Successful login... set user_login_attempts to zero... - return array( - 'status' => LOGIN_SUCCESS, - 'error_msg' => false, - 'user_row' => $row, - ); - } - - // Password incorrect - increase login attempts - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_login_attempts = user_login_attempts + 1 - WHERE user_id = ' . (int) $row['user_id'] . ' - AND user_login_attempts < ' . LOGIN_ATTEMPTS_MAX; - $db->sql_query($sql); - - // Give status about wrong password... - return array( - 'status' => ($show_captcha) ? LOGIN_ERROR_ATTEMPTS : LOGIN_ERROR_PASSWORD, - 'error_msg' => ($show_captcha) ? 'LOGIN_ERROR_ATTEMPTS' : 'LOGIN_ERROR_PASSWORD', - 'user_row' => $row, - ); -} diff --git a/phpBB/includes/auth/auth_ldap.php b/phpBB/includes/auth/auth_ldap.php deleted file mode 100644 index 98355dd044..0000000000 --- a/phpBB/includes/auth/auth_ldap.php +++ /dev/null @@ -1,350 +0,0 @@ -lang['LDAP_NO_LDAP_EXTENSION']; - } - - $config['ldap_port'] = (int) $config['ldap_port']; - if ($config['ldap_port']) - { - $ldap = @ldap_connect($config['ldap_server'], $config['ldap_port']); - } - else - { - $ldap = @ldap_connect($config['ldap_server']); - } - - if (!$ldap) - { - return $user->lang['LDAP_NO_SERVER_CONNECTION']; - } - - @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); - @ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); - - if ($config['ldap_user'] || $config['ldap_password']) - { - if (!@ldap_bind($ldap, htmlspecialchars_decode($config['ldap_user']), htmlspecialchars_decode($config['ldap_password']))) - { - return $user->lang['LDAP_INCORRECT_USER_PASSWORD']; - } - } - - // ldap_connect only checks whether the specified server is valid, so the connection might still fail - $search = @ldap_search( - $ldap, - htmlspecialchars_decode($config['ldap_base_dn']), - ldap_user_filter($user->data['username']), - (empty($config['ldap_email'])) ? - array(htmlspecialchars_decode($config['ldap_uid'])) : - array(htmlspecialchars_decode($config['ldap_uid']), htmlspecialchars_decode($config['ldap_email'])), - 0, - 1 - ); - - if ($search === false) - { - return $user->lang['LDAP_SEARCH_FAILED']; - } - - $result = @ldap_get_entries($ldap, $search); - - @ldap_close($ldap); - - - if (!is_array($result) || sizeof($result) < 2) - { - return sprintf($user->lang['LDAP_NO_IDENTITY'], $user->data['username']); - } - - if (!empty($config['ldap_email']) && !isset($result[0][htmlspecialchars_decode($config['ldap_email'])])) - { - return $user->lang['LDAP_NO_EMAIL']; - } - - return false; -} - -/** -* Login function -*/ -function login_ldap(&$username, &$password) -{ - global $db, $config, $user; - - // do not allow empty password - if (!$password) - { - return array( - 'status' => LOGIN_ERROR_PASSWORD, - 'error_msg' => 'NO_PASSWORD_SUPPLIED', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - if (!$username) - { - return array( - 'status' => LOGIN_ERROR_USERNAME, - 'error_msg' => 'LOGIN_ERROR_USERNAME', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - if (!@extension_loaded('ldap')) - { - return array( - 'status' => LOGIN_ERROR_EXTERNAL_AUTH, - 'error_msg' => 'LDAP_NO_LDAP_EXTENSION', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - $config['ldap_port'] = (int) $config['ldap_port']; - if ($config['ldap_port']) - { - $ldap = @ldap_connect($config['ldap_server'], $config['ldap_port']); - } - else - { - $ldap = @ldap_connect($config['ldap_server']); - } - - if (!$ldap) - { - return array( - 'status' => LOGIN_ERROR_EXTERNAL_AUTH, - 'error_msg' => 'LDAP_NO_SERVER_CONNECTION', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); - @ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); - - if ($config['ldap_user'] || $config['ldap_password']) - { - if (!@ldap_bind($ldap, htmlspecialchars_decode($config['ldap_user']), htmlspecialchars_decode($config['ldap_password']))) - { - return array( - 'status' => LOGIN_ERROR_EXTERNAL_AUTH, - 'error_msg' => 'LDAP_NO_SERVER_CONNECTION', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - } - - $search = @ldap_search( - $ldap, - htmlspecialchars_decode($config['ldap_base_dn']), - ldap_user_filter($username), - (empty($config['ldap_email'])) ? - array(htmlspecialchars_decode($config['ldap_uid'])) : - array(htmlspecialchars_decode($config['ldap_uid']), htmlspecialchars_decode($config['ldap_email'])), - 0, - 1 - ); - - $ldap_result = @ldap_get_entries($ldap, $search); - - if (is_array($ldap_result) && sizeof($ldap_result) > 1) - { - if (@ldap_bind($ldap, $ldap_result[0]['dn'], htmlspecialchars_decode($password))) - { - @ldap_close($ldap); - - $sql ='SELECT user_id, username, user_password, user_passchg, user_email, user_type - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - unset($ldap_result); - - // User inactive... - if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) - { - return array( - 'status' => LOGIN_ERROR_ACTIVE, - 'error_msg' => 'ACTIVE_ERROR', - 'user_row' => $row, - ); - } - - // Successful login... set user_login_attempts to zero... - return array( - 'status' => LOGIN_SUCCESS, - 'error_msg' => false, - 'user_row' => $row, - ); - } - else - { - // retrieve default group id - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = '" . $db->sql_escape('REGISTERED') . "' - AND group_type = " . GROUP_SPECIAL; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - trigger_error('NO_GROUP'); - } - - // generate user account data - $ldap_user_row = array( - 'username' => $username, - 'user_password' => phpbb_hash($password), - 'user_email' => (!empty($config['ldap_email'])) ? utf8_htmlspecialchars($ldap_result[0][htmlspecialchars_decode($config['ldap_email'])][0]) : '', - 'group_id' => (int) $row['group_id'], - 'user_type' => USER_NORMAL, - 'user_ip' => $user->ip, - 'user_new' => ($config['new_member_post_limit']) ? 1 : 0, - ); - - unset($ldap_result); - - // this is the user's first login so create an empty profile - return array( - 'status' => LOGIN_SUCCESS_CREATE_PROFILE, - 'error_msg' => false, - 'user_row' => $ldap_user_row, - ); - } - } - else - { - unset($ldap_result); - @ldap_close($ldap); - - // Give status about wrong password... - return array( - 'status' => LOGIN_ERROR_PASSWORD, - 'error_msg' => 'LOGIN_ERROR_PASSWORD', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - } - - @ldap_close($ldap); - - return array( - 'status' => LOGIN_ERROR_USERNAME, - 'error_msg' => 'LOGIN_ERROR_USERNAME', - 'user_row' => array('user_id' => ANONYMOUS), - ); -} - -/** -* Generates a filter string for ldap_search to find a user -* -* @param $username string Username identifying the searched user -* -* @return string A filter string for ldap_search -*/ -function ldap_user_filter($username) -{ - global $config; - - $filter = '(' . $config['ldap_uid'] . '=' . ldap_escape(htmlspecialchars_decode($username)) . ')'; - if ($config['ldap_user_filter']) - { - $_filter = ($config['ldap_user_filter'][0] == '(' && substr($config['ldap_user_filter'], -1) == ')') ? $config['ldap_user_filter'] : "({$config['ldap_user_filter']})"; - $filter = "(&{$filter}{$_filter})"; - } - return $filter; -} - -/** -* Escapes an LDAP AttributeValue -*/ -function ldap_escape($string) -{ - return str_replace(array('*', '\\', '(', ')'), array('\\*', '\\\\', '\\(', '\\)'), $string); -} - -/** -* This function is used to output any required fields in the authentication -* admin panel. It also defines any required configuration table fields. -*/ -function acp_ldap(&$new) -{ - global $user; - - $tpl = ' - -
    -

    ' . $user->lang['LDAP_SERVER_EXPLAIN'] . '
    -
    -
    -
    -

    ' . $user->lang['LDAP_PORT_EXPLAIN'] . '
    -
    -
    -
    -

    ' . $user->lang['LDAP_DN_EXPLAIN'] . '
    -
    -
    -
    -

    ' . $user->lang['LDAP_UID_EXPLAIN'] . '
    -
    -
    -
    -

    ' . $user->lang['LDAP_USER_FILTER_EXPLAIN'] . '
    -
    -
    -
    -

    ' . $user->lang['LDAP_EMAIL_EXPLAIN'] . '
    -
    -
    -
    -

    ' . $user->lang['LDAP_USER_EXPLAIN'] . '
    -
    -
    -
    -

    ' . $user->lang['LDAP_PASSWORD_EXPLAIN'] . '
    -
    -
    - '; - - // These are fields required in the config table - return array( - 'tpl' => $tpl, - 'config' => array('ldap_server', 'ldap_port', 'ldap_base_dn', 'ldap_uid', 'ldap_user_filter', 'ldap_email', 'ldap_user', 'ldap_password') - ); -} diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index c198abeb54..fd00728510 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -134,11 +134,11 @@ class bbcode $style_resource_locator = new phpbb_style_resource_locator(); $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider(), $phpbb_root_path); - $template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, new phpbb_template_context(), $phpbb_extension_manager); + $template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager); $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $template); $style->set_style(); $template->set_filenames(array('bbcode.html' => 'bbcode.html')); - $this->template_filename = $style_resource_locator->get_source_file_for_handle('bbcode.html'); + $this->template_filename = $template->get_source_file_for_handle('bbcode.html'); } $bbcode_ids = $rowset = $sql = array(); diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index ec7636f511..6843f25d72 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -110,12 +110,8 @@ class phpbb_captcha_qa */ static public function is_installed() { - global $db, $phpbb_root_path, $phpEx; + global $db; - if (!class_exists('phpbb_db_tools', false)) - { - include("$phpbb_root_path/includes/db/db_tools.$phpEx"); - } $db_tool = new phpbb_db_tools($db); return $db_tool->sql_table_exists(CAPTCHA_QUESTIONS_TABLE); @@ -297,12 +293,8 @@ class phpbb_captcha_qa */ function install() { - global $db, $phpbb_root_path, $phpEx; + global $db; - if (!class_exists('phpbb_db_tools')) - { - include("$phpbb_root_path/includes/db/db_tools.$phpEx"); - } $db_tool = new phpbb_db_tools($db); $tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE, CAPTCHA_QA_CONFIRM_TABLE); diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 8c27d3fd0c..c1f4c6ac0e 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -87,6 +87,10 @@ define('ITEM_UNLOCKED', 0); define('ITEM_LOCKED', 1); define('ITEM_MOVED', 2); +define('ITEM_UNAPPROVED', 0); // => has not yet been approved +define('ITEM_APPROVED', 1); // => has been approved, and has not been soft deleted +define('ITEM_DELETED', 2); // => has been soft deleted + // Forum Flags define('FORUM_FLAG_LINK_TRACK', 1); define('FORUM_FLAG_PRUNE_POLL', 2); @@ -156,6 +160,7 @@ define('PHYSICAL_LINK', 2); define('CONFIRM_REG', 1); define('CONFIRM_LOGIN', 2); define('CONFIRM_POST', 3); +define('CONFIRM_REPORT', 4); // Categories - Attachments define('ATTACHMENT_CATEGORY_NONE', 0); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b087e1298b..49f2e469bc 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1974,7 +1974,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s */ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false) { - global $db, $tracking_topics, $user, $config, $auth, $request; + global $db, $tracking_topics, $user, $config, $auth, $request, $phpbb_container; // Determine the users last forum mark time if not given. if ($mark_time_forum === false) @@ -1999,7 +1999,7 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti // Handle update of unapproved topics info. // Only update for moderators having m_approve permission for the forum. - $sql_update_unapproved = ($auth->acl_get('m_approve', $forum_id)) ? '': 'AND t.topic_approved = 1'; + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); // Check the forum for any left unread topics. // If there are none, we mark the forum as read. @@ -2019,8 +2019,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti AND tt.user_id = ' . $user->data['user_id'] . ') WHERE t.forum_id = ' . $forum_id . ' AND t.topic_last_post_time > ' . $mark_time_forum . ' - AND t.topic_moved_id = 0 ' . - $sql_update_unapproved . ' + AND t.topic_moved_id = 0 + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . ' AND (tt.topic_id IS NULL OR tt.mark_time < t.topic_last_post_time)'; $result = $db->sql_query_limit($sql, 1); @@ -2044,8 +2044,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' AND t.topic_last_post_time > ' . $mark_time_forum . ' - AND t.topic_moved_id = 0 ' . - $sql_update_unapproved; + AND t.topic_moved_id = 0 + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'); $result = $db->sql_query($sql); $check_forum = $tracking_topics['tf'][$forum_id]; @@ -2345,9 +2345,8 @@ function phpbb_generate_template_pagination($template, $base_url, $block_var_nam $tpl_prefix . 'BASE_URL' => $base_url, 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), $tpl_prefix . 'PER_PAGE' => $per_page, - $tpl_prefix . 'PREVIOUS_PAGE' => $previous_page, - $tpl_prefix . 'PREV_PAGE' => $previous_page, - $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $base_url . $url_delim . $start_name . '=' . ($on_page * $per_page) : '', + 'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => $previous_page, + 'U_' . $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $base_url . $url_delim . $start_name . '=' . ($on_page * $per_page) : '', $tpl_prefix . 'TOTAL_PAGES' => $total_pages, $tpl_prefix . 'CURRENT_PAGE' => $on_page, ); @@ -3302,8 +3301,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa return; } - $redirect = meta_refresh(3, $redirect); - trigger_error($message . '

    ' . sprintf($l_redirect, '', '')); + redirect($redirect); } // Something failed, determine what... diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index ff0e2a1ac1..60c44e90e1 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -82,6 +82,8 @@ function adm_page_header($page_title) 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/", 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/", + 'T_ASSETS_VERSION' => $config['assets_version'], + 'ICON_MOVE_UP' => '' . $user->lang['MOVE_UP'] . '', 'ICON_MOVE_UP_DISABLED' => '' . $user->lang['MOVE_UP'] . '', 'ICON_MOVE_DOWN' => '' . $user->lang['MOVE_DOWN'] . '', diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 72855af5f8..fc29492ac1 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -644,7 +644,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s 'posts' => ($call_delete_posts) ? delete_posts($where_type, $where_ids, false, true, $post_count_sync, false) : 0, ); - $sql = 'SELECT topic_id, forum_id, topic_approved, topic_moved_id + $sql = 'SELECT topic_id, forum_id, topic_visibility, topic_moved_id FROM ' . TOPICS_TABLE . ' WHERE ' . $where_clause; $result = $db->sql_query($sql); @@ -654,7 +654,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s $forum_ids[] = $row['forum_id']; $topic_ids[] = $row['topic_id']; - if ($row['topic_approved'] && !$row['topic_moved_id']) + if ($row['topic_visibility'] == ITEM_APPROVED && !$row['topic_moved_id']) { $approved_topics++; } @@ -775,7 +775,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $approved_posts = 0; $post_ids = $topic_ids = $forum_ids = $post_counts = $remove_topics = array(); - $sql = 'SELECT post_id, poster_id, post_approved, post_postcount, topic_id, forum_id + $sql = 'SELECT post_id, poster_id, post_visibility, post_postcount, topic_id, forum_id FROM ' . POSTS_TABLE . ' WHERE ' . $where_clause; $result = $db->sql_query($sql); @@ -787,12 +787,12 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $topic_ids[] = (int) $row['topic_id']; $forum_ids[] = (int) $row['forum_id']; - if ($row['post_postcount'] && $post_count_sync && $row['post_approved']) + if ($row['post_postcount'] && $post_count_sync && $row['post_visibility'] == ITEM_APPROVED) { $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1; } - if ($row['post_approved']) + if ($row['post_visibility'] == ITEM_APPROVED) { $approved_posts++; } @@ -889,7 +889,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = sync('forum', 'forum_id', $forum_ids, true, true); } - if ($approved_posts) + if ($approved_posts && $post_count_sync) { set_config_count('num_posts', $approved_posts * (-1), true); } @@ -1292,7 +1292,7 @@ function phpbb_unlink($filename, $mode = 'file', $entry_removed = false) * - forum Resync complete forum * - topic Resync topics * - topic_moved Removes topic shadows that would be in the same forum as the topic they link to -* - topic_approved Resyncs the topic_approved flag according to the status of the first post +* - topic_visibility Resyncs the topic_visibility flag according to the status of the first post * - post_reported Resyncs the post_reported flag, relying on actual reports * - topic_reported Resyncs the topic_reported flag, relying on post_reported flags * - post_attachement Same as post_reported, but with attachment flags @@ -1312,7 +1312,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $where_ids = ($where_ids) ? array((int) $where_ids) : array(); } - if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_approved' || $mode == 'topic_reported' || $mode == 'post_reported') + if ($mode == 'forum' || $mode == 'topic' || $mode == 'topic_visibility' || $mode == 'topic_reported' || $mode == 'post_reported') { if (!$where_type) { @@ -1398,43 +1398,55 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_transaction('commit'); break; - case 'topic_approved': + case 'topic_visibility': $db->sql_transaction('begin'); - switch ($db->sql_layer) + + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and p.topic_id = t.topic_id + AND p.post_visibility = " . ITEM_APPROVED; + $result = $db->sql_query($sql); + + $topics_approved = array(); + while ($row = $db->sql_fetchrow($result)) { - case 'mysql4': - case 'mysqli': - $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - SET t.topic_approved = p.post_approved - $where_sql_and t.topic_first_post_id = p.post_id"; - $db->sql_query($sql); - break; + $topics_approved[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - default: - $sql = 'SELECT t.topic_id, p.post_approved - FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - $where_sql_and p.post_id = t.topic_first_post_id - AND p.post_approved <> t.topic_approved"; - $result = $db->sql_query($sql); + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and " . $db->sql_in_set('t.topic_id', $topics_approved, true, true) . ' + AND p.topic_id = t.topic_id + AND p.post_visibility = ' . ITEM_DELETED; + $result = $db->sql_query($sql); - $topic_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_ids[] = $row['topic_id']; - } - $db->sql_freeresult($result); + $topics_softdeleted = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topics_softdeleted[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - if (!sizeof($topic_ids)) - { - return; - } + $topics_softdeleted = array_diff($topics_softdeleted, $topics_approved); + $topics_not_unapproved = array_merge($topics_softdeleted, $topics_approved); + $update_ary = array( + ITEM_UNAPPROVED => (!empty($topics_not_unapproved)) ? $where_sql_and . ' ' . $db->sql_in_set('topic_id', $topics_not_unapproved, true) : '', + ITEM_APPROVED => (!empty($topics_approved)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_approved) : '', + ITEM_DELETED => (!empty($topics_softdeleted)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_softdeleted) : '', + ); + + foreach ($topic_visiblities as $visibility => $sql_where) + { + if ($sql_where) + { $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - topic_approved - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); + SET topic_visibility = ' . $visibility . ' + ' . $sql_where; $db->sql_query($sql); - break; + } } $db->sql_transaction('commit'); @@ -1675,9 +1687,12 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $forum_data[$forum_id] = $row; if ($sync_extra) { - $forum_data[$forum_id]['posts'] = 0; - $forum_data[$forum_id]['topics'] = 0; - $forum_data[$forum_id]['topics_real'] = 0; + $forum_data[$forum_id]['posts_approved'] = 0; + $forum_data[$forum_id]['posts_unapproved'] = 0; + $forum_data[$forum_id]['posts_softdeleted'] = 0; + $forum_data[$forum_id]['topics_approved'] = 0; + $forum_data[$forum_id]['topics_unapproved'] = 0; + $forum_data[$forum_id]['topics_softdeleted'] = 0; } $forum_data[$forum_id]['last_post_id'] = 0; $forum_data[$forum_id]['last_post_subject'] = ''; @@ -1698,20 +1713,27 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // 2: Get topic counts for each forum (optional) if ($sync_extra) { - $sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics + $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS total_topics FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' - GROUP BY forum_id, topic_approved'; + GROUP BY forum_id, topic_visibility'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $forum_id = (int) $row['forum_id']; - $forum_data[$forum_id]['topics_real'] += $row['forum_topics']; - if ($row['topic_approved']) + if ($row['topic_visibility'] == ITEM_APPROVED) { - $forum_data[$forum_id]['topics'] = $row['forum_topics']; + $forum_data[$forum_id]['topics_approved'] = $row['total_topics']; + } + else if ($row['topic_visibility'] == ITEM_UNAPPROVED) + { + $forum_data[$forum_id]['topics_unapproved'] = $row['total_topics']; + } + else if ($row['topic_visibility'] == ITEM_DELETED) + { + $forum_data[$forum_id]['topics_softdeleted'] = $row['total_topics']; } } $db->sql_freeresult($result); @@ -1722,18 +1744,16 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { if (sizeof($forum_ids) == 1) { - $sql = 'SELECT SUM(t.topic_replies + 1) AS forum_posts + $sql = 'SELECT SUM(t.topic_posts_approved) AS forum_posts_approved, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 AND t.topic_status <> ' . ITEM_MOVED; } else { - $sql = 'SELECT t.forum_id, SUM(t.topic_replies + 1) AS forum_posts + $sql = 'SELECT t.forum_id, SUM(t.topic_posts_approved) AS forum_posts_approved, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 AND t.topic_status <> ' . ITEM_MOVED . ' GROUP BY t.forum_id'; } @@ -1744,7 +1764,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, { $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; - $forum_data[$forum_id]['posts'] = (int) $row['forum_posts']; + $forum_data[$forum_id]['posts_approved'] = (int) $row['forum_posts_approved']; + $forum_data[$forum_id]['posts_unapproved'] = (int) $row['forum_posts_unapproved']; + $forum_data[$forum_id]['posts_softdeleted'] = (int) $row['forum_posts_softdeleted']; } $db->sql_freeresult($result); } @@ -1755,14 +1777,14 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT MAX(t.topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1'; + AND t.topic_visibility = ' . ITEM_APPROVED; } else { $sql = 'SELECT t.forum_id, MAX(t.topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_approved = 1 + AND t.topic_visibility = ' . ITEM_APPROVED . ' GROUP BY t.forum_id'; } @@ -1825,7 +1847,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($sync_extra) { - array_push($fieldnames, 'posts', 'topics', 'topics_real'); + array_push($fieldnames, 'posts_approved', 'posts_unapproved', 'posts_softdeleted', 'topics_approved', 'topics_unapproved', 'topics_softdeleted'); } foreach ($forum_data as $forum_id => $row) @@ -1860,11 +1882,11 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, break; case 'topic': - $topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array(); + $topic_data = $post_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array(); $db->sql_transaction('begin'); - $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time + $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time FROM ' . TOPICS_TABLE . " t $where_sql"; $result = $db->sql_query($sql); @@ -1879,8 +1901,10 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $topic_id = (int) $row['topic_id']; $topic_data[$topic_id] = $row; - $topic_data[$topic_id]['replies_real'] = -1; - $topic_data[$topic_id]['replies'] = 0; + $topic_data[$topic_id]['visibility'] = ITEM_UNAPPROVED; + $topic_data[$topic_id]['posts_approved'] = 0; + $topic_data[$topic_id]['posts_unapproved'] = 0; + $topic_data[$topic_id]['posts_softdeleted'] = 0; $topic_data[$topic_id]['first_post_id'] = 0; $topic_data[$topic_id]['last_post_id'] = 0; unset($topic_data[$topic_id]['topic_id']); @@ -1897,11 +1921,11 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $db->sql_freeresult($result); // Use "t" as table alias because of the $where_sql clause - // NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown. - $sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id + // NOTE: 't.post_visibility' in the GROUP BY is causing a major slowdown. + $sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id FROM ' . POSTS_TABLE . " t $where_sql - GROUP BY t.topic_id, t.post_approved"; + GROUP BY t.topic_id, t.post_visibility"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -1922,14 +1946,38 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, // When we'll be done, only topics with no posts will remain unset($delete_topics[$topic_id]); - $topic_data[$topic_id]['replies_real'] += $row['total_posts']; - $topic_data[$topic_id]['first_post_id'] = (!$topic_data[$topic_id]['first_post_id']) ? $row['first_post_id'] : min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']); - - if ($row['post_approved'] || !$topic_data[$topic_id]['last_post_id']) + if ($row['post_visibility'] == ITEM_APPROVED) { - $topic_data[$topic_id]['replies'] = $row['total_posts'] - 1; + $topic_data[$topic_id]['posts_approved'] = $row['total_posts']; + } + else if ($row['post_visibility'] == ITEM_UNAPPROVED) + { + $topic_data[$topic_id]['posts_unapproved'] = $row['total_posts']; + } + else if ($row['post_visibility'] == ITEM_DELETED) + { + $topic_data[$topic_id]['posts_softdeleted'] = $row['total_posts']; + } + + if ($row['post_visibility'] == ITEM_APPROVED) + { + $topic_data[$topic_id]['visibility'] = ITEM_APPROVED; + $topic_data[$topic_id]['first_post_id'] = $row['first_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; } + else if ($topic_data[$topic_id]['visibility'] != ITEM_APPROVED) + { + // If there is no approved post, we take the min/max of the other visibilities + // for the last and first post info, because it is only visible to moderators anyway + $topic_data[$topic_id]['first_post_id'] = (!empty($topic_data[$topic_id]['first_post_id'])) ? min($topic_data[$topic_id]['first_post_id'], $row['first_post_id']) : $row['first_post_id']; + $topic_data[$topic_id]['last_post_id'] = max($topic_data[$topic_id]['last_post_id'], $row['last_post_id']); + + if ($topic_data[$topic_id]['visibility'] == ITEM_UNAPPROVED) + { + // Soft delete status is stronger than unapproved. + $topic_data[$topic_id]['visibility'] = $row['post_visibility']; + } + } } } $db->sql_freeresult($result); @@ -1970,7 +2018,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, unset($delete_topics, $delete_topic_ids); } - $sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour + $sql = 'SELECT p.post_id, p.topic_id, p.post_visibility, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' AND u.user_id = p.poster_id'; @@ -1983,10 +2031,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, if ($row['post_id'] == $topic_data[$topic_id]['first_post_id']) { - if ($topic_data[$topic_id]['topic_approved'] != $row['post_approved']) - { - $approved_unapproved_ids[] = $topic_id; - } $topic_data[$topic_id]['time'] = $row['post_time']; $topic_data[$topic_id]['poster'] = $row['poster_id']; $topic_data[$topic_id]['first_poster_name'] = ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']; @@ -2047,7 +2091,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sync_shadow_topics = array(); if (sizeof($post_ids)) { - $sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour + $sql = 'SELECT p.post_id, p.topic_id, p.post_visibility, p.poster_id, p.post_subject, p.post_username, p.post_time, u.username, u.user_colour FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' AND u.user_id = p.poster_id'; @@ -2114,18 +2158,8 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, unset($sync_shadow_topics, $shadow_topic_data); } - // approved becomes unapproved, and vice-versa - if (sizeof($approved_unapproved_ids)) - { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - topic_approved - WHERE ' . $db->sql_in_set('topic_id', $approved_unapproved_ids); - $db->sql_query($sql); - } - unset($approved_unapproved_ids); - // These are fields that will be synchronised - $fieldnames = array('time', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); + $fieldnames = array('time', 'visibility', 'posts_approved', 'posts_unapproved', 'posts_softdeleted', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); if ($sync_extra) { @@ -2899,7 +2933,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout)) { - @fputs($fsock, "GET $directory/$filename HTTP/1.1\r\n"); + @fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n"); @fputs($fsock, "HOST: $host\r\n"); @fputs($fsock, "Connection: close\r\n\r\n"); diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index e22fa9919a..5c6bd6dd8a 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -20,6 +20,71 @@ if (!defined('IN_PHPBB')) exit; } +/** +* Get DB connection from config.php. +* +* Used to bootstrap the container. +* +* @param string $config_file +* @return phpbb_db_driver +*/ +function phpbb_bootstrap_db_connection($config_file) +{ + require($config_file); + $dbal_driver_class = phpbb_convert_30_dbms_to_31($dbms); + + $db = new $dbal_driver_class(); + $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, defined('PHPBB_DB_NEW_LINK')); + + return $db; +} + +/** +* Get table prefix from config.php. +* +* Used to bootstrap the container. +* +* @param string $config_file +* @return string table prefix +*/ +function phpbb_bootstrap_table_prefix($config_file) +{ + require($config_file); + return $table_prefix; +} + +/** +* Get enabled extensions. +* +* Used to bootstrap the container. +* +* @param string $config_file +* @param string $phpbb_root_path +* @return array enabled extensions +*/ +function phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path) +{ + $db = phpbb_bootstrap_db_connection($config_file); + $table_prefix = phpbb_bootstrap_table_prefix($config_file); + $extension_table = $table_prefix.'ext'; + + $sql = 'SELECT * + FROM ' . $extension_table . ' + WHERE ext_active = 1'; + + $result = $db->sql_query($sql); + $rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + $exts = array(); + foreach ($rows as $row) + { + $exts[$row['ext_name']] = $phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; + } + + return $exts; +} + /** * Create the ContainerBuilder object * @@ -106,16 +171,9 @@ function phpbb_create_update_container($phpbb_root_path, $php_ext, $config_path) * @param string $php_ext PHP Extension * @return ContainerBuilder object (compiled) */ -function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) +function phpbb_create_compiled_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) { - // Create a temporary container for access to the ext.manager service - $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); - $tmp_container->compile(); - - // XXX stop writing to global $cache when - // http://tracker.phpbb.com/browse/PHPBB3-11203 is fixed - $GLOBALS['cache'] = $tmp_container->get('cache'); - $installed_exts = $tmp_container->get('ext.manager')->all_enabled(); + $installed_exts = phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path); // Now pass the enabled extension paths into the ext compiler extension $extensions[] = new phpbb_di_extension_ext($installed_exts); @@ -142,7 +200,7 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb * @param string $php_ext PHP Extension * @return ContainerBuilder object (compiled) */ -function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) +function phpbb_create_dumped_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) { // Check for our cached container; if it exists, use it $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); @@ -152,7 +210,7 @@ function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_ return new phpbb_cache_container(); } - $container = phpbb_create_compiled_container($extensions, $passes, $phpbb_root_path, $php_ext); + $container = phpbb_create_compiled_container($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); // Lastly, we create our cached container class $dumper = new PhpDumper($container); @@ -182,10 +240,10 @@ function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_ * @param string $php_ext PHP Extension * @return ContainerBuilder object (compiled) */ -function phpbb_create_dumped_container_unless_debug(array $extensions, array $passes, $phpbb_root_path, $php_ext) +function phpbb_create_dumped_container_unless_debug($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) { $container_factory = defined('DEBUG') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container'; - return $container_factory($extensions, $passes, $phpbb_root_path, $php_ext); + return $container_factory($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); } /** @@ -199,9 +257,11 @@ function phpbb_create_dumped_container_unless_debug(array $extensions, array $pa */ function phpbb_create_default_container($phpbb_root_path, $php_ext) { + $config_file = $phpbb_root_path . 'config.' . $php_ext; return phpbb_create_dumped_container_unless_debug( + $config_file, array( - new phpbb_di_extension_config($phpbb_root_path . 'config.' . $php_ext), + new phpbb_di_extension_config($config_file), new phpbb_di_extension_core($phpbb_root_path . 'config'), ), array( diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index ac791e0d9b..a34a193f60 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1768,7 +1768,7 @@ function sync_post_count($offset, $limit) $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id FROM ' . POSTS_TABLE . ' WHERE post_postcount = 1 - AND post_approved = 1 + AND post_visibility = ' . ITEM_APPROVED . ' GROUP BY poster_id ORDER BY poster_id'; $result = $db->sql_query_limit($sql, $limit, $offset); @@ -1941,7 +1941,7 @@ function update_dynamic_config() $sql = 'SELECT COUNT(post_id) AS stat FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1'; + WHERE post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1950,7 +1950,7 @@ function update_dynamic_config() $sql = 'SELECT COUNT(topic_id) AS stat FROM ' . TOPICS_TABLE . ' - WHERE topic_approved = 1'; + WHERE topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 9854cd6d70..b1dac64bec 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -22,7 +22,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod { global $db, $auth, $user, $template; global $phpbb_root_path, $phpEx, $config; - global $request, $phpbb_dispatcher; + global $request, $phpbb_dispatcher, $phpbb_container; $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); $parent_id = $visible_forums = 0; @@ -149,6 +149,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_tracking_info = array(); $branch_root_id = $root_data['forum_id']; + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + while ($row = $db->sql_fetchrow($result)) { /** @@ -213,9 +215,11 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark']; } - // Count the difference of real to public topics, so we can display an information to moderators - $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0; - $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics']; + // Lets check whether there are unapproved topics/posts, so we can display an information to moderators + $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0; + $row['forum_id_unapproved_posts'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_posts_unapproved']) ? $forum_id : 0; + $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id); + $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id); // Display active topics from this forum? if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) @@ -278,6 +282,11 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id; } + if (!$forum_rows[$parent_id]['forum_id_unapproved_posts'] && $row['forum_id_unapproved_posts']) + { + $forum_rows[$parent_id]['forum_id_unapproved_posts'] = $forum_id; + } + $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics']; // Do not list redirects in LINK Forums as Posts. @@ -545,6 +554,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'L_MODERATOR_STR' => $l_moderator, 'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_topics&f=' . $row['forum_id_unapproved_topics']) : '', + 'U_UNAPPROVED_POSTS' => ($row['forum_id_unapproved_posts']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_posts&f=' . $row['forum_id_unapproved_posts']) : '', 'U_VIEWFORUM' => $u_viewforum, 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'U_LAST_POST' => $last_post_url, @@ -584,6 +594,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'), + 'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED'), )); if ($return_moderators) @@ -815,7 +826,7 @@ function gen_forum_auth_level($mode, $forum_id, $forum_status) ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'], ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'], ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'], - ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], + ($user->data['is_registered'] && ($auth->acl_gets('f_delete', 'm_delete', $forum_id) || $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], ); if ($config['allow_attachments']) @@ -1005,7 +1016,7 @@ function display_reasons($reason_id = 0) function display_user_activity(&$userdata) { global $auth, $template, $db, $user; - global $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpEx, $phpbb_container; // Do not display user activity for users having more than 5000 posts... if ($userdata['user_posts'] > 5000) @@ -1015,73 +1026,65 @@ function display_user_activity(&$userdata) $forum_ary = array(); - // Do not include those forums the user is not having read access to... - $forum_read_ary = $auth->acl_getf('!f_read'); - - foreach ($forum_read_ary as $forum_id => $not_allowed) + $forum_read_ary = $auth->acl_getf('f_read'); + foreach ($forum_read_ary as $forum_id => $allowed) { - if ($not_allowed['f_read']) + if ($allowed['f_read']) { $forum_ary[] = (int) $forum_id; } } - $forum_ary = array_unique($forum_ary); - $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : ''; + $forum_ary = array_diff($forum_ary, $user->get_passworded_forums()); - $fid_m_approve = $auth->acl_getf('m_approve', true); - $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : ''; - - // Obtain active forum - $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts - FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . " - AND post_postcount = 1 - AND (post_approved = 1 - $sql_m_approve) - $forum_sql - GROUP BY forum_id - ORDER BY num_posts DESC"; - $result = $db->sql_query_limit($sql, 1); - $active_f_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!empty($active_f_row)) + $active_f_row = $active_t_row = array(); + if (!empty($forum_ary)) { - $sql = 'SELECT forum_name - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $active_f_row['forum_id']; - $result = $db->sql_query($sql, 3600); - $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + + // Obtain active forum + $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts + FROM ' . POSTS_TABLE . ' + WHERE poster_id = ' . $userdata['user_id'] . ' + AND post_postcount = 1 + AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' + GROUP BY forum_id + ORDER BY num_posts DESC'; + $result = $db->sql_query_limit($sql, 1); + $active_f_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - } - // Obtain active topic - // We need to exclude passworded forums here so we do not leak the topic title - $forum_ary_topic = array_unique(array_merge($forum_ary, $user->get_passworded_forums())); - $forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : ''; + if (!empty($active_f_row)) + { + $sql = 'SELECT forum_name + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $active_f_row['forum_id']; + $result = $db->sql_query($sql, 3600); + $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); + $db->sql_freeresult($result); + } - $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts - FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . " - AND post_postcount = 1 - AND (post_approved = 1 - $sql_m_approve) - $forum_sql_topic - GROUP BY topic_id - ORDER BY num_posts DESC"; - $result = $db->sql_query_limit($sql, 1); - $active_t_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!empty($active_t_row)) - { - $sql = 'SELECT topic_title - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $active_t_row['topic_id']; - $result = $db->sql_query($sql); - $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); + // Obtain active topic + $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts + FROM ' . POSTS_TABLE . ' + WHERE poster_id = ' . $userdata['user_id'] . ' + AND post_postcount = 1 + AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' + GROUP BY topic_id + ORDER BY num_posts DESC'; + $result = $db->sql_query_limit($sql, 1); + $active_t_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + + if (!empty($active_t_row)) + { + $sql = 'SELECT topic_title + FROM ' . TOPICS_TABLE . ' + WHERE topic_id = ' . $active_t_row['topic_id']; + $result = $db->sql_query($sql); + $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); + $db->sql_freeresult($result); + } } $userdata['active_t_row'] = $active_t_row; diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 8978e3fadd..bd0ffaaf00 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -184,12 +184,6 @@ function dbms_select($default = '', $only_20x_options = false) */ function get_tables(&$db) { - if (!class_exists('phpbb_db_tools')) - { - global $phpbb_root_path, $phpEx; - require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); - } - $db_tools = new phpbb_db_tools($db); return $db_tools->sql_list_tables(); diff --git a/phpBB/includes/functions_jabber.php b/phpBB/includes/functions_jabber.php index 3d8e403f4b..b260ffad6e 100644 --- a/phpBB/includes/functions_jabber.php +++ b/phpBB/includes/functions_jabber.php @@ -249,7 +249,7 @@ class jabber return true; } - // Apparently an error occured... + // Apparently an error occurred... $this->add_to_log('Error: open_socket() - ' . $errorstr); return false; } diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index a646f35fdd..0222a57bcc 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -27,8 +27,9 @@ class messenger var $mail_priority = MAIL_NORMAL_PRIORITY; var $use_queue = true; - var $tpl_obj = NULL; - var $tpl_msg = array(); + /** @var phpbb_template */ + protected $template; + var $eol = "\n"; /** @@ -55,10 +56,10 @@ class messenger $this->vars = $this->msg = $this->replyto = $this->from = ''; $this->mail_priority = MAIL_NORMAL_PRIORITY; } - + /** * Set addresses for to/im as available - * + * * @param array $user User row */ function set_addresses($user) @@ -210,6 +211,8 @@ class messenger { global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager; + $this->setup_template(); + if (!trim($template_file)) { trigger_error('No template file for emailing set.', E_USER_ERROR); @@ -219,46 +222,43 @@ class messenger { // fall back to board default language if the user's language is // missing $template_file. If this does not exist either, - // $tpl->set_filenames will do a trigger_error + // $this->template->set_filenames will do a trigger_error $template_lang = basename($config['default_lang']); } - // tpl_msg now holds a template object we can use to parse the template file - if (!isset($this->tpl_msg[$template_lang . $template_file])) + if ($template_path) { - $style_resource_locator = new phpbb_style_resource_locator(); - $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider(), $phpbb_root_path); - $tpl = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, new phpbb_template_context(), $phpbb_extension_manager); - $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $tpl); + $template_paths = array( + $template_path, + ); + } + else + { + $template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/'; + $template_path .= $template_lang . '/email'; - $this->tpl_msg[$template_lang . $template_file] = $tpl; + $template_paths = array( + $template_path, + ); - $fallback_template_path = false; - - if (!$template_path) + // we can only specify default language fallback when the path is not a custom one for which we + // do not know the default language alternative + if ($template_lang !== basename($config['default_lang'])) { - $template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/'; - $template_path .= $template_lang . '/email'; + $fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/'; + $fallback_template_path .= basename($config['default_lang']) . '/email'; - // we can only specify default language fallback when the path is not a custom one for which we - // do not know the default language alternative - if ($template_lang !== basename($config['default_lang'])) - { - $fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/'; - $fallback_template_path .= basename($config['default_lang']) . '/email'; - } + $template_paths[] = $fallback_template_path; } - - $style->set_custom_style($template_lang . '_email', array($template_path, $fallback_template_path), array(), ''); - - $tpl->set_filenames(array( - 'body' => $template_file . '.txt', - )); } - $this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file]; - $this->vars = &$this->tpl_obj->_rootref; - $this->tpl_msg = ''; + $this->set_template_paths($template_lang . '_email', $template_paths); + + $this->template->set_filenames(array( + 'body' => $template_file . '.txt', + )); + + $this->vars = $this->template->get_template_vars(); return true; } @@ -268,22 +268,16 @@ class messenger */ function assign_vars($vars) { - if (!is_object($this->tpl_obj)) - { - return; - } + $this->setup_template(); - $this->tpl_obj->assign_vars($vars); + $this->template->assign_vars($vars); } function assign_block_vars($blockname, $vars) { - if (!is_object($this->tpl_obj)) - { - return; - } + $this->setup_template(); - $this->tpl_obj->assign_block_vars($blockname, $vars); + $this->template->assign_block_vars($blockname, $vars); } /** @@ -316,7 +310,7 @@ class messenger } // Parse message through template - $this->msg = trim($this->tpl_obj->assign_display('body')); + $this->msg = trim($this->template->assign_display('body')); // Because we use \n for newlines in the body message we need to fix line encoding errors for those admins who uploaded email template files in the wrong encoding $this->msg = str_replace("\r\n", "\n", $this->msg); @@ -643,6 +637,31 @@ class messenger unset($addresses); return true; } + + /** + * Setup template engine + */ + protected function setup_template() + { + global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager; + + if ($this->template instanceof phpbb_template) + { + return; + } + + $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager); + } + + /** + * Set template paths to load + */ + protected function set_template_paths($path_name, $paths) + { + $this->setup_template(); + + $this->template->set_style_names(array($path_name), $paths); + } } /** diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 0d387ace6d..99c24fcb19 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -455,7 +455,7 @@ class p_master */ function load_active($mode = false, $module_url = false, $execute_module = true) { - global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $phpbb_style; $module_path = $this->include_path . $this->p_class; $icat = request_var('icat', ''); @@ -494,6 +494,24 @@ class p_master // We pre-define the action parameter we are using all over the place if (defined('IN_ADMIN')) { + /* + * If this is an extension module, we'll try to automatically set + * the style paths for the extension (the ext author can change them + * if necessary). + */ + $module_dir = explode('_', get_class($this->module)); + + // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... + if (isset($module_dir[3]) && $module_dir[1] === 'ext') + { + $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/adm/style'; + + if (is_dir($module_style_dir)) + { + $phpbb_style->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), array(), ''); + } + } + // Is first module automatically enabled a duplicate and the category not passed yet? if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) { @@ -505,6 +523,24 @@ class p_master } else { + /* + * If this is an extension module, we'll try to automatically set + * the style paths for the extension (the ext author can change them + * if necessary). + */ + $module_dir = explode('_', get_class($this->module)); + + // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... + if (isset($module_dir[3]) && $module_dir[1] === 'ext') + { + $module_style_dir = 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/styles'; + + if (is_dir($phpbb_root_path . $module_style_dir)) + { + $phpbb_style->set_style(array($module_style_dir, 'styles')); + } + } + // If user specified the module url we will use it... if ($module_url !== false) { diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b9b518ad32..03565c27bb 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -176,7 +176,7 @@ function update_post_information($type, $ids, $return_update_sql = false) if ($type != 'topic') { $topic_join = ', ' . TOPICS_TABLE . ' t'; - $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1'; + $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_visibility = ' . ITEM_APPROVED; } else { @@ -190,7 +190,7 @@ function update_post_information($type, $ids, $return_update_sql = false) FROM ' . POSTS_TABLE . " p $topic_join WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " $topic_condition - AND p.post_approved = 1"; + AND p.post_visibility = " . ITEM_APPROVED; } else { @@ -198,7 +198,7 @@ function update_post_information($type, $ids, $return_update_sql = false) FROM ' . POSTS_TABLE . " p $topic_join WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " $topic_condition - AND p.post_approved = 1 + AND p.post_visibility = " . ITEM_APPROVED . " GROUP BY p.{$type}_id"; } $result = $db->sql_query($sql); @@ -982,13 +982,15 @@ function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $ms function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true) { global $user, $auth, $db, $template, $bbcode, $cache; - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx, $phpbb_container; + + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); // Go ahead and pull all data for this topic $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . ' + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1175,14 +1177,14 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id /** * Delete Post */ -function delete_post($forum_id, $topic_id, $post_id, &$data) +function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '') { - global $db, $user, $auth; + global $db, $user, $auth, $phpbb_container; global $config, $phpEx, $phpbb_root_path; // Specify our post mode $post_mode = 'delete'; - if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && $data['topic_replies_real'] == 0) + if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1)) { $post_mode = 'delete_topic'; } @@ -1224,20 +1226,30 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $db->sql_freeresult($result); } - if (!delete_posts('post_id', array($post_id), false, false)) + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + + // (Soft) delete the post + if ($is_soft && ($post_mode != 'delete_topic')) { - // Try to delete topic, we may had an previous error causing inconsistency - if ($post_mode == 'delete_topic') + $phpbb_content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); + } + else if (!$is_soft) + { + if (!delete_posts('post_id', array($post_id), false, false, false)) { - delete_topics('topic_id', array($topic_id), false); + // Try to delete topic, we may had an previous error causing inconsistency + if ($post_mode == 'delete_topic') + { + delete_topics('topic_id', array($topic_id), false); + } + trigger_error('ALREADY_DELETED'); } - trigger_error('ALREADY_DELETED'); } $db->sql_transaction('commit'); // Collect the necessary information for updating the tables - $sql_data[FORUMS_TABLE] = ''; + $sql_data[FORUMS_TABLE] = $sql_data[TOPICS_TABLE] = ''; switch ($post_mode) { case 'delete_topic': @@ -1246,21 +1258,43 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) { // counting is fun! we only have to do sizeof($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) - $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_topics_real = forum_topics_real - ' . $topic_count . ', forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum); + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET forum_topics_approved = forum_topics_approved - ' . $topic_count . ' + WHERE forum_id = ' . $updated_forum; + $db->sql_query($sql); update_post_information('forum', $updated_forum); } - delete_topics('topic_id', array($topic_id), false); - - $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; - $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; - - $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) + if ($is_soft) { - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + $topic_row = array(); + $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); } + else + { + delete_topics('topic_id', array($topic_id), false); + + if ($data['topic_visibility'] == ITEM_APPROVED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1'; + } + else if ($data['topic_visibility'] == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1'; + } + else if ($data['topic_visibility'] == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1'; + } + + $update_sql = update_post_information('forum', $forum_id, true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; + $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + } + } + break; case 'delete_first_post': @@ -1268,73 +1302,101 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u WHERE p.topic_id = $topic_id AND p.poster_id = u.user_id - ORDER BY p.post_time ASC"; + AND p.post_visibility = " . ITEM_APPROVED . ' + ORDER BY p.post_time ASC'; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; - - $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; - - // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply" - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); + if (!$row) + { + // No approved post, so the first is a not-approved post (unapproved or soft deleted) + $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u + WHERE p.topic_id = $topic_id + AND p.poster_id = u.user_id + ORDER BY p.post_time ASC"; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } $next_post_id = (int) $row['post_id']; + + $sql_data[TOPICS_TABLE] = $db->sql_build_array('UPDATE', array( + 'topic_poster' => (int) $row['poster_id'], + 'topic_first_post_id' => (int) $row['post_id'], + 'topic_first_poster_colour' => $row['user_colour'], + 'topic_first_poster_name' => ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username'], + 'topic_time' => (int) $row['post_time'], + )); break; case 'delete_last_post': - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; - - $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) + if (!$is_soft) { - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + // Update last post information when hard deleting. Soft delete already did that by itself. + $update_sql = update_post_information('forum', $forum_id, true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . implode(', ', $update_sql[$forum_id]); + } + + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0'; + + $update_sql = update_post_information('topic', $topic_id, true); + if (!empty($update_sql)) + { + $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); + $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); + } } - $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - - $update_sql = update_post_information('topic', $topic_id, true); - if (sizeof($update_sql)) - { - $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); - $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); - } - else + if (!$next_post_id) { $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : ''); + WHERE topic_id = $topic_id + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); + $next_post_id = (int) $db->sql_fetchfield('last_post_id'); $db->sql_freeresult($result); - - $next_post_id = (int) $row['last_post_id']; } break; case 'delete': $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . ' + WHERE topic_id = $topic_id + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); + $next_post_id = (int) $db->sql_fetchfield('post_id'); $db->sql_freeresult($result); - - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; - - $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - $next_post_id = (int) $row['post_id']; break; } if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) { + if (!$is_soft) + { + if ($data['post_visibility'] == ITEM_APPROVED) + { + $phpbb_content_visibility->remove_post_from_statistic($data, $sql_data); + } + else if ($data['post_visibility'] == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1'; + } + else if ($data['post_visibility'] == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1'; + } + } + $sql = 'SELECT 1 AS has_attachments FROM ' . ATTACHMENTS_TABLE . ' WHERE topic_id = ' . $topic_id; @@ -1344,18 +1406,16 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) if (!$has_attachments) { - $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_attachment = 0'; } } -// $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : ''; - $db->sql_transaction('begin'); $where_sql = array( FORUMS_TABLE => "forum_id = $forum_id", TOPICS_TABLE => "topic_id = $topic_id", - USERS_TABLE => 'user_id = ' . $data['poster_id'] + USERS_TABLE => 'user_id = ' . $data['poster_id'], ); foreach ($sql_data as $table => $update_sql) @@ -1425,7 +1485,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } else if ($mode == 'edit') { - $post_mode = ($data['topic_replies_real'] == 0) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); + $post_mode = ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); } // First of all make sure the subject and topic title are having the correct length. @@ -1438,9 +1498,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id']; // Retrieve some additional information if not present - if ($mode == 'edit' && (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false)) + if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { - $sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved + $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; @@ -1448,26 +1508,29 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $topic_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $data['topic_approved'] = $topic_row['topic_approved']; - $data['post_approved'] = $topic_row['post_approved']; + $data['topic_visibility'] = $topic_row['topic_visibility']; + $data['post_visibility'] = $topic_row['post_visibility']; } - // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval - // The variable name should be $post_approved, because it indicates if the post is approved or not - $post_approval = 1; + // This variable indicates if the user is able to post or put into the queue + $post_visibility = ITEM_APPROVED; // Check the permissions for post approval. // Moderators must go through post approval like ordinary users. if (!$auth->acl_get('f_noapprove', $data['forum_id'])) { // Post not approved, but in queue - $post_approval = 0; + $post_visibility = ITEM_UNAPPROVED; } - // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved + // MODs/Extensions are able to force any visibility on posts if (isset($data['force_approved_state'])) { - $post_approval = ($data['force_approved_state']) ? 1 : 0; + $post_visibility = (in_array((int) $data['force_approved_state'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED))) ? (int) $data['force_approved_state'] : $post_visibility; + } + if (isset($data['force_visibility'])) + { + $post_visibility = (in_array((int) $data['force_visibility'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED))) ? (int) $data['force_visibility'] : $post_visibility; } // Start the transaction here @@ -1484,7 +1547,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, - 'post_approved' => $post_approval, + 'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1550,7 +1613,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'forum_id' => $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], - 'post_approved' => (!$post_approval) ? 0 : $data['post_approved'], + // We will change the visibility later + //'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1571,8 +1635,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } - - $post_approved = $sql_data[POSTS_TABLE]['sql']['post_approved']; $topic_row = array(); // And the topic ladies and gentlemen @@ -1585,7 +1647,11 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_approved' => $post_approval, + 'topic_posts_approved' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, + 'topic_posts_softdeleted' => ($post_visibility == ITEM_DELETED) ? 1 : 0, + 'topic_posts_unapproved' => ($post_visibility == ITEM_UNAPPROVED) ? 1 : 0, + 'topic_visibility' => $post_visibility, + 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], @@ -1617,28 +1683,47 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u ); } - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); + $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_approved = forum_topics_approved + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; + } + else if ($post_visibility == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_unapproved = forum_topics_unapproved + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; + } + else if ($post_visibility == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_softdeleted = forum_topics_softdeleted + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; } - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : ''); break; case 'reply': $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', - topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . - (($post_approval) ? ', topic_replies = topic_replies + 1' : '') . + (($post_visibility == ITEM_APPROVED) ? ', topic_posts_approved = topic_posts_approved + 1' : '') . + (($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') . + (($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); + $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; + } + else if ($post_visibility == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; + } + else if ($post_visibility == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; } break; @@ -1662,7 +1747,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[TOPICS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_approved' => (!$post_approval) ? 0 : $data['topic_approved'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, @@ -1677,56 +1761,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0), ); - // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved - if (!$post_approval && $data['topic_approved']) - { - // Do we need to grab some topic informations? - if (!sizeof($topic_row)) - { - $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $data['topic_id']; - $result = $db->sql_query($sql); - $topic_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - // If this is the only post remaining we do not need to decrement topic_replies. - // Also do not decrement if first post - then the topic_replies will not be adjusted if approving the topic again. - - // If this is an edited topic or the first post the topic gets completely disapproved later on... - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1'; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1); - - set_config_count('num_topics', -1, true); - set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true); - - // Only decrement this post, since this is the one non-approved now - if ($auth->acl_get('f_postcount', $data['forum_id'])) - { - $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; - } - } - - break; - - case 'edit': - case 'edit_last_post': - - // Correctly set back the topic replies and forum posts... but only if the post was approved before. - if (!$post_approval && $data['post_approved']) - { - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; - - set_config_count('num_posts', -1, true); - - if ($auth->acl_get('f_postcount', $data['forum_id'])) - { - $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; - } - } - break; } @@ -1751,27 +1785,48 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_mode == 'reply') { $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( - 'topic_id' => $data['topic_id']) - ); + 'topic_id' => $data['topic_id'], + )); } $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); $db->sql_query($sql); $data['post_id'] = $db->sql_nextid(); - if ($post_mode == 'post') + if ($post_mode == 'post' || $post_visibility == ITEM_APPROVED) { $sql_data[TOPICS_TABLE]['sql'] = array( - 'topic_first_post_id' => $data['post_id'], 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, - 'topic_last_poster_id' => (int) $user->data['user_id'], - 'topic_last_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), + 'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'], + 'topic_last_poster_name' => ($user->data['user_id'] == ANONYMOUS) ? $sql_data[POSTS_TABLE]['sql']['post_username'] : $user->data['username'], 'topic_last_poster_colour' => $user->data['user_colour'], 'topic_last_post_subject' => (string) $subject, ); } + if ($post_mode == 'post') + { + $sql_data[TOPICS_TABLE]['sql']['topic_first_post_id'] = $data['post_id']; + } + + // Update total post count and forum information + if ($post_visibility == ITEM_APPROVED) + { + if ($post_mode == 'post') + { + set_config_count('num_topics', 1, true); + } + set_config_count('num_posts', 1, true); + + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id']; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'"; + } + unset($sql_data[POSTS_TABLE]['sql']); } @@ -1782,6 +1837,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' WHERE topic_id = ' . $data['topic_id']; $db->sql_query($sql); + + unset($sql_data[TOPICS_TABLE]['sql']); } // Update the posts table @@ -1791,6 +1848,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' WHERE post_id = ' . $data['post_id']; $db->sql_query($sql); + + unset($sql_data[POSTS_TABLE]['sql']); } // Update Poll Tables @@ -1936,114 +1995,21 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } - // we need to update the last forum information - // only applicable if the topic is approved - if ($post_approved || !$data['post_approved']) + // Fix the post's and topic's visibility and first/last post information, when the post is edited + if (($post_mode != 'post' && $post_mode != 'reply') && $data['post_visibility'] != $post_visibility) { - // the last post makes us update the forum table. This can happen if... - // We make a new topic - // We reply to a topic - // We edit the last post in a topic and this post is the latest in the forum (maybe) - // We edit the only post in the topic - // We edit the first post in the topic and all the other posts are not approved - if (($post_mode == 'post' || $post_mode == 'reply') && $post_approved) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'"; - } - else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) - { - // this does not _necessarily_ mean that we must update the info again, - // it just means that we might have to - $sql = 'SELECT forum_last_post_id, forum_last_post_subject - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . (int) $data['forum_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + // If the post was not approved, it could also be the starter, + // so we sync the starter after approving/restoring, to ensure that the stats are correct + // Same applies for the last post + $is_starter = ($post_mode == 'edit_first_post' || $data['post_visibility'] != ITEM_APPROVED); + $is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); - // this post is the latest post in the forum, better update - if ($row['forum_last_post_id'] == $data['post_id']) - { - // If post approved and subject changed, or poster is anonymous, we need to update the forum_last* rows - if ($post_approved && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) - { - // the post's subject changed - if ($row['forum_last_post_subject'] !== $subject) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\''; - } - - // Update the user name if poster is anonymous... just in case an admin changed it - if ($data['poster_id'] == ANONYMOUS) - { - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; - } - } - else if ($data['post_approved'] !== $post_approved) - { - // we need a fresh change of socks, everything has become invalidated - $sql = 'SELECT MAX(topic_last_post_id) as last_post_id - FROM ' . TOPICS_TABLE . ' - WHERE forum_id = ' . (int) $data['forum_id'] . ' - AND topic_approved = 1'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // any posts left in this forum? - if (!empty($row['last_post_id'])) - { - $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_id = ' . (int) $row['last_post_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // salvation, a post is found! jam it into the forums table - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time']; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; - } - else - { - // just our luck, the last topic in the forum has just been turned unapproved... - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''"; - } - } - } - } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $phpbb_content_visibility->set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest); } - - // topic sync time! - // simply, we update if it is a reply or the last post is edited - if ($post_approved) + else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) { - // reply requires the whole thing - if ($post_mode == 'reply') - { - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $data['post_id']; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $user->data['user_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . (($user->data['user_id'] != ANONYMOUS) ? $db->sql_escape($user->data['user_colour']) : '') . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $current_time; - } - else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) + if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility) { // only the subject can be changed from edit $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; @@ -2053,57 +2019,44 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'"; } - } - } - else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) - { - // like having the rug pulled from under us - $sql = 'SELECT MAX(post_id) as last_post_id - FROM ' . POSTS_TABLE . ' - WHERE topic_id = ' . (int) $data['topic_id'] . ' - AND post_approved = 1'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - // any posts left in this forum? - if (!empty($row['last_post_id'])) - { - $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_id = ' . (int) $row['last_post_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + if ($post_visibility == ITEM_APPROVED) + { + // this does not _necessarily_ mean that we must update the info again, + // it just means that we might have to + $sql = 'SELECT forum_last_post_id, forum_last_post_subject + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . (int) $data['forum_id']; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - // salvation, a post is found! jam it into the topics table - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $row['post_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $row['post_time']; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $row['poster_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; - } - } + // this post is the latest post in the forum, better update + if ($row['forum_last_post_id'] == $data['post_id'] && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) + { + // the post's subject changed + if ($row['forum_last_post_subject'] !== $subject) + { + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; + } - // Update total post count, do not consider moderated posts/topics - if ($post_approval) - { - if ($post_mode == 'post') - { - set_config_count('num_topics', 1, true); - set_config_count('num_posts', 1, true); - } - - if ($post_mode == 'reply') - { - set_config_count('num_posts', 1, true); + // Update the user name if poster is anonymous... just in case a moderator changed it + if ($data['poster_id'] == ANONYMOUS) + { + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; + } + } + } } } // Update forum stats - $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id); + $where_sql = array( + POSTS_TABLE => 'post_id = ' . $data['post_id'], + TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], + FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], + USERS_TABLE => 'user_id = ' . $poster_id + ); foreach ($sql_data as $table => $update_ary) { @@ -2226,7 +2179,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications = $phpbb_container->get('notification_manager'); - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { switch ($mode) { @@ -2259,7 +2212,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } } - else + else if ($post_visibility == ITEM_UNAPPROVED) { switch ($mode) { @@ -2276,6 +2229,32 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit_first_post': case 'edit': case 'edit_last_post': + // @todo: Check whether these notification deletions are correct + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + + $phpbb_notifications->delete_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $data['post_id']); + break; + } + } + else if ($post_visibility == ITEM_DELETED) + { + switch ($mode) + { + case 'post': + case 'reply': + case 'quote': + // Nothing to do here + break; + + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': + // @todo: Check whether these notification deletions are correct $phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications(array( @@ -2289,7 +2268,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $params = $add_anchor = ''; - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { $params .= '&t=' . $data['topic_id']; diff --git a/phpBB/includes/mcp/info/mcp_queue.php b/phpBB/includes/mcp/info/mcp_queue.php index 7ad79f9781..68cac5abd2 100644 --- a/phpBB/includes/mcp/info/mcp_queue.php +++ b/phpBB/includes/mcp/info/mcp_queue.php @@ -21,6 +21,8 @@ class mcp_queue_info 'modes' => array( 'unapproved_topics' => array('title' => 'MCP_QUEUE_UNAPPROVED_TOPICS', 'auth' => 'aclf_m_approve', 'cat' => array('MCP_QUEUE')), 'unapproved_posts' => array('title' => 'MCP_QUEUE_UNAPPROVED_POSTS', 'auth' => 'aclf_m_approve', 'cat' => array('MCP_QUEUE')), + 'deleted_topics' => array('title' => 'MCP_QUEUE_DELETED_TOPICS', 'auth' => 'aclf_m_approve', 'cat' => array('MCP_QUEUE')), + 'deleted_posts' => array('title' => 'MCP_QUEUE_DELETED_POSTS', 'auth' => 'aclf_m_approve', 'cat' => array('MCP_QUEUE')), 'approve_details' => array('title' => 'MCP_QUEUE_APPROVE_DETAILS', 'auth' => 'acl_m_approve,$id || (!$id && aclf_m_approve)', 'cat' => array('MCP_QUEUE')), ), ); diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 0fad9e2a22..841a0afddb 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -22,7 +22,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) { global $template, $db, $user, $auth, $cache, $module; global $phpEx, $phpbb_root_path, $config; - global $request, $phpbb_dispatcher; + global $request, $phpbb_dispatcher, $phpbb_container; $user->add_lang(array('viewtopic', 'viewforum')); @@ -98,7 +98,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $sort_by_sql = $sort_order_sql = array(); mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id); - $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total; + $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; $base_url = $url . "&i=$id&action=$action&mode=$mode&sd=$sort_dir&sk=$sort_key&st=$sort_days" . (($merge_select) ? $selected_ids : ''); @@ -116,6 +116,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'S_CAN_REPORT' => $auth->acl_get('m_report', $forum_id), 'S_CAN_DELETE' => $auth->acl_get('m_delete', $forum_id), + 'S_CAN_RESTORE' => $auth->acl_get('m_approve', $forum_id), 'S_CAN_MERGE' => $auth->acl_get('m_merge', $forum_id), 'S_CAN_MOVE' => $auth->acl_get('m_move', $forum_id), 'S_CAN_FORK' => $auth->acl_get('m_', $forum_id), @@ -151,10 +152,12 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $read_tracking_join = $read_tracking_select = ''; } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' - ' . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . " + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . " $limit_time_sql ORDER BY t.topic_type DESC, $sort_order_sql"; $result = $db->sql_query_limit($sql, $topics_per_page, $start); @@ -203,7 +206,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $row = &$topic_rows[$topic_id]; - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; + $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED) { @@ -220,9 +223,11 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $topic_title = censor_text($row['topic_title']); - $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; - $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; + $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; + $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; + $topic_deleted = $row['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; + $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . '&i=queue&mode=deleted_topics&t=' . $topic_id : $u_mcp_queue; $topic_row = array( 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', @@ -232,6 +237,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', + 'DELETED_IMG' => ($topic_deleted) ? $user->img('icon_topic_deleted', 'POSTS_DELETED') : '', 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), @@ -245,7 +251,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'TOPIC_TYPE' => $topic_type, 'TOPIC_TITLE' => $topic_title, - 'REPLIES' => ($auth->acl_get('m_approve', $row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'], + 'REPLIES' => $phpbb_content_visibility->get_count('topic_posts', $row, $row['forum_id']) - 1, 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'], @@ -254,6 +260,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, + 'S_TOPIC_DELETED' => $topic_deleted, 'S_UNREAD_TOPIC' => $unread_topic, ); diff --git a/phpBB/includes/mcp/mcp_front.php b/phpBB/includes/mcp/mcp_front.php index ba4b15895a..44cab5d910 100644 --- a/phpBB/includes/mcp/mcp_front.php +++ b/phpBB/includes/mcp/mcp_front.php @@ -39,7 +39,7 @@ function mcp_front_view($id, $mode, $action) $sql = 'SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' - AND post_approved = 0'; + AND post_visibility = ' . ITEM_UNAPPROVED; $result = $db->sql_query($sql); $total = (int) $db->sql_fetchfield('total'); $db->sql_freeresult($result); @@ -60,7 +60,7 @@ function mcp_front_view($id, $mode, $action) $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' - AND post_approved = 0 + AND post_visibility = ' . ITEM_UNAPPROVED . ' ORDER BY post_time DESC'; $result = $db->sql_query_limit($sql, 5); diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index c28b466bcf..275edbe55a 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -33,7 +33,7 @@ class mcp_main function main($id, $mode) { global $auth, $db, $user, $template, $action; - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx, $request; $quickmod = ($mode == 'quickmod') ? true : false; @@ -108,27 +108,48 @@ class mcp_main case 'delete_topic': $user->add_lang('viewtopic'); - $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); + // f parameter is not reliable for permission usage, however we just use it to decide + // which permission we will check later on. So if it is manipulated, we will still catch it later on. + $forum_id = $request->variable('f', 0); + $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); + $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; if (!sizeof($topic_ids)) { trigger_error('NO_TOPIC_SELECTED'); } - mcp_delete_topic($topic_ids); + mcp_delete_topic($topic_ids, $soft_delete, ($soft_delete) ? $request->variable('delete_reason', '', true) : ''); break; case 'delete_post': $user->add_lang('posting'); - $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0)); + // f parameter is not reliable for permission usage, however we just use it to decide + // which permission we will check later on. So if it is manipulated, we will still catch it later on. + $forum_id = $request->variable('f', 0); + $post_ids = (!$quickmod) ? $request->variable('post_id_list', array(0)) : array($request->variable('p', 0)); + $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false; if (!sizeof($post_ids)) { trigger_error('NO_POST_SELECTED'); } - mcp_delete_post($post_ids); + mcp_delete_post($post_ids, $soft_delete, ($soft_delete) ? $request->variable('delete_reason', '', true) : ''); + break; + + case 'restore_topic': + $user->add_lang('posting'); + + $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0)); + + if (!sizeof($topic_ids)) + { + trigger_error('NO_TOPIC_SELECTED'); + } + + mcp_restore_topic($topic_ids); break; } @@ -455,60 +476,31 @@ function mcp_move_topic($topic_ids) $forum_sync_data[$forum_id] = current($topic_data); $forum_sync_data[$to_forum_id] = $forum_data; - // Real topics added to target forum - $topics_moved = sizeof($topic_data); - - // Approved topics added to target forum - $topics_authed_moved = 0; - - // Posts (topic replies + topic post if approved) added to target forum - $topic_posts_added = 0; - - // Posts (topic replies + topic post if approved and not global announcement) removed from source forum - $topic_posts_removed = 0; - - // Real topics removed from source forum (all topics without global announcements) - $topics_removed = 0; - - // Approved topics removed from source forum (except global announcements) - $topics_authed_removed = 0; + $topics_moved = $topics_moved_unapproved = $topics_moved_softdeleted = 0; + $posts_moved = $posts_moved_unapproved = $posts_moved_softdeleted = 0; foreach ($topic_data as $topic_id => $topic_info) { - if ($topic_info['topic_approved']) + if ($topic_info['topic_visibility'] == ITEM_APPROVED) { - $topics_authed_moved++; - $topic_posts_added++; + $topics_moved++; + } + elseif ($topic_info['topic_visibility'] == ITEM_UNAPPROVED) + { + $topics_moved_unapproved++; + } + elseif ($topic_info['topic_visibility'] == ITEM_DELETED) + { + $topics_moved_softdeleted++; } - $topic_posts_added += $topic_info['topic_replies']; - - $topics_removed++; - $topic_posts_removed += $topic_info['topic_replies']; - - if ($topic_info['topic_approved']) - { - $topics_authed_removed++; - $topic_posts_removed++; - } + $posts_moved += $topic_info['topic_posts_approved']; + $posts_moved_unapproved += $topic_info['topic_posts_unapproved']; + $posts_moved_softdeleted += $topic_info['topic_posts_softdeleted']; } $db->sql_transaction('begin'); - $sync_sql = array(); - - if ($topic_posts_added) - { - $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added; - } - - if ($topics_authed_moved) - { - $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved; - } - - $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved; - // Move topics, but do not resync yet move_topics($topic_ids, $to_forum_id, false); @@ -520,6 +512,7 @@ function mcp_move_topic($topic_ids) $db->sql_query($sql); } + $shadow_topics = 0; $forum_ids = array($to_forum_id); foreach ($topic_data as $topic_id => $row) { @@ -528,21 +521,22 @@ function mcp_move_topic($topic_ids) add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']); // Leave a redirection if required and only if the topic is visible to users - if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL) + if ($leave_shadow && $row['topic_visibility'] == ITEM_APPROVED && $row['topic_type'] != POST_GLOBAL) { $shadow = array( 'forum_id' => (int) $row['forum_id'], 'icon_id' => (int) $row['icon_id'], 'topic_attachment' => (int) $row['topic_attachment'], - 'topic_approved' => 1, // a shadow topic is always approved + 'topic_visibility' => ITEM_APPROVED, // a shadow topic is always approved 'topic_reported' => 0, // a shadow topic is never reported 'topic_title' => (string) $row['topic_title'], 'topic_poster' => (int) $row['topic_poster'], 'topic_time' => (int) $row['topic_time'], 'topic_time_limit' => (int) $row['topic_time_limit'], 'topic_views' => (int) $row['topic_views'], - 'topic_replies' => (int) $row['topic_replies'], - 'topic_replies_real' => (int) $row['topic_replies_real'], + 'topic_posts_approved' => (int) $row['topic_posts_approved'], + 'topic_posts_unapproved'=> (int) $row['topic_posts_unapproved'], + 'topic_posts_softdeleted'=> (int) $row['topic_posts_softdeleted'], 'topic_status' => ITEM_MOVED, 'topic_type' => POST_NORMAL, 'topic_first_post_id' => (int) $row['topic_first_post_id'], @@ -568,25 +562,45 @@ function mcp_move_topic($topic_ids) $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow)); // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts - $topics_removed--; - $topics_authed_removed--; + $shadow_topics++; } } unset($topic_data); - if ($topic_posts_removed) + $sync_sql = array(); + if ($posts_moved) { - $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed; + $sync_sql[$to_forum_id][] = 'forum_posts_approved = forum_posts_approved + ' . (int) $posts_moved; + $sync_sql[$forum_id][] = 'forum_posts_approved = forum_posts_approved - ' . (int) $posts_moved; + } + if ($posts_moved_unapproved) + { + $sync_sql[$to_forum_id][] = 'forum_posts_unapproved = forum_posts_unapproved + ' . (int) $posts_moved_unapproved; + $sync_sql[$forum_id][] = 'forum_posts_unapproved = forum_posts_unapproved - ' . (int) $posts_moved_unapproved; + } + if ($posts_moved_softdeleted) + { + $sync_sql[$to_forum_id][] = 'forum_posts_softdeleted = forum_posts_softdeleted + ' . (int) $posts_moved_softdeleted; + $sync_sql[$forum_id][] = 'forum_posts_softdeleted = forum_posts_softdeleted - ' . (int) $posts_moved_softdeleted; } - if ($topics_removed) + if ($topics_moved) { - $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed; + $sync_sql[$to_forum_id][] = 'forum_topics_approved = forum_topics_approved + ' . (int) $topics_moved; + if ($topics_moved - $shadow_topics > 0) + { + $sync_sql[$forum_id][] = 'forum_topics_approved = forum_topics_approved - ' . (int) ($topics_moved - $shadow_topics); + } } - - if ($topics_authed_removed) + if ($topics_moved_unapproved) { - $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed; + $sync_sql[$to_forum_id][] = 'forum_topics_unapproved = forum_topics_unapproved + ' . (int) $topics_moved_unapproved; + $sync_sql[$forum_id][] = 'forum_topics_unapproved = forum_topics_unapproved - ' . (int) $topics_moved_unapproved; + } + if ($topics_moved_softdeleted) + { + $sync_sql[$to_forum_id][] = 'forum_topics_softdeleted = forum_topics_softdeleted + ' . (int) $topics_moved_softdeleted; + $sync_sql[$forum_id][] = 'forum_topics_softdeleted = forum_topics_softdeleted - ' . (int) $topics_moved_softdeleted; } $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS'; @@ -635,26 +649,99 @@ function mcp_move_topic($topic_ids) } } +/** +* Restore Topics +*/ +function mcp_restore_topic($topic_ids) +{ + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; + + if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_approve'))) + { + return; + } + + $redirect = $request->variable('redirect', build_url(array('action', 'quickmod'))); + $forum_id = $request->variable('f', 0); + + $s_hidden_fields = build_hidden_fields(array( + 'topic_id_list' => $topic_ids, + 'f' => $forum_id, + 'action' => 'restore_topic', + 'redirect' => $redirect, + )); + $success_msg = ''; + + if (confirm_box(true)) + { + $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_RESTORED_SUCCESS' : 'TOPICS_RESTORED_SUCCESS'; + + $data = get_topic_data($topic_ids); + + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + foreach ($data as $topic_id => $row) + { + $return = $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), ''); + if (!empty($return)) + { + add_log('mod', $row['forum_id'], $topic_id, 'LOG_RESTORE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + } + } + } + else + { + confirm_box(false, (sizeof($topic_ids) == 1) ? 'RESTORE_TOPIC' : 'RESTORE_TOPICS', $s_hidden_fields); + } + + $topic_id = $request->variable('t', 0); + if (!$request->is_set('quickmod', phpbb_request_interface::REQUEST)) + { + $redirect = $request->variable('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); + $redirect_message = 'PAGE'; + } + else if ($topic_id) + { + $redirect = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id); + $redirect_message = 'TOPIC'; + } + else + { + $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); + $redirect_message = 'FORUM'; + } + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, $redirect); + trigger_error($user->lang[$success_msg] . '

    ' . sprintf($user->lang['RETURN_' . $redirect_message], '', '')); + } +} + /** * Delete Topics */ -function mcp_delete_topic($topic_ids) +function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_topic') { - global $auth, $user, $db, $phpEx, $phpbb_root_path; + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete'))) { return; } - $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); - $forum_id = request_var('f', 0); + $redirect = $request->variable('redirect', build_url(array('action', 'quickmod'))); + $forum_id = $request->variable('f', 0); - $s_hidden_fields = build_hidden_fields(array( + $s_hidden_fields = array( 'topic_id_list' => $topic_ids, 'f' => $forum_id, - 'action' => 'delete_topic', - 'redirect' => $redirect) + 'action' => $action, + 'redirect' => $redirect, ); $success_msg = ''; @@ -672,23 +759,81 @@ function mcp_delete_topic($topic_ids) } else { - add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + // Only soft delete non-shadow topics + if ($is_soft) + { + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $return = $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), $soft_delete_reason); + if (!empty($return)) + { + add_log('mod', $row['forum_id'], $topic_id, 'LOG_SOFTDELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + } + } + else + { + add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); + } } } - $return = delete_topics('topic_id', $topic_ids); + if (!$is_soft) + { + $return = delete_topics('topic_id', $topic_ids); + } } else { - confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields); + global $template; + + $user->add_lang('posting'); + + $only_softdeleted = false; + if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) + { + // If there are only soft deleted topics, we display a message why the option is not available + $sql = 'SELECT topic_id + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . ' + AND topic_visibility <> ' . ITEM_DELETED; + $result = $db->sql_query_limit($sql, 1); + $only_softdeleted = !$db->sql_fetchfield('topic_id'); + $db->sql_freeresult($result); + } + + $template->assign_vars(array( + 'S_SOFTDELETED' => $only_softdeleted, + 'S_TOPIC_MODE' => true, + 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id), + 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id), + 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), + )); + + $l_confirm = (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; + if ($only_softdeleted) + { + $l_confirm .= '_PERMANENTLY'; + $s_hidden_fields['delete_permanent'] = '1'; + } + else if (!$auth->acl_get('m_softdelete', $forum_id)) + { + $s_hidden_fields['delete_permanent'] = '1'; + } + + confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } - if (!isset($_REQUEST['quickmod'])) + $topic_id = $request->variable('t', 0); + if (!$request->is_set('quickmod', phpbb_request_interface::REQUEST)) { - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); $redirect_message = 'PAGE'; } + else if ($is_soft && $topic_id) + { + $redirect = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id); + $redirect_message = 'TOPIC'; + } else { $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); @@ -709,27 +854,93 @@ function mcp_delete_topic($topic_ids) /** * Delete Posts */ -function mcp_delete_post($post_ids) +function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_post') { - global $auth, $user, $db, $phpEx, $phpbb_root_path; + global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; - if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete'))) + if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_softdelete'))) { return; } - $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); - $forum_id = request_var('f', 0); + $redirect = $request->variable('redirect', build_url(array('action', 'quickmod'))); + $forum_id = $request->variable('f', 0); - $s_hidden_fields = build_hidden_fields(array( + $s_hidden_fields = array( 'post_id_list' => $post_ids, 'f' => $forum_id, - 'action' => 'delete_post', - 'redirect' => $redirect) + 'action' => $action, + 'redirect' => $redirect, ); $success_msg = ''; - if (confirm_box(true)) + if (confirm_box(true) && $is_soft) + { + $post_info = get_post_data($post_ids); + + $topic_info = $approve_log = array(); + + // Group the posts by topic_id + foreach ($post_info as $post_id => $post_data) + { + if ($post_data['post_visibility'] != ITEM_APPROVED) + { + continue; + } + $topic_id = (int) $post_data['topic_id']; + + $topic_info[$topic_id]['posts'][] = (int) $post_id; + $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id']; + + if ($post_id == $post_data['topic_first_post_id']) + { + $topic_info[$topic_id]['first_post'] = true; + } + + if ($post_id == $post_data['topic_last_post_id']) + { + $topic_info[$topic_id]['last_post'] = true; + } + + $approve_log[] = array( + 'forum_id' => $post_data['forum_id'], + 'topic_id' => $post_data['topic_id'], + 'post_subject' => $post_data['post_subject'], + 'poster_id' => $post_data['poster_id'], + 'post_username' => $post_data['post_username'], + 'username' => $post_data['username'], + ); + } + + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + foreach ($topic_info as $topic_id => $topic_data) + { + $phpbb_content_visibility->set_post_visibility(ITEM_DELETED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), $soft_delete_reason, isset($topic_data['first_post']), isset($topic_data['last_post'])); + } + $affected_topics = sizeof($topic_info); + // None of the topics is really deleted, so a redirect won't hurt much. + $deleted_topics = 0; + + $success_msg = (sizeof($post_info) == 1) ? 'POST_DELETED_SUCCESS' : 'POSTS_DELETED_SUCCESS'; + + foreach ($approve_log as $row) + { + $post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username']; + add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_SOFTDELETE_POST', $row['post_subject'], $post_username); + } + + $topic_id = $request->variable('t', 0); + + // Return links + $return_link = array(); + if ($affected_topics == 1 && $topic_id) + { + $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '', ''); + } + $return_link[] = sprintf($user->lang['RETURN_FORUM'], '', ''); + + } + else if (confirm_box(true)) { if (!function_exists('delete_posts')) { @@ -772,7 +983,7 @@ function mcp_delete_post($post_ids) $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics; $db->sql_freeresult($result); - $topic_id = request_var('t', 0); + $topic_id = $request->variable('t', 0); // Return links $return_link = array(); @@ -810,10 +1021,45 @@ function mcp_delete_post($post_ids) } else { - confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields); + global $template; + + $user->add_lang('posting'); + + $only_softdeleted = false; + if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) + { + // If there are only soft deleted posts, we display a message why the option is not available + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + WHERE ' . $db->sql_in_set('post_id', $post_ids) . ' + AND post_visibility <> ' . ITEM_DELETED; + $result = $db->sql_query_limit($sql, 1); + $only_softdeleted = !$db->sql_fetchfield('post_id'); + $db->sql_freeresult($result); + } + + $template->assign_vars(array( + 'S_SOFTDELETED' => $only_softdeleted, + 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id), + 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id), + 'S_DELETE_REASON' => $auth->acl_get('m_softdelete', $forum_id), + )); + + $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS'; + if ($only_softdeleted) + { + $l_confirm .= '_PERMANENTLY'; + $s_hidden_fields['delete_permanent'] = '1'; + } + else if (!$auth->acl_get('m_softdelete', $forum_id)) + { + $s_hidden_fields['delete_permanent'] = '1'; + } + + confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = $request->variable('redirect', "index.$phpEx"); $redirect = reapply_sid($redirect); if (!$success_msg) @@ -898,10 +1144,10 @@ function mcp_fork_topic($topic_ids) { $topic_data = get_topic_data($topic_ids, 'f_post'); - $total_posts = 0; + $total_topics = $total_topics_unapproved = $total_topics_softdeleted = 0; + $total_posts = $total_posts_unapproved = $total_posts_softdeleted = 0; $new_topic_id_list = array(); - foreach ($topic_data as $topic_id => $topic_row) { if (!isset($search_type) && $topic_row['enable_indexing']) @@ -932,13 +1178,14 @@ function mcp_fork_topic($topic_ids) 'forum_id' => (int) $to_forum_id, 'icon_id' => (int) $topic_row['icon_id'], 'topic_attachment' => (int) $topic_row['topic_attachment'], - 'topic_approved' => 1, + 'topic_visibility' => (int) $topic_row['topic_visibility'], 'topic_reported' => 0, 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], 'topic_time' => (int) $topic_row['topic_time'], - 'topic_replies' => (int) $topic_row['topic_replies_real'], - 'topic_replies_real' => (int) $topic_row['topic_replies_real'], + 'topic_posts_approved' => (int) $topic_row['topic_posts_approved'], + 'topic_posts_unapproved' => (int) $topic_row['topic_posts_unapproved'], + 'topic_posts_softdeleted' => (int) $topic_row['topic_posts_softdeleted'], 'topic_status' => (int) $topic_row['topic_status'], 'topic_type' => (int) $topic_row['topic_type'], 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], @@ -959,6 +1206,19 @@ function mcp_fork_topic($topic_ids) $new_topic_id = $db->sql_nextid(); $new_topic_id_list[$topic_id] = $new_topic_id; + switch ($topic_row['topic_visibility']) + { + case ITEM_APPROVED: + $total_topics++; + break; + case ITEM_UNAPPROVED: + $total_topics_unapproved++; + break; + case ITEM_DELETED: + $total_topics_softdeleted++; + break; + } + if ($topic_row['poll_start']) { $poll_rows = array(); @@ -999,7 +1259,6 @@ function mcp_fork_topic($topic_ids) continue; } - $total_posts += sizeof($post_rows); foreach ($post_rows as $row) { $sql_ary = array( @@ -1009,7 +1268,7 @@ function mcp_fork_topic($topic_ids) 'icon_id' => (int) $row['icon_id'], 'poster_ip' => (string) $row['poster_ip'], 'post_time' => (int) $row['post_time'], - 'post_approved' => 1, + 'post_visibility' => (int) $row['post_visibility'], 'post_reported' => 0, 'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_smilies' => (int) $row['enable_smilies'], @@ -1033,6 +1292,19 @@ function mcp_fork_topic($topic_ids) $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $new_post_id = $db->sql_nextid(); + switch ($row['post_visibility']) + { + case ITEM_APPROVED: + $total_posts++; + break; + case ITEM_UNAPPROVED: + $total_posts_unapproved++; + break; + case ITEM_DELETED: + $total_posts_softdeleted++; + break; + } + // Copy whether the topic is dotted markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']); @@ -1125,23 +1397,19 @@ function mcp_fork_topic($topic_ids) } // Sync new topics, parent forums and board stats + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET forum_posts_approved = forum_posts_approved + ' . $total_posts . ', + forum_posts_unapproved = forum_posts_unapproved + ' . $total_posts_unapproved . ', + forum_posts_softdeleted = forum_posts_softdeleted + ' . $total_posts_softdeleted . ', + forum_topics_approved = forum_topics_approved + ' . $total_topics . ', + forum_topics_unapproved = forum_topics_unapproved + ' . $total_topics_unapproved . ', + forum_topics_softdeleted = forum_topics_softdeleted + ' . $total_topics_softdeleted . ' + WHERE forum_id = ' . $to_forum_id; + $db->sql_query($sql); + sync('topic', 'topic_id', $new_topic_id_list); - - $sync_sql = array(); - - $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts; - $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list); - $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list); - - foreach ($sync_sql as $forum_id_key => $array) - { - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET ' . implode(', ', $array) . ' - WHERE forum_id = ' . $forum_id_key; - $db->sql_query($sql); - } - sync('forum', 'forum_id', $to_forum_id); + set_config_count('num_topics', sizeof($new_topic_id_list), true); set_config_count('num_posts', $total_posts, true); diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php index 520c964228..734fa96a78 100644 --- a/phpBB/includes/mcp/mcp_post.php +++ b/phpBB/includes/mcp/mcp_post.php @@ -174,6 +174,33 @@ function mcp_post_details($id, $mode, $action) } } + // Deleting information + if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user']) + { + // User having deleted the post also being the post author? + if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id']) + { + $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']); + } + else + { + $sql = 'SELECT user_id, username, user_colour + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $post_info['post_delete_user']; + $result = $db->sql_query($sql); + $user_delete_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $display_username = get_username_string('full', $post_info['post_delete_user'], $user_delete_row['username'], $user_delete_row['user_colour']); + } + + $user->add_lang('viewtopic'); + $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true)); + } + else + { + $l_deleted_by = ''; + } + $template->assign_vars(array( 'U_MCP_ACTION' => "$url&i=main&quickmod=1&mode=post_details", // Use this for mode paramaters 'U_POST_ACTION' => "$url&i=$id&mode=post_details", // Use this for action parameters @@ -185,10 +212,13 @@ function mcp_post_details($id, $mode, $action) 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false, - 'S_POST_UNAPPROVED' => (!$post_info['post_approved']) ? true : false, + 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED) ? true : false, + 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED) ? true : false, 'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false, 'S_USER_NOTES' => true, 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, + 'DELETED_MESSAGE' => $l_deleted_by, + 'DELETE_REASON' => $post_info['post_delete_reason'], 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '', 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp_chgposter&field=username&select_single=true'), @@ -205,6 +235,7 @@ function mcp_post_details($id, $mode, $action) 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '', ''), 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']), + 'DELETED_IMG' => $user->img('icon_topic_deleted', $user->lang['POST_DELETED']), 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']), 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']), @@ -415,7 +446,7 @@ function change_poster(&$post_info, $userdata) } // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway) - if ($post_info['post_postcount'] && $post_info['post_approved']) + if ($post_info['post_postcount'] && $post_info['post_visibility'] == ITEM_APPROVED) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = user_posts - 1 diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 24afa1f210..8a9390212f 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -25,14 +25,14 @@ class mcp_queue var $p_master; var $u_action; - function mcp_queue(&$p_master) + public function mcp_queue(&$p_master) { $this->p_master = &$p_master; } - function main($id, $mode) + public function main($id, $mode) { - global $auth, $db, $user, $template, $cache; + global $auth, $db, $user, $template, $cache, $request; global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -45,25 +45,99 @@ class mcp_queue switch ($action) { case 'approve': - case 'disapprove': + case 'restore': include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $post_id_list = request_var('post_id_list', array(0)); + $post_id_list = $request->variable('post_id_list', array(0)); + $topic_id_list = $request->variable('topic_id_list', array(0)); - if (!sizeof($post_id_list)) + if (!empty($post_id_list)) { - trigger_error('NO_POST_SELECTED'); + self::approve_posts($action, $post_id_list, 'queue', $mode); } - - if ($action == 'approve') + else if (!empty($topic_id_list)) { - approve_post($post_id_list, 'queue', $mode); + self::approve_topics($action, $topic_id_list, 'queue', $mode); } else { - disapprove_post($post_id_list, 'queue', $mode); + trigger_error('NO_POST_SELECTED'); + } + break; + + case 'delete': + $post_id_list = $request->variable('post_id_list', array(0)); + $topic_id_list = $request->variable('topic_id_list', array(0)); + + if (!empty($post_id_list)) + { + if (!function_exists('mcp_delete_post')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); + } + mcp_delete_post($post_id_list, false, '', $action); + } + else if (!empty($topic_id_list)) + { + if (!function_exists('mcp_delete_topic')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); + } + mcp_delete_topic($topic_id_list, false, '', $action); + } + else + { + trigger_error('NO_POST_SELECTED'); + } + break; + + case 'disapprove': + $post_id_list = $request->variable('post_id_list', array(0)); + $topic_id_list = $request->variable('topic_id_list', array(0)); + + if (!empty($topic_id_list) && $mode == 'deleted_topics') + { + if (!function_exists('mcp_delete_topics')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); + } + mcp_delete_topic($topic_id_list, false, '', 'disapprove'); + return; } + if (!class_exists('messenger')) + { + include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + } + + if (!empty($topic_id_list)) + { + $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : ITEM_UNAPPROVED; + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + WHERE post_visibility = ' . $post_visibility . ' + AND ' . $db->sql_in_set('topic_id', $topic_id_list); + $result = $db->sql_query($sql); + + $post_id_list = array(); + while ($row = $db->sql_fetchrow($result)) + { + $post_id_list[] = (int) $row['post_id']; + } + $db->sql_freeresult($result); + } + + if (!empty($post_id_list)) + { + self::disapprove_posts($post_id_list, 'queue', $mode); + } + else + { + trigger_error('NO_POST_SELECTED'); + } break; } @@ -111,8 +185,8 @@ class mcp_queue $template->assign_vars(array( 'S_TOPIC_REVIEW' => true, 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'], - 'TOPIC_TITLE' => $post_info['topic_title']) - ); + 'TOPIC_TITLE' => $post_info['topic_title'], + )); } $extensions = $attachments = $topic_tracking_info = array(); @@ -175,12 +249,39 @@ class mcp_queue foreach ($attachments as $attachment) { $template->assign_block_vars('attachment', array( - 'DISPLAY_ATTACHMENT' => $attachment) - ); + 'DISPLAY_ATTACHMENT' => $attachment, + )); } } } + // Deleting information + if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user']) + { + // User having deleted the post also being the post author? + if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id']) + { + $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']); + } + else + { + $sql = 'SELECT u.user_id, u.username, u.user_colour + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u + WHERE p.post_id = ' . $post_info['post_id'] . ' + AND p.post_delete_user = u.user_id'; + $result = $db->sql_query($sql); + $post_delete_userinfo = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $display_username = get_username_string('full', $post_info['post_delete_user'], $post_delete_userinfo['username'], $post_delete_userinfo['user_colour']); + } + + $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true)); + } + else + { + $l_deleted_by = ''; + } + $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']); $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']); @@ -189,9 +290,12 @@ class mcp_queue 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], - 'S_POST_UNAPPROVED' => !$post_info['post_approved'], + 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED), 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, + 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED), + 'DELETED_MESSAGE' => $l_deleted_by, + 'DELETE_REASON' => $post_info['post_delete_reason'], 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '', 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id), @@ -203,7 +307,8 @@ class mcp_queue 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), - 'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '", ''), + + 'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '', ''), 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '', ''), 'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '', ''), 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), @@ -230,9 +335,16 @@ class mcp_queue case 'unapproved_topics': case 'unapproved_posts': + case 'deleted_topics': + case 'deleted_posts': + $m_perm = 'm_approve'; + $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false; + $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false; + $visibility_const = (!$is_restore) ? ITEM_UNAPPROVED : ITEM_DELETED; + $user->add_lang(array('viewtopic', 'viewforum')); - $topic_id = request_var('t', 0); + $topic_id = $request->variable('t', 0); $forum_info = array(); if ($topic_id) @@ -248,7 +360,7 @@ class mcp_queue $forum_id = $topic_info['forum_id']; } - $forum_list_approve = get_forum_list('m_approve', false, true); + $forum_list_approve = get_forum_list($m_perm, false, true); $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs // Remove forums we cannot read @@ -274,16 +386,16 @@ class mcp_queue trigger_error('NOT_MODERATOR'); } - $sql = 'SELECT SUM(forum_topics) as sum_forum_topics + $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list); $result = $db->sql_query($sql); - $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics'); + $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics'); $db->sql_freeresult($result); } else { - $forum_info = get_forum_data(array($forum_id), 'm_approve'); + $forum_info = get_forum_data(array($forum_id), $m_perm); if (!sizeof($forum_info)) { @@ -305,21 +417,22 @@ class mcp_queue $sort_by_sql = $sort_order_sql = array(); mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); - $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total; + $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; $forum_names = array(); - if ($mode == 'unapproved_posts') + if (!$is_topics) { $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . ' WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . ' - AND p.post_approved = 0 + AND p.post_visibility = ' . $visibility_const . ' ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " AND t.topic_id = p.topic_id - AND t.topic_first_post_id <> p.post_id + AND (t.topic_visibility <> p.post_visibility + OR t.topic_delete_user = 0) $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); @@ -365,9 +478,10 @@ class mcp_queue else { $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour - FROM ' . TOPICS_TABLE . " t - WHERE " . $db->sql_in_set('forum_id', $forum_list) . " - AND topic_approved = 0 + FROM ' . TOPICS_TABLE . ' t + WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' + AND topic_visibility = ' . $visibility_const . " + AND topic_delete_user <> 0 $limit_time_sql ORDER BY $sort_order_sql"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); @@ -401,7 +515,7 @@ class mcp_queue { if (empty($row['post_username'])) { - $row['post_username'] = $user->lang['GUEST']; + $row['post_username'] = $row['username'] ?: $user->lang['GUEST']; } $template->assign_block_vars('postrow', array( @@ -416,6 +530,7 @@ class mcp_queue 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_ID' => $row['post_id'], + 'TOPIC_ID' => $row['topic_id'], 'FORUM_NAME' => $forum_names[$row['forum_id']], 'POST_SUBJECT' => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'TOPIC_TITLE' => $row['topic_title'], @@ -430,249 +545,631 @@ class mcp_queue // Now display the page $template->assign_vars(array( - 'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], - 'L_EXPLAIN' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'], - 'L_TITLE' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'], + 'L_DISPLAY_ITEMS' => (!$is_topics) ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], + 'L_EXPLAIN' => $user->lang['MCP_QUEUE_' . strtoupper($mode) . '_EXPLAIN'], + 'L_TITLE' => $user->lang['MCP_QUEUE_' . strtoupper($mode)], 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '', 'S_FORUM_OPTIONS' => $forum_options, 'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')), - 'S_TOPICS' => ($mode == 'unapproved_posts') ? false : true, + 'S_TOPICS' => $is_topics, + 'S_RESTORE' => $is_restore, 'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $total, $config['topics_per_page'], $start), 'TOPIC_ID' => $topic_id, - 'TOTAL' => $user->lang((($mode == 'unapproved_posts') ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total), + 'TOTAL' => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total), )); $this->tpl_name = 'mcp_queue'; break; } } -} -/** -* Approve Post/Topic -*/ -function approve_post($post_id_list, $id, $mode) -{ - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path; - global $request, $phpbb_container; - - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + /** + * Approve/Restore posts + * + * @param $action string Action we perform on the posts ('approve' or 'restore') + * @param $post_id_list array IDs of the posts to approve/restore + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return null + */ + static public function approve_posts($action, $post_id_list, $id, $mode) { - trigger_error('NOT_AUTHORISED'); - } + global $db, $template, $user, $config, $request, $phpbb_container; + global $phpEx, $phpbb_root_path; - $redirect = request_var('redirect', build_url(array('quickmod'))); - $success_msg = ''; - - $s_hidden_fields = build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'post_id_list' => $post_id_list, - 'action' => 'approve', - 'redirect' => $redirect) - ); - - $post_info = get_post_data($post_id_list, 'm_approve'); - - if (confirm_box(true)) - { - $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - - // If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1 - // If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1 - - $total_topics = $total_posts = 0; - $topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array(); - $user_posts_sql = $post_approved_list = array(); - - foreach ($post_info as $post_id => $post_data) + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { - if ($post_data['post_approved']) - { - $post_approved_list[] = $post_id; - continue; - } + trigger_error('NOT_AUTHORISED'); + } - $topic_id_list[$post_data['topic_id']] = 1; - $forum_id_list[$post_data['forum_id']] = 1; + $redirect = $request->variable('redirect', build_url(array('quickmod'))); + $success_msg = $post_url = ''; + $approve_log = array(); - // User post update (we do not care about topic or post, since user posts are strictly connected to posts) - // But we care about forums where post counts get not increased. ;) - if ($post_data['post_postcount']) - { - $user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1; - } + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'post_id_list' => $post_id_list, + 'action' => $action, + 'redirect' => $redirect, + )); - // Topic or Post. ;) - if ($post_data['topic_first_post_id'] == $post_id) + $post_info = get_post_data($post_id_list, 'm_approve'); + + if (confirm_box(true)) + { + $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])); + + $topic_info = array(); + + // Group the posts by topic_id + foreach ($post_info as $post_id => $post_data) { - $total_topics++; - $topic_approve_sql[] = $post_data['topic_id']; + if ($post_data['post_visibility'] == ITEM_APPROVED) + { + continue; + } + $topic_id = (int) $post_data['topic_id']; + + $topic_info[$topic_id]['posts'][] = (int) $post_id; + $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id']; + + // Refresh the first post, if the time or id is older then the current one + if ($post_id <= $post_data['topic_first_post_id'] || $post_data['post_time'] <= $post_data['topic_time']) + { + $topic_info[$topic_id]['first_post'] = true; + } + + // Refresh the last post, if the time or id is newer then the current one + if ($post_id >= $post_data['topic_last_post_id'] || $post_data['post_time'] >= $post_data['topic_last_post_time']) + { + $topic_info[$topic_id]['last_post'] = true; + } + + $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; $approve_log[] = array( - 'type' => 'topic', - 'post_subject' => $post_data['post_subject'], 'forum_id' => $post_data['forum_id'], 'topic_id' => $post_data['topic_id'], - ); - } - else - { - $approve_log[] = array( - 'type' => 'post', 'post_subject' => $post_data['post_subject'], - 'forum_id' => $post_data['forum_id'], - 'topic_id' => $post_data['topic_id'], ); } - $total_posts++; - - // Increment by topic_replies if we approve a topic... - // This works because we do not adjust the topic_replies when re-approving a topic after an edit. - if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies']) + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + foreach ($topic_info as $topic_id => $topic_data) { - $total_posts += $post_data['topic_replies']; + $phpbb_content_visibility->set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); } - $post_approve_sql[] = $post_id; - } - - $post_id_list = array_values(array_diff($post_id_list, $post_approved_list)); - for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++) - { - unset($post_info[$post_approved_list[$i]]); - } - - if (sizeof($topic_approve_sql)) - { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_approved = 1 - WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql); - $db->sql_query($sql); - } - - if (sizeof($post_approve_sql)) - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_approved = 1 - WHERE ' . $db->sql_in_set('post_id', $post_approve_sql); - $db->sql_query($sql); - } - - unset($topic_approve_sql, $post_approve_sql); - - foreach ($approve_log as $log_data) - { - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']); - } - - if (sizeof($user_posts_sql)) - { - // Try to minimize the query count by merging users with the same post count additions - $user_posts_update = array(); - - foreach ($user_posts_sql as $user_id => $user_posts) + if (sizeof($post_info) >= 1) { - $user_posts_update[$user_posts][] = $user_id; + $success_msg = (sizeof($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS'; } - foreach ($user_posts_update as $user_posts => $user_id_ary) + foreach ($approve_log as $log_data) { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_posts = user_posts + ' . $user_posts . ' - WHERE ' . $db->sql_in_set('user_id', $user_id_ary); - $db->sql_query($sql); + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_POST_' . strtoupper($action) . 'D', $log_data['post_subject']); } - } - if ($total_topics) - { - set_config_count('num_topics', $total_topics, true); - } - - if ($total_posts) - { - set_config_count('num_posts', $total_posts, true); - } - - sync('topic', 'topic_id', array_keys($topic_id_list), true); - sync('forum', 'forum_id', array_keys($forum_id_list), true, true); - unset($topic_id_list, $forum_id_list); - - // Send out normal user notifications - $email_sig = str_replace('
    ', "\n", "-- \n" . $config['board_email_sig']); - - $phpbb_notifications = $phpbb_container->get('notification_manager'); - - // Handle notifications - foreach ($post_info as $post_id => $post_data) - { - if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + // Only send out the mails, when the posts are being approved + if ($action == 'approve') { - $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + $phpbb_notifications = $phpbb_container->get('notification_manager'); - $phpbb_notifications->add_notifications(array( - 'quote', - 'topic', - ), $post_data); - - $phpbb_notifications->mark_notifications_read('quote', $post_data['post_id'], $user->data['user_id']); - $phpbb_notifications->mark_notifications_read('topic', $post_data['topic_id'], $user->data['user_id']); - - if ($notify_poster) + // Handle notifications + foreach ($post_info as $post_id => $post_data) { - $phpbb_notifications->add_notifications('approve_topic', $post_data); + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); + + $phpbb_notifications->add_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $post_data); + + $phpbb_notifications->mark_notifications_read(array( + 'quote', + 'bookmark', + 'post', + ), $post_data['post_id'], $user->data['user_id']); + + // Notify Poster? + if ($notify_poster) + { + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + + $phpbb_notifications->add_notifications('approve_post', $post_data); + } } } - else - { - $phpbb_notifications->delete_notifications('post_in_queue', $post_id); - - $phpbb_notifications->add_notifications(array( - 'quote', - 'bookmark', - 'post', - ), $post_data); - - $phpbb_notifications->mark_notifications_read(array( - 'quote', - 'bookmark', - 'post', - ),$post_data['post_id'], $user->data['user_id']); - - if ($notify_poster) - { - $phpbb_notifications->add_notifications('approve_post', $post_data); - } - } - } - - if (sizeof($post_id_list) == 1) - { - $post_data = $post_info[$post_id_list[0]]; - $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; - } - unset($post_info); - - if ($total_topics) - { - $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS'; } else { - $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS'; + $show_notify = false; + + if ($action == 'approve') + { + foreach ($post_info as $post_data) + { + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + else + { + $show_notify = true; + break; + } + } + } + + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => $show_notify, + 'S_' . strtoupper($action) => true, + )); + + confirm_box(false, strtoupper($action) . '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + } + + $redirect = $request->variable('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, $redirect); + + // If approving one post, also give links back to post... + $add_message = ''; + if (sizeof($post_info) == 1 && $post_url) + { + $add_message = '

    ' . sprintf($user->lang['RETURN_POST'], '', ''); + } + + $message = $user->lang[$success_msg] . '

    ' . sprintf($user->lang['RETURN_PAGE'], '', '') . $add_message; + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => true, + )); + } + + trigger_error($message); } } - else - { - $show_notify = false; - if ($config['email_enable'] || $config['jab_enable']) + /** + * Approve/Restore topics + * + * @param $action string Action we perform on the posts ('approve' or 'restore') + * @param $topic_id_list array IDs of the topics to approve/restore + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return null + */ + static public function approve_topics($action, $topic_id_list, $id, $mode) + { + global $db, $template, $user, $config; + global $phpEx, $phpbb_root_path, $request, $phpbb_container; + + if (!check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) { + trigger_error('NOT_AUTHORISED'); + } + + $redirect = $request->variable('redirect', build_url(array('quickmod'))); + $success_msg = $topic_url = ''; + $approve_log = array(); + + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'topic_id_list' => $topic_id_list, + 'action' => $action, + 'redirect' => $redirect, + )); + + $topic_info = get_topic_data($topic_id_list, 'm_approve'); + + if (confirm_box(true)) + { + $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; + + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + foreach ($topic_info as $topic_id => $topic_data) + { + $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); + + $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}"); + + $approve_log[] = array( + 'forum_id' => $topic_data['forum_id'], + 'topic_id' => $topic_data['topic_id'], + 'topic_title' => $topic_data['topic_title'], + ); + } + + if (sizeof($topic_info) >= 1) + { + $success_msg = (sizeof($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; + } + + foreach ($approve_log as $log_data) + { + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_TOPIC_' . strtoupper($action) . 'D', $log_data['topic_title']); + } + + // Only send out the mails, when the posts are being approved + if ($action == 'approve') + { + // Handle notifications + $phpbb_notifications = $phpbb_container->get('notification_manager'); + + foreach ($topic_info as $topic_id => $topic_data) + { + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + $phpbb_notifications->add_notifications(array( + 'quote', + 'topic', + ), $post_data); + + $phpbb_notifications->mark_notifications_read('quote', $post_data['post_id'], $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('topic', $post_data['topic_id'], $user->data['user_id']); + + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_topic', $post_data); + } + } + } + } + else + { + $show_notify = false; + + if ($action == 'approve') + { + foreach ($topic_info as $topic_data) + { + if ($topic_data['topic_poster'] == ANONYMOUS) + { + continue; + } + else + { + $show_notify = true; + break; + } + } + } + + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => $show_notify, + 'S_' . strtoupper($action) => true, + )); + + confirm_box(false, strtoupper($action) . '_TOPIC' . ((sizeof($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + } + + $redirect = $request->variable('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); + + if (!$success_msg) + { + redirect($redirect); + } + else + { + meta_refresh(3, $redirect); + + // If approving one topic, also give links back to topic... + $add_message = ''; + if (sizeof($topic_info) == 1 && $topic_url) + { + $add_message = '

    ' . sprintf($user->lang['RETURN_TOPIC'], '', ''); + } + + $message = $user->lang[$success_msg] . '

    ' . sprintf($user->lang['RETURN_PAGE'], '', '') . $add_message; + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => true, + )); + } + + trigger_error($message); + } + } + + /** + * Disapprove Post + * + * @param $post_id_list array IDs of the posts to disapprove/delete + * @param $id mixed Category of the current active module + * @param $mode string Active module + * @return null + */ + static public function disapprove_posts($post_id_list, $id, $mode) + { + global $db, $template, $user, $config, $phpbb_container; + global $phpEx, $phpbb_root_path, $request; + + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + { + trigger_error('NOT_AUTHORISED'); + } + + $redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); + $reason = $request->variable('reason', '', true); + $reason_id = $request->variable('reason_id', 0); + $success_msg = $additional_msg = ''; + + $s_hidden_fields = build_hidden_fields(array( + 'i' => $id, + 'mode' => $mode, + 'post_id_list' => $post_id_list, + 'action' => 'disapprove', + 'redirect' => $redirect, + )); + + $notify_poster = $request->is_set('notify_poster'); + $disapprove_reason = ''; + + if ($reason_id) + { + $sql = 'SELECT reason_title, reason_description + FROM ' . REPORTS_REASONS_TABLE . " + WHERE reason_id = $reason_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row || (!$reason && strtolower($row['reason_title']) == 'other')) + { + $additional_msg = $user->lang['NO_REASON_DISAPPROVAL']; + + $request->overwrite('confirm', null, phpbb_request_interface::POST); + $request->overwrite('confirm_key', null, phpbb_request_interface::POST); + $request->overwrite('confirm_key', null, phpbb_request_interface::REQUEST); + } + else + { + // If the reason is defined within the language file, we will use the localized version, else just use the database entry... + $disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : ''; + $disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; + + if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) + { + $disapprove_reason_lang = strtoupper($row['reason_title']); + } + } + } + + $post_info = get_post_data($post_id_list, 'm_approve'); + + $is_disapproving = false; + foreach ($post_info as $post_id => $post_data) + { + if ($post_data['post_visibility'] == ITEM_DELETED) + { + continue; + } + + $is_disapproving = true; + } + + if (confirm_box(true)) + { + $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); + $topic_posts_unapproved = $post_disapprove_list = $topic_information = array(); + + // Build a list of posts to be disapproved and get the related topics real replies count + foreach ($post_info as $post_id => $post_data) + { + $post_disapprove_list[$post_id] = $post_data['topic_id']; + if (!isset($topic_posts_unapproved[$post_data['topic_id']])) + { + $topic_information[$post_data['topic_id']] = $post_data; + $topic_posts_unapproved[$post_data['topic_id']] = 0; + } + $topic_posts_unapproved[$post_data['topic_id']]++; + } + + // Now we build the log array + foreach ($post_disapprove_list as $post_id => $topic_id) + { + // If the count of disapproved posts for the topic is equal + // to the number of unapproved posts in the topic, and there are no different + // posts, we disapprove the hole topic + if ($topic_information[$topic_id]['topic_posts_approved'] == 0 && + $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && + $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]) + { + // Don't write the log more than once for every topic + if (!isset($disapprove_log_topics[$topic_id])) + { + // Build disapproved topics log + $disapprove_log_topics[$topic_id] = array( + 'type' => 'topic', + 'post_subject' => $post_info[$post_id]['topic_title'], + 'forum_id' => $post_info[$post_id]['forum_id'], + 'topic_id' => 0, // useless to log a topic id, as it will be deleted + 'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'], + ); + } + } + else + { + // Build disapproved posts log + $disapprove_log_posts[] = array( + 'type' => 'post', + 'post_subject' => $post_info[$post_id]['post_subject'], + 'forum_id' => $post_info[$post_id]['forum_id'], + 'topic_id' => $post_info[$post_id]['topic_id'], + 'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'], + ); + + } + } + + // Get disapproved posts/topics counts separately + $num_disapproved_topics = sizeof($disapprove_log_topics); + $num_disapproved_posts = sizeof($disapprove_log_posts); + + // Build the whole log + $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts); + + // Unset unneeded arrays + unset($post_data, $disapprove_log_topics, $disapprove_log_posts); + + // Let's do the job - delete disapproved posts + if (sizeof($post_disapprove_list)) + { + if (!function_exists('delete_posts')) + { + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } + + // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts + // Note: function delete_posts triggers related forums/topics sync, + // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually + delete_posts('post_id', array_keys($post_disapprove_list)); + + foreach ($disapprove_log as $log_data) + { + if ($is_disapproving) + { + $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED'; + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $disapprove_reason); + } + else + { + $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST'; + add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $log_data['post_username']); + } + } + } + + $phpbb_notifications = $phpbb_container->get('notification_manager'); + + $lang_reasons = array(); + + foreach ($post_info as $post_id => $post_data) + { + $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 && + $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && + $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]; + + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); + + // Do we disapprove the whole topic? Remove potential notifications + if ($disapprove_all_posts_in_topic) + { + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + } + + // Notify Poster? + if ($notify_poster) + { + if ($post_data['poster_id'] == ANONYMOUS) + { + continue; + } + + $post_data['disapprove_reason'] = ''; + if (isset($disapprove_reason_lang)) + { + // Okay we need to get the reason from the posters language + if (!isset($lang_reasons[$post_data['user_lang']])) + { + // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity. + $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; + + // Only load up the language pack if the language is different to the current one + if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) + { + // Load up the language pack + $lang = array(); + @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx); + + // If we find the reason in this language pack use it + if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) + { + $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; + } + + unset($lang); // Free memory + } + } + + $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; + $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; + } + + + if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1) + { + // If there is only 1 post when disapproving the topic, + // we send the user a "disapprove topic" notification... + $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + } + else + { + // ... otherwise there are multiple unapproved posts and + // all of them are disapproved as posts. + $phpbb_notifications->add_notifications('disapprove_post', $post_data); + } + } + } + + unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang); + + + if ($num_disapproved_topics) + { + $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS'; + } + else + { + $success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS'; + } + + if ($is_disapproving) + { + $success_msg .= '_DISAPPROVED_SUCCESS'; + } + else + { + $success_msg .= '_DELETED_SUCCESS'; + } + } + else + { + if (!function_exists('display_reasons')) + { + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + } + + $show_notify = false; + foreach ($post_info as $post_data) { if ($post_data['poster_id'] == ANONYMOUS) @@ -685,326 +1182,56 @@ function approve_post($post_id_list, $id, $mode) break; } } - } - $template->assign_vars(array( - 'S_NOTIFY_POSTER' => $show_notify, - 'S_APPROVE' => true) - ); + $l_confirm_msg = 'DISAPPROVE_POST'; + $confirm_template = 'mcp_approve.html'; + if ($is_disapproving) + { + display_reasons($reason_id); + } + else + { + $user->add_lang('posting'); - confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); - } + $l_confirm_msg = 'DELETE_POST_PERMANENTLY'; + $confirm_template = 'confirm_delete_body.html'; + } + $l_confirm_msg .= ((sizeof($post_id_list) == 1) ? '' : 'S'); - $redirect = request_var('redirect', "index.$phpEx"); - $redirect = reapply_sid($redirect); - - if (!$success_msg) - { - redirect($redirect); - } - else - { - meta_refresh(3, $redirect); - - // If approving one post, also give links back to post... - $add_message = ''; - if (sizeof($post_id_list) == 1 && !empty($post_url)) - { - $add_message = '

    ' . sprintf($user->lang['RETURN_POST'], '', ''); - } - - $message = $user->lang[$success_msg] . '

    ' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; - - if ($request->is_ajax()) - { - $json_response = new phpbb_json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $message, - 'REFRESH_DATA' => null, - 'approved' => true + $template->assign_vars(array( + 'S_NOTIFY_POSTER' => $show_notify, + 'S_APPROVE' => false, + 'REASON' => ($is_disapproving) ? $reason : '', + 'ADDITIONAL_MSG' => $additional_msg, )); + + confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template); } - trigger_error($message); - } -} + $redirect = $request->variable('redirect', "index.$phpEx"); + $redirect = reapply_sid($redirect); -/** -* Disapprove Post/Topic -*/ -function disapprove_post($post_id_list, $id, $mode) -{ - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path; - global $request, $phpbb_container; - - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) - { - trigger_error('NOT_AUTHORISED'); - } - - $redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); - $reason = utf8_normalize_nfc(request_var('reason', '', true)); - $reason_id = request_var('reason_id', 0); - $success_msg = $additional_msg = ''; - - $s_hidden_fields = build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'post_id_list' => $post_id_list, - 'action' => 'disapprove', - 'redirect' => $redirect) - ); - - $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false; - $disapprove_reason = ''; - - if ($reason_id) - { - $sql = 'SELECT reason_title, reason_description - FROM ' . REPORTS_REASONS_TABLE . " - WHERE reason_id = $reason_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row || (!$reason && strtolower($row['reason_title']) == 'other')) + if (!$success_msg) { - $additional_msg = $user->lang['NO_REASON_DISAPPROVAL']; - - $request->overwrite('confirm', null, phpbb_request_interface::POST); - $request->overwrite('confirm_key', null, phpbb_request_interface::POST); - $request->overwrite('confirm_key', null, phpbb_request_interface::REQUEST); + redirect($redirect); } else { - // If the reason is defined within the language file, we will use the localized version, else just use the database entry... - $disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : ''; - $disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; + $message = $user->lang[$success_msg] . '

    ' . sprintf($user->lang['RETURN_PAGE'], '', ''); - if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) + if ($request->is_ajax()) { - $disapprove_reason_lang = strtoupper($row['reason_title']); + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'visible' => false, + )); } - $email_disapprove_reason = $disapprove_reason; + meta_refresh(3, $redirect); + trigger_error($message); } } - - $post_info = get_post_data($post_id_list, 'm_approve'); - - if (confirm_box(true)) - { - $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); - $topic_replies_real = $post_disapprove_list = array(); - - // Build a list of posts to be unapproved and get the related topics real replies count - foreach ($post_info as $post_id => $post_data) - { - $post_disapprove_list[$post_id] = $post_data['topic_id']; - if (!isset($topic_replies_real[$post_data['topic_id']])) - { - $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real']; - } - } - - // Now we build the log array - foreach ($post_disapprove_list as $post_id => $topic_id) - { - // If the count of disapproved posts for the topic is greater - // than topic's real replies count, the whole topic is disapproved/deleted - if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id]) - { - // Don't write the log more than once for every topic - if (!isset($disapprove_log_topics[$topic_id])) - { - // Build disapproved topics log - $disapprove_log_topics[$topic_id] = array( - 'type' => 'topic', - 'post_subject' => $post_info[$post_id]['topic_title'], - 'forum_id' => $post_info[$post_id]['forum_id'], - 'topic_id' => 0, // useless to log a topic id, as it will be deleted - ); - } - } - else - { - // Build disapproved posts log - $disapprove_log_posts[] = array( - 'type' => 'post', - 'post_subject' => $post_info[$post_id]['post_subject'], - 'forum_id' => $post_info[$post_id]['forum_id'], - 'topic_id' => $post_info[$post_id]['topic_id'], - ); - - } - } - - // Get disapproved posts/topics counts separately - $num_disapproved_topics = sizeof($disapprove_log_topics); - $num_disapproved_posts = sizeof($disapprove_log_posts); - - // Build the whole log - $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts); - - // Unset unneeded arrays - unset($post_data, $disapprove_log_topics, $disapprove_log_posts); - - // Let's do the job - delete disapproved posts - if (sizeof($post_disapprove_list)) - { - if (!function_exists('delete_posts')) - { - include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } - - // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts - // Note: function delete_posts triggers related forums/topics sync, - // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually - delete_posts('post_id', array_keys($post_disapprove_list)); - - foreach ($disapprove_log as $log_data) - { - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason); - } - } - - $phpbb_notifications = $phpbb_container->get('notification_manager'); - - foreach ($post_info as $post_id => $post_data) - { - if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) - { - $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); - } - else - { - $phpbb_notifications->delete_notifications('post_in_queue', $post_id); - } - } - - // Notify Poster? - if ($notify_poster) - { - $lang_reasons = array(); - - // Handle notifications - foreach ($post_info as $post_id => $post_data) - { - $post_data['disapprove_reason'] = ''; - if (isset($disapprove_reason_lang)) - { - // Okay we need to get the reason from the posters language - if (!isset($lang_reasons[$post_data['user_lang']])) - { - // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity. - $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; - - // Only load up the language pack if the language is different to the current one - if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) - { - // Load up the language pack - $lang = array(); - @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx); - - // If we find the reason in this language pack use it - if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) - { - $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; - } - - unset($lang); // Free memory - } - } - - $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; - $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; - } - - if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) - { - if ($notify_poster) - { - $phpbb_notifications->add_notifications('disapprove_topic', $post_data); - } - } - else - { - if ($notify_poster) - { - $phpbb_notifications->add_notifications('disapprove_post', $post_data); - } - } - } - - unset($lang_reasons); - } - unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); - - if ($num_disapproved_topics) - { - $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS'; - } - else - { - $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS'; - } - } - else - { - include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); - - display_reasons($reason_id); - - $show_notify = false; - - foreach ($post_info as $post_data) - { - if ($post_data['poster_id'] == ANONYMOUS) - { - continue; - } - else - { - $show_notify = true; - break; - } - } - - $template->assign_vars(array( - 'S_NOTIFY_POSTER' => $show_notify, - 'S_APPROVE' => false, - 'REASON' => $reason, - 'ADDITIONAL_MSG' => $additional_msg) - ); - - confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); - } - - $redirect = request_var('redirect', "index.$phpEx"); - $redirect = reapply_sid($redirect); - - if (!$success_msg) - { - redirect($redirect); - } - else - { - $message = $user->lang[$success_msg] . '

    ' . sprintf($user->lang['RETURN_PAGE'], "", ''); - - if ($request->is_ajax()) - { - $json_response = new phpbb_json_response; - $json_response->send(array( - 'MESSAGE_TITLE' => $user->lang['INFORMATION'], - 'MESSAGE_TEXT' => $message, - 'REFRESH_DATA' => null, - 'approved' => false - )); - } - - meta_refresh(3, $redirect); - trigger_error($message); - } } diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 0a600d7057..72400ce623 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -187,7 +187,7 @@ class mcp_reports 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], - 'S_POST_UNAPPROVED' => !$post_info['post_approved'], + 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == POST_UNAPPROVED), 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, @@ -292,11 +292,11 @@ class mcp_reports $global_id = $forum_list[0]; - $sql = 'SELECT SUM(forum_topics) as sum_forum_topics + $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_list); $result = $db->sql_query($sql); - $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics'); + $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics'); $db->sql_freeresult($result); } else @@ -328,7 +328,7 @@ class mcp_reports $sort_by_sql = $sort_order_sql = array(); mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); - $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total; + $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : ''; if ($mode == 'reports') diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index e3dd5a6b57..d0e4a2e057 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) function mcp_topic_view($id, $mode, $action) { global $phpEx, $phpbb_root_path, $config; - global $template, $db, $user, $auth, $cache; + global $template, $db, $user, $auth, $cache, $phpbb_container; $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url()); @@ -84,8 +84,8 @@ function mcp_topic_view($id, $mode, $action) $subject = $topic_info['topic_title']; } - // Approve posts? - if ($action == 'approve' && $auth->acl_get('m_approve', $topic_info['forum_id'])) + // Restore or pprove posts? + if (($action == 'restore' || $action == 'approve') && $auth->acl_get('m_approve', $topic_info['forum_id'])) { include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -98,7 +98,7 @@ function mcp_topic_view($id, $mode, $action) if (!$sort) { - approve_post($post_id_list, $id, $mode); + mcp_queue::approve_posts($action, $post_id_list, $id, $mode); } } @@ -112,17 +112,11 @@ function mcp_topic_view($id, $mode, $action) mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $topic_id, $where_sql); $limit_time_sql = ($sort_days) ? 'AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); if ($total == -1) { - if ($auth->acl_get('m_approve', $topic_info['forum_id'])) - { - $total = $topic_info['topic_replies_real'] + 1; - } - else - { - $total = $topic_info['topic_replies'] + 1; - } + $total = $phpbb_content_visibility->get_count('topic_posts', $topic_info, $topic_info['forum_id']); } $posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page']))); @@ -145,8 +139,8 @@ function mcp_topic_view($id, $mode, $action) $sql = 'SELECT u.username, u.username_clean, u.user_colour, p.* FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . ' - p.topic_id = ' . $topic_id . ' ' . - ((!$auth->acl_get('m_approve', $topic_info['forum_id'])) ? ' AND p.post_approved = 1 ' : '') . ' + p.topic_id = ' . $topic_id . ' + AND ' . $phpbb_content_visibility->get_visibility_sql('post', $topic_info['forum_id'], 'p.') . ' AND p.poster_id = u.user_id ' . $limit_time_sql . ' ORDER BY ' . $sort_order_sql; @@ -182,7 +176,7 @@ function mcp_topic_view($id, $mode, $action) $topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id); } - $has_unapproved_posts = false; + $has_unapproved_posts = $has_deleted_posts = false; // Grab extensions $extensions = $attachments = array(); @@ -227,11 +221,16 @@ function mcp_topic_view($id, $mode, $action) parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count); } - if (!$row['post_approved']) + if ($row['post_visibility'] == ITEM_UNAPPROVED) { $has_unapproved_posts = true; } + if ($row['post_visibility'] == ITEM_DELETED) + { + $has_deleted_posts = true; + } + $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false; $template->assign_block_vars('postrow', array( @@ -249,7 +248,8 @@ function mcp_topic_view($id, $mode, $action) 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])), - 'S_POST_UNAPPROVED' => (!$row['post_approved'] && $auth->acl_get('m_approve', $topic_info['forum_id'])), + 'S_POST_UNAPPROVED' => ($row['post_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $topic_info['forum_id'])), + 'S_POST_DELETED' => ($row['post_visibility'] == ITEM_DELETED && $auth->acl_get('m_approve', $topic_info['forum_id'])), 'S_CHECKED' => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false, 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, @@ -325,6 +325,7 @@ function mcp_topic_view($id, $mode, $action) 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'), + 'DELETED_IMG' => $user->img('icon_topic_deleted', 'POST_DELETED_RESTORE'), 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'), 'S_MCP_ACTION' => "$url&i=$id&mode=$mode&action=$action&start=$start", @@ -333,6 +334,7 @@ function mcp_topic_view($id, $mode, $action) 'S_CAN_MERGE' => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false, 'S_CAN_DELETE' => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false, 'S_CAN_APPROVE' => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false, + 'S_CAN_RESTORE' => ($has_deleted_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false, 'S_CAN_LOCK' => ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false, 'S_CAN_REPORT' => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? true : false, 'S_CAN_SYNC' => $auth->acl_get('m_', $topic_info['forum_id']), @@ -448,7 +450,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) if ($sort_order_sql[0] == 'u') { - $sql = 'SELECT p.post_id, p.forum_id, p.post_approved + $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u WHERE p.topic_id = $topic_id AND p.poster_id = u.user_id @@ -457,7 +459,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) } else { - $sql = 'SELECT p.post_id, p.forum_id, p.post_approved + $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility FROM ' . POSTS_TABLE . " p WHERE p.topic_id = $topic_id $limit_time_sql @@ -470,7 +472,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) while ($row = $db->sql_fetchrow($result)) { // If split from selected post (split_beyond), we split the unapproved items too. - if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) + if ($row['post_visibility'] == ITEM_UNAPPROVED && !$auth->acl_get('m_approve', $row['forum_id'])) { // continue; } @@ -497,10 +499,10 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) $icon_id = request_var('icon', 0); $sql_ary = array( - 'forum_id' => $to_forum_id, - 'topic_title' => $subject, - 'icon_id' => $icon_id, - 'topic_approved'=> 1 + 'forum_id' => $to_forum_id, + 'topic_title' => $subject, + 'icon_id' => $icon_id, + 'topic_visibility' => 1 ); $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php deleted file mode 100644 index 76cb3011df..0000000000 --- a/phpBB/includes/template/compile.php +++ /dev/null @@ -1,166 +0,0 @@ -filter_params = $this->default_filter_params = array( - 'allow_php' => $allow_php, - 'style_names' => $style_names, - 'locator' => $locator, - 'phpbb_root_path' => $phpbb_root_path, - 'extension_manager' => $extension_manager, - 'user' => $user, - 'template_compile' => $this, - 'cleanup' => true, - ); - } - - /** - * Set filter parameters - * - * @param array $params Array of parameters (will be merged onto $this->filter_params) - */ - public function set_filter_params($params) - { - $this->filter_params = array_merge( - $this->filter_params, - $params - ); - } - - /** - * Reset filter parameters to their default settings - */ - public function reset_filter_params() - { - $this->filter_params = $this->default_filter_params; - } - - /** - * Compiles template in $source_file and writes compiled template to - * cache directory - * - * @param string $handle Template handle to compile - * @param string $source_file Source template file - * @return bool Return true on success otherwise false - */ - public function compile_file_to_file($source_file, $compiled_file) - { - $lock = new phpbb_lock_flock($compiled_file); - $lock->acquire(); - - $source_handle = @fopen($source_file, 'rb'); - $destination_handle = @fopen($compiled_file, 'wb'); - - if (!$source_handle || !$destination_handle) - { - return false; - } - - $this->compile_stream_to_stream($source_handle, $destination_handle); - - @fclose($source_handle); - @fclose($destination_handle); - - phpbb_chmod($compiled_file, CHMOD_READ | CHMOD_WRITE); - - $lock->release(); - - clearstatcache(); - - return true; - } - - /** - * Compiles a template located at $source_file. - * - * Returns PHP source suitable for eval(). - * - * @param string $source_file Source template file - * @return string|bool Return compiled code on successful compilation otherwise false - */ - public function compile_file($source_file) - { - $source_handle = @fopen($source_file, 'rb'); - $destination_handle = @fopen('php://temp' ,'r+b'); - - if (!$source_handle || !$destination_handle) - { - return false; - } - - $this->compile_stream_to_stream($source_handle, $destination_handle); - - @fclose($source_handle); - - rewind($destination_handle); - $contents = stream_get_contents($destination_handle); - @fclose($dest_handle); - - return $contents; - } - - /** - * Compiles contents of $source_stream into $dest_stream. - * - * A stream filter is appended to $source_stream as part of the - * process. - * - * @param resource $source_stream Source stream - * @param resource $dest_stream Destination stream - * @return null - */ - private function compile_stream_to_stream($source_stream, $dest_stream) - { - stream_filter_append($source_stream, 'phpbb_template', null, $this->filter_params); - stream_copy_to_stream($source_stream, $dest_stream); - } -} diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php deleted file mode 100644 index f2bd442010..0000000000 --- a/phpBB/includes/template/filter.php +++ /dev/null @@ -1,1260 +0,0 @@ -'; - - const REGEX_TOKENS = '~|{((?:[a-z_][a-z_0-9]+\.)*\\$?[A-Z][A-Z_0-9]+)}~'; - - /** - * @var array - */ - private $block_names = array(); - - /** - * @var array - */ - private $block_else_level = array(); - - /** - * @var string - */ - private $chunk; - - /** - * @var bool - */ - private $in_php; - - /** - * Whether inline PHP code, and tags - * are allowed. If this is false all PHP code will be silently - * removed from the template during compilation. - * - * @var bool - */ - private $allow_php; - - /** - * Whether cleanup will be performed on resulting code, see compile() - * (Preserve whitespace) - * - * @var bool - */ - private $cleanup = true; - - /** - * Resource locator. - * - * @var phpbb_template_locator - */ - private $locator; - - /** - * @var string phpBB root path - */ - private $phpbb_root_path; - - /** - * Name of the style that the template being compiled and/or rendered - * belongs to, and its parents, in inheritance tree order. - * - * Used to invoke style-specific template events. - * - * @var array - */ - private $style_names; - - /** - * Extension manager. - * - * @var phpbb_extension_manager - */ - private $extension_manager; - - /** - * Current user - * - * @var phpbb_user - */ - private $user; - - /** - * Template compiler. - * - * @var phpbb_template_compile - */ - private $template_compile; - - /** - * Stream filter - * - * Is invoked for evey chunk of the stream, allowing us - * to work on a chunk at a time, which saves memory. - */ - public function filter($in, $out, &$consumed, $closing) - { - $written = false; - $first = false; - - while ($bucket = stream_bucket_make_writeable($in)) - { - $consumed += $bucket->datalen; - - $data = $this->chunk . $bucket->data; - $last_nl = strrpos($data, "\n"); - $this->chunk = substr($data, $last_nl); - $data = substr($data, 0, $last_nl); - - if (!strlen($data)) - { - continue; - } - - $written = true; - - $data = $this->compile($data); - if (!$first) - { - $data = $this->prepend_preamble($data); - $first = false; - } - $bucket->data = $data; - $bucket->datalen = strlen($bucket->data); - stream_bucket_append($out, $bucket); - } - - if ($closing && strlen($this->chunk)) - { - $written = true; - $bucket = stream_bucket_new($this->stream, $this->compile($this->chunk)); - stream_bucket_append($out, $bucket); - } - - return $written ? PSFS_PASS_ON : PSFS_FEED_ME; - } - - /** - * Initializer, called on creation. - * - * Get the allow_php option, style_names, root directory and locator from params, - * which are passed to stream_filter_append. - * - * @return boolean Returns true - */ - public function onCreate() - { - $this->chunk = ''; - $this->in_php = false; - $this->allow_php = $this->params['allow_php']; - $this->locator = $this->params['locator']; - $this->phpbb_root_path = $this->params['phpbb_root_path']; - $this->style_names = $this->params['style_names']; - $this->extension_manager = $this->params['extension_manager']; - $this->cleanup = $this->params['cleanup']; - if (isset($this->params['user'])) - { - $this->user = $this->params['user']; - } - $this->template_compile = $this->params['template_compile']; - return true; - } - - /** - * Compiles a chunk of template. - * - * The chunk must comprise of one or more complete lines from the source - * template. - * - * @param string $data Chunk of source template to compile - * @return string Compiled PHP/HTML code - */ - private function compile($data) - { - $block_start_in_php = $this->in_php; - - $data = preg_replace('#<(?:[\\?%]|script)#s', '', $data); - $data = preg_replace_callback(self::REGEX_TOKENS, array($this, 'replace'), $data); - - // Remove php - if (!$this->allow_php) - { - if ($block_start_in_php - && $this->in_php - && strpos($data, '') === false - && strpos($data, '') === false) - { - // This is just php code - return ''; - } - $data = preg_replace('~^.*?~', '', $data); - $data = preg_replace('~.*?~', '', $data); - $data = preg_replace('~.*?$~', '', $data); - } - - if ($this->cleanup) - { - /* - - Preserve whitespace. - PHP removes a newline after the closing tag (if it's there). - This is by design: - - http://www.php.net/manual/en/language.basic-syntax.phpmode.php - http://www.php.net/manual/en/language.basic-syntax.instruction-separation.php - - - Consider the following template: - - - some content - - - If we were to simply preserve all whitespace, we could simply - replace all "?>" tags with "?>\n". - Doing that, would add additional newlines to the compiled - template in place of the IF and ENDIF statements. These - newlines are unwanted (and one is conditional). The IF and - ENDIF are usually on their own line for ease of reading. - - This replacement preserves newlines only for statements that - are not the only statement on a line. It will NOT preserve - newlines at the end of statements in the above example. - It will preserve newlines in situations like: - - inline content - - */ - - $data = preg_replace('~(?)$~m', "$1\n", $data); - $data = str_replace('/**/?>', "?>\n", $data); - $data = str_replace('?>' . $data); - return $data; - } - - /** - * Callback for replacing matched tokens with compiled template code. - * - * Compiled template code is an HTML stream with embedded PHP. - * - * @param array $matches Regular expression matches - * @return string compiled template code - */ - private function replace($matches) - { - if ($this->in_php && $matches[1] != 'ENDPHP') - { - return ''; - } - - if (isset($matches[3])) - { - return $this->compile_var_tags($matches[0]); - } - - switch ($matches[1]) - { - case 'BEGIN': - $this->block_else_level[] = false; - return 'compile_tag_block($matches[2]) . ' ?>'; - break; - - case 'BEGINELSE': - $this->block_else_level[sizeof($this->block_else_level) - 1] = true; - return ''; - break; - - case 'END': - array_pop($this->block_names); - return 'block_else_level)) ? '}' : '}}') . ' ?>'; - break; - - case 'IF': - return 'compile_tag_if($matches[2], false) . ' ?>'; - break; - - case 'ELSE': - return ''; - break; - - case 'ELSEIF': - return 'compile_tag_if($matches[2], true) . ' ?>'; - break; - - case 'ENDIF': - return ''; - break; - - case 'DEFINE': - return 'compile_tag_define($matches[2], true) . ' ?>'; - break; - - case 'UNDEFINE': - return 'compile_tag_define($matches[2], false) . ' ?>'; - break; - - case 'ENDDEFINE': - return 'compile_tag_enddefine() . ' ?>'; - break; - - case 'INCLUDE': - return 'compile_tag_include($matches[2]) . ' ?>'; - break; - - case 'INCLUDEPHP': - return ($this->allow_php) ? 'compile_tag_include_php($matches[2]) . ' ?>' : ''; - break; - - case 'INCLUDEJS': - return 'compile_tag_include_js($matches[2]) . ' ?>'; - break; - - case 'PHP': - if ($this->allow_php) - { - $this->in_php = true; - return ''; - break; - - case 'ENDPHP': - if ($this->allow_php) - { - $this->in_php = false; - return ' ?>'; - } - return ''; - break; - - case 'EVENT': - return 'compile_tag_event($matches[2]) . '?>'; - break; - - default: - return $matches[0]; - break; - - } - return ''; - } - - /** - * Convert template variables into PHP varrefs - * - * @param string $text_blocks Variable reference in source template - * @param bool $is_expr Returns whether the source was an expression type variable (i.e. S_FIRST_ROW) - * @return string PHP variable name - */ - private function get_varref($text_blocks, &$is_expr) - { - // change template varrefs into PHP varrefs - $varrefs = array(); - - // This one will handle varrefs WITH namespaces - preg_match_all('#\{((?:' . self::REGEX_NS . '\.)+)(\$)?(' . self::REGEX_VAR . ')\}#', $text_blocks, $varrefs, PREG_SET_ORDER); - - foreach ($varrefs as $var_val) - { - $namespace = $var_val[1]; - $varname = $var_val[3]; - $new = $this->generate_block_varref($namespace, $varname, $is_expr, $var_val[2]); - - $text_blocks = str_replace($var_val[0], $new, $text_blocks); - } - - // Language variables cannot be reduced to a single varref, so they must be skipped - // These two replacements would break language variables, so we can only run them on non-language types - if (strpos($text_blocks, '{L_') === false && strpos($text_blocks, '{LA_') === false) - { - // This will handle the remaining root-level varrefs - $text_blocks = preg_replace('#\{(' . self::REGEX_VAR . ')\}#', "\$_rootref['\\1']", $text_blocks); - $text_blocks = preg_replace('#\{\$(' . self::REGEX_VAR . ')\}#', "\$_tpldata['DEFINE']['.']['\\1']", $text_blocks); - } - - return $text_blocks; - } - - /** - * Parse paths of the form {FOO}/a/{BAR}/b - * - * Note: this method assumes at least one variable in the path, this should - * be checked before this method is called. - * - * @param string $path The path to parse - * @param string $include_type The type of template function to call - * @return string An appropriately formatted string to include in the - * template or an empty string if an expression like S_FIRST_ROW was - * incorrectly used - */ - private function parse_dynamic_path($path, $include_type) - { - $matches = array(); - $replace = array(); - $is_expr = true; - - preg_match_all('#\{((?:' . self::REGEX_NS . '\.)*)(\$)?(' . self::REGEX_VAR . ')\}#', $path, $matches); - foreach ($matches[0] as $var_str) - { - $tmp_is_expr = false; - $var = $this->get_varref($var_str, $tmp_is_expr); - $is_expr = $is_expr && $tmp_is_expr; - $replace[] = "' . $var . '"; - } - - if (!$is_expr) - { - return " \$_template->$include_type('" . str_replace($matches[0], $replace, $path) . "', true);"; - } - else - { - return ''; - } - } - - /** - * Compile variables - * - * @param string $text_blocks Variable reference in source template - * @return string compiled template code - */ - private function compile_var_tags(&$text_blocks) - { - $text_blocks = $this->get_varref($text_blocks, $is_expr); - $lang_replaced = $this->compile_language_tags($text_blocks); - - if(!$lang_replaced) - { - $text_blocks = ''; - } - - return $text_blocks; - } - - /** - * Handles special language tags L_ and LA_ - * - * @param string $text_blocks Variable reference in source template - * @return bool Whether a replacement occurred or not - */ - private function compile_language_tags(&$text_blocks) - { - $replacements = 0; - - // transform vars prefixed by L_ into their language variable pendant if nothing is set within the tpldata array - if (strpos($text_blocks, '{L_') !== false) - { - $text_blocks = preg_replace('#\{L_(' . self::REGEX_VAR_SUFFIX . ')\}#', "", $text_blocks, -1, $replacements); - return (bool) $replacements; - } - - // Handle addslashed language variables prefixed with LA_ - // If a template variable already exist, it will be used in favor of it... - if (strpos($text_blocks, '{LA_') !== false) - { - $text_blocks = preg_replace('#\{LA_(' . self::REGEX_VAR_SUFFIX . '+)\}#', "", $text_blocks, -1, $replacements); - return (bool) $replacements; - } - - return false; - } - - /** - * Compile blocks - * - * @param string $tag_args Block contents in source template - * @return string compiled template code - */ - private function compile_tag_block($tag_args) - { - $no_nesting = false; - - // Is the designer wanting to call another loop in a loop? - // - // - // - // - // 'loop2' is actually on the same nesting level as 'loop' you assign - // variables to it with template->assign_block_vars('loop2', array(...)) - if (strpos($tag_args, '!') === 0) - { - // Count the number if ! occurrences (not allowed in vars) - $no_nesting = substr_count($tag_args, '!'); - $tag_args = substr($tag_args, $no_nesting); - } - - // Allow for control of looping (indexes start from zero): - // foo(2) : Will start the loop on the 3rd entry - // foo(-2) : Will start the loop two entries from the end - // foo(3,4) : Will start the loop on the fourth entry and end it on the fifth - // foo(3,-4) : Will start the loop on the fourth entry and end it four from last - $match = array(); - - if (preg_match('#^([^()]*)\(([\-\d]+)(?:,([\-\d]+))?\)$#', $tag_args, $match)) - { - $tag_args = $match[1]; - - if ($match[2] < 0) - { - $loop_start = '($_' . $tag_args . '_count ' . $match[2] . ' < 0 ? 0 : $_' . $tag_args . '_count ' . $match[2] . ')'; - } - else - { - $loop_start = '($_' . $tag_args . '_count < ' . $match[2] . ' ? $_' . $tag_args . '_count : ' . $match[2] . ')'; - } - - if (!isset($match[3]) || strlen($match[3]) < 1 || $match[3] == -1) - { - $loop_end = '$_' . $tag_args . '_count'; - } - else if ($match[3] >= 0) - { - $loop_end = '(' . ($match[3] + 1) . ' > $_' . $tag_args . '_count ? $_' . $tag_args . '_count : ' . ($match[3] + 1) . ')'; - } - else //if ($match[3] < -1) - { - $loop_end = '$_' . $tag_args . '_count' . ($match[3] + 1); - } - } - else - { - $loop_start = 0; - $loop_end = '$_' . $tag_args . '_count'; - } - - $tag_template_php = ''; - array_push($this->block_names, $tag_args); - - if ($no_nesting !== false) - { - // We need to implode $no_nesting times from the end... - $block = array_slice($this->block_names, -$no_nesting); - } - else - { - $block = $this->block_names; - } - - if (sizeof($block) < 2) - { - // Block is not nested. - $tag_template_php = '$_' . $tag_args . "_count = (isset(\$_tpldata['$tag_args'])) ? sizeof(\$_tpldata['$tag_args']) : 0;"; - $varref = "\$_tpldata['$tag_args']"; - } - else - { - // This block is nested. - // Generate a namespace string for this block. - $namespace = implode('.', $block); - - // Get a reference to the data array for this block that depends on the - // current indices of all parent blocks. - $varref = $this->generate_block_data_ref($namespace, false); - - // Create the for loop code to iterate over this block. - $tag_template_php = '$_' . $tag_args . '_count = (isset(' . $varref . ')) ? sizeof(' . $varref . ') : 0;'; - } - - $tag_template_php .= 'if ($_' . $tag_args . '_count) {'; - - /** - * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory - * - * if (!$offset) - * { - * $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){'; - * } - * - */ - - $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){'; - $tag_template_php .= '$_' . $tag_args . '_val = &' . $varref . '[$_' . $tag_args . '_i];'; - - return $tag_template_php; - } - - /** - * Compile a general expression - much of this is from Smarty with - * some adaptions for our block level methods - * - * @param string $tag_args Expression (tag arguments) in source template - * @return string compiled template code - */ - private function compile_expression($tag_args) - { - $match = array(); - preg_match_all('/(?: - "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" | - \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' | - [(),] | - [^\s(),]+)/x', $tag_args, $match); - - $tokens = $match[0]; - $is_arg_stack = array(); - - for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) - { - $token = &$tokens[$i]; - - switch ($token) - { - case '!==': - case '===': - case '<<': - case '>>': - case '|': - case '^': - case '&': - case '~': - case ')': - case ',': - case '+': - case '-': - case '*': - case '/': - case '@': - break; - - case '==': - case 'eq': - $token = '=='; - break; - - case '!=': - case '<>': - case 'ne': - case 'neq': - $token = '!='; - break; - - case '<': - case 'lt': - $token = '<'; - break; - - case '<=': - case 'le': - case 'lte': - $token = '<='; - break; - - case '>': - case 'gt': - $token = '>'; - break; - - case '>=': - case 'ge': - case 'gte': - $token = '>='; - break; - - case '&&': - case 'and': - $token = '&&'; - break; - - case '||': - case 'or': - $token = '||'; - break; - - case '!': - case 'not': - $token = '!'; - break; - - case '%': - case 'mod': - $token = '%'; - break; - - case '(': - array_push($is_arg_stack, $i); - break; - - case 'is': - $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1; - $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); - - $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); - - array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens); - - $i = $is_arg_start; - - // no break - - default: - $varrefs = array(); - if (preg_match('#^((?:' . self::REGEX_NS . '\.)+)?(\$)?(?=[A-Z])([A-Z0-9\-_]+)#s', $token, $varrefs)) - { - if (!empty($varrefs[1])) - { - $namespace = substr($varrefs[1], 0, -1); - $dot_pos = strrchr($namespace, '.'); - if ($dot_pos !== false) - { - $namespace = substr($dot_pos, 1); - } - - // S_ROW_COUNT is deceptive, it returns the current row number not the number of rows - // hence S_ROW_COUNT is deprecated in favour of S_ROW_NUM - switch ($varrefs[3]) - { - case 'S_ROW_NUM': - case 'S_ROW_COUNT': - $token = "\$_${namespace}_i"; - break; - - case 'S_NUM_ROWS': - $token = "\$_${namespace}_count"; - break; - - case 'S_FIRST_ROW': - $token = "(\$_${namespace}_i == 0)"; - break; - - case 'S_LAST_ROW': - $token = "(\$_${namespace}_i == \$_${namespace}_count - 1)"; - break; - - case 'S_BLOCK_NAME': - $token = "'$namespace'"; - break; - - default: - $token = $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']'; - $token = '(isset(' . $token . ') ? ' . $token . ' : null)'; - break; - } - } - else - { - $token = ($varrefs[2]) ? '$_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[3] . '\']' : '$_rootref[\'' . $varrefs[3] . '\']'; - $token = '(isset(' . $token . ') ? ' . $token . ' : null)'; - } - - } - else if (preg_match('#^\.((?:' . self::REGEX_NS . '\.?)+)$#s', $token, $varrefs)) - { - // Allow checking if loops are set with .loopname - // It is also possible to check the loop count by doing for example - $blocks = explode('.', $varrefs[1]); - - // If the block is nested, we have a reference that we can grab. - // If the block is not nested, we just go and grab the block from _tpldata - if (sizeof($blocks) > 1) - { - $block = array_pop($blocks); - $namespace = implode('.', $blocks); - $varref = $this->generate_block_data_ref($namespace, true); - - // Add the block reference for the last child. - $varref .= "['" . $block . "']"; - } - else - { - $varref = '$_tpldata'; - - // Add the block reference for the last child. - $varref .= "['" . $blocks[0] . "']"; - } - $token = "(isset($varref) ? sizeof($varref) : 0)"; - } - - break; - } - } - - return $tokens; - } - - /** - * Compile IF tags - * - * @param string $tag_args Expression given with IF in source template - * @param bool $elseif True if compiling an IF tag, false if compiling an ELSEIF tag - * @return string compiled template code - */ - private function compile_tag_if($tag_args, $elseif) - { - $tokens = $this->compile_expression($tag_args); - - $tpl = ($elseif) ? '} else if (' : 'if ('; - - $tpl .= implode(' ', $tokens); - $tpl .= ') { '; - - return $tpl; - } - - /** - * Compile DEFINE tags - * - * @param string $tag_args Expression given with DEFINE in source template - * @param bool $op True if compiling a DEFINE tag, false if compiling an UNDEFINE tag - * @return string compiled template code - */ - private function compile_tag_define($tag_args, $op) - { - $match = array(); - preg_match('#^((?:' . self::REGEX_NS . '\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (.*?))?$#', $tag_args, $match); - - if (!empty($match[2]) && !isset($match[3]) && $op) - { - // DEFINE tag with ENDDEFINE - $array = "\$_tpldata['DEFINE']['.vars']"; - $code = 'ob_start(); '; - $code .= "if (!isset($array)) { $array = array(); } "; - $code .= "{$array}[] = '{$match[2]}'"; - return $code; - } - - if (empty($match[2]) || (!isset($match[3]) && $op)) - { - return ''; - } - - if (!$op) - { - return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ');'; - } - - /* - * Define tags that contain template variables (enclosed in curly brackets) - * need to be treated differently. - */ - if (substr($match[3], 1, 1) == '{' && substr($match[3], -2, 1) == '}') - { - $parsed_statement = implode(' ', $this->compile_expression(substr($match[3], 2, -2))); - } - else - { - $parsed_statement = implode(' ', $this->compile_expression($match[3])); - } - - return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $parsed_statement . ';'; - } - - /** - * Compile ENDDEFINE tag - * - * @return string compiled template code - */ - private function compile_tag_enddefine() - { - $array = "\$_tpldata['DEFINE']['.vars']"; - $code = "if (!isset($array) || !sizeof($array)) { trigger_error('ENDDEFINE tag without DEFINE in ' . basename(__FILE__), E_USER_ERROR); }"; - $code .= "\$define_var = array_pop($array); "; - $code .= "\$_tpldata['DEFINE']['.'][\$define_var] = ob_get_clean();"; - return $code; - } - - /** - * Compile INCLUDE tag - * - * @param string $tag_args Expression given with INCLUDE in source template - * @return string compiled template code - */ - private function compile_tag_include($tag_args) - { - // Process dynamic includes - if (strpos($tag_args, '{') !== false) - { - return $this->parse_dynamic_path($tag_args, '_tpl_include'); - } - - return "\$_template->_tpl_include('$tag_args');"; - } - - /** - * Compile INCLUDE_PHP tag - * - * @param string $tag_args Expression given with INCLUDEPHP in source template - * @return string compiled template code - */ - private function compile_tag_include_php($tag_args) - { - if (strpos($tag_args, '{') !== false) - { - return $this->parse_dynamic_path($tag_args, '_php_include'); - } - - return "\$_template->_php_include('$tag_args');"; - } - - /** - * Compile EVENT tag. - * - * $tag_args should be a single string identifying the event. - * The event name can contain letters, numbers and underscores only. - * If an invalid event name is specified, an E_USER_ERROR will be - * triggered. - * - * Event tags are only functional when the template engine has - * an instance of the extension manager. Extension manager would - * be called upon to find all extensions listening for the specified - * event, and to obtain additional template fragments. All such - * template fragments will be compiled and included in the generated - * compiled template code for the current template being compiled. - * - * The above means that whenever an extension is enabled or disabled, - * template cache should be cleared in order to update the compiled - * template code for the active set of template event listeners. - * - * This also means that extensions cannot return different template - * fragments at different times. Once templates are compiled, changing - * such template fragments would have no effect. - * - * @param string $tag_args EVENT tag arguments, as a string - for EVENT this is the event name - * @return string compiled template code - */ - private function compile_tag_event($tag_args) - { - if (!preg_match('/^\w+$/', $tag_args)) - { - // The event location is improperly formatted, - if ($this->user) - { - trigger_error($this->user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR); - } - else - { - trigger_error(sprintf('The specified template event location [%s] is improperly formatted.', $tag_args), E_USER_ERROR); - } - } - $location = $tag_args; - - if ($this->extension_manager) - { - $finder = $this->extension_manager->get_finder(); - - $files = $finder - ->extension_prefix($location) - ->extension_suffix('.html') - ->extension_directory("/styles/all/template") - ->get_files(); - - foreach ($this->style_names as $style_name) - { - $more_files = $finder - ->extension_prefix($location) - ->extension_suffix('.html') - ->extension_directory("/styles/" . $style_name . "/template") - ->get_files(); - if (!empty($more_files)) - { - $files = array_merge($files, $more_files); - break; - } - } - - $all_compiled = ''; - foreach ($files as $file) - { - $this->template_compile->set_filter_params(array( - 'cleanup' => false, - )); - - $compiled = $this->template_compile->compile_file($file); - - $this->template_compile->reset_filter_params(); - - if ($compiled === false) - { - if ($this->user) - { - trigger_error($this->user->lang('ERR_TEMPLATE_COMPILATION', phpbb_filter_root_path($file)), E_USER_ERROR); - } - else - { - trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); - } - } - - $all_compiled .= $compiled; - } - // Need spaces inside php tags as php cannot grok - // < ?php? > sans the spaces - return ' ?' . '>' . $all_compiled . 'parse_dynamic_path($tag_args, '_js_include'); - } - - // Locate file - $filename = $this->locator->get_first_file_location(array($tag_args), false, true); - - if ($filename === false) - { - // File does not exist, find it during run time - return ' $_template->_js_include(\'' . addslashes($tag_args) . '\', true); '; - } - - if (substr($filename, 0, strlen($this->phpbb_root_path)) != $this->phpbb_root_path) - { - // Absolute path, include as is - return ' $_template->_js_include(\'' . addslashes($filename) . '\', false, false); '; - } - - // Relative path, remove root path from it - $filename = substr($filename, strlen($this->phpbb_root_path)); - return ' $_template->_js_include(\'' . addslashes($filename) . '\', false, true); '; - } - - /** - * Generates a reference to the given variable inside the given (possibly nested) - * block namespace. This is a string of the form: - * ' . $_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' - * It's ready to be inserted into an "echo" line in one of the templates. - * - * @param string $namespace Namespace to access (expects a trailing "." on the namespace) - * @param string $varname Variable name to use - * @param bool $expr Returns whether the source was an expression type - * @param bool $defop If true this is a variable created with the DEFINE construct, otherwise template variable - * @return string Code to access variable or echo it if $echo is true - */ - private function generate_block_varref($namespace, $varname, &$expr, $defop = false) - { - // Strip the trailing period. - $namespace = substr($namespace, 0, -1); - - if (($pos = strrpos($namespace, '.')) !== false) - { - $local_namespace = substr($namespace, $pos + 1); - } - else - { - $local_namespace = $namespace; - } - - $expr = true; - - // S_ROW_COUNT is deceptive, it returns the current row number now the number of rows - // hence S_ROW_COUNT is deprecated in favour of S_ROW_NUM - switch ($varname) - { - case 'S_ROW_NUM': - case 'S_ROW_COUNT': - $varref = "\$_${local_namespace}_i"; - break; - - case 'S_NUM_ROWS': - $varref = "\$_${local_namespace}_count"; - break; - - case 'S_FIRST_ROW': - $varref = "(\$_${local_namespace}_i == 0)"; - break; - - case 'S_LAST_ROW': - $varref = "(\$_${local_namespace}_i == \$_${local_namespace}_count - 1)"; - break; - - case 'S_BLOCK_NAME': - $varref = "'$local_namespace'"; - break; - - default: - // Get a reference to the data block for this namespace. - $varref = $this->generate_block_data_ref($namespace, true, $defop); - // Prepend the necessary code to stick this in an echo line. - - // Append the variable reference. - $varref .= "['$varname']"; - - $expr = false; - break; - } - // @todo Test the !$expr more - - return $varref; - } - - /** - * Generates a reference to the array of data values for the given - * (possibly nested) block namespace. This is a string of the form: - * $_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] - * - * @param string $blockname Block to access (does not expect a trailing "." on the blockname) - * @param bool $include_last_iterator If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. - * @param bool $defop If true this is a variable created with the DEFINE construct, otherwise template variable - * @return string Code to access variable - */ - private function generate_block_data_ref($blockname, $include_last_iterator, $defop = false) - { - // Get an array of the blocks involved. - $blocks = explode('.', $blockname); - $blockcount = sizeof($blocks) - 1; - - // DEFINE is not an element of any referenced variable, we must use _tpldata to access it - if ($defop) - { - $varref = '$_tpldata[\'DEFINE\']'; - // Build up the string with everything but the last child. - for ($i = 0; $i < $blockcount; $i++) - { - $varref .= "['" . $blocks[$i] . "'][\$_" . $blocks[$i] . '_i]'; - } - // Add the block reference for the last child. - $varref .= "['" . $blocks[$blockcount] . "']"; - // Add the iterator for the last child if requried. - if ($include_last_iterator) - { - $varref .= '[$_' . $blocks[$blockcount] . '_i]'; - } - return $varref; - } - else if ($include_last_iterator) - { - return '$_'. $blocks[$blockcount] . '_val'; - } - else - { - return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']'; - } - } -} diff --git a/phpBB/includes/template/renderer.php b/phpBB/includes/template/renderer.php deleted file mode 100644 index 30e234a733..0000000000 --- a/phpBB/includes/template/renderer.php +++ /dev/null @@ -1,35 +0,0 @@ -code = $code; - $this->template = $template; - } - - /** - * Displays the template managed by this renderer by eval'ing php code - * of the template. - * - * @param phpbb_template_context $context Template context to use - * @param array $lang Language entries to use - */ - public function render($context, $lang) - { - $_template = $this->template; - $_tpldata = &$context->get_data_ref(); - $_rootref = &$context->get_root_ref(); - $_lang = $lang; - - eval(' ?>' . $this->code . 'path = $path; - $this->template = $template; - } - - /** - * Displays the template managed by this renderer by including - * the php file containing the template. - * - * @param phpbb_template_context $context Template context to use - * @param array $lang Language entries to use - */ - public function render($context, $lang) - { - $_template = $this->template; - $_tpldata = &$context->get_data_ref(); - $_rootref = &$context->get_root_ref(); - $_lang = $lang; - - include($this->path); - } -} diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php deleted file mode 100644 index bbec768613..0000000000 --- a/phpBB/includes/template/template.php +++ /dev/null @@ -1,515 +0,0 @@ - $user->img('icon_contact', 'CONTACT', 'full'); -* -* More in-depth... -* yadayada -*/ - -/** -* Base Template class. -* @package phpBB3 -*/ -class phpbb_template -{ - /** - * Template context. - * Stores template data used during template rendering. - * @var phpbb_template_context - */ - private $context; - - /** - * Path of the cache directory for the template - * @var string - */ - public $cachepath = ''; - - /** - * phpBB root path - * @var string - */ - private $phpbb_root_path; - - /** - * PHP file extension - * @var string - */ - private $php_ext; - - /** - * phpBB config instance - * @var phpbb_config - */ - private $config; - - /** - * Current user - * @var phpbb_user - */ - private $user; - - /** - * Template locator - * @var phpbb_template_locator - */ - private $locator; - - /** - * Extension manager. - * - * @var phpbb_extension_manager - */ - private $extension_manager; - - /** - * Name of the style that the template being compiled and/or rendered - * belongs to, and its parents, in inheritance tree order. - * - * Used to invoke style-specific template events. - * - * @var array - */ - private $style_names; - - /** - * Constructor. - * - * @param string $phpbb_root_path phpBB root path - * @param user $user current user - * @param phpbb_template_locator $locator template locator - * @param phpbb_template_context $context template context - * @param phpbb_extension_manager $extension_manager extension manager, if null then template events will not be invoked - */ - public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null) - { - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->config = $config; - $this->user = $user; - $this->locator = $locator; - $this->context = $context; - $this->extension_manager = $extension_manager; - } - - /** - * Sets the template filenames for handles. - * - * @param array $filename_array Should be a hash of handle => filename pairs. - */ - public function set_filenames(array $filename_array) - { - $this->locator->set_filenames($filename_array); - - return true; - } - - /** - * Sets the style names corresponding to style hierarchy being compiled - * and/or rendered. - * - * @param array $style_names List of style names in inheritance tree order - * @return null - */ - public function set_style_names(array $style_names) - { - $this->style_names = $style_names; - } - - /** - * Clears all variables and blocks assigned to this template. - */ - public function destroy() - { - $this->context->clear(); - } - - /** - * Reset/empty complete block - * - * @param string $blockname Name of block to destroy - */ - public function destroy_block_vars($blockname) - { - $this->context->destroy_block_vars($blockname); - } - - /** - * Display a template for provided handle. - * - * The template will be loaded and compiled, if necessary, first. - * - * This function calls hooks. - * - * @param string $handle Handle to display - * @return bool True on success, false on failure - */ - public function display($handle) - { - $result = $this->call_hook($handle, __FUNCTION__); - if ($result !== false) - { - return $result[0]; - } - - return $this->load_and_render($handle); - } - - /** - * Loads a template for $handle, compiling it if necessary, and - * renders the template. - * - * @param string $handle Template handle to render - * @return bool True on success, false on failure - */ - private function load_and_render($handle) - { - $renderer = $this->_tpl_load($handle); - - if ($renderer) - { - $renderer->render($this->context, $this->get_lang()); - return true; - } - else - { - return false; - } - } - - /** - * Calls hook if any is defined. - * - * @param string $handle Template handle being displayed. - * @param string $method Method name of the caller. - */ - private function call_hook($handle, $method) - { - global $phpbb_hook; - - if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) - { - if ($phpbb_hook->hook_return(array(__CLASS__, $method))) - { - $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); - return array($result); - } - } - - return false; - } - - /** - * Obtains language array. - * This is either lang property of $user property, or if - * it is not set an empty array. - * @return array language entries - */ - public function get_lang() - { - if (isset($this->user->lang)) - { - $lang = $this->user->lang; - } - else - { - $lang = array(); - } - return $lang; - } - - /** - * Display the handle and assign the output to a template variable - * or return the compiled result. - * - * @param string $handle Handle to operate on - * @param string $template_var Template variable to assign compiled handle to - * @param bool $return_content If true return compiled handle, otherwise assign to $template_var - * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true - */ - public function assign_display($handle, $template_var = '', $return_content = true) - { - ob_start(); - $result = $this->display($handle); - $contents = ob_get_clean(); - if ($result === false) - { - return false; - } - - if ($return_content) - { - return $contents; - } - - $this->assign_var($template_var, $contents); - - return true; - } - - /** - * Obtains a template renderer for a template identified by specified - * handle. The template renderer can display the template later. - * - * Template source will first be compiled into php code. - * If template cache is writable the compiled php code will be stored - * on filesystem and template will not be subsequently recompiled. - * If template cache is not writable template source will be recompiled - * every time it is needed. DEBUG define and load_tplcompile - * configuration setting may be used to force templates to be always - * recompiled. - * - * Returns an object implementing phpbb_template_renderer, or null - * if template loading or compilation failed. Call render() on the - * renderer to display the template. This will result in template - * contents sent to the output stream (unless, of course, output - * buffering is in effect). - * - * @param string $handle Handle of the template to load - * @return phpbb_template_renderer Template renderer object, or null on failure - * @uses phpbb_template_compile is used to compile template source - */ - private function _tpl_load($handle) - { - $output_file = $this->_compiled_file_for_handle($handle); - - $recompile = defined('DEBUG') || - !file_exists($output_file) || - @filesize($output_file) === 0; - - if ($recompile || $this->config['load_tplcompile']) - { - // Set only if a recompile or an mtime check are required. - $source_file = $this->locator->get_source_file_for_handle($handle); - - if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) - { - $recompile = true; - } - } - - // Recompile page if the original template is newer, otherwise load the compiled version - if (!$recompile) - { - return new phpbb_template_renderer_include($output_file, $this); - } - - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->style_names, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user); - - if ($compile->compile_file_to_file($source_file, $output_file) !== false) - { - $renderer = new phpbb_template_renderer_include($output_file, $this); - } - else if (($code = $compile->compile_file($source_file)) !== false) - { - $renderer = new phpbb_template_renderer_eval($code, $this); - } - else - { - $renderer = null; - } - - return $renderer; - } - - /** - * Determines compiled file path for handle $handle. - * - * @param string $handle Template handle (i.e. "friendly" template name) - * @return string Compiled file path - */ - private function _compiled_file_for_handle($handle) - { - $source_file = $this->locator->get_filename_for_handle($handle); - $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; - return $compiled_file; - } - - /** - * Assign key variable pairs from an array - * - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_vars(array $vararray) - { - foreach ($vararray as $key => $val) - { - $this->assign_var($key, $val); - } - } - - /** - * Assign a single scalar value to a single key. - * - * Value can be a string, an integer or a boolean. - * - * @param string $varname Variable name - * @param string $varval Value to assign to variable - */ - public function assign_var($varname, $varval) - { - $this->context->assign_var($varname, $varval); - } - - /** - * Append text to the string value stored in a key. - * - * Text is appended using the string concatenation operator (.). - * - * @param string $varname Variable name - * @param string $varval Value to append to variable - */ - public function append_var($varname, $varval) - { - $this->context->append_var($varname, $varval); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Assign key variable pairs from an array to a specified block - * @param string $blockname Name of block to assign $vararray to - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_block_vars($blockname, array $vararray) - { - return $this->context->assign_block_vars($blockname, $vararray); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Change already assigned key variable pair (one-dimensional - single loop entry) - * - * An example of how to use this function: - * {@example alter_block_array.php} - * - * @param string $blockname the blockname, for example 'loop' - * @param array $vararray the var array to insert/add or merge - * @param mixed $key Key to search for - * - * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] - * - * int: Position [the position to change or insert at directly given] - * - * If key is false the position is set to 0 - * If key is true the position is set to the last entry - * - * @param string $mode Mode to execute (valid modes are 'insert' and 'change') - * - * If insert, the vararray is inserted at the given position (position counting from zero). - * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). - * - * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) - * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) - * - * @return bool false on error, true on success - */ - public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') - { - return $this->context->alter_block_array($blockname, $vararray, $key, $mode); - } - - /** - * Include a separate template. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Template filename to include - * @param bool $include True to include the file, false to just load it - * @uses template_compile is used to compile uncached templates - */ - public function _tpl_include($filename, $include = true) - { - $this->locator->set_filenames(array($filename => $filename)); - - if (!$this->load_and_render($filename)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; - } - } - - /** - * Include a PHP file. - * - * If a relative path is passed in $filename, it is considered to be - * relative to board root ($phpbb_root_path). Absolute paths are - * also allowed. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Path to PHP file to include - */ - public function _php_include($filename) - { - if (phpbb_is_absolute($filename)) - { - $file = $filename; - } - else - { - $file = $this->phpbb_root_path . $filename; - } - - if (!file_exists($file)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; - return; - } - include($file); - } - - /** - * Include JS file - * - * @param string $file file name - * @param bool $locate True if file needs to be located - * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true - */ - public function _js_include($file, $locate = false, $relative = false) - { - // Locate file - if ($locate) - { - $located = $this->locator->get_first_file_location(array($file), false, true); - if ($located) - { - $file = $located; - } - } - else if ($relative) - { - $file = $this->phpbb_root_path . $file; - } - - $file .= (strpos($file, '?') === false) ? '?' : '&'; - $file .= 'assets_version=' . $this->config['assets_version']; - - // Add HTML code - $code = ''; - $this->context->append_var('SCRIPTS', $code); - } -} diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index aada0525a8..8620e33e47 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -565,7 +565,7 @@ class ucp_groups if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour', true)))) { // Replace "error" string with its real, localised form - $error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error)); + $error = array_merge($error, $colour_error); } if (!sizeof($error)) @@ -613,6 +613,7 @@ class ucp_groups if (sizeof($error)) { + $error = array_map(array(&$user, 'lang'), $error); $group_rank = $submit_ary['rank']; $group_desc_data = array( diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php index 94fd59433b..615b567134 100644 --- a/phpBB/includes/ucp/ucp_main.php +++ b/phpBB/includes/ucp/ucp_main.php @@ -642,7 +642,7 @@ class ucp_main */ function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array()) { - global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx; + global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_container; $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE; $start = request_var('start', 0); @@ -768,6 +768,8 @@ class ucp_main } } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + foreach ($topic_list as $topic_id) { $row = &$rowset[$topic_id]; @@ -778,7 +780,7 @@ class ucp_main $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; // Replies - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; + $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id'])) { diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index 5f30625980..4532ecb609 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -497,8 +497,9 @@ if (!$get_info) array('topic_title', 'topics.topic_title', 'phpbb_set_encoding'), array('topic_time', 'topics.topic_time', ''), array('topic_views', 'topics.topic_views', ''), - array('topic_replies', 'topics.topic_replies', ''), - array('topic_replies_real', 'topics.topic_replies', ''), + array('topic_posts_approved', 'topics.topic_replies + 1', ''), + array('topic_posts_unapproved', 0, ''), + array('topic_posts_softdeleted',0, ''), array('topic_last_post_id', 'topics.topic_last_post_id', ''), array('topic_status', 'topics.topic_status', 'is_topic_locked'), array('topic_moved_id', 0, ''), @@ -530,8 +531,9 @@ if (!$get_info) array('topic_title', 'topics.topic_title', 'phpbb_set_encoding'), array('topic_time', 'topics.topic_time', ''), array('topic_views', 'topics.topic_views', ''), - array('topic_replies', 'topics.topic_replies', ''), - array('topic_replies_real', 'topics.topic_replies', ''), + array('topic_posts_approved', 'topics.topic_replies + 1', ''), + array('topic_posts_unapproved', 0, ''), + array('topic_posts_softdeleted',0, ''), array('topic_last_post_id', 'topics.topic_last_post_id', ''), array('topic_status', ITEM_MOVED, ''), array('topic_moved_id', 'topics.topic_moved_id', ''), diff --git a/phpBB/install/convertors/functions_phpbb20.php b/phpBB/install/convertors/functions_phpbb20.php index 0b6daeef47..a698f0ef13 100644 --- a/phpBB/install/convertors/functions_phpbb20.php +++ b/phpBB/install/convertors/functions_phpbb20.php @@ -243,9 +243,12 @@ function phpbb_insert_forums() 'forum_rules_options' => 7, 'forum_rules_uid' => '', 'forum_topics_per_page' => 0, - 'forum_posts' => 0, - 'forum_topics' => 0, - 'forum_topics_real' => 0, + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 0, 'forum_last_poster_id' => 0, 'forum_last_post_subject' => '', diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index e0ecc242e1..44cbc74d29 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -102,7 +102,7 @@ $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relati $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path; // Include files -phpbb_require_updated('includes/class_loader.' . $phpEx); +phpbb_require_updated('phpbb/class_loader.' . $phpEx); phpbb_require_updated('includes/functions.' . $phpEx); phpbb_require_updated('includes/functions_content.' . $phpEx); @@ -116,9 +116,9 @@ phpbb_require_updated('includes/utf/utf_tools.' . $phpEx); set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); // Setup class loader first -$phpbb_class_loader_new = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}install/update/new/includes/", $phpEx); +$phpbb_class_loader_new = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}install/update/new/phpbb/", $phpEx); $phpbb_class_loader_new->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", $phpEx); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); // Set up container (must be done here because extensions table may not exist) @@ -242,7 +242,7 @@ $phpbb_extension_manager = $phpbb_container->get('ext.manager'); $finder = $phpbb_extension_manager->get_finder(); $migrations = $finder - ->core_path('includes/db/migration/data/') + ->core_path('phpbb/db/migration/data/') ->get_classes(); $migrator->set_migrations($migrations); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 055fb72d7c..ada1f43905 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -95,7 +95,7 @@ $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relati $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path; // Include essential scripts -phpbb_require_updated('includes/class_loader.' . $phpEx); +phpbb_require_updated('phpbb/class_loader.' . $phpEx); phpbb_require_updated('includes/functions.' . $phpEx); phpbb_require_updated('includes/functions_container.' . $phpEx); @@ -108,9 +108,9 @@ phpbb_include_updated('includes/utf/utf_tools.' . $phpEx); phpbb_require_updated('includes/functions_install.' . $phpEx); // Setup class loader first -$phpbb_class_loader_new = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}install/update/new/includes/", $phpEx); +$phpbb_class_loader_new = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}install/update/new/phpbb/", $phpEx); $phpbb_class_loader_new->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", $phpEx); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}phpbb/", $phpEx); $phpbb_class_loader->register(); $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); @@ -246,7 +246,7 @@ $config = new phpbb_config(array( $phpbb_style_resource_locator = new phpbb_style_resource_locator(); $phpbb_style_path_provider = new phpbb_style_path_provider(); -$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, new phpbb_template_context()); +$template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context()); $phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template); $phpbb_style->set_ext_dir_prefix('adm/'); $phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), ''); diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 6198efe4c7..8a8c440036 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -1464,7 +1464,6 @@ class install_convert extends module $end = ($sync_batch + $batch_size - 1); // Sync all topics in batch mode... - sync('topic_approved', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, false); sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true); $template->assign_block_vars('checks', array( diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 5bf3f572d9..ea23c318e3 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -53,7 +53,7 @@ class install_install extends module function main($mode, $sub) { global $lang, $template, $language, $phpbb_root_path, $phpEx; - global $phpbb_container, $cache, $phpbb_log; + global $phpbb_container, $cache, $phpbb_log, $request; switch ($sub) { @@ -102,6 +102,9 @@ class install_install extends module break; case 'final': + // Enable super globals to prevent issues with the new phpbb_request object + $request->enable_super_globals(); + // Create a normal container now $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); @@ -1432,7 +1435,7 @@ class install_install extends module $db->sql_return_on_error(true); include_once($phpbb_root_path . 'includes/constants.' . $phpEx); - include_once($phpbb_root_path . 'includes/search/fulltext_native.' . $phpEx); + include_once($phpbb_root_path . 'phpbb/search/fulltext_native.' . $phpEx); // We need to fill the config to let internal functions correctly work $config = new phpbb_config_db($db, new phpbb_cache_driver_null, CONFIG_TABLE); @@ -1885,7 +1888,7 @@ class install_install extends module /** * Populate migrations for the installation * - * This "installs" all migrations from (root path)/includes/db/migrations/data. + * This "installs" all migrations from (root path)/phpbb/db/migrations/data. * "installs" means it adds all migrations to the migrations table, but does not * perform any of the actions in the migrations. * @@ -1897,7 +1900,7 @@ class install_install extends module $finder = $extension_manager->get_finder(); $migrations = $finder - ->core_path('includes/db/migration/data/') + ->core_path('phpbb/db/migration/data/') ->get_classes(); $migrator->populate_migrations($migrations); } diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index a64b8eeffc..ca68ea387d 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -372,9 +372,12 @@ CREATE TABLE phpbb_forums ( forum_topics_per_page INTEGER DEFAULT 0 NOT NULL, forum_type INTEGER DEFAULT 0 NOT NULL, forum_status INTEGER DEFAULT 0 NOT NULL, - forum_posts INTEGER DEFAULT 0 NOT NULL, - forum_topics INTEGER DEFAULT 0 NOT NULL, - forum_topics_real INTEGER DEFAULT 0 NOT NULL, + forum_posts_approved INTEGER DEFAULT 0 NOT NULL, + forum_posts_unapproved INTEGER DEFAULT 0 NOT NULL, + forum_posts_softdeleted INTEGER DEFAULT 0 NOT NULL, + forum_topics_approved INTEGER DEFAULT 0 NOT NULL, + forum_topics_unapproved INTEGER DEFAULT 0 NOT NULL, + forum_topics_softdeleted INTEGER DEFAULT 0 NOT NULL, forum_last_post_id INTEGER DEFAULT 0 NOT NULL, forum_last_poster_id INTEGER DEFAULT 0 NOT NULL, forum_last_post_subject VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, @@ -722,7 +725,7 @@ CREATE TABLE phpbb_posts ( icon_id INTEGER DEFAULT 0 NOT NULL, poster_ip VARCHAR(40) CHARACTER SET NONE DEFAULT '' NOT NULL, post_time INTEGER DEFAULT 0 NOT NULL, - post_approved INTEGER DEFAULT 1 NOT NULL, + post_visibility INTEGER DEFAULT 0 NOT NULL, post_reported INTEGER DEFAULT 0 NOT NULL, enable_bbcode INTEGER DEFAULT 1 NOT NULL, enable_smilies INTEGER DEFAULT 1 NOT NULL, @@ -740,7 +743,10 @@ CREATE TABLE phpbb_posts ( post_edit_reason VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, post_edit_user INTEGER DEFAULT 0 NOT NULL, post_edit_count INTEGER DEFAULT 0 NOT NULL, - post_edit_locked INTEGER DEFAULT 0 NOT NULL + post_edit_locked INTEGER DEFAULT 0 NOT NULL, + post_delete_time INTEGER DEFAULT 0 NOT NULL, + post_delete_reason VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, + post_delete_user INTEGER DEFAULT 0 NOT NULL );; ALTER TABLE phpbb_posts ADD PRIMARY KEY (post_id);; @@ -749,7 +755,7 @@ CREATE INDEX phpbb_posts_forum_id ON phpbb_posts(forum_id);; CREATE INDEX phpbb_posts_topic_id ON phpbb_posts(topic_id);; CREATE INDEX phpbb_posts_poster_ip ON phpbb_posts(poster_ip);; CREATE INDEX phpbb_posts_poster_id ON phpbb_posts(poster_id);; -CREATE INDEX phpbb_posts_post_approved ON phpbb_posts(post_approved);; +CREATE INDEX phpbb_posts_post_visibility ON phpbb_posts(post_visibility);; CREATE INDEX phpbb_posts_post_username ON phpbb_posts(post_username);; CREATE INDEX phpbb_posts_tid_post_time ON phpbb_posts(topic_id, post_time);; @@ -1215,15 +1221,16 @@ CREATE TABLE phpbb_topics ( forum_id INTEGER DEFAULT 0 NOT NULL, icon_id INTEGER DEFAULT 0 NOT NULL, topic_attachment INTEGER DEFAULT 0 NOT NULL, - topic_approved INTEGER DEFAULT 1 NOT NULL, + topic_visibility INTEGER DEFAULT 0 NOT NULL, topic_reported INTEGER DEFAULT 0 NOT NULL, topic_title VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, topic_poster INTEGER DEFAULT 0 NOT NULL, topic_time INTEGER DEFAULT 0 NOT NULL, topic_time_limit INTEGER DEFAULT 0 NOT NULL, topic_views INTEGER DEFAULT 0 NOT NULL, - topic_replies INTEGER DEFAULT 0 NOT NULL, - topic_replies_real INTEGER DEFAULT 0 NOT NULL, + topic_posts_approved INTEGER DEFAULT 0 NOT NULL, + topic_posts_unapproved INTEGER DEFAULT 0 NOT NULL, + topic_posts_softdeleted INTEGER DEFAULT 0 NOT NULL, topic_status INTEGER DEFAULT 0 NOT NULL, topic_type INTEGER DEFAULT 0 NOT NULL, topic_first_post_id INTEGER DEFAULT 0 NOT NULL, @@ -1244,7 +1251,10 @@ CREATE TABLE phpbb_topics ( poll_length INTEGER DEFAULT 0 NOT NULL, poll_max_options INTEGER DEFAULT 1 NOT NULL, poll_last_vote INTEGER DEFAULT 0 NOT NULL, - poll_vote_change INTEGER DEFAULT 0 NOT NULL + poll_vote_change INTEGER DEFAULT 0 NOT NULL, + topic_delete_time INTEGER DEFAULT 0 NOT NULL, + topic_delete_reason VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, + topic_delete_user INTEGER DEFAULT 0 NOT NULL );; ALTER TABLE phpbb_topics ADD PRIMARY KEY (topic_id);; @@ -1252,8 +1262,8 @@ ALTER TABLE phpbb_topics ADD PRIMARY KEY (topic_id);; CREATE INDEX phpbb_topics_forum_id ON phpbb_topics(forum_id);; CREATE INDEX phpbb_topics_forum_id_type ON phpbb_topics(forum_id, topic_type);; CREATE INDEX phpbb_topics_last_post_time ON phpbb_topics(topic_last_post_time);; -CREATE INDEX phpbb_topics_topic_approved ON phpbb_topics(topic_approved);; -CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics(forum_id, topic_approved, topic_last_post_id);; +CREATE INDEX phpbb_topics_topic_visibility ON phpbb_topics(topic_visibility);; +CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics(forum_id, topic_visibility, topic_last_post_id);; CREATE INDEX phpbb_topics_fid_time_moved ON phpbb_topics(forum_id, topic_last_post_time, topic_moved_id);; CREATE GENERATOR phpbb_topics_gen;; diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 8465dc4d72..a2a6d2192c 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -459,9 +459,12 @@ CREATE TABLE [phpbb_forums] ( [forum_topics_per_page] [int] DEFAULT (0) NOT NULL , [forum_type] [int] DEFAULT (0) NOT NULL , [forum_status] [int] DEFAULT (0) NOT NULL , - [forum_posts] [int] DEFAULT (0) NOT NULL , - [forum_topics] [int] DEFAULT (0) NOT NULL , - [forum_topics_real] [int] DEFAULT (0) NOT NULL , + [forum_posts_approved] [int] DEFAULT (0) NOT NULL , + [forum_posts_unapproved] [int] DEFAULT (0) NOT NULL , + [forum_posts_softdeleted] [int] DEFAULT (0) NOT NULL , + [forum_topics_approved] [int] DEFAULT (0) NOT NULL , + [forum_topics_unapproved] [int] DEFAULT (0) NOT NULL , + [forum_topics_softdeleted] [int] DEFAULT (0) NOT NULL , [forum_last_post_id] [int] DEFAULT (0) NOT NULL , [forum_last_poster_id] [int] DEFAULT (0) NOT NULL , [forum_last_post_subject] [varchar] (255) DEFAULT ('') NOT NULL , @@ -889,7 +892,7 @@ CREATE TABLE [phpbb_posts] ( [icon_id] [int] DEFAULT (0) NOT NULL , [poster_ip] [varchar] (40) DEFAULT ('') NOT NULL , [post_time] [int] DEFAULT (0) NOT NULL , - [post_approved] [int] DEFAULT (1) NOT NULL , + [post_visibility] [int] DEFAULT (0) NOT NULL , [post_reported] [int] DEFAULT (0) NOT NULL , [enable_bbcode] [int] DEFAULT (1) NOT NULL , [enable_smilies] [int] DEFAULT (1) NOT NULL , @@ -907,7 +910,10 @@ CREATE TABLE [phpbb_posts] ( [post_edit_reason] [varchar] (255) DEFAULT ('') NOT NULL , [post_edit_user] [int] DEFAULT (0) NOT NULL , [post_edit_count] [int] DEFAULT (0) NOT NULL , - [post_edit_locked] [int] DEFAULT (0) NOT NULL + [post_edit_locked] [int] DEFAULT (0) NOT NULL , + [post_delete_time] [int] DEFAULT (0) NOT NULL , + [post_delete_reason] [varchar] (255) DEFAULT ('') NOT NULL , + [post_delete_user] [int] DEFAULT (0) NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO @@ -930,7 +936,7 @@ GO CREATE INDEX [poster_id] ON [phpbb_posts]([poster_id]) ON [PRIMARY] GO -CREATE INDEX [post_approved] ON [phpbb_posts]([post_approved]) ON [PRIMARY] +CREATE INDEX [post_visibility] ON [phpbb_posts]([post_visibility]) ON [PRIMARY] GO CREATE INDEX [post_username] ON [phpbb_posts]([post_username]) ON [PRIMARY] @@ -1463,15 +1469,16 @@ CREATE TABLE [phpbb_topics] ( [forum_id] [int] DEFAULT (0) NOT NULL , [icon_id] [int] DEFAULT (0) NOT NULL , [topic_attachment] [int] DEFAULT (0) NOT NULL , - [topic_approved] [int] DEFAULT (1) NOT NULL , + [topic_visibility] [int] DEFAULT (0) NOT NULL , [topic_reported] [int] DEFAULT (0) NOT NULL , [topic_title] [varchar] (255) DEFAULT ('') NOT NULL , [topic_poster] [int] DEFAULT (0) NOT NULL , [topic_time] [int] DEFAULT (0) NOT NULL , [topic_time_limit] [int] DEFAULT (0) NOT NULL , [topic_views] [int] DEFAULT (0) NOT NULL , - [topic_replies] [int] DEFAULT (0) NOT NULL , - [topic_replies_real] [int] DEFAULT (0) NOT NULL , + [topic_posts_approved] [int] DEFAULT (0) NOT NULL , + [topic_posts_unapproved] [int] DEFAULT (0) NOT NULL , + [topic_posts_softdeleted] [int] DEFAULT (0) NOT NULL , [topic_status] [int] DEFAULT (0) NOT NULL , [topic_type] [int] DEFAULT (0) NOT NULL , [topic_first_post_id] [int] DEFAULT (0) NOT NULL , @@ -1492,7 +1499,10 @@ CREATE TABLE [phpbb_topics] ( [poll_length] [int] DEFAULT (0) NOT NULL , [poll_max_options] [int] DEFAULT (1) NOT NULL , [poll_last_vote] [int] DEFAULT (0) NOT NULL , - [poll_vote_change] [int] DEFAULT (0) NOT NULL + [poll_vote_change] [int] DEFAULT (0) NOT NULL , + [topic_delete_time] [int] DEFAULT (0) NOT NULL , + [topic_delete_reason] [varchar] (255) DEFAULT ('') NOT NULL , + [topic_delete_user] [int] DEFAULT (0) NOT NULL ) ON [PRIMARY] GO @@ -1512,10 +1522,10 @@ GO CREATE INDEX [last_post_time] ON [phpbb_topics]([topic_last_post_time]) ON [PRIMARY] GO -CREATE INDEX [topic_approved] ON [phpbb_topics]([topic_approved]) ON [PRIMARY] +CREATE INDEX [topic_visibility] ON [phpbb_topics]([topic_visibility]) ON [PRIMARY] GO -CREATE INDEX [forum_appr_last] ON [phpbb_topics]([forum_id], [topic_approved], [topic_last_post_id]) ON [PRIMARY] +CREATE INDEX [forum_appr_last] ON [phpbb_topics]([forum_id], [topic_visibility], [topic_last_post_id]) ON [PRIMARY] GO CREATE INDEX [fid_time_moved] ON [phpbb_topics]([forum_id], [topic_last_post_time], [topic_moved_id]) ON [PRIMARY] diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 37e4e66ad7..2c5931bae4 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -257,9 +257,12 @@ CREATE TABLE phpbb_forums ( forum_topics_per_page tinyint(4) DEFAULT '0' NOT NULL, forum_type tinyint(4) DEFAULT '0' NOT NULL, forum_status tinyint(4) DEFAULT '0' NOT NULL, - forum_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - forum_topics mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - forum_topics_real mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_posts_approved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_posts_unapproved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_posts_softdeleted mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_topics_approved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_topics_unapproved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_topics_softdeleted mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_last_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_last_poster_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_last_post_subject blob NOT NULL, @@ -508,7 +511,7 @@ CREATE TABLE phpbb_posts ( icon_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, poster_ip varbinary(40) DEFAULT '' NOT NULL, post_time int(11) UNSIGNED DEFAULT '0' NOT NULL, - post_approved tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + post_visibility tinyint(3) DEFAULT '0' NOT NULL, post_reported tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, enable_bbcode tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, enable_smilies tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, @@ -527,12 +530,15 @@ CREATE TABLE phpbb_posts ( post_edit_user mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, post_edit_count smallint(4) UNSIGNED DEFAULT '0' NOT NULL, post_edit_locked tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, + post_delete_time int(11) UNSIGNED DEFAULT '0' NOT NULL, + post_delete_reason blob NOT NULL, + post_delete_user mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (post_id), KEY forum_id (forum_id), KEY topic_id (topic_id), KEY poster_ip (poster_ip), KEY poster_id (poster_id), - KEY post_approved (post_approved), + KEY post_visibility (post_visibility), KEY post_username (post_username(255)), KEY tid_post_time (topic_id, post_time) ); @@ -839,15 +845,16 @@ CREATE TABLE phpbb_topics ( forum_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, icon_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, topic_attachment tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, - topic_approved tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + topic_visibility tinyint(3) DEFAULT '0' NOT NULL, topic_reported tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, topic_title blob NOT NULL, topic_poster mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, topic_time int(11) UNSIGNED DEFAULT '0' NOT NULL, topic_time_limit int(11) UNSIGNED DEFAULT '0' NOT NULL, topic_views mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - topic_replies mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - topic_replies_real mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_posts_approved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_posts_unapproved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_posts_softdeleted mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, topic_status tinyint(3) DEFAULT '0' NOT NULL, topic_type tinyint(3) DEFAULT '0' NOT NULL, topic_first_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -869,12 +876,15 @@ CREATE TABLE phpbb_topics ( poll_max_options tinyint(4) DEFAULT '1' NOT NULL, poll_last_vote int(11) UNSIGNED DEFAULT '0' NOT NULL, poll_vote_change tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, + topic_delete_time int(11) UNSIGNED DEFAULT '0' NOT NULL, + topic_delete_reason blob NOT NULL, + topic_delete_user mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (topic_id), KEY forum_id (forum_id), KEY forum_id_type (forum_id, topic_type), KEY last_post_time (topic_last_post_time), - KEY topic_approved (topic_approved), - KEY forum_appr_last (forum_id, topic_approved, topic_last_post_id), + KEY topic_visibility (topic_visibility), + KEY forum_appr_last (forum_id, topic_visibility, topic_last_post_id), KEY fid_time_moved (forum_id, topic_last_post_time, topic_moved_id) ); diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index ff0f315f93..7b7be3c462 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -257,9 +257,12 @@ CREATE TABLE phpbb_forums ( forum_topics_per_page tinyint(4) DEFAULT '0' NOT NULL, forum_type tinyint(4) DEFAULT '0' NOT NULL, forum_status tinyint(4) DEFAULT '0' NOT NULL, - forum_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - forum_topics mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - forum_topics_real mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_posts_approved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_posts_unapproved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_posts_softdeleted mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_topics_approved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_topics_unapproved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + forum_topics_softdeleted mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_last_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_last_poster_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_last_post_subject varchar(255) DEFAULT '' NOT NULL, @@ -508,7 +511,7 @@ CREATE TABLE phpbb_posts ( icon_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, poster_ip varchar(40) DEFAULT '' NOT NULL, post_time int(11) UNSIGNED DEFAULT '0' NOT NULL, - post_approved tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + post_visibility tinyint(3) DEFAULT '0' NOT NULL, post_reported tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, enable_bbcode tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, enable_smilies tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, @@ -527,12 +530,15 @@ CREATE TABLE phpbb_posts ( post_edit_user mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, post_edit_count smallint(4) UNSIGNED DEFAULT '0' NOT NULL, post_edit_locked tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, + post_delete_time int(11) UNSIGNED DEFAULT '0' NOT NULL, + post_delete_reason varchar(255) DEFAULT '' NOT NULL, + post_delete_user mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (post_id), KEY forum_id (forum_id), KEY topic_id (topic_id), KEY poster_ip (poster_ip), KEY poster_id (poster_id), - KEY post_approved (post_approved), + KEY post_visibility (post_visibility), KEY post_username (post_username), KEY tid_post_time (topic_id, post_time) ) CHARACTER SET `utf8` COLLATE `utf8_bin`; @@ -839,15 +845,16 @@ CREATE TABLE phpbb_topics ( forum_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, icon_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, topic_attachment tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, - topic_approved tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + topic_visibility tinyint(3) DEFAULT '0' NOT NULL, topic_reported tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, topic_title varchar(255) DEFAULT '' NOT NULL COLLATE utf8_unicode_ci, topic_poster mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, topic_time int(11) UNSIGNED DEFAULT '0' NOT NULL, topic_time_limit int(11) UNSIGNED DEFAULT '0' NOT NULL, topic_views mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - topic_replies mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - topic_replies_real mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_posts_approved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_posts_unapproved mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_posts_softdeleted mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, topic_status tinyint(3) DEFAULT '0' NOT NULL, topic_type tinyint(3) DEFAULT '0' NOT NULL, topic_first_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, @@ -869,12 +876,15 @@ CREATE TABLE phpbb_topics ( poll_max_options tinyint(4) DEFAULT '1' NOT NULL, poll_last_vote int(11) UNSIGNED DEFAULT '0' NOT NULL, poll_vote_change tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, + topic_delete_time int(11) UNSIGNED DEFAULT '0' NOT NULL, + topic_delete_reason varchar(255) DEFAULT '' NOT NULL, + topic_delete_user mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (topic_id), KEY forum_id (forum_id), KEY forum_id_type (forum_id, topic_type), KEY last_post_time (topic_last_post_time), - KEY topic_approved (topic_approved), - KEY forum_appr_last (forum_id, topic_approved, topic_last_post_id), + KEY topic_visibility (topic_visibility), + KEY forum_appr_last (forum_id, topic_visibility, topic_last_post_id), KEY fid_time_moved (forum_id, topic_last_post_time, topic_moved_id) ) CHARACTER SET `utf8` COLLATE `utf8_bin`; diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 11f245869d..75c01446d8 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -520,9 +520,12 @@ CREATE TABLE phpbb_forums ( forum_topics_per_page number(4) DEFAULT '0' NOT NULL, forum_type number(4) DEFAULT '0' NOT NULL, forum_status number(4) DEFAULT '0' NOT NULL, - forum_posts number(8) DEFAULT '0' NOT NULL, - forum_topics number(8) DEFAULT '0' NOT NULL, - forum_topics_real number(8) DEFAULT '0' NOT NULL, + forum_posts_approved number(8) DEFAULT '0' NOT NULL, + forum_posts_unapproved number(8) DEFAULT '0' NOT NULL, + forum_posts_softdeleted number(8) DEFAULT '0' NOT NULL, + forum_topics_approved number(8) DEFAULT '0' NOT NULL, + forum_topics_unapproved number(8) DEFAULT '0' NOT NULL, + forum_topics_softdeleted number(8) DEFAULT '0' NOT NULL, forum_last_post_id number(8) DEFAULT '0' NOT NULL, forum_last_poster_id number(8) DEFAULT '0' NOT NULL, forum_last_post_subject varchar2(765) DEFAULT '' , @@ -977,7 +980,7 @@ CREATE TABLE phpbb_posts ( icon_id number(8) DEFAULT '0' NOT NULL, poster_ip varchar2(40) DEFAULT '' , post_time number(11) DEFAULT '0' NOT NULL, - post_approved number(1) DEFAULT '1' NOT NULL, + post_visibility number(3) DEFAULT '0' NOT NULL, post_reported number(1) DEFAULT '0' NOT NULL, enable_bbcode number(1) DEFAULT '1' NOT NULL, enable_smilies number(1) DEFAULT '1' NOT NULL, @@ -996,6 +999,9 @@ CREATE TABLE phpbb_posts ( post_edit_user number(8) DEFAULT '0' NOT NULL, post_edit_count number(4) DEFAULT '0' NOT NULL, post_edit_locked number(1) DEFAULT '0' NOT NULL, + post_delete_time number(11) DEFAULT '0' NOT NULL, + post_delete_reason varchar2(765) DEFAULT '' , + post_delete_user number(8) DEFAULT '0' NOT NULL, CONSTRAINT pk_phpbb_posts PRIMARY KEY (post_id) ) / @@ -1008,7 +1014,7 @@ CREATE INDEX phpbb_posts_poster_ip ON phpbb_posts (poster_ip) / CREATE INDEX phpbb_posts_poster_id ON phpbb_posts (poster_id) / -CREATE INDEX phpbb_posts_post_approved ON phpbb_posts (post_approved) +CREATE INDEX phpbb_posts_post_visibility ON phpbb_posts (post_visibility) / CREATE INDEX phpbb_posts_post_username ON phpbb_posts (post_username) / @@ -1607,15 +1613,16 @@ CREATE TABLE phpbb_topics ( forum_id number(8) DEFAULT '0' NOT NULL, icon_id number(8) DEFAULT '0' NOT NULL, topic_attachment number(1) DEFAULT '0' NOT NULL, - topic_approved number(1) DEFAULT '1' NOT NULL, + topic_visibility number(3) DEFAULT '0' NOT NULL, topic_reported number(1) DEFAULT '0' NOT NULL, topic_title varchar2(765) DEFAULT '' , topic_poster number(8) DEFAULT '0' NOT NULL, topic_time number(11) DEFAULT '0' NOT NULL, topic_time_limit number(11) DEFAULT '0' NOT NULL, topic_views number(8) DEFAULT '0' NOT NULL, - topic_replies number(8) DEFAULT '0' NOT NULL, - topic_replies_real number(8) DEFAULT '0' NOT NULL, + topic_posts_approved number(8) DEFAULT '0' NOT NULL, + topic_posts_unapproved number(8) DEFAULT '0' NOT NULL, + topic_posts_softdeleted number(8) DEFAULT '0' NOT NULL, topic_status number(3) DEFAULT '0' NOT NULL, topic_type number(3) DEFAULT '0' NOT NULL, topic_first_post_id number(8) DEFAULT '0' NOT NULL, @@ -1637,6 +1644,9 @@ CREATE TABLE phpbb_topics ( poll_max_options number(4) DEFAULT '1' NOT NULL, poll_last_vote number(11) DEFAULT '0' NOT NULL, poll_vote_change number(1) DEFAULT '0' NOT NULL, + topic_delete_time number(11) DEFAULT '0' NOT NULL, + topic_delete_reason varchar2(765) DEFAULT '' , + topic_delete_user number(8) DEFAULT '0' NOT NULL, CONSTRAINT pk_phpbb_topics PRIMARY KEY (topic_id) ) / @@ -1647,9 +1657,9 @@ CREATE INDEX phpbb_topics_forum_id_type ON phpbb_topics (forum_id, topic_type) / CREATE INDEX phpbb_topics_last_post_time ON phpbb_topics (topic_last_post_time) / -CREATE INDEX phpbb_topics_topic_approved ON phpbb_topics (topic_approved) +CREATE INDEX phpbb_topics_topic_visibility ON phpbb_topics (topic_visibility) / -CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics (forum_id, topic_approved, topic_last_post_id) +CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics (forum_id, topic_visibility, topic_last_post_id) / CREATE INDEX phpbb_topics_fid_time_moved ON phpbb_topics (forum_id, topic_last_post_time, topic_moved_id) / diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index fea5700167..c7fbe9a507 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -395,9 +395,12 @@ CREATE TABLE phpbb_forums ( forum_topics_per_page INT2 DEFAULT '0' NOT NULL, forum_type INT2 DEFAULT '0' NOT NULL, forum_status INT2 DEFAULT '0' NOT NULL, - forum_posts INT4 DEFAULT '0' NOT NULL CHECK (forum_posts >= 0), - forum_topics INT4 DEFAULT '0' NOT NULL CHECK (forum_topics >= 0), - forum_topics_real INT4 DEFAULT '0' NOT NULL CHECK (forum_topics_real >= 0), + forum_posts_approved INT4 DEFAULT '0' NOT NULL CHECK (forum_posts_approved >= 0), + forum_posts_unapproved INT4 DEFAULT '0' NOT NULL CHECK (forum_posts_unapproved >= 0), + forum_posts_softdeleted INT4 DEFAULT '0' NOT NULL CHECK (forum_posts_softdeleted >= 0), + forum_topics_approved INT4 DEFAULT '0' NOT NULL CHECK (forum_topics_approved >= 0), + forum_topics_unapproved INT4 DEFAULT '0' NOT NULL CHECK (forum_topics_unapproved >= 0), + forum_topics_softdeleted INT4 DEFAULT '0' NOT NULL CHECK (forum_topics_softdeleted >= 0), forum_last_post_id INT4 DEFAULT '0' NOT NULL CHECK (forum_last_post_id >= 0), forum_last_poster_id INT4 DEFAULT '0' NOT NULL CHECK (forum_last_poster_id >= 0), forum_last_post_subject varchar(255) DEFAULT '' NOT NULL, @@ -694,7 +697,7 @@ CREATE TABLE phpbb_posts ( icon_id INT4 DEFAULT '0' NOT NULL CHECK (icon_id >= 0), poster_ip varchar(40) DEFAULT '' NOT NULL, post_time INT4 DEFAULT '0' NOT NULL CHECK (post_time >= 0), - post_approved INT2 DEFAULT '1' NOT NULL CHECK (post_approved >= 0), + post_visibility INT2 DEFAULT '0' NOT NULL, post_reported INT2 DEFAULT '0' NOT NULL CHECK (post_reported >= 0), enable_bbcode INT2 DEFAULT '1' NOT NULL CHECK (enable_bbcode >= 0), enable_smilies INT2 DEFAULT '1' NOT NULL CHECK (enable_smilies >= 0), @@ -713,6 +716,9 @@ CREATE TABLE phpbb_posts ( post_edit_user INT4 DEFAULT '0' NOT NULL CHECK (post_edit_user >= 0), post_edit_count INT2 DEFAULT '0' NOT NULL CHECK (post_edit_count >= 0), post_edit_locked INT2 DEFAULT '0' NOT NULL CHECK (post_edit_locked >= 0), + post_delete_time INT4 DEFAULT '0' NOT NULL CHECK (post_delete_time >= 0), + post_delete_reason varchar(255) DEFAULT '' NOT NULL, + post_delete_user INT4 DEFAULT '0' NOT NULL CHECK (post_delete_user >= 0), PRIMARY KEY (post_id) ); @@ -720,7 +726,7 @@ CREATE INDEX phpbb_posts_forum_id ON phpbb_posts (forum_id); CREATE INDEX phpbb_posts_topic_id ON phpbb_posts (topic_id); CREATE INDEX phpbb_posts_poster_ip ON phpbb_posts (poster_ip); CREATE INDEX phpbb_posts_poster_id ON phpbb_posts (poster_id); -CREATE INDEX phpbb_posts_post_approved ON phpbb_posts (post_approved); +CREATE INDEX phpbb_posts_post_visibility ON phpbb_posts (post_visibility); CREATE INDEX phpbb_posts_post_username ON phpbb_posts (post_username); CREATE INDEX phpbb_posts_tid_post_time ON phpbb_posts (topic_id, post_time); @@ -1093,15 +1099,16 @@ CREATE TABLE phpbb_topics ( forum_id INT4 DEFAULT '0' NOT NULL CHECK (forum_id >= 0), icon_id INT4 DEFAULT '0' NOT NULL CHECK (icon_id >= 0), topic_attachment INT2 DEFAULT '0' NOT NULL CHECK (topic_attachment >= 0), - topic_approved INT2 DEFAULT '1' NOT NULL CHECK (topic_approved >= 0), + topic_visibility INT2 DEFAULT '0' NOT NULL, topic_reported INT2 DEFAULT '0' NOT NULL CHECK (topic_reported >= 0), topic_title varchar(255) DEFAULT '' NOT NULL, topic_poster INT4 DEFAULT '0' NOT NULL CHECK (topic_poster >= 0), topic_time INT4 DEFAULT '0' NOT NULL CHECK (topic_time >= 0), topic_time_limit INT4 DEFAULT '0' NOT NULL CHECK (topic_time_limit >= 0), topic_views INT4 DEFAULT '0' NOT NULL CHECK (topic_views >= 0), - topic_replies INT4 DEFAULT '0' NOT NULL CHECK (topic_replies >= 0), - topic_replies_real INT4 DEFAULT '0' NOT NULL CHECK (topic_replies_real >= 0), + topic_posts_approved INT4 DEFAULT '0' NOT NULL CHECK (topic_posts_approved >= 0), + topic_posts_unapproved INT4 DEFAULT '0' NOT NULL CHECK (topic_posts_unapproved >= 0), + topic_posts_softdeleted INT4 DEFAULT '0' NOT NULL CHECK (topic_posts_softdeleted >= 0), topic_status INT2 DEFAULT '0' NOT NULL, topic_type INT2 DEFAULT '0' NOT NULL, topic_first_post_id INT4 DEFAULT '0' NOT NULL CHECK (topic_first_post_id >= 0), @@ -1123,14 +1130,17 @@ CREATE TABLE phpbb_topics ( poll_max_options INT2 DEFAULT '1' NOT NULL, poll_last_vote INT4 DEFAULT '0' NOT NULL CHECK (poll_last_vote >= 0), poll_vote_change INT2 DEFAULT '0' NOT NULL CHECK (poll_vote_change >= 0), + topic_delete_time INT4 DEFAULT '0' NOT NULL CHECK (topic_delete_time >= 0), + topic_delete_reason varchar(255) DEFAULT '' NOT NULL, + topic_delete_user INT4 DEFAULT '0' NOT NULL CHECK (topic_delete_user >= 0), PRIMARY KEY (topic_id) ); CREATE INDEX phpbb_topics_forum_id ON phpbb_topics (forum_id); CREATE INDEX phpbb_topics_forum_id_type ON phpbb_topics (forum_id, topic_type); CREATE INDEX phpbb_topics_last_post_time ON phpbb_topics (topic_last_post_time); -CREATE INDEX phpbb_topics_topic_approved ON phpbb_topics (topic_approved); -CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics (forum_id, topic_approved, topic_last_post_id); +CREATE INDEX phpbb_topics_topic_visibility ON phpbb_topics (topic_visibility); +CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics (forum_id, topic_visibility, topic_last_post_id); CREATE INDEX phpbb_topics_fid_time_moved ON phpbb_topics (forum_id, topic_last_post_time, topic_moved_id); /* diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 355981721e..d03fdf9de4 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -39,6 +39,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_sig_pm', '1' INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_sig_smilies', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_smilies', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_topic_notify', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('assets_version', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('attachment_quota', '52428800'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('auth_bbcode_pm', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('auth_flash_pm', '0'); @@ -320,6 +321,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_subscribe', 1); INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_user_lock', 1); INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_vote', 1); INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_votechg', 1); +INSERT INTO phpbb_acl_options (auth_option, is_local) VALUES ('f_softdelete', 1); # -- Moderator related auth options INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_', 1, 1); @@ -333,6 +335,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_merg INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_move', 1, 1); INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_report', 1, 1); INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_split', 1, 1); +INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_softdelete', 1, 1); # -- Global moderator auth option (not a local option) INSERT INTO phpbb_acl_options (auth_option, is_local, is_global) VALUES ('m_ban', 0, 1); @@ -453,9 +456,9 @@ INSERT INTO phpbb_acl_roles (role_name, role_description, role_type, role_order) INSERT INTO phpbb_styles (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, ''); # -- Forums -INSERT INTO phpbb_forums (forum_name, forum_desc, left_id, right_id, parent_id, forum_type, forum_posts, forum_topics, forum_topics_real, forum_last_post_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour, forum_last_post_time, forum_link, forum_password, forum_image, forum_rules, forum_rules_link, forum_rules_uid, forum_desc_uid, prune_days, prune_viewed, forum_parents) VALUES ('{L_FORUMS_FIRST_CATEGORY}', '', 1, 4, 0, 0, 1, 1, 1, 1, 2, 'Admin', 'AA0000', 972086460, '', '', '', '', '', '', '', 0, 0, ''); +INSERT INTO phpbb_forums (forum_name, forum_desc, left_id, right_id, parent_id, forum_type, forum_posts_approved, forum_posts_unapproved, forum_posts_softdeleted, forum_topics_approved, forum_topics_unapproved, forum_topics_softdeleted, forum_last_post_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour, forum_last_post_time, forum_link, forum_password, forum_image, forum_rules, forum_rules_link, forum_rules_uid, forum_desc_uid, prune_days, prune_viewed, forum_parents) VALUES ('{L_FORUMS_FIRST_CATEGORY}', '', 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 'Admin', 'AA0000', 972086460, '', '', '', '', '', '', '', 0, 0, ''); -INSERT INTO phpbb_forums (forum_name, forum_desc, left_id, right_id, parent_id, forum_type, forum_posts, forum_topics, forum_topics_real, forum_last_post_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour, forum_last_post_subject, forum_last_post_time, forum_link, forum_password, forum_image, forum_rules, forum_rules_link, forum_rules_uid, forum_desc_uid, prune_days, prune_viewed, forum_parents, forum_flags) VALUES ('{L_FORUMS_TEST_FORUM_TITLE}', '{L_FORUMS_TEST_FORUM_DESC}', 2, 3, 1, 1, 1, 1, 1, 1, 2, 'Admin', 'AA0000', '{L_TOPICS_TOPIC_TITLE}', 972086460, '', '', '', '', '', '', '', 0, 0, '', 48); +INSERT INTO phpbb_forums (forum_name, forum_desc, left_id, right_id, parent_id, forum_type, forum_posts_approved, forum_posts_unapproved, forum_posts_softdeleted, forum_topics_approved, forum_topics_unapproved, forum_topics_softdeleted, forum_last_post_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour, forum_last_post_subject, forum_last_post_time, forum_link, forum_password, forum_image, forum_rules, forum_rules_link, forum_rules_uid, forum_desc_uid, prune_days, prune_viewed, forum_parents, forum_flags) VALUES ('{L_FORUMS_TEST_FORUM_TITLE}', '{L_FORUMS_TEST_FORUM_DESC}', 2, 3, 1, 1, 1, 0, 0, 1, 0, 0, 1, 2, 'Admin', 'AA0000', '{L_TOPICS_TOPIC_TITLE}', 972086460, '', '', '', '', '', '', '', 0, 0, '', 48); # -- Users / Anonymous user INSERT INTO phpbb_users (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd, user_allow_massemail) VALUES (2, 1, 'Anonymous', 'anonymous', 0, '', '', 'en', 1, 0, '', 0, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 0); @@ -523,7 +526,7 @@ INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 11, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'm_%' AND auth_option NOT IN ('m_ban', 'm_chgposter'); # Simple Moderator (m_) -INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 12, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'm_%' AND auth_option IN ('m_', 'm_delete', 'm_edit', 'm_info', 'm_report'); +INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 12, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'm_%' AND auth_option IN ('m_', 'm_delete', 'm_softdelete', 'm_edit', 'm_info', 'm_report'); # Queue Moderator (m_) INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 13, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'm_%' AND auth_option IN ('m_', 'm_approve', 'm_edit'); @@ -621,10 +624,10 @@ INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, # -- Demo Topic -INSERT INTO phpbb_topics (topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_replies_real, forum_id, topic_status, topic_type, topic_first_post_id, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_subject, topic_last_post_time, topic_last_view_time, poll_title) VALUES ('{L_TOPICS_TOPIC_TITLE}', 2, 972086460, 0, 0, 0, 2, 0, 0, 1, 'Admin', 'AA0000', 1, 2, 'Admin', 'AA0000', '{L_TOPICS_TOPIC_TITLE}', 972086460, 972086460, ''); +INSERT INTO phpbb_topics (topic_title, topic_poster, topic_time, topic_views, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, forum_id, topic_status, topic_type, topic_first_post_id, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_subject, topic_last_post_time, topic_last_view_time, poll_title, topic_visibility) VALUES ('{L_TOPICS_TOPIC_TITLE}', 2, 972086460, 0, 1, 0, 0, 2, 0, 0, 1, 'Admin', 'AA0000', 1, 2, 'Admin', 'AA0000', '{L_TOPICS_TOPIC_TITLE}', 972086460, 972086460, '', 1); # -- Demo Post -INSERT INTO phpbb_posts (topic_id, forum_id, poster_id, icon_id, post_time, post_username, poster_ip, post_subject, post_text, post_checksum, bbcode_uid) VALUES (1, 2, 2, 0, 972086460, '', '127.0.0.1', '{L_TOPICS_TOPIC_TITLE}', '{L_DEFAULT_INSTALL_POST}', '5dd683b17f641daf84c040bfefc58ce9', ''); +INSERT INTO phpbb_posts (topic_id, forum_id, poster_id, icon_id, post_time, post_username, poster_ip, post_subject, post_text, post_checksum, bbcode_uid, post_visibility) VALUES (1, 2, 2, 0, 972086460, '', '127.0.0.1', '{L_TOPICS_TOPIC_TITLE}', '{L_DEFAULT_INSTALL_POST}', '5dd683b17f641daf84c040bfefc58ce9', '', 1); # -- Admin posted to the demo topic INSERT INTO phpbb_topics_posted (user_id, topic_id, topic_posted) VALUES (2, 1, 1); diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 02ffb9a857..72b2b276da 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -250,9 +250,12 @@ CREATE TABLE phpbb_forums ( forum_topics_per_page tinyint(4) NOT NULL DEFAULT '0', forum_type tinyint(4) NOT NULL DEFAULT '0', forum_status tinyint(4) NOT NULL DEFAULT '0', - forum_posts INTEGER UNSIGNED NOT NULL DEFAULT '0', - forum_topics INTEGER UNSIGNED NOT NULL DEFAULT '0', - forum_topics_real INTEGER UNSIGNED NOT NULL DEFAULT '0', + forum_posts_approved INTEGER UNSIGNED NOT NULL DEFAULT '0', + forum_posts_unapproved INTEGER UNSIGNED NOT NULL DEFAULT '0', + forum_posts_softdeleted INTEGER UNSIGNED NOT NULL DEFAULT '0', + forum_topics_approved INTEGER UNSIGNED NOT NULL DEFAULT '0', + forum_topics_unapproved INTEGER UNSIGNED NOT NULL DEFAULT '0', + forum_topics_softdeleted INTEGER UNSIGNED NOT NULL DEFAULT '0', forum_last_post_id INTEGER UNSIGNED NOT NULL DEFAULT '0', forum_last_poster_id INTEGER UNSIGNED NOT NULL DEFAULT '0', forum_last_post_subject text(65535) NOT NULL DEFAULT '', @@ -493,7 +496,7 @@ CREATE TABLE phpbb_posts ( icon_id INTEGER UNSIGNED NOT NULL DEFAULT '0', poster_ip varchar(40) NOT NULL DEFAULT '', post_time INTEGER UNSIGNED NOT NULL DEFAULT '0', - post_approved INTEGER UNSIGNED NOT NULL DEFAULT '1', + post_visibility tinyint(3) NOT NULL DEFAULT '0', post_reported INTEGER UNSIGNED NOT NULL DEFAULT '0', enable_bbcode INTEGER UNSIGNED NOT NULL DEFAULT '1', enable_smilies INTEGER UNSIGNED NOT NULL DEFAULT '1', @@ -511,14 +514,17 @@ CREATE TABLE phpbb_posts ( post_edit_reason text(65535) NOT NULL DEFAULT '', post_edit_user INTEGER UNSIGNED NOT NULL DEFAULT '0', post_edit_count INTEGER UNSIGNED NOT NULL DEFAULT '0', - post_edit_locked INTEGER UNSIGNED NOT NULL DEFAULT '0' + post_edit_locked INTEGER UNSIGNED NOT NULL DEFAULT '0', + post_delete_time INTEGER UNSIGNED NOT NULL DEFAULT '0', + post_delete_reason text(65535) NOT NULL DEFAULT '', + post_delete_user INTEGER UNSIGNED NOT NULL DEFAULT '0' ); CREATE INDEX phpbb_posts_forum_id ON phpbb_posts (forum_id); CREATE INDEX phpbb_posts_topic_id ON phpbb_posts (topic_id); CREATE INDEX phpbb_posts_poster_ip ON phpbb_posts (poster_ip); CREATE INDEX phpbb_posts_poster_id ON phpbb_posts (poster_id); -CREATE INDEX phpbb_posts_post_approved ON phpbb_posts (post_approved); +CREATE INDEX phpbb_posts_post_visibility ON phpbb_posts (post_visibility); CREATE INDEX phpbb_posts_post_username ON phpbb_posts (post_username); CREATE INDEX phpbb_posts_tid_post_time ON phpbb_posts (topic_id, post_time); @@ -811,15 +817,16 @@ CREATE TABLE phpbb_topics ( forum_id INTEGER UNSIGNED NOT NULL DEFAULT '0', icon_id INTEGER UNSIGNED NOT NULL DEFAULT '0', topic_attachment INTEGER UNSIGNED NOT NULL DEFAULT '0', - topic_approved INTEGER UNSIGNED NOT NULL DEFAULT '1', + topic_visibility tinyint(3) NOT NULL DEFAULT '0', topic_reported INTEGER UNSIGNED NOT NULL DEFAULT '0', topic_title text(65535) NOT NULL DEFAULT '', topic_poster INTEGER UNSIGNED NOT NULL DEFAULT '0', topic_time INTEGER UNSIGNED NOT NULL DEFAULT '0', topic_time_limit INTEGER UNSIGNED NOT NULL DEFAULT '0', topic_views INTEGER UNSIGNED NOT NULL DEFAULT '0', - topic_replies INTEGER UNSIGNED NOT NULL DEFAULT '0', - topic_replies_real INTEGER UNSIGNED NOT NULL DEFAULT '0', + topic_posts_approved INTEGER UNSIGNED NOT NULL DEFAULT '0', + topic_posts_unapproved INTEGER UNSIGNED NOT NULL DEFAULT '0', + topic_posts_softdeleted INTEGER UNSIGNED NOT NULL DEFAULT '0', topic_status tinyint(3) NOT NULL DEFAULT '0', topic_type tinyint(3) NOT NULL DEFAULT '0', topic_first_post_id INTEGER UNSIGNED NOT NULL DEFAULT '0', @@ -840,14 +847,17 @@ CREATE TABLE phpbb_topics ( poll_length INTEGER UNSIGNED NOT NULL DEFAULT '0', poll_max_options tinyint(4) NOT NULL DEFAULT '1', poll_last_vote INTEGER UNSIGNED NOT NULL DEFAULT '0', - poll_vote_change INTEGER UNSIGNED NOT NULL DEFAULT '0' + poll_vote_change INTEGER UNSIGNED NOT NULL DEFAULT '0', + topic_delete_time INTEGER UNSIGNED NOT NULL DEFAULT '0', + topic_delete_reason text(65535) NOT NULL DEFAULT '', + topic_delete_user INTEGER UNSIGNED NOT NULL DEFAULT '0' ); CREATE INDEX phpbb_topics_forum_id ON phpbb_topics (forum_id); CREATE INDEX phpbb_topics_forum_id_type ON phpbb_topics (forum_id, topic_type); CREATE INDEX phpbb_topics_last_post_time ON phpbb_topics (topic_last_post_time); -CREATE INDEX phpbb_topics_topic_approved ON phpbb_topics (topic_approved); -CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics (forum_id, topic_approved, topic_last_post_id); +CREATE INDEX phpbb_topics_topic_visibility ON phpbb_topics (topic_visibility); +CREATE INDEX phpbb_topics_forum_appr_last ON phpbb_topics (forum_id, topic_visibility, topic_last_post_id); CREATE INDEX phpbb_topics_fid_time_moved ON phpbb_topics (forum_id, topic_last_post_time, topic_moved_id); # Table: 'phpbb_topics_track' diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 93f163364b..9c470efcd9 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -311,7 +311,7 @@ $lang = array_merge($lang, array( // PHP info $lang = array_merge($lang, array( - 'ACP_PHP_INFO_EXPLAIN' => 'This page lists information on the version of PHP installed on this server. It includes details of loaded modules, available variables and default settings. This information may be useful when diagnosing problems. Please be aware that some hosting companies will limit what information is displayed here for security reasons. You are advised to not give out any details on this page except when asked by official team members on the support forums.', + 'ACP_PHP_INFO_EXPLAIN' => 'This page lists information on the version of PHP installed on this server. It includes details of loaded modules, available variables and default settings. This information may be useful when diagnosing problems. Please be aware that some hosting companies will limit what information is displayed here for security reasons. You are advised to not give out any details on this page except when asked by official team members on the support forums.', 'NO_PHPINFO_AVAILABLE' => 'Information about your PHP configuration is unable to be determined. Phpinfo() has been disabled for security reasons.', )); @@ -559,12 +559,17 @@ $lang = array_merge($lang, array( 'LOG_POST_APPROVED' => 'Approved post
    » %s', 'LOG_POST_DISAPPROVED' => 'Disapproved post “%1$s” with the following reason
    » %2$s', 'LOG_POST_EDITED' => 'Edited post “%1$s” written by
    » %2$s', + 'LOG_POST_RESTORED' => 'Restored post
    » %s', 'LOG_REPORT_CLOSED' => 'Closed report
    » %s', 'LOG_REPORT_DELETED' => 'Deleted report
    » %s', + 'LOG_RESTORE_TOPIC' => 'Restored topic “%1$s” written by
    » %2$s', + 'LOG_SOFTDELETE_POST' => 'Soft deleted post “%1$s” written by
    » %2$s', + 'LOG_SOFTDELETE_TOPIC' => 'Soft deleted topic “%1$s” written by
    » %2$s', 'LOG_SPLIT_DESTINATION' => 'Moved split posts
    » to %s', 'LOG_SPLIT_SOURCE' => 'Split posts
    » from %s', 'LOG_TOPIC_APPROVED' => 'Approved topic
    » %s', + 'LOG_TOPIC_RESTORED' => 'Restored topic
    » %s', 'LOG_TOPIC_DISAPPROVED' => 'Disapproved topic “%1$s” with the following reason
    %2$s', 'LOG_TOPIC_RESYNC' => 'Resynchronised topic counters
    » %s', 'LOG_TOPIC_TYPE_CHANGED' => 'Changed topic type
    » %s', @@ -601,7 +606,7 @@ $lang = array_merge($lang, array( 'LOG_FORUM_MOVE_UP' => 'Moved forum %1$s above %2$s', 'LOG_FORUM_SYNC' => 'Re-synchronised forum
    » %s', - 'LOG_GENERAL_ERROR' => 'A general error occured: %1$s
    » %2$s', + 'LOG_GENERAL_ERROR' => 'A general error occurred: %1$s
    » %2$s', 'LOG_GROUP_CREATED' => 'New usergroup created
    » %s', 'LOG_GROUP_DEFAULTS' => 'Group “%1$s” made default for members
    » %2$s', diff --git a/phpBB/language/en/acp/permissions.php b/phpBB/language/en/acp/permissions.php index cf5ad33bab..709836e828 100644 --- a/phpBB/language/en/acp/permissions.php +++ b/phpBB/language/en/acp/permissions.php @@ -52,7 +52,7 @@ $lang = array_merge($lang, array(
    -

    For further information on setting up and managing permissions on your phpBB3 board, please see Chapter 1.5 of our Quick Start Guide.

    +

    For further information on setting up and managing permissions on your phpBB3 board, please see Chapter 1.5 of our Quick Start Guide.

    ', 'ACL_NEVER' => 'Never', diff --git a/phpBB/language/en/acp/permissions_phpbb.php b/phpBB/language/en/acp/permissions_phpbb.php index 27ef714f8b..98679ad544 100644 --- a/phpBB/language/en/acp/permissions_phpbb.php +++ b/phpBB/language/en/acp/permissions_phpbb.php @@ -152,7 +152,8 @@ $lang = array_merge($lang, array( 'acl_f_announce' => array('lang' => 'Can post announcements', 'cat' => 'post'), 'acl_f_reply' => array('lang' => 'Can reply to topics', 'cat' => 'post'), 'acl_f_edit' => array('lang' => 'Can edit own posts', 'cat' => 'post'), - 'acl_f_delete' => array('lang' => 'Can delete own posts', 'cat' => 'post'), + 'acl_f_delete' => array('lang' => 'Can permanently delete own posts', 'cat' => 'post'), + 'acl_f_softdelete' => array('lang' => 'Can soft delete own posts
    Moderators, who have the approve posts permission, can restore soft deleted posts.', 'cat' => 'post'), 'acl_f_ignoreflood' => array('lang' => 'Can ignore flood limit', 'cat' => 'post'), 'acl_f_postcount' => array('lang' => 'Increment post counter
    Please note that this setting only affects new posts.', 'cat' => 'post'), 'acl_f_noapprove' => array('lang' => 'Can post without approval', 'cat' => 'post'), @@ -173,8 +174,9 @@ $lang = array_merge($lang, array( // Moderator Permissions $lang = array_merge($lang, array( 'acl_m_edit' => array('lang' => 'Can edit posts', 'cat' => 'post_actions'), - 'acl_m_delete' => array('lang' => 'Can delete posts', 'cat' => 'post_actions'), - 'acl_m_approve' => array('lang' => 'Can approve posts', 'cat' => 'post_actions'), + 'acl_m_delete' => array('lang' => 'Can permanently delete posts', 'cat' => 'post_actions'), + 'acl_m_softdelete' => array('lang' => 'Can soft delete posts
    Moderators, who have the approve posts permission, can restore soft deleted posts.', 'cat' => 'post_actions'), + 'acl_m_approve' => array('lang' => 'Can approve and restore posts', 'cat' => 'post_actions'), 'acl_m_report' => array('lang' => 'Can close and delete reports', 'cat' => 'post_actions'), 'acl_m_chgposter' => array('lang' => 'Can change post author', 'cat' => 'post_actions'), diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index 89e171744f..ea3eadb0dd 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -83,7 +83,8 @@ $lang = array_merge($lang, array( 'NUMBER' => 'Any series of digits', 'EMAIL' => 'A valid email address', 'URL' => 'A valid URL using any protocol (http, ftp, etc… cannot be used for javascript exploits). If none is given, “http://” is prefixed to the string.', - 'LOCAL_URL' => 'A local URL. The URL must be relative to the topic page and cannot contain a server name or protocol.', + 'LOCAL_URL' => 'A local URL. The URL must be relative to the topic page and cannot contain a server name or protocol, as links are prefixed with “%s”', + 'RELATIVE_URL' => 'A relative URL. You can use this to match parts of a URL, but be careful: a full URL is a valid relative URL. When you want to use relative URLs of your board, use the LOCAL_URL token.', 'COLOR' => 'A HTML colour, can be either in the numeric form #FF1234 or a CSS colour keyword such as fuchsia or InactiveBorder' ) )); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index cdfd3416f5..b188d90f3a 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -204,8 +204,8 @@ $lang = array_merge($lang, array( 'ERR_TEMPLATE_EVENT_LOCATION' => 'The specified template event location [%s] is improperly formatted.', 'ERR_TEMPLATE_COMPILATION' => 'The file could not be compiled: %s', 'ERR_UNABLE_TO_LOGIN' => 'The specified username or password is incorrect.', - 'ERR_UNWATCHING' => 'An error occured while trying to unsubscribe.', - 'ERR_WATCHING' => 'An error occured while trying to subscribe.', + 'ERR_UNWATCHING' => 'An error occurred while trying to unsubscribe.', + 'ERR_WATCHING' => 'An error occurred while trying to subscribe.', 'ERR_WRONG_PATH_TO_PHPBB' => 'The phpBB path specified appears to be invalid.', 'ERROR' => 'Error', 'EXPAND_VIEW' => 'Expand view', @@ -338,7 +338,7 @@ $lang = array_merge($lang, array( 'LAST_VISIT' => 'Last visit', 'LDAP_NO_LDAP_EXTENSION' => 'LDAP extension not available.', 'LDAP_NO_SERVER_CONNECTION' => 'Could not connect to LDAP server.', - 'LDAP_SEARCH_FAILED' => 'An error occured while searching the LDAP directory.', + 'LDAP_SEARCH_FAILED' => 'An error occurred while searching the LDAP directory.', 'LEGEND' => 'Legend', 'LOADING' => 'Loading', 'LOCATION' => 'Location', @@ -519,8 +519,12 @@ $lang = array_merge($lang, array( 'POSTS' => 'Posts', 'POSTS_UNAPPROVED' => 'At least one post in this topic has not been approved.', 'POST_BY_AUTHOR' => 'by', - 'POST_BY_FOE' => 'This post was made by %1$s who is currently on your ignore list. %2$sDisplay this post%3$s.', + 'POST_BY_FOE' => '%1$s, who is currently on your ignore list, made this post.', + 'POST_DISPLAY' => '%1$sDisplay this post%2$s.', 'POST_DAY' => '%.2f posts per day', + 'POST_DELETED' => 'Deleted post:', + 'POST_DELETED_BY' => '%2$s deleted the post by %1$s on %3$s.', + 'POST_DELETED_BY_REASON'=> '%2$s deleted the post by %1$s on %3$s for the following reason: %4$s', 'POST_DETAILS' => 'Post details', 'POST_NEW_TOPIC' => 'Post new topic', 'POST_PCT' => '%.2f%% of all posts', diff --git a/phpBB/language/en/help_faq.php b/phpBB/language/en/help_faq.php index 9500943b88..68dc05f992 100644 --- a/phpBB/language/en/help_faq.php +++ b/phpBB/language/en/help_faq.php @@ -328,7 +328,7 @@ $help = array( ), array( 0 => 'Who wrote this bulletin board?', - 1 => 'This software (in its unmodified form) is produced, released and is copyright phpBB Group. It is made available under the GNU General Public License and may be freely distributed. See the link for more details.' + 1 => 'This software (in its unmodified form) is produced, released and is copyright phpBB Group. It is made available under the GNU General Public License and may be freely distributed. See the link for more details.' ), array( 0 => 'Why isn’t X feature available?', diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index 7607512eab..be45047861 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -78,7 +78,7 @@ $lang = array_merge($lang, array( 'CONTINUE_OLD_CONVERSION' => 'Continue previously started conversion', 'CONVERT' => 'Convert', 'CONVERT_COMPLETE' => 'Conversion completed', - 'CONVERT_COMPLETE_EXPLAIN' => 'You have now successfully converted your board to phpBB 3.1. You can now login and access your board. Please ensure that the settings were transferred correctly before enabling your board by deleting the install directory. Remember that help on using phpBB is available online via the Documentation and the support forums.', + 'CONVERT_COMPLETE_EXPLAIN' => 'You have now successfully converted your board to phpBB 3.1. You can now login and access your board. Please ensure that the settings were transferred correctly before enabling your board by deleting the install directory. Remember that help on using phpBB is available online via the Documentation and the support forums.', 'CONVERT_INTRO' => 'Welcome to the phpBB Unified Convertor Framework', 'CONVERT_INTRO_BODY' => 'From here, you are able to import data from other (installed) board systems. The list below shows all the conversion modules currently available. If there is no convertor shown in this list for the board software you wish to convert from, please check our website where further conversion modules may be available for download.', 'CONVERT_NEW_CONVERSION' => 'New conversion', @@ -192,7 +192,7 @@ $lang = array_merge($lang, array(

    Convert an existing board to phpBB3

    The phpBB Unified Convertor Framework supports the conversion of phpBB 2.0.x and other board systems to phpBB3. If you have an existing board that you wish to convert, please proceed to the convertor.

    Go live with your phpBB3!

    -

    Clicking the button below will take you to a form for submitting statistical data to phpBB in your Administration Control Panel (ACP). We would appreciate it if you could help us by sending that information. Afterwards you should take some time to examine the options available to you. Remember that help is available online via the Documentation, README and the Support Forums.

    Please delete, move or rename the install directory before using your board. While this directory exists, only the Administration Control Panel (ACP) will be accessible.', +

    Clicking the button below will take you to a form for submitting statistical data to phpBB in your Administration Control Panel (ACP). We would appreciate it if you could help us by sending that information. Afterwards you should take some time to examine the options available to you. Remember that help is available online via the Documentation, README and the Support Forums.

    Please delete, move or rename the install directory before using your board. While this directory exists, only the Administration Control Panel (ACP) will be accessible.', 'INSTALL_INTRO' => 'Welcome to Installation', 'INSTALL_INTRO_BODY' => 'With this option, it is possible to install phpBB3 onto your server.

    In order to proceed, you will need your database settings. If you do not know your database settings, please contact your host and ask for them. You will not be able to continue without them. You need:

    @@ -275,7 +275,7 @@ $lang = array_merge($lang, array( 'MAKE_FOLDER_WRITABLE' => 'Please make sure that this folder exists and is writable by the webserver then try again:
    »%s.', 'MAKE_FOLDERS_WRITABLE' => 'Please make sure that these folders exist and are writable by the webserver then try again:
    »%s.', - 'MYSQL_SCHEMA_UPDATE_REQUIRED' => 'Your MySQL database schema for phpBB is outdated. phpBB detected a schema for MySQL 3.x/4.x, but the server runs on MySQL %2$s.
    Before you proceed the update, you need to upgrade the schema.

    Please refer to the Knowledge Base article about upgrading the MySQL schema. If you encounter problems, please use our support forums.', + 'MYSQL_SCHEMA_UPDATE_REQUIRED' => 'Your MySQL database schema for phpBB is outdated. phpBB detected a schema for MySQL 3.x/4.x, but the server runs on MySQL %2$s.
    Before you proceed the update, you need to upgrade the schema.

    Please refer to the Knowledge Base article about upgrading the MySQL schema. If you encounter problems, please use our support forums.', 'NAMING_CONFLICT' => 'Naming conflict: %s and %s are both aliases

    %s', 'NEXT_STEP' => 'Proceed to next step', @@ -286,7 +286,7 @@ $lang = array_merge($lang, array( 'NO_LOCATION' => 'Cannot determine location. If you know Imagemagick is installed, you may specify the location later within your administration control panel', 'NO_TABLES_FOUND' => 'No tables found.', - 'OVERVIEW_BODY' => 'Welcome to phpBB3!

    phpBB™ is the most widely used open source bulletin board solution in the world. phpBB3 is the latest installment in a package line started in 2000. Like its predecessors, phpBB3 is feature-rich, user-friendly, and fully supported by the phpBB Team. phpBB3 greatly improves on what made phpBB2 popular, and adds commonly requested features that were not present in previous versions. We hope it exceeds your expectations.

    This installation system will guide you through installing phpBB3, updating to the latest version of phpBB3 from past releases, as well as converting to phpBB3 from a different discussion board system (including phpBB2). For more information, we encourage you to read the installation guide.

    To read the phpBB3 license or learn about obtaining support and our stance on it, please select the respective options from the side menu. To continue, please select the appropriate tab above.', + 'OVERVIEW_BODY' => 'Welcome to phpBB3!

    phpBB® is the most widely used open source bulletin board solution in the world. phpBB3 is the latest installment in a package line started in 2000. Like its predecessors, phpBB3 is feature-rich, user-friendly, and fully supported by the phpBB Team. phpBB3 greatly improves on what made phpBB2 popular, and adds commonly requested features that were not present in previous versions. We hope it exceeds your expectations.

    This installation system will guide you through installing phpBB3, updating to the latest version of phpBB3 from past releases, as well as converting to phpBB3 from a different discussion board system (including phpBB2). For more information, we encourage you to read the installation guide.

    To read the phpBB3 license or learn about obtaining support and our stance on it, please select the respective options from the side menu. To continue, please select the appropriate tab above.', 'PCRE_UTF_SUPPORT' => 'PCRE UTF-8 support', 'PCRE_UTF_SUPPORT_EXPLAIN' => 'phpBB will not run if your PHP installation is not compiled with UTF-8 support in the PCRE extension.', @@ -346,7 +346,7 @@ $lang = array_merge($lang, array( 'SUB_LICENSE' => 'License', 'SUB_SUPPORT' => 'Support', 'SUCCESSFUL_CONNECT' => 'Successful connection', - 'SUPPORT_BODY' => 'Full support will be provided for the current stable release of phpBB3, free of charge. This includes:

    • installation
    • configuration
    • technical questions
    • problems relating to potential bugs in the software
    • updating from Release Candidate (RC) versions to the latest stable version
    • converting from phpBB 2.0.x to phpBB3
    • converting from other discussion board software to phpBB3 (please see the Convertors Forum)

    We encourage users still running beta versions of phpBB3 to replace their installation with a fresh copy of the latest version.

    MODs / Styles

    For issues relating to MODs, please post in the appropriate Modifications Forum.
    For issues relating to styles, templates and themes, please post in the appropriate Styles Forum.

    If your question relates to a specific package, please post directly in the topic dedicated to the package.

    Obtaining Support

    The phpBB Welcome Package
    Support Section
    Quick Start Guide

    To ensure you stay up to date with the latest news and releases, why not subscribe to our mailing list?

    ', + 'SUPPORT_BODY' => 'Full support will be provided for the current stable release of phpBB3, free of charge. This includes:

    • installation
    • configuration
    • technical questions
    • problems relating to potential bugs in the software
    • updating from Release Candidate (RC) versions to the latest stable version
    • converting from phpBB 2.0.x to phpBB3
    • converting from other discussion board software to phpBB3 (please see the Convertors Forum)

    We encourage users still running beta versions of phpBB3 to replace their installation with a fresh copy of the latest version.

    MODs / Styles

    For issues relating to MODs, please post in the appropriate Modifications Forum.
    For issues relating to styles, templates and themes, please post in the appropriate Styles Forum.

    If your question relates to a specific package, please post directly in the topic dedicated to the package.

    Obtaining Support

    The phpBB Welcome Package
    Support Section
    Quick Start Guide

    To ensure you stay up to date with the latest news and releases, why not subscribe to our mailing list?

    ', 'SYNC_FORUMS' => 'Starting to synchronise forums', 'SYNC_POST_COUNT' => 'Synchronising post_counts', 'SYNC_POST_COUNT_ID' => 'Synchronising post_counts from entry %1$s to %2$s.', @@ -364,7 +364,7 @@ $lang = array_merge($lang, array( 'UNAVAILABLE' => 'Unavailable', 'UNWRITABLE' => 'Unwritable', 'UPDATE_TOPICS_POSTED' => 'Generating topics posted information', - 'UPDATE_TOPICS_POSTED_ERR' => 'An error occured while generating topics posted information. You can retry this step in the ACP after the conversion process is completed.', + 'UPDATE_TOPICS_POSTED_ERR' => 'An error occurred while generating topics posted information. You can retry this step in the ACP after the conversion process is completed.', 'VERIFY_OPTIONS' => 'Verifying conversion options', 'VERSION' => 'Version', @@ -472,7 +472,7 @@ $lang = array_merge($lang, array( 'NO_ERRORS' => 'No errors', 'NO_UPDATE_FILES' => 'Not updating the following files', 'NO_UPDATE_FILES_EXPLAIN' => 'The following files are new or modified but the directory they normally reside in could not be found on your installation. If this list contains files to other directories than language/ or styles/ than you may have modified your directory structure and the update may be incomplete.', - 'NO_UPDATE_FILES_OUTDATED' => 'No valid update directory was found, please make sure you uploaded the relevant files.

    Your installation does not seem to be up to date. Updates are available for your version of phpBB %1$s, please visit http://www.phpbb.com/downloads/ to obtain the correct package to update from Version %2$s to Version %3$s.', + 'NO_UPDATE_FILES_OUTDATED' => 'No valid update directory was found, please make sure you uploaded the relevant files.

    Your installation does not seem to be up to date. Updates are available for your version of phpBB %1$s, please visit https://www.phpbb.com/downloads/ to obtain the correct package to update from Version %2$s to Version %3$s.', 'NO_UPDATE_FILES_UP_TO_DATE' => 'Your version is up to date. There is no need to run the update tool. If you want to make an integrity check on your files make sure you uploaded the correct update files.', 'NO_UPDATE_INFO' => 'Update file information could not be found.', 'NO_UPDATES_REQUIRED' => 'No updates required', @@ -540,7 +540,7 @@ $lang = array_merge($lang, array(

    The recommended way of updating your installation listed here is only valid for the automatic update package. You are also able to update your installation using the methods listed within the INSTALL.html document. The steps for updating phpBB3 automatically are:

      -
    • Go to the phpBB.com downloads page and download the "Automatic Update Package" archive.

    • +
    • Go to the phpBB.com downloads page and download the "Automatic Update Package" archive.

    • Unpack the archive.

    • Upload the complete uncompressed install folder to your phpBB root directory (where your config.php file is).

    diff --git a/phpBB/language/en/mcp.php b/phpBB/language/en/mcp.php index 29f418183f..b75e0ea495 100644 --- a/phpBB/language/en/mcp.php +++ b/phpBB/language/en/mcp.php @@ -52,6 +52,10 @@ $lang = array_merge($lang, array( 'APPROVE_POST_CONFIRM' => 'Are you sure you want to approve this post?', 'APPROVE_POSTS' => 'Approve posts', 'APPROVE_POSTS_CONFIRM' => 'Are you sure you want to approve the selected posts?', + 'APPROVE_TOPIC' => 'Approve topic', + 'APPROVE_TOPIC_CONFIRM' => 'Are you sure you want to approve this topic?', + 'APPROVE_TOPICS' => 'Approve topics', + 'APPROVE_TOPICS_CONFIRM'=> 'Are you sure you want to approve the selected topics?', 'CANNOT_MOVE_SAME_FORUM'=> 'You cannot move a topic to the forum it’s already in.', 'CANNOT_WARN_ANONYMOUS' => 'You cannot warn unregistered guest users.', @@ -72,16 +76,12 @@ $lang = array_merge($lang, array( 'DELETE_PM_REPORTS' => 'Delete PM reports', 'DELETE_PM_REPORTS_CONFIRM' => 'Are you sure you want to delete the selected PM reports?', 'DELETE_POSTS' => 'Delete posts', - 'DELETE_POSTS_CONFIRM' => 'Are you sure you want to delete these posts?', - 'DELETE_POST_CONFIRM' => 'Are you sure you want to delete this post?', 'DELETE_REPORT' => 'Delete report', 'DELETE_REPORT_CONFIRM' => 'Are you sure you want to delete the selected report?', 'DELETE_REPORTS' => 'Delete reports', 'DELETE_REPORTS_CONFIRM' => 'Are you sure you want to delete the selected reports?', 'DELETE_SHADOW_TOPIC' => 'Delete shadow topic', 'DELETE_TOPICS' => 'Delete selected topics', - 'DELETE_TOPICS_CONFIRM' => 'Are you sure you want to delete these topics?', - 'DELETE_TOPIC_CONFIRM' => 'Are you sure you want to delete this topic?', 'DISAPPROVE' => 'Disapprove', 'DISAPPROVE_REASON' => 'Reason for disapproval', 'DISAPPROVE_POST' => 'Disapprove post', @@ -201,6 +201,10 @@ $lang = array_merge($lang, array( 'MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN' => 'This is a list of all posts which require approving before they will be visible to users.', 'MCP_QUEUE_UNAPPROVED_TOPICS' => 'Topics awaiting approval', 'MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN' => 'This is a list of all topics which require approving before they will be visible to users.', + 'MCP_QUEUE_DELETED_POSTS' => 'Deleted posts', + 'MCP_QUEUE_DELETED_POSTS_EXPLAIN' => 'This is a list of all soft deleted posts. You can restore or permanently delete the posts from this screen.', + 'MCP_QUEUE_DELETED_TOPICS' => 'Deleted topics', + 'MCP_QUEUE_DELETED_TOPICS_EXPLAIN' => 'This is a list of all soft deleted topics. You can restore or permanently delete the topics from this screen.', 'MCP_VIEW_USER' => 'View warnings for a specific user', @@ -238,6 +242,7 @@ $lang = array_merge($lang, array( 'NO_POST' => 'You have to select a post in order to warn the user for a post.', 'NO_POST_REPORT' => 'This post was not reported.', 'NO_POST_SELECTED' => 'You must select at least one post to perform this action.', + 'NO_POSTS_DELETED' => 'There are no deleted posts.', 'NO_POSTS_QUEUE' => 'There are no posts waiting for approval.', 'NO_REASON_DISAPPROVAL' => 'Please give an appropriate reason for disapproval.', 'NO_REPORT' => 'No report found', @@ -245,6 +250,7 @@ $lang = array_merge($lang, array( 'NO_REPORT_SELECTED' => 'You must select at least one report to perform this action.', 'NO_TOPIC_ICON' => 'None', 'NO_TOPIC_SELECTED' => 'You must select at least one topic to perform this action.', + 'NO_TOPICS_DELETED' => 'There are no deleted topics.', 'NO_TOPICS_QUEUE' => 'There are no topics waiting for approval.', 'ONLY_TOPIC' => 'Only topic “%s”', @@ -269,15 +275,17 @@ $lang = array_merge($lang, array( 'POSTS_DISAPPROVED_SUCCESS' => 'The selected posts have been disapproved.', 'POSTS_LOCKED_SUCCESS' => 'The selected posts have been locked successfully.', 'POSTS_MERGED_SUCCESS' => 'The selected posts have been merged.', - 'POSTS_UNLOCKED_SUCCESS' => 'The selected posts have been unlocked successfully.', 'POSTS_PER_PAGE' => 'Posts per page', 'POSTS_PER_PAGE_EXPLAIN' => '(Set to 0 to view all posts.)', + 'POSTS_RESTORED_SUCCESS' => 'The selected posts have been restored successfully.', + 'POSTS_UNLOCKED_SUCCESS' => 'The selected posts have been unlocked successfully.', 'POST_APPROVED_SUCCESS' => 'The selected post has been approved.', 'POST_DELETED_SUCCESS' => 'The selected post has been successfully removed from the database.', 'POST_DISAPPROVED_SUCCESS' => 'The selected post has been disapproved.', 'POST_LOCKED_SUCCESS' => 'Post locked successfully.', 'POST_NOT_EXIST' => 'The post you requested does not exist.', 'POST_REPORTED_SUCCESS' => 'This post has been successfully reported.', + 'POST_RESTORED_SUCCESS' => 'This post has been restored successfully.', 'POST_UNLOCKED_SUCCESS' => 'Post unlocked successfully.', 'READ_USERNOTES' => 'User notes', @@ -304,6 +312,15 @@ $lang = array_merge($lang, array( 'REPORT_POST_EXPLAIN' => 'Use this form to report the selected post to the forum moderators and board administrators. Reporting should generally be used only if the post breaks forum rules.', 'REPORT_REASON' => 'Report reason', 'REPORT_TIME' => 'Report time', + 'RESTORE' => 'Restore', + 'RESTORE_POST' => 'Restore post', + 'RESTORE_POST_CONFIRM' => 'Are you sure you want to restore this post?', + 'RESTORE_POSTS' => 'Restore posts', + 'RESTORE_POSTS_CONFIRM' => 'Are you sure you want to restore the selected posts?', + 'RESTORE_TOPIC' => 'Restore topic', + 'RESTORE_TOPIC_CONFIRM' => 'Are you sure you want to restore this topic?', + 'RESTORE_TOPICS' => 'Restore topics', + 'RESTORE_TOPICS_CONFIRM' => 'Are you sure you want to restore the selected topics?', 'RESYNC' => 'Resync', 'RETURN_MESSAGE' => '%sReturn to the message%s', 'RETURN_NEW_FORUM' => '%sGo to the new forum%s', @@ -344,6 +361,7 @@ $lang = array_merge($lang, array( 'TOPICS_FORKED_SUCCESS' => 'The selected topics have been copied successfully.', 'TOPICS_LOCKED_SUCCESS' => 'The selected topics have been locked.', 'TOPICS_MOVED_SUCCESS' => 'The selected topics have been moved successfully.', + 'TOPICS_RESTORED_SUCCESS' => 'The selected topics have been restored successfully.', 'TOPICS_RESYNC_SUCCESS' => 'The selected topics have been resynchronised.', 'TOPICS_TYPE_CHANGED' => 'Topic types changed successfully.', 'TOPICS_UNLOCKED_SUCCESS' => 'The selected topics have been unlocked.', @@ -354,6 +372,7 @@ $lang = array_merge($lang, array( 'TOPIC_LOCKED_SUCCESS' => 'The selected topic has been locked.', 'TOPIC_MOVED_SUCCESS' => 'The selected topic has been moved successfully.', 'TOPIC_NOT_EXIST' => 'The topic you selected does not exist.', + 'TOPIC_RESTORED_SUCCESS' => 'The selected topic has been restored successfully.', 'TOPIC_RESYNC_SUCCESS' => 'The selected topic has been resynchronised.', 'TOPIC_SPLIT_SUCCESS' => 'The selected topic has been split successfully.', 'TOPIC_TIME' => 'Topic time', diff --git a/phpBB/language/en/migrator.php b/phpBB/language/en/migrator.php index f94c27be8c..34dcbf4c52 100644 --- a/phpBB/language/en/migrator.php +++ b/phpBB/language/en/migrator.php @@ -45,7 +45,7 @@ $lang = array_merge($lang, array( 'MIGRATION_NOT_FULFILLABLE' => 'The migration "%1$s" is not fulfillable, missing migration "%2$s".', 'MIGRATION_SCHEMA_DONE' => 'Installed Schema: %s', - 'MODULE_ERROR' => 'An error occured while creating a module: %s', + 'MODULE_ERROR' => 'An error occurred while creating a module: %s', 'MODULE_INFO_FILE_NOT_EXIST' => 'A required module info file is missing: %2$s', 'MODULE_NOT_EXIST' => 'A required module does not exist: %s', diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index 7651ff2b63..0e8d59a92e 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -77,8 +77,20 @@ $lang = array_merge($lang, array( 'DELETE_MESSAGE' => 'Delete message', 'DELETE_MESSAGE_CONFIRM' => 'Are you sure you want to delete this message?', 'DELETE_OWN_POSTS' => 'Sorry but you can only delete your own posts.', + 'DELETE_PERMANENTLY' => 'Delete permanently', 'DELETE_POST_CONFIRM' => 'Are you sure you want to delete this post?', - 'DELETE_POST_WARN' => 'Once deleted the post cannot be recovered', + 'DELETE_POST_PERMANENTLY_CONFIRM' => 'Are you sure you want to permanently delete this post?', + 'DELETE_POST_PERMANENTLY' => 'Permanently delete this post so it can not be recovered', + 'DELETE_POSTS_CONFIRM' => 'Are you sure you want to delete these posts?', + 'DELETE_POSTS_PERMANENTLY_CONFIRM' => 'Are you sure you want to permanently delete these posts?', + 'DELETE_REASON' => 'Soft delete reason', + 'DELETE_REASON_EXPLAIN' => 'The specified reason for deletion will be visible to moderators.', + 'DELETE_POST_WARN' => 'Deleted this post', + 'DELETE_TOPIC_CONFIRM' => 'Are you sure you want to delete this topic?', + 'DELETE_TOPIC_PERMANENTLY' => 'Permanently delete this topic so it can not be recovered', + 'DELETE_TOPIC_PERMANENTLY_CONFIRM' => 'Are you sure you want to permanently delete this topic?', + 'DELETE_TOPICS_CONFIRM' => 'Are you sure you want to delete these topics?', + 'DELETE_TOPICS_PERMANENTLY_CONFIRM' => 'Are you sure you want to permanently delete these topics?', 'DISABLE_BBCODE' => 'Disable BBCode', 'DISABLE_MAGIC_URL' => 'Do not automatically parse URLs', 'DISABLE_SMILIES' => 'Disable smilies', diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index a91b6b84d5..51823ddb12 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -38,7 +38,7 @@ if (empty($lang) || !is_array($lang)) $lang = array_merge($lang, array( 'TERMS_OF_USE_CONTENT' => 'By accessing “%1$s” (hereinafter “we”, “us”, “our”, “%1$s”, “%2$s”), you agree to be legally bound by the following terms. If you do not agree to be legally bound by all of the following terms then please do not access and/or use “%1$s”. We may change these at any time and we’ll do our utmost in informing you, though it would be prudent to review this regularly yourself as your continued usage of “%1$s” after changes mean you agree to be legally bound by these terms as they are updated and/or amended.

    - Our forums are powered by phpBB (hereinafter “they”, “them”, “their”, “phpBB software”, “www.phpbb.com”, “phpBB Group”, “phpBB Teams”) which is a bulletin board solution released under the “GNU General Public License v2” (hereinafter “GPL”) and can be downloaded from www.phpbb.com. The phpBB software only facilitates internet based discussions, the phpBB Group are not responsible for what we allow and/or disallow as permissible content and/or conduct. For further information about phpBB, please see: http://www.phpbb.com/.
    + Our forums are powered by phpBB (hereinafter “they”, “them”, “their”, “phpBB software”, “www.phpbb.com”, “phpBB Group”, “phpBB Teams”) which is a bulletin board solution released under the “GNU General Public License v2” (hereinafter “GPL”) and can be downloaded from www.phpbb.com. The phpBB software only facilitates internet based discussions, the phpBB Group are not responsible for what we allow and/or disallow as permissible content and/or conduct. For further information about phpBB, please see: https://www.phpbb.com/.

    You agree not to post any abusive, obscene, vulgar, slanderous, hateful, threatening, sexually-orientated or any other material that may violate any laws be it of your country, the country where “%1$s” is hosted or International Law. Doing so may lead to you being immediately and permanently banned, with notification of your Internet Service Provider if deemed required by us. The IP address of all posts are recorded to aid in enforcing these conditions. You agree that “%1$s” have the right to remove, edit, move or close any topic at any time should we see fit. As a user you agree to any information you have entered to being stored in a database. While this information will not be disclosed to any third party without your consent, neither “%1$s” nor phpBB shall be held responsible for any hacking attempt that may lead to the data being compromised. ', diff --git a/phpBB/language/en/viewtopic.php b/phpBB/language/en/viewtopic.php index 278c064fe7..6f318c39f1 100644 --- a/phpBB/language/en/viewtopic.php +++ b/phpBB/language/en/viewtopic.php @@ -50,6 +50,7 @@ $lang = array_merge($lang, array( 'CODE' => 'Code', 'DELETE_TOPIC' => 'Delete topic', + 'DELETED_INFORMATION' => 'Deleted by %1$s on %2$s', 'DISAPPROVE' => 'Disapprove', 'DOWNLOAD_NOTICE' => 'You do not have the required permissions to view the files attached to this post.', @@ -89,6 +90,7 @@ $lang = array_merge($lang, array( 'POLL_ENDED_AT' => 'Poll ended at %s', 'POLL_RUN_TILL' => 'Poll runs till %s', 'POLL_VOTED_OPTION' => 'You voted for this option', + 'POST_DELETED_RESTORE' => 'This post has been deleted. It can be restored.', 'PRINT_TOPIC' => 'Print view', 'QUICK_MOD' => 'Quick-mod tools', @@ -96,6 +98,8 @@ $lang = array_merge($lang, array( 'QUOTE' => 'Quote', 'REPLY_TO_TOPIC' => 'Reply to topic', + 'RESTORE' => 'Restore', + 'RESTORE_TOPIC' => 'Restore topic', 'RETURN_POST' => '%sReturn to the post%s', 'SUBMIT_VOTE' => 'Submit vote', diff --git a/phpBB/mcp.php b/phpBB/mcp.php index c36faad74b..5beea45c7d 100644 --- a/phpBB/mcp.php +++ b/phpBB/mcp.php @@ -158,6 +158,7 @@ if ($quickmod) case 'move': case 'delete_post': case 'delete_topic': + case 'restore_topic': $module->load('mcp', 'main', 'quickmod'); return; break; @@ -199,7 +200,7 @@ if (!$post_id) $module->set_display('warn', 'warn_post', false); } -if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts') +if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts' || $mode == 'deleted_topics' || $mode == 'deleted_posts') { $module->set_display('queue', 'approve_details', false); } @@ -483,7 +484,7 @@ function get_post_data($post_ids, $acl_list = false, $read_tracking = false) continue; } - if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) + if ($row['post_visibility'] != ITEM_APPROVED && !$auth->acl_get('m_approve', $row['forum_id'])) { // Moderators without the permission to approve post should at least not see them. ;) continue; @@ -501,7 +502,7 @@ function get_post_data($post_ids, $acl_list = false, $read_tracking = false) */ function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false) { - global $auth, $db, $user, $config; + global $auth, $db, $user, $config, $phpbb_container; $rowset = array(); @@ -531,6 +532,8 @@ function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false) WHERE " . $db->sql_in_set('f.forum_id', $forum_id); $result = $db->sql_query($sql); + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + while ($row = $db->sql_fetchrow($result)) { if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) @@ -538,10 +541,7 @@ function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false) continue; } - if ($auth->acl_get('m_approve', $row['forum_id'])) - { - $row['forum_topics'] = $row['forum_topics_real']; - } + $row['forum_topics_approved'] = $phpbb_content_visibility->get_count('forum_topics', $row, $row['forum_id']); $rowset[$row['forum_id']] = $row; } @@ -619,7 +619,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, if (!$auth->acl_get('m_approve', $forum_id)) { - $sql .= 'AND topic_approved = 1'; + $sql .= 'AND topic_visibility = ' . ITEM_APPROVED; } break; @@ -635,11 +635,13 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, if (!$auth->acl_get('m_approve', $forum_id)) { - $sql .= 'AND post_approved = 1'; + $sql .= 'AND post_visibility = ' . ITEM_APPROVED; } break; case 'unapproved_posts': + case 'deleted_posts': + $visibility_const = ($mode == 'unapproved_posts') ? ITEM_UNAPPROVED : ITEM_DELETED; $type = 'posts'; $default_key = 't'; $default_dir = 'd'; @@ -648,9 +650,9 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, $sql = 'SELECT COUNT(p.post_id) AS total FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t $where_sql " . $db->sql_in_set('p.forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . ' - AND p.post_approved = 0 + AND p.post_visibility = ' . $visibility_const . ' AND t.topic_id = p.topic_id - AND t.topic_first_post_id <> p.post_id'; + AND t.topic_visibility <> p.post_visibility'; if ($min_time) { @@ -659,6 +661,8 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, break; case 'unapproved_topics': + case 'deleted_topics': + $visibility_const = ($mode == 'unapproved_topics') ? ITEM_UNAPPROVED : ITEM_DELETED; $type = 'topics'; $default_key = 't'; $default_dir = 'd'; @@ -666,7 +670,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, $sql = 'SELECT COUNT(topic_id) AS total FROM ' . TOPICS_TABLE . " $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . ' - AND topic_approved = 0'; + AND topic_visibility = ' . $visibility_const; if ($min_time) { @@ -748,7 +752,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); - $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views'); + $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_posts_approved + t.topic_posts_unapproved + t.topic_posts_softdeleted' : 't.topic_posts_approved'), 's' => 't.topic_title', 'v' => 't.topic_views'); $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : ''; break; @@ -796,7 +800,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, 'S_SELECT_SORT_DAYS' => $s_limit_days) ); - if (($sort_days && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts')) || $where_sql != 'WHERE') + if (($sort_days && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts', 'deleted_topics', 'deleted_posts')) || $where_sql != 'WHERE') { $result = $db->sql_query($sql); $total = (int) $db->sql_fetchfield('total'); diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 7ecf332720..46136dbdd4 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -638,7 +638,7 @@ switch ($mode) $sql = 'SELECT COUNT(post_id) as posts_in_queue FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $user_id . ' - AND post_approved = 0'; + AND post_visibility = ' . ITEM_UNAPPROVED; $result = $db->sql_query($sql); $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue'); $db->sql_freeresult($result); diff --git a/phpBB/includes/auth/auth.php b/phpBB/phpbb/auth/auth.php similarity index 99% rename from phpBB/includes/auth/auth.php rename to phpBB/phpbb/auth/auth.php index 2535247571..279959974d 100644 --- a/phpBB/includes/auth/auth.php +++ b/phpBB/phpbb/auth/auth.php @@ -927,15 +927,14 @@ class phpbb_auth */ function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0) { - global $config, $db, $user, $phpbb_root_path, $phpEx; + global $config, $db, $user, $phpbb_root_path, $phpEx, $phpbb_container; $method = trim(basename($config['auth_method'])); - include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); - $method = 'login_' . $method; - if (function_exists($method)) + $provider = $phpbb_container->get('auth.provider.' . $method); + if ($provider) { - $login = $method($username, $password, $user->ip, $user->browser, $user->forwarded_for); + $login = $provider->login($username, $password); // 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/index.htm b/phpBB/phpbb/auth/index.htm similarity index 100% rename from phpBB/includes/auth/index.htm rename to phpBB/phpbb/auth/index.htm diff --git a/phpBB/phpbb/auth/provider/apache.php b/phpBB/phpbb/auth/provider/apache.php new file mode 100644 index 0000000000..2e80436f78 --- /dev/null +++ b/phpBB/phpbb/auth/provider/apache.php @@ -0,0 +1,259 @@ +db = $db; + $this->config = $config; + $this->request = $request; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * {@inheritdoc} + */ + public function init() + { + if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER) || $this->user->data['username'] !== htmlspecialchars_decode($this->request->server('PHP_AUTH_USER'))) + { + return $this->user->lang['APACHE_SETUP_BEFORE_USE']; + } + return false; + } + + /** + * {@inheritdoc} + */ + public function login($username, $password) + { + // do not allow empty password + if (!$password) + { + return array( + 'status' => LOGIN_ERROR_PASSWORD, + 'error_msg' => 'NO_PASSWORD_SUPPLIED', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + if (!$username) + { + return array( + 'status' => LOGIN_ERROR_USERNAME, + 'error_msg' => 'LOGIN_ERROR_USERNAME', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) + { + return array( + 'status' => LOGIN_ERROR_EXTERNAL_AUTH, + 'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + $php_auth_user = htmlspecialchars_decode($this->request->server('PHP_AUTH_USER')); + $php_auth_pw = htmlspecialchars_decode($this->request->server('PHP_AUTH_PW')); + + if (!empty($php_auth_user) && !empty($php_auth_pw)) + { + if ($php_auth_user !== $username) + { + return array( + 'status' => LOGIN_ERROR_USERNAME, + 'error_msg' => 'LOGIN_ERROR_USERNAME', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type + FROM ' . USERS_TABLE . " + WHERE username = '" . $this->db->sql_escape($php_auth_user) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + // User inactive... + if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) + { + return array( + 'status' => LOGIN_ERROR_ACTIVE, + 'error_msg' => 'ACTIVE_ERROR', + 'user_row' => $row, + ); + } + + // Successful login... + return array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => $row, + ); + } + + // this is the user's first login so create an empty profile + return array( + 'status' => LOGIN_SUCCESS_CREATE_PROFILE, + 'error_msg' => false, + 'user_row' => user_row_apache($php_auth_user, $php_auth_pw), + ); + } + + // Not logged into apache + return array( + 'status' => LOGIN_ERROR_EXTERNAL_AUTH, + 'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + /** + * {@inheritdoc} + */ + public function autologin() + { + if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) + { + return array(); + } + + $php_auth_user = htmlspecialchars_decode($this->request->server('PHP_AUTH_USER')); + $php_auth_pw = htmlspecialchars_decode($this->request->server('PHP_AUTH_PW')); + + if (!empty($php_auth_user) && !empty($php_auth_pw)) + { + set_var($php_auth_user, $php_auth_user, 'string', true); + set_var($php_auth_pw, $php_auth_pw, 'string', true); + + $sql = 'SELECT * + FROM ' . USERS_TABLE . " + WHERE username = '" . $this->db->sql_escape($php_auth_user) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) ? array() : $row; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + // create the user if he does not exist yet + user_add(user_row_apache($php_auth_user, $php_auth_pw)); + + $sql = 'SELECT * + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($php_auth_user)) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return $row; + } + } + + return array(); + } + + /** + * This function generates an array which can be passed to the user_add + * function in order to create a user + * + * @param string $username The username of the new user. + * @param string $password The password of the new user. + * @return array Contains data that can be passed directly to + * the user_add function. + */ + private function user_row($username, $password) + { + // first retrieve default group id + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "' + AND group_type = " . GROUP_SPECIAL; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + trigger_error('NO_GROUP'); + } + + // generate user account data + return array( + 'username' => $username, + 'user_password' => phpbb_hash($password), + 'user_email' => '', + 'group_id' => (int) $row['group_id'], + 'user_type' => USER_NORMAL, + 'user_ip' => $this->user->ip, + 'user_new' => ($this->config['new_member_post_limit']) ? 1 : 0, + ); + } + + /** + * {@inheritdoc} + */ + public function validate_session($user) + { + // Check if PHP_AUTH_USER is set and handle this case + if ($this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) + { + $php_auth_user = $this->request->server('PHP_AUTH_USER'); + + return ($php_auth_user === $user['username']) ? true : false; + } + + // PHP_AUTH_USER is not set. A valid session is now determined by the user type (anonymous/bot or not) + if ($user['user_type'] == USER_IGNORE) + { + return true; + } + + return false; + } +} diff --git a/phpBB/phpbb/auth/provider/base.php b/phpBB/phpbb/auth/provider/base.php new file mode 100644 index 0000000000..7eaf8bb2d3 --- /dev/null +++ b/phpBB/phpbb/auth/provider/base.php @@ -0,0 +1,72 @@ +db = $db; + $this->config = $config; + $this->request = $request; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * {@inheritdoc} + */ + public function login($username, $password) + { + // Auth plugins get the password untrimmed. + // For compatibility we trim() here. + $password = trim($password); + + // do not allow empty password + if (!$password) + { + return array( + 'status' => LOGIN_ERROR_PASSWORD, + 'error_msg' => 'NO_PASSWORD_SUPPLIED', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + if (!$username) + { + return array( + 'status' => LOGIN_ERROR_USERNAME, + 'error_msg' => 'LOGIN_ERROR_USERNAME', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + $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 = '" . $this->db->sql_escape($username_clean) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (($this->user->ip && !$this->config['ip_login_limit_use_forwarded']) || + ($this->user->forwarded_for && $this->config['ip_login_limit_use_forwarded'])) + { + $sql = 'SELECT COUNT(*) AS attempts + FROM ' . LOGIN_ATTEMPT_TABLE . ' + WHERE attempt_time > ' . (time() - (int) $this->config['ip_login_limit_time']); + if ($this->config['ip_login_limit_use_forwarded']) + { + $sql .= " AND attempt_forwarded_for = '" . $this->db->sql_escape($this->user->forwarded_for) . "'"; + } + else + { + $sql .= " AND attempt_ip = '" . $this->db->sql_escape($this->user->ip) . "' "; + } + + $result = $this->db->sql_query($sql); + $attempts = (int) $this->db->sql_fetchfield('attempts'); + $this->db->sql_freeresult($result); + + $attempt_data = array( + 'attempt_ip' => $this->user->ip, + 'attempt_browser' => trim(substr($this->user->browser, 0, 149)), + 'attempt_forwarded_for' => $this->user->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 . $this->db->sql_build_array('INSERT', $attempt_data); + $result = $this->db->sql_query($sql); + } + else + { + $attempts = 0; + } + + if (!$row) + { + if ($this->config['ip_login_limit_max'] && $attempts >= $this->config['ip_login_limit_max']) + { + return array( + 'status' => LOGIN_ERROR_ATTEMPTS, + 'error_msg' => 'LOGIN_ERROR_ATTEMPTS', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + return array( + 'status' => LOGIN_ERROR_USERNAME, + 'error_msg' => 'LOGIN_ERROR_USERNAME', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + $show_captcha = ($this->config['max_login_attempts'] && $row['user_login_attempts'] >= $this->config['max_login_attempts']) || + ($this->config['ip_login_limit_max'] && $attempts >= $this->config['ip_login_limit_max']); + + // If there are too many login attempts, we need to check for a confirm image + // Every auth module is able to define what to do by itself... + if ($show_captcha) + { + // Visual Confirmation handling + if (!class_exists('phpbb_captcha_factory', false)) + { + include ($this->phpbb_root_path . 'includes/captcha/captcha_factory.' . $this->php_ext); + } + + $captcha = phpbb_captcha_factory::get_instance($this->config['captcha_plugin']); + $captcha->init(CONFIRM_LOGIN); + $vc_response = $captcha->validate($row); + if ($vc_response) + { + return array( + 'status' => LOGIN_ERROR_ATTEMPTS, + 'error_msg' => 'LOGIN_ERROR_ATTEMPTS', + 'user_row' => $row, + ); + } + else + { + $captcha->reset(); + } + + } + + // If the password convert flag is set we need to convert it + if ($row['user_pass_convert']) + { + // enable super globals to get literal value + // this is needed to prevent unicode normalization + $super_globals_disabled = $this->request->super_globals_disabled(); + if ($super_globals_disabled) + { + $this->request->enable_super_globals(); + } + + // in phpBB2 passwords were used exactly as they were sent, with addslashes applied + $password_old_format = isset($_REQUEST['password']) ? (string) $_REQUEST['password'] : ''; + $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format; + $password_new_format = $this->request->variable('password', '', true); + + if ($super_globals_disabled) + { + $this->request->disable_super_globals(); + } + + if ($password == $password_new_format) + { + if (!function_exists('utf8_to_cp1252')) + { + include($this->phpbb_root_path . 'includes/utf/data/recode_basic.' . $this->php_ext); + } + + // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding + // plain md5 support left in for conversions from other systems. + if ((strlen($row['user_password']) == 34 && (phpbb_check_hash(md5($password_old_format), $row['user_password']) || phpbb_check_hash(md5(utf8_to_cp1252($password_old_format)), $row['user_password']))) + || (strlen($row['user_password']) == 32 && (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password']))) + { + $hash = phpbb_hash($password_new_format); + + // Update the password in the users table to the new format and remove user_pass_convert flag + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_password = \'' . $this->db->sql_escape($hash) . '\', + user_pass_convert = 0 + WHERE user_id = ' . $row['user_id']; + $this->db->sql_query($sql); + + $row['user_pass_convert'] = 0; + $row['user_password'] = $hash; + } + else + { + // Although we weren't able to convert this password we have to + // increase login attempt count to make sure this cannot be exploited + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = user_login_attempts + 1 + WHERE user_id = ' . (int) $row['user_id'] . ' + AND user_login_attempts < ' . LOGIN_ATTEMPTS_MAX; + $this->db->sql_query($sql); + + return array( + 'status' => LOGIN_ERROR_PASSWORD_CONVERT, + 'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT', + 'user_row' => $row, + ); + } + } + } + + // Check password ... + if (!$row['user_pass_convert'] && phpbb_check_hash($password, $row['user_password'])) + { + // Check for old password hash... + if (strlen($row['user_password']) == 32) + { + $hash = phpbb_hash($password); + + // Update the password in the users table to the new format + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_password = '" . $this->db->sql_escape($hash) . "', + user_pass_convert = 0 + WHERE user_id = {$row['user_id']}"; + $this->db->sql_query($sql); + + $row['user_password'] = $hash; + } + + $sql = 'DELETE FROM ' . LOGIN_ATTEMPT_TABLE . ' + WHERE user_id = ' . $row['user_id']; + $this->db->sql_query($sql); + + if ($row['user_login_attempts'] != 0) + { + // Successful, reset login attempts (the user passed all stages) + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = 0 + WHERE user_id = ' . $row['user_id']; + $this->db->sql_query($sql); + } + + // User inactive... + if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) + { + return array( + 'status' => LOGIN_ERROR_ACTIVE, + 'error_msg' => 'ACTIVE_ERROR', + 'user_row' => $row, + ); + } + + // Successful login... set user_login_attempts to zero... + return array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => $row, + ); + } + + // Password incorrect - increase login attempts + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = user_login_attempts + 1 + WHERE user_id = ' . (int) $row['user_id'] . ' + AND user_login_attempts < ' . LOGIN_ATTEMPTS_MAX; + $this->db->sql_query($sql); + + // Give status about wrong password... + return array( + 'status' => ($show_captcha) ? LOGIN_ERROR_ATTEMPTS : LOGIN_ERROR_PASSWORD, + 'error_msg' => ($show_captcha) ? 'LOGIN_ERROR_ATTEMPTS' : 'LOGIN_ERROR_PASSWORD', + 'user_row' => $row, + ); + } +} diff --git a/phpBB/includes/search/index.htm b/phpBB/phpbb/auth/provider/index.htm similarity index 100% rename from phpBB/includes/search/index.htm rename to phpBB/phpbb/auth/provider/index.htm diff --git a/phpBB/phpbb/auth/provider/interface.php b/phpBB/phpbb/auth/provider/interface.php new file mode 100644 index 0000000000..47043bc107 --- /dev/null +++ b/phpBB/phpbb/auth/provider/interface.php @@ -0,0 +1,105 @@ + status constant + * 'error_msg' => string + * 'user_row' => array + * ) + */ + public function login($username, $password); + + /** + * Autologin function + * + * @return array|null containing the user row, empty if no auto login + * should take place, or null if not impletmented. + */ + public function autologin(); + + /** + * This function is used to output any required fields in the authentication + * admin panel. It also defines any required configuration table fields. + * + * @return array|null Returns null if not implemented or an array of the + * configuration fields of the provider. + */ + public function acp(); + + /** + * This function updates the template with variables related to the acp + * options with whatever configuraton values are passed to it as an array. + * It then returns the name of the acp file related to this authentication + * provider. + * @param array $new_config Contains the new configuration values that + * have been set in acp_board. + * @return array|null Returns null if not implemented or an array with + * the template file name and an array of the vars + * that the template needs that must conform to the + * following example: + * array( + * 'TEMPLATE_FILE' => string, + * 'TEMPLATE_VARS' => array(...), + * ) + */ + public function get_acp_template($new_config); + + /** + * Performs additional actions during logout. + * + * @param array $data An array corresponding to + * phpbb_session::data + * @param boolean $new_session True for a new session, false for no new + * session. + */ + public function logout($data, $new_session); + + /** + * The session validation function checks whether the user is still logged + * into phpBB. + * + * @param array $user + * @return boolean true if the given user is authenticated, false if the + * session should be closed, or null if not implemented. + */ + public function validate_session($user); +} diff --git a/phpBB/phpbb/auth/provider/ldap.php b/phpBB/phpbb/auth/provider/ldap.php new file mode 100644 index 0000000000..0196529408 --- /dev/null +++ b/phpBB/phpbb/auth/provider/ldap.php @@ -0,0 +1,346 @@ +db = $db; + $this->config = $config; + $this->user = $user; + } + + /** + * {@inheritdoc} + */ + public function init() + { + if (!@extension_loaded('ldap')) + { + return $this->user->lang['LDAP_NO_LDAP_EXTENSION']; + } + + $this->config['ldap_port'] = (int) $this->config['ldap_port']; + if ($this->config['ldap_port']) + { + $ldap = @ldap_connect($this->config['ldap_server'], $this->config['ldap_port']); + } + else + { + $ldap = @ldap_connect($this->config['ldap_server']); + } + + if (!$ldap) + { + return $this->user->lang['LDAP_NO_SERVER_CONNECTION']; + } + + @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); + @ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); + + if ($this->config['ldap_user'] || $this->config['ldap_password']) + { + if (!@ldap_bind($ldap, htmlspecialchars_decode($this->config['ldap_user']), htmlspecialchars_decode($this->config['ldap_password']))) + { + return $this->user->lang['LDAP_INCORRECT_USER_PASSWORD']; + } + } + + // ldap_connect only checks whether the specified server is valid, so the connection might still fail + $search = @ldap_search( + $ldap, + htmlspecialchars_decode($this->config['ldap_base_dn']), + $this->ldap_user_filter($this->user->data['username']), + (empty($this->config['ldap_email'])) ? + array(htmlspecialchars_decode($this->config['ldap_uid'])) : + array(htmlspecialchars_decode($this->config['ldap_uid']), htmlspecialchars_decode($this->config['ldap_email'])), + 0, + 1 + ); + + if ($search === false) + { + return $this->user->lang['LDAP_SEARCH_FAILED']; + } + + $result = @ldap_get_entries($ldap, $search); + + @ldap_close($ldap); + + + if (!is_array($result) || sizeof($result) < 2) + { + return sprintf($this->user->lang['LDAP_NO_IDENTITY'], $this->user->data['username']); + } + + if (!empty($this->config['ldap_email']) && !isset($result[0][htmlspecialchars_decode($this->config['ldap_email'])])) + { + return $this->user->lang['LDAP_NO_EMAIL']; + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function login($username, $password) + { + // do not allow empty password + if (!$password) + { + return array( + 'status' => LOGIN_ERROR_PASSWORD, + 'error_msg' => 'NO_PASSWORD_SUPPLIED', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + if (!$username) + { + return array( + 'status' => LOGIN_ERROR_USERNAME, + 'error_msg' => 'LOGIN_ERROR_USERNAME', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + if (!@extension_loaded('ldap')) + { + return array( + 'status' => LOGIN_ERROR_EXTERNAL_AUTH, + 'error_msg' => 'LDAP_NO_LDAP_EXTENSION', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + $this->config['ldap_port'] = (int) $this->config['ldap_port']; + if ($this->config['ldap_port']) + { + $ldap = @ldap_connect($this->config['ldap_server'], $this->config['ldap_port']); + } + else + { + $ldap = @ldap_connect($this->config['ldap_server']); + } + + if (!$ldap) + { + return array( + 'status' => LOGIN_ERROR_EXTERNAL_AUTH, + 'error_msg' => 'LDAP_NO_SERVER_CONNECTION', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); + @ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); + + if ($this->config['ldap_user'] || $this->config['ldap_password']) + { + if (!@ldap_bind($ldap, htmlspecialchars_decode($this->config['ldap_user']), htmlspecialchars_decode($this->config['ldap_password']))) + { + return array( + 'status' => LOGIN_ERROR_EXTERNAL_AUTH, + 'error_msg' => 'LDAP_NO_SERVER_CONNECTION', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + } + + $search = @ldap_search( + $ldap, + htmlspecialchars_decode($this->config['ldap_base_dn']), + $this->ldap_user_filter($username), + (empty($this->config['ldap_email'])) ? + array(htmlspecialchars_decode($this->config['ldap_uid'])) : + array(htmlspecialchars_decode($this->config['ldap_uid']), htmlspecialchars_decode($this->config['ldap_email'])), + 0, + 1 + ); + + $ldap_result = @ldap_get_entries($ldap, $search); + + if (is_array($ldap_result) && sizeof($ldap_result) > 1) + { + if (@ldap_bind($ldap, $ldap_result[0]['dn'], htmlspecialchars_decode($password))) + { + @ldap_close($ldap); + + $sql ='SELECT user_id, username, user_password, user_passchg, user_email, user_type + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + unset($ldap_result); + + // User inactive... + if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) + { + return array( + 'status' => LOGIN_ERROR_ACTIVE, + 'error_msg' => 'ACTIVE_ERROR', + 'user_row' => $row, + ); + } + + // Successful login... set user_login_attempts to zero... + return array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => $row, + ); + } + else + { + // retrieve default group id + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "' + AND group_type = " . GROUP_SPECIAL; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + trigger_error('NO_GROUP'); + } + + // generate user account data + $ldap_user_row = array( + 'username' => $username, + 'user_password' => phpbb_hash($password), + 'user_email' => (!empty($this->config['ldap_email'])) ? utf8_htmlspecialchars($ldap_result[0][htmlspecialchars_decode($this->config['ldap_email'])][0]) : '', + 'group_id' => (int) $row['group_id'], + 'user_type' => USER_NORMAL, + 'user_ip' => $this->user->ip, + 'user_new' => ($this->config['new_member_post_limit']) ? 1 : 0, + ); + + unset($ldap_result); + + // this is the user's first login so create an empty profile + return array( + 'status' => LOGIN_SUCCESS_CREATE_PROFILE, + 'error_msg' => false, + 'user_row' => $ldap_user_row, + ); + } + } + else + { + unset($ldap_result); + @ldap_close($ldap); + + // Give status about wrong password... + return array( + 'status' => LOGIN_ERROR_PASSWORD, + 'error_msg' => 'LOGIN_ERROR_PASSWORD', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + } + + @ldap_close($ldap); + + return array( + 'status' => LOGIN_ERROR_USERNAME, + 'error_msg' => 'LOGIN_ERROR_USERNAME', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + /** + * {@inheritdoc} + */ + + public function acp() + { + // These are fields required in the config table + return array( + 'ldap_server', 'ldap_port', 'ldap_base_dn', 'ldap_uid', 'ldap_user_filter', 'ldap_email', 'ldap_user', 'ldap_password', + ); + } + + /** + * {@inheritdoc} + */ + public function get_acp_template($new_config) + { + return array( + 'TEMPLATE_FILE' => 'auth_provider_ldap.html', + 'TEMPLATE_VARS' => array( + 'AUTH_LDAP_DN' => $new_config['ldap_base_dn'], + 'AUTH_LDAP_EMAIL' => $new_config['ldap_email'], + 'AUTH_LDAP_PASSORD' => $new_config['ldap_password'], + 'AUTH_LDAP_PORT' => $new_config['ldap_port'], + 'AUTH_LDAP_SERVER' => $new_config['ldap_server'], + 'AUTH_LDAP_UID' => $new_config['ldap_uid'], + 'AUTH_LDAP_USER' => $new_config['ldap_user'], + 'AUTH_LDAP_USER_FILTER' => $new_config['ldap_user_filter'], + ), + ); + } + + /** + * Generates a filter string for ldap_search to find a user + * + * @param $username string Username identifying the searched user + * + * @return string A filter string for ldap_search + */ + private function ldap_user_filter($username) + { + $filter = '(' . $this->config['ldap_uid'] . '=' . $this->ldap_escape(htmlspecialchars_decode($username)) . ')'; + if ($this->config['ldap_user_filter']) + { + $_filter = ($this->config['ldap_user_filter'][0] == '(' && substr($this->config['ldap_user_filter'], -1) == ')') ? $this->config['ldap_user_filter'] : "({$this->config['ldap_user_filter']})"; + $filter = "(&{$filter}{$_filter})"; + } + return $filter; + } + + /** + * Escapes an LDAP AttributeValue + * + * @param string $string The string to be escaped + * @return string The escaped string + */ + private function ldap_escape($string) + { + return str_replace(array('*', '\\', '(', ')'), array('\\*', '\\\\', '\\(', '\\)'), $string); + } +} diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php similarity index 100% rename from phpBB/includes/avatar/driver/driver.php rename to phpBB/phpbb/avatar/driver/driver.php diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/phpbb/avatar/driver/gravatar.php similarity index 100% rename from phpBB/includes/avatar/driver/gravatar.php rename to phpBB/phpbb/avatar/driver/gravatar.php diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/phpbb/avatar/driver/interface.php similarity index 100% rename from phpBB/includes/avatar/driver/interface.php rename to phpBB/phpbb/avatar/driver/interface.php diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/phpbb/avatar/driver/local.php similarity index 100% rename from phpBB/includes/avatar/driver/local.php rename to phpBB/phpbb/avatar/driver/local.php diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/phpbb/avatar/driver/remote.php similarity index 100% rename from phpBB/includes/avatar/driver/remote.php rename to phpBB/phpbb/avatar/driver/remote.php diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php similarity index 89% rename from phpBB/includes/avatar/driver/upload.php rename to phpBB/phpbb/avatar/driver/upload.php index baf51f61c1..685ac4f349 100644 --- a/phpBB/includes/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -77,6 +77,32 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver } elseif (!empty($this->config['allow_avatar_remote_upload']) && !empty($url)) { + if (!preg_match('#^(http|https|ftp)://#i', $url)) + { + $url = 'http://' . $url; + } + + if (!function_exists('validate_data')) + { + require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $validate_array = validate_data( + array( + 'url' => $url, + ), + array( + 'url' => array('string', true, 5, 255), + ) + ); + + $error = array_merge($error, $validate_array); + + if (!empty($error)) + { + return false; + } + $file = $upload->remote_upload($url); } else diff --git a/phpBB/includes/avatar/manager.php b/phpBB/phpbb/avatar/manager.php similarity index 100% rename from phpBB/includes/avatar/manager.php rename to phpBB/phpbb/avatar/manager.php diff --git a/phpBB/includes/cache/driver/apc.php b/phpBB/phpbb/cache/driver/apc.php similarity index 100% rename from phpBB/includes/cache/driver/apc.php rename to phpBB/phpbb/cache/driver/apc.php diff --git a/phpBB/includes/cache/driver/base.php b/phpBB/phpbb/cache/driver/base.php similarity index 100% rename from phpBB/includes/cache/driver/base.php rename to phpBB/phpbb/cache/driver/base.php diff --git a/phpBB/includes/cache/driver/eaccelerator.php b/phpBB/phpbb/cache/driver/eaccelerator.php similarity index 100% rename from phpBB/includes/cache/driver/eaccelerator.php rename to phpBB/phpbb/cache/driver/eaccelerator.php diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php similarity index 100% rename from phpBB/includes/cache/driver/file.php rename to phpBB/phpbb/cache/driver/file.php diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/phpbb/cache/driver/interface.php similarity index 100% rename from phpBB/includes/cache/driver/interface.php rename to phpBB/phpbb/cache/driver/interface.php diff --git a/phpBB/includes/cache/driver/memcache.php b/phpBB/phpbb/cache/driver/memcache.php similarity index 100% rename from phpBB/includes/cache/driver/memcache.php rename to phpBB/phpbb/cache/driver/memcache.php diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php similarity index 100% rename from phpBB/includes/cache/driver/memory.php rename to phpBB/phpbb/cache/driver/memory.php diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/phpbb/cache/driver/null.php similarity index 100% rename from phpBB/includes/cache/driver/null.php rename to phpBB/phpbb/cache/driver/null.php diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php similarity index 100% rename from phpBB/includes/cache/driver/redis.php rename to phpBB/phpbb/cache/driver/redis.php diff --git a/phpBB/includes/cache/driver/wincache.php b/phpBB/phpbb/cache/driver/wincache.php similarity index 100% rename from phpBB/includes/cache/driver/wincache.php rename to phpBB/phpbb/cache/driver/wincache.php diff --git a/phpBB/includes/cache/driver/xcache.php b/phpBB/phpbb/cache/driver/xcache.php similarity index 100% rename from phpBB/includes/cache/driver/xcache.php rename to phpBB/phpbb/cache/driver/xcache.php diff --git a/phpBB/includes/cache/service.php b/phpBB/phpbb/cache/service.php similarity index 100% rename from phpBB/includes/cache/service.php rename to phpBB/phpbb/cache/service.php diff --git a/phpBB/includes/class_loader.php b/phpBB/phpbb/class_loader.php similarity index 100% rename from phpBB/includes/class_loader.php rename to phpBB/phpbb/class_loader.php diff --git a/phpBB/includes/config/config.php b/phpBB/phpbb/config/config.php similarity index 100% rename from phpBB/includes/config/config.php rename to phpBB/phpbb/config/config.php diff --git a/phpBB/includes/config/db.php b/phpBB/phpbb/config/db.php similarity index 100% rename from phpBB/includes/config/db.php rename to phpBB/phpbb/config/db.php diff --git a/phpBB/includes/config/db_text.php b/phpBB/phpbb/config/db_text.php similarity index 100% rename from phpBB/includes/config/db_text.php rename to phpBB/phpbb/config/db_text.php diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php new file mode 100644 index 0000000000..4ad5f6793e --- /dev/null +++ b/phpBB/phpbb/content_visibility.php @@ -0,0 +1,651 @@ +auth = $auth; + $this->db = $db; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->forums_table = $forums_table; + $this->posts_table = $posts_table; + $this->topics_table = $topics_table; + $this->users_table = $users_table; + } + + /** + * Can the current logged-in user soft-delete posts? + * + * @param $forum_id int Forum ID whose permissions to check + * @param $poster_id int Poster ID of the post in question + * @param $post_locked bool Is the post locked? + * @return bool + */ + public function can_soft_delete($forum_id, $poster_id, $post_locked) + { + if ($this->auth->acl_get('m_softdelete', $forum_id)) + { + return true; + } + else if ($this->auth->acl_get('f_softdelete', $forum_id) && $poster_id == $this->user->data['user_id'] && !$post_locked) + { + return true; + } + + return false; + } + + /** + * Get the topics post count or the forums post/topic count based on permissions + * + * @param $mode string One of topic_posts, forum_posts or forum_topics + * @param $data array Array with the topic/forum data to calculate from + * @param $forum_id int The forum id is used for permission checks + * @return int Number of posts/topics the user can see in the topic/forum + */ + public function get_count($mode, $data, $forum_id) + { + if (!$this->auth->acl_get('m_approve', $forum_id)) + { + return (int) $data[$mode . '_approved']; + } + + return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted']; + } + + /** + * Create topic/post visibility SQL for a given forum ID + * + * Note: Read permissions are not checked. + * + * @param $mode string Either "topic" or "post" + * @param $forum_id int The forum id is used for permission checks + * @param $table_alias string Table alias to prefix in SQL queries + * @return string The appropriate combination SQL logic for topic/post_visibility + */ + public function get_visibility_sql($mode, $forum_id, $table_alias = '') + { + if ($this->auth->acl_get('m_approve', $forum_id)) + { + return '1 = 1'; + } + + return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED; + } + + /** + * Create topic/post visibility SQL for a set of forums + * + * Note: Read permissions are not checked. Forums without read permissions + * should not be in $forum_ids + * + * @param $mode string Either "topic" or "post" + * @param $forum_ids array Array of forum ids which the posts/topics are limited to + * @param $table_alias string Table alias to prefix in SQL queries + * @return string The appropriate combination SQL logic for topic/post_visibility + */ + public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '') + { + $where_sql = '('; + + $approve_forums = array_intersect($forum_ids, array_keys($this->auth->acl_getf('m_approve', true))); + + if (sizeof($approve_forums)) + { + // Remove moderator forums from the rest + $forum_ids = array_diff($forum_ids, $approve_forums); + + if (!sizeof($forum_ids)) + { + // The user can see all posts/topics in all specified forums + return $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums); + } + else + { + // Moderator can view all posts/topics in some forums + $where_sql .= $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ' OR '; + } + } + else + { + // The user is just a normal user + return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ' + AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true); + } + + $where_sql .= '(' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ' + AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids) . '))'; + + return $where_sql; + } + + /** + * Create topic/post visibility SQL for all forums on the board + * + * Note: Read permissions are not checked. Forums without read permissions + * should be in $exclude_forum_ids + * + * @param $mode string Either "topic" or "post" + * @param $exclude_forum_ids array Array of forum ids which are excluded + * @param $table_alias string Table alias to prefix in SQL queries + * @return string The appropriate combination SQL logic for topic/post_visibility + */ + public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '') + { + $where_sqls = array(); + + $approve_forums = array_diff(array_keys($this->auth->acl_getf('m_approve', true)), $exclude_forum_ids); + + if (sizeof($exclude_forum_ids)) + { + $where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . ' + AND ' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ')'; + } + else + { + $where_sqls[] = $table_alias . $mode . '_visibility = ' . ITEM_APPROVED; + } + + if (sizeof($approve_forums)) + { + $where_sqls[] = $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums); + return '(' . implode(' OR ', $where_sqls) . ')'; + } + + // There is only one element, so we just return that one + return $where_sqls[0]; + } + + /** + * Change visibility status of one post or all posts of a topic + * + * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} + * @param $post_id mixed Post ID or array of post IDs to act on, + * if it is empty, all posts of topic_id will be modified + * @param $topic_id int Topic where $post_id is found + * @param $forum_id int Forum where $topic_id is found + * @param $user_id int User performing the action + * @param $time int Timestamp when the action is performed + * @param $reason string Reason why the visibilty was changed. + * @param $is_starter bool Is this the first post of the topic changed? + * @param $is_latest bool Is this the last post of the topic changed? + * @param $limit_visibility mixed Limit updating per topic_id to a certain visibility + * @param $limit_delete_time mixed Limit updating per topic_id to a certain deletion time + * @return array Changed post data, empty array if an error occured. + */ + public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false) + { + if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) + { + return array(); + } + + if ($post_id) + { + if (is_array($post_id)) + { + $where_sql = $this->db->sql_in_set('post_id', array_map('intval', $post_id)); + } + else + { + $where_sql = 'post_id = ' . (int) $post_id; + } + $where_sql .= ' AND topic_id = ' . (int) $topic_id; + } + else + { + $where_sql = 'topic_id = ' . (int) $topic_id; + + // Limit the posts to a certain visibility and deletion time + // This allows us to only restore posts, that were approved + // when the topic got soft deleted. So previous soft deleted + // and unapproved posts are still soft deleted/unapproved + if ($limit_visibility !== false) + { + $where_sql .= ' AND post_visibility = ' . (int) $limit_visibility; + } + + if ($limit_delete_time !== false) + { + $where_sql .= ' AND post_delete_time = ' . (int) $limit_delete_time; + } + } + + $sql = 'SELECT poster_id, post_id, post_postcount, post_visibility + FROM ' . $this->posts_table . ' + WHERE ' . $where_sql; + $result = $this->db->sql_query($sql); + + $post_ids = $poster_postcounts = $postcounts = $postcount_visibility = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $post_ids[] = (int) $row['post_id']; + + if ($row['post_visibility'] != $visibility) + { + if ($row['post_postcount'] && !isset($poster_postcounts[(int) $row['poster_id']])) + { + $poster_postcounts[(int) $row['poster_id']] = 1; + } + else if ($row['post_postcount']) + { + $poster_postcounts[(int) $row['poster_id']]++; + } + + if (!isset($postcount_visibility[$row['post_visibility']])) + { + $postcount_visibility[$row['post_visibility']] = 1; + } + else + { + $postcount_visibility[$row['post_visibility']]++; + } + } + } + $this->db->sql_freeresult($result); + + if (empty($post_ids)) + { + return array(); + } + + $data = array( + 'post_visibility' => (int) $visibility, + 'post_delete_user' => (int) $user_id, + 'post_delete_time' => ((int) $time) ?: time(), + 'post_delete_reason' => truncate_string($reason, 255, 255, false), + ); + + $sql = 'UPDATE ' . $this->posts_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $data) . ' + WHERE ' . $this->db->sql_in_set('post_id', $post_ids); + $this->db->sql_query($sql); + + // Group the authors by post count, to reduce the number of queries + foreach ($poster_postcounts as $poster_id => $num_posts) + { + $postcounts[$num_posts][] = $poster_id; + } + + // Update users postcounts + foreach ($postcounts as $num_posts => $poster_ids) + { + if ($visibility == ITEM_DELETED) + { + $sql = 'UPDATE ' . $this->users_table . ' + SET user_posts = 0 + WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . ' + AND user_posts < ' . $num_posts; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . $this->users_table . ' + SET user_posts = user_posts - ' . $num_posts . ' + WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . ' + AND user_posts >= ' . $num_posts; + $this->db->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . $this->users_table . ' + SET user_posts = user_posts + ' . $num_posts . ' + WHERE ' . $this->db->sql_in_set('user_id', $poster_ids); + $this->db->sql_query($sql); + } + } + + $update_topic_postcount = true; + + // Sync the first/last topic information if needed + if (!$is_starter && $is_latest) + { + // update_post_information can only update the last post info ... + if ($topic_id) + { + update_post_information('topic', $topic_id, false); + } + if ($forum_id) + { + update_post_information('forum', $forum_id, false); + } + } + else if ($is_starter && $topic_id) + { + if (!function_exists('sync')) + { + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); + } + + // ... so we need to use sync, if the first post is changed. + // The forum is resynced recursive by sync() itself. + sync('topic', 'topic_id', $topic_id, true); + + // sync recalculates the topic replies and forum posts by itself, so we don't do that. + $update_topic_postcount = false; + } + + // Update the topic's reply count and the forum's post count + if ($update_topic_postcount) + { + $cur_posts = $cur_unapproved_posts = $cur_softdeleted_posts = 0; + foreach ($postcount_visibility as $post_visibility => $visibility_posts) + { + // We need to substract the posts from the counters ... + if ($post_visibility == ITEM_APPROVED) + { + $cur_posts += $visibility_posts; + } + else if ($post_visibility == ITEM_UNAPPROVED) + { + $cur_unapproved_posts += $visibility_posts; + } + else if ($post_visibility == ITEM_DELETED) + { + $cur_softdeleted_posts += $visibility_posts; + } + } + + $sql_ary = array(); + if ($visibility == ITEM_DELETED) + { + if ($cur_posts) + { + $sql_ary['posts_approved'] = ' - ' . $cur_posts; + } + if ($cur_unapproved_posts) + { + $sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts; + } + if ($cur_posts + $cur_unapproved_posts) + { + $sql_ary['posts_softdeleted'] = ' + ' . ($cur_posts + $cur_unapproved_posts); + } + } + else + { + if ($cur_unapproved_posts) + { + $sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts; + } + if ($cur_softdeleted_posts) + { + $sql_ary['posts_softdeleted'] = ' - ' . $cur_softdeleted_posts; + } + if ($cur_softdeleted_posts + $cur_unapproved_posts) + { + $sql_ary['posts_approved'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts); + } + } + + if (sizeof($sql_ary)) + { + $topic_sql = $forum_sql = array(); + + foreach ($sql_ary as $field => $value_change) + { + $topic_sql[] = 'topic_' . $field . ' = topic_' . $field . $value_change; + $forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change; + } + + // Update the number for replies and posts + $sql = 'UPDATE ' . $this->topics_table . ' + SET ' . implode(', ', $topic_sql) . ' + WHERE topic_id = ' . (int) $topic_id; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . $this->forums_table . ' + SET ' . implode(', ', $forum_sql) . ' + WHERE forum_id = ' . (int) $forum_id; + $this->db->sql_query($sql); + } + } + + return $data; + } + + /** + * Set topic visibility + * + * Allows approving (which is akin to undeleting/restore) or soft deleting an entire topic. + * Calls set_post_visibility as needed. + * + * Note: By default, when a soft deleted topic is restored. Only posts that + * were approved at the time of soft deleting, are being restored. + * Same applies to soft deleting. Only approved posts will be marked + * as soft deleted. + * If you want to update all posts, use the force option. + * + * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED} + * @param $topic_id mixed Topic ID to act on + * @param $forum_id int Forum where $topic_id is found + * @param $user_id int User performing the action + * @param $time int Timestamp when the action is performed + * @param $reason string Reason why the visibilty was changed. + * @param $force_update_all bool Force to update all posts within the topic + * @return array Changed topic data, empty array if an error occured. + */ + public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) + { + if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED))) + { + return array(); + } + + if (!$force_update_all) + { + $sql = 'SELECT topic_visibility, topic_delete_time + FROM ' . $this->topics_table . ' + WHERE topic_id = ' . (int) $topic_id; + $result = $this->db->sql_query($sql); + $original_topic_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$original_topic_data) + { + // The topic does not exist... + return array(); + } + } + + // Note, we do not set a reason for the posts, just for the topic + $data = array( + 'topic_visibility' => (int) $visibility, + 'topic_delete_user' => (int) $user_id, + 'topic_delete_time' => ((int) $time) ?: time(), + 'topic_delete_reason' => truncate_string($reason, 255, 255, false), + ); + + $sql = 'UPDATE ' . $this->topics_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $data) . ' + WHERE topic_id = ' . (int) $topic_id; + $this->db->sql_query($sql); + + if (!$this->db->sql_affectedrows()) + { + return array(); + } + + if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) + { + // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. + self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']); + } + else if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED) + { + // If we're soft deleting a topic we only approved posts are soft deleted. + self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']); + } + else + { + self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); + } + + return $data; + } + + /** + * Add post to topic and forum statistics + * + * @param $data array Contains information from the topics table about given topic + * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @return void + */ + public function add_post_to_statistic($data, &$sql_data) + { + $sql_data[$this->topics_table] = (($sql_data[$this->topics_table]) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved + 1'; + + $sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved + 1'; + + if ($data['post_postcount']) + { + $sql_data[$this->users_table] = (($sql_data[$this->users_table]) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts + 1'; + } + + set_config_count('num_posts', 1, true); + } + + /** + * Remove post from topic and forum statistics + * + * @param $data array Contains information from the topics table about given topic + * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @return void + */ + public function remove_post_from_statistic($data, &$sql_data) + { + $sql_data[$this->topics_table] = ((!empty($sql_data[$this->topics_table])) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1'; + $sql_data[$this->forums_table] = ((!empty($sql_data[$this->forums_table])) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1'; + + if ($data['post_postcount']) + { + $sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1'; + } + + set_config_count('num_posts', -1, true); + } + + /** + * Remove topic from forum statistics + * + * @param $topic_id int The topic to act on + * @param $forum_id int Forum where the topic is found + * @param $topic_row array Contains information from the topic, may be empty at call time + * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @return void + */ + public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data) + { + // Do we need to grab some topic informations? + if (!sizeof($topic_row)) + { + $sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility + FROM ' . $this->topics_table . ' + WHERE topic_id = ' . (int) $topic_id; + $result = $this->db->sql_query($sql); + $topic_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + } + + // If this is an edited topic or the first post the topic gets completely disapproved later on... + $sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_topics_approved = forum_topics_approved - 1'; + $sql_data[$this->forums_table] .= ', forum_posts_approved = forum_posts_approved - ' . $topic_row['topic_posts_approved']; + $sql_data[$this->forums_table] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved']; + $sql_data[$this->forums_table] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; + + set_config_count('num_topics', -1, true); + set_config_count('num_posts', $topic_row['topic_posts_approved'] * (-1), true); + + // Get user post count information + $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts + FROM ' . $this->posts_table . ' + WHERE topic_id = ' . (int) $topic_id . ' + AND post_postcount = 1 + AND post_visibility = ' . ITEM_APPROVED . ' + GROUP BY poster_id'; + $result = $this->db->sql_query($sql); + + $postcounts = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $postcounts[(int) $row['num_posts']][] = (int) $row['poster_id']; + } + $this->db->sql_freeresult($result); + + // Decrement users post count + foreach ($postcounts as $num_posts => $poster_ids) + { + $sql = 'UPDATE ' . $this->users_table . ' + SET user_posts = 0 + WHERE user_posts < ' . $num_posts . ' + AND ' . $this->db->sql_in_set('user_id', $poster_ids); + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . $this->users_table . ' + SET user_posts = user_posts - ' . $num_posts . ' + WHERE user_posts >= ' . $num_posts . ' + AND ' . $this->db->sql_in_set('user_id', $poster_ids); + $this->db->sql_query($sql); + } + } +} diff --git a/phpBB/includes/controller/exception.php b/phpBB/phpbb/controller/exception.php similarity index 100% rename from phpBB/includes/controller/exception.php rename to phpBB/phpbb/controller/exception.php diff --git a/phpBB/includes/controller/helper.php b/phpBB/phpbb/controller/helper.php similarity index 100% rename from phpBB/includes/controller/helper.php rename to phpBB/phpbb/controller/helper.php diff --git a/phpBB/includes/controller/provider.php b/phpBB/phpbb/controller/provider.php similarity index 100% rename from phpBB/includes/controller/provider.php rename to phpBB/phpbb/controller/provider.php diff --git a/phpBB/includes/controller/resolver.php b/phpBB/phpbb/controller/resolver.php similarity index 80% rename from phpBB/includes/controller/resolver.php rename to phpBB/phpbb/controller/resolver.php index ee469aa9c8..95dfc8da8e 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/phpbb/controller/resolver.php @@ -37,16 +37,24 @@ class phpbb_controller_resolver implements ControllerResolverInterface */ protected $container; + /** + * phpbb_style object + * @var phpbb_style + */ + protected $style; + /** * Construct method * * @param phpbb_user $user User Object * @param ContainerInterface $container ContainerInterface object + * @param phpbb_style $style */ - public function __construct(phpbb_user $user, ContainerInterface $container) + public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style = null) { $this->user = $user; $this->container = $container; + $this->style = $style; } /** @@ -80,6 +88,24 @@ class phpbb_controller_resolver implements ControllerResolverInterface $controller_object = $this->container->get($service); + /* + * If this is an extension controller, we'll try to automatically set + * the style paths for the extension (the ext author can change them + * if necessary). + */ + $controller_dir = explode('_', get_class($controller_object)); + + // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... + if (!is_null($this->style) && isset($controller_dir[3]) && $controller_dir[1] === 'ext') + { + $controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles'; + + if (is_dir($controller_style_dir)) + { + $this->style->set_style(array($controller_style_dir, 'styles')); + } + } + return array($controller_object, $method); } diff --git a/phpBB/includes/cron/manager.php b/phpBB/phpbb/cron/manager.php similarity index 100% rename from phpBB/includes/cron/manager.php rename to phpBB/phpbb/cron/manager.php diff --git a/phpBB/includes/cron/task/base.php b/phpBB/phpbb/cron/task/base.php similarity index 100% rename from phpBB/includes/cron/task/base.php rename to phpBB/phpbb/cron/task/base.php diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/phpbb/cron/task/core/prune_all_forums.php similarity index 100% rename from phpBB/includes/cron/task/core/prune_all_forums.php rename to phpBB/phpbb/cron/task/core/prune_all_forums.php diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/phpbb/cron/task/core/prune_forum.php similarity index 100% rename from phpBB/includes/cron/task/core/prune_forum.php rename to phpBB/phpbb/cron/task/core/prune_forum.php diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/phpbb/cron/task/core/queue.php similarity index 100% rename from phpBB/includes/cron/task/core/queue.php rename to phpBB/phpbb/cron/task/core/queue.php diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/phpbb/cron/task/core/tidy_cache.php similarity index 100% rename from phpBB/includes/cron/task/core/tidy_cache.php rename to phpBB/phpbb/cron/task/core/tidy_cache.php diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/phpbb/cron/task/core/tidy_database.php similarity index 100% rename from phpBB/includes/cron/task/core/tidy_database.php rename to phpBB/phpbb/cron/task/core/tidy_database.php diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/phpbb/cron/task/core/tidy_search.php similarity index 90% rename from phpBB/includes/cron/task/core/tidy_search.php rename to phpBB/phpbb/cron/task/core/tidy_search.php index 3ec25aa021..a3d5b7dbd2 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/phpbb/cron/task/core/tidy_search.php @@ -61,11 +61,6 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base // Select the search method $search_type = basename($this->config['search_type']); - if (!class_exists($search_type)) - { - include($this->phpbb_root_path . "includes/search/$search_type." . $this->php_ext); - } - // We do some additional checks in the module to ensure it can actually be utilised $error = false; $search = new $search_type($error, $this->phpbb_root_path, $this->php_ext, $this->auth, $this->config, $this->db, $this->user); @@ -90,7 +85,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base // Select the search method $search_type = basename($this->config['search_type']); - return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->php_ext); + return class_exists($search_type); } /** diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/phpbb/cron/task/core/tidy_sessions.php similarity index 100% rename from phpBB/includes/cron/task/core/tidy_sessions.php rename to phpBB/phpbb/cron/task/core/tidy_sessions.php diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/phpbb/cron/task/core/tidy_warnings.php similarity index 100% rename from phpBB/includes/cron/task/core/tidy_warnings.php rename to phpBB/phpbb/cron/task/core/tidy_warnings.php diff --git a/phpBB/includes/cron/task/parametrized.php b/phpBB/phpbb/cron/task/parametrized.php similarity index 100% rename from phpBB/includes/cron/task/parametrized.php rename to phpBB/phpbb/cron/task/parametrized.php diff --git a/phpBB/includes/cron/task/task.php b/phpBB/phpbb/cron/task/task.php similarity index 100% rename from phpBB/includes/cron/task/task.php rename to phpBB/phpbb/cron/task/task.php diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/phpbb/cron/task/wrapper.php similarity index 100% rename from phpBB/includes/cron/task/wrapper.php rename to phpBB/phpbb/cron/task/wrapper.php diff --git a/phpBB/includes/datetime.php b/phpBB/phpbb/datetime.php similarity index 100% rename from phpBB/includes/datetime.php rename to phpBB/phpbb/datetime.php diff --git a/phpBB/includes/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php similarity index 99% rename from phpBB/includes/db/driver/driver.php rename to phpBB/phpbb/db/driver/driver.php index b915ee081b..08c966c07a 100644 --- a/phpBB/includes/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -878,7 +878,7 @@ class phpbb_db_driver diff --git a/phpBB/includes/db/driver/firebird.php b/phpBB/phpbb/db/driver/firebird.php similarity index 100% rename from phpBB/includes/db/driver/firebird.php rename to phpBB/phpbb/db/driver/firebird.php diff --git a/phpBB/includes/db/driver/mssql.php b/phpBB/phpbb/db/driver/mssql.php similarity index 100% rename from phpBB/includes/db/driver/mssql.php rename to phpBB/phpbb/db/driver/mssql.php diff --git a/phpBB/includes/db/driver/mssql_base.php b/phpBB/phpbb/db/driver/mssql_base.php similarity index 100% rename from phpBB/includes/db/driver/mssql_base.php rename to phpBB/phpbb/db/driver/mssql_base.php diff --git a/phpBB/includes/db/driver/mssql_odbc.php b/phpBB/phpbb/db/driver/mssql_odbc.php similarity index 99% rename from phpBB/includes/db/driver/mssql_odbc.php rename to phpBB/phpbb/db/driver/mssql_odbc.php index cde9d332ba..a1d1a5d5dd 100644 --- a/phpBB/includes/db/driver/mssql_odbc.php +++ b/phpBB/phpbb/db/driver/mssql_odbc.php @@ -253,7 +253,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver_mssql_base * Fetch current row * @note number of bytes returned depends on odbc.defaultlrl php.ini setting. If it is limited to 4K for example only 4K of data is returned max. */ - function sql_fetchrow($query_id = false, $debug = false) + function sql_fetchrow($query_id = false) { global $cache; diff --git a/phpBB/includes/db/driver/mssqlnative.php b/phpBB/phpbb/db/driver/mssqlnative.php similarity index 98% rename from phpBB/includes/db/driver/mssqlnative.php rename to phpBB/phpbb/db/driver/mssqlnative.php index 6f433e10cf..28fc88298a 100644 --- a/phpBB/includes/db/driver/mssqlnative.php +++ b/phpBB/phpbb/db/driver/mssqlnative.php @@ -326,7 +326,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver_mssql_base $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -394,7 +394,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver_mssql_base */ function sql_affectedrows() { - return (!empty($this->query_result)) ? @sqlsrv_rows_affected($this->query_result) : false; + return ($this->db_connect_id) ? @sqlsrv_rows_affected($this->query_result) : false; } /** @@ -409,7 +409,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver_mssql_base $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -474,9 +474,9 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver_mssql_base return $cache->sql_freeresult($query_id); } - if (isset($this->open_queries[$query_id])) + if (isset($this->open_queries[(int) $query_id])) { - unset($this->open_queries[$query_id]); + unset($this->open_queries[(int) $query_id]); return @sqlsrv_free_stmt($query_id); } return false; diff --git a/phpBB/includes/db/driver/mysql.php b/phpBB/phpbb/db/driver/mysql.php similarity index 100% rename from phpBB/includes/db/driver/mysql.php rename to phpBB/phpbb/db/driver/mysql.php diff --git a/phpBB/includes/db/driver/mysql_base.php b/phpBB/phpbb/db/driver/mysql_base.php similarity index 100% rename from phpBB/includes/db/driver/mysql_base.php rename to phpBB/phpbb/db/driver/mysql_base.php diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/phpbb/db/driver/mysqli.php similarity index 100% rename from phpBB/includes/db/driver/mysqli.php rename to phpBB/phpbb/db/driver/mysqli.php diff --git a/phpBB/includes/db/driver/oracle.php b/phpBB/phpbb/db/driver/oracle.php similarity index 100% rename from phpBB/includes/db/driver/oracle.php rename to phpBB/phpbb/db/driver/oracle.php diff --git a/phpBB/includes/db/driver/postgres.php b/phpBB/phpbb/db/driver/postgres.php similarity index 100% rename from phpBB/includes/db/driver/postgres.php rename to phpBB/phpbb/db/driver/postgres.php diff --git a/phpBB/includes/db/driver/sqlite.php b/phpBB/phpbb/db/driver/sqlite.php similarity index 100% rename from phpBB/includes/db/driver/sqlite.php rename to phpBB/phpbb/db/driver/sqlite.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_1.php b/phpBB/phpbb/db/migration/data/30x/3_0_1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_10.php b/phpBB/phpbb/db/migration/data/30x/3_0_10.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_10.php rename to phpBB/phpbb/db/migration/data/30x/3_0_10.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_10_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_10_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_10_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_10_rc2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_10_rc2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_10_rc2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc3.php b/phpBB/phpbb/db/migration/data/30x/3_0_10_rc3.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_10_rc3.php rename to phpBB/phpbb/db/migration/data/30x/3_0_10_rc3.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_11.php b/phpBB/phpbb/db/migration/data/30x/3_0_11.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_11.php rename to phpBB/phpbb/db/migration/data/30x/3_0_11.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_11_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_11_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_11_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_11_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_11_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_11_rc2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_11_rc2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_11_rc2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_12_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_12_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_12_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_12_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_1_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_1_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_1_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_1_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_2.php b/phpBB/phpbb/db/migration/data/30x/3_0_2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_2_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_2_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_2_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_2_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_2_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_2_rc2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_2_rc2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_2_rc2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_3.php b/phpBB/phpbb/db/migration/data/30x/3_0_3.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_3.php rename to phpBB/phpbb/db/migration/data/30x/3_0_3.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_3_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_3_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_3_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_3_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_4.php b/phpBB/phpbb/db/migration/data/30x/3_0_4.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_4.php rename to phpBB/phpbb/db/migration/data/30x/3_0_4.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_4_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_4_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_4_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_4_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_5.php b/phpBB/phpbb/db/migration/data/30x/3_0_5.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_5.php rename to phpBB/phpbb/db/migration/data/30x/3_0_5.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_5_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_5_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_5_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_5_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php b/phpBB/phpbb/db/migration/data/30x/3_0_5_rc1part2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_5_rc1part2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_6.php b/phpBB/phpbb/db/migration/data/30x/3_0_6.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_6.php rename to phpBB/phpbb/db/migration/data/30x/3_0_6.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_6_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_6_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_6_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_6_rc2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_6_rc2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_6_rc2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc3.php b/phpBB/phpbb/db/migration/data/30x/3_0_6_rc3.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_6_rc3.php rename to phpBB/phpbb/db/migration/data/30x/3_0_6_rc3.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc4.php b/phpBB/phpbb/db/migration/data/30x/3_0_6_rc4.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_6_rc4.php rename to phpBB/phpbb/db/migration/data/30x/3_0_6_rc4.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_7.php b/phpBB/phpbb/db/migration/data/30x/3_0_7.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_7.php rename to phpBB/phpbb/db/migration/data/30x/3_0_7.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_pl1.php b/phpBB/phpbb/db/migration/data/30x/3_0_7_pl1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_7_pl1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_7_pl1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_7_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_7_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_7_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_7_rc2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_7_rc2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_7_rc2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_8.php b/phpBB/phpbb/db/migration/data/30x/3_0_8.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_8.php rename to phpBB/phpbb/db/migration/data/30x/3_0_8.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_8_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_8_rc1.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_8_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_8_rc1.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_9.php b/phpBB/phpbb/db/migration/data/30x/3_0_9.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_9.php rename to phpBB/phpbb/db/migration/data/30x/3_0_9.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc1.php similarity index 96% rename from phpBB/includes/db/migration/data/30x/3_0_9_rc1.php rename to phpBB/phpbb/db/migration/data/30x/3_0_9_rc1.php index 1f8622798e..4c345b429b 100644 --- a/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php +++ b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc1.php @@ -27,8 +27,8 @@ class phpbb_db_migration_data_30x_3_0_9_rc1 extends phpbb_db_migration 'COLUMNS' => array( // this column was removed from the database updater // after 3.0.9-RC3 was released. It might still exist - // in 3.0.9-RCX installations and has to be dropped in - // 3.0.12 after the db_tools class is capable of properly + // in 3.0.9-RCX installations and has to be dropped as + // soon as the db_tools class is capable of properly // removing a primary key. // 'attempt_id' => array('UINT', NULL, 'auto_increment'), 'attempt_ip' => array('VCHAR:40', ''), diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc2.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_9_rc2.php rename to phpBB/phpbb/db/migration/data/30x/3_0_9_rc2.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc3.php b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc3.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_9_rc3.php rename to phpBB/phpbb/db/migration/data/30x/3_0_9_rc3.php diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc4.php b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc4.php similarity index 100% rename from phpBB/includes/db/migration/data/30x/3_0_9_rc4.php rename to phpBB/phpbb/db/migration/data/30x/3_0_9_rc4.php diff --git a/phpBB/phpbb/db/migration/data/30x/local_url_bbcode.php b/phpBB/phpbb/db/migration/data/30x/local_url_bbcode.php new file mode 100644 index 0000000000..f324b8880d --- /dev/null +++ b/phpBB/phpbb/db/migration/data/30x/local_url_bbcode.php @@ -0,0 +1,57 @@ +db->sql_like_expression($this->db->any_char . 'LOCAL_URL' . $this->db->any_char); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (!class_exists('acp_bbcodes')) + { + global $phpEx; + phpbb_require_updated('includes/acp/acp_bbcodes.' . $phpEx); + } + $bbcode_match = $row['bbcode_match']; + $bbcode_tpl = $row['bbcode_tpl']; + + $acp_bbcodes = new acp_bbcodes(); + $sql_ary = $acp_bbcodes->build_regexp($bbcode_match, $bbcode_tpl); + + $sql = 'UPDATE ' . BBCODES_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE bbcode_id = ' . (int) $row['bbcode_id']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } +} diff --git a/phpBB/includes/db/migration/data/310/avatars.php b/phpBB/phpbb/db/migration/data/310/avatars.php similarity index 100% rename from phpBB/includes/db/migration/data/310/avatars.php rename to phpBB/phpbb/db/migration/data/310/avatars.php diff --git a/phpBB/includes/db/migration/data/310/boardindex.php b/phpBB/phpbb/db/migration/data/310/boardindex.php similarity index 100% rename from phpBB/includes/db/migration/data/310/boardindex.php rename to phpBB/phpbb/db/migration/data/310/boardindex.php diff --git a/phpBB/includes/db/migration/data/310/config_db_text.php b/phpBB/phpbb/db/migration/data/310/config_db_text.php similarity index 100% rename from phpBB/includes/db/migration/data/310/config_db_text.php rename to phpBB/phpbb/db/migration/data/310/config_db_text.php diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/phpbb/db/migration/data/310/dev.php similarity index 98% rename from phpBB/includes/db/migration/data/310/dev.php rename to phpBB/phpbb/db/migration/data/310/dev.php index 13b36bbf30..0fc2950987 100644 --- a/phpBB/includes/db/migration/data/310/dev.php +++ b/phpBB/phpbb/db/migration/data/310/dev.php @@ -82,7 +82,10 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration public function update_data() { return array( - array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), + array('if', array( + (strpos('phpbb_search_', $this->config['search_type']) !== 0), + array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), + )), array('config.add', array('fulltext_postgres_ts_name', 'simple')), array('config.add', array('fulltext_postgres_min_word_len', 4)), diff --git a/phpBB/includes/db/migration/data/310/extensions.php b/phpBB/phpbb/db/migration/data/310/extensions.php similarity index 100% rename from phpBB/includes/db/migration/data/310/extensions.php rename to phpBB/phpbb/db/migration/data/310/extensions.php diff --git a/phpBB/includes/db/migration/data/310/forgot_password.php b/phpBB/phpbb/db/migration/data/310/forgot_password.php similarity index 100% rename from phpBB/includes/db/migration/data/310/forgot_password.php rename to phpBB/phpbb/db/migration/data/310/forgot_password.php diff --git a/phpBB/includes/db/migration/data/310/jquery_update.php b/phpBB/phpbb/db/migration/data/310/jquery_update.php similarity index 100% rename from phpBB/includes/db/migration/data/310/jquery_update.php rename to phpBB/phpbb/db/migration/data/310/jquery_update.php diff --git a/phpBB/phpbb/db/migration/data/310/notification_options_reconvert.php b/phpBB/phpbb/db/migration/data/310/notification_options_reconvert.php new file mode 100644 index 0000000000..d994d7ec5f --- /dev/null +++ b/phpBB/phpbb/db/migration/data/310/notification_options_reconvert.php @@ -0,0 +1,118 @@ +table_prefix . 'user_notifications'; + $insert_buffer = new phpbb_db_sql_insert_buffer($this->db, $insert_table); + + $this->perform_conversion($insert_buffer, $insert_table); + } + + /** + * Perform the conversion (separate for testability) + * + * @param phpbb_db_sql_insert_buffer $insert_buffer + * @param string $insert_table + */ + public function perform_conversion(phpbb_db_sql_insert_buffer $insert_buffer, $insert_table) + { + $sql = 'DELETE FROM ' . $insert_table; + $this->db->sql_query($sql); + + $sql = 'SELECT user_id, user_notify_type, user_notify_pm + FROM ' . USERS_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $notification_methods = array(); + + // In-board notification + $notification_methods[] = ''; + + if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) + { + $notification_methods[] = 'email'; + } + + if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) + { + $notification_methods[] = 'jabber'; + } + + // Notifications for posts + foreach (array('post', 'topic') as $item_type) + { + $this->add_method_rows( + $insert_buffer, + $item_type, + 0, + $row['user_id'], + $notification_methods + ); + } + + if ($row['user_notify_pm']) + { + // Notifications for private messages + // User either gets all methods or no method + $this->add_method_rows( + $insert_buffer, + 'pm', + 0, + $row['user_id'], + $notification_methods + ); + } + } + $this->db->sql_freeresult($result); + + $insert_buffer->flush(); + } + + /** + * Insert method rows to DB + * + * @param phpbb_db_sql_insert_buffer $insert_buffer + * @param string $item_type + * @param int $item_id + * @param int $user_id + * @param string $methods + */ + protected function add_method_rows(phpbb_db_sql_insert_buffer $insert_buffer, $item_type, $item_id, $user_id, array $methods) + { + $row_base = array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'notify' => 1 + ); + + foreach ($methods as $method) + { + $row_base['method'] = $method; + $insert_buffer->insert($row_base); + } + } +} diff --git a/phpBB/includes/db/migration/data/310/notifications.php b/phpBB/phpbb/db/migration/data/310/notifications.php similarity index 56% rename from phpBB/includes/db/migration/data/310/notifications.php rename to phpBB/phpbb/db/migration/data/310/notifications.php index 82bfd4cb2d..17c939d95a 100644 --- a/phpBB/includes/db/migration/data/310/notifications.php +++ b/phpBB/phpbb/db/migration/data/310/notifications.php @@ -91,70 +91,6 @@ class phpbb_db_migration_data_310_notifications extends phpbb_db_migration ), )), array('config.add', array('load_notifications', 1)), - array('custom', array(array($this, 'convert_notifications'))), ); } - - public function convert_notifications() - { - $convert_notifications = array( - array( - 'check' => ($this->config['allow_topic_notify']), - 'item_type' => 'post', - ), - array( - 'check' => ($this->config['allow_forum_notify']), - 'item_type' => 'topic', - ), - array( - 'check' => ($this->config['allow_bookmarks']), - 'item_type' => 'bookmark', - ), - array( - 'check' => ($this->config['allow_privmsg']), - 'item_type' => 'pm', - ), - ); - - foreach ($convert_notifications as $convert_data) - { - if ($convert_data['check']) - { - $sql = 'SELECT user_id, user_notify_type - FROM ' . USERS_TABLE . ' - WHERE user_notify = 1'; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array( - 'item_type' => $convert_data['item_type'], - 'item_id' => 0, - 'user_id' => $row['user_id'], - 'method' => '', - ))); - - if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) - { - $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array( - 'item_type' => $convert_data['item_type'], - 'item_id' => 0, - 'user_id' => $row['user_id'], - 'method' => 'email', - ))); - } - - if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) - { - $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array( - 'item_type' => $convert_data['item_type'], - 'item_id' => 0, - 'user_id' => $row['user_id'], - 'method' => 'jabber', - ))); - } - } - $this->db->sql_freeresult($result); - } - } - } } diff --git a/phpBB/includes/db/migration/data/310/notifications_schema_fix.php b/phpBB/phpbb/db/migration/data/310/notifications_schema_fix.php similarity index 100% rename from phpBB/includes/db/migration/data/310/notifications_schema_fix.php rename to phpBB/phpbb/db/migration/data/310/notifications_schema_fix.php diff --git a/phpBB/includes/db/migration/data/310/reported_posts_display.php b/phpBB/phpbb/db/migration/data/310/reported_posts_display.php similarity index 100% rename from phpBB/includes/db/migration/data/310/reported_posts_display.php rename to phpBB/phpbb/db/migration/data/310/reported_posts_display.php diff --git a/phpBB/phpbb/db/migration/data/310/signature_module_auth.php b/phpBB/phpbb/db/migration/data/310/signature_module_auth.php new file mode 100644 index 0000000000..e4fbb27bcb --- /dev/null +++ b/phpBB/phpbb/db/migration/data/310/signature_module_auth.php @@ -0,0 +1,51 @@ +db->sql_query($sql); + $module_auth = $this->db_sql_fetchfield('module_auth'); + $this->db->sql_freeresult($result); + + return $module_auth === 'acl_u_sig' || $module_auth === false; + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_31x_dev'); + } + + public function update_data() + { + return array( + array('custom', array( + array($this, 'update_signature_module_auth'), + ), + ), + ); + } + + public function update_signature_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_sig' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'signature' + AND module_auth = ''"; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/phpbb/db/migration/data/310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/310/softdelete_p1.php new file mode 100644 index 0000000000..84f8eebd4a --- /dev/null +++ b/phpBB/phpbb/db/migration/data/310/softdelete_p1.php @@ -0,0 +1,171 @@ +db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_visibility'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_dev'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_posts_approved' => array('UINT', 0), + 'forum_posts_unapproved' => array('UINT', 0), + 'forum_posts_softdeleted' => array('UINT', 0), + 'forum_topics_approved' => array('UINT', 0), + 'forum_topics_unapproved' => array('UINT', 0), + 'forum_topics_softdeleted' => array('UINT', 0), + ), + $this->table_prefix . 'posts' => array( + 'post_visibility' => array('TINT:3', 0), + 'post_delete_time' => array('TIMESTAMP', 0), + 'post_delete_reason' => array('STEXT_UNI', ''), + 'post_delete_user' => array('UINT', 0), + ), + $this->table_prefix . 'topics' => array( + 'topic_visibility' => array('TINT:3', 0), + 'topic_delete_time' => array('TIMESTAMP', 0), + 'topic_delete_reason' => array('STEXT_UNI', ''), + 'topic_delete_user' => array('UINT', 0), + 'topic_posts_approved' => array('UINT', 0), + 'topic_posts_unapproved' => array('UINT', 0), + 'topic_posts_softdeleted' => array('UINT', 0), + ), + ), + 'add_index' => array( + $this->table_prefix . 'posts' => array( + 'post_visibility' => array('post_visibility'), + ), + $this->table_prefix . 'topics' => array( + 'topic_visibility' => array('topic_visibility'), + 'forum_vis_last' => array('forum_id', 'topic_visibility', 'topic_last_post_id'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_posts_approved', + 'forum_posts_unapproved', + 'forum_posts_softdeleted', + 'forum_topics_approved', + 'forum_topics_unapproved', + 'forum_topics_softdeleted', + ), + $this->table_prefix . 'posts' => array( + 'post_visibility', + 'post_delete_time', + 'post_delete_reason', + 'post_delete_user', + ), + $this->table_prefix . 'topics' => array( + 'topic_visibility', + 'topic_delete_time', + 'topic_delete_reason', + 'topic_delete_user', + 'topic_posts_approved', + 'topic_posts_unapproved', + 'topic_posts_softdeleted', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'posts' => array('post_visibility'), + $this->table_prefix . 'topics' => array('topic_visibility', 'forum_vis_last'), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_post_visibility'))), + array('custom', array(array($this, 'update_topic_visibility'))), + array('custom', array(array($this, 'update_topic_forum_counts'))), + + array('permission.add', array('f_softdelete', false)), + array('permission.add', array('m_softdelete', false)), + ); + } + + public function update_post_visibility() + { + $sql = 'UPDATE ' . $this->table_prefix . 'posts + SET post_visibility = post_approved'; + $this->sql_query($sql); + } + + public function update_topic_visibility() + { + $sql = 'UPDATE ' . $this->table_prefix . 'topics + SET topic_visibility = topic_approved'; + $this->sql_query($sql); + } + + public function update_topic_forum_counts() + { + $sql = 'UPDATE ' . $this->table_prefix . 'topics + SET topic_posts_approved = topic_replies + 1, + topic_posts_unapproved = topic_replies_real - topic_replies + WHERE topic_visibility = ' . ITEM_APPROVED; + $this->sql_query($sql); + + $sql = 'UPDATE ' . $this->table_prefix . 'topics + SET topic_posts_approved = 0, + topic_posts_unapproved = (topic_replies_real - topic_replies) + 1 + WHERE topic_visibility = ' . ITEM_UNAPPROVED; + $this->sql_query($sql); + + $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved + FROM ' . $this->table_prefix . 'topics + GROUP BY forum_id, topic_visibility'; + $result = $this->db->sql_query($sql); + + $update_forums = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $forum_id = (int) $row['forum_id']; + if (!isset($update_forums[$forum_id])) + { + $update_forums[$forum_id] = array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + ); + } + + $update_forums[$forum_id]['forum_posts_approved'] += (int) $row['sum_posts_approved']; + $update_forums[$forum_id]['forum_posts_unapproved'] += (int) $row['sum_posts_unapproved']; + + $update_forums[$forum_id][(($row['topic_visibility'] == ITEM_APPROVED) ? 'forum_topics_approved' : 'forum_topics_unapproved')] += (int) $row['sum_topics']; + } + $this->db->sql_freeresult($result); + + foreach ($update_forums as $forum_id => $forum_data) + { + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $forum_data) . ' + WHERE forum_id = ' . $forum_id; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/phpbb/db/migration/data/310/softdelete_p2.php b/phpBB/phpbb/db/migration/data/310/softdelete_p2.php new file mode 100644 index 0000000000..7320a2c2bf --- /dev/null +++ b/phpBB/phpbb/db/migration/data/310/softdelete_p2.php @@ -0,0 +1,68 @@ +db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_approved'); + } + + static public function depends_on() + { + return array( + 'phpbb_db_migration_data_310_dev', + 'phpbb_db_migration_data_310_softdelete_p1', + ); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array('forum_posts', 'forum_topics', 'forum_topics_real'), + $this->table_prefix . 'posts' => array('post_approved'), + $this->table_prefix . 'topics' => array('topic_approved', 'topic_replies', 'topic_replies_real'), + ), + 'drop_keys' => array( + $this->table_prefix . 'posts' => array('post_approved'), + $this->table_prefix . 'topics' => array('forum_appr_last'), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_posts' => array('UINT', 0), + 'forum_topics' => array('UINT', 0), + 'forum_topics_real' => array('UINT', 0), + ), + $this->table_prefix . 'posts' => array( + 'post_approved' => array('BOOL', 1), + ), + $this->table_prefix . 'topics' => array( + 'topic_approved' => array('BOOL', 1), + 'topic_replies' => array('UINT', 0), + 'topic_replies_real' => array('UINT', 0), + ), + ), + 'add_index' => array( + $this->table_prefix . 'posts' => array( + 'post_approved' => array('post_approved'), + ), + $this->table_prefix . 'topics' => array( + 'forum_appr_last' => array('forum_id', 'topic_approved', 'topic_last_post_id'), + ), + ), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/style_update_p1.php b/phpBB/phpbb/db/migration/data/310/style_update_p1.php similarity index 100% rename from phpBB/includes/db/migration/data/310/style_update_p1.php rename to phpBB/phpbb/db/migration/data/310/style_update_p1.php diff --git a/phpBB/includes/db/migration/data/310/style_update_p2.php b/phpBB/phpbb/db/migration/data/310/style_update_p2.php similarity index 100% rename from phpBB/includes/db/migration/data/310/style_update_p2.php rename to phpBB/phpbb/db/migration/data/310/style_update_p2.php diff --git a/phpBB/includes/db/migration/data/310/teampage.php b/phpBB/phpbb/db/migration/data/310/teampage.php similarity index 100% rename from phpBB/includes/db/migration/data/310/teampage.php rename to phpBB/phpbb/db/migration/data/310/teampage.php diff --git a/phpBB/includes/db/migration/data/310/timezone.php b/phpBB/phpbb/db/migration/data/310/timezone.php similarity index 100% rename from phpBB/includes/db/migration/data/310/timezone.php rename to phpBB/phpbb/db/migration/data/310/timezone.php diff --git a/phpBB/includes/db/migration/data/310/timezone_p2.php b/phpBB/phpbb/db/migration/data/310/timezone_p2.php similarity index 100% rename from phpBB/includes/db/migration/data/310/timezone_p2.php rename to phpBB/phpbb/db/migration/data/310/timezone_p2.php diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/phpbb/db/migration/exception.php similarity index 100% rename from phpBB/includes/db/migration/exception.php rename to phpBB/phpbb/db/migration/exception.php diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/phpbb/db/migration/migration.php similarity index 99% rename from phpBB/includes/db/migration/migration.php rename to phpBB/phpbb/db/migration/migration.php index 5f14a6953c..0ffa96fd14 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/phpbb/db/migration/migration.php @@ -44,7 +44,7 @@ abstract class phpbb_db_migration /** @var string */ protected $php_ext; - /** @var array Errors, if any occured */ + /** @var array Errors, if any occurred */ protected $errors; /** @var array List of queries executed through $this->sql_query() */ diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/phpbb/db/migration/tool/config.php similarity index 100% rename from phpBB/includes/db/migration/tool/config.php rename to phpBB/phpbb/db/migration/tool/config.php diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/phpbb/db/migration/tool/interface.php similarity index 100% rename from phpBB/includes/db/migration/tool/interface.php rename to phpBB/phpbb/db/migration/tool/interface.php diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php similarity index 100% rename from phpBB/includes/db/migration/tool/module.php rename to phpBB/phpbb/db/migration/tool/module.php diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/phpbb/db/migration/tool/permission.php similarity index 100% rename from phpBB/includes/db/migration/tool/permission.php rename to phpBB/phpbb/db/migration/tool/permission.php diff --git a/phpBB/includes/db/migrator.php b/phpBB/phpbb/db/migrator.php similarity index 100% rename from phpBB/includes/db/migrator.php rename to phpBB/phpbb/db/migrator.php diff --git a/phpBB/includes/db/sql_insert_buffer.php b/phpBB/phpbb/db/sql_insert_buffer.php similarity index 100% rename from phpBB/includes/db/sql_insert_buffer.php rename to phpBB/phpbb/db/sql_insert_buffer.php diff --git a/phpBB/includes/db/db_tools.php b/phpBB/phpbb/db/tools.php similarity index 99% rename from phpBB/includes/db/db_tools.php rename to phpBB/phpbb/db/tools.php index 983cdc18ea..492284ffcd 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/phpbb/db/tools.php @@ -303,7 +303,7 @@ class phpbb_db_tools * @param phpbb_db_driver $db Database connection * @param bool $return_statements True if only statements should be returned and no SQL being executed */ - function phpbb_db_tools(phpbb_db_driver $db, $return_statements = false) + public function __construct(phpbb_db_driver $db, $return_statements = false) { $this->db = $db; $this->return_statements = $return_statements; diff --git a/phpBB/includes/di/extension/config.php b/phpBB/phpbb/di/extension/config.php similarity index 100% rename from phpBB/includes/di/extension/config.php rename to phpBB/phpbb/di/extension/config.php diff --git a/phpBB/includes/di/extension/core.php b/phpBB/phpbb/di/extension/core.php similarity index 100% rename from phpBB/includes/di/extension/core.php rename to phpBB/phpbb/di/extension/core.php diff --git a/phpBB/includes/di/extension/ext.php b/phpBB/phpbb/di/extension/ext.php similarity index 100% rename from phpBB/includes/di/extension/ext.php rename to phpBB/phpbb/di/extension/ext.php diff --git a/phpBB/includes/di/pass/collection_pass.php b/phpBB/phpbb/di/pass/collection_pass.php similarity index 100% rename from phpBB/includes/di/pass/collection_pass.php rename to phpBB/phpbb/di/pass/collection_pass.php diff --git a/phpBB/includes/di/pass/kernel_pass.php b/phpBB/phpbb/di/pass/kernel_pass.php similarity index 100% rename from phpBB/includes/di/pass/kernel_pass.php rename to phpBB/phpbb/di/pass/kernel_pass.php diff --git a/phpBB/includes/di/service_collection.php b/phpBB/phpbb/di/service_collection.php similarity index 100% rename from phpBB/includes/di/service_collection.php rename to phpBB/phpbb/di/service_collection.php diff --git a/phpBB/includes/error_collector.php b/phpBB/phpbb/error_collector.php similarity index 100% rename from phpBB/includes/error_collector.php rename to phpBB/phpbb/error_collector.php diff --git a/phpBB/includes/event/data.php b/phpBB/phpbb/event/data.php similarity index 100% rename from phpBB/includes/event/data.php rename to phpBB/phpbb/event/data.php diff --git a/phpBB/includes/event/dispatcher.php b/phpBB/phpbb/event/dispatcher.php similarity index 100% rename from phpBB/includes/event/dispatcher.php rename to phpBB/phpbb/event/dispatcher.php diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/phpbb/event/extension_subscriber_loader.php similarity index 100% rename from phpBB/includes/event/extension_subscriber_loader.php rename to phpBB/phpbb/event/extension_subscriber_loader.php diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php similarity index 100% rename from phpBB/includes/event/kernel_exception_subscriber.php rename to phpBB/phpbb/event/kernel_exception_subscriber.php diff --git a/phpBB/includes/event/kernel_request_subscriber.php b/phpBB/phpbb/event/kernel_request_subscriber.php similarity index 100% rename from phpBB/includes/event/kernel_request_subscriber.php rename to phpBB/phpbb/event/kernel_request_subscriber.php diff --git a/phpBB/includes/event/kernel_terminate_subscriber.php b/phpBB/phpbb/event/kernel_terminate_subscriber.php similarity index 100% rename from phpBB/includes/event/kernel_terminate_subscriber.php rename to phpBB/phpbb/event/kernel_terminate_subscriber.php diff --git a/phpBB/includes/extension/base.php b/phpBB/phpbb/extension/base.php similarity index 100% rename from phpBB/includes/extension/base.php rename to phpBB/phpbb/extension/base.php diff --git a/phpBB/includes/extension/exception.php b/phpBB/phpbb/extension/exception.php similarity index 100% rename from phpBB/includes/extension/exception.php rename to phpBB/phpbb/extension/exception.php diff --git a/phpBB/includes/extension/finder.php b/phpBB/phpbb/extension/finder.php similarity index 99% rename from phpBB/includes/extension/finder.php rename to phpBB/phpbb/extension/finder.php index 49bb2a514f..155a41cda5 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/phpbb/extension/finder.php @@ -275,7 +275,7 @@ class phpbb_extension_finder $classes = array(); foreach ($files as $file => $ext_name) { - $file = preg_replace('#^includes/#', '', $file); + $file = preg_replace('#^(phpbb|includes)/#', '', $file); $classes[] = 'phpbb_' . str_replace('/', '_', substr($file, 0, -strlen('.' . $this->php_ext))); } @@ -377,7 +377,7 @@ class phpbb_extension_finder return $files; } - + /** * Finds all file system entries matching the configured options for one * specific extension diff --git a/phpBB/includes/extension/interface.php b/phpBB/phpbb/extension/interface.php similarity index 100% rename from phpBB/includes/extension/interface.php rename to phpBB/phpbb/extension/interface.php diff --git a/phpBB/includes/extension/manager.php b/phpBB/phpbb/extension/manager.php similarity index 100% rename from phpBB/includes/extension/manager.php rename to phpBB/phpbb/extension/manager.php diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php similarity index 100% rename from phpBB/includes/extension/metadata_manager.php rename to phpBB/phpbb/extension/metadata_manager.php diff --git a/phpBB/includes/extension/provider.php b/phpBB/phpbb/extension/provider.php similarity index 100% rename from phpBB/includes/extension/provider.php rename to phpBB/phpbb/extension/provider.php diff --git a/phpBB/includes/feed/base.php b/phpBB/phpbb/feed/base.php similarity index 95% rename from phpBB/includes/feed/base.php rename to phpBB/phpbb/feed/base.php index af28ee8dc8..296d830932 100644 --- a/phpBB/includes/feed/base.php +++ b/phpBB/phpbb/feed/base.php @@ -80,10 +80,11 @@ abstract class phpbb_feed_base * @param phpbb_cache_driver_interface $cache Cache object * @param phpbb_user $user User object * @param phpbb_auth $auth Auth object + * @param phpbb_content_visibility $content_visibility Auth object * @param string $phpEx php file extension * @return null */ - function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, $phpEx) + function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, phpbb_content_visibility $content_visibility, $phpEx) { $this->config = $config; $this->helper = $helper; @@ -91,6 +92,7 @@ abstract class phpbb_feed_base $this->cache = $cache; $this->user = $user; $this->auth = $auth; + $this->content_visibility = $content_visibility; $this->phpEx = $phpEx; $this->set_keys(); diff --git a/phpBB/includes/feed/factory.php b/phpBB/phpbb/feed/factory.php similarity index 100% rename from phpBB/includes/feed/factory.php rename to phpBB/phpbb/feed/factory.php diff --git a/phpBB/includes/feed/forum.php b/phpBB/phpbb/feed/forum.php similarity index 90% rename from phpBB/includes/feed/forum.php rename to phpBB/phpbb/feed/forum.php index 7670fbeaaa..b5f0dd0f8f 100644 --- a/phpBB/includes/feed/forum.php +++ b/phpBB/phpbb/feed/forum.php @@ -90,14 +90,12 @@ class phpbb_feed_forum extends phpbb_feed_post_base function get_sql() { - $m_approve = ($this->auth->acl_get('m_approve', $this->forum_id)) ? true : false; - // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' WHERE forum_id = ' . $this->forum_id . ' AND topic_moved_id = 0 - ' . ((!$m_approve) ? 'AND topic_approved = 1' : '') . ' + AND ' . $this->content_visibility->get_visibility_sql('topic', $this->forum_id) . ' ORDER BY topic_last_post_time DESC'; $result = $this->db->sql_query_limit($sql, $this->num_items); @@ -117,14 +115,14 @@ class phpbb_feed_forum extends phpbb_feed_post_base } $this->sql = array( - '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, ' . + 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, 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', USERS_TABLE => 'u', ), 'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . ' - ' . ((!$m_approve) ? 'AND p.post_approved = 1' : '') . ' + AND ' . $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.') . ' AND p.post_time >= ' . $min_post_time . ' AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', diff --git a/phpBB/includes/feed/forums.php b/phpBB/phpbb/feed/forums.php similarity index 91% rename from phpBB/includes/feed/forums.php rename to phpBB/phpbb/feed/forums.php index 72f786aa6a..409097a9f3 100644 --- a/phpBB/includes/feed/forums.php +++ b/phpBB/phpbb/feed/forums.php @@ -49,7 +49,7 @@ class phpbb_feed_forums extends phpbb_feed_base $this->sql = array( 'SELECT' => 'f.forum_id, f.left_id, f.forum_name, f.forum_last_post_time, f.forum_desc, f.forum_desc_bitfield, f.forum_desc_uid, f.forum_desc_options, - f.forum_topics, f.forum_posts', + f.forum_topics_approved, f.forum_posts_approved', 'FROM' => array(FORUMS_TABLE => 'f'), 'WHERE' => 'f.forum_type = ' . FORUM_POST . ' AND ' . $this->db->sql_in_set('f.forum_id', $in_fid_ary), @@ -65,8 +65,8 @@ class phpbb_feed_forums extends phpbb_feed_base if ($this->config['feed_item_statistics']) { - $item_row['statistics'] = $this->user->lang('TOTAL_TOPICS', (int) $row['forum_topics']) - . ' ' . $this->separator_stats . ' ' . $this->user->lang('TOTAL_POSTS_COUNT', (int) $row['forum_posts']); + $item_row['statistics'] = $this->user->lang('TOTAL_TOPICS', (int) $row['forum_topics_approved']) + . ' ' . $this->separator_stats . ' ' . $this->user->lang('TOTAL_POSTS_COUNT', (int) $row['forum_posts_approved']); } } } diff --git a/phpBB/includes/feed/helper.php b/phpBB/phpbb/feed/helper.php similarity index 100% rename from phpBB/includes/feed/helper.php rename to phpBB/phpbb/feed/helper.php diff --git a/phpBB/includes/feed/news.php b/phpBB/phpbb/feed/news.php similarity index 93% rename from phpBB/includes/feed/news.php rename to phpBB/phpbb/feed/news.php index 92cc18a3ab..f2d45b5165 100644 --- a/phpBB/includes/feed/news.php +++ b/phpBB/phpbb/feed/news.php @@ -72,7 +72,7 @@ class phpbb_feed_news extends phpbb_feed_topic_base FROM ' . TOPICS_TABLE . ' WHERE ' . $this->db->sql_in_set('forum_id', $in_fid_ary) . ' AND topic_moved_id = 0 - AND topic_approved = 1 + AND topic_visibility = ' . ITEM_APPROVED . ' ORDER BY topic_time DESC'; $result = $this->db->sql_query_limit($sql, $this->num_items); @@ -90,7 +90,7 @@ 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, t.topic_last_post_time, + t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, 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', diff --git a/phpBB/includes/feed/overall.php b/phpBB/phpbb/feed/overall.php similarity index 77% rename from phpBB/includes/feed/overall.php rename to phpBB/phpbb/feed/overall.php index 5fb922f6bb..869df7cde0 100644 --- a/phpBB/includes/feed/overall.php +++ b/phpBB/phpbb/feed/overall.php @@ -33,17 +33,11 @@ class phpbb_feed_overall extends phpbb_feed_post_base return false; } - // m_approve forums - $fid_m_approve = $this->get_moderator_approve_forums(); - $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $this->db->sql_in_set('forum_id', $fid_m_approve) : ''; - // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' - WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . ' - AND topic_moved_id = 0 - AND (topic_approved = 1 - ' . $sql_m_approve . ') + WHERE topic_moved_id = 0 + AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids) . ' ORDER BY topic_last_post_time DESC'; $result = $this->db->sql_query_limit($sql, $this->num_items); @@ -65,7 +59,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_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, ' . + 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, 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', @@ -78,8 +72,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base ), ), 'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . ' - AND (p.post_approved = 1 - ' . str_replace('forum_id', 'p.forum_id', $sql_m_approve) . ') + AND ' . $this->content_visibility->get_visibility_sql('post', array(), 'p.') . ' AND p.post_time >= ' . $min_post_time . ' AND u.user_id = p.poster_id', 'ORDER_BY' => 'p.post_time DESC', diff --git a/phpBB/includes/feed/post_base.php b/phpBB/phpbb/feed/post_base.php similarity index 88% rename from phpBB/includes/feed/post_base.php rename to phpBB/phpbb/feed/post_base.php index a25ed50263..1f4cb4b5ef 100644 --- a/phpBB/includes/feed/post_base.php +++ b/phpBB/phpbb/feed/post_base.php @@ -51,7 +51,7 @@ abstract class phpbb_feed_post_base extends phpbb_feed_base { $item_row['statistics'] = $this->user->lang['POSTED'] . ' ' . $this->user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) . ' ' . $this->separator_stats . ' ' . $this->user->format_date($row[$this->get('published')]) - . (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POST_UNAPPROVED'] : ''); + . (($this->is_moderator_approve_forum($row['forum_id']) && $row['post_visibility'] !== ITEM_APPROVED) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POST_UNAPPROVED'] : ''); } } } diff --git a/phpBB/includes/feed/topic.php b/phpBB/phpbb/feed/topic.php similarity index 87% rename from phpBB/includes/feed/topic.php rename to phpBB/phpbb/feed/topic.php index 7d9a344982..36f958ac60 100644 --- a/phpBB/includes/feed/topic.php +++ b/phpBB/phpbb/feed/topic.php @@ -43,7 +43,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base function open() { - $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_approved, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type + $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_visibility, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type FROM ' . TOPICS_TABLE . ' t LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id) @@ -94,14 +94,14 @@ class phpbb_feed_topic extends phpbb_feed_post_base function get_sql() { $this->sql = array( - '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, ' . + 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, 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', USERS_TABLE => 'u', ), 'WHERE' => 'p.topic_id = ' . $this->topic_id . ' - ' . ($this->forum_id && !$this->auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . ' + AND ' . $this->content_visibility->get_visibility_sql('post', $this->forum_id, 'p.') . ' AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', ); diff --git a/phpBB/includes/feed/topic_base.php b/phpBB/phpbb/feed/topic_base.php similarity index 83% rename from phpBB/includes/feed/topic_base.php rename to phpBB/phpbb/feed/topic_base.php index e6a47b4c86..b104a46631 100644 --- a/phpBB/includes/feed/topic_base.php +++ b/phpBB/phpbb/feed/topic_base.php @@ -51,9 +51,9 @@ abstract class phpbb_feed_topic_base extends phpbb_feed_base { $item_row['statistics'] = $this->user->lang['POSTED'] . ' ' . $this->user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) . ' ' . $this->separator_stats . ' ' . $this->user->format_date($row[$this->get('published')]) - . ' ' . $this->separator_stats . ' ' . $this->user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies']) + . ' ' . $this->separator_stats . ' ' . $this->user->lang['REPLIES'] . ' ' . $this->content_visibility->get_count('topic_posts', $row, $row['forum_id']) - 1 . ' ' . $this->separator_stats . ' ' . $this->user->lang['VIEWS'] . ' ' . $row['topic_views'] - . (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POSTS_UNAPPROVED'] : ''); + . (($this->is_moderator_approve_forum($row['forum_id']) && $row['topic_posts_unapproved']) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POSTS_UNAPPROVED'] : ''); } } } diff --git a/phpBB/includes/feed/topics.php b/phpBB/phpbb/feed/topics.php similarity index 91% rename from phpBB/includes/feed/topics.php rename to phpBB/phpbb/feed/topics.php index c8761d7176..31f5177773 100644 --- a/phpBB/includes/feed/topics.php +++ b/phpBB/phpbb/feed/topics.php @@ -44,7 +44,7 @@ class phpbb_feed_topics extends phpbb_feed_topic_base FROM ' . TOPICS_TABLE . ' WHERE ' . $this->db->sql_in_set('forum_id', $in_fid_ary) . ' AND topic_moved_id = 0 - AND topic_approved = 1 + AND topic_visibility = ' . ITEM_APPROVED . ' ORDER BY topic_time DESC'; $result = $this->db->sql_query_limit($sql, $this->num_items); @@ -62,7 +62,7 @@ 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, t.topic_last_post_time, + t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, 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', diff --git a/phpBB/includes/feed/topics_active.php b/phpBB/phpbb/feed/topics_active.php similarity index 95% rename from phpBB/includes/feed/topics_active.php rename to phpBB/phpbb/feed/topics_active.php index d1c920c136..249dd1d66a 100644 --- a/phpBB/includes/feed/topics_active.php +++ b/phpBB/phpbb/feed/topics_active.php @@ -59,7 +59,7 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base FROM ' . TOPICS_TABLE . ' WHERE ' . $this->db->sql_in_set('forum_id', $in_fid_ary) . ' AND topic_moved_id = 0 - AND topic_approved = 1 + AND topic_visibility = ' . ITEM_APPROVED . ' ' . $last_post_time_sql . ' ORDER BY topic_last_post_time DESC'; $result = $this->db->sql_query_limit($sql, $this->num_items); @@ -78,7 +78,7 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base $this->sql = array( '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_id, t.topic_title, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, 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_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', 'FROM' => array( diff --git a/phpBB/includes/filesystem.php b/phpBB/phpbb/filesystem.php similarity index 100% rename from phpBB/includes/filesystem.php rename to phpBB/phpbb/filesystem.php diff --git a/phpBB/includes/groupposition/exception.php b/phpBB/phpbb/groupposition/exception.php similarity index 100% rename from phpBB/includes/groupposition/exception.php rename to phpBB/phpbb/groupposition/exception.php diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/phpbb/groupposition/interface.php similarity index 100% rename from phpBB/includes/groupposition/interface.php rename to phpBB/phpbb/groupposition/interface.php diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/phpbb/groupposition/legend.php similarity index 100% rename from phpBB/includes/groupposition/legend.php rename to phpBB/phpbb/groupposition/legend.php diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/phpbb/groupposition/teampage.php similarity index 100% rename from phpBB/includes/groupposition/teampage.php rename to phpBB/phpbb/groupposition/teampage.php diff --git a/phpBB/includes/hook/finder.php b/phpBB/phpbb/hook/finder.php similarity index 100% rename from phpBB/includes/hook/finder.php rename to phpBB/phpbb/hook/finder.php diff --git a/phpBB/includes/json_response.php b/phpBB/phpbb/json_response.php similarity index 100% rename from phpBB/includes/json_response.php rename to phpBB/phpbb/json_response.php diff --git a/phpBB/includes/lock/db.php b/phpBB/phpbb/lock/db.php similarity index 100% rename from phpBB/includes/lock/db.php rename to phpBB/phpbb/lock/db.php diff --git a/phpBB/includes/lock/flock.php b/phpBB/phpbb/lock/flock.php similarity index 100% rename from phpBB/includes/lock/flock.php rename to phpBB/phpbb/lock/flock.php diff --git a/phpBB/includes/log/interface.php b/phpBB/phpbb/log/interface.php similarity index 100% rename from phpBB/includes/log/interface.php rename to phpBB/phpbb/log/interface.php diff --git a/phpBB/includes/log/log.php b/phpBB/phpbb/log/log.php similarity index 100% rename from phpBB/includes/log/log.php rename to phpBB/phpbb/log/log.php diff --git a/phpBB/includes/notification/exception.php b/phpBB/phpbb/notification/exception.php similarity index 100% rename from phpBB/includes/notification/exception.php rename to phpBB/phpbb/notification/exception.php diff --git a/phpBB/includes/notification/manager.php b/phpBB/phpbb/notification/manager.php similarity index 100% rename from phpBB/includes/notification/manager.php rename to phpBB/phpbb/notification/manager.php diff --git a/phpBB/includes/notification/method/base.php b/phpBB/phpbb/notification/method/base.php similarity index 100% rename from phpBB/includes/notification/method/base.php rename to phpBB/phpbb/notification/method/base.php diff --git a/phpBB/includes/notification/method/email.php b/phpBB/phpbb/notification/method/email.php similarity index 100% rename from phpBB/includes/notification/method/email.php rename to phpBB/phpbb/notification/method/email.php diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/phpbb/notification/method/interface.php similarity index 100% rename from phpBB/includes/notification/method/interface.php rename to phpBB/phpbb/notification/method/interface.php diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/phpbb/notification/method/jabber.php similarity index 100% rename from phpBB/includes/notification/method/jabber.php rename to phpBB/phpbb/notification/method/jabber.php diff --git a/phpBB/includes/notification/method/messenger_base.php b/phpBB/phpbb/notification/method/messenger_base.php similarity index 100% rename from phpBB/includes/notification/method/messenger_base.php rename to phpBB/phpbb/notification/method/messenger_base.php diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php similarity index 100% rename from phpBB/includes/notification/type/approve_post.php rename to phpBB/phpbb/notification/type/approve_post.php diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php similarity index 100% rename from phpBB/includes/notification/type/approve_topic.php rename to phpBB/phpbb/notification/type/approve_topic.php diff --git a/phpBB/includes/notification/type/base.php b/phpBB/phpbb/notification/type/base.php similarity index 100% rename from phpBB/includes/notification/type/base.php rename to phpBB/phpbb/notification/type/base.php diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php similarity index 100% rename from phpBB/includes/notification/type/bookmark.php rename to phpBB/phpbb/notification/type/bookmark.php diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/phpbb/notification/type/disapprove_post.php similarity index 100% rename from phpBB/includes/notification/type/disapprove_post.php rename to phpBB/phpbb/notification/type/disapprove_post.php diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/phpbb/notification/type/disapprove_topic.php similarity index 100% rename from phpBB/includes/notification/type/disapprove_topic.php rename to phpBB/phpbb/notification/type/disapprove_topic.php diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/phpbb/notification/type/interface.php similarity index 100% rename from phpBB/includes/notification/type/interface.php rename to phpBB/phpbb/notification/type/interface.php diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/phpbb/notification/type/pm.php similarity index 100% rename from phpBB/includes/notification/type/pm.php rename to phpBB/phpbb/notification/type/pm.php diff --git a/phpBB/includes/notification/type/post.php b/phpBB/phpbb/notification/type/post.php similarity index 100% rename from phpBB/includes/notification/type/post.php rename to phpBB/phpbb/notification/type/post.php diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/phpbb/notification/type/post_in_queue.php similarity index 100% rename from phpBB/includes/notification/type/post_in_queue.php rename to phpBB/phpbb/notification/type/post_in_queue.php diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php similarity index 100% rename from phpBB/includes/notification/type/quote.php rename to phpBB/phpbb/notification/type/quote.php diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/phpbb/notification/type/report_pm.php similarity index 100% rename from phpBB/includes/notification/type/report_pm.php rename to phpBB/phpbb/notification/type/report_pm.php diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/phpbb/notification/type/report_pm_closed.php similarity index 100% rename from phpBB/includes/notification/type/report_pm_closed.php rename to phpBB/phpbb/notification/type/report_pm_closed.php diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/phpbb/notification/type/report_post.php similarity index 100% rename from phpBB/includes/notification/type/report_post.php rename to phpBB/phpbb/notification/type/report_post.php diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php similarity index 100% rename from phpBB/includes/notification/type/report_post_closed.php rename to phpBB/phpbb/notification/type/report_post_closed.php diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php similarity index 100% rename from phpBB/includes/notification/type/topic.php rename to phpBB/phpbb/notification/type/topic.php diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/phpbb/notification/type/topic_in_queue.php similarity index 100% rename from phpBB/includes/notification/type/topic_in_queue.php rename to phpBB/phpbb/notification/type/topic_in_queue.php diff --git a/phpBB/includes/php/ini.php b/phpBB/phpbb/php/ini.php similarity index 100% rename from phpBB/includes/php/ini.php rename to phpBB/phpbb/php/ini.php diff --git a/phpBB/includes/request/deactivated_super_global.php b/phpBB/phpbb/request/deactivated_super_global.php similarity index 100% rename from phpBB/includes/request/deactivated_super_global.php rename to phpBB/phpbb/request/deactivated_super_global.php diff --git a/phpBB/includes/request/interface.php b/phpBB/phpbb/request/interface.php similarity index 100% rename from phpBB/includes/request/interface.php rename to phpBB/phpbb/request/interface.php diff --git a/phpBB/includes/request/request.php b/phpBB/phpbb/request/request.php similarity index 100% rename from phpBB/includes/request/request.php rename to phpBB/phpbb/request/request.php diff --git a/phpBB/includes/request/type_cast_helper.php b/phpBB/phpbb/request/type_cast_helper.php similarity index 100% rename from phpBB/includes/request/type_cast_helper.php rename to phpBB/phpbb/request/type_cast_helper.php diff --git a/phpBB/includes/request/type_cast_helper_interface.php b/phpBB/phpbb/request/type_cast_helper_interface.php similarity index 100% rename from phpBB/includes/request/type_cast_helper_interface.php rename to phpBB/phpbb/request/type_cast_helper_interface.php diff --git a/phpBB/includes/search/base.php b/phpBB/phpbb/search/base.php similarity index 100% rename from phpBB/includes/search/base.php rename to phpBB/phpbb/search/base.php diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/phpbb/search/fulltext_mysql.php similarity index 95% rename from phpBB/includes/search/fulltext_mysql.php rename to phpBB/phpbb/search/fulltext_mysql.php index aa493c3281..7dc4da8ffe 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/phpbb/search/fulltext_mysql.php @@ -140,7 +140,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Checks for correct MySQL version and stores min/max word length in the config * - * @return string|bool Language key of the error/incompatiblity occured + * @return string|bool Language key of the error/incompatiblity occurred */ public function init() { @@ -351,7 +351,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -360,7 +360,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts if (!$this->search_query) @@ -378,7 +378,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary) ))); @@ -445,19 +445,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary === array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } - $sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : ''; $sql_select = ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id'; $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : ''; @@ -480,7 +467,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; - $sql_where_options .= $m_approve_fid_sql; + $sql_where_options .= ' AND ' . $post_visibility; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_where_options .= $sql_match_where; @@ -546,7 +533,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -574,7 +561,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -629,18 +616,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary == array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } + $m_approve_fid_sql = ' AND ' . $post_visibility; // If the cache was completely empty count the results $calc_results = ($result_count) ? '' : 'SQL_CALC_FOUND_ROWS '; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/phpbb/search/fulltext_native.php similarity index 97% rename from phpBB/includes/search/fulltext_native.php rename to phpBB/phpbb/search/fulltext_native.php index b9c784ea67..730c3a6c2d 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/phpbb/search/fulltext_native.php @@ -507,7 +507,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -516,7 +516,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts. if (empty($this->search_query)) @@ -544,7 +544,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -721,14 +721,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_where[] = '(' . implode(' OR ', $is_null_joins) . ')'; } - if (!sizeof($m_approve_fid_ary)) - { - $sql_where[] = 'p.post_approved = 1'; - } - else if ($m_approve_fid_ary !== array(-1)) - { - $sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } + $sql_where[] = $post_visibility; if ($topic_id) { @@ -911,7 +904,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -920,7 +913,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) @@ -939,7 +932,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -967,6 +960,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; + $post_visibility = ($post_visibility) ? ' AND ' . $post_visibility : ''; // Build sql strings for sorting $sql_sort = $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); @@ -989,19 +983,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary == array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } - $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; $is_mysql = false; @@ -1024,7 +1005,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora $sql_time"; } @@ -1044,7 +1025,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora AND t.topic_id = p.topic_id $sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : ''); @@ -1070,7 +1051,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora $sql_sort_join $sql_time @@ -1084,7 +1065,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base WHERE $sql_author $sql_topic_id $sql_firstpost - $m_approve_fid_sql + $post_visibility $sql_fora AND t.topic_id = p.topic_id $sql_sort_join diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/phpbb/search/fulltext_postgres.php similarity index 95% rename from phpBB/includes/search/fulltext_postgres.php rename to phpBB/phpbb/search/fulltext_postgres.php index 496a29f5a3..6b4b310f2e 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/phpbb/search/fulltext_postgres.php @@ -185,7 +185,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base /** * Checks for correct PostgreSQL version and stores min/max word length in the config * - * @return string|bool Language key of the error/incompatiblity occured + * @return string|bool Language key of the error/incompatiblity occurred */ public function init() { @@ -334,7 +334,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -343,7 +343,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts if (!$this->search_query) @@ -367,7 +367,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary) ))); @@ -434,19 +434,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary === array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } - $sql_select = ($type == 'posts') ? 'p.post_id' : 'DISTINCT t.topic_id'; $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : ''; $field = ($type == 'posts') ? 'post_id' : 'topic_id'; @@ -470,7 +457,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; - $sql_where_options .= $m_approve_fid_sql; + $sql_where_options .= ' AND ' . $post_visibility; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_where_options .= $sql_match_where; @@ -550,7 +537,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -559,7 +546,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) @@ -578,7 +565,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sort_key, $topic_id, implode(',', $ex_fid_ary), - implode(',', $m_approve_fid_ary), + $post_visibility, implode(',', $author_ary), $author_name, ))); @@ -633,18 +620,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base break; } - if (!sizeof($m_approve_fid_ary)) - { - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } - else if ($m_approve_fid_ary == array(-1)) - { - $m_approve_fid_sql = ''; - } - else - { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; - } + $m_approve_fid_sql = ' AND ' . $post_visibility; // Build the query for really selecting the post_ids if ($type == 'posts') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/phpbb/search/fulltext_sphinx.php similarity index 96% rename from phpBB/includes/search/fulltext_sphinx.php rename to phpBB/phpbb/search/fulltext_sphinx.php index 63e35eb4af..4f3f852664 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/phpbb/search/fulltext_sphinx.php @@ -135,11 +135,6 @@ class phpbb_search_fulltext_sphinx $this->db = $db; $this->auth = $auth; - if (!class_exists('phpbb_db_tools')) - { - require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->php_ext); - } - // Initialize phpbb_db_tools object $this->db_tools = new phpbb_db_tools($this->db); @@ -274,6 +269,7 @@ class phpbb_search_fulltext_sphinx p.forum_id, p.topic_id, p.poster_id, + p.post_visibility, CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, p.post_time, p.post_subject, @@ -291,6 +287,7 @@ class phpbb_search_fulltext_sphinx array('sql_attr_uint', 'forum_id'), array('sql_attr_uint', 'topic_id'), array('sql_attr_uint', 'poster_id'), + array('sql_attr_uint', 'post_visibility'), array('sql_attr_bool', 'topic_first_post'), array('sql_attr_bool', 'deleted'), array('sql_attr_timestamp' , 'post_time'), @@ -306,6 +303,7 @@ class phpbb_search_fulltext_sphinx p.forum_id, p.topic_id, p.poster_id, + p.post_visibility, CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, p.post_time, p.post_subject, @@ -445,7 +443,7 @@ class phpbb_search_fulltext_sphinx * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -454,7 +452,7 @@ class phpbb_search_fulltext_sphinx * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts. if (!strlen($this->search_query) && !sizeof($author_ary)) @@ -569,6 +567,11 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetFilter('poster_id', $author_ary); } + // As this is not simply possible at the moment, we limit the result to approved posts. + // This will make it impossible for moderators to search unapproved and softdeleted posts, + // but at least it will also cause the same for normal users. + $this->sphinx->SetFilter('post_visibility', array(ITEM_APPROVED)); + if (sizeof($ex_fid_ary)) { // All forums that a user is allowed to access @@ -611,7 +614,7 @@ class phpbb_search_fulltext_sphinx $result_count = $result['total_found']; - if ($start >= $result_count) + if ($result_count && $start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; @@ -663,7 +666,7 @@ class phpbb_search_fulltext_sphinx * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched - * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param string $post_visibility specifies which types of posts the user can view in which forums * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched * @param array $author_ary an array of author ids * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match @@ -672,14 +675,14 @@ class phpbb_search_fulltext_sphinx * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { $this->search_query = ''; $this->sphinx->SetMatchMode(SPH_MATCH_FULLSCAN); $fields = ($firstpost_only) ? 'firstpost' : 'all'; $terms = 'all'; - return $this->keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, $id_ary, $start, $per_page); + return $this->keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, $id_ary, $start, $per_page); } /** diff --git a/phpBB/phpbb/search/index.htm b/phpBB/phpbb/search/index.htm new file mode 100644 index 0000000000..ee1f723a7d --- /dev/null +++ b/phpBB/phpbb/search/index.htm @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/phpBB/includes/search/sphinx/config.php b/phpBB/phpbb/search/sphinx/config.php similarity index 100% rename from phpBB/includes/search/sphinx/config.php rename to phpBB/phpbb/search/sphinx/config.php diff --git a/phpBB/includes/search/sphinx/config_comment.php b/phpBB/phpbb/search/sphinx/config_comment.php similarity index 100% rename from phpBB/includes/search/sphinx/config_comment.php rename to phpBB/phpbb/search/sphinx/config_comment.php diff --git a/phpBB/includes/search/sphinx/config_section.php b/phpBB/phpbb/search/sphinx/config_section.php similarity index 100% rename from phpBB/includes/search/sphinx/config_section.php rename to phpBB/phpbb/search/sphinx/config_section.php diff --git a/phpBB/includes/search/sphinx/config_variable.php b/phpBB/phpbb/search/sphinx/config_variable.php similarity index 100% rename from phpBB/includes/search/sphinx/config_variable.php rename to phpBB/phpbb/search/sphinx/config_variable.php diff --git a/phpBB/includes/session.php b/phpBB/phpbb/session.php similarity index 98% rename from phpBB/includes/session.php rename to phpBB/phpbb/session.php index 6bc71da0c1..e0585b1523 100644 --- a/phpBB/includes/session.php +++ b/phpBB/phpbb/session.php @@ -207,7 +207,7 @@ class phpbb_session function session_begin($update_session_page = true) { global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $config, $phpbb_root_path; - global $request; + global $request, $phpbb_container; // Give us some basic information $this->time_now = time(); @@ -402,15 +402,18 @@ class phpbb_session // Check whether the session is still valid if we have one $method = basename(trim($config['auth_method'])); - include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); - $method = 'validate_session_' . $method; - if (function_exists($method)) + $provider = $phpbb_container->get('auth.provider.' . $method); + + if (!($provider instanceof phpbb_auth_provider_interface)) { - if (!$method($this->data)) - { - $session_expired = true; - } + throw new \RuntimeException($provider . ' must implement phpbb_auth_provider_interface'); + } + + $ret = $provider->validate_session($this->data); + if ($ret !== null && !$ret) + { + $session_expired = true; } if (!$session_expired) @@ -504,7 +507,7 @@ class phpbb_session */ function session_create($user_id = false, $set_admin = false, $persist_login = false, $viewonline = true) { - global $SID, $_SID, $db, $config, $cache, $phpbb_root_path, $phpEx; + global $SID, $_SID, $db, $config, $cache, $phpbb_root_path, $phpEx, $phpbb_container; $this->data = array(); @@ -568,18 +571,14 @@ class phpbb_session } $method = basename(trim($config['auth_method'])); - include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); - $method = 'autologin_' . $method; - if (function_exists($method)) + $provider = $phpbb_container->get('auth.provider.' . $method); + $this->data = $provider->autologin(); + + if (sizeof($this->data)) { - $this->data = $method(); - - if (sizeof($this->data)) - { - $this->cookie_data['k'] = ''; - $this->cookie_data['u'] = $this->data['user_id']; - } + $this->cookie_data['k'] = ''; + $this->cookie_data['u'] = $this->data['user_id']; } // If we're presented with an autologin key we'll join against it. @@ -884,7 +883,7 @@ class phpbb_session */ function session_kill($new_session = true) { - global $SID, $_SID, $db, $config, $phpbb_root_path, $phpEx; + global $SID, $_SID, $db, $config, $phpbb_root_path, $phpEx, $phpbb_container; $sql = 'DELETE FROM ' . SESSIONS_TABLE . " WHERE session_id = '" . $db->sql_escape($this->session_id) . "' @@ -893,13 +892,9 @@ class phpbb_session // Allow connecting logout with external auth method logout $method = basename(trim($config['auth_method'])); - include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); - $method = 'logout_' . $method; - if (function_exists($method)) - { - $method($this->data, $new_session); - } + $provider = $phpbb_container->get('auth.provider.' . $method); + $provider->logout($this->data, $new_session); if ($this->data['user_id'] != ANONYMOUS) { diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/phpbb/style/extension_path_provider.php similarity index 100% rename from phpBB/includes/style/extension_path_provider.php rename to phpBB/phpbb/style/extension_path_provider.php diff --git a/phpBB/includes/style/path_provider.php b/phpBB/phpbb/style/path_provider.php similarity index 100% rename from phpBB/includes/style/path_provider.php rename to phpBB/phpbb/style/path_provider.php diff --git a/phpBB/includes/style/path_provider_interface.php b/phpBB/phpbb/style/path_provider_interface.php similarity index 100% rename from phpBB/includes/style/path_provider_interface.php rename to phpBB/phpbb/style/path_provider_interface.php diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/phpbb/style/resource_locator.php similarity index 100% rename from phpBB/includes/style/resource_locator.php rename to phpBB/phpbb/style/resource_locator.php diff --git a/phpBB/includes/style/style.php b/phpBB/phpbb/style/style.php similarity index 71% rename from phpBB/includes/style/style.php rename to phpBB/phpbb/style/style.php index 4703c3a219..034f518091 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/phpbb/style/style.php @@ -85,28 +85,62 @@ class phpbb_style } /** - * Set style location based on (current) user's chosen style. + * Get the style tree of the style preferred by the current user + * + * @return array Style tree, most specific first */ - public function set_style() + public function get_user_style() { - $style_path = $this->user->style['style_path']; - $style_dirs = ($this->user->style['style_parent_id']) ? array_reverse(explode('/', $this->user->style['style_parent_tree'])) : array(); + $style_list = array( + $this->user->style['style_path'], + ); - $names = array($style_path); - foreach ($style_dirs as $dir) + if ($this->user->style['style_parent_id']) { - $names[] = $dir; + $style_list = array_merge($style_list, array_reverse(explode('/', $this->user->style['style_parent_tree']))); } - // Add 'all' path, used as last fallback path by events and extensions - //$names[] = 'all'; + + return $style_list; + } + + /** + * Set style location based on (current) user's chosen style. + * + * @param array $style_directories The directories to add style paths for + * E.g. array('ext/foo/bar/styles', 'styles') + * Default: array('styles') (phpBB's style directory) + * @return bool true + */ + public function set_style($style_directories = array('styles')) + { + $this->names = $this->get_user_style(); $paths = array(); - foreach ($names as $name) + foreach ($style_directories as $directory) { - $paths[] = $this->get_style_path($name); + foreach ($this->names as $name) + { + $path = $this->get_style_path($name, $directory); + + if (is_dir($path)) + { + $paths[] = $path; + } + } } - return $this->set_custom_style($style_path, $paths, $names); + $this->provider->set_styles($paths); + $this->locator->set_paths($this->provider); + + $new_paths = array(); + foreach ($paths as $path) + { + $new_paths[] = $path . '/template/'; + } + + $this->template->set_style_names($this->names, $new_paths, ($style_directories === array('styles'))); + + return true; } /** @@ -118,6 +152,7 @@ class phpbb_style * @param array or string $paths Array of style paths, relative to current root directory * @param array $names Array of names of templates in inheritance tree order, used by extensions. If empty, $name will be used. * @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/). + * @return bool true */ public function set_custom_style($name, $paths, $names = array(), $template_path = false) { @@ -135,18 +170,18 @@ class phpbb_style $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); - $this->template->set_style_names($names); - if ($template_path !== false) { $this->locator->set_template_path($template_path); } - else + + $new_paths = array(); + foreach ($paths as $path) { - $this->locator->set_default_template_path(); + $new_paths[] = $path . '/' . (($template_path !== false) ? $template_path : 'template/'); } - $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; + $this->template->set_style_names($names, $new_paths); return true; } @@ -155,11 +190,14 @@ class phpbb_style * Get location of style directory for specific style_path * * @param string $path Style path, such as "prosilver" + * @param string $style_base_directory The base directory the style is in + * E.g. 'styles', 'ext/foo/bar/styles' + * Default: 'styles' * @return string Path to style directory, relative to current path */ - public function get_style_path($path) + public function get_style_path($path, $style_base_directory = 'styles') { - return $this->phpbb_root_path . 'styles/' . $path; + return $this->phpbb_root_path . trim($style_base_directory, '/') . '/' . $path; } /** diff --git a/phpBB/phpbb/template/asset.php b/phpBB/phpbb/template/asset.php new file mode 100644 index 0000000000..7c322cd971 --- /dev/null +++ b/phpBB/phpbb/template/asset.php @@ -0,0 +1,182 @@ +set_url($url); + } + + /** + * Set URL + * + * @param string $url URL + */ + public function set_url($url) + { + if (version_compare(PHP_VERSION, '5.4.7') < 0 && substr($url, 0, 2) === '//') + { + // Workaround for PHP 5.4.6 and older bug #62844 - add fake scheme and then remove it + $this->components = parse_url('http:' . $url); + $this->components['scheme'] = ''; + return; + } + $this->components = parse_url($url); + } + + /** + * Convert URL components into string + * + * @param array $components URL components + * @return string URL + */ + protected function join_url($components) + { + $path = ''; + if (isset($components['scheme'])) + { + $path = $components['scheme'] === '' ? '//' : $components['scheme'] . '://'; + } + + if (isset($components['user']) || isset($components['pass'])) + { + if ($path === '' && !isset($components['port'])) + { + $path = '//'; + } + $path .= $components['user']; + if (isset($components['pass'])) + { + $path .= ':' . $components['pass']; + } + $path .= '@'; + } + + if (isset($components['host'])) + { + if ($path === '' && !isset($components['port'])) + { + $path = '//'; + } + $path .= $components['host']; + if (isset($components['port'])) + { + $path .= ':' . $components['port']; + } + } + + if (isset($components['path'])) + { + $path .= $components['path']; + } + + if (isset($components['query'])) + { + $path .= '?' . $components['query']; + } + + if (isset($components['fragment'])) + { + $path .= '#' . $components['fragment']; + } + + return $path; + } + + /** + * Get URL + * + * @return string URL + */ + public function get_url() + { + return $this->join_url($this->components); + } + + /** + * Checks if URL is local and relative + * + * @return boolean True if URL is local and relative + */ + public function is_relative() + { + if (empty($this->components) || !isset($this->components['path'])) + { + // Invalid URL + return false; + } + return !isset($this->components['scheme']) && !isset($this->components['host']) && substr($this->components['path'], 0, 1) !== '/'; + } + + /** + * Get path component of current URL + * + * @return string Path + */ + public function get_path() + { + return isset($this->components['path']) ? $this->components['path'] : ''; + } + + /** + * Set path component + * + * @param string $path Path component + * @param boolean $urlencode If true, parts of path should be encoded with rawurlencode() + */ + public function set_path($path, $urlencode = false) + { + if ($urlencode) + { + $paths = explode('/', $path); + foreach ($paths as &$dir) + { + $dir = rawurlencode($dir); + } + $path = implode('/', $paths); + } + $this->components['path'] = $path; + } + + /** + * Add assets_version parameter to URL. + * Parameter will not be added if assets_version already exists in URL + * + * @param string $version Version + */ + public function add_assets_version($version) + { + if (!isset($this->components['query'])) + { + $this->components['query'] = 'assets_version=' . $version; + return; + } + $query = $this->components['query']; + if (!preg_match('/(^|[&;])assets_version=/', $query)) + { + $this->components['query'] = $query . '&assets_version=' . $version; + } + } +} diff --git a/phpBB/includes/template/context.php b/phpBB/phpbb/template/context.php similarity index 90% rename from phpBB/includes/template/context.php rename to phpBB/phpbb/template/context.php index ec09da1cf3..c5ce7422b9 100644 --- a/phpBB/includes/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -138,7 +138,7 @@ class phpbb_template_context } $s_row_count = isset($str[$blocks[$blockcount]]) ? sizeof($str[$blocks[$blockcount]]) : 0; - $vararray['S_ROW_COUNT'] = $s_row_count; + $vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count; // Assign S_FIRST_ROW if (!$s_row_count) @@ -146,6 +146,9 @@ class phpbb_template_context $vararray['S_FIRST_ROW'] = true; } + // Assign S_BLOCK_NAME + $vararray['S_BLOCK_NAME'] = $blocks[$blockcount]; + // Now the tricky part, we always assign S_LAST_ROW and remove the entry before // This is much more clever than going through the complete template data on display (phew) $vararray['S_LAST_ROW'] = true; @@ -158,12 +161,18 @@ class phpbb_template_context // We're adding a new iteration to this block with the given // variable assignments. $str[$blocks[$blockcount]][] = $vararray; + + // Set S_NUM_ROWS + foreach ($str[$blocks[$blockcount]] as &$mod_block) + { + $mod_block['S_NUM_ROWS'] = sizeof($str[$blocks[$blockcount]]); + } } else { // Top-level block. $s_row_count = (isset($this->tpldata[$blockname])) ? sizeof($this->tpldata[$blockname]) : 0; - $vararray['S_ROW_COUNT'] = $s_row_count; + $vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count; // Assign S_FIRST_ROW if (!$s_row_count) @@ -171,6 +180,9 @@ class phpbb_template_context $vararray['S_FIRST_ROW'] = true; } + // Assign S_BLOCK_NAME + $vararray['S_BLOCK_NAME'] = $blockname; + // We always assign S_LAST_ROW and remove the entry before $vararray['S_LAST_ROW'] = true; if ($s_row_count > 0) @@ -180,6 +192,12 @@ class phpbb_template_context // Add a new iteration to this block with the variable assignments we were given. $this->tpldata[$blockname][] = $vararray; + + // Set S_NUM_ROWS + foreach ($this->tpldata[$blockname] as &$mod_block) + { + $mod_block['S_NUM_ROWS'] = sizeof($this->tpldata[$blockname]); + } } return true; @@ -298,14 +316,26 @@ class phpbb_template_context $vararray['S_FIRST_ROW'] = true; } + // Assign S_BLOCK_NAME + $vararray['S_BLOCK_NAME'] = $blockname; + // Re-position template blocks for ($i = sizeof($block); $i > $key; $i--) { $block[$i] = $block[$i-1]; + + $block[$i]['S_ROW_COUNT'] = $block[$i]['S_ROW_NUM'] = $i; } // Insert vararray at given position $block[$key] = $vararray; + $block[$key]['S_ROW_COUNT'] = $block[$key]['S_ROW_NUM'] = $key; + + // Set S_NUM_ROWS + foreach ($this->tpldata[$blockname] as &$mod_block) + { + $mod_block['S_NUM_ROWS'] = sizeof($this->tpldata[$blockname]); + } return true; } diff --git a/phpBB/includes/template/locator.php b/phpBB/phpbb/template/locator.php similarity index 100% rename from phpBB/includes/template/locator.php rename to phpBB/phpbb/template/locator.php diff --git a/phpBB/phpbb/template/template.php b/phpBB/phpbb/template/template.php new file mode 100644 index 0000000000..89a01e924d --- /dev/null +++ b/phpBB/phpbb/template/template.php @@ -0,0 +1,157 @@ + filename pairs. + * @return phpbb_template $this + */ + public function set_filenames(array $filename_array); + + /** + * Sets the style names/paths corresponding to style hierarchy being compiled + * and/or rendered. + * + * @param array $style_names List of style names in inheritance tree order + * @param array $style_paths List of style paths in inheritance tree order + * @return phpbb_template $this + */ + public function set_style_names(array $style_names, array $style_paths); + + /** + * Clears all variables and blocks assigned to this template. + * + * @return phpbb_template $this + */ + public function destroy(); + + /** + * Reset/empty complete block + * + * @param string $blockname Name of block to destroy + * @return phpbb_template $this + */ + public function destroy_block_vars($blockname); + + /** + * Display a template for provided handle. + * + * The template will be loaded and compiled, if necessary, first. + * + * This function calls hooks. + * + * @param string $handle Handle to display + * @return phpbb_template $this + */ + public function display($handle); + + /** + * Display the handle and assign the output to a template variable + * or return the compiled result. + * + * @param string $handle Handle to operate on + * @param string $template_var Template variable to assign compiled handle to + * @param bool $return_content If true return compiled handle, otherwise assign to $template_var + * @return phpbb_template|string if $return_content is true return string of the compiled handle, otherwise return $this + */ + public function assign_display($handle, $template_var = '', $return_content = true); + + /** + * Assign key variable pairs from an array + * + * @param array $vararray A hash of variable name => value pairs + * @return phpbb_template $this + */ + public function assign_vars(array $vararray); + + /** + * Assign a single scalar value to a single key. + * + * Value can be a string, an integer or a boolean. + * + * @param string $varname Variable name + * @param string $varval Value to assign to variable + * @return phpbb_template $this + */ + public function assign_var($varname, $varval); + + /** + * Append text to the string value stored in a key. + * + * Text is appended using the string concatenation operator (.). + * + * @param string $varname Variable name + * @param string $varval Value to append to variable + * @return phpbb_template $this + */ + public function append_var($varname, $varval); + + /** + * Assign key variable pairs from an array to a specified block + * @param string $blockname Name of block to assign $vararray to + * @param array $vararray A hash of variable name => value pairs + * @return phpbb_template $this + */ + public function assign_block_vars($blockname, array $vararray); + + /** + * Change already assigned key variable pair (one-dimensional - single loop entry) + * + * An example of how to use this function: + * {@example alter_block_array.php} + * + * @param string $blockname the blockname, for example 'loop' + * @param array $vararray the var array to insert/add or merge + * @param mixed $key Key to search for + * + * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] + * + * int: Position [the position to change or insert at directly given] + * + * If key is false the position is set to 0 + * If key is true the position is set to the last entry + * + * @param string $mode Mode to execute (valid modes are 'insert' and 'change') + * + * If insert, the vararray is inserted at the given position (position counting from zero). + * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). + * + * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) + * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) + * + * @return bool false on error, true on success + */ + public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert'); + + /** + * Get path to template for handle (required for BBCode parser) + * + * @return string + */ + public function get_source_file_for_handle($handle); +} diff --git a/phpBB/phpbb/template/twig/definition.php b/phpBB/phpbb/template/twig/definition.php new file mode 100644 index 0000000000..6557b209eb --- /dev/null +++ b/phpBB/phpbb/template/twig/definition.php @@ -0,0 +1,69 @@ +definitions[$name])) ? $this->definitions[$name] : null; + } + + /** + * DEFINE a variable + * + * @param string $name + * @param mixed $value + * @return phpbb_template_twig_definition + */ + public function set($name, $value) + { + $this->definitions[$name] = $value; + + return $this; + } + + /** + * Append to a variable + * + * @param string $name + * @param string $value + * @return phpbb_template_twig_definition + */ + public function append($name, $value) + { + if (!isset($this->definitions[$name])) + { + $this->definitions[$name] = ''; + } + + $this->definitions[$name] .= $value; + + return $this; + } +} diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php new file mode 100644 index 0000000000..b60cd72325 --- /dev/null +++ b/phpBB/phpbb/template/twig/environment.php @@ -0,0 +1,140 @@ + path) + * @param string $phpbb_root_path + * @param Twig_LoaderInterface $loader + * @param array $options Array of options to pass to Twig + */ + public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array()) + { + $this->phpbb_config = $phpbb_config; + $this->phpbb_extensions = $phpbb_extensions; + $this->phpbb_root_path = $phpbb_root_path; + + return parent::__construct($loader, $options); + } + + /** + * Get the list of enabled phpBB extensions + * + * Used in EVENT node + * + * @return array + */ + public function get_phpbb_extensions() + { + return $this->phpbb_extensions; + } + + /** + * Get phpBB config + * + * @return phpbb_config + */ + public function get_phpbb_config() + { + return $this->phpbb_config; + } + + /** + * Get the phpBB root path + * + * @return string + */ + public function get_phpbb_root_path() + { + return $this->phpbb_root_path; + } + + /** + * Get the namespace look up order + * + * @return array + */ + public function getNamespaceLookUpOrder() + { + return $this->namespace_look_up_order; + } + + /** + * Set the namespace look up order to load templates from + * + * @param array $namespace + * @return Twig_Environment + */ + public function setNamespaceLookUpOrder($namespace) + { + $this->namespace_look_up_order = $namespace; + + return $this; + } + + /** + * Loads a template by name. + * + * @param string $name The template name + * @param integer $index The index if it is an embedded template + * @return Twig_TemplateInterface A template instance representing the given template name + */ + public function loadTemplate($name, $index = null) + { + if (strpos($name, '@') === false) + { + foreach ($this->getNamespaceLookUpOrder() as $namespace) + { + try + { + if ($namespace === '__main__') + { + return parent::loadTemplate($name, $index); + } + + return parent::loadTemplate('@' . $namespace . '/' . $name, $index); + } + catch (Twig_Error_Loader $e) + { + } + } + + // We were unable to load any templates + throw $e; + } + else + { + return parent::loadTemplate($name, $index); + } + } +} diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php new file mode 100644 index 0000000000..c279726434 --- /dev/null +++ b/phpBB/phpbb/template/twig/extension.php @@ -0,0 +1,188 @@ +context = $context; + $this->user = $user; + } + + /** + * Get the name of this extension + * + * @return string + */ + public function getName() + { + return 'phpbb'; + } + + /** + * Returns the token parser instance to add to the existing list. + * + * @return array An array of Twig_TokenParser instances + */ + public function getTokenParsers() + { + return array( + new phpbb_template_twig_tokenparser_define, + new phpbb_template_twig_tokenparser_include, + new phpbb_template_twig_tokenparser_includejs, + new phpbb_template_twig_tokenparser_includecss, + new phpbb_template_twig_tokenparser_event, + new phpbb_template_twig_tokenparser_includephp, + new phpbb_template_twig_tokenparser_php, + ); + } + + /** + * Returns a list of filters to add to the existing list. + * + * @return array An array of filters + */ + public function getFilters() + { + return array( + new Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), + new Twig_SimpleFilter('addslashes', 'addslashes'), + ); + } + + /** + * Returns a list of global functions to add to the existing list. + * + * @return array An array of global functions + */ + public function getFunctions() + { + return array( + new Twig_SimpleFunction('lang', array($this, 'lang')), + ); + } + + /** + * Returns a list of operators to add to the existing list. + * + * @return array An array of operators + */ + public function getOperators() + { + return array( + array( + '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), + ), + array( + // precedence settings are copied from similar operators in Twig core extension + '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + + 'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + + 'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + + '===' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_equalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '!==' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_notequalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + + 'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + + 'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + ), + ); + } + + /** + * Grabs a subset of a loop + * + * @param Twig_Environment $env A Twig_Environment instance + * @param mixed $item A variable + * @param integer $start Start of the subset + * @param integer $end End of the subset + * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array) + * + * @return mixed The sliced variable + */ + function loop_subset(Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false) + { + // We do almost the same thing as Twig's slice (array_slice), except when $end is positive + if ($end >= 1) + { + // When end is > 1, subset will end on the last item in an array with the specified $end + // This is different from slice in that it is the number we end on rather than the number + // of items to grab (length) + + // Start must always be the actual starting number for this calculation (not negative) + $start = ($start < 0) ? sizeof($item) + $start : $start; + $end = $end - $start; + } + + // We always include the last element (this was the past design) + $end = ($end == -1 || $end === null) ? null : $end + 1; + + return twig_slice($env, $item, $start, $end, $preserveKeys); + } + + /** + * Get output for a language variable (L_FOO, LA_FOO) + * + * This function checks to see if the language var was outputted to $context + * (e.g. in the ACP, L_TITLE) + * If not, we return the result of $user->lang() + * + * @param string $lang name + * @return string + */ + function lang() + { + $args = func_get_args(); + $key = $args[0]; + + $context = $this->context->get_data_ref(); + $context_vars = $context['.'][0]; + + if (isset($context_vars['L_' . $key])) + { + return $context_vars['L_' . $key]; + } + + // LA_ is transformed into lang(\'$1\')|addslashes, so we should not + // need to check for it + + return call_user_func_array(array($this->user, 'lang'), $args); + } +} diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php new file mode 100644 index 0000000000..46412ad048 --- /dev/null +++ b/phpBB/phpbb/template/twig/lexer.php @@ -0,0 +1,300 @@ +fix_inline_variable_tokens(array( + 'DEFINE.+=', + 'INCLUDE', + 'INCLUDEPHP', + 'INCLUDEJS', + 'INCLUDECSS', + ), $code); + + // Fix our BEGIN statements + $code = $this->fix_begin_tokens($code); + + // Fix our IF tokens + $code = $this->fix_if_tokens($code); + + // Fix our DEFINE tokens + $code = $this->fix_define_tokens($code); + + // Replace all of our starting tokens, with Twig style, {% TOKEN %} + // This also strips outer parenthesis, becomes + $code = preg_replace('##', '{% $1 $2 %}', $code); + + // Replace all of our twig masks with Twig code (e.g. with {% block $1 %}) + $code = $this->replace_twig_tag_masks($code, $twig_tags); + + // Replace all of our language variables, {L_VARNAME}, with Twig style, {{ lang('NAME') }} + // Appends any filters after lang() + $code = preg_replace('#{L_([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ lang(\'$1\')$2 }}', $code); + + // Replace all of our escaped language variables, {LA_VARNAME}, with Twig style, {{ lang('NAME')|addslashes }} + // Appends any filters after lang(), but before addslashes + $code = preg_replace('#{LA_([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ lang(\'$1\')$2|addslashes }}', $code); + + // Replace all of our variables, {VARNAME}, with Twig style, {{ VARNAME }} + // Appends any filters + $code = preg_replace('#{([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ $1$2 }}', $code); + + return parent::tokenize($code, $filename); + } + + /** + * Fix tokens that may have inline variables + * + * E.g. "; + }; + + return preg_replace_callback('##', $callback, $code); + } + + /** + * Fix begin tokens (convert our BEGIN to Twig for) + * + * Not meant to be used outside of this context, public because the anonymous function calls this + * + * @param string $code + * @param array $parent_nodes (used in recursion) + * @return string + */ + public function fix_begin_tokens($code, $parent_nodes = array()) + { + // PHP 5.3 cannot use $this in an anonymous function, so use this as a work-around + $parent_class = $this; + $callback = function ($matches) use ($parent_class, $parent_nodes) + { + $name = $matches[1]; + $subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis + $body = $matches[3]; + + // Is the designer wanting to call another loop in a loop? + // + // + // + // + // 'loop2' is actually on the same nesting level as 'loop' you assign + // variables to it with template->assign_block_vars('loop2', array(...)) + if (strpos($name, '!') === 0) + { + // Count the number if ! occurrences + $count = substr_count($name, '!'); + for ($i = 0; $i < $count; $i++) + { + array_pop($parent_nodes); + $name = substr($name, 1); + } + } + + // Remove all parent nodes, e.g. foo, bar from foo.bar.foobar.VAR + foreach ($parent_nodes as $node) + { + $body = preg_replace('#([^a-zA-Z0-9_])' . $node . '\.([a-zA-Z0-9_]+)\.#', '$1$2.', $body); + } + + // Add current node to list of parent nodes for child nodes + $parent_nodes[] = $name; + + // Recursive...fix any child nodes + $body = $parent_class->fix_begin_tokens($body, $parent_nodes); + + // Rename loopname vars (to prevent collisions, loop children are named (loop name)_loop_element) + $body = str_replace($name . '.', $name . '_loop_element.', $body); + + // Need the parent variable name + array_pop($parent_nodes); + $parent = (!empty($parent_nodes)) ? end($parent_nodes) . '_loop_element.' : ''; + + if ($subset !== '') + { + $subset = '|subset(' . $subset . ')'; + } + + // Turn into a Twig for loop, using (loop name)_loop_element for each child + return "{% for {$name}_loop_element in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; + }; + + // Replace correctly, only needs to be done once + $code = str_replace('', '{% else %}', $code); + + return preg_replace_callback('#(.+?)#s', $callback, $code); + } + + /** + * Fix IF statements + * + * @param string $code + * @return string + */ + protected function fix_if_tokens($code) + { + $callback = function($matches) + { + // Replace $TEST with definition.TEST + $matches[1] = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $matches[1]); + + // Replace .test with test|length + $matches[1] = preg_replace('#\s\.([a-zA-Z_0-9\.]+)#', ' $1|length', $matches[1]); + + return ''; + }; + + // Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces) + $code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); + + return preg_replace_callback('##', $callback, $code); + } + + /** + * Fix DEFINE statements and {$VARNAME} variables + * + * @param string $code + * @return string + */ + protected function fix_define_tokens($code) + { + /** + * Changing $VARNAME to definition.varname because set is only local + * context (e.g. DEFINE $TEST will only make $TEST available in current + * template and any child templates, but not any parent templates). + * + * DEFINE handles setting it properly to definition in its node, but the + * variables reading FROM it need to be altered to definition.VARNAME + * + * Setting up definition as a class in the array passed to Twig + * ($context) makes set definition.TEST available in the global context + */ + + // Replace #', '{% DEFINE $1 %}', $code); + + // Changing UNDEFINE NAME to DEFINE NAME = null to save from creating an extra token parser/node + $code = preg_replace('##', '{% DEFINE $1= null %}', $code); + + // Replace all of our variables, {$VARNAME}, with Twig style, {{ definition.VARNAME }} + $code = preg_replace('#{\$([a-zA-Z0-9_\.]+)}#', '{{ definition.$1 }}', $code); + + // Replace all of our variables, ~ $VARNAME ~, with Twig style, ~ definition.VARNAME ~ + $code = preg_replace('#~ \$([a-zA-Z0-9_\.]+) ~#', '~ definition.$1 ~', $code); + + return $code; + } + + /** + * Replace Twig tag masks with Twig tag calls + * + * E.g. with {% block foo %} + * + * @param string $code + * @param array $twig_tags All tags we want to create a mask for + * @return string + */ + protected function replace_twig_tag_masks($code, $twig_tags) + { + $callback = function ($matches) + { + $matches[1] = strtolower($matches[1]); + + return "{% {$matches[1]}{$matches[2]}%}"; + }; + + foreach ($twig_tags as &$tag) + { + $tag = strtoupper($tag); + } + + // twig_tags is an array of the twig tags, which are all lowercase, but we use all uppercase tags + $code = preg_replace_callback('##',$callback, $code); + + return $code; + } +} diff --git a/phpBB/phpbb/template/twig/node/define.php b/phpBB/phpbb/template/twig/node/define.php new file mode 100644 index 0000000000..fcb19cc773 --- /dev/null +++ b/phpBB/phpbb/template/twig/node/define.php @@ -0,0 +1,58 @@ + $name, 'value' => $value), array('capture' => $capture, 'safe' => false), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); + + if ($this->getAttribute('capture')) { + $compiler + ->write("ob_start();\n") + ->subcompile($this->getNode('value')) + ; + + $compiler->write("\$value = ('' === \$value = ob_get_clean()) ? '' : new Twig_Markup(\$value, \$this->env->getCharset());\n"); + } + else + { + $compiler + ->write("\$value = ") + ->subcompile($this->getNode('value')) + ->raw(";\n") + ; + } + + $compiler + ->write("\$context['definition']->set('") + ->raw($this->getNode('name')->getAttribute('name')) + ->raw("', \$value);\n") + ; + } +} diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php new file mode 100644 index 0000000000..971dea14fa --- /dev/null +++ b/phpBB/phpbb/template/twig/node/event.php @@ -0,0 +1,79 @@ +environment = $environment; + + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $location = $this->getNode('expr')->getAttribute('name'); + + foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path) + { + $ext_namespace = str_replace('/', '_', $ext_namespace); + + if (defined('DEBUG')) + { + // If debug mode is enabled, lets check for new/removed EVENT + // templates on page load rather than at compile. This is + // slower, but makes developing extensions easier (no need to + // purge the cache when a new event template file is added) + $compiler + ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n") + ->indent() + ; + } + + if (defined('DEBUG') || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) + { + $compiler + ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") + + // We set the namespace lookup order to be this extension first, then the main path + ->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n") + ->write("\$this->env->loadTemplate('@{$ext_namespace}/{$location}.html')->display(\$context);\n") + ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") + ; + } + + if (defined('DEBUG')) + { + $compiler + ->outdent() + ->write("}\n\n") + ; + } + } + } +} diff --git a/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php new file mode 100644 index 0000000000..8ec2069114 --- /dev/null +++ b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php @@ -0,0 +1,25 @@ +raw('==='); + } +} diff --git a/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php new file mode 100644 index 0000000000..96f32c502e --- /dev/null +++ b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php @@ -0,0 +1,25 @@ +raw('!=='); + } +} diff --git a/phpBB/phpbb/template/twig/node/include.php b/phpBB/phpbb/template/twig/node/include.php new file mode 100644 index 0000000000..5c6ae1bbcf --- /dev/null +++ b/phpBB/phpbb/template/twig/node/include.php @@ -0,0 +1,56 @@ +addDebugInfo($this); + + $compiler + ->write("\$location = ") + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ->write("\$namespace = false;\n") + ->write("if (strpos(\$location, '@') === 0) {\n") + ->indent() + ->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n") + ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") + + // We set the namespace lookup order to be this namespace first, then the main path + ->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n") + ->outdent() + ->write("}\n") + ; + + parent::compile($compiler); + + $compiler + ->write("if (\$namespace) {\n") + ->indent() + ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") + ->outdent() + ->write("}\n") + ; + } +} diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php new file mode 100644 index 0000000000..990b1c984f --- /dev/null +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -0,0 +1,60 @@ +environment = $environment; + + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + } + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $config = $this->environment->get_phpbb_config(); + + $compiler + ->write("\$asset_file = ") + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ->write("\$asset = new phpbb_template_asset(\$asset_file);\n") + ->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n") + ->indent() + ->write("\$asset_path = \$asset->get_path();") + ->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n") + ->write("if (!file_exists(\$local_file)) {\n") + ->indent() + ->write("\$local_file = \$this->getEnvironment()->getLoader()->getCacheKey(\$asset_path);\n") + ->write("\$asset->set_path(\$local_file, true);\n") + ->outdent() + ->write("\$asset->add_assets_version({$config['assets_version']});\n") + ->write("\$asset_file = \$asset->get_url();\n") + ->write("}\n") + ->outdent() + ->write("}\n") + ->write("\$context['definition']->append('{$this->get_definition_name()}', '") + ; + + $this->append_asset($compiler); + + $compiler + ->raw("\n');\n") + ; + } +} diff --git a/phpBB/phpbb/template/twig/node/includecss.php b/phpBB/phpbb/template/twig/node/includecss.php new file mode 100644 index 0000000000..01fda44aad --- /dev/null +++ b/phpBB/phpbb/template/twig/node/includecss.php @@ -0,0 +1,30 @@ +raw("raw("\$asset_file . '\"") + ->raw(' rel="stylesheet" type="text/css" media="screen, projection" />') + ; + } +} diff --git a/phpBB/phpbb/template/twig/node/includejs.php b/phpBB/phpbb/template/twig/node/includejs.php new file mode 100644 index 0000000000..fdf2bea3ed --- /dev/null +++ b/phpBB/phpbb/template/twig/node/includejs.php @@ -0,0 +1,32 @@ +environment->get_phpbb_config(); + + $compiler + ->raw("\n") + ; + } +} diff --git a/phpBB/phpbb/template/twig/node/includephp.php b/phpBB/phpbb/template/twig/node/includephp.php new file mode 100644 index 0000000000..dbe54f0e1a --- /dev/null +++ b/phpBB/phpbb/template/twig/node/includephp.php @@ -0,0 +1,91 @@ +environment = $environment; + + parent::__construct(array('expr' => $expr), array('ignore_missing' => (Boolean) $ignoreMissing), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $config = $this->environment->get_phpbb_config(); + + if (!$config['tpl_allow_php']) + { + $compiler + ->write("// INCLUDEPHP Disabled\n") + ; + + return; + } + + if ($this->getAttribute('ignore_missing')) { + $compiler + ->write("try {\n") + ->indent() + ; + } + + $compiler + ->write("\$location = ") + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ->write("if (phpbb_is_absolute(\$location)) {\n") + ->indent() + // Absolute path specified + ->write("require(\$location);\n") + ->outdent() + ->write("} else if (file_exists(\$this->getEnvironment()->get_phpbb_root_path() . \$location)) {\n") + ->indent() + // PHP file relative to phpbb_root_path + ->write("require(\$this->getEnvironment()->get_phpbb_root_path() . \$location);\n") + ->outdent() + ->write("} else {\n") + ->indent() + // Local path (behaves like INCLUDE) + ->write("require(\$this->getEnvironment()->getLoader()->getCacheKey(\$location));\n") + ->outdent() + ->write("}\n") + ; + + if ($this->getAttribute('ignore_missing')) { + $compiler + ->outdent() + ->write("} catch (Twig_Error_Loader \$e) {\n") + ->indent() + ->write("// ignore missing template\n") + ->outdent() + ->write("}\n\n") + ; + } + } +} diff --git a/phpBB/phpbb/template/twig/node/php.php b/phpBB/phpbb/template/twig/node/php.php new file mode 100644 index 0000000000..c11539ea7f --- /dev/null +++ b/phpBB/phpbb/template/twig/node/php.php @@ -0,0 +1,55 @@ +environment = $environment; + + parent::__construct(array('text' => $text), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $config = $this->environment->get_phpbb_config(); + + if (!$config['tpl_allow_php']) + { + $compiler + ->write("// PHP Disabled\n") + ; + + return; + } + + $compiler + ->raw($this->getNode('text')->getAttribute('data')) + ; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/define.php b/phpBB/phpbb/template/twig/tokenparser/define.php new file mode 100644 index 0000000000..4ea15388c4 --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/define.php @@ -0,0 +1,66 @@ +getLine(); + $stream = $this->parser->getStream(); + $name = $this->parser->getExpressionParser()->parseExpression(); + + $capture = false; + if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) { + $stream->next(); + $value = $this->parser->getExpressionParser()->parseExpression(); + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + } else { + $capture = true; + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + $value = $this->parser->subparse(array($this, 'decideBlockEnd'), true); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + } + + return new phpbb_template_twig_node_define($capture, $name, $value, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Twig_Token $token) + { + return $token->test('ENDDEFINE'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'DEFINE'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/event.php b/phpBB/phpbb/template/twig/tokenparser/event.php new file mode 100644 index 0000000000..e4dddd6dcc --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/event.php @@ -0,0 +1,47 @@ +parser->getExpressionParser()->parseExpression(); + + $stream = $this->parser->getStream(); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new phpbb_template_twig_node_event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'EVENT'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/include.php b/phpBB/phpbb/template/twig/tokenparser/include.php new file mode 100644 index 0000000000..520f9fd1a0 --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/include.php @@ -0,0 +1,46 @@ +parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + return new phpbb_template_twig_node_include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'INCLUDE'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/includecss.php b/phpBB/phpbb/template/twig/tokenparser/includecss.php new file mode 100644 index 0000000000..6c24dda647 --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/includecss.php @@ -0,0 +1,38 @@ +parser->getExpressionParser()->parseExpression(); + + $stream = $this->parser->getStream(); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new phpbb_template_twig_node_includecss($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'INCLUDECSS'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/includejs.php b/phpBB/phpbb/template/twig/tokenparser/includejs.php new file mode 100644 index 0000000000..b02b2f89ba --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/includejs.php @@ -0,0 +1,47 @@ +parser->getExpressionParser()->parseExpression(); + + $stream = $this->parser->getStream(); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new phpbb_template_twig_node_includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'INCLUDEJS'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/includephp.php b/phpBB/phpbb/template/twig/tokenparser/includephp.php new file mode 100644 index 0000000000..13fe6de8a6 --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/includephp.php @@ -0,0 +1,56 @@ +parser->getExpressionParser()->parseExpression(); + + $stream = $this->parser->getStream(); + + $ignoreMissing = false; + if ($stream->test(Twig_Token::NAME_TYPE, 'ignore')) { + $stream->next(); + $stream->expect(Twig_Token::NAME_TYPE, 'missing'); + + $ignoreMissing = true; + } + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new phpbb_template_twig_node_includephp($expr, $this->parser->getEnvironment(), $ignoreMissing, $token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'INCLUDEPHP'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/php.php b/phpBB/phpbb/template/twig/tokenparser/php.php new file mode 100644 index 0000000000..197980a59a --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/php.php @@ -0,0 +1,55 @@ +parser->getStream(); + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + $body = $this->parser->subparse(array($this, 'decideEnd'), true); + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new phpbb_template_twig_node_php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); + } + + public function decideEnd(Twig_Token $token) + { + return $token->test('ENDPHP'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'PHP'; + } +} diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php new file mode 100644 index 0000000000..92a37d1634 --- /dev/null +++ b/phpBB/phpbb/template/twig/twig.php @@ -0,0 +1,465 @@ +phpbb_root_path = $phpbb_root_path; + $this->adm_relative_path = $adm_relative_path; + $this->php_ext = $php_ext; + $this->config = $config; + $this->user = $user; + $this->context = $context; + $this->extension_manager = $extension_manager; + + $this->cachepath = $phpbb_root_path . 'cache/twig/'; + + // Initiate the loader, __main__ namespace paths will be setup later in set_style_names() + $loader = new Twig_Loader_Filesystem(''); + + $this->twig = new phpbb_template_twig_environment( + $this->config, + ($this->extension_manager) ? $this->extension_manager->all_enabled() : array(), + $this->phpbb_root_path, + $loader, + array( + 'cache' => (defined('IN_INSTALL')) ? false : $this->cachepath, + 'debug' => defined('DEBUG'), + 'auto_reload' => (bool) $this->config['load_tplcompile'], + 'autoescape' => false, + ) + ); + + $this->twig->addExtension( + new phpbb_template_twig_extension( + $this->context, + $this->user + ) + ); + + $lexer = new phpbb_template_twig_lexer($this->twig); + + $this->twig->setLexer($lexer); + } + + /** + * Clear the cache + * + * @return phpbb_template + */ + public function clear_cache() + { + if (is_dir($this->cachepath)) + { + $this->twig->clearCacheFiles(); + } + + return $this; + } + + /** + * Sets the template filenames for handles. + * + * @param array $filename_array Should be a hash of handle => filename pairs. + * @return phpbb_template $this + */ + public function set_filenames(array $filename_array) + { + $this->filenames = array_merge($this->filenames, $filename_array); + + return $this; + } + + /** + * Sets the style names/paths corresponding to style hierarchy being compiled + * and/or rendered. + * + * @param array $style_names List of style names in inheritance tree order + * @param array $style_paths List of style paths in inheritance tree order + * @param bool $is_core True if the style names are the "core" styles for this page load + * Core means the main phpBB template files + * @return phpbb_template $this + */ + public function set_style_names(array $style_names, array $style_paths, $is_core = false) + { + $this->style_names = $style_names; + + // Set as __main__ namespace + $this->twig->getLoader()->setPaths($style_paths); + + // Core style namespace from phpbb_style::set_style() + if ($is_core) + { + $this->twig->getLoader()->setPaths($style_paths, 'core'); + } + + // Add admin namespace + if (is_dir($this->phpbb_root_path . $this->adm_relative_path . 'style/')) + { + $this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->adm_relative_path . 'style/', 'admin'); + } + + // Add all namespaces for all extensions + if ($this->extension_manager instanceof phpbb_extension_manager) + { + $style_names[] = 'all'; + + foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path) + { + // namespaces cannot contain / + $namespace = str_replace('/', '_', $ext_namespace); + $paths = array(); + + foreach ($style_names as $style_name) + { + $ext_style_path = $ext_path . 'styles/' . $style_name . '/template'; + + if (is_dir($ext_style_path)) + { + $paths[] = $ext_style_path; + } + } + + $this->twig->getLoader()->setPaths($paths, $namespace); + } + } + + return $this; + } + + /** + * Clears all variables and blocks assigned to this template. + * + * @return phpbb_template $this + */ + public function destroy() + { + $this->context = array(); + + return $this; + } + + /** + * Reset/empty complete block + * + * @param string $blockname Name of block to destroy + * @return phpbb_template $this + */ + public function destroy_block_vars($blockname) + { + $this->context->destroy_block_vars($blockname); + + return $this; + } + + /** + * Display a template for provided handle. + * + * The template will be loaded and compiled, if necessary, first. + * + * This function calls hooks. + * + * @param string $handle Handle to display + * @return phpbb_template $this + */ + public function display($handle) + { + $result = $this->call_hook($handle, __FUNCTION__); + if ($result !== false) + { + return $result[0]; + } + + $this->twig->display($this->get_filename_from_handle($handle), $this->get_template_vars()); + + return $this; + } + + /** + * Calls hook if any is defined. + * + * @param string $handle Template handle being displayed. + * @param string $method Method name of the caller. + */ + protected function call_hook($handle, $method) + { + global $phpbb_hook; + + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) + { + if ($phpbb_hook->hook_return(array(__CLASS__, $method))) + { + $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); + return array($result); + } + } + + return false; + } + + /** + * Display the handle and assign the output to a template variable + * or return the compiled result. + * + * @param string $handle Handle to operate on + * @param string $template_var Template variable to assign compiled handle to + * @param bool $return_content If true return compiled handle, otherwise assign to $template_var + * @return phpbb_template|string if $return_content is true return string of the compiled handle, otherwise return $this + */ + public function assign_display($handle, $template_var = '', $return_content = true) + { + if ($return_content) + { + return $this->twig->render($this->get_filename_from_handle($handle), $this->get_template_vars()); + } + + $this->assign_var($template_var, $this->twig->render($this->get_filename_from_handle($handle, $this->get_template_vars()))); + + return $this; + } + + /** + * Assign key variable pairs from an array + * + * @param array $vararray A hash of variable name => value pairs + * @return phpbb_template $this + */ + public function assign_vars(array $vararray) + { + foreach ($vararray as $key => $val) + { + $this->assign_var($key, $val); + } + + return $this; + } + + /** + * Assign a single scalar value to a single key. + * + * Value can be a string, an integer or a boolean. + * + * @param string $varname Variable name + * @param string $varval Value to assign to variable + * @return phpbb_template $this + */ + public function assign_var($varname, $varval) + { + $this->context->assign_var($varname, $varval); + + return $this; + } + + /** + * Append text to the string value stored in a key. + * + * Text is appended using the string concatenation operator (.). + * + * @param string $varname Variable name + * @param string $varval Value to append to variable + * @return phpbb_template $this + */ + public function append_var($varname, $varval) + { + $this->context->append_var($varname, $varval); + + return $this; + } + + /** + * Assign key variable pairs from an array to a specified block + * @param string $blockname Name of block to assign $vararray to + * @param array $vararray A hash of variable name => value pairs + * @return phpbb_template $this + */ + public function assign_block_vars($blockname, array $vararray) + { + $this->context->assign_block_vars($blockname, $vararray); + + return $this; + } + + /** + * Change already assigned key variable pair (one-dimensional - single loop entry) + * + * An example of how to use this function: + * {@example alter_block_array.php} + * + * @param string $blockname the blockname, for example 'loop' + * @param array $vararray the var array to insert/add or merge + * @param mixed $key Key to search for + * + * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] + * + * int: Position [the position to change or insert at directly given] + * + * If key is false the position is set to 0 + * If key is true the position is set to the last entry + * + * @param string $mode Mode to execute (valid modes are 'insert' and 'change') + * + * If insert, the vararray is inserted at the given position (position counting from zero). + * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). + * + * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) + * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) + * + * @return bool false on error, true on success + */ + public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') + { + return $this->context->alter_block_array($blockname, $vararray, $key, $mode); + } + + /** + * Get template vars in a format Twig will use (from the context) + * + * @return array + */ + public function get_template_vars() + { + $context_vars = $this->context->get_data_ref(); + + $vars = array_merge( + $context_vars['.'][0], // To get normal vars + $context_vars, // To get loops + array( + 'definition' => new phpbb_template_twig_definition(), + 'user' => $this->user, + ) + ); + + // cleanup + unset($vars['.']); + + return $vars; + } + + /** + * Get a filename from the handle + * + * @param string $handle + * @return string + */ + protected function get_filename_from_handle($handle) + { + return (isset($this->filenames[$handle])) ? $this->filenames[$handle] : $handle; + } + + /** + * Get path to template for handle (required for BBCode parser) + * + * @return string + */ + public function get_source_file_for_handle($handle) + { + return $this->twig->getLoader()->getCacheKey($this->get_filename_from_handle($handle)); + } +} diff --git a/phpBB/includes/tree/interface.php b/phpBB/phpbb/tree/interface.php similarity index 100% rename from phpBB/includes/tree/interface.php rename to phpBB/phpbb/tree/interface.php diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/phpbb/tree/nestedset.php similarity index 100% rename from phpBB/includes/tree/nestedset.php rename to phpBB/phpbb/tree/nestedset.php diff --git a/phpBB/includes/tree/nestedset_forum.php b/phpBB/phpbb/tree/nestedset_forum.php similarity index 100% rename from phpBB/includes/tree/nestedset_forum.php rename to phpBB/phpbb/tree/nestedset_forum.php diff --git a/phpBB/includes/user.php b/phpBB/phpbb/user.php similarity index 100% rename from phpBB/includes/user.php rename to phpBB/phpbb/user.php diff --git a/phpBB/includes/user_loader.php b/phpBB/phpbb/user_loader.php similarity index 100% rename from phpBB/includes/user_loader.php rename to phpBB/phpbb/user_loader.php diff --git a/phpBB/posting.php b/phpBB/posting.php index c6b9ff4cce..ac459197b3 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -35,11 +35,17 @@ $submit = (isset($_POST['post'])) ? true : false; $preview = (isset($_POST['preview'])) ? true : false; $save = (isset($_POST['save'])) ? true : false; $load = (isset($_POST['load'])) ? true : false; -$delete = (isset($_POST['delete'])) ? true : false; +$confirm = $request->is_set_post('confirm'); $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; -$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview) ? true : false; -$mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); +$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview); +$mode = request_var('mode', ''); + +// If the user is not allowed to delete the post, we try to soft delete it, so we overwrite the mode here. +if ($mode == 'delete' && (($confirm && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id))) +{ + $mode = 'soft_delete'; +} $error = $post_data = array(); $current_time = time(); @@ -92,6 +98,8 @@ if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$foru trigger_error('NO_FORUM'); } +$phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // We need to know some basic information in all cases before we do anything. switch ($mode) { @@ -121,13 +129,14 @@ switch ($mode) $sql = 'SELECT f.*, t.* FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.topic_id = $topic_id - AND f.forum_id = t.forum_id" . - (($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND t.topic_approved = 1'); + AND f.forum_id = t.forum_id + AND " . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'); break; case 'quote': case 'edit': case 'delete': + case 'soft_delete': if (!$post_id) { $user->setup('posting'); @@ -149,8 +158,8 @@ switch ($mode) WHERE p.post_id = $post_id AND t.topic_id = p.topic_id AND u.user_id = p.poster_id - AND f.forum_id = t.forum_id" . - (($auth->acl_get('m_approve', $forum_id)) ? '' : ' AND p.post_approved = 1'); + AND f.forum_id = t.forum_id + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id, 'p.'); break; case 'smilies': @@ -198,7 +207,7 @@ if (!$post_data) // Not able to reply to unapproved posts/topics // TODO: add more descriptive language key -if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && !$post_data['topic_approved']) || ($mode == 'quote' && !$post_data['post_approved']))) +if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && $post_data['topic_visibility'] != ITEM_APPROVED) || ($mode == 'quote' && $post_data['post_visibility'] != ITEM_APPROVED))) { trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED'); } @@ -290,11 +299,23 @@ switch ($mode) break; case 'delete': - if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id)) + if ($user->data['is_registered'] && ($auth->acl_get('m_delete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)))) { $is_authed = true; } break; + + case 'soft_delete': + if ($user->data['is_registered'] && $phpbb_content_visibility->can_soft_delete($forum_id, $post_data['poster_id'], $post_data['post_edit_locked'])) + { + $is_authed = true; + } + else + { + // Display the same error message for softdelete we use for delete + $mode = 'delete'; + } + break; } if (!$is_authed) @@ -342,9 +363,17 @@ if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id)) } // Handle delete mode... -if ($mode == 'delete') +if ($mode == 'delete' || $mode == 'soft_delete') { - handle_post_delete($forum_id, $topic_id, $post_id, $post_data); + if ($mode == 'soft_delete' && $post_data['post_visibility'] == ITEM_DELETED) + { + $user->setup('posting'); + trigger_error('NO_POST'); + } + + $allow_reason = $auth->acl_get('m_softdelete', $forum_id) || ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)); + $soft_delete_reason = ($mode == 'soft_delete' && $allow_reason) ? $request->variable('delete_reason', '', true) : ''; + handle_post_delete($forum_id, $topic_id, $post_id, $post_data, ($mode == 'soft_delete'), $soft_delete_reason); return; } @@ -900,6 +929,19 @@ if ($submit || $preview || $refresh) $error[] = $user->lang['FORM_INVALID']; } + if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && $auth->acl_get('m_approve', $forum_id)) + { + $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_posts_approved']); + $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_posts_approved']); + $updated_post_data = $phpbb_content_visibility->set_post_visibility(ITEM_APPROVED, $post_id, $post_data['topic_id'], $post_data['forum_id'], $user->data['user_id'], time(), '', $is_first_post, $is_last_post); + + if (!empty($updated_post_data)) + { + // Update the post_data, so we don't need to refetch it. + $post_data = array_merge($post_data, $updated_post_data); + } + } + // Parse subject if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id))) { @@ -1099,14 +1141,15 @@ if ($submit || $preview || $refresh) 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, - 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false, - 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false, + 'topic_visibility' => (isset($post_data['topic_visibility'])) ? $post_data['topic_visibility'] : false, + 'post_visibility' => (isset($post_data['post_visibility'])) ? $post_data['post_visibility'] : false, ); if ($mode == 'edit') { - $data['topic_replies_real'] = $post_data['topic_replies_real']; - $data['topic_replies'] = $post_data['topic_replies']; + $data['topic_posts_approved'] = $post_data['topic_posts_approved']; + $data['topic_posts_unapproved'] = $post_data['topic_posts_unapproved']; + $data['topic_posts_softdeleted'] = $post_data['topic_posts_softdeleted']; } // The last parameter tells submit_post if search indexer has to be run @@ -1117,6 +1160,15 @@ if ($submit || $preview || $refresh) $captcha->reset(); } + // Handle delete mode... + if ($request->is_set_post('delete') || $request->is_set_post('delete_permanent')) + { + $allow_reason = $auth->acl_get('m_softdelete', $forum_id) || ($auth->acl_gets('m_delete', 'f_delete', $forum_id) && $auth->acl_gets('m_softdelete', 'f_softdelete', $forum_id)); + $soft_delete_reason = (!$request->is_set_post('delete_permanent') && $allow_reason) ? $request->variable('delete_reason', '', true) : ''; + handle_post_delete($forum_id, $topic_id, $post_id, $post_data, !$request->is_set_post('delete_permanent'), $soft_delete_reason); + return; + } + // Check the permissions for post approval. // Moderators must go through post approval like ordinary users. if ((!$auth->acl_get('f_noapprove', $data['forum_id']) && empty($data['force_approved_state'])) || (isset($data['force_approved_state']) && !$data['force_approved_state'])) @@ -1438,6 +1490,11 @@ $template->assign_vars(array( 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '', 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', + 'S_SOFTDELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '', + 'S_DELETE_REASON' => ($mode == 'edit' && $auth->acl_get('m_softdelete', $forum_id)) ? true : false, + 'S_SOFTDELETE_ALLOWED' => ($mode == 'edit' && $phpbb_content_visibility->can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false, + 'S_RESTORE_ALLOWED' => $auth->acl_get('m_approve', $forum_id), + 'S_IS_DELETED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? true : false, 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', 'S_TYPE_TOGGLE' => $topic_type_toggle, @@ -1539,18 +1596,20 @@ function upload_popup($forum_style = 0) /** * Do the various checks required for removing posts as well as removing it */ -function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data) +function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_soft = false, $soft_delete_reason = '') { global $user, $db, $auth, $config; global $phpbb_root_path, $phpEx; + $perm_check = ($is_soft) ? 'softdelete' : 'delete'; + // If moderator removing post or user itself removing post, present a confirmation screen - if ($auth->acl_get('m_delete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_delete', $forum_id) && $post_id == $post_data['topic_last_post_id'] && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']))) + if ($auth->acl_get("m_$perm_check", $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get("f_$perm_check", $forum_id) && $post_id == $post_data['topic_last_post_id'] && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']))) { - $s_hidden_fields = build_hidden_fields(array( + $s_hidden_fields = array( 'p' => $post_id, 'f' => $forum_id, - 'mode' => 'delete') + 'mode' => ($is_soft) ? 'soft_delete' : 'delete', ); if (confirm_box(true)) @@ -1558,29 +1617,31 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data) $data = array( 'topic_first_post_id' => $post_data['topic_first_post_id'], 'topic_last_post_id' => $post_data['topic_last_post_id'], - 'topic_replies_real' => $post_data['topic_replies_real'], - 'topic_approved' => $post_data['topic_approved'], + 'topic_posts_approved' => $post_data['topic_posts_approved'], + 'topic_posts_unapproved' => $post_data['topic_posts_unapproved'], + 'topic_posts_softdeleted' => $post_data['topic_posts_softdeleted'], + 'topic_visibility' => $post_data['topic_visibility'], 'topic_type' => $post_data['topic_type'], - 'post_approved' => $post_data['post_approved'], + 'post_visibility' => $post_data['post_visibility'], 'post_reported' => $post_data['post_reported'], 'post_time' => $post_data['post_time'], 'poster_id' => $post_data['poster_id'], - 'post_postcount' => $post_data['post_postcount'] + 'post_postcount' => $post_data['post_postcount'], ); - $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data); + $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $soft_delete_reason); $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username']; if ($next_post_id === false) { - add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title'], $post_username); + add_log('mod', $forum_id, $topic_id, (($is_soft) ? 'LOG_SOFTDELETE_TOPIC' : 'LOG_DELETE_TOPIC'), $post_data['topic_title'], $post_username); $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"); $message = $user->lang['POST_DELETED']; } else { - add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject'], $post_username); + add_log('mod', $forum_id, $topic_id, (($is_soft) ? 'LOG_SOFTDELETE_POST' : 'LOG_DELETE_POST'), $post_data['post_subject'], $post_username); $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p=$next_post_id") . "#p$next_post_id"; $message = $user->lang['POST_DELETED'] . '

    ' . sprintf($user->lang['RETURN_TOPIC'], '', ''); @@ -1592,7 +1653,32 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data) } else { - confirm_box(false, 'DELETE_POST', $s_hidden_fields); + global $user, $template, $request; + + $can_delete = $auth->acl_get('m_delete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_delete', $forum_id)); + $can_softdelete = $auth->acl_get('m_softdelete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_softdelete', $forum_id)); + $display_reason = $auth->acl_get('m_softdelete', $forum_id) || ($can_delete && $can_softdelete); + + $template->assign_vars(array( + 'S_SOFTDELETED' => $post_data['post_visibility'] == ITEM_DELETED, + 'S_CHECKED_PERMANENT' => $request->is_set_post('delete_permanent') ? ' checked="checked"' : '', + 'S_ALLOWED_DELETE' => $can_delete, + 'S_ALLOWED_SOFTDELETE' => $can_softdelete, + 'S_DELETE_REASON' => $display_reason, + )); + + $l_confirm = 'DELETE_POST'; + if ($post_data['post_visibility'] == ITEM_DELETED) + { + $l_confirm .= '_PERMANENTLY'; + $s_hidden_fields['delete_permanent'] = '1'; + } + else if (!$can_softdelete) + { + $s_hidden_fields['delete_permanent'] = '1'; + } + + confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html'); } } diff --git a/phpBB/report.php b/phpBB/report.php index ce9fae13ef..3f2e7a91ff 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -144,9 +144,25 @@ else $reported_post_enable_magic_url = $report_data['reported_post_enable_magic_url']; } +if ($config['enable_post_confirm'] && !$user->data['is_registered']) +{ + include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx); + $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']); + $captcha->init(CONFIRM_REPORT); +} + +$error = array(); +$s_hidden_fields = ''; + // Submit report? if ($submit && $reason_id) { + $visual_confirmation_response = $captcha->validate(); + if ($visual_confirmation_response) + { + $error[] = $visual_confirmation_response; + } + $sql = 'SELECT * FROM ' . REPORTS_REASONS_TABLE . " WHERE reason_id = $reason_id"; @@ -156,96 +172,108 @@ if ($submit && $reason_id) if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other')) { - trigger_error('EMPTY_REPORT'); + $error[] = $user->lang('EMPTY_REPORT'); } - $sql_ary = array( - 'reason_id' => (int) $reason_id, - 'post_id' => $post_id, - 'pm_id' => $pm_id, - 'user_id' => (int) $user->data['user_id'], - 'user_notify' => (int) $user_notify, - 'report_closed' => 0, - 'report_time' => (int) time(), - 'report_text' => (string) $report_text, - 'reported_post_text' => $reported_post_text, - 'reported_post_uid' => $reported_post_uid, - 'reported_post_bitfield' => $reported_post_bitfield, - 'reported_post_enable_bbcode' => $reported_post_enable_bbcode, - 'reported_post_enable_smilies' => $reported_post_enable_smilies, - 'reported_post_enable_magic_url' => $reported_post_enable_magic_url, - ); - - $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - $report_id = $db->sql_nextid(); - - $phpbb_notifications = $phpbb_container->get('notification_manager'); - - if ($post_id) + if (!sizeof($error)) { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_reported = 1 - WHERE post_id = ' . $post_id; - $db->sql_query($sql); - - if (!$report_data['topic_reported']) + if (isset($captcha)) { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_reported = 1 - WHERE topic_id = ' . $report_data['topic_id'] . ' - OR topic_moved_id = ' . $report_data['topic_id']; - $db->sql_query($sql); + $captcha->reset(); } - $lang_return = $user->lang['RETURN_TOPIC']; - $lang_success = $user->lang['POST_REPORTED_SUCCESS']; - - $phpbb_notifications->add_notifications('report_post', array_merge($report_data, $row, $forum_data, array( - 'report_text' => $report_text, - ))); - } - else - { - $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' - SET message_reported = 1 - WHERE msg_id = ' . $pm_id; - $db->sql_query($sql); - $sql_ary = array( - 'msg_id' => $pm_id, - 'user_id' => ANONYMOUS, - 'author_id' => (int) $report_data['author_id'], - 'pm_deleted' => 0, - 'pm_new' => 0, - 'pm_unread' => 0, - 'pm_replied' => 0, - 'pm_marked' => 0, - 'pm_forwarded' => 0, - 'folder_id' => PRIVMSGS_INBOX, + 'reason_id' => (int) $reason_id, + 'post_id' => $post_id, + 'pm_id' => $pm_id, + 'user_id' => (int) $user->data['user_id'], + 'user_notify' => (int) $user_notify, + 'report_closed' => 0, + 'report_time' => (int) time(), + 'report_text' => (string) $report_text, + 'reported_post_text' => $reported_post_text, + 'reported_post_uid' => $reported_post_uid, + 'reported_post_bitfield' => $reported_post_bitfield, + 'reported_post_enable_bbcode' => $reported_post_enable_bbcode, + 'reported_post_enable_smilies' => $reported_post_enable_smilies, + 'reported_post_enable_magic_url' => $reported_post_enable_magic_url, ); - $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); + $report_id = $db->sql_nextid(); - $lang_return = $user->lang['RETURN_PM']; - $lang_success = $user->lang['PM_REPORTED_SUCCESS']; + $phpbb_notifications = $phpbb_container->get('notification_manager'); - $phpbb_notifications->add_notifications('report_pm', array_merge($report_data, $row, array( - 'report_text' => $report_text, - 'from_user_id' => $report_data['author_id'], - 'report_id' => $report_id, - ))); + if ($post_id) + { + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_reported = 1 + WHERE post_id = ' . $post_id; + $db->sql_query($sql); + + if (!$report_data['topic_reported']) + { + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_reported = 1 + WHERE topic_id = ' . $report_data['topic_id'] . ' + OR topic_moved_id = ' . $report_data['topic_id']; + $db->sql_query($sql); + } + + $lang_return = $user->lang['RETURN_TOPIC']; + $lang_success = $user->lang['POST_REPORTED_SUCCESS']; + + $phpbb_notifications->add_notifications('report_post', array_merge($report_data, $row, $forum_data, array( + 'report_text' => $report_text, + ))); + } + else + { + $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' + SET message_reported = 1 + WHERE msg_id = ' . $pm_id; + $db->sql_query($sql); + + $sql_ary = array( + 'msg_id' => $pm_id, + 'user_id' => ANONYMOUS, + 'author_id' => (int) $report_data['author_id'], + 'pm_deleted' => 0, + 'pm_new' => 0, + 'pm_unread' => 0, + 'pm_replied' => 0, + 'pm_marked' => 0, + 'pm_forwarded' => 0, + 'folder_id' => PRIVMSGS_INBOX, + ); + + $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + $lang_return = $user->lang['RETURN_PM']; + $lang_success = $user->lang['PM_REPORTED_SUCCESS']; + + $phpbb_notifications->add_notifications('report_pm', array_merge($report_data, $row, array( + 'report_text' => $report_text, + 'from_user_id' => $report_data['author_id'], + 'report_id' => $report_id, + ))); + } + + meta_refresh(3, $redirect_url); + + $message = $lang_success . '

    ' . sprintf($lang_return, '', ''); + if ($return_forum_url) + { + $message .= '

    ' . sprintf($user->lang['RETURN_FORUM'], '', ''); + } + trigger_error($message); } - - meta_refresh(3, $redirect_url); - - $message = $lang_success . '

    ' . sprintf($lang_return, '', ''); - if ($return_forum_url) + else if (isset($captcha) && $captcha->is_solved() !== false) { - $message .= '

    ' . sprintf($user->lang['RETURN_FORUM'], '', ''); + $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields()); } - trigger_error($message); } // Generate the reasons @@ -253,10 +281,20 @@ display_reasons($reason_id); $page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST']; +if (isset($captcha) && $captcha->is_solved() === false) +{ + $template->assign_vars(array( + 'S_CONFIRM_CODE' => true, + 'CAPTCHA_TEMPLATE' => $captcha->get_template(), + )); +} + $template->assign_vars(array( + 'ERROR' => (sizeof($error)) ? implode('
    ', $error) : '', 'S_REPORT_POST' => ($pm_id) ? false : true, 'REPORT_TEXT' => $report_text, 'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $post_id . '&pm=' . $pm_id), + 'S_HIDDEN_FIELDS' => (sizeof($s_hidden_fields)) ? $s_hidden_fields : null, 'S_NOTIFY' => $user_notify, 'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false) diff --git a/phpBB/search.php b/phpBB/search.php index 7d20d8d4a2..2429c81dae 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -119,6 +119,8 @@ $sort_by_text = array('a' => $user->lang['SORT_AUTHOR'], 't' => $user->lang['SOR $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); +$phpbb_content_visibility = $phpbb_container->get('content.visibility'); + if ($keywords || $author || $author_id || $search_id || $submit) { // clear arrays @@ -249,22 +251,9 @@ if ($keywords || $author || $author_id || $search_id || $submit) } $db->sql_freeresult($result); - // find out in which forums the user is allowed to view approved posts - if ($auth->acl_get('m_approve')) - { - $m_approve_fid_ary = array(-1); - $m_approve_fid_sql = ''; - } - else if ($auth->acl_getf_global('m_approve')) - { - $m_approve_fid_ary = array_diff(array_keys($auth->acl_getf('!m_approve', true)), $ex_fid_ary); - $m_approve_fid_sql = ' AND (p.post_approved = 1' . ((sizeof($m_approve_fid_ary)) ? ' OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) : '') . ')'; - } - else - { - $m_approve_fid_ary = array(); - $m_approve_fid_sql = ' AND p.post_approved = 1'; - } + // find out in which forums the user is allowed to view posts + $m_approve_posts_fid_sql = $phpbb_content_visibility->get_global_visibility_sql('post', $ex_fid_ary, 'p.'); + $m_approve_topics_fid_sql = $phpbb_content_visibility->get_global_visibility_sql('topic', $ex_fid_ary, 't.'); if ($reset_search_forum) { @@ -342,7 +331,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) FROM ' . TOPICS_TABLE . " t WHERE t.topic_moved_id = 0 $last_post_time_sql - " . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' + AND " . $m_approve_topics_fid_sql . ' ' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . ' ORDER BY t.topic_last_post_time DESC'; $field = 'topic_id'; @@ -380,7 +369,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) WHERE t.topic_replies = 0 AND p.topic_id = t.topic_id $last_post_time - $m_approve_fid_sql + AND $m_approve_posts_fid_sql " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . " $sql_sort"; $field = 'post_id'; @@ -393,7 +382,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) AND t.topic_moved_id = 0 AND p.topic_id = t.topic_id $last_post_time - $m_approve_fid_sql + AND $m_approve_topics_fid_sql " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . " $sql_sort"; $field = 'topic_id'; @@ -409,7 +398,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); $sql_where = 'AND t.topic_moved_id = 0 - ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' + AND ' . $m_approve_topics_fid_sql . ' ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : ''); gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); @@ -432,9 +421,9 @@ if ($keywords || $author || $author_id || $search_id || $submit) { $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p - WHERE p.post_time > ' . $user->data['user_lastvisit'] . " - $m_approve_fid_sql - " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . " + WHERE p.post_time > ' . $user->data['user_lastvisit'] . ' + AND ' . $m_approve_posts_fid_sql . ' + ' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . " $sql_sort"; $field = 'post_id'; } @@ -444,7 +433,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) FROM ' . TOPICS_TABLE . ' t WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . ' AND t.topic_moved_id = 0 - ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' + AND ' . $m_approve_topics_fid_sql . ' ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . " $sql_sort"; /* @@ -456,8 +445,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) WHERE p.post_time > ' . $user->data['user_lastvisit'] . ' AND t.topic_id = p.topic_id AND t.topic_moved_id = 0 - ' . $m_approve_fid_sql . ' - ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . " + AND ' . $m_approve_topics_fid_sql . " GROUP BY t.topic_id $sql_sort"; */ @@ -533,17 +521,16 @@ if ($keywords || $author || $author_id || $search_id || $submit) // make sure that some arrays are always in the same order sort($ex_fid_ary); - sort($m_approve_fid_ary); sort($author_id_ary); if ($search->get_search_query()) { - $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); + $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_posts_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); } else if (sizeof($author_id_ary)) { $firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false; - $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); + $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_posts_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); } // For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options. @@ -558,7 +545,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) { $sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary); $sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : ''; - $sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_approved', 'p.forum_id'), array('t.topic_approved', 't.forum_id'), $m_approve_fid_sql); + $sql_where .= ' AND ' . (($show_results == 'posts') ? $m_approve_posts_fid_sql : $m_approve_topics_fid_sql); } if ($show_results == 'posts') @@ -638,6 +625,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), + 'DELETED_IMG' => $user->img('icon_topic_deleted', 'TOPIC_DELETED'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'U_SEARCH_WORDS' => $u_search, @@ -874,12 +862,11 @@ if ($keywords || $author || $author_id || $search_id || $submit) $forum_id = $row['forum_id']; $result_topic_id = $row['topic_id']; $topic_title = censor_text($row['topic_title']); + $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1; $view_topic_url_params = "f=$forum_id&t=$result_topic_id" . (($u_hilit) ? "&hilit=$u_hilit" : ''); $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params); - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; - if ($show_results == 'topics') { if ($config['load_db_track'] && $author_id === $user->data['user_id']) @@ -892,9 +879,11 @@ if ($keywords || $author || $author_id || $search_id || $submit) $unread_topic = (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false; - $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; - $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; + $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $forum_id)) ? true : false; + $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; + $topic_deleted = $row['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$result_topic_id", true, $user->session_id) : ''; + $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&mode=deleted_topics&t=$result_topic_id", true, $user->session_id) : ''; $row['topic_title'] = preg_replace('#(?!<.*)(?]*(?:)#is', '$1', $row['topic_title']); @@ -929,6 +918,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, + 'S_TOPIC_DELETED' => $topic_deleted, 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index 2528b96ece..394aca749b 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -126,11 +126,19 @@ phpbb.addAjaxCallback('post_delete', function() { }); // This callback removes the approve / disapprove div or link. -phpbb.addAjaxCallback('post_approve', function(res) { - var remove = (res.approved) ? $(this) : $(this).parents('.post'); +phpbb.addAjaxCallback('post_visibility', function(res) { + var remove = (res.visible) ? $(this) : $(this).parents('.post'); $(remove).css('pointer-events', 'none').fadeOut(function() { $(this).remove(); }); + + if (res.visible) + { + // Remove the "Deleted by" message from the post on restoring. + remove.parents('.post').find('.post_deleted_msg').css('pointer-events', 'none').fadeOut(function() { + $(this).remove(); + }); + } }); // This removes the parent row of the link or form that fired the callback. @@ -178,6 +186,20 @@ $('#qr_full_editor').click(function() { }); +/** + * Make the display post links to use JS + */ +$('.display_post').click(function(e) { + // Do not follow the link + e.preventDefault(); + + var post_id = $(this).attr('data-post-id'); + $('#post_content' + post_id).show(); + $('#profile' + post_id).show(); + $('#post_hidden' + post_id).hide(); +}); + + /** * This AJAXifies the quick-mod tools. The reason it cannot be a standard @@ -208,6 +230,14 @@ $('#quick-mod-select').change(function () { $('#quickmodform').submit(); }); +$('#delete_permanent').click(function () { + if ($(this).attr('checked')) { + $('#delete_reason').hide(); + } else { + $('#delete_reason').show(); + } +}); + /** * Toggle the member search panel in memberlist.php. * diff --git a/phpBB/styles/prosilver/template/confirm_delete_body.html b/phpBB/styles/prosilver/template/confirm_delete_body.html new file mode 100644 index 0000000000..759b6b46b2 --- /dev/null +++ b/phpBB/styles/prosilver/template/confirm_delete_body.html @@ -0,0 +1,72 @@ + +

    {MESSAGE_TEXT}

    + + + + + + + + + + + +
    +   + +
    + + + + + +
    +
    +
    + +

    {MESSAGE_TITLE}

    + +

    {MESSAGE_TEXT}

    + + +
    + +
    +
    +
    + +
    +
    + + + +
    +

    {L_DELETE_REASON_EXPLAIN}
    +
    +
    + +
    + + +
    + {S_HIDDEN_FIELDS} +   + +
    + +
    +
    + + + + diff --git a/phpBB/styles/prosilver/template/forum_fn.js b/phpBB/styles/prosilver/template/forum_fn.js index bb29f00490..eccb12e827 100644 --- a/phpBB/styles/prosilver/template/forum_fn.js +++ b/phpBB/styles/prosilver/template/forum_fn.js @@ -106,32 +106,51 @@ function dE(n, s, type) { /** * Alternate display of subPanels */ -function subPanels(p) { - var i, e, t; +jQuery(document).ready(function() { + jQuery('.sub-panels').each(function() { - if (typeof(p) === 'string') { - show_panel = p; - } + var panels = [], + childNodes = jQuery('a[data-subpanel]', this).each(function() { + panels.push(this.getAttribute('data-subpanel')); + }), + show_panel = this.getAttribute('data-show-panel'); - for (i = 0; i < panels.length; i++) { - e = document.getElementById(panels[i]); - t = document.getElementById(panels[i] + '-tab'); + if (panels.length) { + subPanels(show_panel); + childNodes.click(function () { + subPanels(this.getAttribute('data-subpanel')); + return false; + }); + } - if (e) { - if (panels[i] === show_panel) { - e.style.display = 'block'; - if (t) { - t.className = 'activetab'; - } - } else { - e.style.display = 'none'; - if (t) { - t.className = ''; + function subPanels(p) { + var i, e, t; + + if (typeof(p) === 'string') { + show_panel = p; + } + + for (i = 0; i < panels.length; i++) { + e = document.getElementById(panels[i]); + t = document.getElementById(panels[i] + '-tab'); + + if (e) { + if (panels[i] === show_panel) { + e.style.display = 'block'; + if (t) { + t.className = 'activetab'; + } + } else { + e.style.display = 'none'; + if (t) { + t.className = ''; + } + } } } } - } -} + }); +}); /** * Call print preview @@ -385,3 +404,22 @@ function apply_onkeypress_event() { } jQuery(document).ready(apply_onkeypress_event); + +/** +* Adjust HTML code for IE8 and older versions +*/ +(function($) { + $(document).ready(function() { + var test = document.createElement('div'), + oldBrowser = (typeof test.style.borderRadius == 'undefined'); + delete test; + + if (!oldBrowser) { + return; + } + + // Fix .linkslist.bulletin lists + $('ul.linklist.bulletin li:first-child, ul.linklist.bulletin li.rightside:last-child').addClass('no-bulletin'); + }); +})(jQuery); + diff --git a/phpBB/styles/prosilver/template/forumlist_body.html b/phpBB/styles/prosilver/template/forumlist_body.html index 0c67de76ec..9fb6b3d951 100644 --- a/phpBB/styles/prosilver/template/forumlist_body.html +++ b/phpBB/styles/prosilver/template/forumlist_body.html @@ -50,7 +50,11 @@
    {forumrow.TOPICS} {L_TOPICS}
    {forumrow.POSTS} {L_POSTS}
    - {UNAPPROVED_IMG} + + {UNAPPROVED_IMG} + + {UNAPPROVED_POST_IMG} + {L_LAST_POST} diff --git a/phpBB/styles/prosilver/template/index_body.html b/phpBB/styles/prosilver/template/index_body.html index 57ad540a4a..e0a9279738 100644 --- a/phpBB/styles/prosilver/template/index_body.html +++ b/phpBB/styles/prosilver/template/index_body.html @@ -4,9 +4,16 @@

    {CURRENT_TIME}
    {L_MCP} ]

    {CURRENT_TIME}

    -
    -
    +
    + + + + + +
  6. @@ -67,8 +73,8 @@
    - {L_NEXT} - {L_PREVIOUS} + {L_NEXT} + {L_PREVIOUS} @@ -88,7 +94,13 @@ -

    {L_NO_TOPICS_QUEUE}{L_NO_POSTS_QUEUE}

    +

    + + {L_NO_TOPICS_DELETED}{L_NO_POSTS_DELETED} + + {L_NO_TOPICS_QUEUE}{L_NO_POSTS_QUEUE} + +

    @@ -96,9 +108,20 @@
    + +   + +   - + +
    diff --git a/phpBB/styles/prosilver/template/mcp_reports.html b/phpBB/styles/prosilver/template/mcp_reports.html index 9a70b4a62a..902744fe25 100644 --- a/phpBB/styles/prosilver/template/mcp_reports.html +++ b/phpBB/styles/prosilver/template/mcp_reports.html @@ -72,8 +72,8 @@
    - {L_NEXT} - {L_PREVIOUS} + {L_NEXT} + {L_PREVIOUS} diff --git a/phpBB/styles/prosilver/template/mcp_topic.html b/phpBB/styles/prosilver/template/mcp_topic.html index 8dfee55cbf..0fd5a9455f 100644 --- a/phpBB/styles/prosilver/template/mcp_topic.html +++ b/phpBB/styles/prosilver/template/mcp_topic.html @@ -3,33 +3,24 @@

    {L_TOPIC}{L_COLON} {TOPIC_TITLE}

    - - -
    + @@ -110,9 +101,10 @@ onload_functions.push('subPanels()');

    {postrow.POST_SUBJECT}

    {postrow.MINI_POST_IMG} {L_POSTED} {postrow.POST_DATE} {L_POST_BY_AUTHOR} {postrow.POST_AUTHOR_FULL} [ {L_POST_DETAILS} ]

    - +

    {UNAPPROVED_IMG} {L_POST_UNAPPROVED}
    + {DELETED_IMG} {L_POST_DELETED}
    {REPORTED_IMG} {L_POST_REPORTED}

    @@ -159,6 +151,7 @@ onload_functions.push('subPanels()'); + diff --git a/phpBB/styles/prosilver/template/memberlist_body.html b/phpBB/styles/prosilver/template/memberlist_body.html index 17dc2c33c0..07a7e2e182 100644 --- a/phpBB/styles/prosilver/template/memberlist_body.html +++ b/phpBB/styles/prosilver/template/memberlist_body.html @@ -140,8 +140,8 @@
    - {L_PREVIOUS} - {L_NEXT} + {L_PREVIOUS} + {L_NEXT}
    diff --git a/phpBB/styles/prosilver/template/memberlist_search.html b/phpBB/styles/prosilver/template/memberlist_search.html index 61bfd630ff..4f029627fc 100644 --- a/phpBB/styles/prosilver/template/memberlist_search.html +++ b/phpBB/styles/prosilver/template/memberlist_search.html @@ -38,7 +38,7 @@ function insert_single(user) // ]]> - +

    {L_FIND_USERNAME}

    @@ -74,6 +74,10 @@ function insert_single(user)
    +
    +
    +
    +
    diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index ba0412ddd3..b948d9f627 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -5,16 +5,21 @@ - + diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html index 00b735fae6..c5078df268 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html +++ b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html @@ -122,8 +122,8 @@
    - {L_PREVIOUS} - {L_NEXT} + {L_PREVIOUS} + {L_NEXT} diff --git a/phpBB/styles/prosilver/template/viewforum_body.html b/phpBB/styles/prosilver/template/viewforum_body.html index dd16b27988..69b0608a64 100644 --- a/phpBB/styles/prosilver/template/viewforum_body.html +++ b/phpBB/styles/prosilver/template/viewforum_body.html @@ -146,6 +146,7 @@
    {NEWEST_POST_IMG} {topicrow.TOPIC_TITLE} {topicrow.UNAPPROVED_IMG} + {DELETED_IMG} {REPORTED_IMG}
    - +
    - {L_PREVIOUS}{L_PREVIOUS}{L_NEXT}{L_NEXT} + {L_PREVIOUS}{L_PREVIOUS}{L_NEXT}{L_NEXT}
    diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 5f999ade0c..a8bac42842 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -114,19 +114,30 @@ -
    +
    - -
    {postrow.L_IGNORE_POST}
    - + + +
    + {postrow.L_POST_DELETED_MESSAGE}
    + {postrow.L_POST_DISPLAY} +
    + +
    + {postrow.L_IGNORE_POST}
    + {postrow.L_POST_DISPLAY} +
    + + +
    style="display: none;">
    - -
    +
    style="display: none;">
    {postrow.POSTER_AVATAR}{postrow.POSTER_AVATAR}
    @@ -233,7 +259,6 @@
    - @@ -245,12 +270,12 @@ - +
    - {L_PREVIOUS} - {L_NEXT} + {L_PREVIOUS} + {L_NEXT} diff --git a/phpBB/styles/prosilver/theme/buttons.css b/phpBB/styles/prosilver/theme/buttons.css index 09021c771f..9336dd09f8 100644 --- a/phpBB/styles/prosilver/theme/buttons.css +++ b/phpBB/styles/prosilver/theme/buttons.css @@ -97,17 +97,9 @@ a.sendemail { padding: 1px 0 0 17px; } -.icon-notification:before, .icon-notification:after { - display: inline; - font: inherit; -} - -.icon-notification:before { - content: '['; -} - -.icon-notification:after { - content: ']'; +ul.linklist.bulletin li.icon-home:before, ul.linklist.bulletin li.icon-ucp:before, +ul.linklist.bulletin li.icon-bookmark:before, ul.linklist.bulletin li.icon-bump:before, ul.linklist.bulletin li.icon-subscribe:before, ul.linklist.bulletin li.icon-unsubscribe:before { + display: none; } /* Poster profile icons diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 89b3ab7ada..e58386de45 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -356,6 +356,38 @@ ul.rightside { text-align: right; } +/* Bulletin icons for list items +----------------------------------------*/ +ul.linklist.bulletin li:before { + display: inline-block; + content: "\2022"; + font-size: inherit; + line-height: inherit; + padding-right: 4px; +} + +ul.linklist.bulletin li:first-child:before, ul.linklist.bulletin li.rightside:last-child:before { + display: none; +} + +ul.linklist.bulletin li.no-bulletin:before { + display: none; +} + +.icon-notification:before, ul.linklist.bulletin li.icon-notification:before, .icon-notification:after { + display: inline; + font: inherit; +} + +.icon-notification:before, ul.linklist.bulletin li.icon-notification:before { + content: '['; + padding-right: 0; +} + +.icon-notification:after { + content: ']'; +} + /* Table styles ----------------------------------------*/ table.table1 { diff --git a/phpBB/styles/prosilver/theme/content.css b/phpBB/styles/prosilver/theme/content.css index b6db4c7230..4b8c972697 100644 --- a/phpBB/styles/prosilver/theme/content.css +++ b/phpBB/styles/prosilver/theme/content.css @@ -159,7 +159,7 @@ dl.icon dt .list-inner { } dl.icon dt, dl.icon dd { - min-height: 40px; + min-height: 35px; } dd.posts, dd.topics, dd.views, dd.extra, dd.mark { diff --git a/phpBB/styles/prosilver/theme/images/icon_topic_deleted.png b/phpBB/styles/prosilver/theme/images/icon_topic_deleted.png new file mode 100644 index 0000000000..494b4fb563 Binary files /dev/null and b/phpBB/styles/prosilver/theme/images/icon_topic_deleted.png differ diff --git a/phpBB/styles/prosilver/theme/imageset.css b/phpBB/styles/prosilver/theme/imageset.css index cb99e9e715..296c617f17 100644 --- a/phpBB/styles/prosilver/theme/imageset.css +++ b/phpBB/styles/prosilver/theme/imageset.css @@ -340,6 +340,11 @@ span.imageset { padding-left: 16px; padding-top: 14px; } +.imageset.icon_topic_deleted { + background-image: url("./images/icon_topic_deleted.png"); + padding-left: 16px; + padding-top: 14px; +} .imageset.icon_topic_unapproved { background-image: url("./images/icon_topic_unapproved.gif"); padding-left: 16px; diff --git a/phpBB/styles/subsilver2/template/confirm_delete_body.html b/phpBB/styles/subsilver2/template/confirm_delete_body.html new file mode 100644 index 0000000000..9e416f5195 --- /dev/null +++ b/phpBB/styles/subsilver2/template/confirm_delete_body.html @@ -0,0 +1,56 @@ + + +
    + + + +
{items.EMOTION} - {ICON_MOVE_UP_DISABLED}{ICON_MOVE_UP}  - {ICON_MOVE_DOWN_DISABLED}{ICON_MOVE_DOWN} + {ICON_MOVE_UP_DISABLED}{ICON_MOVE_UP}  + {ICON_MOVE_DOWN_DISABLED}{ICON_MOVE_DOWN}  {ICON_EDIT} {ICON_DELETE}
+ + + + + + +
{MESSAGE_TITLE}
+
+

{MESSAGE_TEXT}

+
+ + + + + + + + + + + + + + + +
{L_DELETE_PERMANENTLY}{L_COLON} + + {L_DELETE_TOPIC_PERMANENTLY}{L_DELETE_POST_PERMANENTLY} +
{L_DELETE_REASON}{L_COLON}
{L_DELETE_REASON_EXPLAIN}
+
+ + {S_HIDDEN_FIELDS} +    + +
+ + + + + +
+ + + +
+ +
+ + diff --git a/phpBB/styles/subsilver2/template/forumlist_body.html b/phpBB/styles/subsilver2/template/forumlist_body.html index 3e30561f3a..a222607ae8 100644 --- a/phpBB/styles/subsilver2/template/forumlist_body.html +++ b/phpBB/styles/subsilver2/template/forumlist_body.html @@ -64,7 +64,14 @@

{forumrow.LAST_POST_SUBJECT_TRUNCATED}

-

{UNAPPROVED_IMG} {forumrow.LAST_POST_TIME}

+

+ + {UNAPPROVED_IMG}  + + {UNAPPROVED_POST_IMG}  + + {forumrow.LAST_POST_TIME} +

{forumrow.LAST_POSTER_FULL} {LAST_POST_IMG}

diff --git a/phpBB/styles/subsilver2/template/mcp_approve.html b/phpBB/styles/subsilver2/template/mcp_approve.html index 5ad7d2f9b5..8c2ef0806b 100644 --- a/phpBB/styles/subsilver2/template/mcp_approve.html +++ b/phpBB/styles/subsilver2/template/mcp_approve.html @@ -16,7 +16,7 @@ {L_NOTIFY_POSTER_APPROVAL}{L_NOTIFY_POSTER_DISAPPROVAL}
- +
diff --git a/phpBB/styles/subsilver2/template/mcp_forum.html b/phpBB/styles/subsilver2/template/mcp_forum.html index 6972f14b79..b168bf3ac8 100644 --- a/phpBB/styles/subsilver2/template/mcp_forum.html +++ b/phpBB/styles/subsilver2/template/mcp_forum.html @@ -33,6 +33,9 @@ {topicrow.UNAPPROVED_IMG}  + + {topicrow.DELETED_IMG}  + {REPORTED_IMG}  @@ -58,6 +61,7 @@ - + diff --git a/phpBB/styles/subsilver2/template/mcp_queue.html b/phpBB/styles/subsilver2/template/mcp_queue.html index febde7e59c..7ca659b5da 100644 --- a/phpBB/styles/subsilver2/template/mcp_queue.html +++ b/phpBB/styles/subsilver2/template/mcp_queue.html @@ -23,15 +23,37 @@ - + - + - +
{L_PM_SUBJECT}{L_POST_SUBJECT}{L_COLON} {POST_SUBJECT} {UNAPPROVED_IMG} {L_POST_UNAPPROVED} {REPORTED_IMG} {L_POST_REPORTED} + {POST_SUBJECT} + {UNAPPROVED_IMG} {L_POST_UNAPPROVED} + {DELETED_IMG} {L_POST_DELETED} + {REPORTED_IMG} {L_POST_REPORTED} +
{L_PM_FROM}{L_POSTER}{L_COLON} {postrow.POST_AUTHOR_FULL}
[ {L_VIEW_DETAILS} ]
{postrow.POST_TIME} + + + + + +
{L_NO_TOPICS_QUEUE}{L_NO_POSTS_QUEUE} + + + {L_NO_TOPICS_DELETED}{L_NO_POSTS_DELETED} + + {L_NO_TOPICS_QUEUE}{L_NO_POSTS_QUEUE} + + +
   + +    + + +    + + +
{S_FORM_TOKEN} @@ -39,7 +61,15 @@ - +
{L_MARK_ALL} :: {L_UNMARK_ALL} + + + {L_MARK_ALL} :: {L_UNMARK_ALL} + + {L_MARK_ALL} :: {L_UNMARK_ALL} + + +
diff --git a/phpBB/styles/subsilver2/template/mcp_topic.html b/phpBB/styles/subsilver2/template/mcp_topic.html index 014d8b9468..d3b4408243 100644 --- a/phpBB/styles/subsilver2/template/mcp_topic.html +++ b/phpBB/styles/subsilver2/template/mcp_topic.html @@ -112,6 +112,7 @@ {UNAPPROVED_IMG} {L_POST_UNAPPROVED}
+ {DELETED_IMG} {L_POST_DELETED}
{REPORTED_IMG} {L_POST_REPORTED} {postrow.MINI_POST_IMG} @@ -133,6 +134,7 @@ + diff --git a/phpBB/styles/subsilver2/template/overall_footer.html b/phpBB/styles/subsilver2/template/overall_footer.html index 3a29a0d752..d2b30c22a0 100644 --- a/phpBB/styles/subsilver2/template/overall_footer.html +++ b/phpBB/styles/subsilver2/template/overall_footer.html @@ -13,9 +13,11 @@ - -{SCRIPTS} + + +{$SCRIPTS} + diff --git a/phpBB/styles/subsilver2/template/overall_header.html b/phpBB/styles/subsilver2/template/overall_header.html index 0317d6e45c..bc2307154b 100644 --- a/phpBB/styles/subsilver2/template/overall_header.html +++ b/phpBB/styles/subsilver2/template/overall_header.html @@ -132,6 +132,8 @@ function marklist(id, name, state) +{$STYLESHEETS} + diff --git a/phpBB/styles/subsilver2/template/posting_body.html b/phpBB/styles/subsilver2/template/posting_body.html index 4feb4e955a..635b05aaa0 100644 --- a/phpBB/styles/subsilver2/template/posting_body.html +++ b/phpBB/styles/subsilver2/template/posting_body.html @@ -114,13 +114,6 @@ - - - {L_DELETE_POST}{L_COLON} - [ {L_DELETE_POST_WARN} ] - - - {L_ICON}{L_COLON} @@ -310,7 +303,7 @@ -   + {L_CHANGE_TOPIC_TO}{L_POST_TOPIC_AS}{L_COLON} {topic_type.L_TOPIC_TYPE}   @@ -319,6 +312,26 @@ + + + {L_DELETE_POST}{L_COLON} + + + + + + + + + + + + +
{L_DELETE_POST_WARN}
{L_DELETE_POST_PERMANENTLY}
+ + + + {L_STICK_TOPIC_FOR}{L_COLON}
{L_STICKY_ANNOUNCE_TIME_LIMIT} diff --git a/phpBB/styles/subsilver2/template/report_body.html b/phpBB/styles/subsilver2/template/report_body.html index 9ed510bb9f..906a957ef4 100644 --- a/phpBB/styles/subsilver2/template/report_body.html +++ b/phpBB/styles/subsilver2/template/report_body.html @@ -6,6 +6,11 @@ {L_REPORT_POST}{L_REPORT_MESSAGE} + + + {ERROR} + + {L_REPORT_POST_EXPLAIN}{L_REPORT_MESSAGE_EXPLAIN} @@ -25,6 +30,9 @@ {L_MORE_INFO}{L_COLON}
{L_CAN_LEAVE_BLANK} + + +   diff --git a/phpBB/styles/subsilver2/template/search_results.html b/phpBB/styles/subsilver2/template/search_results.html index 8ced5a5301..d98079de20 100644 --- a/phpBB/styles/subsilver2/template/search_results.html +++ b/phpBB/styles/subsilver2/template/search_results.html @@ -39,6 +39,9 @@ {searchresults.UNAPPROVED_IMG}  + + {DELETED_IMG}  + {REPORTED_IMG}  diff --git a/phpBB/styles/subsilver2/template/timezone_option.html b/phpBB/styles/subsilver2/template/timezone_option.html index 26ba2388c9..0f27719f86 100644 --- a/phpBB/styles/subsilver2/template/timezone_option.html +++ b/phpBB/styles/subsilver2/template/timezone_option.html @@ -15,6 +15,6 @@ {S_TZ_OPTIONS} - + diff --git a/phpBB/styles/subsilver2/template/ucp_groups_manage.html b/phpBB/styles/subsilver2/template/ucp_groups_manage.html index 8064e1e6e9..b8e7e29481 100644 --- a/phpBB/styles/subsilver2/template/ucp_groups_manage.html +++ b/phpBB/styles/subsilver2/template/ucp_groups_manage.html @@ -95,7 +95,7 @@ - + diff --git a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html index 697cceabb9..60a816d00a 100644 --- a/phpBB/styles/subsilver2/template/ucp_profile_avatar.html +++ b/phpBB/styles/subsilver2/template/ucp_profile_avatar.html @@ -48,6 +48,6 @@ - + diff --git a/phpBB/styles/subsilver2/template/viewforum_body.html b/phpBB/styles/subsilver2/template/viewforum_body.html index 664a6a26c5..d07e9a1372 100644 --- a/phpBB/styles/subsilver2/template/viewforum_body.html +++ b/phpBB/styles/subsilver2/template/viewforum_body.html @@ -43,7 +43,10 @@ {NEWEST_POST_IMG} {topicrow.ATTACH_ICON_IMG} {topicrow.TOPIC_TYPE} {topicrow.TOPIC_TITLE} - {UNAPPROVED_IMG}  + {topicrow.UNAPPROVED_IMG}  + + + {DELETED_IMG}  {REPORTED_IMG}  @@ -205,6 +208,9 @@ {topicrow.UNAPPROVED_IMG}  + + {DELETED_IMG}  + {REPORTED_IMG}  diff --git a/phpBB/styles/subsilver2/template/viewtopic_body.html b/phpBB/styles/subsilver2/template/viewtopic_body.html index b561b99abd..299b8219eb 100644 --- a/phpBB/styles/subsilver2/template/viewtopic_body.html +++ b/phpBB/styles/subsilver2/template/viewtopic_body.html @@ -136,8 +136,19 @@ - - {postrow.L_IGNORE_POST} + + + + + + + {postrow.L_POST_DELETED_MESSAGE} + + {postrow.L_IGNORE_POST} + +
{postrow.L_POST_DISPLAY} + + @@ -207,10 +218,14 @@
- + - +
{UNAPPROVED_IMG} {L_POST_UNAPPROVED}
{REPORTED_IMG} {L_POST_REPORTED}
+ {UNAPPROVED_IMG} {L_POST_UNAPPROVED}
+ {DELETED_IMG} {L_POST_DELETED}
+ {REPORTED_IMG} {L_POST_REPORTED} +
@@ -241,7 +256,22 @@

_________________
{postrow.SIGNATURE}
- + + +

+ + + + + + + +
{postrow.DELETED_MESSAGE}
{postrow.DELETE_REASON}
+ +

+ {postrow.DELETED_MESSAGE} + +

diff --git a/phpBB/styles/subsilver2/theme/images/icon_topic_deleted.png b/phpBB/styles/subsilver2/theme/images/icon_topic_deleted.png new file mode 100644 index 0000000000..494b4fb563 Binary files /dev/null and b/phpBB/styles/subsilver2/theme/images/icon_topic_deleted.png differ diff --git a/phpBB/styles/subsilver2/theme/stylesheet.css b/phpBB/styles/subsilver2/theme/stylesheet.css index df46c91d8d..bfb80a53b5 100644 --- a/phpBB/styles/subsilver2/theme/stylesheet.css +++ b/phpBB/styles/subsilver2/theme/stylesheet.css @@ -985,6 +985,11 @@ a.imageset { padding-left: 19px; padding-top: 18px; } +.imageset.icon_topic_deleted { + background-image: url("./images/icon_topic_deleted.png"); + padding-left: 14px; + padding-top: 14px; +} /* English images for fallback */ diff --git a/phpBB/ucp.php b/phpBB/ucp.php index a7e75f76c4..7180c54de6 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -85,17 +85,16 @@ switch ($mode) { $user->session_kill(); $user->session_begin(); - $message = $user->lang['LOGOUT_REDIRECT']; } - else + else if ($user->data['user_id'] != ANONYMOUS) { - $message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED']; + meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")); + + $message = $user->lang['LOGOUT_FAILED'] . '

' . sprintf($user->lang['RETURN_INDEX'], '', ' '); + trigger_error($message); } - meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")); - - $message = $message . '

' . sprintf($user->lang['RETURN_INDEX'], '', ' '); - trigger_error($message); + redirect(append_sid("{$phpbb_root_path}index.$phpEx")); break; case 'terms': diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 5fed514a12..5a59e021b3 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -105,7 +105,7 @@ if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link']) if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) { $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_posts = forum_posts + 1 + SET forum_posts_approved = forum_posts_approved + 1 WHERE forum_id = ' . $forum_id; $db->sql_query($sql); } @@ -241,14 +241,14 @@ gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']); $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); -$sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views'); +$sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_posts_approved + t.topic_posts_unapproved + t.topic_posts_softdeleted' : 't.topic_posts_approved'), 's' => 't.topic_title', 'v' => 't.topic_views'); $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir); +$phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // Limit topics to certain time frame, obtain correct topic count -// global announcements must not be counted, normal announcements have to -// be counted, as forum_topics(_real) includes them if ($sort_days) { $min_post_time = time() - ($sort_days * 86400); @@ -259,7 +259,7 @@ if ($sort_days) AND (topic_last_post_time >= $min_post_time OR topic_type = " . POST_ANNOUNCE . ' OR topic_type = ' . POST_GLOBAL . ') - ' . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1'); + AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id); $result = $db->sql_query($sql); $topics_count = (int) $db->sql_fetchfield('num_topics'); $db->sql_freeresult($result); @@ -275,7 +275,7 @@ if ($sort_days) } else { - $topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics']; + $topics_count = $phpbb_content_visibility->get_count('forum_topics', $forum_data, $forum_id); $sql_limit_time = ''; } @@ -325,6 +325,7 @@ $template->assign_vars(array( 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), + 'DELETED_IMG' => $user->img('icon_topic_deleted', 'TOPIC_DELETED'), 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'), 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'], @@ -371,7 +372,7 @@ $sql_array = array( 'LEFT_JOIN' => array(), ); -$sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; +$sql_approved = ' AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'); if ($user->data['is_registered']) { @@ -422,9 +423,9 @@ if ($forum_data['forum_type'] == FORUM_POST) while ($row = $db->sql_fetchrow($result)) { - if (!$row['topic_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) + if ($row['topic_visibility'] != ITEM_APPROVED && !$auth->acl_get('m_approve', $row['forum_id'])) { - // Do not display announcements that are waiting for approval. + // Do not display announcements that are waiting for approval or soft deleted. continue; } @@ -683,7 +684,7 @@ if (sizeof($topic_list)) $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0; // Replies - $replies = ($auth->acl_get('m_approve', $topic_forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; + $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $topic_forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED) { @@ -703,9 +704,12 @@ if (sizeof($topic_list)) $view_topic_url_params = 'f=' . $row['forum_id'] . '&t=' . $topic_id; $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params); - $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; - $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false; + $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED && $auth->acl_get('m_approve', $row['forum_id'])); + $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row['forum_id'])); + $topic_deleted = $row['topic_visibility'] == ITEM_DELETED; + $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id) : ''; + $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=deleted_topics&t=' . $topic_id, true, $user->session_id) : $u_mcp_queue; // Send vars to template $topic_row = array( @@ -744,6 +748,7 @@ if (sizeof($topic_list)) 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, + 'S_TOPIC_DELETED' => $topic_deleted, 'S_HAS_POLL' => ($row['poll_start']) ? true : false, 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false, 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false, diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 59ef7bbc80..1e444f47ad 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -55,6 +55,8 @@ if (!$topic_id && !$post_id) trigger_error('NO_TOPIC'); } +$phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // Find topic id if user requested a newer or older topic if ($view && !$post_id) { @@ -77,13 +79,12 @@ if ($view && !$post_id) { // Get topic tracking info $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id); - $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0; $sql = 'SELECT post_id, topic_id, forum_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1') . " + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id) . " AND post_time > $topic_last_read AND forum_id = $forum_id ORDER BY post_time ASC"; @@ -137,7 +138,7 @@ if ($view && !$post_id) WHERE forum_id = ' . $row['forum_id'] . " AND topic_moved_id = 0 AND topic_last_post_time $sql_condition {$row['topic_last_post_time']} - " . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . " + AND " . $phpbb_content_visibility->get_visibility_sql('topic', $row['forum_id']) . " ORDER BY topic_last_post_time $sql_ordering"; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); @@ -145,7 +146,14 @@ if ($view && !$post_id) if (!$row) { - $user->setup('viewtopic'); + $sql = 'SELECT forum_style + FROM ' . FORUMS_TABLE . " + WHERE forum_id = $forum_id"; + $result = $db->sql_query($sql); + $forum_style = (int) $db->sql_fetchfield('forum_style'); + $db->sql_freeresult($result); + + $user->setup('viewtopic', $forum_style); trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS'); } else @@ -174,7 +182,7 @@ $sql_array = array( // The FROM-Order is quite important here, else t.* columns can not be correctly bound. if ($post_id) { - $sql_array['SELECT'] .= ', p.post_approved, p.post_time, p.post_id'; + $sql_array['SELECT'] .= ', p.post_visibility, p.post_time, p.post_id'; $sql_array['FROM'][POSTS_TABLE] = 'p'; } @@ -245,11 +253,18 @@ if (!$topic_data) } $forum_id = (int) $topic_data['forum_id']; + +// Now we know the forum_id and can check the permissions +if ($topic_data['topic_visibility'] != ITEM_APPROVED && !$auth->acl_get('m_approve', $forum_id)) +{ + trigger_error('NO_TOPIC'); +} + // This is for determining where we are (page) if ($post_id) { // are we where we are supposed to be? - if (!$topic_data['post_approved'] && !$auth->acl_get('m_approve', $topic_data['forum_id'])) + if ($topic_data['post_visibility'] == ITEM_UNAPPROVED && !$auth->acl_get('m_approve', $topic_data['forum_id'])) { // If post_id was submitted, we try at least to display the topic as a last resort... if ($topic_id) @@ -265,7 +280,7 @@ if ($post_id) if ($sort_dir == $check_sort) { - $topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies']; + $topic_data['prev_posts'] = $phpbb_content_visibility->get_count('topic_posts', $topic_data, $forum_id) - 1; } else { @@ -277,7 +292,7 @@ if ($post_id) $sql = 'SELECT COUNT(p.post_id) AS prev_posts FROM ' . POSTS_TABLE . " p WHERE p.topic_id = {$topic_data['topic_id']} - " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : ''); + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id, 'p.'); if ($sort_dir == 'd') { @@ -297,8 +312,7 @@ if ($post_id) } $topic_id = (int) $topic_data['topic_id']; -// -$topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies']; +$topic_replies = $phpbb_content_visibility->get_count('topic_posts', $topic_data, $forum_id) - 1; // Check sticky/announcement time limit if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == POST_ANNOUNCE) && $topic_data['topic_time_limit'] && ($topic_data['topic_time'] + $topic_data['topic_time_limit']) < time()) @@ -315,11 +329,6 @@ if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == PO // Setup look and feel $user->setup('viewtopic', $topic_data['forum_style']); -if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id)) -{ - trigger_error('NO_TOPIC'); -} - // Start auth check if (!$auth->acl_get('f_read', $forum_id)) { @@ -402,7 +411,7 @@ if ($sort_days) FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id AND post_time >= $min_post_time - " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1'); + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $total_posts = (int) $db->sql_fetchfield('num_posts'); $db->sql_freeresult($result); @@ -524,7 +533,8 @@ $quickmod_array = array( 'lock' => array('LOCK_TOPIC', ($topic_data['topic_status'] == ITEM_UNLOCKED) && ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'] && $topic_data['topic_status'] == ITEM_UNLOCKED))), 'unlock' => array('UNLOCK_TOPIC', ($topic_data['topic_status'] != ITEM_UNLOCKED) && ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'] && $topic_data['topic_status'] == ITEM_UNLOCKED))), - 'delete_topic' => array('DELETE_TOPIC', $auth->acl_get('m_delete', $forum_id)), + 'delete_topic' => array('DELETE_TOPIC', ($auth->acl_get('m_delete', $forum_id) || (($topic_data['topic_visibility'] != ITEM_DELETED) && $auth->acl_get('m_softdelete', $forum_id)))), + 'restore_topic' => array('RESTORE_TOPIC', (($topic_data['topic_visibility'] == ITEM_DELETED) && $auth->acl_get('m_approve', $forum_id))), 'move' => array('MOVE_TOPIC', $auth->acl_get('m_move', $forum_id) && $topic_data['topic_status'] != ITEM_MOVED), 'split' => array('SPLIT_TOPIC', $auth->acl_get('m_split', $forum_id)), 'merge' => array('MERGE_POSTS', $auth->acl_get('m_merge', $forum_id)), @@ -609,6 +619,7 @@ $template->assign_vars(array( 'REPLY_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED || $topic_data['topic_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'TOPIC_LOCKED') : $user->img('button_topic_reply', 'REPLY_TO_TOPIC'), 'EDIT_IMG' => $user->img('icon_post_edit', 'EDIT_POST'), 'DELETE_IMG' => $user->img('icon_post_delete', 'DELETE_POST'), + 'DELETED_IMG' => $user->img('icon_topic_deleted', 'POST_DELETED_RESTORE'), 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'), 'PROFILE_IMG' => $user->img('icon_user_profile', 'READ_PROFILE'), 'SEARCH_IMG' => $user->img('icon_user_search', 'SEARCH_USER_POSTS'), @@ -929,7 +940,7 @@ else } // Container for user details, only process once -$post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array(); +$post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = $post_delete_list = array(); $has_attachments = $display_notice = false; $bbcode_bitfield = ''; $i = $i_total = 0; @@ -938,7 +949,7 @@ $i = $i_total = 0; $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . " WHERE p.topic_id = $topic_id - " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . " + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id, 'p.') . " " . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . " $limit_posts_time ORDER BY $sql_sort_order"; @@ -1020,14 +1031,14 @@ while ($row = $db->sql_fetchrow($result)) { $attach_list[] = (int) $row['post_id']; - if ($row['post_approved']) + if ($row['post_visibility'] == ITEM_UNAPPROVED) { $has_attachments = true; } } $rowset[$row['post_id']] = array( - 'hide_post' => ($row['foe'] && ($view != 'show' || $post_id != $row['post_id'])) ? true : false, + 'hide_post' => (($row['foe'] || $row['post_visibility'] == ITEM_DELETED) && ($view != 'show' || $post_id != $row['post_id'])) ? true : false, 'post_id' => $row['post_id'], 'post_time' => $row['post_time'], @@ -1042,11 +1053,14 @@ while ($row = $db->sql_fetchrow($result)) 'post_edit_reason' => $row['post_edit_reason'], 'post_edit_user' => $row['post_edit_user'], 'post_edit_locked' => $row['post_edit_locked'], + 'post_delete_time' => $row['post_delete_time'], + 'post_delete_reason'=> $row['post_delete_reason'], + 'post_delete_user' => $row['post_delete_user'], // Make sure the icon actually exists 'icon_id' => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ? $row['icon_id'] : 0, 'post_attachment' => $row['post_attachment'], - 'post_approved' => $row['post_approved'], + 'post_visibility' => $row['post_visibility'], 'post_reported' => $row['post_reported'], 'post_username' => $row['post_username'], 'post_text' => $row['post_text'], @@ -1313,8 +1327,8 @@ if (sizeof($attach_list)) $sql = 'SELECT a.post_msg_id as post_id FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p WHERE p.topic_id = $topic_id - AND p.post_approved = 1 - AND p.topic_id = a.topic_id"; + AND p.post_visibility = " . ITEM_APPROVED . ' + AND p.topic_id = a.topic_id'; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1495,6 +1509,62 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) $l_edited_by = ''; } + // Deleting information + if ($row['post_visibility'] == ITEM_DELETED && $row['post_delete_user']) + { + // Get usernames for all following posts if not already stored + if (!sizeof($post_delete_list) && ($row['post_delete_reason'] || ($row['post_delete_user'] && !isset($user_cache[$row['post_delete_user']])))) + { + // Remove all post_ids already parsed (we do not have to check them) + $post_storage_list = (!$store_reverse) ? array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i); + + $sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u + WHERE ' . $db->sql_in_set('p.post_id', $post_storage_list) . ' + AND p.post_delete_user <> 0 + AND p.post_delete_user = u.user_id'; + $result2 = $db->sql_query($sql); + while ($user_delete_row = $db->sql_fetchrow($result2)) + { + $post_delete_list[$user_delete_row['user_id']] = $user_delete_row; + } + $db->sql_freeresult($result2); + + unset($post_storage_list); + } + + if ($row['post_delete_user'] && !isset($user_cache[$row['post_delete_user']])) + { + $user_cache[$row['post_delete_user']] = $post_delete_list[$row['post_delete_user']]; + } + + $display_postername = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']); + + // User having deleted the post also being the post author? + if (!$row['post_delete_user'] || $row['post_delete_user'] == $poster_id) + { + $display_username = $display_postername; + } + else + { + $display_username = get_username_string('full', $row['post_delete_user'], $user_cache[$row['post_delete_user']]['username'], $user_cache[$row['post_delete_user']]['user_colour']); + } + + if ($row['post_delete_reason']) + { + $l_deleted_message = $user->lang('POST_DELETED_BY_REASON', $display_postername, $display_username, $user->format_date($row['post_delete_time'], false, true), $row['post_delete_reason']); + } + else + { + $l_deleted_message = $user->lang('POST_DELETED_BY', $display_postername, $display_username, $user->format_date($row['post_delete_time'], false, true)); + } + $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($row['post_delete_time'], false, true)); + } + else + { + $l_deleted_by = $l_deleted_message = ''; + } + // Bump information if ($topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id'] && isset($user_cache[$topic_data['topic_bumper']]) ) { @@ -1531,9 +1601,9 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) ($row['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']) ))); - $delete_allowed = ($user->data['is_registered'] && ($auth->acl_get('m_delete', $forum_id) || ( + $delete_allowed = ($user->data['is_registered'] && (($auth->acl_get('m_delete', $forum_id) || ($auth->acl_get('m_softdelete', $forum_id) && $row['post_visibility'] != ITEM_DELETED)) || ( $user->data['user_id'] == $poster_id && - $auth->acl_get('f_delete', $forum_id) && + ($auth->acl_get('f_delete', $forum_id) || ($auth->acl_get('f_softdelete', $forum_id) && $row['post_visibility'] != ITEM_DELETED)) && $topic_data['topic_last_post_id'] == $row['post_id'] && ($row['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']) && // we do not want to allow removal of the last post if a moderator locked it! @@ -1563,6 +1633,8 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '', 'EDITED_MESSAGE' => $l_edited_by, 'EDIT_REASON' => $row['post_edit_reason'], + 'DELETED_MESSAGE' => $l_deleted_by, + 'DELETE_REASON' => $row['post_delete_reason'], 'BUMPED_MESSAGE' => $l_bumped_by, 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), @@ -1589,10 +1661,11 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'U_YIM' => $user_cache[$poster_id]['yim'], 'U_JABBER' => $user_cache[$poster_id]['jabber'], - 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p={$row['post_id']}&f=$forum_id"), + 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p={$row['post_id']}&f=$forum_id&redirect=" . urlencode(str_replace('&', '&', $viewtopic_url . '&p=' . $row['post_id'] . '#p' . $row['post_id']))), 'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $row['post_id']) : '', 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '', 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '', + 'U_MCP_RESTORE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_data['topic_visibility'] != ITEM_DELETED) ? 'deleted_posts' : 'deleted_topics') . '&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '', 'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'], 'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$post_list[$i + 1]])) ? $rowset[$post_list[$i + 1]]['post_id'] : '', 'U_PREV_POST_ID' => $prev_post_id, @@ -1605,7 +1678,9 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, 'S_MULTIPLE_ATTACHMENTS' => !empty($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']]) > 1, - 'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true, + 'S_POST_UNAPPROVED' => ($row['post_visibility'] == ITEM_UNAPPROVED) ? true : false, + 'S_POST_DELETED' => ($row['post_visibility'] == ITEM_DELETED) ? true : false, + 'L_POST_DELETED_MESSAGE' => $l_deleted_message, 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false, 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'], 'S_FRIEND' => ($row['friend']) ? true : false, @@ -1614,8 +1689,10 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false, 'S_TOPIC_POSTER' => ($topic_data['topic_poster'] == $poster_id) ? true : false, - 'S_IGNORE_POST' => ($row['hide_post']) ? true : false, - 'L_IGNORE_POST' => ($row['hide_post']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), '', '') : '', + 'S_IGNORE_POST' => ($row['foe']) ? true : false, + 'L_IGNORE_POST' => ($row['foe']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username'])) : '', + 'S_POST_HIDDEN' => $row['hide_post'], + 'L_POST_DISPLAY' => ($row['hide_post']) ? $user->lang('POST_DISPLAY', '', '') : '', ); $user_poster_data = $user_cache[$poster_id]; diff --git a/phpunit.xml.all b/phpunit.xml.all index 3639843771..d18518d3e3 100644 --- a/phpunit.xml.all +++ b/phpunit.xml.all @@ -14,6 +14,10 @@ ./tests/ + tests/lint_test.php + + + tests/lint_test.php @@ -23,9 +27,10 @@ ./phpBB/includes/ + ./phpBB/phpbb/ - ./phpBB/includes/search/fulltext_native.php - ./phpBB/includes/search/fulltext_mysql.php + ./phpBB/phpbb/search/fulltext_native.php + ./phpBB/phpbb/search/fulltext_mysql.php ./phpBB/includes/captcha/ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f1cb4b9d09..c852f91b50 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,6 +14,10 @@ ./tests/ + tests/lint_test.php + + + tests/lint_test.php @@ -30,9 +34,10 @@ ./phpBB/includes/ + ./phpBB/phpbb/ - ./phpBB/includes/search/fulltext_native.php - ./phpBB/includes/search/fulltext_mysql.php + ./phpBB/phpbb/search/fulltext_native.php + ./phpBB/phpbb/search/fulltext_mysql.php ./phpBB/includes/captcha/ diff --git a/phpunit.xml.functional b/phpunit.xml.functional index 99f11477aa..cd9cc8771f 100644 --- a/phpunit.xml.functional +++ b/phpunit.xml.functional @@ -14,6 +14,10 @@ ./tests/ + tests/lint_test.php + + + tests/lint_test.php @@ -29,9 +33,10 @@ ./phpBB/includes/ + ./phpBB/phpbb/ - ./phpBB/includes/search/fulltext_native.php - ./phpBB/includes/search/fulltext_mysql.php + ./phpBB/phpbb/search/fulltext_native.php + ./phpBB/phpbb/search/fulltext_mysql.php ./phpBB/includes/captcha/ diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index f89c1fefeb..f2688ab675 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -50,9 +50,11 @@ Database Tests By default all tests requiring a database connection will use sqlite. If you do not have sqlite installed the tests will be skipped. If you wish to run the tests on a different database you have to create a test_config.php file within -your tests directory following the same format as phpBB's config.php. An -example for mysqli can be found below. More information on configuration -options can be found on the wiki (see below). +your tests directory following the same format as phpBB's config.php. Testing +makes use of a seperate database defined in this config file and before running +the tests each time this database is deleted. An example for mysqli can be +found below. More information on configuration options can be found on the +wiki (see below). Acp_board_valid'), + array('acp_board_invalid', ''), + ); + } + + public function setUp() + { + parent::setUp(); + + global $phpbb_container; + $phpbb_container = new phpbb_mock_container_builder(); + + $phpbb_container->set('auth.provider_collection', array( + 'auth.provider.acp_board_valid' => new phpbb_auth_provider_acp_board_valid, + 'auth.provider.acp_board_invalid' => new phpbb_auth_provider_acp_board_invalid, + )); + + $this->acp_board = new acp_board(); + } + + /** + * @dataProvider select_auth_method_data + */ + public function test_select_auth_method($selected, $expected) + { + $this->assertEquals($expected, $this->acp_board->select_auth_method($selected)); + } +} diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml new file mode 100644 index 0000000000..34584babbf --- /dev/null +++ b/tests/auth/fixtures/user.xml @@ -0,0 +1,33 @@ + + +
+ user_id + username + username_clean + user_password + user_passchg + user_pass_convert + user_email + user_type + user_login_attempts + user_permissions + user_sig + user_occ + user_interests + + 1 + foobar + foobar + $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ + 0 + 0 + example@example.com + 0 + 0 + + + + + +
+ diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php new file mode 100644 index 0000000000..0ca6ef763e --- /dev/null +++ b/tests/auth/provider_apache_test.php @@ -0,0 +1,206 @@ +new_dbal(); + $config = new phpbb_config(array()); + $this->request = $this->getMock('phpbb_request'); + $this->user = $this->getMock('phpbb_user'); + + $this->provider = new phpbb_auth_provider_apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } + + /** + * Test to see if a user is identified to Apache. Expects false if they are. + */ + public function test_init() + { + $this->user->data['username'] = 'foobar'; + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->once()) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + + $this->assertFalse($this->provider->init()); + } + + public function test_login() + { + $username = 'foobar'; + $password = 'example'; + + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->at(1)) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + $this->request->expects($this->at(2)) + ->method('server') + ->with('PHP_AUTH_PW') + ->will($this->returnValue('example')); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + ), + ); + + $this->assertEquals($expected, $this->provider->login($username, $password)); + } + + public function test_autologin() + { + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->at(1)) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + $this->request->expects($this->at(2)) + ->method('server') + ->with('PHP_AUTH_PW') + ->will($this->returnValue('example')); + + $expected = array( + 'user_id' => '1', + 'user_type' => '0', + 'group_id' => '3', + 'user_permissions' => '', + 'user_perm_from' => '0', + 'user_ip' => '', + 'user_regdate' => '0', + 'username' => 'foobar', + 'username_clean' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_email_hash' => '0', + 'user_birthday' => '', + 'user_lastvisit' => '0', + 'user_lastmark' => '0', + 'user_lastpost_time' => '0', + 'user_lastpage' => '', + 'user_last_confirm_key' => '', + 'user_last_search' => '0', + 'user_warnings' => '0', + 'user_last_warning' => '0', + 'user_login_attempts' => '0', + 'user_inactive_reason' => '0', + 'user_inactive_time' => '0', + 'user_posts' => '0', + 'user_lang' => '', + 'user_timezone' => 'UTC', + 'user_dateformat' => 'd M Y H:i', + 'user_style' => '0', + 'user_rank' => '0', + 'user_colour' => '', + 'user_new_privmsg' => '0', + 'user_unread_privmsg' => '0', + 'user_last_privmsg' => '0', + 'user_message_rules' => '0', + 'user_full_folder' => '-3', + 'user_emailtime' => '0', + 'user_topic_show_days' => '0', + 'user_topic_sortby_type' => 't', + 'user_topic_sortby_dir' => 'd', + 'user_post_show_days' => '0', + 'user_post_sortby_type' => 't', + 'user_post_sortby_dir' => 'a', + 'user_notify' => '0', + 'user_notify_pm' => '1', + 'user_notify_type' => '0', + 'user_allow_pm' => '1', + 'user_allow_viewonline' => '1', + 'user_allow_viewemail' => '1', + 'user_allow_massemail' => '1', + 'user_options' => '230271', + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => '0', + 'user_avatar_height' => '0', + 'user_sig' => '', + 'user_sig_bbcode_uid' => '', + 'user_sig_bbcode_bitfield' => '', + 'user_from' => '', + 'user_icq' => '', + 'user_aim' => '', + 'user_yim' => '', + 'user_msnm' => '', + 'user_jabber' => '', + 'user_website' => '', + 'user_occ' => '', + 'user_interests' => '', + 'user_actkey' => '', + 'user_newpasswd' => '', + 'user_form_salt' => '', + 'user_new' => '1', + 'user_reminded' => '0', + 'user_reminded_time' => '0', + ); + + $this->assertEquals($expected, $this->provider->autologin()); + } + + public function test_validate_session() + { + $user = array( + 'username' => 'foobar', + 'user_type' + ); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->once()) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + + $this->assertTrue($this->provider->validate_session($user)); + } +} diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php new file mode 100644 index 0000000000..d876683f84 --- /dev/null +++ b/tests/auth/provider_db_test.php @@ -0,0 +1,50 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } + + public function test_login() + { + global $phpbb_root_path, $phpEx; + + $db = $this->new_dbal(); + $config = new phpbb_config(array( + 'ip_login_limit_max' => 0, + 'ip_login_limit_use_forwarded' => 0, + 'max_login_attempts' => 0, + )); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + $provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + 'user_login_attempts' => '0', + ), + ); + + $this->assertEquals($expected, $provider->login('foobar', 'example')); + } +} diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index cb895b521a..4ebe79c9cd 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -19,24 +19,35 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $this->phpbb_container->expects($this->any()) ->method('get') - ->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar')); + ->will($this->returnArgument(0)); // Prepare dependencies for avatar manager and driver $config = new phpbb_config(array()); $request = $this->getMock('phpbb_request'); $cache = $this->getMock('phpbb_cache_driver_interface'); + // $this->avatar_foobar will be needed later on $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); $this->avatar_foobar->expects($this->any()) - ->method('get_name') - ->will($this->returnValue('avatar.driver.foobar')); + ->method('get_name') + ->will($this->returnValue('avatar.driver.foobar')); + // barfoo driver can't be mocked with constructor arguments $this->avatar_barfoo = $this->getMock('phpbb_avatar_driver_barfoo', array('get_name')); $this->avatar_barfoo->expects($this->any()) - ->method('get_name') - ->will($this->returnValue('avatar.driver.barfoo')); - + ->method('get_name') + ->will($this->returnValue('avatar.driver.barfoo')); $avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo); + foreach ($this->avatar_drivers() as $driver) + { + $cur_avatar = $this->getMock('phpbb_avatar_driver_' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); + $cur_avatar->expects($this->any()) + ->method('get_name') + ->will($this->returnValue('avatar.driver.' . $driver)); + $config['allow_avatar_' . get_class($cur_avatar)] = false; + $avatar_drivers[] = $cur_avatar; + } + $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; @@ -44,28 +55,27 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); } - public function test_get_driver() + protected function avatar_drivers() { - $driver = $this->manager->get_driver('avatar.driver.foobar', false); - $this->assertEquals('avatar.driver.foobar', $driver); - - $driver = $this->manager->get_driver('avatar.driver.foo_wrong', false); - $this->assertNull($driver); - - $driver = $this->manager->get_driver('avatar.driver.foobar'); - $this->assertEquals('avatar.driver.foobar', $driver); - - $driver = $this->manager->get_driver('avatar.driver.foo_wrong'); - $this->assertNull($driver); + return array( + 'local', + 'upload', + 'remote', + 'gravatar', + ); } public function test_get_all_drivers() { $drivers = $this->manager->get_all_drivers(); - $this->assertArrayHasKey('avatar.driver.foobar', $drivers); - $this->assertArrayHasKey('avatar.driver.barfoo', $drivers); - $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); - $this->assertEquals('avatar.driver.barfoo', $drivers['avatar.driver.barfoo']); + $this->assertEquals(array( + 'avatar.driver.barfoo' => 'avatar.driver.barfoo', + 'avatar.driver.foobar' => 'avatar.driver.foobar', + 'avatar.driver.local' => 'avatar.driver.local', + 'avatar.driver.remote' => 'avatar.driver.remote', + 'avatar.driver.upload' => 'avatar.driver.upload', + 'avatar.driver.gravatar' => 'avatar.driver.gravatar', + ), $drivers); } public function test_get_enabled_drivers() @@ -76,6 +86,48 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); } + public function get_driver_data_enabled() + { + return array( + array('avatar.driver.foobar', 'avatar.driver.foobar'), + array('avatar.driver.foo_wrong', null), + array('avatar.driver.local', null), + array(AVATAR_GALLERY, null), + array(AVATAR_UPLOAD, null), + array(AVATAR_REMOTE, null), + ); + } + + /** + * @dataProvider get_driver_data_enabled + */ + public function test_get_driver_enabled($driver_name, $expected) + { + $driver = $this->manager->get_driver($driver_name); + $this->assertEquals($expected, $driver); + } + + public function get_driver_data_all() + { + return array( + array('avatar.driver.foobar', 'avatar.driver.foobar'), + array('avatar.driver.foo_wrong', null), + array('avatar.driver.local', 'avatar.driver.local'), + array(AVATAR_GALLERY, 'avatar.driver.local'), + array(AVATAR_UPLOAD, 'avatar.driver.upload'), + array(AVATAR_REMOTE, 'avatar.driver.remote'), + ); + } + + /** + * @dataProvider get_driver_data_all + */ + public function test_get_driver_all($driver_name, $expected) + { + $driver = $this->manager->get_driver($driver_name, false); + $this->assertEquals($expected, $driver); + } + public function test_get_avatar_settings() { $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar); @@ -157,4 +209,38 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey($key, $cleaned_row); } } + + public function test_clean_driver_name() + { + $this->assertEquals('avatar.driver.local', $this->manager->clean_driver_name('avatar_driver_local')); + } + + public function test_prepare_driver_name() + { + $this->assertEquals('avatar_driver_local', $this->manager->prepare_driver_name('avatar.driver.local')); + } + + public function test_localize_errors() + { + $user = $this->getMock('phpbb_user'); + $lang_array = array( + array('FOOBAR_OFF', 'foobar_off'), + array('FOOBAR_EXPLAIN', 'FOOBAR_EXPLAIN %s'), + ); + $user->expects($this->any()) + ->method('lang') + ->will($this->returnValueMap($lang_array)); + + // Pass error as string + $this->assertEquals(array('foobar_off'), $this->manager->localize_errors($user, array('FOOBAR_OFF'))); + + // Pass error as array for vsprintf() + $this->assertEquals(array('FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array(array('FOOBAR_EXPLAIN', 'foo')))); + + // Pass both types + $this->assertEquals(array('foobar_off', 'FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array( + 'FOOBAR_OFF', + array('FOOBAR_EXPLAIN', 'foo'), + ))); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a38740c82d..68cbb64c03 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,13 +14,13 @@ require_once $phpbb_root_path . 'includes/startup.php'; $table_prefix = 'phpbb_'; require_once $phpbb_root_path . 'includes/constants.php'; -require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; +require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx; $phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php"); $phpbb_class_loader_mock->register(); $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', "php"); $phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', "php"); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'phpbb/', "php"); $phpbb_class_loader->register(); require_once 'test_framework/phpbb_test_case_helpers.php'; diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index bf27c7c217..2b55c1ff8d 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -30,9 +30,9 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase public function test_resolve_path() { $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/'); + $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'phpbb/'); - $prefix .= 'includes/'; + $prefix .= 'phpbb/'; $this->assertEquals( '', @@ -71,10 +71,10 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $cache = new phpbb_mock_cache($cache_map); $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/', 'php', $cache); - $class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'includes/', 'php', $cache); + $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'phpbb/', 'php', $cache); + $class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'phpbb/', 'php', $cache); - $prefix .= 'includes/'; + $prefix .= 'phpbb/'; $this->assertEquals( $prefix . 'dir/class_name.php', diff --git a/tests/class_loader/includes/class_name.php b/tests/class_loader/phpbb/class_name.php similarity index 100% rename from tests/class_loader/includes/class_name.php rename to tests/class_loader/phpbb/class_name.php diff --git a/tests/class_loader/includes/dir.php b/tests/class_loader/phpbb/dir.php similarity index 100% rename from tests/class_loader/includes/dir.php rename to tests/class_loader/phpbb/dir.php diff --git a/tests/class_loader/includes/dir/class_name.php b/tests/class_loader/phpbb/dir/class_name.php similarity index 100% rename from tests/class_loader/includes/dir/class_name.php rename to tests/class_loader/phpbb/dir/class_name.php diff --git a/tests/class_loader/includes/dir/subdir/class_name.php b/tests/class_loader/phpbb/dir/subdir/class_name.php similarity index 100% rename from tests/class_loader/includes/dir/subdir/class_name.php rename to tests/class_loader/phpbb/dir/subdir/class_name.php diff --git a/tests/class_loader/includes/dir2/dir2.php b/tests/class_loader/phpbb/dir2/dir2.php similarity index 100% rename from tests/class_loader/includes/dir2/dir2.php rename to tests/class_loader/phpbb/dir2/dir2.php diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php new file mode 100644 index 0000000000..6234aac9ad --- /dev/null +++ b/tests/content_visibility/delete_post_test.php @@ -0,0 +1,310 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_post.xml'); + } + + public function delete_post_data() + { + $info_data = array( + 'topic_first_post_id' => 1, + 'topic_last_post_id' => 3, + 'topic_posts_approved' => 3, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_visibility' => ITEM_APPROVED, + 'post_time' => 2, + 'post_visibility' => ITEM_APPROVED, + 'post_postcount' => true, + 'poster_id' => 1, + 'post_reported' => false, + ); + + return array( + array( + 1, 1, 2, + array_merge($info_data, array( + 'post_time' => 2, + )), + false, 'harddelete', + array( + array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + //array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + ), + array( + array( + 'topic_visibility' => ITEM_APPROVED, + 'topic_first_post_id' => 1, + 'topic_last_post_id' => 3, + 'topic_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), + ), + ), + array( + 1, 1, 1, + array_merge($info_data, array( + 'post_time' => 1, + )), + false, 'harddelete', + array( + //array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + ), + array( + array( + 'topic_visibility' => ITEM_APPROVED, + 'topic_first_post_id' => 2, + 'topic_last_post_id' => 3, + 'topic_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), + ), + ), + array( + 1, 1, 3, + array_merge($info_data, array( + 'post_time' => 3, + )), + false, 'harddelete', + array( + array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + //array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + ), + array( + array( + 'topic_visibility' => ITEM_APPROVED, + 'topic_first_post_id' => 1, + 'topic_last_post_id' => 2, + 'topic_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), + ), + ), + array( + 1, 1, 2, + array_merge($info_data, array( + 'post_time' => 2, + )), + true, 'soft delete', + array( + array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'), + array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + ), + array( + array( + 'topic_visibility' => ITEM_APPROVED, + 'topic_first_post_id' => 1, + 'topic_last_post_id' => 3, + 'topic_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), + ), + ), + array( + 1, 1, 1, + array_merge($info_data, array( + 'post_time' => 1, + )), + true, 'soft delete', + array( + array('post_id' => 1, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'), + array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + ), + array( + array( + 'topic_visibility' => ITEM_APPROVED, + 'topic_first_post_id' => 2, + 'topic_last_post_id' => 3, + 'topic_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), + ), + ), + array( + 1, 1, 3, + array_merge($info_data, array( + 'post_time' => 3, + )), + true, 'soft delete', + array( + array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'), + ), + array( + array( + 'topic_visibility' => ITEM_APPROVED, + 'topic_first_post_id' => 1, + 'topic_last_post_id' => 2, + 'topic_posts_approved' => 2, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => '', + ), + ), + array( + array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), + ), + ), + + array( + 2, 2, 4, + array( + 'topic_first_post_id' => 4, + 'topic_last_post_id' => 4, + 'topic_posts_approved' => 1, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_visibility' => ITEM_APPROVED, + 'post_time' => 4, + 'post_visibility' => ITEM_APPROVED, + 'post_postcount' => true, + 'poster_id' => 1, + 'post_reported' => false, + ), + false, 'harddelete', + array( + ), + array( + ), + array( + array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 0), + ), + ), + + array( + 2, 2, 4, + array( + 'topic_first_post_id' => 4, + 'topic_last_post_id' => 4, + 'topic_posts_approved' => 1, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 0, + 'topic_visibility' => ITEM_APPROVED, + 'post_time' => 4, + 'post_visibility' => ITEM_APPROVED, + 'post_postcount' => true, + 'poster_id' => 1, + 'post_reported' => false, + ), + true, 'soft delete', + array( + array('post_id' => 4, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''), + ), + array( + array( + 'topic_visibility' => ITEM_DELETED, + 'topic_first_post_id' => 4, + 'topic_last_post_id' => 4, + 'topic_posts_approved' => 0, + 'topic_posts_unapproved' => 0, + 'topic_posts_softdeleted' => 1, + 'topic_delete_reason' => 'soft delete', + ), + ), + array( + array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 1, 'forum_last_post_id' => 0), + ), + ), + ); + } + + /** + * @dataProvider delete_post_data + */ + public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum) + { + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_root_path, $phpEx; + + $config['search_type'] = 'phpbb_mock_search'; + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + set_config_count(null, null, null, new phpbb_config(array('num_posts' => 3, 'num_topics' => 1))); + + // Create auth mock + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap(array( + array('m_approve', 1, true), + ))); + $user = $this->getMock('phpbb_user'); + + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + $phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); + + delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason); + + $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason + FROM phpbb_posts + WHERE topic_id = ' . $topic_id . ' + ORDER BY post_id ASC'); + + $this->assertEquals($expected_posts, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + + $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_delete_reason + FROM phpbb_topics + WHERE topic_id = ' . $topic_id); + + $this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + + $result = $db->sql_query('SELECT forum_posts_approved, forum_posts_unapproved, forum_posts_softdeleted, forum_topics_approved, forum_topics_unapproved, forum_topics_softdeleted, forum_last_post_id + FROM phpbb_forums + WHERE forum_id = ' . $forum_id); + + $this->assertEquals($expected_forum, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + } +} diff --git a/tests/content_visibility/fixtures/delete_post.xml b/tests/content_visibility/fixtures/delete_post.xml new file mode 100644 index 0000000000..deca9c74b6 --- /dev/null +++ b/tests/content_visibility/fixtures/delete_post.xml @@ -0,0 +1,167 @@ + + + + forum_id + forum_posts_approved + forum_posts_unapproved + forum_posts_softdeleted + forum_topics_approved + forum_topics_unapproved + forum_topics_softdeleted + forum_last_post_id + forum_parents + forum_desc + forum_rules + + + 1 + 3 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + 2 + 1 + 0 + 0 + 1 + 0 + 0 + 4 + + + + +
+ + topic_id + forum_id + topic_visibility + topic_title + topic_first_post_id + topic_last_post_id + topic_delete_user + topic_delete_time + topic_delete_reason + topic_posts_approved + topic_posts_unapproved + topic_posts_softdeleted + + + 1 + 1 + 1 + Approved + 1 + 3 + 0 + 0 + + 3 + 0 + 0 + + + 2 + 2 + 1 + Approved + 4 + 4 + 0 + 0 + + 1 + 0 + 0 + +
+ + post_id + poster_id + topic_id + forum_id + post_visibility + post_time + post_text + post_delete_user + post_delete_time + post_delete_reason + + 1 + 1 + 1 + 1 + 1 + 1 + Approved + 0 + 0 + + + + 2 + 1 + 1 + 1 + 1 + 2 + Approved + 0 + 0 + + + + 3 + 1 + 1 + 1 + 1 + 3 + Approved + 0 + 0 + + + + + 4 + 1 + 2 + 2 + 1 + 4 + Approved + 0 + 0 + + +
+ + user_id + user_posts + username + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + 4 + user 1 + user 1 + + + + + +
+
diff --git a/tests/content_visibility/fixtures/get_forums_visibility_sql.xml b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml new file mode 100644 index 0000000000..658d34398f --- /dev/null +++ b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml @@ -0,0 +1,133 @@ + + + + topic_id + forum_id + topic_visibility + topic_title + + 1 + 1 + 0 + Unapproved + + + 2 + 1 + 1 + Approved + + + 3 + 1 + 2 + Softdeleted + + + 4 + 2 + 0 + Unapproved + + + 5 + 2 + 1 + Approved + + + 6 + 2 + 2 + Softdeleted + + + 7 + 3 + 0 + Unapproved + + + 8 + 3 + 1 + Approved + + + 9 + 3 + 2 + Softdeleted + +
+ + post_id + topic_id + forum_id + post_visibility + post_text + + 1 + 1 + 1 + 0 + Unapproved + + + 2 + 2 + 1 + 1 + Approved + + + 3 + 3 + 1 + 2 + Softdeleted + + + 4 + 4 + 2 + 0 + Unapproved + + + 5 + 5 + 2 + 1 + Approved + + + 6 + 6 + 2 + 2 + Softdeleted + + + 7 + 7 + 3 + 0 + Unapproved + + + 8 + 8 + 3 + 1 + Approved + + + 9 + 9 + 3 + 2 + Softdeleted + +
+
diff --git a/tests/content_visibility/fixtures/get_visibility_sql.xml b/tests/content_visibility/fixtures/get_visibility_sql.xml new file mode 100644 index 0000000000..146244263e --- /dev/null +++ b/tests/content_visibility/fixtures/get_visibility_sql.xml @@ -0,0 +1,55 @@ + + + + topic_id + forum_id + topic_visibility + topic_title + + 1 + 1 + 0 + Unapproved + + + 2 + 1 + 1 + Approved + + + 3 + 1 + 2 + Softdeleted + +
+ + post_id + topic_id + forum_id + post_visibility + post_text + + 1 + 1 + 1 + 0 + Unapproved + + + 2 + 2 + 1 + 1 + Approved + + + 3 + 3 + 1 + 2 + Softdeleted + +
+
diff --git a/tests/content_visibility/fixtures/set_post_visibility.xml b/tests/content_visibility/fixtures/set_post_visibility.xml new file mode 100644 index 0000000000..722525deaa --- /dev/null +++ b/tests/content_visibility/fixtures/set_post_visibility.xml @@ -0,0 +1,162 @@ + + + + topic_id + forum_id + topic_visibility + topic_title + topic_first_post_id + topic_last_post_id + topic_posts_approved + topic_posts_softdeleted + topic_posts_unapproved + + 1 + 1 + 1 + Approved + 2 + 2 + 1 + 1 + 1 + + + + 2 + 1 + 1 + 2 Approved posts + 5 + 6 + 1 + 1 + 1 + + + + 3 + 1 + 1 + Only 1 Approved posts + 8 + 8 + 1 + 0 + 0 + +
+ + post_id + poster_id + topic_id + forum_id + post_visibility + post_text + + 1 + 1 + 1 + 1 + 0 + Unapproved + + + 2 + 2 + 1 + 1 + 1 + Approved + + + 3 + 3 + 1 + 1 + 2 + Softdeleted + + + + 4 + 1 + 2 + 1 + 0 + Unapproved + + + 5 + 2 + 2 + 1 + 1 + Approved + + + 6 + 2 + 2 + 1 + 1 + Approved 2 + + + 7 + 3 + 2 + 1 + 2 + Softdeleted + + + 8 + 1 + 3 + 1 + 1 + Approved + +
+ + user_id + user_posts + username + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + 1 + user 1 + user 1 + + + + + + + 2 + 1 + user 2 + user 2 + + + + + + + 3 + 1 + user 3 + user 3 + + + + + +
+
diff --git a/tests/content_visibility/fixtures/set_topic_visibility.xml b/tests/content_visibility/fixtures/set_topic_visibility.xml new file mode 100644 index 0000000000..a875012d4f --- /dev/null +++ b/tests/content_visibility/fixtures/set_topic_visibility.xml @@ -0,0 +1,136 @@ + + + + topic_id + forum_id + topic_visibility + topic_title + topic_first_post_id + topic_last_post_id + topic_delete_user + topic_delete_time + topic_delete_reason + + + 1 + 1 + 1 + Approved + 1 + 1 + 0 + 0 + + + + + 2 + 1 + 2 + Soft deleted + 4 + 5 + 2 + 123 + + +
+ + post_id + poster_id + topic_id + forum_id + post_visibility + post_text + post_delete_user + post_delete_time + post_delete_reason + + 1 + 1 + 1 + 1 + 1 + Approved + 2 + 0 + + + + 2 + 1 + 1 + 1 + 2 + Soft deleted + 2 + 123 + manually + + + 3 + 1 + 1 + 1 + 0 + Unapproved + 0 + 0 + + + + + 4 + 1 + 2 + 1 + 2 + Soft deleted by topic soft delete + 2 + 123 + + + + 5 + 1 + 2 + 1 + 2 + Soft deleted before the topic was soft deleted + 2 + 120 + manually + + + 6 + 1 + 2 + 1 + 0 + Unapproved before the topic was soft deleted + 0 + 0 + + +
+ + user_id + user_posts + username + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + 6 + user 1 + user 1 + + + + + +
+
diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php new file mode 100644 index 0000000000..aa44fa4013 --- /dev/null +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -0,0 +1,143 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); + } + + public function get_forums_visibility_sql_data() + { + return array( + array( + 'phpbb_topics', + 'topic', array(1, 2, 3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 7), + array('topic_id' => 8), + array('topic_id' => 9), + ), + ), + array( + 'phpbb_topics', + 'topic', array(1, 2), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + ), + ), + array( + 'phpbb_topics', + 'topic', array(1, 2, 3), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('topic_id' => 2), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 8), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2, 3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 7), + array('post_id' => 8), + array('post_id' => 9), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2, 3), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('post_id' => 2), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 8), + ), + ), + ); + } + + /** + * @dataProvider get_forums_visibility_sql_data + */ + public function test_get_forums_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_getf') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + $user = $this->getMock('phpbb_user'); + $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . $content_visibility->get_forums_visibility_sql($mode, $forum_ids, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/content_visibility/get_global_visibility_sql_test.php b/tests/content_visibility/get_global_visibility_sql_test.php new file mode 100644 index 0000000000..0f019ffa50 --- /dev/null +++ b/tests/content_visibility/get_global_visibility_sql_test.php @@ -0,0 +1,143 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); + } + + public function get_global_visibility_sql_data() + { + return array( + array( + 'phpbb_topics', + 'topic', array(), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 7), + array('topic_id' => 8), + array('topic_id' => 9), + ), + ), + array( + 'phpbb_topics', + 'topic', array(3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + ), + ), + array( + 'phpbb_topics', + 'topic', array(), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('topic_id' => 2), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 8), + ), + ), + array( + 'phpbb_posts', + 'post', array(), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 7), + array('post_id' => 8), + array('post_id' => 9), + ), + ), + array( + 'phpbb_posts', + 'post', array(3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + ), + ), + array( + 'phpbb_posts', + 'post', array(), '', + array( + array('m_approve', true, array(2 => true)), + ), + array( + array('post_id' => 2), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 8), + ), + ), + ); + } + + /** + * @dataProvider get_global_visibility_sql_data + */ + public function test_get_global_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_getf') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + $user = $this->getMock('phpbb_user'); + $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . $content_visibility->get_global_visibility_sql($mode, $forum_ids, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php new file mode 100644 index 0000000000..cc6c10c649 --- /dev/null +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -0,0 +1,90 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/get_visibility_sql.xml'); + } + + public function get_visibility_sql_data() + { + return array( + array( + 'phpbb_posts', + 'post', 1, '', + array( + array('m_approve', 1, true), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + ), + ), + array( + 'phpbb_posts', + 'post', 1, '', + array( + ), + array( + array('post_id' => 2), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array( + array('m_approve', 1, true), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array(), + array( + array('topic_id' => 2), + ), + ), + ); + } + + /** + * @dataProvider get_visibility_sql_data + */ + public function test_get_visibility_sql($table, $mode, $forum_id, $table_alias, $permissions, $expected) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + $user = $this->getMock('phpbb_user'); + $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . $content_visibility->get_visibility_sql($mode, $forum_id, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/content_visibility/set_post_visibility_test.php b/tests/content_visibility/set_post_visibility_test.php new file mode 100644 index 0000000000..81abf56c75 --- /dev/null +++ b/tests/content_visibility/set_post_visibility_test.php @@ -0,0 +1,143 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/set_post_visibility.xml'); + } + + public function set_post_visibility_data() + { + return array( + array( + ITEM_APPROVED, + 1, 1, 1, + 2, time(), 'approve', + true, false, + array( + array('post_id' => 1, 'post_visibility' => 1, 'post_delete_reason' => 'approve'), + array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 1, 'topic_last_post_id' => 2), + ), + ), + array( + ITEM_APPROVED, + 3, 1, 1, + 2, time(), 'approve', + false, true, + array( + array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => 1, 'post_delete_reason' => 'approve'), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 2, 'topic_last_post_id' => 3), + ), + ), + array( + ITEM_DELETED, + 2, 1, 1, + 2, time(), 'deleted', + true, true, + array( + array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3), + ), + ), + array( + ITEM_DELETED, + 5, 2, 1, + 2, time(), 'deleted', + true, false, + array( + array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 6, 'topic_last_post_id' => 6), + ), + ), + array( + ITEM_DELETED, + 6, 2, 1, + 2, time(), 'deleted', + false, true, + array( + array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 6, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 5, 'topic_last_post_id' => 5), + ), + ), + array( + ITEM_DELETED, + 8, 3, 1, + 2, time(), 'deleted', + true, true, + array( + array('post_id' => 8, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 8, 'topic_last_post_id' => 8), + ), + ), + ); + } + + /** + * @dataProvider set_post_visibility_data + */ + public function test_set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected, $expected_topic) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $auth = $this->getMock('phpbb_auth'); + $user = $this->getMock('phpbb_user'); + $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest); + + $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason + FROM phpbb_posts + WHERE topic_id = ' . $topic_id . ' + ORDER BY post_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + + $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id + FROM phpbb_topics + WHERE topic_id = ' . $topic_id); + + $this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + } +} diff --git a/tests/content_visibility/set_topic_visibility_test.php b/tests/content_visibility/set_topic_visibility_test.php new file mode 100644 index 0000000000..6b5d884a2b --- /dev/null +++ b/tests/content_visibility/set_topic_visibility_test.php @@ -0,0 +1,107 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/set_topic_visibility.xml'); + } + + public function set_topic_visibility_data() + { + return array( + array( + ITEM_DELETED, 1, 1, + 2, time(), 'delete', false, + array( + array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), + array('post_id' => 3, 'post_visibility' => 0, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete'), + ), + ), + array( + ITEM_DELETED, 1, 1, + 2, time(), 'delete-forced', true, + array( + array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''), + array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => ''), + array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete-forced'), + ), + ), + array( + ITEM_APPROVED, 2, 1, + 2, time(), 'approved', false, + array( + array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'manually'), + array('post_id' => 6, 'post_visibility' => 0, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 4, 'topic_delete_reason' => 'approved'), + ), + ), + array( + ITEM_APPROVED, 2, 1, + 2, time(), 'approved-forced', true, + array( + array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''), + array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''), + ), + array( + array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 6, 'topic_delete_reason' => 'approved-forced'), + ), + ), + ); + } + + /** + * @dataProvider set_topic_visibility_data + */ + public function test_set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all, $expected_posts, $expected_topic) + { + global $cache, $db, $auth, $phpbb_root_path, $phpEx; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $auth = $this->getMock('phpbb_auth'); + $user = $this->getMock('phpbb_user'); + $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + + $content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all); + + $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason + FROM phpbb_posts + WHERE topic_id = ' . $topic_id . ' + ORDER BY post_id ASC'); + + $this->assertEquals($expected_posts, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + + $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_delete_reason + FROM phpbb_topics + WHERE topic_id = ' . $topic_id); + + $this->assertEquals($expected_topic, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); + } +} diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index c06bf7d548..dfc4f80469 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -59,7 +59,7 @@ class phpbb_controller_controller_test extends phpbb_test_case } if (!class_exists('phpbb_controller_foo')) { - include(__DIR__.'/includes/controller/foo.php'); + include(__DIR__.'/phpbb/controller/foo.php'); } $resolver = new phpbb_controller_resolver(new phpbb_user, $container); diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index 2c22700ca6..6686b77e8f 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -45,15 +45,17 @@ class phpbb_controller_helper_url_test extends phpbb_test_case */ public function test_helper_url($route, $params, $is_amp, $session_id, $expected, $description) { - global $phpbb_dispatcher; + global $phpbb_dispatcher, $phpbb_root_path, $phpEx; $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->user = $this->getMock('phpbb_user'); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, new phpbb_template_context()); + $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->style_provider = new phpbb_style_path_provider(); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, new phpbb_config(array()), $this->user, $this->style_resource_locator, $this->style_provider, $this->template); $helper = new phpbb_controller_helper($this->template, $this->user, '', 'php'); $this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected); } } - diff --git a/tests/controller/includes/controller/foo.php b/tests/controller/phpbb/controller/foo.php similarity index 100% rename from tests/controller/includes/controller/foo.php rename to tests/controller/phpbb/controller/foo.php diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php index c28925272e..2d97672878 100644 --- a/tests/datetime/from_format_test.php +++ b/tests/datetime/from_format_test.php @@ -7,9 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/user.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/datetime.php'; require_once dirname(__FILE__) . '/../mock/lang.php'; class phpbb_datetime_from_format_test extends phpbb_test_case diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index e87fc1c6bd..077bfad933 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; class phpbb_dbal_auto_increment_test extends phpbb_database_test_case { diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index c20e46011f..7bdbc696e7 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; class phpbb_dbal_db_tools_test extends phpbb_database_test_case { diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 1e40c9c6d6..9e55e4dd35 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -8,10 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; - require_once dirname(__FILE__) . '/migration/dummy.php'; require_once dirname(__FILE__) . '/migration/unfulfillable.php'; require_once dirname(__FILE__) . '/migration/if.php'; diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index 7d582f230b..b82d1ef48d 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -7,9 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; - class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { public function setup() diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 3303086b26..828fb76c65 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -8,8 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case { diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 438ab2b28e..79d9db66da 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -8,8 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case { diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index 84d454742f..d826765681 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -18,6 +18,11 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case { $db = $this->new_dbal(); + if (strpos($db->sql_layer, 'mysql') === 0 && version_compare($db->sql_server_info(true, false), '5.6', '>=')) + { + $this->markTestSkipped('MySQL 5.6 fails to order things correctly. See also: http://tracker.phpbb.com/browse/PHPBB3-11571 http://bugs.mysql.com/bug.php?id=69005'); + } + // http://tracker.phpbb.com/browse/PHPBB3-10507 // Test ORDER BY LOWER(style_name) $db->sql_return_on_error(true); @@ -58,7 +63,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case 'style_parent_id' => 0, 'style_parent_tree' => '', ) - ), + ), $db->sql_fetchrowset($result) ); } diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index d6a5ec823b..c570f19ebd 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -40,11 +40,12 @@ class phpbb_di_container_test extends phpbb_test_case public function test_phpbb_create_compiled_container() { $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $config_file = __DIR__ . '/fixtures/config.php'; $extensions = array( new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), new phpbb_di_extension_core($phpbb_root_path . 'config'), ); - $container = phpbb_create_compiled_container($extensions, array(), $phpbb_root_path, 'php'); + $container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php'); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); $this->assertTrue($container->isFrozen()); diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php index d67dea3719..fceb8aa3d8 100644 --- a/tests/error_collector_test.php +++ b/tests/error_collector_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../phpBB/includes/error_collector.php'; class phpbb_error_collector_test extends phpbb_test_case { diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 6f3cebbd7c..3bf2c42573 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -36,7 +36,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_suffix_get_classes() { $classes = $this->finder - ->core_path('includes/default/') + ->core_path('phpbb/default/') ->extension_suffix('_class') ->get_classes(); @@ -81,7 +81,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_prefix_get_classes() { $classes = $this->finder - ->core_path('includes/default/') + ->core_path('phpbb/default/') ->extension_prefix('hidden_') ->get_classes(); @@ -98,7 +98,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_directory_get_classes() { $classes = $this->finder - ->core_path('includes/default/') + ->core_path('phpbb/default/') ->extension_directory('type') ->get_classes(); @@ -209,7 +209,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_cached_get_files() { $query = array( - 'core_path' => 'includes/foo', + 'core_path' => 'phpbb/foo', 'core_suffix' => false, 'core_prefix' => false, 'core_directory' => 'bar', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index d410333f09..e5bd29092e 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; - class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { protected $class_loader; @@ -42,12 +40,11 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->user = new phpbb_user(); $this->table_prefix = 'phpbb_'; - $this->template = new phpbb_template( + $this->template = new phpbb_template_twig( $this->phpbb_root_path, $this->phpEx, $this->config, $this->user, - new phpbb_style_resource_locator(), new phpbb_template_context() ); diff --git a/tests/extension/includes/default/implementation.php b/tests/extension/phpbb/default/implementation.php similarity index 100% rename from tests/extension/includes/default/implementation.php rename to tests/extension/phpbb/default/implementation.php diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index ff4d3ced5c..cfd85571b7 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -39,7 +39,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // logout $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out $crawler = self::request('GET', 'index.php'); diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 8c014aebed..6c6572af62 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -36,6 +36,26 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $this->add_lang(array('ucp', 'acp/groups')); } + // Enable all avatars in the ACP + protected function enable_all_avatars() + { + $this->add_lang('acp/board'); + + $crawler = self::request('GET', 'adm/index.php?i=board&mode=avatar&sid=' . $this->sid); + // Check the default entries we should have + $this->assertContains($this->lang('ALLOW_REMOTE'), $crawler->text()); + $this->assertContains($this->lang('ALLOW_AVATARS'), $crawler->text()); + $this->assertContains($this->lang('ALLOW_LOCAL'), $crawler->text()); + + // Now start setting the needed settings + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['config[allow_avatar_local]']->select(1); + $form['config[allow_avatar_remote]']->select(1); + $form['config[allow_avatar_remote_upload]']->select(1); + $crawler = self::submit($form); + $this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->text()); + } + public function groups_manage_test_data() { return array( @@ -60,4 +80,34 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $crawler = self::submit($form); $this->assertContains($this->lang($expected), $crawler->text()); } + + public function group_avatar_min_max_data() + { + return array( + array('avatar_driver_upload', 'avatar_upload_url', 'foo', 'AVATAR_URL_INVALID'), + array('avatar_driver_upload', 'avatar_upload_url', 'foobar', 'AVATAR_URL_INVALID'), + array('avatar_driver_upload', 'avatar_upload_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'), + array('avatar_driver_remote', 'avatar_remote_url', 'foo', 'AVATAR_URL_INVALID'), + array('avatar_driver_remote', 'avatar_remote_url', 'foobar', 'AVATAR_URL_INVALID'), + array('avatar_driver_remote', 'avatar_remote_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'), + ); + } + + /** + * @dataProvider group_avatar_min_max_data + */ + public function test_group_avatar_min_max($avatar_type, $form_name, $input, $expected) + { + $this->login(); + $this->admin_login(); + $this->add_lang(array('ucp', 'acp/groups')); + $this->enable_all_avatars(); + + $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['avatar_driver']->setValue($avatar_type); + $form[$form_name]->setValue($input); + $crawler = self::submit($form); + $this->assertContains($this->lang($expected), $crawler->text()); + } } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 9ddf1e3e5c..7d29f0000c 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -6,7 +6,6 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; /** * @group functional diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index c573ea5410..c31a892ce9 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -6,8 +6,6 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ - -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php'; /** diff --git a/tests/functional/forum_style_test.php b/tests/functional/forum_style_test.php new file mode 100644 index 0000000000..59f7341eb6 --- /dev/null +++ b/tests/functional/forum_style_test.php @@ -0,0 +1,45 @@ +assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = self::request('GET', 'viewtopic.php?t=1'); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + } + + public function test_custom_forum_style() + { + $db = $this->get_db(); + $this->add_style(2, 'test_style'); + $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 2 WHERE forum_id = 2'); + + $crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = self::request('GET', 'viewtopic.php?t=1'); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 0 WHERE forum_id = 2'); + $this->delete_style(2, 'test_style'); + } +} diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index c55e7373ea..651c99a99d 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; - /** * @group functional */ diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php new file mode 100644 index 0000000000..d5adc6ad0a --- /dev/null +++ b/tests/functional/paging_test.php @@ -0,0 +1,39 @@ +login(); + + $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); + for ($post_id = 1; $post_id < 20; $post_id++) + { + $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post no' . $post_id . ' posted by the testing framework.'); + } + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $this->assertContains('post no9', $crawler->text()); + $this->assertNotContains('post no19', $crawler->text()); + + $next_link = $crawler->filter('#viewtopic > fieldset > a.arrow-right')->attr('href'); + $crawler = self::request('GET', $next_link); + $this->assertContains('post no19', $crawler->text()); + $this->assertNotContains('post no9', $crawler->text()); + + $prev_link = $crawler->filter('#viewtopic > fieldset > a.arrow-left')->attr('href'); + $crawler = self::request('GET', $prev_link); + $this->assertContains('post no9', $crawler->text()); + $this->assertNotContains('post no19', $crawler->text()); + } +} diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 9bcfcc2fda..7fd1e4fdcf 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -32,105 +32,4 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } - - /** - * Creates a topic - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return self::submit_post($posting_url, 'POST_TOPIC', $form_data); - } - - /** - * Creates a post - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return self::submit_post($posting_url, 'POST_REPLY', $form_data); - } - - /** - * Helper for submitting posts - * - * @param string $posting_url - * @param string $posting_contains - * @param array $form_data - * @return array post_id, topic_id - */ - protected function submit_post($posting_url, $posting_contains, $form_data) - { - $this->add_lang('posting'); - - $crawler = self::request('GET', $posting_url); - $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); - - $hidden_fields = array( - $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }), - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } - - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; - - // I use a request because the form submission method does not allow you to send data that is not - // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) - // Instead, I send it as a request with the submit button "post" set to true. - $crawler = self::request('POST', $posting_url, $form_data); - $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - - $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); - - $matches = $topic_id = $post_id = false; - preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); - - $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; - $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; - - return array( - 'topic_id' => $topic_id, - 'post_id' => $post_id, - ); - } } diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php new file mode 100644 index 0000000000..af713775c5 --- /dev/null +++ b/tests/functional/report_post_captcha.php @@ -0,0 +1,61 @@ +login(); + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + } + + public function test_guest_report_post() + { + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->add_lang('mcp'); + $this->assertContains($this->lang('USER_CANNOT_REPORT'), $crawler->filter('html')->text()); + + $this->set_reporting_guest(1); + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + $this->set_reporting_guest(-1); + } + + protected function set_reporting_guest($report_post_allowed) + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=permissions&icat=12&mode=setting_group_local&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values["group_id[0]"] = 1; + $form->setValues($values); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values["forum_id"] = 2; + $form->setValues($values); + $crawler = self::submit($form); + + $this->add_lang('acp/permissions'); + $form = $crawler->selectButton($this->lang('APPLY_ALL_PERMISSIONS'))->form(); + $values = $form->getValues(); + $values["setting[1][2][f_report]"] = $report_post_allowed; + $form->setValues($values); + $crawler = self::submit($form); + + $crawler = self::request('GET', 'ucp.php?mode=logout&sid=' . $this->sid); + } +} diff --git a/tests/functional/softdelete_test.php b/tests/functional/softdelete_test.php new file mode 100644 index 0000000000..bd4d34cf99 --- /dev/null +++ b/tests/functional/softdelete_test.php @@ -0,0 +1,761 @@ +login(); + $this->admin_login(); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Soft Delete #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + $crawler = self::submit($form); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Soft Delete #2', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + $crawler = self::submit($form); + } + + public function test_create_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + // Test creating topic + $post = $this->create_topic($this->data['forums']['Soft Delete #1'], 'Soft Delete Topic #1', 'This is a test topic posted by the testing framework.'); + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + + $this->assertContains('Soft Delete Topic #1', $crawler->filter('html')->text()); + $this->data['topics']['Soft Delete Topic #1'] = (int) $post['topic_id']; + $this->data['posts']['Soft Delete Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after creating topic #1'); + + // Test creating a reply + $post2 = $this->create_post($this->data['forums']['Soft Delete #1'], $post['topic_id'], 'Re: Soft Delete Topic #1-#2', 'This is a test post posted by the testing framework.'); + $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + + $this->assertContains('Re: Soft Delete Topic #1-#2', $crawler->filter('html')->text()); + $this->data['posts']['Re: Soft Delete Topic #1-#2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->eq(1)->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#2'], + ), 'after replying'); + } + + public function test_softdelete_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#2'], + ), 'before softdelete'); + + $this->add_lang('posting'); + $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Soft Delete #1']}&p={$this->data['posts']['Re: Soft Delete Topic #1-#2']}&sid={$this->sid}"); + $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('POST_DELETED', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after softdelete'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); + } + + public function test_move_softdeleted_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before moving #2'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('move'); + $crawler = self::submit($form); + $this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text()); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after moving #2'); + } + + public function test_softdelete_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before softdeleting #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before softdeleting #2'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('posting'); + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('delete_topic'); + $crawler = self::submit($form); + $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'after moving #2'); + } + + public function test_move_softdeleted_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'before moving #2'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('move'); + $crawler = self::submit($form); + $this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text()); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #1']); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'after moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after moving #2'); + } + + public function test_restore_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'before restoring #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before restoring #2'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->selectButton($this->lang('RESTORE'))->form(); + $crawler = self::submit($form); + $this->assertContainsLang('RESTORE_POST', $crawler->text()); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('POST_RESTORED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after restoring #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after restoring #2'); + } + + public function test_split_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before splitting #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before splitting #2'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('split'); + $crawler = self::submit($form); + $this->assertContainsLang('SPLIT_TOPIC_EXPLAIN', $crawler->text()); + + $form = $crawler->selectButton('Submit')->form(array( + 'subject' => 'Soft Delete Topic #2', + )); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); + $form['post_id_list'][1]->tick(); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_SPLIT_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + $this->assertNotContains('Re: Soft Delete Topic #1-#2', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after restoring #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'after restoring #2'); + } + + public function test_move_topic_back() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + 'Soft Delete Topic #2', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + + $form = $crawler->selectButton('Go')->eq(1)->form(); + $form['action']->select('move'); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #1']); + $crawler = self::submit($form); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after moving back'); + } + + public function test_merge_topics() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + 'Soft Delete Topic #2', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before merging #1'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Go')->eq(1)->form(); + $form['action']->select('merge_topic'); + $crawler = self::submit($form); + $this->assertContainsLang('SELECT_MERGE', $crawler->text()); + + $crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Soft Delete #1']}&t={$this->data['topics']['Soft Delete Topic #2']}&i=main&mode=forum_view&action=merge_topic&to_topic_id={$this->data['topics']['Soft Delete Topic #1']}"); + $this->assertContainsLang('MERGE_TOPICS_CONFIRM', $crawler->text()); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('POSTS_MERGED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + $this->assertContainsLang('POST_DELETED', $crawler->filter('body')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after merging #1'); + } + + public function test_fork_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before forking #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before forking #2'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('fork'); + $crawler = self::submit($form); + $this->assertContainsLang('FORK_TOPIC', $crawler->text()); + + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_FORKED_SUCCESS', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after forking #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'] + 2, + ), 'after forking #2'); + } + + public function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + public function load_ids($data) + { + $this->db = $this->get_db(); + + if (!empty($data['forums'])) + { + $sql = 'SELECT * + FROM phpbb_forums + WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['forum_name'], $data['forums'])) + { + $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['topics'])) + { + $sql = 'SELECT * + FROM phpbb_topics + WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['topic_title'], $data['topics'])) + { + $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['posts'])) + { + $sql = 'SELECT * + FROM phpbb_posts + WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['post_subject'], $data['posts'])) + { + $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; + } + } + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php new file mode 100644 index 0000000000..4032ca5b58 --- /dev/null +++ b/tests/functions/get_remote_file_test.php @@ -0,0 +1,75 @@ +markTestSkipped(sprintf( + 'Could not find a DNS record for hostname %s. ' . + 'Assuming network is down.', + $hostname + )); + } + + $errstr = $errno = null; + $file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno); + + $this->assertNotEquals( + 0, + strlen($file), + 'Failed asserting that the response is not empty.' + ); + + $this->assertSame( + '', + $errstr, + 'Failed asserting that the error string is empty.' + ); + + $this->assertSame( + 0, + $errno, + 'Failed asserting that the error number is 0 (i.e. no error occurred).' + ); + + $lines = explode("\n", $file); + + $this->assertGreaterThanOrEqual( + 2, + sizeof($lines), + 'Failed asserting that the version file has at least two lines.' + ); + + $this->assertStringStartsWith( + '3.', + $lines[0], + "Failed asserting that the first line of the version file starts with '3.'" + ); + + $this->assertNotSame( + false, + filter_var($lines[1], FILTER_VALIDATE_URL), + 'Failed asserting that the second line of the version file is a valid URL.' + ); + + $this->assertContains('http', $lines[1]); + $this->assertContains('phpbb.com', $lines[1], '', true); + } +} diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 1ab9488568..6827aaa1b6 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -11,7 +11,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; require_once dirname(__FILE__) . '/../mock/user.php'; require_once dirname(__FILE__) . '/../mock/cache.php'; diff --git a/tests/mock/search.php b/tests/mock/search.php new file mode 100644 index 0000000000..6739719216 --- /dev/null +++ b/tests/mock/search.php @@ -0,0 +1,23 @@ +buffer)) ? true : false; + } + + public function get_buffer() + { + return $this->buffer; + } +} diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php new file mode 100644 index 0000000000..c038020385 --- /dev/null +++ b/tests/notification/convert_test.php @@ -0,0 +1,108 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/convert.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + $this->db = $this->new_dbal(); + + $this->migration = new phpbb_db_migration_data_310_notification_options_reconvert( + new phpbb_config(array()), + $this->db, + new phpbb_db_tools($this->db), + $phpbb_root_path, + $phpEx, + 'phpbb_' + ); + } + + public function test_convert() + { + $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications'); + $this->migration->perform_conversion($buffer, 'phpbb_user_notifications'); + + $expected = array_merge( + $this->create_expected('post', 1, 'email'), + $this->create_expected('topic', 1, 'email'), + + $this->create_expected('post', 2, 'email'), + $this->create_expected('topic', 2, 'email'), + $this->create_expected('pm', 2, 'email'), + + $this->create_expected('post', 3, 'jabber'), + $this->create_expected('topic', 3, 'jabber'), + + $this->create_expected('post', 4, 'jabber'), + $this->create_expected('topic', 4, 'jabber'), + $this->create_expected('pm', 4, 'jabber'), + + $this->create_expected('post', 5, 'both'), + $this->create_expected('topic', 5, 'both'), + + $this->create_expected('post', 6, 'both'), + $this->create_expected('topic', 6, 'both'), + $this->create_expected('pm', 6, 'both') + ); + + $this->assertEquals($expected, $buffer->get_buffer()); + } + + protected function create_expected($type, $user_id, $method = '') + { + $return = array(); + + if ($method !== '') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => 0, + 'user_id' => $user_id, + 'method' => '', + 'notify' => 1, + ); + } + + if ($method === 'email' || $method === 'both') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => 0, + 'user_id' => $user_id, + 'method' => 'email', + 'notify' => 1, + ); + } + + if ($method === 'jabber' || $method === 'both') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => 0, + 'user_id' => $user_id, + 'method' => 'jabber', + 'notify' => 1, + ); + } + + return $return; + } +} diff --git a/tests/notification/fixtures/convert.xml b/tests/notification/fixtures/convert.xml new file mode 100644 index 0000000000..3f0a065cc4 --- /dev/null +++ b/tests/notification/fixtures/convert.xml @@ -0,0 +1,80 @@ + + + + user_id + username + username_clean + user_notify_type + user_notify_pm + user_permissions + user_sig + user_occ + user_interests + + 1 + 1 + 1 + 0 + 0 + + + + + + + 2 + 2 + 2 + 0 + 1 + + + + + + + 3 + 3 + 3 + 1 + 0 + + + + + + + 4 + 4 + 4 + 1 + 1 + + + + + + + 5 + 5 + 5 + 2 + 0 + + + + + + + 6 + 6 + 6 + 2 + 1 + + + + + +
+
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 59daf6c9cb..4e564ce23c 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -96,6 +96,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case // Container $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); $user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index ad78d92299..e5a7f7a4a1 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -53,7 +53,20 @@ class phpbb_session_continue_test extends phpbb_database_test_case */ public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $ip, $expected_sessions, $expected_cookies, $message) { + global $phpbb_container, $phpbb_root_path, $phpEx; + $db = $this->new_dbal(); + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + + $auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container->expects($this->any()) + ->method('get') + ->with('auth.provider.db') + ->will($this->returnValue($auth_provider)); + $session_factory = new phpbb_session_testable_factory; $session_factory->set_cookies(array( '_sid' => $session_id, diff --git a/tests/session/init_test.php b/tests/session/creation_test.php similarity index 60% rename from tests/session/init_test.php rename to tests/session/creation_test.php index 830de34ed0..fde76d6b06 100644 --- a/tests/session/init_test.php +++ b/tests/session/creation_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/testable_factory.php'; -class phpbb_session_init_test extends phpbb_database_test_case +class phpbb_session_creation_test extends phpbb_database_test_case { public function getDataSet() { @@ -20,7 +20,20 @@ class phpbb_session_init_test extends phpbb_database_test_case public function test_login_session_create() { + global $phpbb_container, $phpbb_root_path, $phpEx; + $db = $this->new_dbal(); + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + + $auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container->expects($this->any()) + ->method('get') + ->with('auth.provider.db') + ->will($this->returnValue($auth_provider)); + $session_factory = new phpbb_session_testable_factory; $session = $session_factory->get_session($db); @@ -34,10 +47,11 @@ class phpbb_session_init_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('session_user_id' => 3)), $sql, - 'Check if exacly one session for user id 3 was created' + 'Check if exactly one session for user id 3 was created' ); - $cookie_expire = $session->time_now + 31536000; // default is one year + $one_year_in_seconds = 365 * 24 * 60 * 60; + $cookie_expire = $session->time_now + $one_year_in_seconds; $session->check_cookies($this, array( 'u' => array(null, $cookie_expire), diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index f1012b6939..ff7b890d11 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -15,9 +15,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case { $this->setup_engine(array('tpl_allow_php' => true)); - $cache_file = $this->template->cachepath . 'includephp_relative.html.php'; - - $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); + $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_relative.html')); $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); @@ -27,9 +25,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case { $this->setup_engine(array('tpl_allow_php' => true)); - $cache_file = $this->template->cachepath . 'includephp_variables.html.php'; - - $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php", $cache_file); + $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_variables.html')); $this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); @@ -37,11 +33,13 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case public function test_includephp_absolute() { - $path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc'; + global $phpbb_root_path; + + $path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc'; $this->assertTrue(phpbb_is_absolute($path_to_php)); $template_text = "Path is absolute.\n"; - $cache_dir = dirname($this->template->cachepath) . '/'; + $cache_dir = $phpbb_root_path . 'cache/'; $fp = fopen($cache_dir . 'includephp_absolute.html', 'w'); fputs($fp, $template_text); fclose($fp); @@ -49,9 +47,8 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->setup_engine(array('tpl_allow_php' => true)); $this->style->set_custom_style('tests', $cache_dir, array(), ''); - $cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; - $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file); + $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_absolute.html')); $this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php deleted file mode 100644 index 19d192b8b6..0000000000 --- a/tests/template/invalid_constructs_test.php +++ /dev/null @@ -1,87 +0,0 @@ -template->cachepath . str_replace('/', '.', $file) . '.php'; - - $this->assertFileNotExists($cache_file); - - $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected); - // apparently the template engine does not put - // the trailing newline into compiled templates - $expected = trim($expected); - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); - } - - /** - * @dataProvider template_data_error - */ - public function test_template_error($description, $file, $vars, $block_vars, $destroy, $error, $expected) - { - $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - - $this->assertFileNotExists($cache_file); - - $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected); - // apparently the template engine does not put - // the trailing newline into compiled templates - $expected = trim($expected); - $this->setExpectedTriggerError($error, $expected); - $this->run_template($file, $vars, $block_vars, $destroy, '', $cache_file); - } -} diff --git a/tests/template/parent_templates/parent_only.css b/tests/template/parent_templates/parent_only.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/template/renderer_eval_test.php b/tests/template/renderer_eval_test.php deleted file mode 100644 index 7ebb8b9bda..0000000000 --- a/tests/template/renderer_eval_test.php +++ /dev/null @@ -1,31 +0,0 @@ -">'; - $valid_code = ''; - $context = new phpbb_template_context(); - $template = new phpbb_template_renderer_eval($compiled_code, NULL); - ob_start(); - try - { - $template->render($context, array()); - } - catch (Exception $exception) - { - ob_end_clean(); - throw $exception; - } - $output = ob_get_clean(); - $this->assertEquals($valid_code, $output); - } -} diff --git a/tests/template/subdir/includephp_from_subdir_test.php b/tests/template/subdir/includephp_from_subdir_test.php index 517cb85a30..6f9bc1efa6 100644 --- a/tests/template/subdir/includephp_from_subdir_test.php +++ b/tests/template/subdir/includephp_from_subdir_test.php @@ -19,9 +19,7 @@ class phpbb_template_subdir_includephp_from_subdir_test extends phpbb_template_t { $this->setup_engine(array('tpl_allow_php' => true)); - $cache_file = $this->template->cachepath . 'includephp_relative.html.php'; - - $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); + $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_relative.html')); $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php deleted file mode 100644 index 7393fc1747..0000000000 --- a/tests/template/template_compile_test.php +++ /dev/null @@ -1,31 +0,0 @@ -template_compile = new phpbb_template_compile(false, null, $this->style_resource_locator, ''); - $this->template_path = dirname(__FILE__) . '/templates'; - } - - public function test_in_phpbb() - { - $output = $this->template_compile->compile_file($this->template_path . '/trivial.html'); - $this->assertTrue(strlen($output) > 0); - $statements = explode(';', $output); - $first_statement = $statements[0]; - $this->assertTrue(!!preg_match('#if.*defined.*IN_PHPBB.*exit#', $first_statement)); - } -} diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 0ac50c7f2b..f7bcd2dcc6 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -54,11 +54,9 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c array(), array(), array(), -'Kappa test event in all -Omega test event in all -Zeta test event in all -Kappa test event in silver -Omega test event in silver', +'Kappa test event in silver +Omega test event in silver +Zeta test event in all', ), array( 'Template event with inheritance - child', @@ -68,10 +66,9 @@ Omega test event in silver', array(), array(), array(), -'Kappa test event in all -Omega test event in all -Zeta test event in all -Kappa test event in silver_inherit', +'Kappa test event in silver_inherit +Omega test event in silver +Zeta test event in all', ), array( 'Definition in parent style', @@ -95,8 +92,7 @@ Kappa test event in silver_inherit', $this->setup_engine_for_events($dataset, $style_names); // Run test - $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + $this->run_template($file, $vars, $block_vars, $destroy, $expected); } protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) @@ -111,7 +107,7 @@ Kappa test event in silver_inherit', $this->extension_manager = new phpbb_mock_filesystem_extension_manager( dirname(__FILE__) . "/datasets/$dataset/" ); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); + $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager); $this->style_provider = new phpbb_style_path_provider(); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); $this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php new file mode 100644 index 0000000000..f8999ad1a9 --- /dev/null +++ b/tests/template/template_includecss_test.php @@ -0,0 +1,28 @@ +setup_engine(array('assets_version' => 1)); + + // Prepare correct result + $scripts = array( + '', + '', + ); + + // Run test + $this->run_template('includecss.html', array(), array(), array(), implode('', $scripts)); + } +} diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index 22b020208b..b67fa123a1 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -11,23 +11,93 @@ require_once dirname(__FILE__) . '/template_test_case_with_tree.php'; class phpbb_template_template_includejs_test extends phpbb_template_template_test_case_with_tree { - public function test_includejs_compilation() + public function template_data() + { + return array( + /* + array( + // vars + // expected + ), + */ + array( + array('TEST' => 1), + '', + ), + array( + array('TEST' => 2), + '', + ), + array( + array('TEST' => 3), + '', + ), + array( + array('TEST' => 4), + '', + ), + array( + array('TEST' => 6), + '', + ), + array( + array('TEST' => 7), + '', + ), + array( + array('TEST' => 8), + '', + ), + array( + array('TEST' => 9), + '', + ), + array( + array('TEST' => 10), + '', + ), + array( + array('TEST' => 11), + '', + ), + array( + array('TEST' => 12), + '', + ), + array( + array('TEST' => 14), + '', + ), + array( + array('TEST' => 15), + '', + ), + array( + array('TEST' => 16), + '', + ), + array( + array('TEST' => 17), + '', + ), + array( + array('TEST' => 18), + '', + ), + ); + } + + /** + * @dataProvider template_data + */ + public function test_includejs_compilation($vars, $expected) { // Reset the engine state $this->setup_engine(array('assets_version' => 1)); - // Prepare correct result - $scripts = array( - '', - '', - '', - '', - '', - '', - ); + $this->template->assign_vars($vars); // Run test - $cache_file = $this->template->cachepath . 'includejs.html.php'; - $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts), $cache_file); + $this->run_template('includejs.html', array_merge(array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), $vars), array(), array(), $expected); } } diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index febfed9ef0..cc71ff99e0 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -50,15 +50,6 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t */ public function test_template($name, $file, array $vars, array $block_vars, array $destroy, $expected) { - $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - - $this->assertFileNotExists($cache_file); - - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); - - // Reset the engine state - $this->setup_engine(); - - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + $this->run_template($file, $vars, $block_vars, $destroy, $expected); } } diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php deleted file mode 100644 index 851dcae8ea..0000000000 --- a/tests/template/template_locate_test.php +++ /dev/null @@ -1,68 +0,0 @@ -test_path . '/parent_templates/parent_only.html', - 'parent_only.html', - false, - true, - ), - array( - 'simple inheritance - only child template exists', - $this->test_path . '/templates/child_only.html', - 'child_only.html', - false, - true, - ), - array( - 'simple inheritance - both parent and child templates exist', - $this->test_path . '/templates/parent_and_child.html', - 'parent_and_child.html', - false, - true, - ), - array( - 'find first template - only child template exists in main style', - 'child_only.html', - array('parent_only.html', 'child_only.html'), - false, - false, - ), - array( - 'find first template - both templates exist in main style', - 'parent_and_child.html', - array('parent_and_child.html', 'child_only.html'), - false, - false, - ), - ); - } - - /** - * @dataProvider template_data - */ - public function test_template($name, $expected, $files, $return_default, $return_full_path) - { - // Reset the engine state - $this->setup_engine(); - - // Locate template - $result = $this->style_resource_locator->get_first_template_location($files, $return_default, $return_full_path); - $this->assertSame($expected, $result); - } -} diff --git a/tests/template/template_parser_test.php b/tests/template/template_parser_test.php new file mode 100644 index 0000000000..c200770adf --- /dev/null +++ b/tests/template/template_parser_test.php @@ -0,0 +1,29 @@ +template->set_filenames(array( + 'basic' => 'basic.html', + )); + + $this->assertEquals("passpasspass", str_replace(array("\n", "\r", "\t"), '', $this->template->assign_display('basic'))); + + $this->template->set_filenames(array( + 'basic' => 'if.html', + )); + + $this->assertEquals("03!false", str_replace(array("\n", "\r", "\t"), '', $this->template->assign_display('basic'))); + } +} diff --git a/tests/template/template_spacing_test.php b/tests/template/template_spacing_test.php deleted file mode 100644 index 83f8711b38..0000000000 --- a/tests/template/template_spacing_test.php +++ /dev/null @@ -1,87 +0,0 @@ - '{}', - ), - array(), - array(), - '|{}| -{}|{}| -|{} -
test
', - ), - ); - } - - /** - * @dataProvider template_data - */ - public function test_template($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) - { - // Run test - $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); - } - - /** - * @dataProvider template_data - */ - public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) - { - // Reset the engine state - $this->setup_engine_for_events($dataset, $style_names); - - // Run test - $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); - } - - protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) - { - global $phpbb_root_path, $phpEx, $user; - - $defaults = $this->config_defaults(); - $config = new phpbb_config(array_merge($defaults, $new_config)); - - $this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template"; - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->extension_manager = new phpbb_mock_filesystem_extension_manager( - dirname(__FILE__) . "/datasets/$dataset/" - ); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); - $this->style_provider = new phpbb_style_path_provider(); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); - } -} diff --git a/tests/template/template_test.php b/tests/template/template_test.php index a3c0b69123..802f0c19ba 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -46,28 +46,42 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array(), array(), - '03', + '03!false', ), array( 'if.html', array('S_VALUE' => true), array(), array(), - '1', + '1!false', ), array( 'if.html', array('S_VALUE' => true, 'S_OTHER_VALUE' => true), array(), array(), - '1', + '1!false', ), array( 'if.html', array('S_VALUE' => false, 'S_OTHER_VALUE' => true), array(), array(), - '2', + '2!false', + ), + array( + 'if.html', + array('S_TEST' => false), + array(), + array(), + '03false', + ), + array( + 'if.html', + array('S_TEST' => 0), + array(), + array(), + '03!false', ), array( 'loop.html', @@ -116,7 +130,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array(), - "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner\ninner loop", + "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner", ), array( 'loop_advanced.html', @@ -125,6 +139,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561", ), + array( + 'loop_nested2.html', + array(), + array('outer' => array(array(), array()), 'outer.middle' => array(array(), array())), + array(), + "o0o1m01m11", + ), array( 'define.html', array(), @@ -139,13 +160,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "abc\nzxc\ncde\nbcd", ), - array( - 'define_unclosed.html', - array(), - array(), - array(), - "test", - ), array( 'expressions.html', array(), @@ -247,21 +261,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array(), array(), - "{ VARIABLE }\n{ 1_VARIABLE }\n{ VARIABLE }\n{ 1_VARIABLE }", + "VARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE", ), array( 'lang.html', - array('L_VARIABLE' => "Value'", 'L_1_VARIABLE' => "1 O'Clock"), + array(), array(), array(), "Value'\n1 O'Clock\nValue\'\n1 O\'Clock", - ), - array( - 'lang.html', - array('LA_VARIABLE' => "Value'", 'LA_1_VARIABLE' => "1 O'Clock"), - array(), - array(), - "{ VARIABLE }\n{ 1_VARIABLE }\nValue'\n1 O'Clock", + array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"), ), array( 'loop_nested_multilevel_ref.html', @@ -275,7 +283,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), array(), - // I don't completely understand this output, hopefully it's correct "top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz", ), array( @@ -283,7 +290,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), array(), - // I don't completely understand this output, hopefully it's correct "top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz", ), array( @@ -303,6 +309,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case "a\nb\nc\nd", ), */ + array( + 'twig.html', + array('VARIABLE' => 'FOObar',), + array(), + array(), + "13FOOBAR|foobar", + ), ); } @@ -313,24 +326,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->template->set_filenames(array('test' => $filename)); $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); - $expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', $this->test_path . '/templates/' . $filename); - $this->setExpectedTriggerError(E_USER_ERROR, $expecting); + $this->setExpectedException('Twig_Error_Loader'); $this->display('test'); } - public function test_empty_file() - { - $expecting = 'style resource locator: set_filenames: Empty filename specified for test'; - - $this->setExpectedTriggerError(E_USER_ERROR, $expecting); - $this->template->set_filenames(array('test' => '')); - } public function test_invalid_handle() { - $expecting = 'No file specified for handle test'; - $this->setExpectedTriggerError(E_USER_ERROR, $expecting); + $this->setExpectedException('Twig_Error_Loader'); $this->display('test'); } @@ -338,49 +342,23 @@ class phpbb_template_template_test extends phpbb_template_template_test_case /** * @dataProvider template_data */ - public function test_template($file, array $vars, array $block_vars, array $destroy, $expected) + public function test_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array()) { - $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; - - $this->assertFileNotExists($cache_file); - - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); - - // Reset the engine state - $this->setup_engine(); - - $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $lang_vars); } - /** - * @dataProvider template_data - */ - public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected) + public function test_assign_display() { + $this->run_template('basic.html', array(), array(), array(), "pass\npass\npass\n"); + $this->template->set_filenames(array( - 'test' => $file, - 'container' => 'variable.html', + 'test' => 'basic.html', + 'container' => 'variable.html', )); - $this->template->assign_vars($vars); - - foreach ($block_vars as $block => $loops) - { - foreach ($loops as $_vars) - { - $this->template->assign_block_vars($block, $_vars); - } - } - - foreach ($destroy as $block) - { - $this->template->destroy_block_vars($block); - } - - $this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)"); $this->template->assign_display('test', 'VARIABLE', false); - $this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)"); + $this->assertEquals("pass\npass\npass\n", $this->display('container'), "Testing assign_display($file)"); } public function test_append_var_without_assign_var() @@ -391,7 +369,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $items = array('This ', 'is ', 'a ', 'test'); $expecting = implode('', $items); - + foreach ($items as $word) { $this->template->append_var('VARIABLE', $word); @@ -409,7 +387,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $start = 'This '; $items = array('is ', 'a ', 'test'); $expecting = $start . implode('', $items); - + $this->template->assign_var('VARIABLE', $start); foreach ($items as $word) { @@ -421,13 +399,20 @@ class phpbb_template_template_test extends phpbb_template_template_test_case public function test_php() { + global $phpbb_root_path; + + $template_text = 'echo "test";'; + + $cache_dir = $phpbb_root_path . 'cache/'; + $fp = fopen($cache_dir . 'php.html', 'w'); + fputs($fp, $template_text); + fclose($fp); + $this->setup_engine(array('tpl_allow_php' => true)); - $cache_file = $this->template->cachepath . 'php.html.php'; + $this->style->set_custom_style('tests', $cache_dir, array(), ''); - $this->assertFileNotExists($cache_file); - - $this->run_template('php.html', array(), array(), array(), 'test', $cache_file); + $this->run_template('php.html', array(), array(), array(), 'test'); } public function alter_block_array_data() @@ -533,10 +518,40 @@ EOT $this->template->assign_block_vars('outer.middle', array()); $this->template->assign_block_vars('outer.middle', array()); - $this->assertEquals("outer - 0\nmiddle - 0\nmiddle - 1\nouter - 1\nmiddle - 0\nmiddle - 1\nouter - 2\nmiddle - 0\nmiddle - 1", $this->display('test'), 'Ensuring template is built correctly before modification'); + $this->assertEquals("outer - 0middle - 0middle - 1outer - 1middle - 0middle - 1outer - 2middle - 0middle - 1", $this->display('test'), 'Ensuring template is built correctly before modification'); $this->template->alter_block_array($alter_block, $vararray, $key, $mode); - $this->assertEquals($expect, $this->display('test'), $description); + $this->assertEquals(str_replace(array("\n", "\r", "\t"), '', $expect), str_replace(array("\n", "\r", "\t"), '', $this->display('test')), $description); } + public function test_more_alter_block_array() + { + $this->template->set_filenames(array('test' => 'loop_nested.html')); + + $this->template->assign_var('TEST_MORE', true); + + // @todo Change this + $this->template->assign_block_vars('outer', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer.middle', array()); + + $expect = 'outer - 0[outer|3]middle - 0[middle|1]outer - 1[outer|3]middle - 0[middle|2]middle - 1[middle|2]outer - 2[outer|3]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification'); + + $this->template->alter_block_array('outer', array()); + + $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after insertion'); + + $this->template->alter_block_array('outer', array('VARIABLE' => 'test'), 2, 'change'); + + $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification'); + } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 3c997cb00e..6d87e5ebc0 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -16,6 +16,7 @@ class phpbb_template_template_test_case extends phpbb_test_case protected $template_path; protected $style_resource_locator; protected $style_provider; + protected $user; protected $test_path = 'tests/template'; @@ -28,11 +29,11 @@ class phpbb_template_template_test_case extends phpbb_test_case try { - $this->assertTrue($this->template->display($handle, false)); + $this->template->display($handle, false); } catch (Exception $exception) { - // reset output buffering even when an error occured + // reset output buffering even when an error occurred // PHPUnit turns trigger_error into exceptions as well ob_end_clean(); throw $exception; @@ -59,16 +60,17 @@ class phpbb_template_template_test_case extends phpbb_test_case protected function setup_engine(array $new_config = array()) { - global $phpbb_root_path, $phpEx, $user; + global $phpbb_root_path, $phpEx; $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); + $this->user = new phpbb_user; $this->template_path = $this->test_path . '/templates'; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); + $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, $this->style_provider, $this->template); $this->style->set_custom_style('tests', $this->template_path, array(), ''); } @@ -77,32 +79,18 @@ class phpbb_template_template_test_case extends phpbb_test_case // Test the engine can be used $this->setup_engine(); - $template_cache_dir = dirname($this->template->cachepath); - if (!is_writable($template_cache_dir)) - { - $this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable."); - } - - foreach (glob($this->template->cachepath . '*') as $file) - { - unlink($file); - } - - $this->setup_engine(); + $this->template->clear_cache(); } protected function tearDown() { - if (is_object($this->template)) + if ($this->template) { - foreach (glob($this->template->cachepath . '*') as $file) - { - unlink($file); - } + $this->template->clear_cache(); } } - protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file) + protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array()) { $this->template->set_filenames(array('test' => $file)); $this->template->assign_vars($vars); @@ -120,25 +108,17 @@ class phpbb_template_template_test_case extends phpbb_test_case $this->template->destroy_block_vars($block); } - try + // Previous functionality was $cachefile (string), which was removed, check to prevent errors + if (is_array($lang_vars)) { - $this->assertEquals($expected, $this->display('test'), "Testing $file"); - $this->assertFileExists($cache_file); - } - catch (ErrorException $e) - { - if (file_exists($cache_file)) + foreach ($lang_vars as $name => $value) { - copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); + $this->user->lang[$name] = $value; } - throw $e; } - // For debugging. - // When testing eval path the cache file may not exist. - if (self::PRESERVE_CACHE && file_exists($cache_file)) - { - copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); - } + $expected = str_replace(array("\n", "\r", "\t"), '', $expected); + $output = str_replace(array("\n", "\r", "\t"), '', $this->display('test')); + $this->assertEquals($expected, $output, "Testing $file"); } } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 7585be5728..4b8cbada45 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $this->parent_template_path = $this->test_path . '/parent_templates'; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); + $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context()); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), ''); } diff --git a/tests/template/templates/child_only.css b/tests/template/templates/child_only.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/template/templates/define_unclosed.html b/tests/template/templates/define_unclosed.html deleted file mode 100644 index 1c975eab2b..0000000000 --- a/tests/template/templates/define_unclosed.html +++ /dev/null @@ -1,2 +0,0 @@ - -test diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html index eed431019e..c010aff7fa 100644 --- a/tests/template/templates/if.html +++ b/tests/template/templates/if.html @@ -9,3 +9,11 @@ 04 + + +false + + + +!false + diff --git a/tests/template/templates/includecss.html b/tests/template/templates/includecss.html new file mode 100644 index 0000000000..a09e44f240 --- /dev/null +++ b/tests/template/templates/includecss.html @@ -0,0 +1,3 @@ + + +{$STYLESHEETS} diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html index ef73700eeb..0bcdf1a815 100644 --- a/tests/template/templates/includejs.html +++ b/tests/template/templates/includejs.html @@ -1,8 +1,36 @@ - - - - - - - -{SCRIPTS} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{$SCRIPTS} diff --git a/tests/template/templates/invalid/include_nonexistent_file.html b/tests/template/templates/invalid/include_nonexistent_file.html deleted file mode 100644 index 617d2fdaaa..0000000000 --- a/tests/template/templates/invalid/include_nonexistent_file.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/template/templates/invalid/unknown_tag.html b/tests/template/templates/invalid/unknown_tag.html deleted file mode 100644 index 1489e5e31a..0000000000 --- a/tests/template/templates/invalid/unknown_tag.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/template/templates/loop_nested.html b/tests/template/templates/loop_nested.html index 45b1ef85d4..cf099ecc15 100644 --- a/tests/template/templates/loop_nested.html +++ b/tests/template/templates/loop_nested.html @@ -1,6 +1,6 @@ - outer - {outer.S_ROW_COUNT} - {outer.VARIABLE} - - middle - {middle.S_ROW_COUNT} - {middle.VARIABLE} - +outer - {outer.S_ROW_COUNT} - {outer.VARIABLE}[{outer.S_BLOCK_NAME}|{outer.S_NUM_ROWS}] + +middle - {outer.middle.S_ROW_COUNT} - {outer.middle.VARIABLE}[{outer.middle.S_BLOCK_NAME}|{outer.middle.S_NUM_ROWS}] + diff --git a/tests/template/templates/loop_nested2.html b/tests/template/templates/loop_nested2.html new file mode 100644 index 0000000000..3eeeb5e36a --- /dev/null +++ b/tests/template/templates/loop_nested2.html @@ -0,0 +1,6 @@ + +o{outer.S_ROW_COUNT} + +m{outer.middle.S_ROW_COUNT}{outer.S_ROW_COUNT} + + diff --git a/tests/template/templates/loop_size.html b/tests/template/templates/loop_size.html index f1938441df..8f581cef10 100644 --- a/tests/template/templates/loop_size.html +++ b/tests/template/templates/loop_size.html @@ -36,4 +36,4 @@ in loop - + diff --git a/tests/template/templates/loop_underscore.html b/tests/template/templates/loop_underscore.html index dafce5dea6..4001007868 100644 --- a/tests/template/templates/loop_underscore.html +++ b/tests/template/templates/loop_underscore.html @@ -2,7 +2,7 @@ loop noloop - + loop diff --git a/tests/template/templates/loop_vars.html b/tests/template/templates/loop_vars.html index d94a0ae0f7..7d86d4b7b6 100644 --- a/tests/template/templates/loop_vars.html +++ b/tests/template/templates/loop_vars.html @@ -11,4 +11,3 @@ last last inner -inner loop diff --git a/tests/template/templates/twig.html b/tests/template/templates/twig.html new file mode 100644 index 0000000000..17b94ad8d4 --- /dev/null +++ b/tests/template/templates/twig.html @@ -0,0 +1,6 @@ + + + +3{VARIABLE|upper}|{VARIABLE|lower} + + diff --git a/tests/template/templates/twig_parent.html b/tests/template/templates/twig_parent.html new file mode 100644 index 0000000000..e9863221e1 --- /dev/null +++ b/tests/template/templates/twig_parent.html @@ -0,0 +1,7 @@ + +1 + + + +2 + diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 97fe147d8e..ed307c3ce2 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -219,15 +219,19 @@ class phpbb_functional_test_case extends phpbb_test_case self::recreate_database(self::$config); - if (file_exists($phpbb_root_path . "config.$phpEx")) + $config_file = $phpbb_root_path . "config.$phpEx"; + $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; + $config_file_test = $phpbb_root_path . "config_test.$phpEx"; + + if (file_exists($config_file)) { - if (!file_exists($phpbb_root_path . "config_dev.$phpEx")) + if (!file_exists($config_file_dev)) { - rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx"); + rename($config_file, $config_file_dev); } else { - unlink($phpbb_root_path . "config.$phpEx"); + unlink($config_file); } } @@ -251,10 +255,12 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=requirements $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Database configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -268,10 +274,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -282,16 +290,38 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email' => 'nobody@example.com', )); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::submit($form); - self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, true)); - $form = $crawler->selectButton('submit')->form(); + // We have to skip install/index.php?mode=install&sub=config_file + // because that step will create a config.php file if phpBB has the + // permission to do so. We have to create the config file on our own + // in order to get the DEBUG constants defined. + $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, true); + $config_created = file_put_contents($config_file, $config_php_data) !== false; + if (!$config_created) + { + self::markTestSkipped("Could not write $config_file file."); + } - $crawler = self::submit($form); + // We also have to create a install lock that is normally created by + // the installer. The file will be removed by the final step of the + // installer. + $install_lock_file = $phpbb_root_path . 'cache/install_lock'; + $lock_created = file_put_contents($install_lock_file, '') !== false; + if (!$lock_created) + { + self::markTestSkipped("Could not create $lock_created file."); + } + @chmod($install_lock_file, 0666); + + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); + + $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data); self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'email_enable' => true, @@ -308,14 +338,17 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); + // install/index.php?mode=install&sub=create_table $crawler = self::submit($form); self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=final $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); - copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); + + copy($config_file, $config_file_test); } static private function recreate_database($config) @@ -324,6 +357,109 @@ class phpbb_functional_test_case extends phpbb_test_case $db_conn_mgr->recreate_db(); } + /** + * Creates a new style + * + * @param string $style_id Style ID + * @param string $style_path Style directory + * @param string $parent_style_id Parent style id. Default = 1 + * @param string $parent_style_path Parent style directory. Default = 'prosilver' + */ + protected function add_style($style_id, $style_path, $parent_style_id = 1, $parent_style_path = 'prosilver') + { + global $phpbb_root_path; + + $db = $this->get_db(); + if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) + { + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'template_id' => $style_id, + 'theme_id' => $style_id, + 'imageset_id' => $style_id, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'imageset_id' => $style_id, + 'imageset_name' => $style_path, + 'imageset_copyright' => '', + 'imageset_path' => $style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'template_id' => $style_id, + 'template_name' => $style_path, + 'template_copyright' => '', + 'template_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'template_inherits_id' => $parent_style_id, + 'template_inherit_path' => $parent_style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'theme_id' => $style_id, + 'theme_name' => $style_path, + 'theme_copyright' => '', + 'theme_path' => $style_path, + 'theme_storedb' => 0, + 'theme_mtime' => 0, + 'theme_data' => '', + )); + $db->sql_query($sql); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); + @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); + } + } + else + { + $db->sql_multi_insert(STYLES_TABLE, array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'style_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => $parent_style_id, + 'style_parent_tree' => $parent_style_path, + )); + } + } + + /** + * Remove temporary style created by add_style() + * + * @param string $style_id Style ID + * @param string $style_path Style directory + */ + protected function delete_style($style_id, $style_path) + { + global $phpbb_root_path; + + $db = $this->get_db(); + $db->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $style_id); + if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) + { + $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); + @rmdir($phpbb_root_path . 'styles/' . $style_path); + } + } + } + /** * Creates a new user with limited permissions * @@ -474,7 +610,7 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton($this->lang('LOGIN'))->form(); $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); - $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); + $this->assertNotContains($this->lang('LOGIN'), $crawler->filter('.navbar')->text()); $cookies = self::$cookieJar->all(); @@ -493,7 +629,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->add_lang('ucp'); $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); + $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); unset($this->sid); } @@ -523,7 +659,7 @@ class phpbb_functional_test_case extends phpbb_test_case if (strpos($field, 'password_') === 0) { $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); - $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); + $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); $cookies = self::$cookieJar->all(); @@ -607,6 +743,7 @@ class phpbb_functional_test_case extends phpbb_test_case // Any output before the doc type means there was an error $content = self::$client->getResponse()->getContent(); + self::assertNotContains('[phpBB Debug]', $content); self::assertStringStartsWith('sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_TOPIC', $form_data); + } + + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param int $topic_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->add_lang('posting'); + + $crawler = self::request('GET', $posting_url); + $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = self::request('POST', $posting_url, $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + + return array( + 'topic_id' => $this->get_parameter_from_link($url, 't'), + 'post_id' => $this->get_parameter_from_link($url, 'p'), + ); + } + + /* + * Returns the requested parameter from a URL + * + * @param string $url + * @param string $parameter + * @return string Value of the parameter in the URL, null if not set + */ + public function get_parameter_from_link($url, $parameter) + { + if (strpos($url, '?') === false) + { + return null; + } + + $url_parts = explode('?', $url); + if (isset($url_parts[1])) + { + $url_parameters = $url_parts[1]; + if (strpos($url_parameters, '#') !== false) + { + $url_parameters = explode('#', $url_parameters); + $url_parameters = $url_parameters[0]; + } + + foreach (explode('&', $url_parameters) as $url_param) + { + list($param, $value) = explode('=', $url_param); + if ($param == $parameter) + { + return $value; + } + } + } + return null; + } } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 50b2bf03ec..3d9cd10f32 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -94,6 +94,9 @@ class phpbb_test_case_helpers public function makedirs($path) { + // PHP bug #55124 (fixed in 5.4.0) + $path = str_replace('/./', '/', $path); + mkdir($path, 0777, true); } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 1665c493be..8b9df33a63 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -10,6 +10,7 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; +require_once __DIR__ . '/../mock/filespec.php'; class phpbb_fileupload_test extends phpbb_test_case { diff --git a/travis/phpunit-mysql-travis.xml b/travis/phpunit-mysql-travis.xml index 2d6af0e2ac..715e66c223 100644 --- a/travis/phpunit-mysql-travis.xml +++ b/travis/phpunit-mysql-travis.xml @@ -15,6 +15,10 @@ ../tests/ tests/functional + tests/lint_test.php + + + tests/lint_test.php ../tests/functional diff --git a/travis/phpunit-postgres-travis.xml b/travis/phpunit-postgres-travis.xml index a9062efafb..9f281b4c21 100644 --- a/travis/phpunit-postgres-travis.xml +++ b/travis/phpunit-postgres-travis.xml @@ -15,6 +15,10 @@ ../tests/ tests/functional + tests/lint_test.php + + + tests/lint_test.php ../tests/functional