We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4195
    • 398 Posts
    Need comments in XML format?
    Demo: source | xml

    You can use technique to make comments available as a feed or to create some sort of AJAX implementation of Jot.

    Here’s how to do this:

    1. Create a new chunk: JotTplXML
    This is just one example of a format but you can customize the format any way you want.. just be sure to use :esc in the user edited content placeholders to escape all html tags else the xml will choke.
    [+comment.published:is=`1`:then=`
    <comment id="[+comment.id+]" 
    postnr="[+comment.postnumber+]" 
    createdon="[+comment.createdon:date=`%B %d, %Y, %H:%M:%S`+]" 
    editedon="[+comment.editedon:date=`%B %d, %Y, %H:%M:%S`+]" 
    createdby="[+comment.createdby+]" 
    editedby="[+comment.editedby+]">
    <user postcount="[+comment.userpostcount+]">
    [+comment.createdby:userinfo=`username`:ifempty=`[+comment.custom.name:ifempty=`[+jot.guestname+]`+]`:esc+]
    </user>
    <subject>[+comment.title:esc+]</subject>
    <message>[+comment.content:esc:nl2br:esc+]</message>
    </comment>
    `:strip+]
    


    2. Create a new chunk: JotXML
    You can enter the docid as a static value or you can use a snippet that takes a querystring id to create a dynamic source document. You can also add tag id if you want)

    <?xml version="1.0"?>
    [[Jot?docid=`45` &placeholders=`1` &output=`0` &tplComments=`JotTplXML` &pagination=`0`]]
    <jot>
    [+jot.html.comments+]
    </jot>


    3. Create a new document

    - Set the Content Type to: text/xml
    - In the document content field enter: {{JotXML}}

    View the page smiley
      Armand Pondman
      MODx Coding Team
      :: Jot :: PHx
      • 10357
      • 573 Posts
      great stuff grin
        • 1511
        • 144 Posts
        How to get ALL comments and put them in an XML, not just the ones from a specific document?
          • 4195
          • 398 Posts
          Quote from: andrazk at Dec 18, 2006, 10:25 AM

          How to get ALL comments and put them in an XML, not just the ones from a specific document?

          that isn’t possible yet, i was thinking of a next version that will support something like &docid=`*` and tagid=`*` that will give you all comments
            Armand Pondman
            MODx Coding Team
            :: Jot :: PHx
            • 26868
            • 15 Posts
            Here are the smalls hack for andrazk:
            I’ve also changed the chunks to export in true rss 2.0 format. it’s validated in rss validator and works for me in netvibes.

            1) docid = ’*’ :
            edit the file jot.db.class.inc.php in the includes folder of the snippet :
            Function GetCommentCount, at the end :
            replace :
            $sql = 'SELECT count(id) FROM '.$this->tbl["content"].' WHERE uparent = '.$docid.' AND tagid = "' . $tagid .'"'.$where;
            
            		return intval($modx->db->getValue($sql));

            by :
            		if ($docid == '*') {
                  $sql = 'SELECT count(id) FROM '.$this->tbl["content"].' WHERE tagid = "' . $tagid .'"'.$where;
                } else
                {
            		  $sql = 'SELECT count(id) FROM '.$this->tbl["content"].' WHERE uparent = '.$docid.' AND tagid = "' . $tagid .'"'.$where;
            		}
            		return intval($modx->db->getValue($sql));



            Function GetComments, at the end :
            replace :
            $sql = "select a.* from " . $tbl . " as a " . $tblcustom . " where uparent = '" . $docid . "' and tagid = '" . $tagid ."' and mode = '0' " . $where . $orderby . $limit;
            
            
            		#print $sql;
            		return $this->GetCommentsArray($sql);

            by :
            if ($docid == '*') {
                  $sql = "select a.* from " . $tbl . " as a " . $tblcustom . " where tagid = '" . $tagid ."' and mode = '0' " . $where . $orderby . $limit;
                } else
                {
            		  $sql = "select a.* from " . $tbl . " as a " . $tblcustom . " where uparent = '" . $docid . "' and tagid = '" . $tagid ."' and mode = '0' " . $where . $orderby . $limit;
            		}
            		
            		#print $sql;
            		return $this->GetCommentsArray($sql);


            That’s all for the ’*’ hack.

            RSS 2.0 output :

            JotTplXML :
            [+comment.published:is=`1`:then=`
            <item>
            <title><![CDATA[ [+comment.title:esc+] ]]></title>
            <link><![CDATA[ http://www.mysite.com/index.php?id=[+comment.uparent+] ]]></link>
            <author><![CDATA[ [+comment.createdby:userinfo=`username`:ifempty=`[+comment.custom.name:ifempty=`[+jot.guestname+]`+]`:esc+] ]]></author>
            <guid isPermaLink="false">[+comment.id+]</guid>
            <pubDate>[+comment.createdon:date=`%a, %e %b %Y %H:%M:%S %z`+] </pubDate>
            <description><![CDATA[ [+comment.content:esc:nl2br:esc+] ]]></description>
            </item>
            `:strip+]


            JotXML :
            <?xml version="1.0"?>
            [[JotRSS?docid=`*` &placeholders=`1` &output=`0` &tplComments=`JotTplXML` &pagination=`0`]]
            <rss version="2.0">
            <channel>
            <title>last comments</title>
            <link><![CDATA[http://www.mysite.com]]></link>
            <description>comments</description>
            <language>fr</language>
            <copyright>perso</copyright>
            <ttl>1</ttl>
            [+jot.html.comments+]
            </channel></rss>


            (you can of course change the datas inside <title>, <link>, <description>, <language>, <copyright> and <ttl>
              • 1511
              • 144 Posts
              Thanks for this mod.
              But since I’m not an expert in PHx (I must still explore this extension and its use) I’m interested in how to get the title of the document containing the comment to include it in the comment title.

              I’ll try to call a snippet with the comment owner ID as a parameter and get the document data. Will report if my idea works.

              Still, if I leave CDATA section in <description> tag, whole tpl is output like

              <copyright /> 
                <ttl>120</ttl> 
                [+comment.published:is=`1`:then=` 
               <item>
                <title>title</title> 
                <link>http://www.site.eu:80/#18a8bd4611</link> 
               <description>
               <![CDATA[                  Comment value
                ]]> 
                </description>
                <pubDate>Fri, 15 Dec 2006 14:09:36 +0100</pubDate> 
                <guid isPermaLink="false">http://www.site.eu:80/#11</guid> 
                <dc:creator>Irene</dc:creator> 
                </item>
                `:strip+] 
                </channel>
              


              Note the PHx placeholders. If there is no CDATA tag everything is OK.
                • 26868
                • 15 Posts
                oups sorry i’ve forgotten : it’s [+comment.uparent+]

                I’ve updated the chunk above with the <link> tag :
                <link><![CDATA[ http://www.mysite.com/index.php?id=[+comment.uparent+] ]]></link>
                  • 1511
                  • 144 Posts
                  I have a (looks like) PHx problem with Jot.

                  My document is
                  <?xml version="1.0" encoding="[(etomite_charset)]" ?>
                  <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
                  	<channel>
                  			<title>[*pagetitle*]</title>
                  			<link>[(site_url)][~39~]</link>
                  			<description>[*description*]</description>
                  			<language>english</language>
                  			<copyright>[(site_name)]</copyright>
                  			<ttl>120</ttl>
                  			
                  [[Jot? &docid=`*` &placeholders=`1` &output=`0` &tplComments=`tplJotRSSComments` &pagination=`0` ]]
                  [+jot.html.comments+]
                  </channel>
                  </rss>


                  and tplJotRSSComments
                  [+comment.published:is=`1`:then=`
                  			<item>
                  				<title>
                                                       <![CDATA[ comment for "[[getField?docid=`[+comment.uparent+]`]]" ]]>
                                                  </title>
                  				<link>[(site_url)][~[+comment.uparent+]~]#cid[+comment.id+]</link>
                  				<description>
                                                     <![CDATA[ [+comment.content:esc:nl2br:esc+] ]]>
                                                   </description>
                  				<pubDate>[+comment.createdon:date=`%a, %e %b %Y %H:%M:%S %z`+]</pubDate>
                  				<guid isPermaLink="false">[(site_url)][~[+comment.uparent+]~]#cid[+comment.id+]</guid>
                  				<dc:creator>[+comment.createdby:userinfo=`fullname`:ifempty=`[+comment.custom.name:ifempty=`[+jot.guestname+]`+]`:esc+]</dc:creator>
                  
                  			</item>
                  `:strip+]


                  The problem is that when I use CDATA in tplJotRSSComments the PHx tags
                  [+comment.published:is=`1`:then=`
                  
                  `:strip+]
                  
                  remains in the output XML.

                  As soon as there is no CDATA tags, everything is ok.
                  Why?