Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-14431

Code to improve description field content for RSS feed

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Minor
    • None
    • 1.9.1
    • Distribution - Flavor
    • None
    • Velocity RSS patch
    • Awaiting Pull Request creation

    Description

      Currently description field for RSS feed doesn't contain useful information.
      Below is fixed code from ../xwiki/bin/edit/XWiki/WebRssCode?editor=wiki
      This code makes shortened plain text content form Xwiki document or included object, if it is used (currently for Blog (Xwiki enterprise default) and Recipes (My Custom object)).

      Probably there is no need to use separate Blog feed when this code is corrected.

      Start looking (and merge from) place with:

      ...
      ####################################
      ## Format content for description ##
      ####################################
      ....
      

      till:

      ...
      <description>
      $ccont
      $msg.get("xe.rss.version") $currentdoc.version $msg.get("xe.rss.editedby")
      $xwiki.getXMLEncoded($xwiki.getUserName($currentdoc.author, false))
      </description>
      ....
      {pre}
      $context.setCacheDuration(1800)
      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/" xmlns:html="http://www.w3.org/1999/xhtml">
      <channel rdf:about="$baseurl">
      <title>
      #if($title)
      $title
      #else
      $request.serverName
      #end
      </title>
      <link>$baseurl</link>
      <description>
      #if($description)
      $description
      #else
      $request.serverName
      #end
      </description>
      #set($logourl = $xwiki.getSkinFile($xwiki.getSkinPreference('logo', 'logo.png')))
      #set($port = "")
      #if(($request.scheme == "http") && ($request.serverPort != 80))
      #set($port = ":${request.serverPort}")
      #elseif(($request.scheme == "https") && ($request.serverPort != 443))
      #set($port = ":${request.serverPort}")
      #end
      #set($logourl = "${request.scheme}://${request.serverName}${port}$logourl")
      <image rdf:resource="$logourl"/>
      <dc:language>$doc.defaultLanguage</dc:language>
      <dc:rights>$xwiki.getXMLEncoded($xwiki.webCopyright.replaceAll('<', '<html:').replaceAll('<html:/', '</html:'))</dc:rights>
      <dc:publisher>$xwiki.getUserName($doc.author, false)</dc:publisher>
      <dc:creator>$xwiki.getUserName($doc.author, false)</dc:creator>
      <items>
      <rdf:Seq>
      #if(!$list)
      #if(!$sql)
      #set($sql = "where 1=1 order by doc.date desc")
      #end
      #set($list = $xwiki.searchDocuments($sql, 20, 0))
      #end
      #set($list = $xwiki.wrapDocs($list))
      #foreach ($currentdoc in $list)
      #if($xwiki.hasAccessLevel("view", "${context.database}:${currentdoc.fullName}"))
      <rdf:li rdf:resource="$currentdoc.getExternalURL('view', "language=${currentdoc.realLanguage}")" />
      #end
      #end
      </rdf:Seq>
      </items>
      </channel>
      <image rdf:about="$logourl">
        <title>XWiki Logo</title>
        <link>${baseurl}</link>
        <url>$logourl</url>
      </image>
      #foreach ($currentdoc in $list)
      #if($xwiki.hasAccessLevel("view", "${context.database}:${currentdoc.fullName}"))
      #set($url = $currentdoc.getExternalURL('view', "language=${currentdoc.realLanguage}"))
      
      ####################################
      ## Format content for description ##
      ####################################
      ## Get Xwiki document content
      #set($ccont=$currentdoc.content)
      
      ## If document includes object, get content from related object
      #if($ccont.indexOf("include")>-1)
       ## If Blog object is included
       #if($ccont.indexOf("Blog.BlogPostSheet")>-1)
        #set($ccont=$currentdoc.getObject("Blog.BlogPostClass").extract)
       #end
       ## If Recipe object is attached (would be nice, If you will not remove this clause :-))
       #if($ccont.indexOf("Recipes.RecipeClassSheet")>-1)
        #set($ccont=$currentdoc.getObject("Recipes.RecipeClass").content)
       #end
       ## Feel free to add clauses for your custom objects here
      #end
      
      ## Clean up content
      ## Remove HTML links
      #set($ccont=$ccont.replaceAll('(\<(/?[^\>]+)\>)',''))
      ## Remove HTML links
      #set($ccont=$ccont.replaceAll('<a href="[^"]+">',''))
      ## Remove Xwiki links
      #set($ccont=$ccont.replaceAll('[\||\>](/?[^\>]+)\]',''))
      ## Clean up special characters if some were left
      #set($ccont=$ccont.replaceAll('[\<|\>|\*|\[|\]]',''))
      
      ## Shorten content
      #if ($ccont.length() < 255)
       #set ($length = $ccont.length())
      #else
       #set ($length = 255)
      #end
      #set($ccont=$ccont.substring(0,$length))
      
      <item rdf:about="$url">
      <title>$xwiki.getXMLEncoded(${currentdoc.displayTitle})</title>
      <link>$url</link>
      <description>
      $ccont
      $msg.get("xe.rss.version") $currentdoc.version $msg.get("xe.rss.editedby")
      $xwiki.getXMLEncoded($xwiki.getUserName($currentdoc.author, false))
      </description>
      #set($tz = $xwiki.formatDate($currentdoc.date, "Z"))
      #set($tz = "${tz.substring(0, 3)}:${tz.substring(3)}")
      <dc:date>$xwiki.formatDate($currentdoc.date, "yyyy-MM-dd")T$xwiki.formatDate($currentdoc.date, "hh:mm:ss")$tz</dc:date>
      <dc:creator>$xwiki.getXMLEncoded($xwiki.getUserName($currentdoc.creator, false))</dc:creator>
      <dc:contributor>
      <rdf:Description link="">
      <rdf:value>$xwiki.getXMLEncoded($xwiki.getUserName($currentdoc.author, false))</rdf:value>
      </rdf:Description>
      </dc:contributor>
      </item>
      #end
      #end
      </rdf:RDF>
      {/pre}
      

      Attachments

        1. code.txt
          4 kB
          Valdis Vitolins

        Activity

          People

            Unassigned Unassigned
            valdisvi Valdis Vitolins
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: