HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Follow-up email after download

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#99173 (In Topic #19506)
TQ
Avatar

Honoured member

Hi All

Is there any way I can get the site to automatically send a follow-up email to a member once they have downloaded a file from my site. Ideally it would be a standard message with a variable for the file title or file name they downloaded.

Any help would be much appreciated.

Nick
Back to the top
 
Posted
Rating:
#99181
Avatar

Community saint

As far as I know that would take some custom programming.
Back to the top
 
Posted
Rating:
#99187
TQ
Avatar

Honoured member

Hi Duck,
 
That's disappointing news but you can't have everything!
 
I run a niche hobby site that is 95% download orientated, not because I want it that way but because I think my users are on a mission when they come to the site for the software they need. They Google what they are looking for, create an account, download the file and are gone.
 
They are generally clever people and could contribute in a number of ways to the benefit of other 2000+ members.
 
I'd like to interact with them on a personal basis but don't want to flood them with general messages so that they put me into their spam list hence the wish to email them once they have downloaded something of benefit to them.
 
Frankly, I wouldn't know where to start with custom programming so if anyone else has any pointers or ideas I'd be all ears.
 
Nick
hamfiles.co.uk
Back to the top
 
Posted
Item has a rating of 5 (Liked by Chris Graham)  
Rating:
#99193
Avatar

Community saint

TQ said

Frankly, I wouldn't know where to start with custom programming so if anyone else has any pointers or ideas I'd be all ears.
If you are using the download system (i.e. don't just have direct links to the files) then every download will go through one central script (dload_script() in /downloads2.php if I'm not mistaken) so you can trigger the emails from there.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#99194
Avatar

Community saint

Well one idea could be to require membership to download and you could use the newsletter system to email the group once a month.

This would require no custom programming of course but as you say may not be as conservative as a single email per download per person.

If that doesn't work for you I could look at the file Temp1024 mentioned and see if I can come up with that tailored solution but I wouldn't have time for that till later in the week.
Back to the top
 
Posted
Rating:
#99196
TQ
Avatar

Honoured member

My thanks to both Duck and TEMP1024 for taking the time.
 
I set all downloads to require points to download so that the user has to become a member to download anything.
 
I feel that the type of generic message I want to send could be repeated every time they download but would not be appropriate to send to every member on the system however infrequently.
 
The message itself is basically an few words of encouragement to get them to give something back to the site in the form of a comment about the download or a star rating, forum entry etc. etc. If this was sent within 24 hours of the download I think it would be less likey to be viewed as spam.
 
I've looked at downloads2.php and realise it is way outside my scope. Don't get me wrong, if I have to learn enough PHP to do what I want, I am willing to try but this would push the end result down the road by weeks or more realistically months.
 
Duck, it is very kind of you to offer to look at the download2.php code. If you are still feeling as generous when you do have a spare moment I'd be in your debt. Should you need any clarity on what I'm hoping to achieve please let me know.
 
Thanks again to you both
 
Nick
hamfiles.co.uk
Back to the top
 
Posted
Item has a rating of 5 (Liked by Chris Graham)  
Rating:
#99201
Avatar

Community saint

Just thought I'd add a couple of notes to this...

I like Temp1024's idea to modify the downloads2.php, but I would probably use the 'Replacing/supplementing a file' (http://ocportal.com/docs9/tut_framework.htm) documentation to override the log_download() function at the end of the downloads2.php and place the email sending code right in that function. The main reason I'd do it that way is make it less likely to break with future ocPortal updates and make it much easier (the log_download function if very simple and small) to fix if something were to break.

Another concern I would have is what other parts of ocPortal might be using the downloads2.php. If the code is reused in other areas such as attachments or gallery downloads, then people would get emails for those downloads as well.  I don't think that's the case, but I'd have to search the code to be sure. Sort of along these lines, it might be beneficial to add an option to define download categories that should or shouldn't be exempted from receiving emails.  That way you could have free download categories that wouldn't generate unnecessary or unwanted emails.

Another concern is that none of the above will be able to track the number of emails sent per user per day.  There is a $got_before variable passed to the log_download function that I'm assuming determines whether the currently logged in user has downloaded that file before.  If so, that could be used to make it so emails are only generated the first time the user downloads the file. But, if a user downloads 20 different files in a day then they would get 20 emails that same day.  A quick and dirty hack would be to use the download_logging database table.  It only tracks the download id and when the last download was per user so it won't be perfect for determining whether someone should get an email or not, but it should be workable.  A better fix for that situation would require a new database table to track when download emails are sent per user.  It could all be done by hand and hard coded, but the ideal solution would require a new addon to be created that would generate the necessary database tracking table so users would not get more than one email in a certain period time which could be configurable and more accurate than relying on the download_logging table. I suppose a new addon could also include a configuration option for defining the download category IDs as mentioned above and also include the log_download override as well as an editable email template. 

It might also be beneficial to give an option to tie emails in with email preferences for newsletters perhaps.  The site admin could enable a 'Tie in with newsletter email preference' option and if the user is not subscribed then they wouldn't get any download system emails.  Disable the option and a user would always get the emails.  Or a new Notification would need to be created and the user could turn it on or off from their profile settings.

I guess now that I think about it, this might not be as hard as I thought...I'll take a shot at turning this into an addon this week.
Back to the top
 
Posted
Item has a rating of 5 (Liked by Jason Verhagen)  
Rating:
#99202
Avatar

Community saint

Excellent points Jason and I am glad you are going to tackle it as I think it's an excellent idea for an addon.

You got me thinking though with your ideas might it be also an idea to set the downloads email as a cron job that runs say once a day (or something like that) and that just uses the downloads logging to determine if an email needs sent? You could select a distinct user from the logs and send only one email per user this way you wouldn't need an additional tracking table (well except maybe some way to track last run time of the query I suppose?)
Back to the top
 
Posted
Item has a rating of 5 (Liked by Jason Verhagen)  
Rating:
#99206
Avatar

Community saint

Jason Verhagen said

I would probably use the 'Replacing/supplementing a file' (http://ocportal.com/docs9/tut_framework.htm) documentation to override the log_download() function
Function overriding is absolutely the way to go. I've done that before an it works a treat.

Jason Verhagen said

The main reason I'd do it that way is make it less likely to break with future ocPortal updates and make it much easier (the log_download function if very simple and small) to fix if something were to break.
With function overriding you don't have to touch the original code.  Your log_download() would just contain the new email notification code and then call the original log_download() using the non_overrided__log_download() mechanism.

Duck said

it be also an idea to set the downloads email as a cron job that runs say once a day (or something like that) and that just uses the downloads logging to determine if an email needs sent?
Good idea.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#99211
TQ
Avatar

Honoured member

Once again, thanks to everyone for their input.
 
Jason, you've clearly put a lot of thought into this idea and an addon would be perfect. If you can find the time you know your efforts would be appreciated.
 
Nick
Back to the top
 
Posted
Item has a rating of 5 (Liked by Duck)  
Rating:
#99354
Avatar

Community saint

Here is a quick update. I started simple (no file or function overrides needed) and implemented the suggestion to use the download log and cron to generate and send notifications once per day. Right now it consists of a cron hook to run the task once every 24 hours, a notification hook to handle the notifications, and a language .ini file to configure a message subject and body for the notification that is sent. The admin can use Adminzone->Setup->Notification Lock-down to force the notification or make it optional (it's optional by default). If optional, the user can select which download categories will generate follow-up emails. The way it's setup now it will only send one email per user per day and it won't pass download names or other specific download information to the notification, so the notification subject/body are very basic and generic. Since this uses a cron hook, I believe you will need cron_bridge.php running on a regular schedule via a cron job setup on your web hosting account or by some alternate method (see here: http://ocportal.com/docs9/tut_configuration.htm#title__11). I'll get it tested and make sure it works as intended and then upload it to the github repository and add it to the addons download area for anybody that wants to use it in its current state.

I would still like to add more features to allow more detailed emails, allow emails to be sent immediately instead of waiting for the cron job to generate them, and add some configuration options for various things (which categories user can disable notifications for, how often to run the cron job, custom subject/body notification text). But I've got some questions about how and where to implement the install/uninstall functions if I'm adding functionality to an existing bundled module and not implementing new block or module. I'll start a new topic for that when I get that far if I haven't figured it out by then. 

Also, I think I have a couple of ways to do immediate emails without tracking them in a separate database table, but I may need to do some testing to be sure the code is efficient enough for high traffic download sites.
Back to the top
 
Posted
Rating:
#99365
TQ
Avatar

Honoured member

Thanks for your good work so far, I look forward to testing it.

The cron_bridge is already running on my site so no problem there.

Nick
Back to the top
 
Posted
Item has a rating of 5 (Liked by Duck)  
Rating:
#99426
Avatar

Community saint

Another quick update. I'm almost done with the initial version. I went ahead and incorporated templates with the ability to have download names, file names, and links included in the notification. Since this is a non-bundled 3rd party addon, the bundled templates should not be edited directly since they may be overwritten when updating the addon if you use the ocPortal default theme. I have accounted for this by allowing a copy of the templates with _CUSTOM appended to the base file name to override the default bundled templates. I'll provide additional details and documentation for the templates when the addon is released. The next step is to upload it to one of my production sites to do more testing. If all goes well, I should have it uploaded to github and into the addons download section here at ocportal.com in the next couple of days.

Here is a sample of what a notification would look like if the Private Topic notification was enabled for the Download Follow-up Email notification (Note, the test site uses a red theme. It will adapt to whatever color scheme your site uses.):
Back to the top
 
Posted
Rating:
#99434
Avatar

Community saint

Wow looking great so far!
Back to the top
 
Posted
Item has a rating of 5 (Liked by Guest)  
Rating:
#99502
Avatar

Community saint

Another update. I hope to get this on github and in the addon downloads area some time on Wednesday. I had used another notification hook as a template and incorrectly assumed some things that caused it to not send notifications to everybody that should have been getting them. I think that issue is sorted out now. I just want to clean up the debug code and add a value that can be set via the OcCLE to enable/disable a limited debug mode to dump relevant variables to the cron_bridge.php output and it will be ready.
Back to the top
 
Posted
Rating:
#99569
Avatar

Community saint

It got late last night after posting the addon and I forgot to post the link in this thread for anybody following it. The initial version is done and you can find the support topic at http://ocportal.com/forum/topicview/misc/addons/downloads-follow-up.htm with detailed documentation and links.
Back to the top
 
Posted
Rating:
#99752
TQ
Avatar

Honoured member

Hi Jason,

Firstly I want to apologise for the lengthy delay in my response to your outstanding efforts to address my need for an email option for downloaded files. This was due to two circumstances, my problems with spammers/harvesters on my site which has taken up so much of my time and my inability to get the addon working correctly.

The former I will continue to discuss elsewhere but the latter mainly boiled down to me not reading/following your advice on the "custom" template. I ignored your warning about embedding HTML into the template and assumed that this was the cause of my problem when in fact my problems arose from creating the _CUSTOM template in my custom theme folder not the default theme folder. Nor did I understand that in order to view the debug info I needed to run the cron_bridge.php within the browser to see the debug information.

I have reverted back to the original template with a few text changes and no HTML and everything is now working perfectly. Now that everything is working I will revisit the _CUSTOM version of the template and the HTML side of things. I'm thinking now that I need the _custom template to be in both theme locations as I've already tried it in one or the other but not both.

Future enhancements: Everything you mention in your documentation, in my view, would be worth pursuing. I believe that this will become a "Must-Have" addon for many OCP users so I'm sure your efforts would be appreciated by many.

My desire for an HTML message makes me dare to suggest that the template could just have a place holder for the body of the message and allow the user to create one or more messages in eg the news wysiwyg editor under a unique category. This could then be easily reworded for each sites needs or even more daring, be sent out in rotation if there were more than one.

This may be a totally impractical suggestion (you will soon discover from my other posts that I am no web programmer) but it sounds like something I would strive for if I had the skills to do it.

Once again, I can't express enough how appreciative I am of time and effort you have put into this project.

Kudos

Nick
Back to the top
 
Posted
Item has a rating of 5 (Liked by Guest)  
Rating:
#99771
Avatar

Community saint

TQ said

I ignored your warning about embedding HTML into the template and assumed that this was the cause of my problem when in fact my problems arose from creating the _CUSTOM template in my custom theme folder not the default theme folder. Nor did I understand that in order to view the debug info I needed to run the cron_bridge.php within the browser to see the debug information.

I have reverted back to the original template with a few text changes and no HTML and everything is now working perfectly. Now that everything is working I will revisit the _CUSTOM version of the template and the HTML side of things. I'm thinking now that I need the _custom template to be in both theme locations as I've already tried it in one or the other but not both.

To expand on the HTML warning, you can use HTML, but you shouldn't treat the template as a full HTML page. The template is pre-rendered and placed into the MAIL.tpl template (for emails) where the {CONTENT} tempcode is (in the MAIL.tpl template). Since the default MAIL.tpl already includes the <html><head></head><body></body></html> HTML structure, you would omit that from the downloads_followup_email.tpl (and downloads_followup_email_custom.tpl) template. Other than that, you should be able to use HTML (and ocPortal CSS code) as well as most tempcode and comcode to format and include additional content just as you would anywhere else in ocPortal. The choosing of the _CUSTOM template isn't thoroughly tested since I'm using the default theme or a copy of the default theme on my sites and test site and didn't test all possible location scenarios...now that I think about it, I don't think the cron hook runs under any specific user or zone so it might always be returning 'default' as the theme the way I have it coded (I'm not specifically passing a zone to the get_theme() function nor am I passing the theme to the do_template() function). I know the _CUSTOM templates work when they are in the themes/default/templates_custom directory. I'll add some debug code around that and test it more thoroughly for the next release.

TQ said

Future enhancements: Everything you mention in your documentation, in my view, would be worth pursuing. I believe that this will become a "Must-Have" addon for many OCP users so I'm sure your efforts would be appreciated by many.

To possibly go along with your suggestions below, I can add another template variable and pass the download category ID (if it can't already be done strictly with tempcode) so it can be used to customize what blocks and content can be shown. I can also make a config option that can be used to insert the given text/comcode/tempcode into the template as either a placeholder insert or a full template override which would eliminate the need for _CUSTOM templates. However, I don't think wysiwyg editing is available for config options in the configuration editor (I'll have to check on that).

TQ said

My desire for an HTML message makes me dare to suggest that the template could just have a place holder for the body of the message and allow the user to create one or more messages in eg the news wysiwyg editor under a unique category. This could then be easily reworded for each sites needs or even more daring, be sent out in rotation if there were more than one.

This may be a totally impractical suggestion (you will soon discover from my other posts that I am no web programmer) but it sounds like something I would strive for if I had the skills to do it.

As the addon is now, you could add the same blocks to the template that are available in the comcode block assistant. For example, a 'recent downloads' block could be added by adding the following code somewhere appropriate in the downloads_followup_email_custom.tpl file:

[block param="10" zone="_SEARCH" filter="*"]main_recent_downloads[/block]

I haven't tested this in the template yet but don't see any reason it wouldn't work. If you try it, I did note in the comcode block assistant that this block doesn't filter for permissions, so it may be possible for members to see links to downloads they won't be able to download because they may not have the necessary permission. Other blocks to display other site news and content should work as well. And as I mentioned above, I can add a variable that can be passed to the template and used to further customize the content based on the download category ID.
Back to the top
 
Posted
Rating:
#99870
TQ
Avatar

Honoured member

Hi Jason,

I having a small problem with the download email you may be able to clarify for me. The {DOWNLOAD_LIST} appears to be sending users other peoples download within the list as well as their own.

If I veiw the points system within the users profile it displays an accurate list of their downloads and points are correctly deducted (each download has a value of 5 points).

I will remove {DOWNLOAD_LIST} from the template for now so as not to confuse the member as I have included an incentive message in the template to encourage them to earn points by interacting with the site and I want to avoid messages from them claiming I have deducted too many points.

Any idea why this might be happening?

Nick
Back to the top
 
Posted
Rating:
#99872
Avatar

Community saint

TQ said

Hi Jason,

I having a small problem with the download email you may be able to clarify for me. The {DOWNLOAD_LIST} appears to be sending users other peoples download within the list as well as their own.

If I veiw the points system within the users profile it displays an accurate list of their downloads and points are correctly deducted (each download has a value of 5 points).

I will remove {DOWNLOAD_LIST} from the template for now so as not to confuse the member as I have included an incentive message in the template to encourage them to earn points by interacting with the site and I want to avoid messages from them claiming I have deducted too many points.

Any idea why this might be happening?

Nick
​Hi Nick,

Drats. Thanks for the report! I think that might be because I initialize the download_list outside of the main loop that generates the notifications and don't reset it for each run through the loop. I'll get a fix out right now for it.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Expand