[EventCalendar] ec3_get_events() not translating ampersands into character entities

Alex Tingle alex at firetree.net
Fri Oct 5 15:15:03 UTC 2007


Hi there ejm,

ejm wrote:
> Running WP2.0.11 and EC3.1.0
> 
>> it turns out that it was not the event calendar that was causing the validation errors.
> 
> Well, rats. I fixed the Get Custom Field Value plugin error. And alas,
> my analyis was incorrect. ec3_get_events() IS still causing validation
> errors. 

You are right there. To start with, thank you for finding and reporting 
the error.


> Once again, this is the coding I am using on the left sidebar of
> peacemakers.ca.etherwork.net/bulletins/:
> 
> ec3_get_events('1000 days',' <a href="%LINK%" title="%DATE% -
> %TITLE%"><b>%DATE%</b>: %TITLE%</a>','');
> 
> I also have an events page that uses the following coding:
> 
> ec3_get_events('1000 days','%DATE%: <a href="%LINK%" title="%DATE%:
> %TITLE%">%TITLE%</a>','','j',"%MONTH%:");
> 
> On both those pages, if there are ampersands in %TITLE%, they are NOT
> rendered into their entities in the coding. (I believe I did not make
> it clear that I want any ampersand to be turned into &amp; for the
> html pages)
> 
> I have tried various permutations of Dr.Troxler's fix - (note that I
> have not included "html_entity_decode") but I continue to get
> validation failure. 

oh dear.


> In eventcalendar3 > template-functions.php  I have tried replacing 
> $data['TITLE'] =$entry->post_title;
> 
> with
> ...........................
> $data['TITLE'] =htmlentities($data['TITLE']);
> ..........................

I think this is correct. Even better would be...

$data['TITLE'] =htmlentities($data['TITLE'],ENT_QUOTES);

> With that coding, the ampersands do get translated and the main page
> displays in Firefox. However, any attempt to validate the page fails:
> the validation page states that there are now characters that do not
> belong in UTF-8.

Can you post an example URL that shows this behaviour? The example 
you've posted (above) gets validation errors, but clearly hasn't had the 
titles run through htmlentities(). Here's a snippet...

  <li> <a href="http://peacemakers.ca.etherwork.net/bulletins/?p=623" 
title="23 Oct 2007 - Joan B. Kroc Institute for Peace & Justice Women 
PeaceMakers Conferences and Events"><b>23 Oct 2007</b><span 
style="display:none">:</span> Joan B. Kroc Institute for Peace & Justice 
Women PeaceMakers Conferences and Events</a></li>


The fix should be correct, so I suspect that something else is 
interfering. Do you have caching turned on anywhere? Are you *sure* that 
the code you changed is the code it's running?

To be double sure, I'd try to change it like this...

$data['TITLE'] ='HELLO '.htmlentities($data['TITLE'],ENT_QUOTES);

...now if you don't see 'HELLO' in front of all your titles, you know 
something is wrong.


> But the events page fails to display anything after the date. The link
> and the title are gone. 

Again, an example would be nice. Which browser?

-Alex

--

> 
> P.S. In an effort to keep spammers at bay, I would prefer that the
> address of my wordpress site NOT be made into a link.
> 
> On Wed, 3 Oct 2007 20:05:14 +0200, "Dr. Peter Troxler"  wrote:
>> you will have to tweak the ec3_get_events() in template_tags.php  
>> function in a very peculiar way:
>>
>> find this section
>>
>>       $data['TITLE'] =$entry->post_title;
>>       $data['LINK']  =get_permalink($entry->id);
>>       $data['AUTHOR']=$entry->author;
>>
>> and change it to
>>
>>       $data['TITLE'] =htmlentities(html_entity_decode($entry- 
>>> post_title));
>>       $data['LINK']  =htmlentities(html_entity_decode(get_permalink 
>> ($entry->id)));
>>       $data['AUTHOR']=htmlentities(html_entity_decode($entry->author));
>>
>> this essentially converts all html (that might eventually be sitting  
>> there) to normal characters and converts them back to html
>>
>> I tested it with the title only, so link and author at your own risk  
>> (as of course always the standard disclaimer that nothing is  
>> guaranteed to work or not to break the rest of your blog etc.) test  
>> it first on a defined testcase and ideally in a test blog before  
>> applying it to your production platform. always backup files & data,  
>> etc.
>>
>> It works well visually and validates for both an &amp; or a simple &  
>> put in the title.
>>
>> However, be warned, there seem to be changes in upcoming versions of  
>> WP re html in the title.
>>
>> hope this helps
>>
>> / pt
>>
>> On 3-okt-2007, at 19:03, ejm wrote:
>>
>>> Running WP2.0.11 and EC3.1.0  I am using ec3_get_events() on the
>>> lefthand sidebar of a wordpress I run with the following code:
>>>
>>> ec3_get_events('1000 days',' <a href="%LINK%" title="%DATE% -
>>> %TITLE%"><b>%DATE%</b><span style="display:none">:</span>
>>> %TITLE%</a>','');
>>>
>>> Whenever there is an ampersand or other nonstandard character in the
>>> title or link, it causes the page to not validate in XHTML. Not
>>> knowing a whole lot about PHP, how do I go about encoding an "if,
>>> else"  to make sure that ampersands and non-standard characters are
>>> translated to their character entities the way they are in the rest of
>>> wordpress? (I've searched as best I can for this answer via google but
>>> it must be a "need to know the answer before asking the question" kind
>>> of problem)
>>>
>>> Please note that omitting ampersands, quotation marks, apostrophes and
>>> non-standard characters from titles is not necessarily an option. This
>>> particular wordpress is filled in by someone else who knows even less
>>> about coding than I do and who will not be able to understand why
>>> there is a need to omit the characters.
> 
> _______________________________________________
> Blog: http://wpcal.firetree.net/
> EventCalendar at firetree.net mailing list
> Unsubscribe: http://penguin.firetree.net/eventcalendar


-- 
:: Let me solve your problems: http://www.firetree.net/consulting/
:: alex.tingle AT firetree.net  +44-7901-552763



More information about the EventCalendar mailing list