Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-09-20 21:20:14

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

patching mem_postmaster, guidance would be appreciated

Hi plugin devs.

I’m currently trying to patch mem_postmaster to play more nicely with recent TXP releases (4.5+).
Let me state first that the plugin is somewhat working OK, but I’m trying to bring back a particular functionality that is not working properly now that articles are saved ajax-ly on TXP 4.5+.

For those that don’t know the plugin, it basically lets you send emails to subscribers (and manage the subscribers).
Emails can be sent from the Write tab (a.k.a. email-on-post).

So, for this functionality of sending emails from the Write tab, the plugin adds a fieldset to the UI, with a few fields and buttons.

Those “Send to List” and “Send to Test” buttons are simple two save buttons, so, when the user clicks on any of them, the form is submitted (via AJAX) and the article is saved..

<input type="submit" name="save" value="Send to List" class="publish">
<input type="submit" name="save" value="Send to Test" class="publish">

On the backend, mem_postmaster registers a few callbacks. I copy here only the lines related to the callback I’m interested in.

...
	register_callback("bab_pm_eop", 'article' , 'edit', '0');
	register_callback("bab_pm_eop", 'article' , 'save', '0');
	register_callback("bab_pm_eop", 'article' , 'publish', '0');
        ...

So, when the save step on the article event is called, the plugin runs this bab_pm_eop function.
Here is the function. (Ignore some weird variable names like $bab_pm_radio, which are leftovers of the original ben_postmaster plugin that preceded mem_postmaster.)

// ----------------------------------------------------------------------------
// email on post -- this is called after you click "Save"

function bab_pm_eop()
{
	$bab_pm_PrefsTable = safe_pfx('bab_pm_list_prefs');
	$bab_pm_SubscribersTable = safe_pfx('bab_pm_subscribers');

	$bab_pm_radio = ps('bab_pm_radio'); // this is whether to mail or not, or test
	$save = ps('save');
	if ($save == 'Send to Test')
		$bab_pm_radio = 2;
	if ($save == 'Send to List')
		$bab_pm_radio = 1;
	$listToEmail = ps('listToEmail'); // this is the list name
	$artID=ps('ID');
	$sendFrom=ps('sendFrom');

	// ---- scrub the flag column for next time:
	if ($bab_pm_radio)
	{
		$result = safe_query("UPDATE $bab_pm_SubscribersTable SET flag = NULL");

		$path = "?event=postmaster&step=initialize_mail&radio=$bab_pm_radio&list=$listToEmail&artID=$artID";
		if (!empty($sendFrom)) $path .= '&sendFrom='.urlencode($sendFrom);
		header("HTTP/1.x 301 Moved Permanently");
		header("Status: 301");
		header("Location: ".$path);
		header("Connection: close");
	}
} // end bab_pm_eop

The part I’m mostly interested it’s the redirect happening at the end of the function. When the “Send to List” (or the “Send to Test”) button is pressed, the article is saved via AJAX, but the redirect doesn’t happen on the front-end.
That said, I can see in the Web Inspector that the corresponding URL (the one on the $path appears in the Network tab and that the batch email sending is triggered (and I can confirm that emails are received).

Click to enlarge:

Click to enlarge:

So, the functionality I’d like to restore is this: when the “Send to List” button is clicked, the “save article ajax-ly” magic doesn’t kick in and the user is redirected to the bulk email sending page.

Please, could someone point me how could I approach to solve this issue? I’m not asking for the full solution (but, hey, if you are tempted to give a try, I won’t oppose it), but maybe some hints or high-level directions on where to look.
BTW, in case anyone would like to take a peek at the full plugin code, you can fetch the plugin installer here (it has some minor patches I’ve already applied). You will also need the mem_postmaster_library.

Thanks!


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2014-09-21 14:00:31

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: patching mem_postmaster, guidance would be appreciated

Hi Julián,

long shot: you have to do redirects in js now, but I don’t know if some js event is fired when an article is saved, to give you the possibility to plug in. Might be talking bs too. :)

Offline

#3 2014-09-25 12:50:58

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: patching mem_postmaster, guidance would be appreciated

hi etc,
thanks for the suggestion. I’ll look into doing the redirect on JS.
I’ll also look into the “article_saved” callback, to see if there is a way to trigger the redirect directly on the server side.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB