I want to use AjaxSearch in my website, but I have some pages with & and € in it,Do you use TinyMCE with the entity_encoding parameter set to "named" rather than "raw" (see the configuration tab of TinyMCE). Or these characters comes from an other source ?
Is there a way to make AjaxSearch encode its results well?Look at the &stripOutput parameter, to add a specific encoding before output the results:
---- &stripOutput user function (optional)
to transform on fly the result output
by default: defaultStripOutut
StripOutput user function should be define in the config file as follow :
// string functionName(string $text)
// functionName : name of stripOutput function passed as &stripOutput parameter
// $text : string php variable name as results
// return the filtered results
/*
function myStripOutput($text){
Any Php code which filter the results
The following internal functions could be called:
$text = stripTags($text); // strip all the MODx tags
$text = stripJscript($text); // strip jscript
$text = stripLineBreaking($text); // replace line breaking tags with whitespace
$text = stripHtml($text); // strip all the html tags
You could also developp you own filter based on regular expressions.
See http://fr.php.net/manual/en/intro.pcre.php
return $text;
}
*/
By default : defaultStripOutput function will be used if &stripOutput parameter
is not set or if the function is not defined :
function defaultStripOutput($text){
// replace line breaking tags with whitespace
$text = stripLineBreaking($text);
// strip modx sensitive tags
$text = stripTags($text);
// strip Jscript
$text = stripJscripts($text);
// strip html tags. Tags should be correctly ended
$text = stripHTML($text);
return $text;
}
Do you use TinyMCE with the entity_encoding parameter set to "named" rather than "raw" (see the configuration tab of TinyMCE). Or these characters comes from an other source ?No I don’t use TinyMCE at all (I have it installed but don’t use it), I mostly write my code by hand... but this is not the problem because I want to keep using named entity character encoding. This encoding works well for me in the rest of the site, and I know what these codes stand for... (I don’t know the raw or numerical encoding by heart...).
Look at the &stripOutput parameter, to add a specific encoding before output the results:How would this help me? (my knowledge of PHP is not that good that I could rewrite this function) is there a special function for this or should I just str_replace all special characters to there encoded form?
// encode special characters $text = htmlspecialchars($text);
I don’t know the raw or numerical encoding by heart...The raw encoding leave the characters as typed. e.g: & is stored as & in the database and € stored as €
is there a special function for this or should I just str_replace all special characters to there encoded form?As the characters coming from the database are not transformed, you got & € and possibly all the named entity characters. So you need to encode the output. For this use the html_entity decode function.
When you search "été" (summer in French) you search "été" not "été"Ok That raises a fair point... The changes I made (and mentioned in my edit) did the trick for well formed xml but for searching it didn’t work well...
yeah but when I do this and validate the code it gives more than 50 errors and about the same number of warnings (22 Errors, 21 warning(s) when no search is performed yet)... mostly &-signs give trouble...
Go on this demo page, choose French documents in the left menu, and type "été" as search term. You got a page with several accented characters. They are encoded (see the code of the page) as they are stored in the utf8 database.
<?php
/**
* xhtmlStripOutput : xhtml ouput strip function
*/
function xhtmlStripOutput($text){
if ($text !== ''){
// replace line breaking tags with whitespace
$text = stripLineBreaking($text);
// strip modx sensitive tags
$text = stripTags($text);
// strip Jscripts
$text = stripJscripts($text);
// strip html tags. Tags should be correctly ended
$text = stripHTML($text);
// html_entity encoding
$text = htmlentities($text,ENT_QUOTES,'UTF-8');
}
return $text;
}
?>
), but I haven’t still found the time to solve all the errors listed. May be one day ...Zoek & ' ' © Hier één Curaçao kun je € zoekéén >
<blockquote class="ajaxSearch_resultExtract"><p>...<span class="ajaxSearch_highlight ajaxSearch_highlight1">Zoek</span>en <span class="ajaxSearch_highlight ajaxSearch_highlight1">Zoek</span> & ' ' © Hier één Curaçao kun je € <span class="ajaxSearch_highlight ajaxSearch_highlight1">zoek</span>é&eac...</p></blockquote>