Index > Bug report > ModuleNewsletter - Wrong internal links & newsletter send with split
Hello!
I found 2 bugs in the newsletter module:
- If you insert links to you newsletter by using the "Link to TL-page" function, the urls in the send newsletter are not replaced by the links!
Fix:
open system/modules/newsletter/Newsletter.php
find near line 80
before add
I don't know, if this is right, but it works.
- If you have more recipients than fits into one cycle, the newsletter will not be send to all recipients. For example, if you have a little bit more than 300 recipients, choose 10 per cycle, 40 mails will be send.
Fix:
open system/modules/newsletter/Newsletter.php
find near line 170
replace by
Hi Leo, please check, if my solutions will work!
Manjo
I found 2 bugs in the newsletter module:
- If you insert links to you newsletter by using the "Link to TL-page" function, the urls in the send newsletter are not replaced by the links!
Fix:
open system/modules/newsletter/Newsletter.php
find near line 80
Code:
// Send newsletter if (strlen($this->Input->get('token')) && $this->Input->get('token') == $this->Session->get('tl_newsletter_send'))
before add
Code:
$objNewsletter->content = $this->replaceInsertTags($objNewsletter->content);
I don't know, if this is right, but it works.
- If you have more recipients than fits into one cycle, the newsletter will not be send to all recipients. For example, if you have a little bit more than 300 recipients, choose 10 per cycle, 40 mails will be send.
Fix:
open system/modules/newsletter/Newsletter.php
find near line 170
Code:
if ($objRecipients->numRows < 1 || (($intStart + 1) * $intPages) >= $objTotal->total)
replace by
Code:
if ($objRecipients->numRows < 1 || $intStart + $intPages >= $objTotal->total)
Hi Leo, please check, if my solutions will work!
Manjo
2008-03-16 14:48
Hi Manjo,
insert tags are available in the front end only, so you cannot use them in the newsletter module. Your code seems to work, however, it will insert relative links that cannot be clicked by the recipients. If you want to link to an internal page, you should manually add the complete URL.
Your second fix is correct. There is a bug in system/modules/newsletter/Newsletter.php in line 176
which should be
Thanks for pointing this one out.
Regards
Leo
insert tags are available in the front end only, so you cannot use them in the newsletter module. Your code seems to work, however, it will insert relative links that cannot be clicked by the recipients. If you want to link to an internal page, you should manually add the complete URL.
Your second fix is correct. There is a bug in system/modules/newsletter/Newsletter.php in line 176
Code:
if ($objRecipients->numRows < 1 || (($intStart + 1) * $intPages) >= $objTotal->total)
which should be
Code:
if ($objRecipients->numRows < 1 || ($intStart + $intPages) >= $objTotal->total)
Thanks for pointing this one out.
Regards
Leo
2008-03-17 12:58
Hello Leo,
ok, so I did a new function, which should be placed in Newsletter.php within the class Newsletter:
Part of the code is a copy of the replaceInsertTags-function of the Controller-Class. It seems to work. Maybe you can add this function to the next version.
I changed the code near line 77 to
ok, so I did a new function, which should be placed in Newsletter.php within the class Newsletter:
Code:
/** * Replace insert a-tags with their values * @param string * @return string */ private function replaceInsertLinks($strBuffer) { $tags = array(); preg_match_all('/{{[^}]+}}/i', $strBuffer, $tags); // Replace tags foreach ($tags[0] as $tag) { $elements = explode('::', trim(str_replace(array('{{', '}}'), array('', ''), $tag))); // function only works for internal links if (!preg_match('/^link/',$elements[0])) continue; // Page link $objNextPage = $this->Database->prepare("SELECT id, alias, title, pageTitle FROM tl_page WHERE id=? OR alias=?") ->limit(1) ->execute($elements[1], $elements[1]); if ($objNextPage->numRows < 1) { $strBuffer = str_replace($tag, '', $strBuffer); } else { $strUrl = $this->generateFrontendUrl($objNextPage->row()); $strTitle = strlen($objNextPage->pageTitle) ? $objNextPage->pageTitle : $objNextPage->title; // Replace tag switch (strtolower($elements[0])) { case 'link': $strLink = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($strTitle), $strTitle); break; case 'link_open': $strLink = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($strTitle)); break; case 'link_url': $strLink = $strUrl; break; case 'link_title': $strLink = specialchars($strTitle); break; } $strBuffer = str_replace($tag, $strLink, $strBuffer); } } return $strBuffer; }
Part of the code is a copy of the replaceInsertTags-function of the Controller-Class. It seems to work. Maybe you can add this function to the next version.
I changed the code near line 77 to
Code:
// Add default sender address if (!strlen($objNewsletter->sender)) { $objNewsletter->sender = $GLOBALS['TL_CONFIG']['adminEmail']; } $objNewsletter->content = $this->replaceInsertLinks($objNewsletter->content);
2008-03-17 13:42
Hi Manjo,
I can add a hook to the newsletter class if you want to create a third party extension.
Regards
Leo
I can add a hook to the newsletter class if you want to create a third party extension.
Regards
Leo
2008-03-17 13:56
Hi Leo,
do you think, this is a third party extension? I do not, because, the link functionality does not work correct with newsletters. If you want to inserat a link to a page on your TL site, the way you told me, you first have to call the page in another browser window, copy the full link, go back to the newsletter window, klick "insert a link", ignore the pulldown menu for internal links and paste the full link as exteral link.
But it could be so easy! Add this function and internal links can be inserted by using the pulldown menu in the "insert a link" window.
Are you against adding code, which is not totally made by your own, to the core? btw... the code is nearly a 100% copy of the other function, removing not needed stuff and added not more than 5 lines ;-)
Regards,
Manjo
do you think, this is a third party extension? I do not, because, the link functionality does not work correct with newsletters. If you want to inserat a link to a page on your TL site, the way you told me, you first have to call the page in another browser window, copy the full link, go back to the newsletter window, klick "insert a link", ignore the pulldown menu for internal links and paste the full link as exteral link.
But it could be so easy! Add this function and internal links can be inserted by using the pulldown menu in the "insert a link" window.
Are you against adding code, which is not totally made by your own, to the core? btw... the code is nearly a 100% copy of the other function, removing not needed stuff and added not more than 5 lines ;-)
Regards,
Manjo
2008-03-17 14:15
Hi Manjo,
as I already told you, insert tags are supported in the front end only. If you want to add your functionality to TYPOlight, please create a third party module. The philosophy of TYPOlight is to keep the core as small and clean as possible and to add additonal functionality as extension.
Regards
Leo
as I already told you, insert tags are supported in the front end only. If you want to add your functionality to TYPOlight, please create a third party module. The philosophy of TYPOlight is to keep the core as small and clean as possible and to add additonal functionality as extension.
Regards
Leo
2008-03-17 14:24
Hi Leo,
ok, I understand and I don't wanna have a long discussion here about TL philosophy...
For me it is a bug, if user can choose things in the backend, which make unreadable code, for you it seems to be, that the user should know, not to use this or that function, because it does not work.
Keep the code small - keep the bug (or feature?) *smile*
Regards,
Manjo
ok, I understand and I don't wanna have a long discussion here about TL philosophy...
For me it is a bug, if user can choose things in the backend, which make unreadable code, for you it seems to be, that the user should know, not to use this or that function, because it does not work.
Keep the code small - keep the bug (or feature?) *smile*
Regards,
Manjo
2008-03-17 14:39
By the way, your code is buggy, too. It still generates relative links that will not be clickable if a recipient reads the e-mail in his mail client. I will check if there is a way to modify the TinyMCE plugin, so it does not insert insert tags in the newsletter module.
Regards
Leo
Regards
Leo
2008-03-17 14:45
While we're on the topic, I've noticed that image placed inside a newsletter have document relative instead of absolute urls for the image source.
2008-03-17 15:37
Hi Ben,
that does not matter since all image will be sent as inline images.
Regards
Leo
that does not matter since all image will be sent as inline images.
Regards
Leo
2008-03-17 16:23
Leo,
I understand this now. But, the images are "broken" in some tests that I've done.
I understand this now. But, the images are "broken" in some tests that I've done.
2008-03-18 07:03
Hi Ben,
can you describe what you have done and check against the online demo?
Regards
Leo
can you describe what you have done and check against the online demo?
Regards
Leo
2008-03-18 10:02
Hi Leo,
here is a part of an email, send by newsletter module with my new function to replace links:
How did you find out, that the links are relative?
Regards,
Manjo
here is a part of an email, send by newsletter module with my new function to replace links:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="Generator" content="TYPOlight webCMS"> <title>Test</title> </head> <body> <a href="http://localhost:8888/tl_test/site1.html">Link to internal site</a><br /> <br /> <a href="http://localhost:8888/tl_test/files/css/header.css">Link to file</a><br /> <br /> </body> </html>
How did you find out, that the links are relative?
Regards,
Manjo
2008-03-18 13:27
Hi Manjo,
your code returns relative links which are then converted by TinyMCE. As I already said, it does work on your system but it would not work in a multi-client environment with multiple URLs.
Regards
Leo
your code returns relative links which are then converted by TinyMCE. As I already said, it does work on your system but it would not work in a multi-client environment with multiple URLs.
Regards
Leo
2008-03-18 14:12
Hello there,
I am using tl 2.6.2 and all the relative links (apart from the images) are appended with twice the domain name e.g. http://www.mydomain.com/http://www.mydomain.com/newsreader/some-article.html.
Images links are converted properly.
Is this a bug or am I doing something wrong?
Thank you
I am using tl 2.6.2 and all the relative links (apart from the images) are appended with twice the domain name e.g. http://www.mydomain.com/http://www.mydomain.com/newsreader/some-article.html.
Images links are converted properly.
Is this a bug or am I doing something wrong?
Thank you
2008-11-09 22:21
