Bibsonomy Macro

Last modified by Thomas Mortagne on 2010/12/17 11:10

##################################################################################################
## This is a dirty, ugly hack. it does the job, but its probably very inefficient and unstable. ##
##################################################################################################
## The following is a set of scripts which allow you to display a list of publications from     ##
## bibsonomy. This list is retrieved from the RSS feed of a tag. There's no option to limit the ##
## list to a specific user, etc. The easiest way to use this is to add the following two lines  ##
## to your page:                                                                                ##
##    #includeInContext("scripts.Bibsonomy")                                                    ##
##    #publications_pp("MyTag")                                               ##
##################################################################################################
## to make this code decent, we should use the bibsnomy API, retrieve the list in XML and       ##
## process that, probably in groovy.                                                            ##
##################################################################################################
## This code is provided as is, with no warranties, guaranties, or liabilities.                 ##
## It is licensed under a Creative Commons BY-NC-SA 2.0 UK: England & Wales License.            ##
## http://creativecommons.org/licenses/by-nc-sa/2.0/uk/                                         ##
## Yishay Mor, yishaym@gmail.com                                                                ##
##################################################################################################


#set ($basename = $doc.getFullName()+".")
#set ($createUrl = "?create=")

#### create a new discussion page for bibsonomy entry
#macro(createPage $item $pagename)
#set ($newdoc = $xwiki.getDocument($pagename))
$newdoc.setParent($doc.getFullName())
#set ($content = '<div style="border: 3px coral solid;">'+$item.getDescription().value+'</div>')
$newdoc.setContent($content)
$newdoc.save()
## this should work, but needs programming rights:
## $context.setDoc($newdoc)
<script type="text/javascript">
<!--
window.location = "$newdoc.getExternalURL()"
//-->
</script>

#end ### createPage

#### display a bibsonomy tag feed
#macro(bibsonomyfeed $feed $label $raw)
#if ($label)
<h3> $label </h3>
#end
#foreach ($entry in $feed.entries) 
$entry.getDescription().value
<br />
#if(0)
#set($val = $entry.getDescription().value)
#if(!$raw)
 ## get title
 #set($index = $val.indexOf("bmtitle") +10)
 #set($val = $val.substring($index))
 #set($index = $val.indexOf("</div>"))
 #set($headline = $val.substring(0, $index))
 #set($index = $index +6)
 #set($val = $val.substring($index))

----
 <h4> $headline </h4>
 ## xtract bibsonomy key
 #set ($index = $headline.indexOf("/bibtex/") + 8)
 #if ($index <0) #set($index = 0) <!-- /bibtex/ --> #end
 #set ($bibkey = $headline.substring($index))
 #set ($index  = $bibkey.indexOf("/"))
 #if ($index <0) #set($index = 0) <!-- / --> #end
 #set ($bibkey = $bibkey.substring(0, $index))
 ## generate link to discussion doc
 #set($itempagename = $basename+$bibkey)
 #if ($request.create == $bibkey)
    #createPage($entry $itempagename)
 #end

 ## page exists?
 #if ($xwiki.exists($itempagename))
    #set ($comcount = 0)
    #set ($bibdoc = $xwiki.getDocument($itempagename))
    #set ($comcount = $bibdoc.getComments().size())
    <a href="$bibdoc.getURL()">$comcount comments</a>
 #else
    <a href="$createUrl$bibkey">Discuss (new)</a>
 #end
 #if ($request.showabstracts.equalsIgnoreCase("true")) 
    ## do nothing
 #else
    ## cut after the reference
    #set ($index = $val.indexOf("</div>") +6)
    #if ($index <0) #set($index = 0) <!-- /div --> #end
    #set ($val = $val.substring(0,$index))
 #end

<blockquote>
\{pre\}
<div>
#else
----
\{pre\}
#end ## raw
$val
\{/pre\}
</blockquote>
#end
#end
#end #### macro(bibsonomy $tag)

############## bibsonomy publications feed
#macro(publications $tag) 
#if ($request.filter && $request.filter.length() > 0)
#set ($tag = $tag+'+'+$request.filter)
#end
#set($feed = $xwiki.feed.getFeeds("http://www.bibsonomy.org/publrssN/tag/${tag}?items=1000"))
#set($title = '<a href="http://www.bibsonomy.org/tag/'+$tag+'">'+$tag+'</a> publications' )
#bibsonomyfeed( $feed $title false)
#end
############## /bibsonomy publications feed

############## bibsonomy publications feed with controls
#macro(publications_pp $tag) 
<form action="" id="publications" method="post">
<input type="checkbox" #if ($request.showabstracts) checked #end name="showabstracts" value="true" />&nbsp;Show abstracts&nbsp;
<input type="text" size="20" name="filter" value="$!request.filter" />
<input type="submit" name="filter" value="Filter" />
</form>

#publications($tag)
#end
############## /bibsonomy publications feed with controls
#macro(publicationspp $tag) 
#publications_pp($tag)
#end

############## bibsonomy links feed
#macro(links $tag) 
#set($feed = $xwiki.feed.getFeeds("http://www.bibsonomy.org/rss/tag/${tag}?items=1000"))
#set($title = '<a href="http://www.bibsonomy.org/tag/"'+$tag+'">'+$tag+'</a> links' )
#bibsonomyfeed( $feed $title true)
#end
############## /bibsonomy publications feed

############## bibsonomy all NOT WORKING
#macro(bibsonomyall $tag) 
<div style="float:left;width:40%;padding:5px;border:1px solid black;">
#publications( $tag)
</div>
<div style="float:left;width:40%;padding:5px;border:1px solid black;">
#links( $tag)
</div>

#end
############## /bibsonomy all