Skip to content

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWCS committed Dec 14, 2024
1 parent acea9bb commit c278fb7
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ env:
EXTNAME: lukewcs/statspermissions # Your extension vendor/package name
SNIFF: 1 # Run code sniffer on your code? 1 or 0
IMAGE_ICC: 1 # Run icc profile sniffer on your images? 1 or 0
EPV: 1 # Run EPV (Extension Pre Validator) on your code? 1 or 0
EPV: 0 # Run EPV (Extension Pre Validator) on your code? 1 or 0
EXECUTABLE_FILES: 1 # Run check for executable files? 1 or 0
PHPBB_BRANCH: 3.3.x # The phpBB branch to run tests on

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Extension for phpBB - Allows to define independent permissions for viewing stati

### Requirements
* phpBB 3.3.0 - 3.3.x
* PHP 7.1.3 - 8.3.x
* PHP 7.4.0 - 8.4.x
2 changes: 1 addition & 1 deletion docs/version_check.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"stable": {
"3.3": {
"current": "1.2.0",
"current": "1.2.1",
"announcement": "https://github.com/LukeWCS/stats-permissions/releases",
"eol": null,
"security": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class acp_stats_permissions_module
public $tpl_name;
public $u_action;

public function main($id, $mode)
public function main()
{
global $phpbb_container;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ <h1>{{ lang('STATS_PERMISSIONS_CONFIG_TITLE') }}</h1>
{% endmacro %}

{% macro footer(metadata) %}
<p class="{{ metadata.CLASS }}">
{{ metadata.EXT_NAME }} {{ metadata.EXT_VER }} &copy; LukeWCS<br>
{{ metadata.LANG_DESC|e('html') }} {{ metadata.LANG_VER|e('html') }} &bull; {{ metadata.LANG_AUTHOR|e('html') }}
<p class="{{ metadata.class }}">
{{ metadata.ext_name }} {{ metadata.ext_ver }} &copy; {{ metadata.ext_copyright }}
{% if metadata.lang_ver is defined %}
<br>
{{ metadata.lang_desc|e('html') }} {{ metadata.lang_ver|e('html') }} &bull; {{ metadata.lang_author|e('html') }}
{% endif %}
</p>
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
*/

(function ($) { // IIFE start
(function ($) {

'use strict';

Expand Down Expand Up @@ -76,4 +76,4 @@ $(function() {
$('#stats_permissions_form') .on('reset', formReset);
});

})(jQuery); // IIFE end
})(jQuery);
6 changes: 3 additions & 3 deletions lukewcs/statspermissions/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "phpbb-extension",
"description": "Allows to define independent permissions for viewing statistics and newest member.",
"homepage": "https://github.com/LukeWCS/stats-permissions",
"version": "1.2.0",
"time": "2024-03-29",
"version": "1.2.1",
"time": "2024-12-14",
"license": "GPL-2.0-only",
"authors": [
{
Expand All @@ -14,7 +14,7 @@
}
],
"require": {
"php": ">=7.1.3,<8.4.0@dev",
"php": ">=7.4.0,<8.5.0@dev",
"composer/installers": "~1.0.0"
},
"extra": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

class acp_stats_permissions_controller
{
protected $config;
protected $template;
protected $language;
protected $request;
protected $ext_manager;
protected object $config;
protected object $template;
protected object $language;
protected object $request;
protected object $ext_manager;

protected $metadata;

public $u_action;
protected array $metadata;
public string $u_action;

public function __construct(
\phpbb\config\config $config,
Expand All @@ -47,7 +46,7 @@ public function module_settings(): void
$notes = [];

$this->language->add_lang(['acp_stats_permissions', 'acp_stats_permissions_lang_author'], 'lukewcs/statspermissions');
$this->set_meta_template_vars('STATS_PERMISSIONS');
$this->set_meta_template_vars('STATS_PERMISSIONS', 'LukeWCS');

if ($this->request->is_set_post('submit'))
{
Expand All @@ -58,9 +57,11 @@ public function module_settings(): void
// config section 1
$this->config->set('stats_permissions_admin_mode' , $this->request->variable('stats_permissions_admin_mode', 0));
$this->config->set('stats_permissions_use_permissions' , $this->request->variable('stats_permissions_use_permissions', 0));

$perm_for_guests = $this->request->variable('stats_permissions_perm_for_guests_stats', 0) ? 1 : 0;
$perm_for_guests += $this->request->variable('stats_permissions_perm_for_guests_newest', 0) ? 2 : 0;
$this->config->set('stats_permissions_perm_for_guests' , $perm_for_guests);

$perm_for_bots = $this->request->variable('stats_permissions_perm_for_bots_stats', 0) ? 1 : 0;
$perm_for_bots += $this->request->variable('stats_permissions_perm_for_bots_newest', 0) ? 2 : 0;
$this->config->set('stats_permissions_perm_for_bots' , $perm_for_bots);
Expand All @@ -76,14 +77,14 @@ public function module_settings(): void
}

$this->template->assign_vars([
'STATS_PERMISSIONS_NOTES' => $notes,
'STATS_PERMISSIONS_NOTES' => $notes,

'STATS_PERMISSIONS_ADMIN_MODE' => $this->config['stats_permissions_admin_mode'],
'STATS_PERMISSIONS_USE_PERMISSIONS' => $this->config['stats_permissions_use_permissions'],
'STATS_PERMISSIONS_PERM_FOR_GUESTS' => $this->config['stats_permissions_perm_for_guests'],
'STATS_PERMISSIONS_PERM_FOR_BOTS' => $this->config['stats_permissions_perm_for_bots'],
'STATS_PERMISSIONS_ADMIN_MODE' => (bool) $this->config['stats_permissions_admin_mode'],
'STATS_PERMISSIONS_USE_PERMISSIONS' => (bool) $this->config['stats_permissions_use_permissions'],
'STATS_PERMISSIONS_PERM_FOR_GUESTS' => (int) $this->config['stats_permissions_perm_for_guests'],
'STATS_PERMISSIONS_PERM_FOR_BOTS' => (int) $this->config['stats_permissions_perm_for_bots'],

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

add_form_key('stats_permissions');
Expand All @@ -94,13 +95,18 @@ public function set_page_url(string $u_action): void
$this->u_action = $u_action;
}

// Determine the version of the language pack with fallback to 0.0.0
/*
Determine the version of the language pack with fallback to 0.0.0
*/
private function get_lang_ver(string $lang_ext_ver): string
{
return ($this->language->is_set($lang_ext_ver) ? preg_replace('/[^0-9.]/', '', $this->language->lang($lang_ext_ver)) : '0.0.0');
preg_match('/^([0-9]+\.[0-9]+\.[0-9]+.*)/', $this->language->lang($lang_ext_ver), $matches);
return ($matches[1] ?? '0.0.0');
}

// Check the language pack version for the minimum version and generate notice if outdated
/*
Check the language pack version for the minimum version and generate notice if outdated
*/
private function lang_ver_check_msg(string $lang_version_var, string $lang_outdated_var): string
{
$lang_outdated_msg = '';
Expand All @@ -113,7 +119,7 @@ private function lang_ver_check_msg(string $lang_version_var, string $lang_outda
{
$lang_outdated_msg = $this->language->lang($lang_outdated_var);
}
else // Fallback if the current language package does not yet have the required variable.
else /* Fallback if the current language package does not yet have the required variable. */
{
$lang_outdated_msg = 'Note: The language pack for the extension <strong>%1$s</strong> is no longer up-to-date. (installed: %2$s / needed: %3$s)';
}
Expand All @@ -123,17 +129,20 @@ private function lang_ver_check_msg(string $lang_version_var, string $lang_outda
return $lang_outdated_msg;
}

private function set_meta_template_vars(string $tpl_prefix): void
private function set_meta_template_vars(string $tpl_prefix, string $copyright): void
{
$this->template->assign_vars([
$tpl_prefix . '_METADATA' => [
'EXT_NAME' => $this->metadata['extra']['display-name'],
'EXT_VER' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->metadata['version']),
'LANG_DESC' => $this->language->lang($tpl_prefix . '_LANG_DESC'),
'LANG_VER' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->language->lang($tpl_prefix . '_LANG_VER')),
'LANG_AUTHOR' => $this->language->lang($tpl_prefix . '_LANG_AUTHOR'),
'CLASS' => strtolower($tpl_prefix) . '_footer',
],
]);
$template_vars = [
'ext_name' => $this->metadata['extra']['display-name'],
'ext_ver' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->metadata['version']),
'ext_copyright' => $copyright,
'class' => strtolower($tpl_prefix) . '_footer',
];
$template_vars += $this->language->is_set($tpl_prefix . '_LANG_VER') ? [
'lang_desc' => $this->language->lang($tpl_prefix . '_LANG_DESC'),
'lang_ver' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->language->lang($tpl_prefix . '_LANG_VER')),
'lang_author' => $this->language->lang($tpl_prefix . '_LANG_AUTHOR'),
] : [];

$this->template->assign_vars([$tpl_prefix . '_METADATA' => $template_vars]);
}
}
49 changes: 29 additions & 20 deletions lukewcs/statspermissions/event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@

class listener implements EventSubscriberInterface
{
const PERM_STATS = 1;
const PERM_NEWEST = 2;
protected const PERM_STATS = 1;
protected const PERM_NEWEST = 2;

protected $stats_permissions_core;
protected object $config;
protected object $template;
protected object $language;
protected object $auth;
protected object $user;
protected object $phpbb_dispatcher;

public function __construct(
\phpbb\config\config $config,
Expand All @@ -31,23 +36,26 @@ public function __construct(
\phpbb\event\dispatcher_interface $dispatcher
)
{
$this->config = $config;
$this->template = $template;
$this->language = $language;
$this->auth = $auth;
$this->user = $user;
$this->config = $config;
$this->template = $template;
$this->language = $language;
$this->auth = $auth;
$this->user = $user;
$this->phpbb_dispatcher = $dispatcher;
}

public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
'core.page_header_after' => 'set_template_vars',
'core.permissions' => 'add_permissions',
];
}

public function set_template_vars()
/*
EVENT: core.page_header_after
*/
public function set_template_vars(): void
{
$force_api_mode = false;

Expand All @@ -63,32 +71,32 @@ public function set_template_vars()

$force_api_mode = ($force_api_mode === true);

// Set display permission variables
/* Set display permission variables */
if ($this->config['stats_permissions_admin_mode'])
{
$permission_stats = $this->auth->acl_get('a_');
$permission_newest = $this->auth->acl_get('a_');
}
else
{
if ($this->config['stats_permissions_use_permissions']) // use phpBB permissions
if ($this->config['stats_permissions_use_permissions']) /* use phpBB permissions */
{
$permission_stats = $this->auth->acl_gets('u_stats_permissions_show_stats');
$permission_newest = $this->auth->acl_gets('u_stats_permissions_show_newest');
}
else
{
if ($this->user->data['user_id'] != ANONYMOUS && empty($this->user->data['is_bot'])) // user
if ($this->user->data['user_id'] != ANONYMOUS && empty($this->user->data['is_bot'])) /* user */
{
$permission_stats = true;
$permission_newest = true;
}
else if (!empty($this->user->data['is_bot'])) // bot
else if (!empty($this->user->data['is_bot'])) /* bot */
{
$permission_stats = $this->config['stats_permissions_perm_for_bots'] & self::PERM_STATS;
$permission_newest = $this->config['stats_permissions_perm_for_bots'] & self::PERM_NEWEST;
}
else // guest
else /* guest */
{
$permission_stats = $this->config['stats_permissions_perm_for_guests'] & self::PERM_STATS;
$permission_newest = $this->config['stats_permissions_perm_for_guests'] & self::PERM_NEWEST;
Expand All @@ -105,9 +113,11 @@ public function set_template_vars()
]);
}

public function add_permissions($event)
/*
EVENT: core.permissions
*/
public function add_permissions($event): void
{
$permissions = $event['permissions'];
$lang_show_stats = $this->language->lang('ACL_U_STATS_PERMISSIONS_SHOW_STATS');
$lang_show_newest = $this->language->lang('ACL_U_STATS_PERMISSIONS_SHOW_NEWEST');

Expand All @@ -117,8 +127,7 @@ public function add_permissions($event)
$lang_show_newest = '<span style="opacity: 0.5;">' . $lang_show_newest . '</span>';
}

$permissions['u_stats_permissions_show_stats'] = ['lang' => $lang_show_stats, 'cat' => 'misc'];
$permissions['u_stats_permissions_show_newest'] = ['lang' => $lang_show_newest, 'cat' => 'misc'];
$event['permissions'] = $permissions;
$event->update_subarray('permissions', 'u_stats_permissions_show_stats', ['lang' => $lang_show_stats, 'cat' => 'misc']);
$event->update_subarray('permissions', 'u_stats_permissions_show_newest', ['lang' => $lang_show_newest, 'cat' => 'misc']);
}
}
2 changes: 1 addition & 1 deletion lukewcs/statspermissions/ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ext extends \phpbb\extension\base
public function is_enableable()
{
$valid_phpbb = phpbb_version_compare(PHPBB_VERSION, '3.3.0', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.4.0-dev', '<');
$valid_php = phpbb_version_compare(PHP_VERSION, '7.1.3', '>=') && phpbb_version_compare(PHP_VERSION, '8.4.0-dev', '<');
$valid_php = phpbb_version_compare(PHP_VERSION, '7.4.0', '>=') && phpbb_version_compare(PHP_VERSION, '8.5.0-dev', '<');

return $valid_phpbb && $valid_php;
}
Expand Down
15 changes: 15 additions & 0 deletions stats-permissions_build_changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
### 1.2.1
* Release (2024-12-14)
* PHP:
* Code verwendet jetzt 7.4 Features.
* Code strikter gestaltet.
* ext.php`/`composer.json` angepasst:
* PHP: 7.1.3-8.3.x -> 7.4.0-8.4.x
* ACP-Template:
* Aktuelles Makro `footer()` von EMP 3.0 übernommen.
* ACP-Controller:
* Aktuelle Funktion `get_lang_ver()` von EMP 3.0 übernommen.
* Aktuelle Funktion `set_meta_template_vars()` von EMP 3.0 übernommen.
* Listener:
* Wie bei "Limit Multiple Replies" werden Rechte jetzt mit der Wrapper Funktion `update_subarray()` (>=phpBB 3.2.1) eingehängt, wodurch das umständliche Extrahieren und Zurückkopieren des Subarrays `$event['permissions']` entfällt.

### 1.2.0
* Release (2024-03-29)
* Core Code in den Listener integriert und Core Ordner gelöscht.
Expand Down
7 changes: 7 additions & 0 deletions stats-permissions_changelog_de.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 1.2.1
(2024-12-14)

* Die Voraussetzungen haben sich geändert:
* PHP: 7.4.0 - 8.4.x (Bisher: 7.1.3 - 8.3.x)
* Technik auf den Stand von EMP 3.0 gebracht, Details im Build Changelog.

### 1.2.0
(2024-03-29)

Expand Down

0 comments on commit c278fb7

Please sign in to comment.