Search

No, the callbacks are just inserting data without touching Symphony.

If I understand you correctly, you are doing something very dangerous. Essentially your setup means that you have two systems writing to the same database. You should really know what you do.

If you have s.th. like a "separate system" and want to send emails, you might take a look at how the Email Newsletter Manager (ENM) does it. It has a Command Line Interface background process which also is separated from Symphony but needs some "Symphony environment/objects" in order to send newsletters. You might do s.th. similar to be able to use the ETM's API from your external application.

Thanks Michael. Its sounds like it might be pushing my skills to (and beyond?) the limit, but I'll look into ENM.

The interesting stuff is in /email_newsletter_manager/lib/cli.backgroundprocess.php.

Not sure if this has been asked before (I've looked but can't find anything) but I only want to send a notification email under certain conditions.

In my specific example I have a contact form for a section called enquiries which has a checkbox called spam. I only want an email notification to be sent if the spam checkbox is "No". So in my datasource, as well as the normal $etm-entry-id filter I have added a filter for the checkbox.

The problem I have is that an email is still sent (a blank one) when the spam checkbox is "Yes". I assume this is because the datasource returns no data but the email is still generated.

Is there way to check to see if the datasource is empty before sending the email?

Thanks in advance.

@stuartgpalmer: You might just want to use Mandrill or SendGrid to send emails if you are not doing anything with Symphony data.

Just in order to understand this: You still save the entry, even if the checkbox is "Yes"? And your datasource returns empty?

Is there way to check to see if the datasource is empty before sending the email?

No way that I am aware of. But you could probably write your own event filter. This is what I would try (if I understood your issue correctly). If you don't want to save anything, you might try to have two filters, a spam filter and an ETM filter. As far as I remember, a failing filter will stop the whole process. (Don't take my word for it, but test it before you code for hours and hours!) If that is true, the spam filter must only be executed first, which is (again, as far as I know) a matter of alphabetical order.

Sorry for being not more precise. Maybe someone else can say if I am right here.

Thanks @michael-e for the suggestions. Yes you a right in thinking that I want to save an entry even though the spam checkbox is set to "Yes". To give some background we have a site which has a rather persistent spam bot that has got round both a honeypot filter and a timestamp filter.

All the spam messages contain links however so I've built a regular expression filter to flag anything that has a link in the message field. At this stage though we still want to record all the messages just in case someone puts a link in the message which is not spam. We will probably evaluate this for a few weeks and see how it goes. In the interim though I'd like not to send notification emails for spam messages.

I like you idea of chaining events together (is that what you mean). I'll have a go and see what I come up with. Thanks again.

I've got a solution working now using chained events as you suggested. The first event is a custom event that first checks to see whether the message is considered spam. If it is, it records it in the database but does not trigger the second event which has the email template manager hooked into it.

If the event is not considered spam then the first event does not record anything in the database but instead just fires the second event which has the email template manager hooked in. The second event is a standard event, no customisation.

Below is the code for the first event for anyone that may find it helpful in the future:

public function load(){
    if(isset($_POST['action']['submit-enquiry'])){
        //Assume enquiry is not spam
        $_POST['fields']['spam'] = 'No';

        // The Regular Expression filter
        $reg_exUrl = "/(http|https|ftp|ftps)://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(/S*)?/"; 

        //Check if message field has links in (probably spam)

        $message = $_POST['fields']['message'];

        if(preg_match($reg_exUrl, $message)){
            $_POST['fields']['spam'] = 'Yes';
        }

        return $this->__trigger();
    }

}

public function priority(){
    return self::kHIGH;
}

protected function __trigger(){

    //Test is spam message
    if($_POST['fields']['spam'] == 'Yes'){
        //record in database but don't fire email template event
        include(TOOLKIT . '/events/event.section.php');
    }
    else{
        //don't record in database, do that in email template event
        $result = new XMLElement($this->ROOTELEMENT);
        $result->setAttribute('result', 'success');
    }

    unset($_POST['action']);

    //redirect to email template event
    if($result->getAttribute('result') == "success" && $_POST['fields']['spam'] == 'No') {

        $_POST['action']['enquiry'] = 'Submit';
        $_REQUEST['redirect'] = '/thank-you/';   

    }
    //reidrect to thank you page
    elseif($result->getAttribute('result') == "success"){
        redirect('/thank-you/');
    }
    return $result;

} 

Hey, great to hear that it works! It's not exactly what I had in mind (because I thought it might be done with mutliple event filters), but it's nice and simple.

ah ok, I understand what you mean now by an event filter (the things you select in multi select box when creating an event). Just out of curiosity how would you go about writing a custom event filter? Where would the code go? I assume a reference to it must go into the $eParamFILTERS array?

Well, the reference to an event filter is written into this array by Symphony when you select the filter in the backend. The filter itself subscribes to some delegates so it can be displayed in the backend and is executed at the right time. All that code must be in an extension driver class.

Here is some skeleton code which I extracted from extensions:

<?php

class extension_foobar_and_barfoo extends Extension
{
    /**
     * Delegates to subscribe to
     *
     * @return array
     */
    public function getSubscribedDelegates()
    {
        return array(
            array(
                'page'     => '/blueprints/events/new/',
                'delegate' => 'AppendEventFilter',
                'callback' => 'appendEventFilter'
            ),
            array(
                'page'     => '/blueprints/events/edit/',
                'delegate' => 'AppendEventFilter',
                'callback' => 'appendEventFilter'
            ),
            array(
                'page'      => '/frontend/',
                'delegate'  => 'EventPreSaveFilter',
                'callback'  => 'eventPreSaveFilter'
            ),
            array(
                'page'      => '/frontend/',
                'delegate'  => 'EventPostSaveFilter',
                'callback'  => 'eventPostSaveFilter'
            ),
        );
    }

    /**
     * Append event filters to backend event pages
     *
     * @param string $context
     * @return void
     */
    public function appendEventFilter($context)
    {
        $selected = !is_array($context['selected']) ? array() : $context['selected'];

        $context['options'][] = array(
            'foo-bar',
            in_array('foo-bar', $selected),
            __('Foo Bar')
        );
        $context['options'][] = array(
            'bar-foo',
            in_array('bar-foo', $selected),
            __('Bar Foo')
        );
    }

    /**
     * Before saving the entry, check permissions.
     *
     * Executes some code only when the filter is in the event context
     *
     * @uses EventPreSaveFilter
     * @param string $context
     * @return void
     **/
    public function eventPreSaveFilter($context)
    {
        if (in_array('foo-bar', $context['event']->eParamFILTERS)) {

            // Do your stuff here. Generate a boolean value in the end.

            $permission = false;

            // By adding the boolean value to the context the event will know what to do

            $context['messages'][] = array(
                'permission',
                $permission,
                ($permission == false) ? __('You are not authorised to perform this action.') : NULL
            );
        }
    }

    /**
     * After saving the entry, perform additional tasks.
     *
     * @uses EventPostSaveFilter
     * @param string $context
     * @return void
     **/
    public function eventPostSaveFilter()
    {
        if (in_array('bar-foo', $context['event']->eParamFILTERS)) {
            // Do your stuff
        }
    }
}

I don't say that you must do it using filters! Your solution is fine!

Thanks for posting the code, I'm just starting to get my head round building extensions and this will certainly be of help in the future. Thanks!

Hi,

I'm trying to install Email Template Manager on Symphony 2.3.4. I don't get any error message but when i try to enable/install it, nothing happens, a query is made to the server but the extension is not being installed. Any suggestions ?

Thanks

are entries witten to manifest/logs/main or apache log? which version of ETM you use?

Thanks for pointing me out in the right direction.

The logs showed that the system didn't have the right to create a new folder in workspace.

All good now. Thanks for your help.

Email Template Manager updated to version 6.0 on 13th of June 2014

Compatible with Symphony 2.4

Does ETM support attachments?

I can't find any documentation or discussion on this subject. Thanks

No and yes.

No, officially it doesn't support attachments.

Yes, it's rather simple to implement this, and I have done it for a client: https://github.com/BayernSPD/email_template_manager/tree/bayernspd-sym-2.3

In this (Symphony 2.3 compatible) branch you see two extra commits. One implements the ability to set the "From" header (don't do this if you don't know the possible implications!), the second one implements attachments. You will see that this addition is not very complicated. Feel free to use this code.

[EDIT]: The repo linked above is not an "official" repo, and so (officially) there is zero support for this code.

Wonderful. Thanks Michael.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details