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

#1 2011-10-23 15:50:50

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Please help test like buttons: 10 seconds needed!

Turns out I wasn't able to modify rookwood101's script to fit my needs, so I had to recreate it. Now I'm just testing my new feature. Please try liking/unliking and give feedback!  smile

http://modshare2.tk/likes/?id=969321&mode=img

For the curious ones, the final aim of this project is an almost automatic adding of the like button to every post. Currently, I just have to click on my Chrome extension after I posted and it gives me the code. This could evolve into a one-click feature!

You may see the source 4 posts down. Happy liking!

Last edited by LS97 (2011-10-23 16:20:57)

Offline

 

#2 2011-10-23 15:56:45

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

It works  smile


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#3 2011-10-23 16:13:39

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

It works well!

Code, pwease?

Offline

 

#4 2011-10-23 16:14:23

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Please help test like buttons: 10 seconds needed!

works like a dream  big_smile


Fork Clamor on GitHub!

Offline

 

#5 2011-10-23 16:18:45

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

Works on Firefox


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2011-10-23 16:20:12

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

Source Code

Setup of folder:
- create a main folder called whatever you want
- create subfolder named 'likes'
- add font.ttf, likeBG.png and unlikeBG.png to the main folder
- add index.php to the main folder!

font.ttf: download
likeBG: download
unlikeBG: download

index.php contents:

Code:

<?
    /* Post-Liker:
    An appliccation which allows you to dynamically like and unlike posts on the Scratch forums!
    */
    
    function printImage($hasAlreadyLiked, $likesCount) {
        // Print small like/unlike image
        if($hasAlreadyLiked === true) {
        $img = imagecreatefrompng('unlikeBG.png');
        } else {
        $img = imagecreatefrompng('likeBG.png');
        }
        $text_colour = imagecolorallocate($img, 1, 1, 180);
        $font = realpath('font.ttf');
        imagettftext($img, 11, 0, 10, imagefontheight(7), $text_colour, $font, $likesCount . " likes");
        $whit = imagecolorallocate($img, 0, 0, 0);
        imagepng($img);
        imagecolortransparent($img, $whit);
        header('Content-type: image/png');
        imagedestroy($img);
    }
    
    $id = $_GET['id'];    
    if(is_numeric($id) === false) {
        // Post ID is not a number
        die;
    }
    
    if($_GET['mode'] == 'img') { // Display image with like count        
        // Find likes count
        if(file_exists('likes/' . $id)) {
            $arr = explode('/', file_get_contents('likes/' . $id));
            if($arr[0] === "") {
                unset($arr[0]);
            }
            $likes = count($arr);
            // Find whether user has liked yet
            if(in_array($_SERVER['REMOTE_ADDR'], $arr)) {
                $hasliked = true;
            } else {
                $hasliked = false;
            }
        } else {
            $likes = 0;
            $hasliked = false;
        }
        printImage($hasliked, $likes);
    }
    
    elseif($_GET['mode'] == 'like') { // Add/remove like from database
        // Check whether like exists
        if(file_exists('likes/' . $id)) {
            // Check whether user has already liked
            $arr = explode('/', file_get_contents('likes/' . $id));
            if(in_array($_SERVER['REMOTE_ADDR'], $arr)) {
                $arr = array_diff($arr, array($_SERVER['REMOTE_ADDR']));
                file_put_contents('likes/' . $id, implode('/', $arr));
                if(count($arr) === 0) {
                    unlink('likes/' . $id);
                }
            } else {
                $arr[] = $_SERVER['REMOTE_ADDR'];
                file_put_contents('likes/' . $id, implode('/', $arr));
            }
        } else {
            file_put_contents('likes/' . $id, $_SERVER['REMOTE_ADDR']);
        }
        // Redirect to post
        header('Location: http://scratch.mit.edu/forums/viewtopic.php?pid=' . $id . '#p' . $id);
    }

Last edited by LS97 (2011-10-23 16:21:26)

Offline

 

#7 2011-10-23 16:25:51

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

LS97 wrote:

Turns out I wasn't able to modify rookwood101's script to fit my needs, so I had to recreate it. Now I'm just testing my new feature. Please try liking/unliking and give feedback!  smile

http://modshare2.tk/likes/?id=969321&mode=img

For the curious ones, the final aim of this project is an almost automatic adding of the like button to every post. Currently, I just have to click on my Chrome extension after I posted and it gives me the code. This could evolve into a one-click feature!

You may see the source 4 posts down. Happy liking!

Your's works!
Unlike rookwood101's, unfortunately.


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#8 2011-10-23 16:30:55

cpumaster930
Scratcher
Registered: 2009-02-23
Posts: 100+

Re: Please help test like buttons: 10 seconds needed!

Yep, it works  big_smile


http://i.imgur.com/Qd0lu.png

Offline

 

#9 2011-10-24 12:38:16

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

make the edges transparent  smile
working

Offline

 

#10 2011-10-24 12:53:46

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

roijac wrote:

make the edges transparent  smile
working

Right, edges. On it.

Offline

 

#11 2011-10-29 12:37:17

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Please help test like buttons: 10 seconds needed!

Cool! Sorry I couldn't help, I was on holiday  smile  yours seems to work just fine, and it does it in a different way, without requiring a mysql database!


http://i.imgur.com/zeIZW.png

Offline

 

#12 2011-10-29 15:41:06

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

Works perfectly, and is quite fast.  smile  (You still don't like databases, do you?  tongue )


/* No comment */

Offline

 

#13 2011-10-29 18:30:26

Laternenpfahl
Scratcher
Registered: 2011-06-24
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

works on chrome os


http://i46.tinypic.com/6yd4c0.png

Offline

 

#14 2011-10-29 18:35:47

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

Works perfectly!   smile

Offline

 

#15 2011-10-29 21:07:04

videogame9_test
Scratcher
Registered: 2011-10-17
Posts: 43

Re: Please help test like buttons: 10 seconds needed!

Nice.

*likes*

Offline

 

#16 2011-10-30 03:29:51

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Please help test like buttons: 10 seconds needed!

One-click bookmarklet:

Code:

javascript:(prompt("Copy this:", "[url=http://modshare2.tk/likes/?id="+(window.location+"").replace("http://scratch.mit.edu/forums/viewtopic.php?id=", "")+"&mode=like][img]http://modshare2.tk/likes/?id="+(window.location+"").replace("http://scratch.mit.edu/forums/viewtopic.php?id=", "")+"&mode=img[/img][/url]"))

Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

Board footer