Skip to content

Commit

Permalink
Merge pull request #11 from iMattPro/instruction
Browse files Browse the repository at this point in the history
Compatibility checks and messages
  • Loading branch information
iMattPro authored Jan 3, 2024
2 parents 47bd87c + 1cbf4f8 commit ea29bbd
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tests/ export-ignore
.gitattributes export-ignore
phpunit.xml.* export-ignore
composer.lock export-ignore
composer.phar export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build/
/vendor/
/node_modules/
/composer.phar
33 changes: 14 additions & 19 deletions acp/wpn_acp_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,28 @@ public function main($id, $mode)
$form_key = 'phpbb/webpushnotifications';
add_form_key($form_key);

switch ($mode)
if ($mode === 'webpush')
{
case 'webpush':
// Load a template from adm/style for our ACP page
$this->tpl_name = 'wpn_acp_settings';
// Load a template from adm/style for our ACP page
$this->tpl_name = 'wpn_acp_settings';

$this->lang->add_lang('webpushnotifications_module_acp', 'phpbb/webpushnotifications');
$this->lang->add_lang('webpushnotifications_module_acp', 'phpbb/webpushnotifications');

// Set the page title for our ACP page
$this->page_title = $this->lang->lang('ACP_WEBPUSH_SETTINGS');
// Set the page title for our ACP page
$this->page_title = $this->lang->lang('ACP_WEBPUSH_SETTINGS');

if ($this->request->is_set_post('submit'))
if ($this->request->is_set_post('submit'))
{
if (!check_form_key($form_key))
{
if (!check_form_key($form_key))
{
$language = $phpbb_container->get('language');
trigger_error($language->lang('FORM_INVALID'), E_USER_WARNING);
}

$this->save_settings();
$language = $phpbb_container->get('language');
trigger_error($language->lang('FORM_INVALID'), E_USER_WARNING);
}

$this->display_settings();
break;
$this->save_settings();
}

default:
break;
$this->display_settings();
}
}

Expand Down
5 changes: 5 additions & 0 deletions adm/style/event/acp_main_notice_after.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if S_WPN_COMPATIBILITY_NOTICE %}
<div class="errorbox">
<p>{{ lang('ACP_WEBPUSH_REMOVE_NOTICE') }}</p>
</div>
{% endif %}
4 changes: 2 additions & 2 deletions adm/style/wpn_acp.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ phpbb.addAjaxCallback('generate_vapid_keys', () => {
const privateKeyInput = document.querySelector('#webpush_vapid_private');
publicKeyInput.value = keyPair.publicKey;
privateKeyInput.value = keyPair.privateKey;
})
})
});
});
4 changes: 3 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<delete file="${dir}/composer.phar" />
<delete file="${dir}/phpunit.xml.dist" />
<delete file="${dir}/README.md" />
<delete file="${dir}/package.json" />
<delete file="${dir}/package-lock.json" />
</target>

<!--
Expand Down Expand Up @@ -68,7 +70,7 @@
<if>
<equals arg1="${has-dependencies}" arg2="1" />
<then>
<exec dir="${package-directory}" command="php composer.phar install --no-dev"
<exec dir="${package-directory}" command="php ../../../../../../../../composer.phar install --no-dev"
checkreturn="true" />
</then>
</if>
Expand Down
15 changes: 11 additions & 4 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function getSubscribedEvents()
return [
'core.ucp_notifications_output_notification_types_modify_template_vars' => 'load_template_data',
'core.ucp_display_module_before' => 'load_language',
'core.acp_main_notice' => 'compatibility_notice',
];
}

Expand Down Expand Up @@ -67,7 +68,7 @@ public function __construct(controller_helper $controller_helper, form_helper $f
*/
public function load_template_data($event)
{
if ($event['method_data']['id'] == 'notification.method.phpbb.wpn.webpush')
if ($event['method_data']['id'] === 'notification.method.phpbb.wpn.webpush')
{
$template_ary = $event['method_data']['method']->get_ucp_template_data($this->controller_helper, $this->form_helper);
$this->template->assign_vars($template_ary);
Expand All @@ -76,11 +77,17 @@ public function load_template_data($event)

/**
* Load language file
*
* @param \phpbb\event\data $event
*/
public function load_language($event)
public function load_language()
{
$this->language->add_lang('webpushnotifications_module_ucp', 'phpbb/webpushnotifications');
}

/**
* Check if extension is compatible (it will not be compatible with phpBB 4)
*/
public function compatibility_notice()
{
$this->template->assign_var('S_WPN_COMPATIBILITY_NOTICE', phpbb_version_compare(PHPBB_VERSION, '4.0.0-a1', '>='));
}
}
74 changes: 71 additions & 3 deletions ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,78 @@

/**
* phpBB Browser Push Notifications Extension base
*
* It is recommended to remove this file from
* an extension if it is not going to be used.
*/
class ext extends \phpbb\extension\base
{
/**
* @var array An array of installation error messages
*/
protected $errors = [];

/**
* {@inheritdoc}
*
* Requires phpBB 3.3.12 due to new template and core events.
* Should not be installed in phpBB 4.0.0-a1 because it already has push notifications.
* Requires PHP 7.3 due to 3rd party libraries included.
*/
public function is_enableable()
{
return $this->check_phpbb_version()->check_php_version()->result();
}

/**
* Check the installed phpBB version meets this extension's requirements.
*
* @return \phpbb\webpushnotifications\ext
*/
protected function check_phpbb_version()
{
if (phpbb_version_compare(PHPBB_VERSION, '3.3.12-dev', '<') ||
phpbb_version_compare(PHPBB_VERSION, '4.0.0-a1', '>='))
{
$this->errors[] = 'PHPBB_VERSION_ERROR';
}

return $this;
}

/**
* Check the server PHP version meets this extension's requirements.
*
* @return \phpbb\webpushnotifications\ext
*/
protected function check_php_version()
{
if (phpbb_version_compare(PHP_VERSION_ID, '70300', '<'))
{
$this->errors[] = 'PHP_VERSION_ERROR';
}

return $this;
}

/**
* Return the is_enableable result. Either true, or the best enable failed
* response for the current phpBB environment: array of error messages
* in phpBB 3.3 or newer, false otherwise.
*
* @return array|bool
*/
protected function result()
{
if (empty($this->errors))
{
return true;
}

if (phpbb_version_compare(PHPBB_VERSION, '3.3.0-b1', '>='))
{
$language = $this->container->get('language');
$language->add_lang('install', 'phpbb/webpushnotifications');
return array_map([$language, 'lang'], $this->errors);
}

return false;
}
}
3 changes: 2 additions & 1 deletion language/en/info_acp_webpushnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
//

$lang = array_merge($lang, [
'ACP_WEBPUSH_SETTINGS' => 'Web Push settings',
'ACP_WEBPUSH_SETTINGS' => 'Web Push settings',
'ACP_WEBPUSH_REMOVE_NOTICE' => 'Web Push Notifications are now built-in to phpBB.<br>The extension “phpBB Browser Push Notifications” is no longer needed and should be uninstalled.<br>All settings and user preferences associated with the extension will be migrated into phpBB‘s built-in push notifications when you uninstall the extension.',
'LOG_CONFIG_WEBPUSH' => '<strong>Altered Web Push settings</strong>',
'LOG_WEBPUSH_MESSAGE_FAIL' => '<strong>Web Push message could not be sent:</strong> %s',
'LOG_WEBPUSH_SUBSCRIPTION_REMOVED' => '<strong>Removed Web Push subscription:</strong>» %s',
Expand Down
43 changes: 43 additions & 0 deletions language/en/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
*
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2023, phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

/**
* DO NOT CHANGE
*/
if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = [];
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
//
// Some characters you may want to copy&paste:
// ’ » “ ” …
//

$lang = array_merge($lang, [
'PHPBB_VERSION_ERROR' => 'This extension is not compatible with your board. You must be using phpBB 3.3.12 or newer, up to but not including phpBB 4.x.x.',
'PHP_VERSION_ERROR' => 'This extension is not compatible with your server. Your server must be running PHP 7.3 or newer.',
]);
4 changes: 2 additions & 2 deletions migrations/add_webpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function effectively_installed(): bool
return $this->db_tools->sql_table_exists($this->table_prefix . 'wpn_notification_push');
}

static public function depends_on()
public static function depends_on()
{
return ['\phpbb\webpushnotifications\migrations\handle_subscriptions'];
return ['\phpbb\webpushnotifications\migrations\handle_subscriptions'];
}

public function update_schema(): array
Expand Down
2 changes: 1 addition & 1 deletion tests/notification/notification_method_webpush_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public function test_export_data_with_migration(): void
$sql = "SELECT * FROM phpbb_user_notifications
WHERE method = '" . $this->db->sql_escape('notification.method.phpbb.wpn.webpush') . "'";
$result = $this->db->sql_query($sql);
$this->assertEquals(0, count($this->db->sql_fetchrowset($result)));
$this->assertCount(0, $this->db->sql_fetchrowset($result));
$this->db->sql_freeresult($result);

$this->assertEquals(
Expand Down

0 comments on commit ea29bbd

Please sign in to comment.