MODX: Snippet strips and hangs string when parsing the vars - parsing

i have a snippet call like this:
[!mysnippet?&content=`[*content*]` !]
What happen is that, if i send some html like this:
[!mysnippet?&content=`<p color='red'>Yeah</p>` !]
it will return this:
<p colo
the [test only] snippet code (mysnippet) is:
<?php
return $content;
?>
Why is this happening?
My actual snippet is converting html to pdf, so i really need this.
Thank you all ;D
EDIT: I'm using Modx Evo 1.0.2

MODx Evolution has a limitation whereby you can't use "=" (equals signs) in Snippet parameter values. Best solution is to place the content in a chunk or TV and then call it. This is not an issue in MODx Revolution.

Related

How do I escape HTML for th:errors?

Let's say I have:
<span th:if="${#fields.hasErrors('firstName')}" class="color--error" th:errors="*{firstName}"></span>
How do I escape the text if the error text contains HTML? I know for normal text, we can use th:utext.
As of 3.0.8-SNAPSHOT, Thymeleaf-Spring has th:uerrors.
See this GitHub issue for the discussion: https://github.com/thymeleaf/thymeleaf-spring/issues/153
And this change log for 3.0.8: http://forum.thymeleaf.org/Thymeleaf-3-0-8-JUST-PUBLISHED-td4030687.html
th:errors is just a shortcut. You still use th:utext for this, you just have to manually output your errors. In your case, the code could look something like:
<div th:if="${#fields.hasErrors('firstName')}" th:each="err: ${#fields.errors('firstName')}" th:utext="${err}" class="color--error" />

How to decode windows-874 imap subject?

I'm having a serious problem with imap decoding. I received an email which might be encoded in windows-874. And this causes the whole letter to be read. I tried to use iconv('tis-620','utf-8',$txt) but I've had no luck.
I've tried searching everywhere that there might be an answer but it seems like it is the first problem of the universe. (or I don't search the correct word?)
The subject is :
Charset : ASCII
=?windows-874?Q?=CB=E9=CD=A7=BE=D1=A1=C3=D2=A4=D2=BE=D4=E0=C8=C9=CA=D3=CB=C3=D1=BA=A7=D2=B9=E4=B7=C2=E0=B7=D5=E8=C2=C7=E4=B7=C2=A4=C3=D1=E9=A7=B7=D5=E8
30
=E2=C3=A7=E1=C3=C1=CA=C7=D1=CA=B4=D5=CA=D8=A2=D8=C1=C7=D4=B7=AB=CD=C2 8?=
So, please tell me what the encoding is, if it's not tis-62. How can I decode this into a human language?
Finally I found my way home. Firstly I created a function to detect any encoding in a text given.
function win874($str){
$win874=strpos($str,"windows-874");
return $win874;
}
function utf8($str){
$utf8=strpos($str,"UTF-8");
return $utf8;
}
Then I convert with php functions:
if(win874($headers->subject)=="0" and utf8($headers->subject)=="0"){
echo $headers->subject;
}
if(win874($headers->subject)>="1"){
$subj0=explode("?",$headers->subject);
echo $subj0[3];
}
if(utf8($headers->subject)>="1"){
echo imap_utf8($headers->subject);
}
Because text with windows-874 always begins with "=?windows-874?Q?" so I used the simple function like "explode()" to extract the main idea from the junk. As I said, the main idea always comes after the 3rd question mark. Then I have the subject.
But the problem remains. I still have to change the browser encoding to Thai to make the text readable. (settings>tools>encoding>Thai : in chrome). Any suggestions?

Why won't Razor parse this in html mode?

I'm making a reusable package and in order to get the client side to work both with straight javascript and module loaders I have a code paths that requires me to document.write out script tags.
In my razor view I have something like this:
<script>
...
document.write([
'<script type="text/javascript" src="~/Oaf/SlimHeader/Media/Scripts/jquery-1.9.1.min.js"></script>',
'<script type="text/javascript" src="~/Oaf/SlimHeader/Media/Scripts/jquery-migrate-1.2.1.min.js"></script>',
].join('\n'))
...
</script>
Which Razor refuses to interpret in html mode:
Parser Error Message: Unterminated string literal. Strings that start
with a quotation mark (") must be terminated before the end of the
line. However, strings that start with # and a quotation mark (#")
can span multiple lines.
indicating the error is in the first script tag. This is javascript, I don't want Razor involved at all! (Ok, it would be nice if it parsed the ~ but honestly I can take care of that myself).
I've tried prefixing every line with #: and surrounding the whole thing in #" ... "# but neither seems to work.
This is not a razor issue, this code is invalid even in a simple HTML file, and will cause problems in the browser.
The solution is to:
var a = '<script><' +' /script>';
The bug has been closed as by design.
Thanks to Aron who got me to pare this down thereby prompting me to discover the answer.
Pared down the broken code looked like this (I hadn't included the if in the question):
#if (true) {
<script type="text/javascript">
var a = '<script></script>';
</script>
}
something in the interplay between the #if and the <script> tag in a sting just does not sit well. If I force text mode on each line inside the if by prefixing with #: then it works.
In the original question the solution it to prefix every line inside the Razor block with #:. Surrounding in a <text> block will not work. If you don't prefix every line with #: then you will get a parsing error very possibly for a line that was prefixed.
Seems like a bug with Razor. Will report it.

Extract pieces from URL

I need to extract pieces from a URL and I am trying to learn preg_match_all().
The output in a PHP variable:
$content = 'http://www.domain.com/folder1/firstname_lastname.jpg';
Here is my attempt:
preg_match_all('/http://(.*?).jpg/s', $content, $out, PREG_SET_ORDER);
echo $out[0][0] . "\n";
Matching the URL is not easy.
I need to pick out from:
hxxp://www.domain.com/folder1/firstname_lastname.jpg
the following: "www.domain.com" and "folder1" and "firstname_lastname"
Could I get one preg_match_all() for each example?
Thanks in advance.
I like to learn by example and trial and error.
He he... :)
You can use these:
http://uk3.php.net/parse_url
http://uk1.php.net/manual/en/function.parse-str.php
To get constituent parts of a URL and query string.

SimplePie RSS Parser - Encoding and Weird Characters even on UTF-8

I am using SimplePie to Parse an RSS feed, and I am getting the following output:
Don't forget our "Spot It, Post It" .....
My code is:
<?php
header('Content-type:text/html; charset=utf-8');
require_once('rss/simplepie.inc');
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process.
$feed->set_feed_url('FeedURL');
$feed->enable_cache(true);
$feed->set_cache_duration(3600);
$feed->set_cache_location('cache');
$feed->init();
$feed->handle_content_type();
?>
I'm using HTML5 Doctype AND I also have: <meta charset="charset=utf-8">
I've looked it up and everything talks about changing the charset to UTF-8 which I clearly have.. so I'm not too sure what else is causing this.
Any ideas?
I don't know if you've managed to fix this, but thought I'd share my solution with anyone else who is looking. I had the same problem - the characters were being 'corrupted' in the feed. My code initially (with the problem) was:
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/simplepie.inc';
$feed = new SimplePie('http://domain.wordpress.com/feed/');
?>
Seeing the post above, I tried adding the following header and it worked!
<?php
header('Content-type:text/html; charset=utf-8');
include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/simplepie.inc';
$feed = new SimplePie('http://domain.wordpress.com/feed/');
?>
I hope this helps someone else experiencing the same problems.
Does this happen with every feed? Or just one particular feed? It might be the feed itself. You can use $item->get_content() and look at the content of the feed directly if the description itself is proving problematic. Sometimes it is necessary to do processing on information from a feed or web API, there is PHP code and examples for stripping and replacing characters, the News Blocks 2.0 demo on the SimplePie site has some cleaning code I've been using a lot recently.
Good luck.

Resources