Skip to content

Commit 40ce376

Browse files
authored
Merge pull request #278 from iMattPro/tweaks
Fix phpBB 4 issues plus updates
2 parents 7c802a7 + 8df4a1c commit 40ce376

16 files changed

+132
-110
lines changed

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/functions_install.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class module
4747

4848
function get_db_tools($db)
4949
{
50-
if (defined('PHPBB_40'))
50+
if (qi::phpbb_branch('4.0'))
5151
{
5252
$factory = new \phpbb\db\tools\factory();
5353
return $factory->get(get_db_doctrine());
5454
}
5555

56-
if (defined('PHPBB_32'))
56+
if (qi::phpbb_branch('3.2'))
5757
{
5858
$factory = new \phpbb\db\tools\factory();
5959
return $factory->get($db);
@@ -64,7 +64,7 @@ function get_db_tools($db)
6464

6565
function load_schema($install_path = '', $install_dbms = false)
6666
{
67-
if (defined('PHPBB_31'))
67+
if (qi::phpbb_branch('3.1'))
6868
{
6969
load_schema_31($install_path, $install_dbms);
7070
}
@@ -142,7 +142,7 @@ function load_schema_31($install_path = '', $install_dbms = false)
142142
include($phpbb_root_path . 'includes/constants.' . $phpEx);
143143
}
144144

145-
if (defined('PHPBB_40'))
145+
if (qi::phpbb_branch('4.0'))
146146
{
147147
$finder = new \phpbb\finder\finder(null, true, $phpbb_root_path, $phpEx);
148148
}
@@ -166,7 +166,7 @@ function load_schema_31($install_path = '', $install_dbms = false)
166166
$db_tools = get_db_tools($sqlite_db);
167167

168168
$args = array($classes, new \phpbb\config\config(array()), $sqlite_db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);
169-
if (defined('PHPBB_40'))
169+
if (qi::phpbb_branch('4.0'))
170170
{
171171
$tables_data = \Symfony\Component\Yaml\Yaml::parseFile($phpbb_root_path . '/config/default/container/tables.yml');
172172
$tables = [];
@@ -257,7 +257,7 @@ function load_schema_30($install_path = '', $install_dbms = false)
257257
$install_dbms = $dbms;
258258
}
259259

260-
if (!function_exists('get_available_dbms') && !defined('PHPBB_32'))
260+
if (!function_exists('get_available_dbms') && !qi::phpbb_branch('3.2'))
261261
{
262262
global $phpbb_root_path, $phpEx;
263263
include($phpbb_root_path . 'includes/functions_install.' . $phpEx);
@@ -335,7 +335,7 @@ function load_schema_30($install_path = '', $install_dbms = false)
335335

336336
function qi_split_sql_file($sql, $delimiter)
337337
{
338-
if (defined('PHPBB_32'))
338+
if (qi::phpbb_branch('3.2'))
339339
{
340340
global $phpbb_root_path;
341341
$database = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
@@ -349,7 +349,7 @@ function qi_split_sql_file($sql, $delimiter)
349349

350350
function qi_remove_comments($input)
351351
{
352-
if (defined('PHPBB_32'))
352+
if (qi::phpbb_branch('3.2'))
353353
{
354354
global $phpbb_root_path;
355355
$database = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path);

includes/qi.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class qi
1515
/** @var string The prefix name of phpBB board cookies */
1616
const PHPBB_COOKIE_PREFIX = 'phpbb3_';
1717

18+
/** @var array The list of phpbb branches supported by the loaded source board */
19+
private static $branchCache = [];
20+
1821
/**
1922
* Output the standard page header
2023
*/
@@ -897,11 +900,28 @@ public static function php_phpbb_incompatible($phpbb_version = '')
897900
}
898901

899902
return
900-
(PHP_VERSION_ID >= 70000 && !defined('PHPBB_32')) ||
903+
(PHP_VERSION_ID >= 70000 && !self::phpbb_branch('3.2')) ||
901904
(PHP_VERSION_ID >= 70200 && self::phpbb_version_compare(PHPBB_VERSION, '3.2.2', '<')) ||
902-
(PHP_VERSION_ID >= 70300 && !defined('PHPBB_33')) ||
903-
(PHP_VERSION_ID < 70103 && defined('PHPBB_33')) ||
904-
(PHP_VERSION_ID < 70300 && defined('PHPBB_40'))
905+
(PHP_VERSION_ID >= 70300 && !self::phpbb_branch('3.3')) ||
906+
(PHP_VERSION_ID < 70103 && self::phpbb_branch('3.3')) ||
907+
(PHP_VERSION_ID < 70300 && self::phpbb_branch('4.0'))
905908
;
906909
}
910+
911+
/**
912+
* Is the given phpBB branch defined?
913+
*
914+
* @param string $branch '3.0', '3.1', '3.2', '3.3', '4.0'
915+
* @return bool
916+
*/
917+
public static function phpbb_branch($branch)
918+
{
919+
// Remove any dots from the branch number
920+
$branch = str_replace('.', '', $branch);
921+
922+
if (!isset(self::$branchCache[$branch])) {
923+
self::$branchCache[$branch] = defined('PHPBB_' . $branch);
924+
}
925+
return self::$branchCache[$branch];
926+
}
907927
}

includes/qi_functions.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ function db_connect($db_data = '')
491491
}
492492

493493
// Instantiate the database
494-
if (defined('PHPBB_31'))
494+
if (qi::phpbb_branch('3.1'))
495495
{
496496
$dbal = substr($available_dbms[$dbms]['DRIVER'], strrpos($available_dbms[$dbms]['DRIVER'], '\\') + 1);
497497
// Load the appropriate database class if not already loaded.
@@ -517,7 +517,7 @@ function db_connect($db_data = '')
517517
$sql_db = 'dbal_' . $dbal . '_qi';
518518
$db = new $sql_db();
519519

520-
if (defined('PHPBB_31'))
520+
if (qi::phpbb_branch('3.1'))
521521
{
522522
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
523523
}
@@ -578,7 +578,7 @@ function get_db_doctrine()
578578

579579
function qi_get_available_dbms($dbms)
580580
{
581-
if (defined('PHPBB_32'))
581+
if (qi::phpbb_branch('3.2'))
582582
{
583583
global $phpbb_root_path;
584584
$database = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
@@ -590,22 +590,22 @@ function qi_get_available_dbms($dbms)
590590

591591
function qi_get_phpbb_version()
592592
{
593-
if (defined('PHPBB_40'))
593+
if (qi::phpbb_branch('4.0'))
594594
{
595595
return '4.0';
596596
}
597597

598-
if (defined('PHPBB_33'))
598+
if (qi::phpbb_branch('3.3'))
599599
{
600600
return '3.3';
601601
}
602602

603-
if (defined('PHPBB_32'))
603+
if (qi::phpbb_branch('3.2'))
604604
{
605605
return '3.2';
606606
}
607607

608-
if (defined('PHPBB_31'))
608+
if (qi::phpbb_branch('3.1'))
609609
{
610610
return '3.1';
611611
}

includes/qi_populate.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private function fill_forums()
315315
'topic_title' => qi::lang('TEST_TOPIC_TITLE', $topic_cnt),
316316
);
317317

318-
if (defined('PHPBB_31'))
318+
if (qi::phpbb_branch('3.1'))
319319
{
320320
$topic_arr['topic_posts_approved'] = 1;
321321

@@ -361,10 +361,10 @@ private function fill_forums()
361361
'post_text' => $post_text,
362362
'post_checksum' => md5($post_text),
363363
'bbcode_bitfield' => $bbcode_bitfield,
364-
'bbcode_uid' => defined('PHPBB_32') ? gen_rand_string() : $bbcode_uid,
364+
'bbcode_uid' => qi::phpbb_branch('3.2') ? gen_rand_string() : $bbcode_uid,
365365
);
366366

367-
if (defined('PHPBB_31'))
367+
if (qi::phpbb_branch('3.1'))
368368
{
369369
$sql_posts[count($sql_posts) - 1]['post_visibility'] = ITEM_APPROVED;
370370
}
@@ -377,14 +377,14 @@ private function fill_forums()
377377
$topic_arr['topic_time'] = $post_time;
378378
$topic_arr['topic_poster'] = $poster_arr['user_id'];
379379

380-
if (defined('PHPBB_31'))
380+
if (qi::phpbb_branch('3.1'))
381381
{
382382
$topic_arr['topic_visibility'] = ITEM_APPROVED;
383383
}
384384
}
385385
else
386386
{
387-
if (defined('PHPBB_31'))
387+
if (qi::phpbb_branch('3.1'))
388388
{
389389
$topic_arr['topic_posts_approved']++;
390390
$forum['forum_posts_approved']++;
@@ -435,8 +435,8 @@ private function fill_forums()
435435
}
436436

437437
$sql_ary = array(
438-
'forum_posts' . (defined('PHPBB_31') ? '_approved' : '' ) => $forum['forum_posts' . (defined('PHPBB_31') ? '_approved' : '' )],
439-
'forum_topics' . (defined('PHPBB_31') ? '_approved' : '' ) => $forum['forum_topics' . (defined('PHPBB_31') ? '_approved' : '' )],
438+
'forum_posts' . (qi::phpbb_branch('3.1') ? '_approved' : '' ) => $forum['forum_posts' . (qi::phpbb_branch('3.1') ? '_approved' : '' )],
439+
'forum_topics' . (qi::phpbb_branch('3.1') ? '_approved' : '' ) => $forum['forum_topics' . (qi::phpbb_branch('3.1') ? '_approved' : '' )],
440440
'forum_last_post_id' => $forum['forum_last_post_id'],
441441
'forum_last_poster_id' => $forum['forum_last_poster_id'],
442442
'forum_last_post_subject' => $forum['forum_last_post_subject'],
@@ -445,7 +445,7 @@ private function fill_forums()
445445
'forum_last_poster_colour' => '',
446446
);
447447

448-
if (!defined('PHPBB_31'))
448+
if (!qi::phpbb_branch('3.1'))
449449
{
450450
$sql_ary['forum_topics_real'] = $forum['forum_topics_real'];
451451
}
@@ -609,7 +609,7 @@ private function _create_forums($forum_type, $cnt, $acp_forums, $parent_id = 0)
609609
'forum_last_poster_name' => '',
610610
);
611611

612-
if (defined('PHPBB_31'))
612+
if (qi::phpbb_branch('3.1'))
613613
{
614614
$this->forum_arr[$forum_data['forum_id']]['forum_posts_approved'] = 0;
615615
$this->forum_arr[$forum_data['forum_id']]['forum_topics_approved'] = 0;
@@ -633,7 +633,7 @@ private function save_users()
633633
global $db, $db_tools, $config, $settings;
634634

635635
// Hash the password.
636-
if (defined('PHPBB_31'))
636+
if (qi::phpbb_branch('3.1'))
637637
{
638638
global $passwords_manager;
639639
$password = $passwords_manager->hash('123456');
@@ -652,7 +652,7 @@ private function save_users()
652652
$chunk_cnt = 0;
653653
$sql_ary = array();
654654

655-
if (!defined('PHPBB_31'))
655+
if (!qi::phpbb_branch('3.1'))
656656
{
657657
$tz = new DateTimeZone($settings->get_config('qi_tz', ''));
658658
$tz_ary = $tz->getTransitions(time());
@@ -664,7 +664,7 @@ private function save_users()
664664
foreach ($this->user_arr as $user)
665665
{
666666
$email = $user['username_clean'] . $this->email_domain;
667-
$sql_ary[] = array(
667+
$sql_ary[] = array_merge([
668668
'user_id' => $user['user_id'],
669669
'username' => $user['username'],
670670
'username_clean' => $user['username_clean'],
@@ -684,13 +684,15 @@ private function save_users()
684684
'user_passchg' => $user['user_passchg'],
685685
'user_options' => 230271,
686686
'user_full_folder' => PRIVMSGS_NO_BOX,
687-
'user_notify_type' => NOTIFY_EMAIL,
688687
'user_dateformat' => 'M jS, ’y, H:i',
689688
'user_sig' => '',
689+
], !qi::phpbb_branch('4.0') ?
690+
['user_notify_type' => defined('NOTIFY_EMAIL') ? NOTIFY_EMAIL : 0] :
691+
[]
690692
);
691693

692694
$count = count($sql_ary) - 1;
693-
if (defined('PHPBB_31'))
695+
if (qi::phpbb_branch('3.1'))
694696
{
695697
$sql_ary[$count]['user_timezone'] = $settings->get_config('qi_tz', '');
696698
}
@@ -703,7 +705,7 @@ private function save_users()
703705
$sql_ary[$count]['user_dst'] = $qi_dst;
704706
}
705707

706-
if (!defined('PHPBB_33') || $db_tools->sql_column_exists(USERS_TABLE, 'user_email_hash'))
708+
if (!qi::phpbb_branch('3.3') || $db_tools->sql_column_exists(USERS_TABLE, 'user_email_hash'))
707709
{
708710
$sql_ary[$count]['user_email_hash'] = phpbb_email_hash($email);
709711
}
@@ -780,7 +782,7 @@ private function get_default_forums()
780782

781783
// We are the only ones messing with this database so far.
782784
// So the latest user_id + 1 should be the user id for the first test user.
783-
$sql = 'SELECT forum_id, parent_id, forum_type, forum_posts' . (defined('PHPBB_31') ? '_approved' : '' ) . ', forum_topics' . (defined('PHPBB_31') ? '_approved' : ', forum_topics_real' ) . ', forum_last_post_id, forum_last_poster_id, forum_last_post_subject, forum_last_post_time, forum_last_poster_name FROM ' . FORUMS_TABLE;
785+
$sql = 'SELECT forum_id, parent_id, forum_type, forum_posts' . (qi::phpbb_branch('3.1') ? '_approved' : '' ) . ', forum_topics' . (qi::phpbb_branch('3.1') ? '_approved' : ', forum_topics_real' ) . ', forum_last_post_id, forum_last_poster_id, forum_last_post_subject, forum_last_post_time, forum_last_poster_name FROM ' . FORUMS_TABLE;
784786
$result = $db->sql_query($sql);
785787

786788
while ($row = $db->sql_fetchrow($result))
@@ -795,16 +797,16 @@ private function get_default_forums()
795797
$this->forum_arr[$row['forum_id']] = array(
796798
'forum_id' => $row['forum_id'],
797799
'parent_id' => $row['parent_id'],
798-
'forum_posts' . (defined('PHPBB_31') ? '_approved' : '' ) => $row['forum_posts' . (defined('PHPBB_31') ? '_approved' : '' )],
799-
'forum_topics' . (defined('PHPBB_31') ? '_approved' : '' ) => $row['forum_topics' . (defined('PHPBB_31') ? '_approved' : '' )],
800+
'forum_posts' . (qi::phpbb_branch('3.1') ? '_approved' : '' ) => $row['forum_posts' . (qi::phpbb_branch('3.1') ? '_approved' : '' )],
801+
'forum_topics' . (qi::phpbb_branch('3.1') ? '_approved' : '' ) => $row['forum_topics' . (qi::phpbb_branch('3.1') ? '_approved' : '' )],
800802
'forum_last_post_id' => $row['forum_last_post_id'],
801803
'forum_last_poster_id' => $row['forum_last_poster_id'],
802804
'forum_last_post_subject' => $row['forum_last_post_subject'],
803805
'forum_last_post_time' => $row['forum_last_post_time'],
804806
'forum_last_poster_name' => $row['forum_last_poster_name'],
805807
);
806808

807-
if (!defined('PHPBB_31'))
809+
if (!qi::phpbb_branch('3.1'))
808810
{
809811
$this->forum_arr[$row['forum_id']]['forum_topics_real'] = $row['forum_topics_real'];
810812
}

index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@
157157

158158
require($phpbb_root_path . 'includes/constants.' . $phpEx);
159159

160-
if (!defined('PHPBB_32'))
160+
if (!qi::phpbb_branch('3.2'))
161161
{
162162
require($phpbb_root_path . 'includes/functions_install.' . $phpEx);
163163
}
164164

165-
if (defined('PHPBB_31'))
165+
if (qi::phpbb_branch('3.1'))
166166
{
167-
if (defined('PHPBB_32'))
167+
if (qi::phpbb_branch('3.2'))
168168
{
169169
$cache_dir = $quickinstall_path . $settings->get_config('cache_dir', '');
170170
$cache = new \phpbb\cache\driver\file($cache_dir);
@@ -221,7 +221,7 @@
221221
$errors = $settings->get_errors();
222222

223223
// Set some standard variables we want to force
224-
if (defined('PHPBB_31'))
224+
if (qi::phpbb_branch('3.1'))
225225
{
226226
$config = new \phpbb\config\config(array(
227227
'load_tplcompile' => '1',

0 commit comments

Comments
 (0)