fix mailman bug (exception thrown on subscribe/unsubscribe in nonpublic lists)…

fix mailman bug (exception thrown on subscribe/unsubscribe in nonpublic lists) introduced by 8466d2b2
parent fd1a2f5b
......@@ -66,40 +66,55 @@ if(!class_exists('Mailman_Integration'))
/**
* Helper to fetch and parse the list settings field from DB
* @param $public Fetch public lists only. If false, fetches non-public lists only.
* @param $public What lists to fetch. Permitted values: 'all', 'public', 'private'.
*
* Followed by two helpers that fetch private and public lists' settings, respectively.
*/
public static function getListSettings($public = true){
if($public){
$mmi_setting = get_option('mmi_mailing_lists');
if(null != trim($mmi_setting) && "{}" != trim($mmi_setting))
$mmi_setting = json_decode($mmi_setting);
else
$mmi_setting = (object)array();
public static function getListSettings($public = 'all'){
switch ($public) {
case 'public':
return self::getPublicListSettings();
case 'private':
return self::getPrivateListSettings();
case 'all':
default:
$mmi_public = (array) self::getPublicListSettings();
$mmi_private = (array) self::getPrivateListSettings();
return (object) array_merge($mmi_private, $mmi_public);
}
else {
$mmi_setting = get_option('mmi_mailing_lists_nonpublic');
if(null != trim($mmi_setting)){
$setting_temp = preg_split("/\R/", $mmi_setting);
$mmi_setting = array();
if(is_array($setting_temp)){
foreach($setting_temp as $s){
$s = explode('|', $s);
$mmi_setting[trim($s[1])] = (object)array('name' => trim($s[1]), 'title'=>trim($s[0]), 'password'=>$s[2]);
}
}
else{
$s = explode('|', $setting_temp);
}
private static function getPublicListSettings() {
$mmi_setting = get_option('mmi_mailing_lists');
if(null != trim($mmi_setting) && "{}" != trim($mmi_setting))
$mmi_setting = json_decode($mmi_setting);
else
$mmi_setting = (object)array();
return $mmi_setting;
}
private static function getPrivateListSettings() {
$mmi_setting = get_option('mmi_mailing_lists_nonpublic');
if(null != trim($mmi_setting)){
$setting_temp = preg_split("/\R/", $mmi_setting);
$mmi_setting = array();
if(is_array($setting_temp)){
foreach($setting_temp as $s){
$s = explode('|', $s);
$mmi_setting[trim($s[1])] = (object)array('name' => trim($s[1]), 'title'=>trim($s[0]), 'password'=>$s[2]);
}
$mmi_setting = (object)$mmi_setting;
}
else
$mmi_setting = (object)array();
else{
$s = explode('|', $setting_temp);
$mmi_setting[trim($s[1])] = (object)array('name' => trim($s[1]), 'title'=>trim($s[0]), 'password'=>$s[2]);
}
$mmi_setting = (object)$mmi_setting;
}
else
$mmi_setting = (object)array();
return $mmi_setting;
}
......
......@@ -9,9 +9,7 @@
//require_once(sprintf("%s/../Services/Mailman.php", dirname(__FILE__)));
$mailman = new Services_Mailman($mmi_url);
$lists = (array) Mailman_Integration::getListSettings();
$nonpublic_lists = (array) Mailman_Integration::getListSettings(false);
$lists = (object) array_merge($nonpublic_lists, $lists);
$lists = Mailman_Integration::getListSettings();
if( null != $lists ) : ?>
<h2 class="nav-tab-wrapper wp-clearfix">
......@@ -65,6 +63,15 @@
else :
?><p style="color:red">There are no mailing lists to manage. Go to the <a href="options-general.php?page=mailman_integration">Mailman Integration settings page</a> and fill in your list details first.</p><?php
endif;
/* $mailman = new Services_Mailman('http://steampunkgbg.se/mailman/admin', 'medlemmar_steampunkgbg.se', 'OuT6qG%rEqsg');
$mailman->subscribe('narnigrin@gmail.com');*/
?>
</div>
......
......@@ -71,9 +71,7 @@
$mmi_url = get_option('mmi_admin_list_url');
$mailman = new Mailman_With_Moderation($mmi_url);
$lists = (array) Mailman_Integration::getListSettings();
$nonpublic_lists = (array) Mailman_Integration::getListSettings(false);
$lists = (object) array_merge($nonpublic_lists, $lists);
$lists = Mailman_Integration::getListSettings();
if ( null != $lists ) : ?>
<h2 class="nav-tab-wrapper wp-clearfix">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment