Skip to content

Commit

Permalink
General code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rxu committed Apr 30, 2020
1 parent f4411b4 commit 19e7e92
Show file tree
Hide file tree
Showing 69 changed files with 1,986 additions and 1,743 deletions.
28 changes: 15 additions & 13 deletions acp/acp_thanks_info.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<?php
/**
*
* Thanks For Posts extension for the phpBB Forum Software package.
*
* @copyright (c) 2013 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
*
* Thanks For Posts.
* Adds the ability to thank the author and to use per posts/topics/forum rating system based on the count of thanks.
* An extension for the phpBB Forum Software package.
*
* @copyright (c) 2020, rxu, https://www.phpbbguru.net
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace gfksx\thanksforposts\acp;

class acp_thanks_info
{
function module()
{
return array(
return [
'filename' => '\gfksx\thanksforposts\acp\acp_thanks_module',
'title' => 'ACP_THANKS_SETTINGS',
'version' => '1.3.4',
'modes' => array(
'thanks' => array('title' => 'ACP_THANKS_SETTINGS', 'auth' => 'ext_gfksx/thanksforposts && acl_a_board', 'cat' => array('ACP_THANKS')),
),
);
'version' => '2.0.7',
'modes' => [
'thanks' => ['title' => 'ACP_THANKS_SETTINGS', 'auth' => 'ext_gfksx/thanksforposts && acl_a_board', 'cat' => ['ACP_THANKS']],
],
];
}
}
112 changes: 66 additions & 46 deletions acp/acp_thanks_module.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
/**
*
* Thanks For Posts extension for the phpBB Forum Software package.
*
* @copyright (c) 2013 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
*
* Thanks For Posts.
* Adds the ability to thank the author and to use per posts/topics/forum rating system based on the count of thanks.
* An extension for the phpBB Forum Software package.
*
* @copyright (c) 2020, rxu, https://www.phpbbguru.net
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace gfksx\thanksforposts\acp;

Expand All @@ -16,55 +18,71 @@
class acp_thanks_module
{
var $u_action;
var $new_config = array();
var $new_config = [];

function main($id, $mode)
{
global $config, $request, $user, $phpbb_container, $template;
global $phpbb_container;

/** @var \phpbb\config\config $config Config object */
$config = $phpbb_container->get('config');

/** @var \phpbb\language\language $language Language object */
$language = $phpbb_container->get('language');

/** @var \phpbb\request\request $request Request object */
$request = $phpbb_container->get('request');

/** @var \phpbb\template\template $template Template object */
$template = $phpbb_container->get('template');

/** @var \phpbb\user $user User object */
$user = $phpbb_container->get('user');

$submit = $request->is_set_post('submit');

$form_key = 'acp_thanks';
add_form_key($form_key);

/**
* Validation types are:
* string, int, bool,
* script_path (absolute path in url - beginning with / and no trailing slash),
* rpath (relative), rwpath (realtive, writable), path (relative path, but able to escape the root), wpath (writable)
*/
$display_vars = array(
* Validation types are:
* string, int, bool,
* script_path (absolute path in url - beginning with / and no trailing slash),
* rpath (relative), rwpath (realtive, writable), path (relative path, but able to escape the root), wpath (writable)
*/
$display_vars = [
'title' => 'ACP_THANKS_SETTINGS',
'vars' => array(
'legend' => 'GENERAL_OPTIONS',
'remove_thanks' => array('lang' => 'REMOVE_THANKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_only_first_post' => array('lang' => 'THANKS_ONLY_FIRST_POST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_global_post' => array('lang' => 'THANKS_GLOBAL_POST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_info_page' => array('lang' => 'THANKS_INFO_PAGE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_postlist_view' => array('lang' => 'THANKS_POSTLIST_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_number_post' => array('lang' => 'THANKS_NUMBER_POST', 'validate' => 'int:1:250', 'type' => 'text:4:6', 'explain' => true),
'thanks_time_view' => array('lang' => 'THANKS_TIME_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_counters_view' => array('lang' => 'THANKS_COUNTERS_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_profilelist_view' => array('lang' => 'THANKS_PROFILELIST_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'thanks_number' => array('lang' => 'THANKS_NUMBER', 'validate' => 'int:1', 'type' => 'text:4:4', 'explain' => true),
'thanks_top_number' => array('lang' => 'THANKS_TOP_NUMBER', 'validate' => 'int:0', 'type' => 'text:4:6', 'explain' => true),
)
);
'vars' => [
'legend' => 'GENERAL_OPTIONS',
'remove_thanks' => ['lang' => 'REMOVE_THANKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_only_first_post' => ['lang' => 'THANKS_ONLY_FIRST_POST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_global_post' => ['lang' => 'THANKS_GLOBAL_POST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_info_page' => ['lang' => 'THANKS_INFO_PAGE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_postlist_view' => ['lang' => 'THANKS_POSTLIST_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_number_post' => ['lang' => 'THANKS_NUMBER_POST', 'validate' => 'int:1:250', 'type' => 'text:4:6', 'explain' => true],
'thanks_time_view' => ['lang' => 'THANKS_TIME_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_counters_view' => ['lang' => 'THANKS_COUNTERS_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_profilelist_view' => ['lang' => 'THANKS_PROFILELIST_VIEW', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'thanks_number' => ['lang' => 'THANKS_NUMBER', 'validate' => 'int:1', 'type' => 'text:4:4', 'explain' => true],
'thanks_top_number' => ['lang' => 'THANKS_TOP_NUMBER', 'validate' => 'int:0', 'type' => 'text:4:6', 'explain' => true],
]
];

if (isset($display_vars['lang']))
{
$phpbb_container->get('language')->add_lang($display_vars['lang']);
$language->add_lang($display_vars['lang']);
}

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

// We validate the complete config if whished
validate_config_vars($display_vars['vars'], $cfg_array, $error);

if ($submit && !check_form_key($form_key))
{
$error[] = $user->lang('FORM_INVALID');
$error[] = $language->lang('FORM_INVALID');
}
// Do not write values if there is an error
if (sizeof($error))
Expand Down Expand Up @@ -94,20 +112,21 @@ 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($language->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'),
$template->assign_vars([
'L_TITLE' => $language->lang($display_vars['title']),
'L_TITLE_EXPLAIN' => $language->lang($display_vars['title'] . '_EXPLAIN'),

'S_ERROR' => (sizeof($error)) ? true : false,
'ERROR_MSG' => implode('<br />', $error),

'U_ACTION' => $this->u_action)
'U_ACTION' => $this->u_action,
]
);

// Output relevant page
Expand All @@ -120,9 +139,10 @@ function main($id, $mode)

if (strpos($config_key, 'legend') !== false)
{
$template->assign_block_vars('options', array(
$template->assign_block_vars('options', [
'S_LEGEND' => true,
'LEGEND' => $user->lang($vars))
'LEGEND' => $language->lang($vars),
]
);

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

$content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
Expand All @@ -146,13 +166,13 @@ function main($id, $mode)
continue;
}

$template->assign_block_vars('options', array(
$template->assign_block_vars('options', [
'KEY' => $config_key,
'TITLE' => $user->lang($vars['lang']),
'TITLE' => $language->lang($vars['lang']),
'S_EXPLAIN' => $vars['explain'],
'TITLE_EXPLAIN' => $l_explain,
'CONTENT' => $content,
)
]
);

unset($display_vars['vars'][$config_key]);
Expand Down
28 changes: 15 additions & 13 deletions acp/acp_thanks_refresh_info.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<?php
/**
*
* Thanks For Posts extension for the phpBB Forum Software package.
*
* @copyright (c) 2013 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
*
* Thanks For Posts.
* Adds the ability to thank the author and to use per posts/topics/forum rating system based on the count of thanks.
* An extension for the phpBB Forum Software package.
*
* @copyright (c) 2020, rxu, https://www.phpbbguru.net
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace gfksx\thanksforposts\acp;

class acp_thanks_refresh_info
{
function module()
{
return array(
return [
'filename' => '\gfksx\thanksforposts\acp\acp_thanks_refresh_module',
'title' => 'ACP_THANKS_REFRESH',
'version' => '1.3.4',
'modes' => array(
'thanks' => array('title' => 'ACP_THANKS_REFRESH', 'auth' => 'ext_gfksx/thanksforposts && acl_a_board', 'cat' => array('ACP_THANKS')),
),
);
'version' => '2.0.7',
'modes' => [
'thanks' => ['title' => 'ACP_THANKS_REFRESH', 'auth' => 'ext_gfksx/thanksforposts && acl_a_board', 'cat' => ['ACP_THANKS']],
],
];
}
}
Loading

0 comments on commit 19e7e92

Please sign in to comment.