Skip to content

Commit

Permalink
Merge pull request #1242 from Andrew-Staves-Activ/default_notificatio…
Browse files Browse the repository at this point in the history
…n_method_option

Added an option to set the default notification method for users
  • Loading branch information
geekwright authored Nov 7, 2023
2 parents ad558c5 + 4cefc84 commit 838aafa
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 4 deletions.
10 changes: 10 additions & 0 deletions docs/lang_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ upgrade/language/english/smarty3.php
htdocs/class/xoopseditor/tinymce/language/english.php
- added define('_FAILGETIMG', 'Failed to get image %s');

/htdocs/modules/system/language/english/modinfo.php
- added define('_MI_DEFAULT_NOTIFICATION_METHOD_DISABLE', 'Temporarily disable');
- added define('_MI_DEFAULT_NOTIFICATION_METHOD_EMAIL', 'Email');
- added define('_MI_DEFAULT_NOTIFICATION_METHOD_PM', 'Private message');

/htdocs/modules/system/language/english/admin/preferences.php
- added define('_MD_AM_DEFAULT_NOTIFICATION_METHOD', 'Default notification method');
- added define('_MD_AM_DEFAULT_NOTIFICATION_METHOD_DESC', 'For new users when they subscribe to notifications from, e.g., a forum.');
- added define('_MD_AM_MODULEPREF',

================================
2023/03/19: Version 2.5.11-RC1
================================
Expand Down
9 changes: 9 additions & 0 deletions htdocs/install/include/makedata.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ function make_data($dbm, $adminname, $hashedAdminPass, $adminmail, $language, $g
$dbm->insert('config', " VALUES (133, 1, 0, 'jquery_theme', '_MI_SYSTEM_PREFERENCE_JQUERY_THEME', 'base', '', 'select', 'text', 35)");

$dbm->insert('config', " VALUES (134, 0, 1, 'redirect_message_ajax', '_MD_AM_CUSTOM_REDIRECT', '1', '_MD_AM_CUSTOM_REDIRECT_DESC', 'yesno', 'int', 12)");
//notification method
$dbm->insert('config', " VALUES (135, 0, 2, 'default_notification', '_MD_AM_DEFAULT_NOTIFICATION_METHOD', '1', '_MD_AM_DEFAULT_NOTIFICATION_METHOD_DESC', 'select', 'int', 3)");

require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
$editors = XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH . '/class/xoopseditor');
Expand Down Expand Up @@ -341,6 +343,13 @@ function make_data($dbm, $adminname, $hashedAdminPass, $adminmail, $language, $g
$dbm->insert('configoption', ' VALUES (' . $conf . ", '" . $dir . "', '" . $dir . "', 133)");
++$conf;
}
//notification method
$dbm->insert('configoption', " VALUES ($conf, '_MI_DEFAULT_NOTIFICATION_METHOD_DISABLE', '0', 135)");
++$conf;
$dbm->insert('configoption', " VALUES ($conf, '_MI_DEFAULT_NOTIFICATION_METHOD_PM', '1', 135)");
++$conf;
$dbm->insert('configoption', " VALUES ($conf, '_MI_DEFAULT_NOTIFICATION_METHOD_EMAIL', '2', 135)");
++$conf;

return $groups;
}
5 changes: 4 additions & 1 deletion htdocs/modules/system/admin/users/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function form_user($add_or_edit, $user = '')
include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';

if ($add_or_edit === true) {
/** @var XoopsConfigHandler $config_handler */
$config_handler = xoops_getHandler('config');
$xoopsConfigUser = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
//Add user
$uid_value = '';
$uname_value = '';
Expand All @@ -69,7 +72,7 @@ function form_user($add_or_edit, $user = '')
$umode_value = $xoopsConfig['com_mode'];
$uorder_value = $xoopsConfig['com_order'];
// RMV-NOTIFY
$notify_method_value = XOOPS_NOTIFICATION_METHOD_PM;
$notify_method_value = (isset($xoopsConfigUser['default_notification']) ? $xoopsConfigUser['default_notification'] : XOOPS_NOTIFICATION_METHOD_PM);
$notify_mode_value = XOOPS_NOTIFICATION_MODE_SENDALWAYS;
$bio_value = '';
$rank_value = 0;
Expand Down
7 changes: 5 additions & 2 deletions htdocs/modules/system/language/english/admin/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,11 @@
define('_MD_AM_WELCOMETYPE', 'Sending welcoming message');
define('_MD_AM_WELCOMETYPE_DESC', 'The method for sending a welcome message to a user upon their successful registration.');
define('_MD_AM_WELCOMETYPE_EMAIL', 'Email');
define('_MD_AM_WELCOMETYPE_PM', 'Message');
define('_MD_AM_WELCOMETYPE_BOTH', 'Email and message');
define('_MD_AM_WELCOMETYPE_PM', 'Private message');
define('_MD_AM_WELCOMETYPE_BOTH', 'Email and private message');
//2.5.11
define('_MD_AM_DEFAULT_NOTIFICATION_METHOD', 'Default notification method');
define('_MD_AM_DEFAULT_NOTIFICATION_METHOD_DESC', 'For new users when they subscribe to notifications from, e.g., a forum.');
define('_MD_AM_MODULEPREF', 'Module Preferences');
// Preference module system
define('_AM_SYSTEM_PREFERENCES_SETTINGS', 'System Module Settings');
4 changes: 4 additions & 0 deletions htdocs/modules/system/language/english/modinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@
define('_MI_SYSTEM_PREFERENCE_ANONPOST', '');
define('_MI_SYSTEM_PREFERENCE_REDIRECT', '');
define('_MI_SYSTEM_PREFERENCE_JQUERY_THEME', 'jQuery theme');
//2.5.11
define('_MI_DEFAULT_NOTIFICATION_METHOD_DISABLE', 'Temporarily disable');
define('_MI_DEFAULT_NOTIFICATION_METHOD_EMAIL', 'Email');
define('_MI_DEFAULT_NOTIFICATION_METHOD_PM', 'Private message');
9 changes: 9 additions & 0 deletions htdocs/modules/system/xoops_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,12 @@
$modversion['config'][$i]['formtype'] = 'hidden';
$modversion['config'][$i]['valuetype'] = 'int';
$modversion['config'][$i]['default'] = 0;
//2.5.11
++$i;
$modversion['config'][$i]['name'] = 'default_notification';
$modversion['config'][$i]['title'] = '_MD_AM_DEFAULT_NOTIFICATION_METHOD';
$modversion['config'][$i]['description'] = '_MD_AM_DEFAULT_NOTIFICATION_METHOD_DESC';
$modversion['config'][$i]['formtype'] = 'select';
$modversion['config'][$i]['valuetype'] = 'int';
$modversion['config'][$i]['default'] = 3;
$modversion['config'][$i]['options'] = [_MI_DEFAULT_NOTIFICATION_METHOD_DISABLE => 0, _MI_DEFAULT_NOTIFICATION_METHOD_PM => 1, _MI_DEFAULT_NOTIFICATION_METHOD_EMAIL => 2];
3 changes: 3 additions & 0 deletions htdocs/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
redirect_header('index.php', 6, _US_NOREGISTER);
}

require_once $GLOBALS['xoops']->path('include/notification_constants.php');

/**
* @param $uname
* @param $email
Expand Down Expand Up @@ -161,6 +163,7 @@ function userCheck($uname, $email, $pass, $vpass)
$newuser->setVar('umode', $GLOBALS['xoopsConfig']['com_mode'], true);
$newuser->setVar('theme', $GLOBALS['xoopsConfig']['theme_set'], true);
$newuser->setVar('user_mailok', $user_mailok, true);
$newuser->setVar('notify_method', (isset($xoopsConfigUser['default_notification']) ? $xoopsConfigUser['default_notification'] : XOOPS_NOTIFICATION_METHOD_PM));
if ($xoopsConfigUser['activation_type'] == 1) {
$newuser->setVar('level', 1, true);
} else {
Expand Down
124 changes: 123 additions & 1 deletion upgrade/upd_2.5.10-to-2.5.11/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct()
'templates',
'templatesadmin',
'zapsmarty',
'notificationmethod',
);
$this->usedFiles = array();
$this->pathsToCheck = array(
Expand Down Expand Up @@ -622,7 +623,7 @@ public function check_modulesvarchar()
{
$migrate = new Tables();
$count = $this->fromSmallintToVarchar($migrate, $this->modulesTableName, $this->modulesColumnNames);
return $count == 0;
return $count==0;
}

/**
Expand Down Expand Up @@ -780,6 +781,127 @@ public function apply_zapsmarty()
return true;
}

/**
* Check if default notification method already exists
*
*/
public function check_notificationmethod()
{
$sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('config') . "` WHERE `conf_name` IN ('default_notification')";
if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
return false;
}
return true;
}

/**
* @return bool
*/
public function apply_notificationmethod()
{
$returnResult = true;
$notification_method = false;
$sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('config') . "` WHERE `conf_name` = 'default_notification'";
if ($result = $GLOBALS['xoopsDB']->queryF($sql)) {
list($count) = $GLOBALS['xoopsDB']->fetchRow($result);
if ($count == 1) {
$notification_method = true;
}
}

if (!$notification_method) {
$sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('config') . ' (conf_id, conf_modid, conf_catid, conf_name, conf_title, conf_value, conf_desc, conf_formtype, conf_valuetype, conf_order) ' . ' VALUES ' . " (NULL, 0, 2, 'default_notification', '_MD_AM_DEFAULT_NOTIFICATION_METHOD', '1', '_MD_AM_DEFAULT_NOTIFICATION_METHOD_DESC', 'select', 'int', 3)";

if (!$GLOBALS['xoopsDB']->queryF($sql)) {
return false;
}
$config_id = $GLOBALS['xoopsDB']->getInsertId();

$sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('configoption') . ' (confop_id, confop_name, confop_value, conf_id)'. ' VALUES'
. " (NULL, '_MI_DEFAULT_NOTIFICATION_METHOD_DISABLE', '0', {$config_id}),"
. " (NULL, '_MI_DEFAULT_NOTIFICATION_METHOD_PM', '1', {$config_id}),"
. " (NULL, '_MI_DEFAULT_NOTIFICATION_METHOD_EMAIL', '2', {$config_id})";
if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
return false;
}
}

return $returnResult;
}

/**
* @return bool
*/
public function apply_templatesadmin()
{
include XOOPS_ROOT_PATH . '/modules/system/xoops_version.php';
$dbm = new Db_manager();
$time = time();
foreach ($modversion['templates'] as $tplfile) {
// Admin templates
if (isset($tplfile['type']) && $tplfile['type'] === 'admin' && $fp = fopen('../modules/system/templates/admin/' . $tplfile['file'], 'r')) {
$newtplid = $dbm->insert('tplfile', " VALUES (0, 1, 'system', 'default', '" . addslashes($tplfile['file']) . "', '" . addslashes($tplfile['description']) . "', " . $time . ', ' . $time . ", 'admin')");
$tplsource = fread($fp, filesize('../modules/system/templates/admin/' . $tplfile['file']));
fclose($fp);
$dbm->insert('tplsource', ' (tpl_id, tpl_source) VALUES (' . $newtplid . ", '" . addslashes($tplsource) . "')");
}
}

return true;
}

//modules/system/themes/legacy/legacy.php
/**
* Do we need to delete obsolete Smarty files?
*
* @return bool
*/
public function check_zapsmarty()
{
return !file_exists('../class/smarty/smarty.class.php');
}

/**
* Delete obsolete Smarty files
*
* @return bool
*/
public function apply_zapsmarty()
{
// Define the base directory
$baseDir = '../class/smarty/';

// List of sub-folders and files to delete
$itemsToDelete = array(
'configs',
'internals',
'xoops_plugins',
'Config_File.class.php',
'debug.tpl',
'Smarty.class.php',
'Smarty_Compiler.class.php'
);

// Loop through each item and delete it
foreach ($itemsToDelete as $item) {
$path = $baseDir . $item;

// Check if it's a directory or a file
if (is_dir($path)) {
// Delete directory and its contents
array_map('unlink', glob("$path/*.*"));
rmdir($path);
} elseif (is_file($path)) {
// Delete file
if (is_writable($path)) {
unlink($path);
}
}
}

return true;
}


}

Expand Down

0 comments on commit 838aafa

Please sign in to comment.