diff --git a/public_html/lists/admin/languages.php b/public_html/lists/admin/languages.php
index 098169cd1..4ee97ef0d 100644
--- a/public_html/lists/admin/languages.php
+++ b/public_html/lists/admin/languages.php
@@ -297,7 +297,7 @@ public function databaseTranslation($text)
}
$tr = Sql_Fetch_Row_Query(sprintf('select translation from '.$GLOBALS['tables']['i18n'].' where original = "%s" and lan = "%s"',
- sql_escape(trim($text)), $this->language), 1);
+ sql_escape(trim($text ?? '')), $this->language), 1);
if (empty($tr[0])) {
$tr = Sql_Fetch_Row_Query(sprintf('select translation from '.$GLOBALS['tables']['i18n'].' where original = "%s" and lan = "%s"',
sql_escape($text), $this->language), 1);
@@ -514,7 +514,7 @@ public function getTranslation($text)
public function get($text)
{
- if (trim($text) == '') {
+ if (trim($text ?? '') == '') {
return '';
}
if (strip_tags($text) == '') {
diff --git a/public_html/lists/admin/spageedit.php b/public_html/lists/admin/spageedit.php
index e1f569790..61df0aad4 100644
--- a/public_html/lists/admin/spageedit.php
+++ b/public_html/lists/admin/spageedit.php
@@ -108,10 +108,21 @@
}
Sql_Query(sprintf('replace into %s (id,name,data) values(%d,"attributes","%s")',
$tables['subscribepage_data'], $id, $attributes));
+ $preselectList = 0;
+ if (!empty($_POST['preselectlist'])) {
+ $preselectList = (int) $_POST['preselectlist'];
+ }
if (isset($_POST['list']) && is_array($_POST['list'])) {
+ if (!$preselectList || !isset($_POST['list'][$preselectList])) {
+ $preselectList = 0;
+ }
Sql_Query(sprintf('replace into %s (id,name,data) values(%d,"lists","%s")',
$tables['subscribepage_data'], $id, implode(',', $_POST['list'])));
+ } else {
+ $preselectList = 0;
}
+ Sql_Query(sprintf('replace into %s (id,name,data) values(%d,"preselectlist","%d")',
+ $tables['subscribepage_data'], $id, $preselectList));
//## Store plugin data
foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
@@ -144,6 +155,7 @@
$data['unsubscribesubject'] = getConfig('unsubscribesubject');
$data['htmlchoice'] = 'htmlonly';
$data['emaildoubleentry'] = 'yes';
+$data['preselectlist'] = 0;
$data['rssdefault'] = 'daily'; //Leftover from the preplugin era
$data['rssintro'] = s('Please indicate how often you want to receive messages'); //Leftover from the preplugin era
$selected_lists = array();
@@ -192,7 +204,7 @@
$generalinfoHTML .= sprintf('',
s('Title'),
- htmlspecialchars(stripslashes($data['title'])));
+ htmlspecialchars(stripslashes($data['title'] ?? '')));
$language_files = array();
$language_file = $GLOBALS['language_module'];
@@ -220,24 +232,24 @@
$generalinfoHTML .= sprintf('',
s('Intro'),
- htmlspecialchars(stripslashes($data['intro'])));
+ htmlspecialchars(stripslashes($data['intro'] ?? '')));
$generalinfoHTML .= sprintf('',
s('Header'),
- htmlspecialchars(stripslashes($data['header'])));
+ htmlspecialchars(stripslashes($data['header'] ?? '')));
$generalinfoHTML .= sprintf('',
s('Footer'),
- htmlspecialchars(stripslashes($data['footer'])));
+ htmlspecialchars(stripslashes($data['footer'] ?? '')));
$generalinfoHTML .= sprintf('',
s('Thank you page'),
- htmlspecialchars(stripslashes($data['thankyoupage'])));
+ htmlspecialchars(stripslashes($data['thankyoupage'] ?? '')));
$generalinfoHTML .= sprintf('',
s('Text to display when subscription with an AJAX request was successful'),
- htmlspecialchars(stripslashes($data['ajax_subscribeconfirmation'])));
+ htmlspecialchars(stripslashes($data['ajax_subscribeconfirmation'] ?? '')));
$generalinfoHTML .= sprintf('',
s('Text for Button'),
- htmlspecialchars(stripslashes($data['button'])));
+ htmlspecialchars(stripslashes($data['button'] ?? '')));
$generalinfoHTML .= sprintf('', s('HTML Email choice'));
$generalinfoHTML .= sprintf('
%s
',
@@ -281,24 +293,24 @@
$transactionHTML .= '
| '.s('Attribute').': '.$row['id'].' | '; $attributesHTML .= ''.s('Check this box to use this attribute in the page').' | |||||||||||
| '.s('Name').': | '.htmlspecialchars(stripslashes($row['name'])).' | |||||||||||
| '.s('Name').': | '.htmlspecialchars(stripslashes($row['name'] ?? '')).' | |||||||||||
| '.s('Type').': | '.s($row['type']).' | |||||||||||
| '.s('Default Value').': | ||||||||||||
| '.s('Default Value').': | ||||||||||||
| '.s('Order of Listing').': | '; $attributesHTML .= ' | '.s('Is this attribute required?').': | '.s('Select the lists to offer').'';
-$listsHTML .= ' ';
+$listsHTML .= ' '; // accordion
+echo '
+';
+
$ownerHTML = $singleOwner = '';
$adminCount = 0;
if (isSuperUser() || accessLevel('spageedit') == 'all') {
diff --git a/public_html/lists/admin/subscribelib2.php b/public_html/lists/admin/subscribelib2.php
index cc014e97a..eb5b6a16a 100644
--- a/public_html/lists/admin/subscribelib2.php
+++ b/public_html/lists/admin/subscribelib2.php
@@ -713,12 +713,31 @@
}
}
+/**
+ * Determine whether a list checkbox should be preselected.
+ *
+ * @param bool $hasExplicitListSelection
+ * @param int $preselect_list_id
+ * @param int $listId
+ * @param mixed $rowPreselect
+ * @return bool
+ */
+function shouldPreselectList($hasExplicitListSelection, $preselect_list_id, $listId, $rowPreselect)
+{
+ return !$hasExplicitListSelection &&
+ (
+ ($preselect_list_id && $preselect_list_id == $listId) ||
+ (!$preselect_list_id && !empty($rowPreselect))
+ );
+}
+
/**
* @param int $userid
* @param string $lists_to_show
+ * @param int $preselect_list_id
* @return string
*/
-function ListAvailableLists($userid = 0, $lists_to_show = '')
+function ListAvailableLists($userid = 0, $lists_to_show = '', $preselect_list_id = 0)
{
global $tables;
if (isset($_POST['list'])) {
@@ -730,6 +749,9 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
} else {
$list = '';
}
+ $hasExplicitListSelection = isset($_POST['list'])
+ || (!isset($_POST['subscribe']) && isset($_GET['list']) && preg_match("/^(\d+,)*\d+$/", $_GET['list']));
+ $preselect_list_id = (int) $preselect_list_id;
$subselect = '';
$listset = array();
$subscribed = array();
@@ -766,7 +788,14 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
while ($row = Sql_fetch_array($catresult)) {
- $listspercategory[] = array('id' => $row ['id'], 'name' => $row ['name'], 'description' => $row ['description'], 'active' => $row ['active'], 'category' => $row ['category']);
+ $listspercategory[] = array(
+ 'id' => $row['id'],
+ 'name' => $row['name'],
+ 'description' => $row['description'],
+ 'active' => $row['active'],
+ 'category' => $row['category'],
+ 'preselect' => isset($row['preselect']) ? $row['preselect'] : 0,
+ );
}
@@ -803,6 +832,13 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
if (Sql_Affected_Rows()) {
$html .= 'checked="checked"';
}
+ } elseif (shouldPreselectList(
+ $hasExplicitListSelection,
+ $preselect_list_id,
+ $listelement['id'],
+ $listelement['preselect']
+ )) {
+ $html .= 'checked="checked"';
}
@@ -844,6 +880,13 @@ function ListAvailableLists($userid = 0, $lists_to_show = '')
if (Sql_Affected_Rows()) {
$html .= 'checked="checked"';
}
+ } elseif (shouldPreselectList(
+ $hasExplicitListSelection,
+ $preselect_list_id,
+ $row['id'],
+ isset($row['preselect']) ? $row['preselect'] : 0
+ )) {
+ $html .= 'checked="checked"';
}
$html .= " /> ';
$listsHTML .= sprintf(' ';
@@ -401,6 +445,36 @@
echo '', s('Display list categories')); $listsHTML .= sprintf('%s ', @@ -374,6 +386,7 @@ } else { $listsHTML .= ' '.s('If you do not choose a list here, all public lists will be displayed.'); + $listsHTML .= ' '.s('One list may be chosen to be selected by default on the subscribe page.'); $hideSingle = getConfig('hide_single_list'); if ($hideSingle) { $listsHTML .= ' '.s('If you choose one list only, a checkbox for this list will not be displayed and the subscriber will automatically be added to this list.'); @@ -382,11 +395,42 @@ } } $listsHTML .= ''; +$preselectList = (int) $data['preselectlist']; +if (!in_array($preselectList, $selected_lists)) { + $preselectList = 0; +} +$listsHTML .= '
';
$desc = nl2br(disableJavascript(stripslashes($row['description'])));
diff --git a/public_html/lists/index.php b/public_html/lists/index.php
index db494c541..81b52186e 100644
--- a/public_html/lists/index.php
+++ b/public_html/lists/index.php
@@ -532,7 +532,11 @@ function checkEmail()
}
}
- $html .= ListAvailableLists($userid, $GLOBALS['pagedata']['lists']);
+ $html .= ListAvailableLists(
+ $userid,
+ $GLOBALS['pagedata']['lists'],
+ isset($GLOBALS['pagedata']['preselectlist']) ? (int) $GLOBALS['pagedata']['preselectlist'] : 0
+ );
if (isBlackListedID($userid)) {
$html .= $GLOBALS['strYouAreBlacklisted'];
}
@@ -690,7 +694,11 @@ function checkGroup(name,value)
$html .= $plugin->displaySubscriptionChoice($GLOBALS['pagedata']);
}
}
- $html .= ListAvailableLists('', $GLOBALS['pagedata']['lists']);
+ $html .= ListAvailableLists(
+ '',
+ $GLOBALS['pagedata']['lists'],
+ isset($GLOBALS['pagedata']['preselectlist']) ? (int) $GLOBALS['pagedata']['preselectlist'] : 0
+ );
if (empty($GLOBALS['pagedata']['button'])) {
$GLOBALS['pagedata']['button'] = $GLOBALS['strSubmit'];
@@ -799,7 +807,11 @@ function subscribePage2($id)
$html .= formStart();
$html .= ' | |||||||||