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)
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).
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`)
);
- ./viewtopic.php
Find the following line:Add the following below it: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") : '',
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:Add the following below it: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 -->
Find this code block: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>
Add the following after it: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> • <!-- ENDIF -->{TOTAL_POSTS} <!-- IF PAGE_NUMBER --><!-- IF PAGINATION --> • <a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{PAGE_NUMBER}</a> • <span>{PAGINATION}</span><!-- ELSE --> • {PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF --> </div> <!-- ENDIF --> </div>
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:
Add the following image to the directory ./styles/prosilver/theme/images/thumbs_up2_22x20.jpg:
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; }
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.