Skip to content

Commit

Permalink
Fix various flows pointed by phpBB extension validator (kasimi) and s…
Browse files Browse the repository at this point in the history
…ome more.
  • Loading branch information
rxu committed Feb 25, 2018
1 parent 73f091c commit 674bb3c
Show file tree
Hide file tree
Showing 60 changed files with 412 additions and 638 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ branches:
- master
- develop
- /^develop-.*$/
- /^.*_prep$/
- /^\d+(\.\d+)?\.x$/

before_install:
Expand Down
18 changes: 8 additions & 10 deletions acp/acp_thanks_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function main($id, $mode)

if ($submit && !check_form_key($form_key))
{
$error[] = $user->lang['FORM_INVALID'];
$error[] = $user->lang('FORM_INVALID');
}
// Do not write values if there is an error
if (sizeof($error))
Expand Down Expand Up @@ -94,17 +94,15 @@ function main($id, $mode)
$phpbb_log = $phpbb_container->get('log');
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_' . strtoupper($mode));

trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
trigger_error($user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action));
}

$this->tpl_name = 'acp_thanks';
$this->page_title = $display_vars['title'];

$template->assign_vars(array(
'L_TITLE' => $user->lang[$display_vars['title']],
'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'],
'L_ACP_THANKS_MOD_VER' => $user->lang['ACP_THANKS_MOD_VER'],
'THANKS_MOD_VERSION' => isset($config['thanks_for_posts_version']) ? $config['thanks_for_posts_version'] : false,
'L_TITLE' => $user->lang($display_vars['title']),
'L_TITLE_EXPLAIN' => $user->lang($display_vars['title'] . '_EXPLAIN'),

'S_ERROR' => (sizeof($error)) ? true : false,
'ERROR_MSG' => implode('<br />', $error),
Expand All @@ -124,7 +122,7 @@ function main($id, $mode)
{
$template->assign_block_vars('options', array(
'S_LEGEND' => true,
'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
'LEGEND' => $user->lang($vars))
);

continue;
Expand All @@ -134,11 +132,11 @@ function main($id, $mode)
$l_explain = '';
if ($vars['explain'] && isset($vars['lang_explain']))
{
$l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
$l_explain = $user->lang($vars['lang_explain']);
}
else if ($vars['explain'])
{
$l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
$l_explain = $user->lang($vars['lang'] . '_EXPLAIN');
}

$content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
Expand All @@ -150,7 +148,7 @@ function main($id, $mode)

$template->assign_block_vars('options', array(
'KEY' => $config_key,
'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'],
'TITLE' => $user->lang($vars['lang']),
'S_EXPLAIN' => $vars['explain'],
'TITLE_EXPLAIN' => $l_explain,
'CONTENT' => $content,
Expand Down
128 changes: 73 additions & 55 deletions acp/acp_thanks_refresh_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function main($id, $mode)
$this->tpl_name = 'acp_thanks_refresh';
$this->page_title = 'ACP_THANKS_REFRESH';

$posts_delete_us = $all_posts = array();
$posts_delete_us = array();
$del_thanks = $end_thanks = $del_uthanks = $end_posts_thanks = $end_users_thanks = $thanks_update = 0;
$del_nofirst_thanks = $del_selfthanks = $all_users_thanks = $all_thanks = $all_posts_number = $all_posts_thanks = 0;
$all_users_thanks = $all_thanks = $all_posts_number = $all_posts_thanks = 0;

$thanks_table = $phpbb_container->getParameter('tables.thanks');

Expand All @@ -41,38 +41,43 @@ function main($id, $mode)
$cache->destroy('_all_posts_number');

// count all posts, thanks, users
$sql = 'SELECT DISTINCT post_id
$sql = 'SELECT COUNT(DISTINCT post_id) as all_posts_thanks
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$all_posts_thanks = $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$all_posts_thanks = (int) $db->sql_fetchfield('all_posts_thanks');

$sql = 'SELECT DISTINCT user_id
$sql = 'SELECT COUNT(DISTINCT user_id) as all_users_thanks
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$all_users_thanks = $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$all_users_thanks = (int) $db->sql_fetchfield('all_users_thanks');

$sql = 'SELECT COUNT(post_id) as total_match_count
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$all_thanks = $db->sql_fetchfield('total_match_count');
$db->sql_freeresult($result);
$db->sql_query($sql);
$all_thanks = (int) $db->sql_fetchfield('total_match_count');

unset($all_posts);
$all_posts = array();

$sql = 'SELECT t.*
FROM ' . $thanks_table .' t
LEFT JOIN ' . POSTS_TABLE .' p ON t.post_id = p.post_id
WHERE p.post_id IS NULL';
$result = $db->sql_query($sql);
$sql_ary = array(
'SELECT' => 't.*',
'FROM' => array(
$thanks_table => 't',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(POSTS_TABLE => 'p'),
'ON' => 't.post_id = p.post_id',
),
),
'WHERE' => 'p.post_id IS NULL',
);
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
while ($row = $db->sql_fetchrow($result))
{
$all_posts[] = $row['post_id'];
$all_posts[] = (int) $row['post_id'];
}
$db->sql_freeresult($result);
$all_posts_number = $config['num_posts'];

$all_posts_number = (int) $config['num_posts'];

$cache->put('_all_posts_thanks', $all_posts_thanks);
$cache->put('_all_users_thanks', $all_users_thanks);
Expand Down Expand Up @@ -102,18 +107,26 @@ function main($id, $mode)
{
$sql = 'DELETE FROM ' . $thanks_table ."
WHERE " . $db->sql_in_set('post_id', $all_posts, false);
$result = $db->sql_query($sql);
$del_thanks = (int) $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$del_thanks = (int) $db->sql_affectedrows();
$end_thanks = $all_thanks - $del_thanks;
}

// update delete users
$sql = 'SELECT t.post_id
FROM ' . $thanks_table . ' t
LEFT JOIN ' . POSTS_TABLE . ' p ON (t.post_id = p.post_id)
WHERE p.poster_id = '. ANONYMOUS;
$result = $db->sql_query($sql);
$sql_ary = array(
'SELECT' => 't.post_id',
'FROM' => array(
$thanks_table => 't',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(POSTS_TABLE => 'p'),
'ON' => 't.post_id = p.post_id',
),
),
'WHERE' => 'p.poster_id = '. ANONYMOUS,
);
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));

while ($row = $db->sql_fetchrow($result))
{
Expand All @@ -126,25 +139,35 @@ function main($id, $mode)
$del_uthanks = count($posts_delete_us);
$sql = 'DELETE FROM ' . $thanks_table ."
WHERE " . $db->sql_in_set('post_id', $posts_delete_us);
$result = $db->sql_query($sql);
$db->sql_freeresult($result);
$db->sql_query($sql);
}

//update move posts /topics /forums and change posters
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p
LEFT JOIN ' . $thanks_table . ' t ON (p.post_id = t.post_id)
WHERE p.topic_id <> t.topic_id OR p.forum_id <> t.forum_id OR p.poster_id <> t.poster_id';
$result = $db->sql_query($sql);
$sql_ary = array(
'SELECT' => 'p.post_id',
'FROM' => array(
POSTS_TABLE => 'p',
),
'LEFT_JOIN' => array(
array(
'FROM' => array($thanks_table => 't'),
'ON' => 'p.post_id = t.post_id',
),
),
'WHERE' => 'p.topic_id <> t.topic_id OR p.forum_id <> t.forum_id OR p.poster_id <> t.poster_id',
);
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
$thanks_update = 0;
if ($result)
{
while ($row = $db->sql_fetchrow($result))
{
$sql = 'SELECT forum_id, topic_id, poster_id, post_id
FROM ' . POSTS_TABLE . '
WHERE post_id = '.$row['post_id'];
WHERE post_id = ' . $row['post_id'];
$results = $db->sql_query($sql);
$rows = $db->sql_fetchrow($results);
$db->sql_freeresult($results);

$sql_ary = array(
'post_id' => $rows['post_id'],
Expand Down Expand Up @@ -180,9 +203,8 @@ function main($id, $mode)
{
$sql = 'DELETE FROM ' . $thanks_table ."
WHERE " . $db->sql_in_set('post_id', $all_first_posts, true);
$result = $db->sql_query($sql);
$del_nofirst_thanks = $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$del_nofirst_thanks = $db->sql_affectedrows();
$end_thanks = $end_thanks - $del_nofirst_thanks;
$del_thanks = $del_thanks + $del_nofirst_thanks;
}
Expand All @@ -204,33 +226,29 @@ function main($id, $mode)
{
$sql = 'DELETE FROM ' . $thanks_table ."
WHERE " . $db->sql_in_set('topic_id', $all_global_posts, false);
$result = $db->sql_query($sql);
$del_global_thanks = $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$del_global_thanks = $db->sql_affectedrows();
$end_thanks = $end_thanks - $del_global_thanks;
$del_thanks = $del_thanks + $del_global_thanks;
}
}
// delete selfthanks
$sql = 'DELETE FROM ' . $thanks_table .'
WHERE poster_id = user_id';
$result = $db->sql_query($sql);
$del_selfthanks = $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$del_selfthanks = $db->sql_affectedrows();
$del_thanks = $del_thanks + $del_selfthanks;
$end_thanks = $end_thanks - $del_selfthanks;

$sql = 'SELECT DISTINCT post_id
$sql = 'SELECT COUNT(DISTINCT post_id) as end_posts_thanks
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$end_posts_thanks = $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$end_posts_thanks = (int) $db->sql_fetchfield('end_posts_thanks');

$sql = 'SELECT DISTINCT user_id
$sql = 'SELECT COUNT(DISTINCT user_id) as end_users_thanks
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$end_users_thanks = $db->sql_affectedrows($result);
$db->sql_freeresult($result);
$db->sql_query($sql);
$end_users_thanks = (int) $db->sql_fetchfield('end_users_thanks');

$template->assign_vars(array(
'S_REFRESH' => true,
Expand Down
3 changes: 1 addition & 2 deletions acp/acp_thanks_reput_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function main($id, $mode)
{
global $request, $user, $template, $config, $phpbb_root_path, $phpbb_container;

$action = $request->variable('action', '');
$submit = $request->is_set_post('submit');

$form_key = 'acp_thanks_reput';
Expand Down Expand Up @@ -58,7 +57,7 @@ function main($id, $mode)
}

$this->new_config = $config;
$cfg_array = ($request->is_set('config')) ? utf8_normalize_nfc($request->variable('config', array('' => ''), true)) : $this->new_config;
$cfg_array = ($request->is_set('config')) ? $request->variable('config', array('' => ''), true) : $this->new_config;
$error = array();

// We validate the complete config if whished
Expand Down
11 changes: 4 additions & 7 deletions acp/acp_thanks_truncate_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,24 @@ function main($id, $mode)
$this->tpl_name = 'acp_thanks_truncate';
$this->page_title = 'ACP_THANKS_TRUNCATE';

$all_posts_thanks = $all_thanks = $del_thanks = $del_uposts = $del_posts = 0;

$thanks_table = $phpbb_container->getParameter('tables.thanks');

$sql = 'SELECT COUNT(post_id) as total_match_count
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$all_thanks = $end_thanks = $del_thanks = $db->sql_fetchfield('total_match_count');
$all_thanks = $end_thanks = (int) $db->sql_fetchfield('total_match_count');
$db->sql_freeresult($result);

$sql = 'SELECT COUNT(DISTINCT post_id) as total_match_count
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$all_posts_thanks = $del_posts = $end_posts_thanks = $db->sql_fetchfield('total_match_count');
$all_posts_thanks = $del_posts = $end_posts_thanks = (int) $db->sql_fetchfield('total_match_count');
$db->sql_freeresult($result);

$sql = 'SELECT COUNT(DISTINCT user_id) as total_match_count
FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$all_users_thanks = $del_uposts = $end_users_thanks = $db->sql_fetchfield('total_match_count');
$all_users_thanks = $del_uposts = $end_users_thanks = (int) $db->sql_fetchfield('total_match_count');
$db->sql_freeresult($result);

$truncate = $request->variable('truncate', false);
Expand All @@ -53,7 +51,7 @@ function main($id, $mode)
// check mode
if (confirm_box(true))
{
$sql = 'TRUNCATE TABLE ' . $thanks_table;
$sql = 'DELETE FROM ' . $thanks_table;
$result = $db->sql_query($sql);
$db->sql_freeresult($result);

Expand All @@ -65,7 +63,6 @@ function main($id, $mode)

$end_posts_thanks = $all_posts_thanks - $del_posts;
$end_users_thanks = $all_users_thanks - $del_uposts;
$del_thanks = $all_thanks - $end_thanks;
}
else
{
Expand Down
1 change: 0 additions & 1 deletion adm/style/acp_thanks.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<h1>{{ lang('TITLE') }}</h1>
<p>{{ lang('TITLE_EXPLAIN') }}</p>
<p>{{ lang('ACP_THANKS_MOD_VER') }}{{ lang('COLON') }}&nbsp;{{ THANKS_MOD_VERSION }}</p>
{% if S_ERROR %}
<div class="errorbox">
<h3>{{ lang('WARNING') }}</h3>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "phpbb-extension",
"description": "Adds the ability to thank the author and to use per posts/topics/forum rating system based on the count of thanks.",
"homepage": "http://www.phpbbguru.net",
"version": "2.0.5",
"version": "2.0.6",
"license": "GPL-2.0",
"authors": [
{
Expand Down
Loading

0 comments on commit 674bb3c

Please sign in to comment.