|
RelatedTwitterResultsInstallation
Related Twitter Results Installation Instructions - version 1.0 (GSA v6.0.0.G32)
Featured, Phase-Deploy, Deprecated IntroductionThis page contains the installation instructions for Related Twitter Results for the GSA. All the appropriate files can be found in the zip file that is available in the downloads section. DetailsInstallation Instructions: ==> NOTE: Google does not warranty or in any way guarantee the reliability of this code. Use it at your own risk. ==>NOTE: Before starting, it is important to use the parameter proxyreload=1 in your browser's URL line (for the search URL) in order to make sure that any changes to a stylesheet are reflected immediately. This parameter should not be used in production, but only for development as it forces the XSLT to be reread and parsed each time it is called. Step 1In the "Other variables (can be customized)" section of the xslt, place the following lines:
<!-- *** twitter options *** --> <!-- *** show_twitter valid values are 0 or 1 *** --> <xsl:variable name="show_twitter">1</xsl:variable> <!-- *** twitter_position valid values are top or right *** --> <xsl:variable name="twitter_position">top</xsl:variable>
Step 2Create the following xsl template, before the "My global page header/footer (can be customized)" section:
<xsl:template name="my_twitter">
<span class="p">
<xsl:text disable-output-escaping="yes"> <!-- Please enter html code below. --></xsl:text>
<!-- ********************************************************************** -->
<div name="my_twitter" id="my_twitter"><font size="1"><br/><br/>   Loading twitter results....</font></div>
<!-- ********************************************************************** -->
</span>
</xsl:template>
Step 3In the "Global Style (do not customize" section, before the </xsl:comment> tag, put in the following lines:
<xsl:if test="$show_twitter = '1'">
<xsl:choose>
<xsl:when test="$twitter_position = 'top'">
div#twitter {font-size: 84%; margin-top: 1em;}
div#twitter h3 {font-size: 100%; font-weight: bold; margin: 0; padding: 0;}
div#twitter table {margin-left: 2em; font-size: 100%;}
div#twitter table a {white-space: nowrap;}
div#twitter table td {padding-right: 1em;}
div#twitter #twitter_status {color: #666666; margin-left: 2em;}
</xsl:when>
<xsl:when test="$twitter_position = 'right'">
div#twitter {font-size: 84%; padding-left: 1em;}
div#twitter h3 {font-size: 100%; font-weight: bold; margin: 0 0 0.6em 0; padding
: 0;}
div#twitter ul {list-style: none; margin: 0; padding: 0;}
div#twitter li {margin-left: 2em; text-indent: -2em;}
div#twitter #twitter_status {color: #666666;}
</xsl:when>
</xsl:choose>
</xsl:if>
Step 4In the "Search results (do not customize)" section, change the following:
<xsl:choose>
<xsl:when test="$show_res_clusters = '1'">
<script language='javascript' src='common.js'></script>
<script language='javascript' src='xmlhttp.js'></script>
<script language='javascript' src='uri.js'></script>
<script language='javascript' src='cluster.js'></script>
<body onLoad="resetForms(); cs_loadClusters('{$search_url_escaped}', cs_drawClusters);" dir="ltr">
<xsl:call-template name="search_results_body"/>
</body>
</xsl:when>
<xsl:otherwise>
<body onLoad="resetForms()" dir="ltr">
<xsl:call-template name="search_results_body"/>
</body>
</xsl:otherwise>
</xsl:choose>
TO:
<xsl:choose>
<xsl:when test="$show_res_clusters = '1'">
<script language='javascript' src='common.js'></script>
<script language='javascript' src='xmlhttp.js'></script>
<script language='javascript' src='uri.js'></script>
<script language='javascript' src='cluster.js'></script>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$show_twitter = '1'">
<!-- Related Twitter Results code start -->
<script language='javascript' src='http://YOUR_HOST/twitter.js'></script>
<!-- Related Twitter Results code end -->
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$show_res_clusters = '1' and $show_twitter = '1'">
<body onLoad="resetForms(); cs_loadClusters('{$search_url_escaped}', cs_drawClusters);twLoad('my_twitter', '{$search_url_escaped}');" dir="ltr">
<xsl:call-template name="search_results_body"/>
</body>
</xsl:when>
<xsl:when test="$show_res_clusters = '1'">
<body onLoad="resetForms(); cs_loadClusters('{$search_url_escaped}', cs_drawClusters);" dir="ltr">
<xsl:call-template name="search_results_body"/>
</body>
</xsl:when>
<xsl:when test="$show_twitter = '1'">
<body onLoad="resetForms();twLoad('my_twitter', '{$search_url_escaped}');" dir="ltr">
<xsl:call-template name="search_results_body"/>
</body>
</xsl:when>
<xsl:otherwise>
<body onLoad="resetForms()" dir="ltr">
<xsl:call-template name="search_results_body"/>
</body>
</xsl:otherwise>
</xsl:choose>
Step 5At this point, you can either decide to have the javascript for twitter search loaded from a remote location, or internally to the XSLT. If you choose from a remote location, then change the value YOUR_HOST in the following line (as inserted into the XSLT in Step 4):
<script language='javascript' src='http://YOUR_HOST/twitter.js'>//Comment</script>
to the hostname and path where you have placed the twitter.js file. Otherwise, you must replace the following line:
<script language='javascript' src='http://YOUR_HOST/twitter.js'>//Comment</script>
with the contents of the twitterInclude.txt file. Step 6Place any other twitter search function calls that are required, before the twLoad statement, which were put into the XSLT in Step 3. For more information on the list of available functions and their description, please see the Related Twitter Results documentation or the readme.txt file. Step 7Call the twitter template by modifying the section labelled 'Handle results (if any)' from:
<!-- *** Handle results (if any) *** -->
<xsl:choose>
<xsl:when test="RES or GM or Spelling or Synonyms or CT or /GSP/ENTOBRESULTS">
<xsl:call-template name="results">
<xsl:with-param name="query" select="Q"/>
<xsl:with-param name="time" select="TM"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="Q=''">
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="no_RES">
<xsl:with-param name="query" select="Q"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
TO:
<table border="0" width="100%">
<xsl:if test="$show_twitter = '1' and $twitter_position = 'top'">
<tr>
<td valign="middle" width="100%">
<xsl:call-template name="my_twitter">
</xsl:call-template>
</td>
</tr>
</xsl:if>
<tr>
<td valign="top" width="750">
<!-- *** Handle results (if any) *** -->
<xsl:choose>
<xsl:when test="RES or GM or Spelling or Synonyms or CT or /GSP/ENTOBRESULTS">
<xsl:call-template name="results">
<xsl:with-param name="query" select="Q"/>
<xsl:with-param name="time" select="TM"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="Q=''">
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="no_RES">
<xsl:with-param name="query" select="Q"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</td>
<xsl:if test="$show_twitter = '1' and $twitter_position = 'right'">
<td valign="top" width="250">
<xsl:call-template name="my_twitter">
</xsl:call-template>
</td>
</xsl:if>
</tr>
</table>
|
Nice!
Any tips on how to do it if you don't use the xslt? I have made my own templates which parse and tranform the xml.
First some comments. The code defaults to using the 'twitter' keyword so you'll need to add word 'twitter' to your searches in order to see any results with the code that's posted here. You can change the need for a keyword with the twSetUseTrigger function.
Also setting twSetTitle does not appear to do anything. The variable in the js file is set to "Twitter Results" but even this default setting doesn't show up in the test center.
Now a question, How can I limit the search of twitter to a specific account or accounts. I would like to only return tweets from http://twitter.com/USGS