We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38346
    • 26 Posts
    revo 2.2.5

    I'm putting together a plugin that when a resource with a particular template is published it emails the contents through to mailchimp beamer which then turns it into a draft ready for sending.

    For sending the email I'm using the following: http://rtfm.modx.com/display/revolution20/modMail

    To populate the email I've setup two chunks mailChimpBeamerTitle and mailChimpBeamerContent. Within the title chunk i just have
    [[*pagetitle]]
    and within the content
    [[*content]]


    I then have the following to call these chunks to put into the email:
    $title = $modx->getChunk('mailChimpBeamerTitle');
    $content = $modx->getChunk('mailChimpBeamerContent');


    When the resource is published the email is sent but rather than the actual tvs within the chunks being processed and emailed I'm getting just the tag through e.g email subject is [[*pagetitle]].

    Oddly enough I have a dev setup (same version of modx, same configuration) and it is actually working as it should do and I can't for the life of me work out why it doesn't work on the live version of modx... [ed. note: enoch1 last edited this post 13 years, 9 months ago.]
      • 4172
      • 5,888 Posts
      I think you should send the resourcefields as array to modx::getChunk

      $properties = $resource->toArray();
      $title = $modx->getChunk('mailChimpBeamerTitle',$properties);
      $content = $modx->getChunk('mailChimpBeamerContent',$properties);


      and use placeholder-tags in your chunks:
      [[+pagetitle]]


      If you just want to have the value of this fields you may not need to call getChunk.



        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 38346
        • 26 Posts
        Many thanks Bruno that cracked it, the only problem remaining is that any urls within the document are relative. Is there a way of processing doc links as absolute urls you know of?
          • 40045
          • 534 Posts
          I actually had the same problem a few weeks ago and first I tried something with makeUrl() http://rtfm.modx.com/display/revolution20/modX.makeUrl in combination with

          &scheme=`full`


          but couldn't get it to work...so I just made two snippets which are used as output modifers in the mail template (one for links in text fields and one for links inside richtext area or textarea text):

          // snippet rel2abs
          // use like [[+link:rel2abs`]]
          if ( !function_exists('rel2abs')) {
          	function rel2abs($rel, $base) {
          		/* return if already absolute URL */
          		if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel;
          
          		/* queries and anchors */
          		if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel;
          
          		/* parse base URL and convert to local variables:
          		 $scheme, $host, $path */
          		extract(parse_url($base));
          
          		/* remove non-directory element from path */
          		$path = preg_replace('#/[^/]*$#', '', $path);
          
          		/* destroy path if relative url points to root */
          		if ($rel[0] == '/') $path = '';
          
          		/* dirty absolute URL */
          		$abs = "$host$path/$rel";
          
          		/* replace '//' or '/./' or '/foo/../' with '/' */
          		$re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
          		for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {}
          
          		/* absolute URL is ready! */
          		return $scheme.'://'.$abs;
          	}
          }
          
          return rel2abs($input, $modx->getOption('site_url'));
          


          and

          // snippet rel2absintext
          // use like [[+text:strip_tags=`<br /><br><a><b><i><strong><em><ul><ol><li>`:rel2absintext]]
          return preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#", '$1' . $modx->getOption('site_url') . '$2$3', $input);
          


          works for me but I would also be open for better ways to do that =)
            • 38346
            • 26 Posts
            Thanks exside, I'll work with this for now and let you know how I get on but I really can't help thinking there has to be a simpler way to do it that I haven't stumbled across yet...
              • 4172
              • 5,888 Posts
              [[~99? &scheme=`full`]] 
              should work
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 38346
                • 26 Posts
                Hi Bruno,

                That would be fine if just pulling in the link to the resource, but the plugin calls the content of the published resource and then needs to apply full urls to all of the links within that content.
                  • 4172
                  • 5,888 Posts
                  do you have some example-codes of this contents?
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 38346
                    • 26 Posts
                    Just any normal text with links, basically a standard content web page. So when the plugin fires it pulls the pagetitle and pops that in the 'subject' field of the email and then pulls the content and places that in the body. In essence it's a newsletter process which turns a resource into an html email. The only issue is that when the content is sent in the email everything is fine but the urls in the content are just like this:
                    <a href="just-a-relative-link" target="_blank">
                    and I need to stick http://domain.com/ on the front of it. I putting base-url in the chunk that's being called but that's not being processed (it still appears as the tag when the I view the html of the email)
                      • 38346
                      • 26 Posts
                      Ok I need to do some more testing but I think I've figured it out. In my chunk I've placed this:
                      <base href="[[++site_url]]" />
                      [[+content]]


                      The key seems to be calling site_url cached as calling it uncached resulted in it not being parsed.