We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1932
    • 137 Posts
    I’ve gone ahead and updated the current version to 0.0.3, please see the updated snippet code and ZIP download on the first post of this thread. The following configuration parameters are new:


    &maxElements
    // Maximum number of times to display a repeating element
    // This setting will be overridden by any limit values in the template
    // Use the colon replacement value for element names which include colons
    // Syntax: ELEMENT_NAME(x) where x is the maximum number of times to display
    // Multiple elements can be defined and must be separated by a colon
    // Example: `CHANNEL(5):ITEM(10)`

    &startElements
    // Define the start (offset) for the displaying of elements
    // This setting will be overridden by any offset values in the template
    // Syntax: ELEMENT_NAME(x) where x is the offset integer
    // Multiple elements can be defined and must be separated by a colon
    // Example: `CHANNEL(1):ITEM(5)`

    &sortElements
    // Specify a field to perform a natural sort on, if %RAND% is specified the elements will be randomized
    // ASC and DESC can be optionally be added to modify the order in which the elements are sorted
    // Syntax: ELEMENT_NAME(fieldName)
    // Multiple elements can be defined and must be separated by a colon
    // Example: `ITEM(pub_date DESC)`

    &oddElements
    // If $outerChunk is defined the snippet will call a chunk, if not,
    // the snippet will attempt to use a file of the given name within the preset directory
    // Syntax: ELEMENT_NAME->calledChunk
    // Multiple elements can be defiend and must be separated by a colon
    // Example: `ITEM->oddChunk`

    &evenElements
    // Syntax: ELEMENT_NAME->calledChunk
    // Multiple elements can be defiend and must be separated by a colon
    // Example: `ITEM->evenChunk`

    &firstElement
    // Syntax: ELEMENT_NAME->calledChunk
    // Multiple elements can be defiend and must be separated by a colon
    // Example: `ITEM->firstChunk`

    &lastElement
    // Syntax: ELEMENT_NAME->calledChunk
    // Multiple elements can be defiend and must be separated by a colon
    // Example: `ITEM->lastChunk`

    Please let me know what you fellas think about the parameter names, I’d like to keep them as verbose and and understandable as possible. I’m more than willing to change them if someone can suggest anything more concise.

    Also, the order of the (optional) offset and limit for chunk calls has been switched. Should be: {{ITEM(limit,offset)->chunkName}} rather than {{ITEM(offset,limit)->chunkName}}

    A quick demo can be seen here: http://brianstanback.com/feedx.html Notice the sorting going on in Zi’s feed and the randomization of Flickr photos.
      • 1932
      • 137 Posts
      Below is an example for using the new sort function for any developers who are planning to use FeedX for XML data caching/retrieval within their own snippet/plugin/etc.

      <?php
      $feedx = new FeedX($config);
      $feedx->getData();
      $myData = $feedx->elements[0]['children'][0]['children'];
      sortNodes($myData, $element, $child, $sortOrder);
      print_r($myData);
      ?>
      


      Where $element is the repeating element, such as ITEM, $child is the sub-element to sort by (or %RAND% for random), and $sortOrder is either DESC or ASC (default). The sort must be performed on the ITEM’s parent array (not the entire data array itself).
        • 14050
        • 788 Posts
        Brian,

        I thought I was just ignorant and unable to get the &sortElements to work. Turns out I was just using the 0.0.2 version because your link on the first post still links to that package, although the link text says 0.0.3.

        Jesse
          Jesse R.
          Consider trying something new and extraordinary.
          Illinois Wine

          Have you considered donating to MODx lately?
          Donate now. Every contribution helps.
          • 1932
          • 137 Posts
          My bad, the link has been updated. embarrassed
            • 30128
            • 78 Posts
            I can’t get my head around this.. I want to show comic strips that are made public through rss feeds, like dilbert: http://feeds.feedburner.com/tapestrydilbert.

            When I make this snippet call on my webpage
            [!FeedX? &url=`http://feeds.feedburner.com/tapestrydilbert` &tplPreset=`rss`!] 

            I only get this output:
            <strong><a href="http://www.dilbert.com/">Dilbert</a></strong>
            <ul>
            <li><a href="http://www.dilbert.com/comics/dilbert/archive/dilbert-20070305.html" title="Posted on Mon, 05 Mar 2007 00:01:00 -0500">Comic for 05 Mar 2007</a></li>
            <li><a href="http://www.dilbert.com/comics/dilbert/archive/dilbert-20070304.html" title="Posted on Sun, 04 Mar 2007 00:01:00 -0500">Comic for 04 Mar 2007</a></li>
            <li><a href="http://www.dilbert.com/comics/dilbert/archive/dilbert-20070303.html" title="Posted on Sat, 03 Mar 2007 00:01:00 -0500">Comic for 03 Mar 2007</a></li>
            <li><a href="http://www.dilbert.com/comics/dilbert/archive/dilbert-20070302.html" title="Posted on Fri, 02 Mar 2007 00:01:00 -0500">Comic for 02 Mar 2007</a></li>
            <li><a href="http://www.dilbert.com/comics/dilbert/archive/dilbert-20070301.html" title="Posted on Thu, 01 Mar 2007 00:01:00 -0500">Comic for 01 Mar 2007</a></li>
            
            </ul>
            (displayed as a list of course on the webpage).

            However if I subscribe to the feed in something like Opera’s RSS reader, I get the image directly, not just links to the "articles."

            Hm.. well in fact what I get IS a link to different posts, but then I can click on them (one for each day) and get the image displayed inline, not taken to a webpage.

            I want of course to display the image on my webpage directly smiley

            [EDIT] Yuhoo I solved it myself smiley
              • 30128
              • 78 Posts
              Ok got it, sorry I just had to be dumb for a while smiley

              Now I only have to figure out how to display the enclosed image for the first item and then links for the next #n items. Preferably in such a way that when people click on the links below the image, the image of the item/post they clicked on will replace the one above. Is there a way already to do content replacement like that in MODx?

              Oh and if I’m not using any of the correct, professional words or terms it’s because I’m totally new at the game smiley
                • 1932
                • 137 Posts
                @tjalve:

                You’ll most likely have to create custom chunks (you could also modify the template files in tpl/rss/). You can display the first element separate from the rest by using the limit, offset notation. Example set of chunks:

                Chunk: outer
                {{RSS->inner}}

                Chunk: inner
                {{CHANNEL->channel}}

                Chunk: channel
                <strong><a href="[+LINK+]">[+TITLE+]</a></strong>
                <ul>
                    {{ITEM(1)->firstItem}}
                    {{ITEM(10,1)->restItems}}
                </ul>

                Chunk: firstItem
                <li class="first"><a href="[+LINK+]" title="Posted on [+PUBDATE+]">[+TITLE+]</a></li>
                

                Chunk: restItems
                <li><a href="[+LINK+]" title="Posted on [+PUBDATE+]">[+TITLE+]</a></li>
                


                Snippet call:
                [!FeedX? &url=`http://feeds.feedburner.com/tapestrydilbert` &outerChunk=`outer`!] 


                If you need more fields from the original rss, add &tplBuilder=`1` to the snippet call for a hierarchal list.

                As for displaying the image when a link is clicked, you could most likely use MooTools or better yet, MooDom (http://moodom.mad4milk.net/). My JavaScript skills are pretty lacking but I understand you could add an event handler on the fly and possibly use rel="" or another link attribute for the image source. Hopefully someone else can comment on this. wink
                  • 30128
                  • 78 Posts
                  Yay, that worked perfectly smiley

                  I’m almost on the javascript thingy.. very basic I can do it like this:

                  Chunk: channel
                  <strong><a href="[+LINK+]">[+TITLE+]</a></strong>
                  <div id="comic">
                  	<span id="stripimage">
                  		{{ITEM(1)->firstItem}}
                  	</span>
                  	<span id="striplinks">
                  		{{ITEM(4,1)->restItems}}
                  	</span>
                  </div>
                  


                  Chunk: firstItem
                  <b>[+TITLE+]</b><br />
                  <a href="[+LINK+]"><img src="[+ENCLOSURE.URL+]" alt="[+TITLE+]" /></a><br />


                  Chunk: restItems
                  <a href="" onclick="document.getElementById('stripimage').innerHTML = '<b>[+TITLE+]</b><br />
                  <a href="[+LINK+]"><img src="[+ENCLOSURE.URL+]" alt="[+TITLE+],posted on [+PUBDATE+]" /></a><br />
                  '">[+TITLE+]</a> 
                  


                  It works if I instead of the code above just have
                  <a href="" onclick="document.getElementById('stripimage').innerHTML = '<img src=[+ENCLOSURE.URL+]'">[+TITLE+]</a>  


                  but that isn’t valid XHTML. I’ve tried every way but can’t get the escape characters correct. This is inside a javascript ’ inside a html " and it don’t help with javascript escape character. I’ve also tried <?PHP echo addslashes(..) ?> to no avail.

                  How can I escape this correctly?

                  Btw this is very cool smiley


                    • 1932
                    • 137 Posts
                    What are you trying to escape, the [+TITLE+]?

                    I think there may be a problem with a null href="", you might try:

                    <a href="javascript:document.getElementById('stripimage').innerHTML = '<img src=[+ENCLOSURE.URL+]';return false">[+TITLE+]</a> 


                    Not sure if you already have it, but the HTML Validator extension for Firefox helps me tremendously with debugging html syntax.

                    I almost forgot.. you can also specify the first item in the snippet call itself (rather than having 2 ITEM->’s in the chunk template). The snippet parameter would look something like this:

                    &firstElement=`ITEM->firstItem`


                    Both methods are perfectly acceptable. wink
                      • 30128
                      • 78 Posts
                      No, I’m trying to escape all the quotes in the HTML that the innerHTML funksjon will replace the current content with. It’s especially important for the alt"" attribute of the img tag. The null ref works fine, onclick takes precedense, and the snippet calls are no problems either, thankfully smiley

                      I’m just at a loss as to who to escape double quotes inside a javascript single quote inside an HTLM double quote, or however you mix and mathc the quotes.

                      As to the first and rest elements, are you saying that when I use the firstElement parameter, the first element will be excluded when I do this call:
                      {{ITEM->restItems}}
                      ?