Initiating NS Pro Actions via custom code

1 year 7 months ago #1 by Chris Paschen
Initiating NS Pro Actions via custom code was created by Chris Paschen
I'm building custom components and would like to consider switching our existing implementation (AcyMailing) to NSPro.
Is it possible to do the following actions via API or class/function calls from our custom components?
  • Create a new list
  • Add/subscribe a user to a list
  • Send an existing email (created in NSPro) to a list
  • Send an existing email (created in NSPro) to an individual email recipient
  • Create a new email (to be sent later)
  • Use custom data within an existing email that we send (i.e. provide values for custom fields on the fly via code)
If any of these are possible, could you provide information/documentation on how we could do any of these processes?

Please Log in or Create an account to join the conversation.

1 year 7 months ago - 1 year 7 months ago #2 by Christopher Mavros
Replied by Christopher Mavros on topic Initiating NS Pro Actions via custom code
Hello Chris and thank you for your post! I apologize for the late response. I had to dig in a little to provide an accurate response to your post.
In JPATH_ADMINISTRATOR/components/com_nspro/lib.php you can find many useful functions.

1. Creating a list is as simple as creating a record in the database. They don't carry any specific information, other than their database ID. You can simply add a record in the `#__nspro_lists` table. If you'd prefer, I can write a simple function to do that in the lib.php file.

2. In order to add/delete a subscriber to/from a list, you can use the following two functions found in the lib.php file.
function DoRemoveListsFromSubscriber($mailing_lists, $sub_id) { ... }
function DoAddListsToSubscriber($mailing_lists, $sub_id) { ... }

The $mailing_lists argument can either be a comma separated string or an array of mailing list database IDs.
The $sub_id is the subscriber numeric ID.

3. In order to send a newsletter to a list, you would need to do one of the following:
Option A: You could change the newsletter's lists in the database, in the `#__nspro_newsletter_lists` db table, which is a simple map of newsletter IDs to mailing list IDs and then use the send function of the sending model.
  function send($cids, $source = 'model') { ... }

In order to load this model, you can write:
  JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_nspro/models');
  $model = JModelLegacy::getInstance('sending', 'NsproModel');


Option B: You can manipulate the Joomla ApplicationInput and leverage the toolkit functions. In the toolkit model, you can find these functions:
  function newsletterToMail() { ... }
  function newsletterToSelectedSubs() { ... }


Both functions except to find a newsletterIdToSend variable in the Joomla input. The first one expects an emailToSend variable in the input, which is a string of the recipient's email address and the second one expects a subscribersToSend variable in the input, which is an array of integer subscriber IDs.

4. Answered above in option B.

5. Creating a new newsletter programmatically wouldn't be as easy, because it has a lot of fields. Essentially, you would have to replicate the newsletter edit form and save it by sending the input to the newsletter.save controller built-in function. If you need to do this, we could implement a lib function with the necessary arguments as a minimum input, and an optional argument with additional options, to cover the rest of the newsletter fields.

6. In lib.php, there's a function called FilterNewsletterSmartText. This function was initially designed to allow PHP. We have disabled that by writing a hard-coded $php_allowed = false; line, but I could move that variable in the function declaration as an argument, and allow you to run your own PHP code in the newsletter, enclosed in {?php ?} instead of <?php ?>

Wrapping up. With a few changes from our side, you can do all these processes programmatically and switch to NS Pro.
We would love to have you on board.

Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!

Please Log in or Create an account to join the conversation.

1 year 7 months ago #3 by Chris Paschen
Replied by Chris Paschen on topic Initiating NS Pro Actions via custom code
Thanks. That all sounds like this might be a way for us to move forward.

I'll take a look at the code and see how difficult this might be for us to implement.

Would you be open to reviewing code from us if we were to contribute it to you/the project to implement some of these issues, and if it meets your standards, incorporate it into the project?
I realize that some of these might not be things that other users are demanding, but might be an added benefit.
And I'd prefer to contribute code rather than do a custom fork just for our needs.

I have at least 2 projects that would need this functionality (possibly more).

I'm expecting a commitment now to accept code (esp. without you seeing it).
I'm just wondering if you are open to contributed code to be 'considered'?
 

Please Log in or Create an account to join the conversation.

1 year 7 months ago #4 by Christopher Mavros
Replied by Christopher Mavros on topic Initiating NS Pro Actions via custom code
Hi again Chris.
If you would like to contribute code into the lib.php file, in order to facilitate any of your requirements, I would happily consider it and include it into the project.
What I wouldn't want, would be to alter existing code that is used from other parts of NS Pro, or other projects, to avoid breaking compatibility.

Let me know if you need any further assistance!
Thanks again.

Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!

Please Log in or Create an account to join the conversation.

1 year 7 months ago #5 by Chris Paschen
Replied by Chris Paschen on topic Initiating NS Pro Actions via custom code
I understand completely.
I'll take a bit of time over the next few weeks to take a look at the existing code, along with the notes you shared, and see what would be needed and I'll try to keep my coding within the structures/styles that you are using and if/when I do have anything to share I'll let you know.

Do you have a git repository somewhere that I should use for contributions?
Or just upload them here?

Please Log in or Create an account to join the conversation.

1 year 7 months ago #6 by Christopher Mavros
Replied by Christopher Mavros on topic Initiating NS Pro Actions via custom code
I have a git repository in Github, but we have some CI/CD actions in place. We can see what we can do.

For now, I can give you read access if that could simplify things for you, and see what needs to be done to allow you to create a pull request.

Let me know via email at me@mavrosxristoforos.com.

Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!

Please Log in or Create an account to join the conversation.

Moderators: Christopher Mavros