This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-07-26 08:09:57

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Forum topic like Buttons!

Hello everyone, Rum here. I've been developing a way for people to "like" forum topics and I'm looking for some testers, all you need to do is click the button below and 'like' this topic. I will also post the source code and how you can add a like button to your own topic.

Click here for Sparks' self updating images and links in posts!!

NEW TOPIC HERE: http://scratch.mit.edu/forums/viewtopic.php?id=70214 DO NOT POST ON THIS ONE

How the liking system works
The image
This checks a mysql database and shows how many people have clicked the like button
The link
This does something a bit more complicated, first of all it checks to see whether people have liked the topic at all before, if not then it adds a whole new entry into the database this entry has your ip address and the topic id. If people have liked the topic before, it checks whether your ip is on the list of ips for that topic, if not then it adds your ip to the list of ips for that topic. This means that you can only like things once.

Please like this topic to show your support: http://scratchloveit.netne.net/topicrate.php?id=69732&ret=image

and the source code:

Code:

<?php
function writetextimage($string, $substring) {
// Credit to LS97 for parts of this function
if ($_REQUEST['style'] == 1 || isset($_REQUEST['style']) == false || $_REQUEST['style'] != 2) {
    if ($_REQUEST['type'] == 'post') {
        $img = imagecreatefrompng ('bgpost.png');
    }
    else {
        $img = imagecreatefrompng ('bg.png');
    }
    $text_colour = imagecolorallocate($img, 1, 1, 1);
    $font = realpath('font.ttf');
    imagettftext($img, 7, 0, 10, imagefontheight(7), $text_colour, $font, $string);
    imagettftext($img, 7, 0, 10, 28, $text_colour, $font, $substring);
    $whit = imagecolorallocate($img, 0, 0, 0);
    imagecolortransparent($img, $whit);
}
if ($_REQUEST['style'] == 2) {
    $img = imagecreatefrompng ('bg2.png');
    if ($_REQUEST['type'] == 'post') {
        $text_colour = imagecolorallocate($img, 0, 102, 185);
    }
    else {
        $text_colour = imagecolorallocate($img, 255, 0, 0);
    }
    $text_colour2 = imagecolorallocate($img, 1, 1, 1);
    $font = realpath('font2.ttf');
    imagettftext($img, 10, 0, 4, 14, $text_colour, $font, $string);
    imagettftext($img, 8, 0, 15, 28, $text_colour2, $font, $substring);
    $whit = imagecolorallocate($img, 255, 255, 255);
    imagecolortransparent($img, $whit);
}
header('Content-type: image/png');
imagepng($img);
imagecolordeallocate($text_color);
if(isset($text_colour2)) {
    imagecolordeallocate($text_color2);
}
imagedestroy($img);
}

include 'mysql.php';
$topicid = $_REQUEST['id'];
$userip = $_SERVER['REMOTE_ADDR'];
if ($_REQUEST['forum'] == 'tbg') {
    $url = 'http://scratch.mit.edu/tbgforums/viewtopic.php?id=' . $topicid;
    $database = 'tbg_topicrate';
    if ($_REQUEST['type'] == 'post') {
        $url = 'http://scratch.mit.edu/tbgforums/viewtopic.php?pid=' . $topicid . '#p' . $topicid;
        $database = 'tbg_postrate';
    }
}
else {
    $url = 'http://scratch.mit.edu/forums/viewtopic.php?id=' . $topicid;
    $database = 'topicrate';
    if ($_REQUEST['type'] == 'post') {
        $url = 'http://scratch.mit.edu/forums/viewtopic.php?pid=' . $topicid . '#p' . $topicid;
        $database = 'postrate';
    }
}

if ($_REQUEST['ret'] == 'image') {
    if (is_numeric($topicid) === false) {
        writetextimage('Error: id is not valid', '');
        exit();
    }
    $urlcontents = trim(file_get_contents($url));
    if (strpos($urlcontents, $bdrq) != false) {
        writetextimage('Error:', 'id not found');
        exit();
    }
    mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error());
    mysql_select_db($mysql_database) or die(mysql_error());
    $checkquery = mysql_query("SELECT * FROM $database WHERE postid='$topicid'");
    if (mysql_num_rows($checkquery) == 0) {
        $likes = 0;
    }
    else {
        $topicratings = mysql_fetch_row($checkquery) or die(mysql_error());
        $ratedips = explode(',', $topicratings[1]);
        $likes = count($ratedips);
        if ($ratedips[0] == '') {
            $likes = 0;
        }
    }
    if ($likes == 1) {
        $likes = 1 . ' Like';
        if($_REQUEST['verb'] == 'love') {
            $likes = 1 . ' Love-it';
        }
    }
    else {
        if($_REQUEST['verb'] == 'love') {
            $likes = $likes . ' Love-its';
        }
        else {
            $likes = $likes . ' Likes';
        }
    }
    $checkquery = mysql_query("SELECT * FROM $database WHERE postid='$topicid'");
    if (mysql_num_rows($checkquery) == 0) {
        $already_liked = 'Like This';
        if ($_REQUEST['verb'] == 'love') {
            $already_liked = 'Love it?';
        }
    }
    else {
        $topicratings = mysql_fetch_row($checkquery) or die(mysql_error());
        $ratedips = explode(',', $topicratings[1]);
        $count = count($ratedips);
        if ($_REQUEST['verb'] == 'love') {
            $already_liked = 'Love it?';
        }
        else {
            $already_liked = 'Like This';
        }
        for($i=0; $i<$count; $i++) {
            if($ratedips[$i] == $userip) {
                $already_liked = 'Unlike This';
                if ($_REQUEST['verb'] == 'love') {
                    $already_liked = 'I love it!';
                }
            }
        }
    }
    writetextimage($likes, $already_liked);
}
elseif ($_REQUEST['ret'] == 'add') {
    if (is_numeric($topicid) === false) {
        writetextimage('Error: id is not valid', '');
        exit();
    }
    $urlcontents = trim(file_get_contents($url));
    if (strpos($urlcontents, $bdrq) != false) {
        writetextimage('Error: id not found', '');
        exit();
    }
    $headerurl = 'Location:' . $url;
    mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error());
    mysql_select_db($mysql_database) or die(mysql_error());
    $checkquery = mysql_query("SELECT * FROM $database WHERE postid='$topicid'");
    if (mysql_num_rows($checkquery) == 0) {
        $addtopic_query = mysql_query("INSERT INTO $database (postid, ips) VALUES ('$topicid', '$userip')");
        header($headerurl);
        exit();
    }
    else {
        $topicratings = mysql_fetch_row($checkquery) or die(mysql_error());
        $ratedips = explode(',', $topicratings[1]);
        $count = count($ratedips);
        for($i=0; $i<$count; $i++) {
            if($ratedips[$i] == $userip) {
                unset($ratedips[$i]);
                $ratedips = implode(',', $ratedips);
                $updateips_query = mysql_query("UPDATE $database SET ips='$ratedips' WHERE postid='$topicid'") or die(mysql_error());
                header($headerurl);
                exit();
            }
        }
        $ratedips[$count] = $userip;
        $ratedips2 = implode(',', $ratedips);
        if ($ratedips[0] == '') {
            $ratedips2 = $userip;
        }
        $updateips_query = mysql_query("UPDATE $database SET ips='$ratedips2' WHERE postid='$topicid'") or die(mysql_error());
        header($headerurl);
        exit();
    }
}
else {
    writetextimage('Error: incorrect URL vars used', 'Better luck next time!');
}
?>

This took a long time to write so please support me!

I'd like to thank LS97 for the writetextimage() code and Sparks for his inspirational API thread.

Right, now for how you can add it to your posts.

First off you need to make a url tag with the url http://scratchloveit.netne.net/topicrate.php?id=TOPIC ID HERE&ret=add to find the topic id, you must first make the post, go out to the forums section your topic is in, click on your topic and you'll see in the url bar something like scratch.mit.edu/forums/viewtopic.php?id=# where # is a number, you need to copy this number and put it in the TOPIC ID HERE.

So far we have

Code:

[url=http://scratchloveit.netne.net/topicrate.php?id=TOPIC ID HERE&ret=add][/url]

Now for the image part
Basically you use the same id but you use an image tag and the url is slightly different so

Code:

[url=http://scratchloveit.netne.net/topicrate.php?id=TOPIC ID HERE&ret=add][img]http://scratchloveit.netne.net/topicrate.php?id=TOPIC ID HERE&ret=image[/img][/url]

notice ret=image now rather than ret=add.
To have a like button that likes a tbg forum topic, just add &forum=tbg to the url for both image and link. To make it use love-its instead of likes (changes the text) then add &verb=love onto the end of the image url only. this is what it looks like: http://scratchloveit.netne.net/topicrate.php?id=69732&amp;ret=image&amp;verb=love

Make sure to check out Sidharth's Javascript code that automatically generates the code for you based on the url of your post! Here it ishttp://scratchloveit.netne.net/topicrate.php?id=852473&amp;ret=image&amp;type=post and you can like it using the new likeable posts feature (see below on how to implement yourself)!

Which brings us nicely onto the new:
Likeable Posts!
So, you've made a post in a topic that you think everyone will like, and want to show there thanks, but the like button only supports topics. Well not anymore!

You can now have likeable posts, all you have to do is use the same code as topics, except change the id to the id of your post. To find this out, when you make a post, check (once you've posted it) what your url bar says, it will have on the end something like #p123456 you need to copy the number bit of it (in this case 123456) and put that as the id in my code

Code:

[url=http://scratchloveit.netne.net/topicrate.php?id=POST ID HERE&ret=add&type=post][img]http://scratchloveit.netne.net/topicrate.php?id=POST ID HERE&ret=image&type=post[/img][/url]

then, as you can see here you put on the end of each of the urls (image and link) &type=post this is to tell my script that you're talking about a post and not a topic. If you leave this blank then it will think it is a topic, and either it won't work, or you will be liking some random topic.



Well, we're done! I hope you like this new feature!

Custom like button styles
So, you like the idea of 'like buttons' but don't like the style they're in?
Introducing:
Custom made like buttons
Basically, you tell me the style of button you want, font, background shape, colours etc. and I make it for you, adding it as an option in the URL of the image eg. stl=1 meaning style = style no.1. I might add the option to change the font colour & size from the URL, it all depends on how many custom requests I get.

Current Styles:
Style 1 - http://scratchloveit.netne.net/topicrate.php?id=69732&amp;ret=image Style 1 is default, no extra code needed
Style 2 - http://scratchloveit.netne.net/topicrate.php?id=69732&amp;ret=image&amp;style=2 add &style=2 to the end of the image url to enable this style. Requested by IHeartGaming.

Thanks,
Rum

Changelog

Code:

V1.0
First Release, allows you to add like buttons to forum topics and like them.

V1.1
Changed text size & Added redirect to topic
V1.5
Added unlike feature so that if you liked
something in the past you can change
your mind and take away the like also
added small text saying either like or
unlike to show you what would happen if
you clicked the link.
V1.5.1
Bug Fixes, such as now displays image of
Error messages and I had a couple of variables
set the wrong way round.
V1.6
Prettier like button, thanks LS97!
V1.6.1
Fixed a bug where people could like topics
even if they didn't exist also put the mysql
details in a seperate file along with a
variable that holds the string 'Bad request'
something or other.
V1.7
TBG support! add &forum=tbg to url for it
to work.
V1.7.1
Have it use Love-its instead of Likes put
&verb=love on the end of the img url to
make it work.
V1.8
Added first custom style requested by
IHeartGaming.
V2.0
Finally added Likeable posts! as requested
by LS97.
V2.1
Added blue colouring for posts, and white
colouring for topics

Todo list

Code:

 · Top liked list
   (a bit liked the top loved section but
   for forum topics)
 · Star Rating System (Seperate project)
 · Customisable Button-added requested one,
   need to make fully user customisable
 · Add Supporters list support using scratch
   login api.
 · Custom Button text (different to Like and Love)

Last edited by RUMCHEERYPOOPOO (2011-07-30 14:40:28)


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#2 2011-07-26 08:19:28

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Forum topic like Buttons!

I can’t see the picture.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#3 2011-07-26 08:25:28

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

just checking, can anyone else not see this: http://scratchloveit.netne.net/topicrate.php?id=69732&amp;ret=image?


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#4 2011-07-26 08:29:36

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Forum topic like Buttons!

Works  big_smile

Last edited by ssss (2011-07-26 08:29:50)


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#5 2011-07-26 08:31:36

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

Hooray !


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#6 2011-07-26 08:41:56

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Forum topic like Buttons!

Cool!


http://i46.tinypic.com/dw7zft.png

Offline

 

#7 2011-07-26 08:55:31

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

Can a mod please change the title of this post to 'Forum topic like Buttons!'


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#8 2011-07-26 09:24:09

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Forum topic like Buttons!

Congratulations, Rum, it works for me though it does not show my like addition until I refresh the forum page  big_smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#9 2011-07-26 09:38:08

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

I'm working on a redirect to the last visited page  smile

Last edited by RUMCHEERYPOOPOO (2011-07-26 09:38:39)


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#10 2011-07-26 10:05:09

rojasscratches
Scratcher
Registered: 2011-06-01
Posts: 59

Re: Forum topic like Buttons!

the only problem with this is i was the 7th like and when i tried to like it again it took away my like  hmm


smile   neutral   sad   big_smile   yikes   wink   hmm   tongue   lol   mad   roll   cool  cool  Scratch Home Page  cool

Offline

 

#11 2011-07-26 10:06:39

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

rojasscratches wrote:

the only problem with this is i was the 7th like and when i tried to like it again it took away my like  hmm

It doesn't take away your like, you have to reload the page for the change to take effect.

I'm working on this.

Edit: should redirect now

Last edited by RUMCHEERYPOOPOO (2011-07-26 10:26:23)


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#12 2011-07-26 16:15:08

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Forum topic like Buttons!

So you can type in any topic id and it'll work? Good job!

Offline

 

#13 2011-07-26 16:19:04

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

Yep  smile  thx although not tbg forum topics but I might implement


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#14 2011-07-26 17:29:36

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

I'm thinking in the next version a top liked topics list and support for the tbg forums. Any other suggestions people have got?

Edit: also I'll make it so that if you have already liked it, you can unlike it.

Last edited by RUMCHEERYPOOPOO (2011-07-26 18:54:02)


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#15 2011-07-26 18:55:14

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

Right! I have made it so you can unlike it if you've already liked it, but in the process I reset the like counter for this thread  tongue .

Also I made it display some text telling you whether you will like it or unlike it when you click it


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#16 2011-07-26 19:14:01

Mcsugarface
Scratcher
Registered: 2009-11-16
Posts: 100+

Re: Forum topic like Buttons!

Cool!  smile  You should ask the Scratch team to maybe add a place for the most liked or something.


Hi! I'm http://blocks.scratchr.org/API.php?user=USERNAMEHERE&amp;action=onlineStatus&amp;type=text!
http://internetometer.com/imagesmall/11070.png

Offline

 

#17 2011-07-26 19:16:22

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

Mcsugarface wrote:

Cool!  smile  You should ask the Scratch team to maybe add a place for the most liked or something.

Maybe someday the scratch team will take pity on me  smile , I quite like it being unofficial it keeps the pressure off somewhat. But if they're offering, I'd happily let them use it.


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#18 2011-07-26 20:57:29

poemon1
Scratcher
Registered: 2011-01-12
Posts: 500+

Re: Forum topic like Buttons!

Works!


http://i47.tinypic.com/rrqe13.gif

Offline

 

#19 2011-07-26 22:37:19

Mcsugarface
Scratcher
Registered: 2009-11-16
Posts: 100+

Re: Forum topic like Buttons!

RUMCHEERYPOOPOO wrote:

Mcsugarface wrote:

Cool!  smile  You should ask the Scratch team to maybe add a place for the most liked or something.

Maybe someday the scratch team will take pity on me  smile , I quite like it being unofficial it keeps the pressure off somewhat. But if they're offering, I'd happily let them use it.

You should try to make a way to list the most liked posts, and ask the Scratch team if they could put up a page or something for the list. XD


Hi! I'm http://blocks.scratchr.org/API.php?user=USERNAMEHERE&amp;action=onlineStatus&amp;type=text!
http://internetometer.com/imagesmall/11070.png

Offline

 

#20 2011-07-27 04:24:47

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

Yeh I can do that I'm sure


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#21 2011-07-27 04:44:39

whizzer
Scratcher
Registered: 2008-05-27
Posts: 500+

Re: Forum topic like Buttons!

Experiment:

http://scratchloveit.netne.net/topicrate.php?id=848781#p848781&amp;ret=image
EDIT: Ah, didn't work. I was trying to make a like button for the post not the topic.

Mabye you could make it a better image, like a Google +1 or a Facebook Like?

Last edited by whizzer (2011-07-27 04:47:50)


http://i46.tinypic.com/33df6me.png I'm whizzer0 for all things Minecraft.

Offline

 

#22 2011-07-27 04:48:42

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

whizzer wrote:

Experiment:

http://scratchloveit.netne.net/topicrat … ;ret=image

Maybe you could make it a better image, like a Google +1 or a Facebook Like?

I see you have tried doing it for posts, unfortunately that doesn't work :\ but yes I suppose I could do that, but I'd rather not use the same one as google or facebook. I could make it prettier though  smile

also the # kinda breaks it

Edit: I made it a picture error message  smile

Last edited by RUMCHEERYPOOPOO (2011-07-27 04:52:13)


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#23 2011-07-27 04:55:34

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Forum topic like Buttons!

Could you make a star rating system? xD


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#24 2011-07-27 05:00:09

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Forum topic like Buttons!

ssss wrote:

Could you make a star rating system? xD

I think a star rating system would be quite hard to do as you would have to have a seperate page that came up after you clicked on the stars to vote on. I may work on this, but alongside the like system, switching them over if I can perfect it. Thanks for the suggestion!


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#25 2011-07-27 05:08:12

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Forum topic like Buttons!

RUMCHEERYPOOPOO wrote:

ssss wrote:

Could you make a star rating system? xD

I think a star rating system would be quite hard to do as you would have to have a seperate page that came up after you clicked on the stars to vote on. I may work on this, but alongside the like system, switching them over if I can perfect it. Thanks for the suggestion!

Welcome.  smile


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

Board footer