Search

We have a twitter feed being pulled into the page on the symphony powered site, but was wondering if there was a way to ensure the formatting of the URL/links in a tweek were rendered as actual links on the page?

Anybody done this?

Client has been told to use shrimp to shorten urls when they enter them in twitter! so all that is needed is the expression to allow url/links to be clickable on the rendered page?

cheers

moonoo2

Should be pretty simple. Let’s say your feed items look like this:

<item>
    <title>symphonycms: Symphony site down again. The issue is the same as last week -- over zealous backup system. Promise to fix it for good this time.</title>
    <description>symphonycms: Symphony site down again. The issue is the same as last week -- over zealous backup system. Promise to fix it for good this time.</description>
    <pubDate>Wed, 23 Sep 2009 11:04:26 +0000</pubDate>
    <guid>http://twitter.com/symphonycms/statuses/4312971259</guid>
    <link>http://twitter.com/symphonycms/statuses/4312971259</link>
</item>

Once you get into the item scope (with something like <xsl:apply-templates select="item"/> or <xsl:for-each select="item">), you just create a link like so:

<a href="{link}"><xsl:value-of select="link"/></a>

Is that what you’re after?

You may be interested in Dustin Diaz’s Twita@talinkahashifyer which reverse-engineers the Twitter formatting by adding back in the @username links and hyperlinking any URLs. If you don’t fancy relying on JavaScript then check out a port to XSLT.

For me I have this bit of XML

<text>Great screencast for Things - http://bit.ly/3nuwkn</text>

How do I get that url to be treated as a link?

I am calling my tweets like this:

<xsl:for-each select="/data/tweets/statuses/status[1]">

<p><xsl:value-of select="text"/></p>

</xsl:for-each>

What about this:

<xsl:for-each select="/data/tweets/statuses/status[1]">
    <xsl:variable name="link"><xsl:value-of select="substring-after(text, ' - ')" /></xsl:variable>
    <p><xsl:value-of select="substring-before(text, 'http://')"/><a href="{$link}"><xsl:value-of select="$link" /></a></p>
</xsl:for-each>

I think that regular expressions solves your problem.

That shows nothing now.

Must be an Xpath problem.

As far as I know libXSLT doesn’t support regex.

@phoque http://www.exslt.org/regexp/regexp.html, Doesn’t it work?

Yup. I tried it once and failed. Plus, the libXSLT EXSLT API Reference doesn’t mention it anywhere.

What Nils did looked like it may work, but what it actually did was remove the content completely. I have looked through his code and it looks fine, but it’s not picking up the data.

Unfortunately the regular expressions functions of EXSLT are not supported with libXSLT. To check, view the function page on the EXSLT site and look for “libxslt” in the table under the heading “IMPLEMENTATIONS”.

Nil’s solution is the next best thing. Did you look at my XSLT version of Dustin Diaz’s Twita@talinkahashifyer above? It should do exactly what you’re after. Call the linkahashify template as pass a parameter named tweet with the plain text content of your Tweet.

Strangely, Nils example now works. Weird.

Hmm, yesterday it worked.

I want to try a simpler method before the Dustin Diaz example.

This is my code:

<xsl:template name="tweeting">
<h3>What's Been Tweeted?</h3>
<xsl:for-each select="tweets/statuses/status[position() = 1]">
<xsl:variable name="link"><xsl:value-of select="substring-after(text, ' - ')" /></xsl:variable>
<p><xsl:value-of select="substring-before(text, 'http://')"/><a href="{$link}"><xsl:value-of select="$link" /></a></p>
</xsl:for-each>
<p class="twitter"><a href="http://twitter.com/NickToye">Follow me on Twitter</a>.</p>
</xsl:template>

Does that look right?

How and where do I place this bit of code?

ify.clean('my tweet text')

I have a xsl file called twitter.xsl and the markup for this file is as template match=”twitter” etc..

and then value=of text .. but not sure where to place the above javascript in the loop for-each I thought it could be

ify.clean('<xsl:value-of "text">')

But this just seems to add the ify.clean etc.. to the outputted string?

any ideas?

P.S

I have included the javascript code itself in the master template and it is being called to the page in the head section.

Look at the source of the Twita@talinkahashifyer page and you’ll see how Dustin does this unobtrusively. With JavaScript you will want to select the elements containing the tweet text, get their text content (innerHTML) then replace the element’s content with the ify.clean version.

@NickToye I think the code you use above will only work if you have one link, it’s after the tweet text and after ’ - ‘.

If you want an XSLT solution, I might suggest using nickdunn’s utility linked above.

That would be tougher than the JavaScript solution, though. JS would also link up @ and # links without having to write some gnarly XSLT.

@nickdunn I like that JavaScript solution. I’m gonna have to bookmark that.

No probs… I wish it was my idea! But I did already port it to XSLT if you’re interested. @NickToye, if you can’t get the JS working then try out my utility.

@nickdunn Sorry, I missed the link above. I edited my post. :-P

Your utility is awesome. Will bookmark that too.

@nickdunn, I plan to - just having time.

I’ll put down to do tomorrow night when I get back from my other job.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details