From f3be40fd722c621e5d73e69be581b6684986c358 Mon Sep 17 00:00:00 2001
From: Marc Alexander
Date: Sat, 6 Jun 2015 14:47:35 +0200
Subject: [PATCH 1/9] [ticket/571] Intval more variables and improve code
quality
B3P-571
---
acp/portal_module.php | 2 +-
includes/functions.php | 18 +++++++--------
migrations/v210_beta1.php | 6 +++--
modules/poll.php | 36 ++++++++++++++++-------------
modules/random_member.php | 2 +-
modules/user_menu.php | 2 +-
modules/whois_online.php | 4 ++--
portal/modules/database_handler.php | 18 +++++++--------
portal/modules/manager.php | 4 ++--
9 files changed, 49 insertions(+), 43 deletions(-)
diff --git a/acp/portal_module.php b/acp/portal_module.php
index eb7ed658..b1ab4060 100644
--- a/acp/portal_module.php
+++ b/acp/portal_module.php
@@ -470,7 +470,7 @@ class portal_module
$sql = 'SELECT module_order
FROM ' . PORTAL_MODULES_TABLE . '
- WHERE module_column = ' . $add_column . '
+ WHERE module_column = ' . (int) $add_column . '
ORDER BY module_order DESC';
$result = $this->db->sql_query_limit($sql, 1);
$module_order = 1 + (int) $this->db->sql_fetchfield('module_order');
diff --git a/includes/functions.php b/includes/functions.php
index 7cb51633..81001e34 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -312,9 +312,9 @@ function get_portal_tracking_info($fetch_news)
$mark_time = array();
$sql = 'SELECT topic_id, mark_time
- FROM ' . TOPICS_TRACK_TABLE . "
- WHERE user_id = {$user->data['user_id']}
- AND " . $db->sql_in_set('topic_id', $current_forum);
+ FROM ' . TOPICS_TRACK_TABLE . '
+ WHERE user_id = ' . (int) $user->data['user_id'] . '
+ AND ' . $db->sql_in_set('topic_id', $current_forum);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -328,9 +328,9 @@ function get_portal_tracking_info($fetch_news)
if (sizeof($topic_ids))
{
$sql = 'SELECT forum_id, mark_time
- FROM ' . FORUMS_TRACK_TABLE . "
- WHERE user_id = {$user->data['user_id']}
- AND " . $db->sql_in_set('forum_id', $forum_ids);
+ FROM ' . FORUMS_TRACK_TABLE . '
+ WHERE user_id = ' . (int) $user->data['user_id'] . '
+ AND ' . $db->sql_in_set('forum_id', $forum_ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -339,10 +339,10 @@ function get_portal_tracking_info($fetch_news)
}
$db->sql_freeresult($result);
- // @todo: do not use $current_forum here as this is already used by the outside foreach
- foreach ($forum_ids as $current_forum)
+ // Set user last mark time
+ foreach ($forum_ids as $current_forum_id)
{
- $user_lastmark[$current_forum] = (isset($mark_time[$current_forum])) ? $mark_time[$current_forum] : $user->data['user_lastmark'];
+ $user_lastmark[$current_forum_id] = (isset($mark_time[$current_forum_id])) ? $mark_time[$current_forum_id] : $user->data['user_lastmark'];
}
// @todo: also check if $user_lastmark has been defined for this specific forum_id
diff --git a/migrations/v210_beta1.php b/migrations/v210_beta1.php
index ecc7768c..e20c01e9 100644
--- a/migrations/v210_beta1.php
+++ b/migrations/v210_beta1.php
@@ -180,7 +180,8 @@ class v210_beta1 extends \phpbb\db\migration\migration
{
if ($this->db_tools->sql_table_exists($this->table_prefix . 'portal_config'))
{
- $sql = 'SELECT * FROM ' . $this->table_prefix . 'portal_config';
+ $sql = 'SELECT *
+ FROM ' . $this->table_prefix . 'portal_config';
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
@@ -198,7 +199,8 @@ class v210_beta1 extends \phpbb\db\migration\migration
$in_ary = array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA');
$groups_ary = array();
- $sql = 'SELECT group_id, group_name FROM ' . $this->table_prefix . 'groups
+ $sql = 'SELECT group_id, group_name
+ FROM ' . $this->table_prefix . 'groups
WHERE ' . $this->db->sql_in_set('group_name', $in_ary);
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
diff --git a/modules/poll.php b/modules/poll.php
index 5efb59f3..91b44285 100644
--- a/modules/poll.php
+++ b/modules/poll.php
@@ -199,8 +199,8 @@ class poll extends module_base
{
$sql = 'SELECT poll_option_id
FROM ' . POLL_VOTES_TABLE . '
- WHERE topic_id = ' . $up_topic_id . '
- AND vote_user_id = ' . $this->user->data['user_id'];
+ WHERE topic_id = ' . (int) $up_topic_id . '
+ AND vote_user_id = ' . (int) $this->user->data['user_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
@@ -222,8 +222,10 @@ class poll extends module_base
}
$sql = 'SELECT t.poll_length, t.poll_start, t.poll_vote_change, t.topic_status, f.forum_status, t.poll_max_options
- FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
- WHERE t.forum_id = f.forum_id AND t.topic_id = " . (int) $up_topic_id . " AND t.forum_id = " . (int) $up_forum_id;
+ FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
+ WHERE t.forum_id = f.forum_id
+ AND t.topic_id = " . (int) $up_topic_id . "
+ AND t.forum_id = " . (int) $up_forum_id;
$result = $this->db->sql_query_limit($sql, 1);
$topic_data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
@@ -312,8 +314,8 @@ class poll extends module_base
}
$sql = 'UPDATE ' . TOPICS_TABLE . '
- SET poll_last_vote = ' . time() . "
- WHERE topic_id = $up_topic_id";
+ SET poll_last_vote = ' . time() . '
+ WHERE topic_id = ' . (int) $up_topic_id;
//, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
$this->db->sql_query($sql);
@@ -351,7 +353,7 @@ class poll extends module_base
if ($this->config['board3_poll_hide_' . $module_id])
{
- $portal_poll_hide = "AND (t.poll_start + t.poll_length > ". time() ." OR t.poll_length = 0)";
+ $portal_poll_hide = 'AND (t.poll_start + t.poll_length > ' . time() . ' OR t.poll_length = 0)';
}
else
{
@@ -362,13 +364,15 @@ class poll extends module_base
{
$sql = 'SELECT t.poll_title, t.poll_start, t.topic_id, t.topic_first_post_id, t.forum_id, t.poll_length, t.poll_vote_change, t.poll_max_options, t.topic_status, f.forum_status, p.bbcode_bitfield, p.bbcode_uid
- FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . " f
- WHERE t.forum_id = f.forum_id AND t.topic_visibility = 1 AND t.poll_start > 0
+ FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . " f
+ WHERE t.forum_id = f.forum_id
+ AND t.topic_visibility = 1
+ AND t.poll_start > 0
{$where}
AND t.topic_moved_id = 0
AND p.post_id = t.topic_first_post_id
{$portal_poll_hide}
- ORDER BY t.poll_start DESC";
+ ORDER BY t.poll_start DESC";
$limit = (isset($this->config['board3_poll_limit_' . $module_id])) ? $this->config['board3_poll_limit_' . $module_id] : 3;
$result = $this->db->sql_query_limit($sql, $limit);
$has_poll = false;
@@ -390,8 +394,8 @@ class poll extends module_base
{
$vote_sql = 'SELECT poll_option_id
FROM ' . POLL_VOTES_TABLE . '
- WHERE topic_id = ' . $topic_id . '
- AND vote_user_id = ' . $this->user->data['user_id'];
+ WHERE topic_id = ' . (int) $topic_id . '
+ AND vote_user_id = ' . (int) $this->user->data['user_id'];
$vote_result = $this->db->sql_query($vote_sql);
while ($row = $this->db->sql_fetchrow($vote_result))
@@ -426,9 +430,9 @@ class poll extends module_base
$s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || ($view == 'viewpoll' && in_array($topic_id, $poll_view_ar))) ? true : false;
$poll_sql = 'SELECT po.poll_option_id, po.poll_option_text, po.poll_option_total
- FROM ' . POLL_OPTIONS_TABLE . " po
- WHERE po.topic_id = {$topic_id}
- ORDER BY po.poll_option_id";
+ FROM ' . POLL_OPTIONS_TABLE . ' po
+ WHERE po.topic_id = ' . (int) $topic_id .'
+ ORDER BY po.poll_option_id';
$poll_result = $this->db->sql_query($poll_sql);
$poll_total_votes = 0;
@@ -483,7 +487,7 @@ class poll extends module_base
$this->template->assign_block_vars(($type !== '') ? 'poll_' . $type : 'poll', array(
'S_POLL_HAS_OPTIONS' => $poll_has_options,
'POLL_QUESTION' => $data['poll_title'],
- 'U_POLL_TOPIC' => append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext . '?t=' . $topic_id . '&f=' . $forum_id),
+ 'U_POLL_TOPIC' => append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, 't=' . $topic_id . '&f=' . $forum_id),
'POLL_LENGTH' => $data['poll_length'],
'TOPIC_ID' => $topic_id,
'TOTAL_VOTES' => $poll_total_votes,
diff --git a/modules/random_member.php b/modules/random_member.php
index 563c3be5..9a34aba8 100644
--- a/modules/random_member.php
+++ b/modules/random_member.php
@@ -127,7 +127,7 @@ class random_member extends module_base
'USER_POSTS' => (int) $row['user_posts'],
'AVATAR_IMG' => $avatar_img,
- 'JOINED' => $this->user->format_date($row['user_regdate'], 'd.M.Y'),
+ 'JOINED' => $this->user->format_date($row['user_regdate']),
// 'USER_OCC' => censor_text($row['user_occ']),
// 'USER_FROM' => censor_text($row['user_from']),
// 'U_WWW' => censor_text($row['user_website']),
diff --git a/modules/user_menu.php b/modules/user_menu.php
index f40c77ed..fa64b579 100644
--- a/modules/user_menu.php
+++ b/modules/user_menu.php
@@ -127,7 +127,7 @@ class user_menu extends module_base
$sql = 'SELECT COUNT(DISTINCT t.topic_id) as total
FROM ' . TOPICS_TABLE . ' t
- WHERE t.topic_last_post_time > ' . $this->user->data['user_lastvisit'] . '
+ WHERE t.topic_last_post_time > ' . (int) $this->user->data['user_lastvisit'] . '
AND t.topic_moved_id = 0
' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
diff --git a/modules/whois_online.php b/modules/whois_online.php
index 14c10859..204ae704 100644
--- a/modules/whois_online.php
+++ b/modules/whois_online.php
@@ -112,11 +112,11 @@ class whois_online extends module_base
LEFT JOIN ' . USER_GROUP_TABLE . ' ug
ON (
g.group_id = ug.group_id
- AND ug.user_id = ' . $this->user->data['user_id'] . '
+ AND ug.user_id = ' . (int) $this->user->data['user_id'] . '
AND ug.user_pending = 0
)
WHERE g.group_legend > 0
- AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $this->user->data['user_id'] . ')
+ AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . (int) $this->user->data['user_id'] . ')
ORDER BY g.' . $order_legend . ' ASC';
}
$result = $this->db->sql_query($sql);
diff --git a/portal/modules/database_handler.php b/portal/modules/database_handler.php
index b2d18036..666654c9 100644
--- a/portal/modules/database_handler.php
+++ b/portal/modules/database_handler.php
@@ -109,7 +109,7 @@ class database_handler
}
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
- SET module_order = module_order' . $other_increment . '
+ SET module_order = module_order' . (int) $other_increment . '
WHERE module_order = ' . (int) ($module_data['module_order'] + ($direction * $step)) . '
AND module_column = ' . (int) $module_data['module_column'];
$this->db->sql_query($sql);
@@ -117,7 +117,7 @@ class database_handler
if ($updated)
{
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
- SET module_order = module_order' . $current_increment . '
+ SET module_order = module_order' . (int) $current_increment . '
WHERE module_id = ' . (int) $module_id;
$this->db->sql_query($sql);
}
@@ -136,20 +136,20 @@ class database_handler
{
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order + 1
- WHERE module_order >= ' . $module_data['module_order'] . '
- AND module_column = ' . ($module_data['module_column'] + $move_action);
+ WHERE module_order >= ' . (int) $module_data['module_order'] . '
+ AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
$this->db->sql_query($sql);
$updated = $this->db->sql_affectedrows();
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
- SET module_column = ' . ($module_data['module_column'] + $move_action) . '
+ SET module_column = ' . (int) ($module_data['module_column'] + $move_action) . '
WHERE module_id = ' . (int) $module_id;
$this->db->sql_query($sql);
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order - 1
- WHERE module_order >= ' . $module_data['module_order'] . '
- AND module_column = ' . $module_data['module_column'];
+ WHERE module_order >= ' . (int) $module_data['module_order'] . '
+ AND module_column = ' . (int) $module_data['module_column'];
$this->db->sql_query($sql);
// the module that needs to moved is in the last row
@@ -157,13 +157,13 @@ class database_handler
{
$sql = 'SELECT MAX(module_order) as new_order
FROM ' . PORTAL_MODULES_TABLE . '
- WHERE module_order < ' . $module_data['module_order'] . '
+ WHERE module_order < ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
$this->db->sql_query($sql);
$new_order = $this->db->sql_fetchfield('new_order') + 1;
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
- SET module_order = ' . $new_order . '
+ SET module_order = ' . (int) $new_order . '
WHERE module_id = ' . (int) $module_id;
$this->db->sql_query($sql);
}
diff --git a/portal/modules/manager.php b/portal/modules/manager.php
index eefd9642..651b8219 100644
--- a/portal/modules/manager.php
+++ b/portal/modules/manager.php
@@ -348,8 +348,8 @@ class manager
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order - 1
- WHERE module_column = ' . $module_data['module_column'] . '
- AND module_order > ' . $module_data['module_order'];
+ WHERE module_column = ' . (int) $module_data['module_column'] . '
+ AND module_order > ' . (int) $module_data['module_order'];
$this->db->sql_query($sql);
$this->cache->purge(); // make sure we don't get errors after re-adding a module
From 9d4515432cef2f0da575ce78c4c8baca67d6020c Mon Sep 17 00:00:00 2001
From: Marc Alexander
Date: Sat, 6 Jun 2015 14:50:46 +0200
Subject: [PATCH 2/9] [ticket/571] Remove unused ext.php
B3P-571
---
ext.php | 16 ----------------
1 file changed, 16 deletions(-)
delete mode 100644 ext.php
diff --git a/ext.php b/ext.php
deleted file mode 100644
index e4c82596..00000000
--- a/ext.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
Date: Sat, 6 Jun 2015 15:29:37 +0200
Subject: [PATCH 3/9] [ticket/571] Some more minor fixes
B3P-571
---
adm/style/portal/acp_portal_calendar.html | 78 +++++++++++------------
adm/style/portal/acp_portal_links.html | 4 +-
modules/links.php | 2 +-
portal/modules/manager.php | 2 +-
4 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/adm/style/portal/acp_portal_calendar.html b/adm/style/portal/acp_portal_calendar.html
index ab3e990e..3ce3519a 100644
--- a/adm/style/portal/acp_portal_calendar.html
+++ b/adm/style/portal/acp_portal_calendar.html
@@ -149,47 +149,47 @@
diff --git a/adm/style/portal/acp_portal_links.html b/adm/style/portal/acp_portal_links.html
index 80d57713..8fb0934c 100644
--- a/adm/style/portal/acp_portal_links.html
+++ b/adm/style/portal/acp_portal_links.html
@@ -64,7 +64,7 @@
-
-
+
| {L_ACP_PORTAL_LINK_TITLE} |
diff --git a/modules/links.php b/modules/links.php
index 2db14e1c..6b583e60 100644
--- a/modules/links.php
+++ b/modules/links.php
@@ -249,7 +249,7 @@ class links extends module_base
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
- $u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\acp\portal_module&mode=config&module_id=' . $module_id);
+ $u_action = append_sid('index.' . $this->php_ext, 'i=-board3-portal-acp-portal_module&mode=config&module_id=' . $module_id);
switch ($action)
{
diff --git a/portal/modules/manager.php b/portal/modules/manager.php
index 651b8219..5c2cce53 100644
--- a/portal/modules/manager.php
+++ b/portal/modules/manager.php
@@ -393,6 +393,6 @@ class manager
*/
public function get_module_link($mode, $module_id)
{
- return preg_replace(array('/i=[0-9]+/', '/mode=[a-zA-Z0-9_]+/'), array('i=%5C' . str_replace('\\', '%5C', $this->acp_class), 'mode=' . $mode), $this->u_action) . (($module_id) ? '&module_id=' . $module_id : '');
+ return preg_replace(array('/i=[0-9]+/', '/mode=[a-zA-Z0-9_]+/'), array('i=%5C' . str_replace('\\', '-', $this->acp_class), 'mode=' . $mode), $this->u_action) . (($module_id) ? '&module_id=' . $module_id : '');
}
}
From 31d01f0aa47dde37c1abf612b89862d7d3547eeb Mon Sep 17 00:00:00 2001
From: Marc Alexander
Date: Sat, 6 Jun 2015 15:37:03 +0200
Subject: [PATCH 4/9] [ticket/571] Use proper links for forms in ACP
B3P-571
---
adm/style/portal/acp_portal_calendar.html | 4 ++--
adm/style/portal/acp_portal_menu.html | 4 ++--
modules/calendar.php | 2 +-
modules/custom.php | 2 +-
modules/main_menu.php | 2 +-
modules/welcome.php | 2 +-
tests/unit/portal/modules_manager_test.php | 2 +-
7 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/adm/style/portal/acp_portal_calendar.html b/adm/style/portal/acp_portal_calendar.html
index 3ce3519a..f703502a 100644
--- a/adm/style/portal/acp_portal_calendar.html
+++ b/adm/style/portal/acp_portal_calendar.html
@@ -80,7 +80,7 @@
-