[TYPO3] Building a "Digg this" link

Christopher Torgalson bedlamhotel at gmail.com
Wed Jan 10 21:15:28 CET 2007


Hi,

On 1/10/07, Jason A. Lefkowitz <jason at jasonlefkowitz.net> wrote:
> Hey everybody...
>
> I've been playing around with adding "Digg this" links to my TYPO3 site.
>   If you don't know about Digg (http://www.digg.com/), it's a "Web 2.0"
> news site where the content is submitted and voted on by the readers.
> You can add links to the pages on your site that will let Digg users
> submit those pages for publication on Digg.
>
> The format of the URL for a "Digg this" link is like this:
>
> http://digg.com/submit?phase=2&url=www.UniqueURL.com&title=StoryTitle&bodytext=StoryDescription&topic=YourSelectedTopic
>
> ... where "url" is the url to the page you want the user to submit,
> "title" is the title of the page/story, "bodytext" is the text of the
> submission (this is optional), and "topic" is a category of stories from
> Digg's taxonomy.  (more info available at http://digg.com/tools/integrate).
>
> I was thinking it would be relatively easy to use Typoscript to build
> links on every page to allow users to Digg that page.  Assuming we've
> set up a Typoscript object in the data structure called lib.digg_this to
> hold the link, and we want to submit our pages into Digg's "Apple"
> topic, my thought was this should work:
>
> lib.digg_this = TEXT
> lib.digg_this.value = Digg this page
> lib.digg_this.dataWrap = <a
> href="http://digg.com/submit?phase=2&url=www.mysite.com/index.php?id={
> page : uid }&title={ page : title }&topic=apple"> | </a>
>
> And in most cases, it does.  However, the value of the "title" attribute
> (being inserted via the { page : title } gettext function) isn't
> URL-encoded, so if the title of the page contains any special
> characters, you get weird results.
>
> So I've been trying to figure out how to URL-encode the link HREF,
> substitute the encoded value into the datawrap, and then wrap it all
> around the TEXT object.  But after hours of thinking, I can't come up
> with a solution.
>
> I'm sure there's some obvious and easy way that I'm just missing.  Any
> ideas?
>

Break it into parts and use a COA; you can use the stdWrap
property/php function rawUrlEncode:

lib.diggit = COA
lib.diggit {
  # http://digg.com/submit?phase=2
  # &url=www.UniqueURL.com
  # &title=StoryTitle
  # &topic=YourSelectedTopic

  stdWrap.dataWrap = <a href="http://digg.com/submit?phase=2|">Digg
this: {field:title}</a>

  # url parameter:
  5 = HTML
  5 {
    value {
      typolink {
        parameter.data = field:uid
        returnLast = url
        wrap = &url=|
      }
    }
  }

  # title parameter:
  10 = HTML
  10 {
    value {
      data = field:title
      rawUrlEncode = 1
      wrap = &title=|
    }
  }

  # topic parameter:
  15 = HTML
  15 {
    value = apple
    value {
      wrap = &topic=|
    }
  }
}

Not tested, but should work unless I've missed something obvious.

-- 
Christopher Torgalson


More information about the TYPO3-english mailing list