Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length


News:

Can't find exactly what you've been wanting? Try searching for what you are looking for in the search box to the right. ----------->


AuthorTopic: Twitter Integration Modification  (Read 629 times)

Mark

  • Basic Member
  • *
  • Reputation Power: 10
  • Mark has no influence.
  • Offline Offline
  • Posts: 17
    • MSN Messenger - musicalme@live.com.au
    • View Profile
    • Email
Twitter Integration Modification
« on: December 18, 2009, 06:35:50 PM »
Please be kind, this is the first modification that I have made.  :)

PART A - Twitter Announcements
1. Copy and paste the code below into a file and name it tannounce.php
2. Change where it says "whatsonthetube" to your Twitter username

Code: [Select]
<?php
/*
MCCodes Lite v2
Copyright (C) 2009-2010 Cronwerks.com
MCCodes Lite original copyright held by Dabomstew(MCCodes.com)

Director:
MarDavFur
www.criminalterritory.com

Other Developers:
1. Username_Here - http://www.cronwerks.com/forum/profile/Username_Here/
2. Username_Here - http://www.cronwerks.com/forum/profile/Username_Here/
3. Username_Here - http://www.cronwerks.com/forum/profile/Username_Here/
4. Username_Here - http://www.cronwerks.com/forum/profile/Username_Here/
5. Username_Here - http://www.cronwerks.com/forum/profile/Username_Here/
*/
session_start();
require 
"global_func.php";
if(
$_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require 
"header.php";
$h = new headers;
$h->startheaders();
include 
"mysql.php";
global 
$c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm);
$h->menuarea();
$tresder=(int) rand(100,999);
print 
"
<script src='http://widgets.twimg.com/j/2/widget.js'></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 4,
  interval: 6000,
  width: 500,
  height: 500,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#07d0eb'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('whatsonthetube').start();
</script>"
;
$h->endpage();
?>


3. Open mainmenu.php and find:

Code: [Select]
<a href='announcement.php'>Announcements</a><br />
and add below

Code: [Select]
<a href='tannounce.php'>Twitter</a><br />
PART B - Twitter Profile Integration
1. Create tusername in the users table, and set the default to your Twitter account username
2. Copy and paste the following into your viewuser.php page

Code: [Select]
<script src='http://widgets.twimg.com/j/2/widget.js'></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 4,
  interval: 6000,
  width: 500,
  height: 500,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#07d0eb'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('{$r['tusername']}').start();
</script>

3. Open preferences.php and find:

Code: [Select]
case 'picchange':
pic_change();
break;

Then add below:

Code: [Select]
case 'twitterusername':
twitter_username();
break;

case 'twitterchange':
do_twitter_change();
break;

You will then need to find:

Code: [Select]
<a href='preferences.php?action=picchange'>Display Pic Change</a><br />
And add below:

Code: [Select]
<a href='preferences.php?action=twitterusername'>Twitter Username</a><br />
Then add the following function at the bottom of the page:

Code: [Select]
function twitter_username()
{
global $ir,$c,$userid,$h;
print "<form action='preferences.php?action=twitterchange' method='post'>
Twitter Username: <input type='text' name='twitterchange' /><br />
<input type='submit' value='Change Name' /></form>";
}
function do_twitter_change()
{
global $ir,$c,$userid,$h;
if($_POST['twitterchange'] == "")
{
print "You did not enter a Twitter Username.<br />
<a href='preferences.php?action=twitterusername'>&gt; Back</a>";
}
else
{
$_POST['twitterchange']=str_replace(array("<", ">", "\\\'"), array("&lt;", "&gt;", "&#039;"), $_POST['twitterchange']);
mysql_query("UPDATE users SET tusername='{$_POST['twitterchange']}' WHERE userid=$userid",$c);
print "Twitter username changed!";
}
}

What you should have achieved, if I posted everything correctly:
1. You should have an announcements page showing your Tweet updates
2. There should be a Twitter module on the viewuser.php page, most likely displaying your tweets by default
3. Users should be able to change the Twitter username in Preferences, thus changing tweets displayed on their profile

What you can do to help:
I am a novice at programming, and it would be good if people could help me to improve this modification. A change that I would like to make is the option for users to hide the module on their profile if they do not have Twitter or do not wish to use it.
Logged

Mark

  • Basic Member
  • *
  • Reputation Power: 10
  • Mark has no influence.
  • Offline Offline
  • Posts: 17
    • MSN Messenger - musicalme@live.com.au
    • View Profile
    • Email
Re: Twitter Integration Modification
« Reply #1 on: December 18, 2009, 06:41:55 PM »
Logged

catles

  • Basic Member
  • *
  • Reputation Power: 20
  • catles has no influence.
  • Offline Offline
  • Posts: 25
    • View Profile
    • Email
Re: Twitter Integration Modification
« Reply #2 on: December 18, 2009, 08:59:38 PM »
to hide this on profile
SQL
Code: [Select]
ALTER TABLE `users` ADD `showtwitt` INT( 1 ) NOT NULL DEFAULT '0'

the profile code
Code: [Select]
if ($ir['showtwitt']==1)
{
echo "
<script src='http://widgets.twimg.com/j/2/widget.js'></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 4,
  interval: 6000,
  width: 500,
  height: 500,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#07d0eb'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('{$r['tusername']}').start();
</script>";
}

and the very end thing you added

Code: [Select]
function twitter_username()
{
global $ir,$c,$userid,$h;
print "<form action='preferences.php?action=twitterchange' method='post'>
Twitter Username: <input type='text' name='twitterchange' /><br />
<input type='submit' value='Change Name' /></form>";
}
function do_twitter_change()
{
global $ir,$c,$userid,$h;
if($_POST['twitterchange'] == "")
{
print "You did not enter a Twitter Username.<br />
<a href='preferences.php?action=twitterusername'>&gt; Back</a>";
}
else
{
$_POST['twitterchange']=str_replace(array("<", ">", "\\\'"), array("&lt;", "&gt;", "&#039;"), $_POST['twitterchange']);
mysql_query("UPDATE users SET tusername='{$_POST['twitterchange']}' WHERE userid=$userid",$c);
mysql_query("UPDATE users SET showtwitt='1' WHERE userid=$userid",$c);
print "Twitter username changed!";
}
}


now you could also do the way the pic one works to witch i can show you if you like it may end up working better
Logged

Mark

  • Basic Member
  • *
  • Reputation Power: 10
  • Mark has no influence.
  • Offline Offline
  • Posts: 17
    • MSN Messenger - musicalme@live.com.au
    • View Profile
    • Email
Re: Twitter Integration Modification
« Reply #3 on: December 18, 2009, 10:24:52 PM »
Thanks for your input. If you believe that it has a benefit, then by all means post it.  :)
Logged

catles

  • Basic Member
  • *
  • Reputation Power: 20
  • catles has no influence.
  • Offline Offline
  • Posts: 25
    • View Profile
    • Email
Re: Twitter Integration Modification
« Reply #4 on: December 18, 2009, 10:30:25 PM »
well i looked over it and realized you can do more with this one then the other one including not limited to the user can make it so only  friends can see it tho it would be harder to code
Logged

Mark

  • Basic Member
  • *
  • Reputation Power: 10
  • Mark has no influence.
  • Offline Offline
  • Posts: 17
    • MSN Messenger - musicalme@live.com.au
    • View Profile
    • Email
Re: Twitter Integration Modification
« Reply #5 on: December 18, 2009, 10:48:11 PM »
well i looked over it and realized you can do more with this one then the other one including not limited to the user can make it so only  friends can see it tho it would be harder to code

That would not be a bad idea, it could put the friends list feature to use. This way users would be able to control who sees their tweets in the game, and only allow people on their friends list to see them. (I am not sure if the friends list is in the lite version, though I am sure that it can be coded in.)
Logged

Danny696

  • Excellent Member
  • ***
  • Reputation Power: 276
  • Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.
  • Offline Offline
  • Posts: 457
    • View Profile
Re: Twitter Integration Modification
« Reply #6 on: December 19, 2009, 06:36:58 AM »
I like the mod, but what about people who dont use twitter
Logged
My Game: GraveYard; Madness || Projects; N/A -  Available for work. Please IM/PM me.

Cronus

  • Administrator
  • Excellent Member
  • *****
  • Reputation Power: 1870
  • Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!
  • Offline Offline
  • Posts: 479
    • View Profile
    • WWW
Re: Twitter Integration Modification
« Reply #7 on: December 19, 2009, 07:06:09 AM »
Since this is only a lite version, i don't believe it will need twitter integration.
However it is a good thought, perhaps on a later version
Logged

dominion

  • Basic Member
  • *
  • Reputation Power: 67
  • dominion has no influence.
  • Offline Offline
  • Posts: 85
    • View Profile
    • Email
Re: Twitter Integration Modification
« Reply #8 on: December 19, 2009, 07:18:06 AM »
hey mark is it ok if i play around with this i would like to make it work with the game i have been developing

and cronus i think you should having one or two things that even v2 does not have will get people to stop trying to find v2 for free when they see this can be worked on it would also get them to buy more of your mods  ;)
« Last Edit: December 19, 2009, 07:43:46 AM by dominion »
Logged

Mark

  • Basic Member
  • *
  • Reputation Power: 10
  • Mark has no influence.
  • Offline Offline
  • Posts: 17
    • MSN Messenger - musicalme@live.com.au
    • View Profile
    • Email
Re: Twitter Integration Modification
« Reply #9 on: December 19, 2009, 09:27:00 AM »
hey mark is it ok if i play around with this i would like to make it work with the game i have been developing

and cronus i think you should having one or two things that even v2 does not have will get people to stop trying to find v2 for free when they see this can be worked on it would also get them to buy more of your mods  ;)

Sure, that is not a problem. :)

Danny696, I am not suggesting that it comes included in the script, I am just suggesting that documentation be included with instructions on how to install the modification, in case someone likes it and wants to use it.

Cronus, Dominion is right about including features that V2 doesn't even have, and it does give you an opportunity to make some more money, and reduce the amount of V2 pirate websites. If you decide otherwise, then could you please move this thread to the free modifications section, rather than delete it. :)
Logged

Zeddicus

  • Basic Member
  • *
  • Reputation Power: 0
  • Zeddicus is looked down upon.Zeddicus is looked down upon.
  • Offline Offline
  • Posts: 41
    • View Profile
    • WWW
Re: Twitter Integration Modification
« Reply #10 on: December 19, 2009, 11:17:16 AM »
Mark, I do suggest using "mysql_real_escape_string" on your "$_POST['twitterchange']".
And also securing output to stop XSS ect ect

Other than that it looks pretty good :)
« Last Edit: December 19, 2009, 12:16:48 PM by Zeddicus »
Logged
New Forums http://McAddons.com.
Sign up for all the latest security updates and modifications!

Djkanna

  • Basic Member
  • *
  • Reputation Power: 0
  • Djkanna is looked down upon.
  • Offline Offline
  • Posts: 26
    • View Profile
Re: Twitter Integration Modification
« Reply #11 on: December 19, 2009, 12:19:06 PM »
I use this on my blog

Code: [Select]
<?php

function Twitter($id){
    
$link "http://twitter.com/statuses/user_timeline/$id.xml?count=1";
    
$loadxml simplexml_load_file($link) or die("Twitter Account: Invalid");
    foreach(
$loadxml->status as $userstatus){
        
$text $userstatus->text;
    }
    echo 
$text;
 }
?>


Usage:
Code: [Select]
<?php Twitter("Djkanna"); // Obviously change that for example $r['twitter_account'] ?>
Just another way you could do it..

And for example you could use Twitter($r['twitter_account']); and have like a preferences part where a user can change it just a thought ;)

EDIT: Will only work if your server allows Simple Xml :)
« Last Edit: December 19, 2009, 12:22:37 PM by djkanna »
Logged