Magento Order comment update - Notify customer email formatting issue - php

This is my first post on the forums, i've been lurking forever now. About time to say hello! I did use the search, but either nobody else has this specific issue, or they don't utilize the comment section the way we do.
We like to send updates to customers through the order comment section of the order page. The email that is sent does not hold any of the line breaks that were used in the original comment. If you have 5 separate sentences, the email shows one big paragraph.
This is really annoying, because our message becomes a big mess. We have to give the customer a series of information about their order, and instructions on how to process with the issue on hand.
Here's two images of what i'm talking about
I have images but I can't post them because I need 10 rep. hmm..
As you can see, this is just an example and not a long comment, But our regular emails can have a lot of information, and maybe some up-selling.

I haven't tested it myself, but David Manners' answer on this question on the Magento Stack Exchange sounds promising.
Basically he suggests running the comments through nl2br to convert the newlines to tags that would render in HTML email, like this:
{{var data.comment:escape|nl2br}}

Related

facebook share Fb.ui description line break [duplicate]

This is an URL I have to send an invitation to an app of mine:
https://www.facebook.com/dialog/send?app_id=MY_APP_ID&
name=hola&
link=http://www.aWebSite.com&
picture=http://www.aWebSite.com/im01068442.jpg&description=participar!&
redirect_uri=http://elsuperdt.com
I'm trying to have a linebreak included within the description, but I just haven't found a way to do so. How do I do it?
I had the same issue and eventually gave up. Facebook seems to have gone to great lengths to avoid letting us have any linebreaks in the description.
The one thing you can do is add a &caption=first%20line which gets you one linebreak between the caption and the description. (There's a pretty short limit on how long the caption can be though - something like 80 characters.)
Update: this no longer works for send dialogs. It does still work for feed dialogs
Try using <center></center> this will create a new line in Facebook dialog description.
Try including %0D%0A in your description where you want the line break to be. This is the URL-encoded equivalent of a line break.
\n works in message but not in name parameter
I tried center></center> and %0D%0A. Both worked... for a split second. You could see the breaks upon page load, and then, like evil magic, facebook took it away and it was all scrunched up. Too bad. I'm trying to share a daily schedule, which would look much better with line breaks.
You can use blanks that are not posted to facebook in the length of the feed so the line breaks.
Or you just style your post by adding ".........." in the end of each line. This way people would maybe be more attracted to your post as they are eyecatching.

How can I reduce spam posted via a simple comment / review system?

I know there is hundreds examples of the question I'm about to ask. But none of them was working for me like a wanted.
So, I have a textarea, in which people can add comments/ reviews. But the commenting box keeps getting spammed.
I guess the regular expression might be the most efficient way to keep spammers out, but I stink at Regex.
Is there any other way to keep the spam out?
Edit: the spammers keep posting something like that:
Brianna
Looking for work Lolita Pics it would of been better if she was fucking in front of the mirror!
its more sexy seeing yourself getting f##$.
just getting horny thinking about it
Preteens Nn Models omg if that
(spoilered, lightly censored to avoid causing folks problems at work)
So i want to block per hyperlink in string
There are many different ways to get rid of spam:
Captcha - for example ReCaptcha, but nowadays you can buy about ~1000 rewritten captcha for less than 3$.
Questions in your language about the most known facts - you can ask your users about some facts that they know, but spammers don't.
Antispam filters - for example Sblam!, Akismet or other anti-spam services. I think it would work best for you.
Alot of Captcha is now bot solvable, and if you're trying to avoid Captcha, then one quick suggestion is to use a simple Text trap.
Under your text area, add a question, such as;
"How many days are in a week?"
Then add another text box, and compare this to say;
7 or Seven etc.
If the test fails, then reject the entry...
You may need to vary your question over time, or even have a list of different questions, but this is a simple and easy method to implement.
The answers here are good, but sometimes fooling bots is a good first step.
The vast majority of bots just read the source code and will fill in all the input fields they can find with garbage, send the request, and then hope it worked. They are pretty stupid, so something like this may fool most bots:
<p style="display:none">Screen readers: Use the next textarea (the first is used to confuse spam bots).</p>
<textarea name="comment" style="display:none"></textarea>
<textarea name="real_comment"></textarea>
And then in your script:
if (isset($_POST['comment']) && strlen($_POST['comment']) > 0) {
die('Bots begone!');
}
$comment = $_POST['real_comment'];
In other words, put a dummy textarea in the HTML, hide it using CSS, and then wait for bots to fill it in.
The simpliest way to do what you want is to search for the string http://
The following if-statement allows up to 3 links in $text
if (substr_count($text,"http://") > 3)
But that's not really a sufficent check, because there is a lot of spam, which doesn't contain any links at all - just rubish.
So the second you have to do, is a black list with "bad words"
$lower = strtolower($text);
foreach ($blockword as $word) {
if (strpos($lower, strtolower($word))>0) {
//handle spam here..
}
}
and after all, you have to maintain a growing list with words and still have to delete a lot of spam..
So you have the option to add an invisible field with random values, which are stored in the session and check if this value is submited correctly
$_SESSION["random_secret"] = //create random string..
and later check
if ($_POST["secret"] == $_SESSION["random_secret"])
with this check, you get rid of a lot of automated spam(but still not all)
and so after all you ended up with captchas

Store data using a txt file

This question might seem strange but I have been searching for an answer for a long time and I couldn't find any.
Let's suppose you have a blog and this blog has many post entries just like any other blog. Now each post can have simple user comments. No like buttons or any other resource that would require data management. Now the query is: Can I store user comments on a single text file? Each post will be associated to a text file that holds the comments. So, if I have n posts I'll have n text files.
I know I can perfectly do this, but I have never seen it anywhere else and no one is talking about it. For me this seems better than storing all coments from all posts in a single mysql table but I don't know what makes it so bad that no one has implemented it yet.
Storing comments in text files associated with corresponding post? Lest see if it's good idea.
Okay adding new comments easy - write new text to the file. But what about format of your data? CSV? Ok then you would have to parse it before rendering.
Paging. If you have a lot of comments you may consider creating paging navigation for it. It can be done easily, sure. But you would need to open the file and read all the records to extract say 20.
Approve your comments. Someone posted new comment. You place it with pending status. So.. In admin panel you need to find those marked comments and process then accordingly - save or remove. Do you think it's convinient with text files? The same if use decided to remove its comment himself.
Reading files if you have many comments and many posts will be slower the it would be in case of database.
Scalability. One day you deside to extend you comments functionality to let one comment to respond to another. How would you do it with text files? Or example from comments by nico: "In 6 months time, when you will want to add a rating field to the comments... you'll have a big headache. Or, just run a simple ALTER query".
This is just for beggining. Someone may add something.
Well, there are good reasons why this isn't done. I can't possibly name them all, but the first things that come to mind:
Efficiency
Flexibility
Databases are much more efficient and flexible than plain text files. You can index, search and assign keys to individual comments and edit and delete any comments based on their key.
Furthermore, you'd get a huge pile of text files if the blog is quite big. While in itself that's not a problem, if you all save them in one directory, it can grow out of proportion and really increase the access time needed to find and open a specific text file.

Changing/Editing tags with PHP

This is my first question here so please bear with me - I apologise if I have not posted correctly.
I have managed to pull a job description from an XML file created by our database however, the database software is very old and it converts certain
characters.
My problem is as follows: Bullet points are converted to something like the following:
" Production of Monthly Management Accounts and variance analysis<BR>
So a "(quote mark) is entered where the dot should be and a <BR> is entered to start a new line.
I was wondering if anyone knows how to convert the quote mark and the <BR> to <li> and </li> repspectively.
I've been looking at multiple options like, preg_match and substr_replace however, none of them have given the desired results.
Obviously the text between the <li> and </li> would change depending on job etc.
To top it all off, once this is working I need to be able to add in <ul> and </ul> around the list items, but I assume I can look for the first instance of <li> and replace with <ul><li> and likewise the last instance of </li> and replace with </li></ul>.
I'm sorry for rambling on, I hope I've made myself clear.
Edit:
Thanks so much for all of the quick responses, I am going to give these a bash tomorrow. I've been stuck on this most of the day so think it's time to step away.
Just to give a bit of extra info if it helps...
The database software is about 12 years old and the support for it is quite limit. If we want something doing it tends to cost a lot of money. It has a few options to export the data however, the XML for whatever reason kept HTML formatting so I went with that route.
All of the jobs have been written in Word first and then pasted into the "job field" in the database, so there is a strong chance that code has been misinterpreted.
I did a test job and made sure I used bullet points in Word and copy - pasted it into the "job field", the quote marks appeared where the dots should be, so I assume the old software doesn't "understand" the bullet points.
I will try all your great responses and report back tomorrow!
Thanks!
EDIT 2
Hi, below I have pasted the actual output from source view.
I have attempted the preg_replace option below which works on a single line, but as you can see the output is annoyingly placing everything continuously with no line breaks.
An exciting opportunity has arisen to join an established company based in Luton for a high calibre Management Accountant. Reporting to the Finance Director, the Management Accountant will provide accurate and reliable management information and financial support to the business. <BR>Key Responsibilities:<BR>" Production of Monthly Management Accounts and variance analysis<BR>" Preparation of Management Reports for Management Meetings.<BR>" Production of Monthly Forecasts and Annual Budgets using Excel.<BR>" Decision support to the business<BR>" Attending and presenting at meetings with business managers<BR>" Assisting external auditors with their audit process at each year end<BR>" Ad-hoc project work<BR>Experience:<BR>" Qualified accountant (ACA or CIMA) <BR>" Strong communication skills - to communicate effectively with all levels of management<BR>" High level of personal motivation, focus and a commitment to quality<BR>" Ability to adapt to the demands of a constantly changing business<BR>" Ability to interact with people at all levels in a sensitive and effective way<BR>If you are interested in this role then please apply now.<BR>
Assumptions:
" begins the line (quote followed by 3 spaces, markdown is removing the spaces)
<BR> is at the very end of the line
There will be no other variation, nor split lines
RegEx:
/^" (.*)<BR>$/
PHP:
$replacedData = preg_replace( '/^" (.*)<BR>$/', '<li>\1</li>', $data );
As you've said that the content is all lumped together, you could try this regex:
/" (.*?)<BR>/
Although you should be warned that it may pick up the wrong quote if the lines happen to contain "quoted" text.
Alternatively, if you know that the lines end as <BR>" (3 spaces being removed due to markdown), you could use 3 replaces to get the desired effect:
$repData = preg_replace(
array( '/<BR>" /', '<BR>', '" ' ),
array( '</li><li>', '</li></ul>', '<ul><li>' ),
$data );
Again, this may pick up the wrong elements especially if <BR> exists elsewhere in the code.
First comment would be to fix the broken database.
Aside from that, why is there formatting in an XML file, or in a database for that matter? If this is an XML file, just strip everything but the actual job description text out of the element, and have your PHP script output it nicely. Given the example above, trim the from the trailing end, then run it through trim('" ') to clean up any enclosing quotes and whitespace.
Or is this one of those cases where you're getting XML from a database, and whoever wrote that part clearly didn't understand what XML is for?
Edit:
Ahhh. It just hit me. Maybe you mean the job description is a plain text blob, with what should be sub-items actually all jammed in there, formatted as you demonstrated. If that's the case, you're going to have a really hard time getting this exact, because the odds are (when working with unstructured data) there are some variances in formatting. I think your best bet would be a regex to pull out all the text between " and the BR tags, build an array of that, and manually check some samples. Oh, and fix the database.
Assuming you've extracted to a variable; for sake of ease of demonstration i'll just set one:
$myVar = '" Production of Monthly Management Accounts and variance analysis<BR>';
As the other answer says, trim() is your friend, and so is either str_replace() or strip_tags() depending specifically what you want to do and what else you might have in your database.
Try this (assuming that you have stored the content in $myVar, as I have in my example).
$cleanedVar = strip_tags(trim($myVar,'" '));
Or this:
$cleanedVar = str_replace("<BR>","",trim($myVar,'" '));
Both of these lines would give you a result in $cleanedVar as
Production of Monthly Management Accounts and variance analysis

How to detect nonsensical text in PHP?

I have comments enabled on my site and I require users to enter at least 30 characters to publish their comments (Just to get some value because they usualy just submitted "I like it")
But some users now use simple technique to overcome this and enter e.g.:
"I like it. asdsdf dfdsfsdf tt erretrt re"
As you can see the rest of the text is nonsense. Is there a way (algorithm) how to filter these comments out in PHP ?
Get a dictionary of English words from the net. Check the post has a certain % (maybe 50%? maybe 70%?) of words that are in the dictionary. You can't look for 100%, or names and technical jargon will not be found.
users will get around this by entering.
I like it ....................................................
So then add logic to parse out punctuation.
Then users will get around it with
I like it. the the the the the the the the
Then you will need to parse it for proper English grammer
Then no one will be able to post on your site becuase it has too many rules.
Better suggestion: Add comment moderation. Dumb posts get downvoted and go away. Good posts stay.
Check out the Akismet PHP5 class.
$WordPressAPIKey = 'KEYHERE';
$MyBlogURL = 'http://www.example.com/blog/';
$akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
$akismet->setCommentAuthor($name);
$akismet->setCommentAuthorEmail($email);
$akismet->setCommentAuthorURL($url);
$akismet->setCommentContent($comment);
$akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
if($akismet->isCommentSpam()) {}
You can use a naive bayesian filter for this. http://www.paulgraham.com/better.html
There are probably existing libraries for this kind of thing. Check out spam assassin.
I'd do a simple check on consecutive consonants or vowels. If there are more than four of any in a row, than there is a high probability of nonsense. Furthermore, check for more than two repetitions of the same character. When looking at some nonsense text, I'm sure you'll find some pragmatic reciepes ;-)
Personally, I would say there's not much you can do about it. Even if you had a dictionary and parser, what if I were to leave a comment: "I like it. As do I like your car." Depending on what they're leaving a comment for, that could be complete nonsense. Best I can say is have an edit available for each comment so that you or a mod or whomever can edit it. Sorry that this isn't of any help.
I had this same issue when trying to create password restrictions. Words couldn't be used, so we needed to use a dictionary, but there is never a comprehensive dictionary. And the biggest thing was eliminating l33t speak. :)
Unfortunately not, your best bet is to modify something like this: Get Spelling Corrections From Google. When messages are close to the 80 character limit, you could look up each word individually and if it doesn't have a direct hit, boot out the input.

Categories