Page 1 of 24

[ABD] "Like" Mod

Posted: Sun Dec 12, 2010 3:51 am
by digioz
Modification Name: Like Mod
Author: digioz

Modification Description: "Like" Mod which provides a "Like" system similar to facebook's like system that is completely stand alone (not related to facebook at all).
Modification Version: 0.0.4
Download ModX: like-mod_0.0.4.zip
View ModX Online: Install.xml
Source Code: DigiOz Github phpbb-mods
Demo: HERE (live board, do not post junk)

Image
Image

Requirements: phpBB 3.0.8, 3.0.9, 3.0.10, 3.0.11

Features:
  • Adds LIKE button to thread view page to allow registered users to LIKE the thread with a single click.
  • Lists all existing users who have previously liked the thread in a separate box above the first post.
  • Completely separate from facebook, and uses phpbb username to LIKE threads.
  • Supports both prosilver and subsilver2 themes.
  • Provides a link on index page to a list view containing the most liked threads based on user permissions (under dev).
  • Lists Like # times and Liked # times in posts under user's avatar (under dev).
  • Shows list of users who like the thread in the font color associated with their group.
  • Shows list of topics user has liked on each user's profile page (under dev).
  • Shows "You , user1, user2, user3, user4 and X others like(s) this thread" (under dev).
  • If a user has already LIKED a thread, they will see an UNLIKE button to unlike the thread (under dev).
  • Adds ACP Module to enable/disable mod and change mod settings (under dev).
  • Adds a button to user profile page, allowing users to like other user's profile (under dev).
Screenshots:

Image

Added Table:

Code: Select all

CREATE TABLE `phpbb_likes` (
  `like_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `forum_id` MEDIUMINT UNSIGNED NOT NULL,
  `topic_id` MEDIUMINT UNSIGNED NOT NULL,
  `user_id` MEDIUMINT UNSIGNED NOT NULL,
  `username` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`like_id`)
);
Modified Files:
  • ./viewtopic.php

    Find the following line:

    Code: Select all

    'U_POST_REPLY_TOPIC' 	=> ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=reply&f=$forum_id&t=$topic_id") : '',
    Add the following below it:

    Code: Select all

    'U_LIKE_TOPIC'          => ($phpbb_root_path."posting.".$phpEx."?mode=like&f=".$forum_id."&t=".$topic_id),
    'U_LIKE_USERS_LIST'     => (get_like_list($forum_id, $topic_id)), 
    
  • Open the file ./language/en/viewtopic.php.
  • Find the following line:

    Code: Select all

    ));
    
  • Before it, add the following:

    Code: Select all

    	'LIKE_TEXT'				=> 'like(s) this thread.',
    
  • ./styles/prosilver/template/viewtopic_body.html (make same change for all styles)

    Find the following code block:

    Code: Select all

    <!-- IF S_DISPLAY_SEARCHBOX -->
    		<div class="search-box">
    			<form method="post" id="topic-search" action="{S_SEARCHBOX_ACTION}">
    			<fieldset>
    				<input class="inputbox search tiny"  type="text" name="keywords" id="search_keywords" size="20" value="{L_SEARCH_TOPIC}" onclick="if(this.value=='{LA_SEARCH_TOPIC}')this.value='';" onblur="if(this.value=='')this.value='{LA_SEARCH_TOPIC}';" />
    				<input class="button2" type="submit" value="{L_SEARCH}" />
    				<input type="hidden" value="{TOPIC_ID}" name="t" />
    				<input type="hidden" value="msgonly" name="sf" />
    			</fieldset>
    			</form>
    		</div>
    	<!-- ENDIF -->
    Add the following below it:

    Code: Select all

        <div class="search-box" valign="bottom">
              <form method="post" id="like-button" action="{U_LIKE_TOPIC}">
                    <input class="buttonlike" type="submit" value="" />
              </form>
        </div>
    
    Find this code block:

    Code: Select all

    <!-- IF PAGINATION or TOTAL_POSTS -->
    		<div class="pagination">
    			<!-- IF U_VIEW_UNREAD_POST and not S_IS_BOT --><a href="{U_VIEW_UNREAD_POST}">{L_VIEW_UNREAD_POST}</a> &bull; <!-- ENDIF -->{TOTAL_POSTS}
    			<!-- IF PAGE_NUMBER --><!-- IF PAGINATION --> &bull; <a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{PAGE_NUMBER}</a> &bull; <span>{PAGINATION}</span><!-- ELSE --> &bull; {PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF -->
    		</div>
    	<!-- ENDIF -->
        
    </div>
    
    Add the following after it:

    Code: Select all

    <!-- IF U_LIKE_USERS_LIST --> 
    <div class="panel">
        <div class="inner">
            <span class="corners-top"><span></span></span>    
            <div style="width:100%">        
                {U_LIKE_USERS_LIST} {L_LIKE_TEXT}
            </div>
            <span class="corners-bottom"><span></span></span>
        </div>
    </div>
    <!-- ENDIF --> 
    
  • Open the following file: ./includes/functions_display.php
  • Right before the "?>" tag, add the following:

    Code: Select all

    function get_like_list($forum_id, $topic_id)
    {
        global $db, $config;
        $like_list = '';
                
        $sql = "SELECT A.user_id, A.username, B.user_colour FROM phpbb_likes AS A, phpbb_users AS B
                WHERE forum_id=$forum_id AND topic_id=$topic_id AND A.user_id = B.user_id
                ORDER BY username ASC;";
    
        $result = $db->sql_query($sql);
        
        $result_set = $db->sql_fetchrowset($result);
        
        for($i = 0; $i < sizeof($result_set); $i++)
        {
            $like_list .= "<a href=\"memberlist.php?mode=viewprofile&u=".$result_set[$i]['user_id']."\">
            <font color=\"".$result_set[$i]['user_colour']."\">".$result_set[$i]['username']."</font></a>";
            
            if ($i < sizeof($result_set) - 1)
            {
                $like_list .= ", ";   
            }
        }
    
        return $like_list;   
    }
    
  • Open the file ./includes/functions_posting.php
  • Add the following code right before "?>" line:

    Code: Select all

    function get_like_exists($forum_id = 0, $topic_id = 0, $username)
    {
        global $db, $config;
        $return_value = false;
                
        $sql = "SELECT COUNT(like_id) AS like_id_count FROM phpbb_likes
                WHERE forum_id=$forum_id AND topic_id=$topic_id
                AND username='$username';";
    
        $result = $db->sql_query($sql);
        $like_count = (int) $db->sql_fetchfield('like_id_count', false, $result);
    
        if ($like_count > 0)
        {
            $return_value = true;
        }
    
        return $return_value;  
    }
    
    function submit_like($forum_id, $topic_id, $user_id, $username)
    {
        if (get_like_exists($forum_id, $topic_id, $username) != true)
        {
            global $db, $config;
            $uid = (int)$user_id;
    
            $data = array(
                'forum_id'  => $forum_id,
                'topic_id'  => $topic_id,
                'user_id'   => $uid,
                'username'  => $username
            );
            
            $sql = "INSERT INTO phpbb_likes ".$db->sql_build_array('INSERT', $data);
            $db->sql_query($sql);
        }
    }
    
  • Open file ./posting.php
  • Find this code block:

    Code: Select all

    	default:
    		$sql = '';
    	break;
    
  • BEFORE it, add this:

    Code: Select all

        case 'like':
              if ($user->data['username'] != "Anonymous")
              {
                submit_like($forum_id, $topic_id, $user->data['user_id'], $user->data['username']);
              }
              
              redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id"));
        break;
    
    
  • Open the file ./styles/prosilver/templates/overall_header.html.
  • Add the following code right before the "</head>" tag:

    Code: Select all

    <link href="{T_THEME_PATH}/mods.css" rel="stylesheet" type="text/css" />
    
  • Create a new file at .styles/prosilver/theme/mods.css and put the following code in it:

    Code: Select all

    /* Like Mod Styles */
    
    .buttonlike {
    	background-image: url('images/thumbs_up2_22x20.jpg'); 
    	background-color:Transparent;
    	width:28px;
    	height:25px;
    	padding:0px 0px 0px 0px;
    	background-repeat:no-repeat;
    }
    
    Add the following image to the directory ./styles/prosilver/theme/images/thumbs_up2_22x20.jpg:
    thumbs_up2_22x20.jpg
Image: Image

Notes:

Hello All,

The purpose of this mod is to provide a phpBB driven "Like" system similar to facebook like, but completely standalone. This is my first larger mod, so please feel free to point out any best practices I may not have followed, or contribute to this mod if you are interested in using it in production in order to speed up the process.

Thanks,
Pete

Update 1/14/11: Updated function get_like_list to shows list of users who like the thread in the font color associated with their group.

Re: [DEV] "Like" Mod

Posted: Sun Dec 12, 2010 7:53 am
by Ather
Hi, this is really an amazing idea! i've made a modx file for ease

http://www.share.cx/files/667233339694/ ... 1.zip.html

Re: [DEV] "Like" Mod

Posted: Sun Dec 12, 2010 11:06 am
by _Al
Good job
has anyone tryed this yet?

can you try to add your like to this comments mod?
http://www.phpbb.com/community/viewtopi ... &t=1477625

Re: [DEV] "Like" Mod

Posted: Sun Dec 12, 2010 12:32 pm
by mr.vixus
i like this idea

Re: [DEV] "Like" Mod

Posted: Sun Dec 12, 2010 12:56 pm
by digioz
Ather wrote:Hi, this is really an amazing idea! i've made a modx file for ease

http://www.share.cx/files/667233339694/ ... 1.zip.html
Thanks Ather! I was in the process of doing that, but you beat me to it.:)

@_Al- I have tested this on my Dev Environment as well as both a Windows IIS and a Redhat Apache Server and it runs fine. As far as adding it to the Comment Mod, not a bad idea, although I wanted to add a section to user profile page to list the threads each user likes. I am still coding that part.

Update 12/15/10: The modx file above is missing two of my functions used for posting, so Automod won't install it correctly. I am working on another modx file will all the updated functions. Obviously if you manually apply the mod it will work just fine.

Re: [DEV] "Like" Mod

Posted: Wed Dec 15, 2010 3:44 am
by digioz
Here are the style mods for subsilver2:
  • Open the file ./styles/subsilver2/templates/overall_header.html.
  • Add the following code right before the "</head>" tag:

    Code: Select all

        <link href="{T_THEME_PATH}/mods.css" rel="stylesheet" type="text/css" />
    
  • Create a new file at .styles/subsilver2/theme/mods.css and put the following code in it:

    Code: Select all

        /* Like Mod Styles */
    
        .buttonlike {
           background-image: url('images/thumbs_up2_22x20.jpg');
           background-color:Transparent;
           width:28px;
           height:25px;
           padding:0px 0px 0px 0px;
           background-repeat:no-repeat;
        }
    
  • Add the thumbs up image to the directory ./styles/prosilver/theme/images/thumbs_up2_22x20.jpg
  • Open the file ./styles/subsilver2/template/viewtopic_body.html and find the following:

    Code: Select all

    <!-- IF TOTAL_POSTS -->
    			<td class="nav" valign="middle" nowrap="nowrap">&nbsp;{PAGE_NUMBER}<br /></td>
    			<td class="gensmall" nowrap="nowrap">&nbsp;[ {TOTAL_POSTS} ]&nbsp;</td>
    
  • Add this below it:

    Code: Select all

    <td>
    			<form method="post" id="like-button" action="{U_LIKE_TOPIC}">
    				<input class="buttonlike" type="submit" value="" />
    			</form>
    			</td>
    
  • Find this code block:

    Code: Select all

    <td class="gensmall" width="100%" align="{S_CONTENT_FLOW_END}" nowrap="nowrap"><!-- INCLUDE pagination.html --></td>
    		<!-- ENDIF -->
    	</tr>
    	</table>
    
  • Add this below it:

    Code: Select all

    <table width="100%" cellspacing="1">
    	<td>
    		<!-- IF U_LIKE_USERS_LIST -->
    		<div class="forumrules">        
    		{U_LIKE_USERS_LIST} like this Topic.
    		</div>
    		<!-- ENDIF --> 
    	</td>
    	</table>
    

Re: [DEV] "Like" Mod

Posted: Wed Dec 15, 2010 5:16 am
by onelazyguy
Requests:
can you full 5 top liked topics onto the index?
*off course with topics based on users permission not displaying all topic.
and add a feature under the user's avatar in viewtopic page something like:
Like: # of times
Liked: # times in # posts
also can u add color to user name based on the usergroup

thank you and I love your mod. Great Job!

Re: [DEV] "Like" Mod

Posted: Thu Dec 16, 2010 1:30 am
by naive
Great.
This is the most wanted mod I am seeking now.

Re: [DEV] "Like" Mod

Posted: Thu Dec 16, 2010 3:28 am
by digioz
@onelazyguy - Instead of putting the topics on the index, wouldn't it make more sense to put them on the individual user profile? That's what I am working on right now. If not where on the index would you want to put it? I don't think it would look nice that way.

As far as # of times liked, sounds like what you are really looking for is the "Thank" mod. This is a feature I have seen for that mod.

@naive - Glad you like the mod. It still needs some work though to finish it. :)

Re: [DEV] "Like" Mod

Posted: Wed Dec 22, 2010 5:15 am
by _Al
Three things i recommand
"Its eazy to keep adding to mods making them bigger, but making them better is the reall goal"

1. Is it possible to show "you and" if you like the post?
2. Only decsplay the frist 5 or so users and hide the rest with a simple Hide/show script
3. Add a un-like, for users who have already clicked on the like button, but have done so unintentionally or no longer like the post

I will be making an ADD-ON for your mod, and post it in this thread :-) However im waiting for your profile, "show users like list" befor i can complete it.

My add-on mod will include "like" for other mods
Arcade: game_id user likes in profile
phpbb3 album: users who like image_id under images
Commments: comments users like
Status: users who like this status
Polls: users who like the poll
ext,
and finally on the index page, a block of <div> row's which show reccent things you like.


The Table may look something like this

Code: Select all

CREATE TABLE `phpbb_likes` (
  `like_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `forum_id` MEDIUMINT UNSIGNED NOT NULL,
  `topic_id` MEDIUMINT UNSIGNED NOT NULL,
  `mod_name` MEDIUMINT UNSIGNED NOT NULL,
  `mod_like_id` MEDIUMINT UNSIGNED NOT NULL,
  `timeline` MEDIUMINT UNSIGNED NOT NULL,
  `user_id` MEDIUMINT UNSIGNED NOT NULL,
  `username` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`like_id`)
);

Re: [DEV] "Like" Mod

Posted: Wed Dec 22, 2010 5:26 am
by digioz
Sounds like a great idea Al. I am working on the profile list right now. Will post it here when I am done.

Pete

Re: [DEV] "Like" Mod

Posted: Wed Dec 22, 2010 3:39 pm
by keith10456
Really, really good mod. One of the mods phpBB needed. Keep up the good work :D

Re: [DEV] "Like" Mod

Posted: Wed Dec 22, 2010 3:43 pm
by digioz
Thanks Keith. Glad others are showing interest towards completing and further expanding this mod. :)

Pete

Re: [DEV] "Like" Mod

Posted: Thu Dec 23, 2010 12:45 am
by theendfear
Great mod,thanks!!! But i will wait the others functions before install it on my live board...
I'm sorry for my bad english... :D :D

Re: [DEV] "Like" Mod

Posted: Thu Dec 23, 2010 3:03 am
by digioz
theendfear wrote:Great mod,thanks!!! But i will wait the others functions before install it on my live board...
I'm sorry for my bad english... :D :D
You are welcome. That is always a good idea when it comes to mods that are still under development. ;)