ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Magpie, PHP, and dollar signs, oh my!

May 07, 2009 8:25pm

Subscribe [3]
  • #1 / May 07, 2009 8:25pm

    Todd Levy

    20 posts

    Okay, I’m running into a very fringe issue and hoping that someone has solved this before.

    It has to do with single vs double quoted strings and the way php “expands” variables in strings.

    Here’s the basics…

    I’m calling magpie in a template that parses php on output.

    Everything is working great… UNLESS… an item in the feed has a dollar sign in it.

    Then it breaks.

    Here’s the relevant part of the code…

    {exp:magpie url="{embed:tweet_feed_url}" limit="100" refresh="2" convert_entities="y"}
      <ul id="tweet-feed" class="results-list nobullets">
      {magpie:items}
        <?php $tweet_title = "{magpie:title}"; ?>                  
        <li><?php echo $tweet_title; ?></li>
      {/magpie:items}
      </ul> 
    {/exp:magpie}


    Here’s something I’ve tried with no success…

    $tweet_title = str_replace('$', '$', "{magpie:title}");


    And this I know works…

    $tweet_title = str_replace('$', '$', 'this is $test feed');


    But it won’t let me do this…

    $tweet_title = str_replace('$', '$', '{magpie:title}');

    ... and gives me a “Parse error: syntax error, unexpected T_STRING”


    Any help greatly appreciated!

    TL

    P.S. You can see it break here… http://phishtwit.com ...but you’ll have to page forward until you get to updates from around 3pm Central to see the one with the dollar sign ($) in it (though you won’t be able to see it b/c it breaks!).

  • #2 / May 08, 2009 1:52am

    John Henry Donovan

    12339 posts

    TL,

    I cannot see it breaking in the link you have provided. Did you mange to sort this one out?

    Is there a reason why you cant do the following?

    {exp:magpie url="{embed:tweet_feed_url}" limit="100" refresh="2" convert_entities="y"}
      <ul id="tweet-feed" class="results-list nobullets">
      {magpie:items}               
        <li>{magpie:title}</li>
      {/magpie:items}
      </ul>
    {/exp:magpie}
  • #3 / May 08, 2009 3:32am

    Todd Levy

    20 posts

    I cannot see it breaking in the link you have provided. Did you mange to sort this one out?

     

    John, thanks for the reply.

    To see the broken one you’ll need to advance a few pages to 3:07 pm CT.

    It immediately follows a Tweet @trent_reznor where you’ll see…

    Notice: Undefined variable: htie in /nfs/c01/h07/mnt/3113/domains/jamtopia.com/html/jamadmin/core/core.functions.php(637) : eval()‘d code on line 3027

    Is there a reason why you cant do the following?

    {exp:magpie url="{embed:tweet_feed_url}" limit="100" refresh="2" convert_entities="y"}
      <ul id="tweet-feed" class="results-list nobullets">
      {magpie:items}               
        <li>{magpie:title}</li>
      {/magpie:items}
      </ul>
    {/exp:magpie}

     

    Yes, because I need to parse the content before I present it.

    TL

  • #4 / May 08, 2009 3:39am

    John Henry Donovan

    12339 posts

    TL,

    You could try the XML encode plugin

    {exp:magpie url="{embed:tweet_feed_url}" limit="100" refresh="2" convert_entities="y" parse="inward"}
      <ul id="tweet-feed" class="results-list nobullets">
      {magpie:items}               
        <li> {exp:xml_encode}{magpie:title} {/ exp:xml_encode}</li>
      {/magpie:items}
      </ul>
    {/exp:magpie}
  • #5 / May 08, 2009 11:02am

    Todd Levy

    20 posts

    TL,

    You could try the XML encode plugin

    {exp:magpie url="{embed:tweet_feed_url}" limit="100" refresh="2" convert_entities="y" parse="inward"}
      <ul id="tweet-feed" class="results-list nobullets">
      {magpie:items}               
        <li> {exp:xml_encode}{magpie:title} {/ exp:xml_encode}</li>
      {/magpie:items}
      </ul>
    {/exp:magpie}

    John -

    I need to do some sophisticated parsing on the value involving complex regular expressions to add links and remove certain words and so on. Will the XML encode plugin will help with that?

    TL

  • #6 / May 08, 2009 11:06am

    Ingmar

    29245 posts

    Just give it a try. If it doesn’t fit your bill you’ll probably need to write some custom code, but it still should give you a head start.

  • #7 / May 14, 2009 12:50am

    Todd Levy

    20 posts

    Well I guess this is just another one of those times where I kept banging away at it until it worked, though I not exactly sure how or why (but don’t really care).

    Here’s the relevant code snippet that I changed…

    class tl_safedollar {
      var $return_data;    
      /** ----------------------------------------
      /**  Safe XML Dollar Sign ($) Encoding function
      /** ----------------------------------------*/
      function Tl_safedollar($str = '')
      {
      global $TMPL;
      $this->return_data = '';
      if ($str == '')
      {
        $str = $TMPL->tagdata;
        $this->return_data = trim(str_replace('$', '$', $str));
      }
    }


    Also had to add parse=“inward” to the magpie tag so it’d resolve before trying to call the encoding function.

    {exp:magpie url="{embed:feed_url}" limit="100" refresh="2" parse="inward"}

    Hope this is helpful to the next person who comes along.

    Thanks to the posters above for their guidance.

    TL

  • #8 / May 14, 2009 1:33am

    John Henry Donovan

    12339 posts

    Glad you were able to find a solution. Feel free to post again if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases