MyBB Community Forums

Full Version: twitter search integrated with forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I created this little hack in order to display a real-time twitter search within specific forums on my test site. It involves the use of a plugin that allows for the addition of php code within a template -- I realize there are some potential security issues with this, so if anyone can suggest a way to achieve the same results without the use of php, please let me know! (newbie coder here)

It automatically displays related tweets below the thread list in a forum, based on the NAME of the forum -- so if the forum is titled "Vampire Diaries" then it will automatically list tweets related to this subject, thanks to a search widget provided by twitter.

Steps:
1. download required plugin
2. see widget example at https://twitter.com/about/resources/widg...get_search
3. modify your forumdisplay_threadlist template file using the supplied code, or with modifications from the twitter link above

--

Download the "PHP in Templates / Complex Templates" plugin found at:
http://mybbhacks.zingaburga.com/showthread.php?tid=260 (needed in order to allow for php code within your template)

Add this code to the end of the forumdisplay_threadlist template file:

<?php
if ($fid == 7 || $fid == 15) { $tweetfrom = date("Y-m-d"); print "

<BR><BR>

<!-- realtime related tweets -->
<script src=\"http://widgets.twimg.com/j/2/widget.js\"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: '\"{$foruminfo['name']}\" -expletive since:$tweetfrom',
  interval: 30000,
  title: 'Related tweets (Note: we are not responsible for external links nor any other content below)',
  subject: '',
  width: 'auto',
  height: 300,
  theme: {
    shell: {
      background: '#750000',
      color: '#ffffff'
    },
    tweets: {
      background: '#f5f5f5',
      color: '#000000',
      links: '#828282'
    }
  },
  features: {
    scrollbar: true,
    loop: false,
    live: false,
    behavior: 'default'
  }
}).render().start();
</script>

"; } ?>

Notes:
  • $fid == 7 || $fid == 15 are set so that the twitter search is only displayed in these two forums (modify as needed for your site)
  • search: '\"{$foruminfo['name']}\" -expletive since:$tweetfrom' allows for the display of tweets related specifically to the forum name; remove the double quotes if you do not want to look for the exact phrase. The $tweetfrom variable is set to the current date, so the widget will only display tweets from the same day as when the user is viewing the forum. Also, be sure to change -expletive in order to filter out tweets containing bad language; more can be added, for example -badword1 -badword2
  • additional search examples can be found at http://support.twitter.com/groups/31-twi...ter-search
  • if you want to avoid useless musings from the twitterverse, you can add specific twitter IDs to the search, so results will come from only trusted sources (such as @CNN for example)

Not entirely sure how useful this will be, but it is a test site so I'm just seeing what I can come up with. Wink

Cheers, Brad.


[attachment=24467]