Jump to content
Matt
 Share


IP.Board 3.1.3 Developers Update: "Like" System

I blogged in a previous entry about the new "like" system that is coming to IP.Gallery, IP.Downloads and IP.Blog.

This is a brand new feature in the core of IP.Board and even though we plan to make more use of it in the actual forums in 3.2, it is ready to be used by modification authors in 3.1.3.

Before I get into the mechanics of the system, I wanted to give you a brief overview of how it works.


This screen shot shows the "like" bar directly underneath the image. The pop-up overlay shows who has "liked" the image. This is opened when you click on the "1 other" link.


When you like an image, you can elect to receive notification of 'updates'. Updates can be various things, in this example it is when a comment is added. You can also elect to 'like' the item anonymously so you can receive updates without showing on the "liked by" list.


All content you "like" is added to your "like center". From here you can bulk remove or update the type of notification. We do plan to make this "like center" more extensive in 3.2.0 with a tabbed interface and more filters but it is ready to use in 3.1.3.


You can quickly access the "like center" from your username drop down at the top of the page.

Implementation
You can add "like" to almost any object by adding a single PHP class into /extensions/like/. I'll take you through the "like" class for Gallery. This file is situated in /admin/applications_addon/ips/gallery/extensions/like/images.php

The class name is as follows:

class like_{app}_{type}_composite extends classes_like_composite



So, for Gallery, this is:

class like_gallery_images_composite extends classes_like_composite



There are only three methods that need to be defined:

The first two are very straight forward:

* Return an array of acceptable frequencies * Possible: immediate, offline, daily, weekly * * @return array */ public function allowedFrequencies() { return array( 'immediate', 'offline' ); } /** * return type of notification available for this item * * @return array (key, readable name) */ public function getNotifyType() { return array( 'comments', 'comments' ); }

/**




















Note: If this "like" will notify of new comments, then the only allowed frequencies are 'immediate' and 'offline'.

The last is getMeta

* Returns the type of item * * @param mixed Relationship ID or array of * @param array Array of meta to select (title, url, type, parentTitle, parentUrl, parentType) null fetches all * @return array Meta data */ public function getMeta( $relId, $selectType=null ) { $return = array(); $isNumeric = false; if ( is_numeric( $relId ) ) { $relId = array( intval($relId) ); $isNumeric = true; } $this->DB->build( array( 'select' => 'i.*', 'from' => array( 'gallery_images' => 'i' ), 'where' => 'i.id IN (' . implode( ',', $relId ) . ')', 'add_join' => array( array( 'select' => 'a.*', 'from' => array( 'gallery_albums_main' => 'a' ), 'where' => 'i.img_album_id=a.album_id', 'type' => 'left' ) ) ) ); $this->DB->execute(); while( $row = $this->DB->fetch() ) { /* Title */ if ( $selectType === null OR ( is_array( $selectType ) AND in_array( 'title', $selectType ) ) ) { $return[ $row['id'] ]['like.title'] = $row['caption']; } /* URL */ if ( $selectType === null OR ( is_array( $selectType ) AND in_array( 'url', $selectType ) ) ) { $return[ $row['id'] ]['like.url'] = $this->registry->output->buildSEOUrl( "app=gallery&image=" . $row['id'], "public", $row['caption_seo'], "viewimage" ); } /* Type */ if ( $selectType === null OR ( is_array( $selectType ) AND in_array( 'type', $selectType ) ) ) { $return[ $row['id'] ]['like.type'] = 'Image'; } /* Parent title */ if ( $selectType === null OR ( is_array( $selectType ) AND in_array( 'parentTitle', $selectType ) ) ) { $return[ $row['id'] ]['like.parentTitle'] = $row['album_name']; } /* Parent url */ if ( $selectType === null OR ( is_array( $selectType ) AND in_array( 'parentTitle', $selectType ) ) ) { $return[ $row['id'] ]['like.parentUrl'] = $this->registry->output->buildSEOUrl( "app=gallery&album=" . $row['album_id'], "public", $row['album_name_seo'], "viewalbum" ); } /* Parent Type */ if ( $selectType === null OR ( is_array( $selectType ) AND in_array( 'parentType', $selectType ) ) ) { $return[ $row['id'] ]['like.parentType'] = 'Album'; } } return ( $isNumeric === true ) ? array_pop( $return ) : $return; }

	/**





































































This method returns meta data about either a single item or an array of items. This is used to generate the data in the "like center".

To add the like bar in your own applications, all you need to do is add:

require_once( IPS_ROOT_PATH . 'sources/classes/like/composite.php' ); $likeClass = classes_like::bootstrap( '{app}', '{type}' ); $like = $likeClass->render( 'summary', $itemId );








$like now contains the HTML which you can use in your templates like so:

<div>{$like}</div>





I will go into more detail on this in our documentation and please watch out for the "comments" class blog entry as it ties in with this class to auto-send comment notifications without any additional coding!

 Share

Comments

Recommended Comments

Are we going to see this featured integrated into IP.Content as well? Since we can have limitless varieties of databases, it would be awesome to be able to "Like" a particular database submission.

For example, your resources section here is built out of IP.Content I believe.. it would be great to "Like" a particular article.

Link to comment
Share on other sites

Good, but the list under the user name is getting rather long.

Could My Gallery, My Blog etc all be under "My Content" ?

Or at least drop "Manage Ignored users" Do we really need a shortcut to it?

Link to comment
Share on other sites

[quote name='Heyhoe' date='27 October 2010 - 02:41 PM']
Good, but the list under the user name is getting rather long.

Could My Gallery, My Blog etc all be under "My Content" ?

Or at least drop "Manage Ignored users" Do we really need a shortcut to it?


It's all editable in your skin templates. :)

Link to comment
Share on other sites

This would definitely work as a "Favorite Posts" feature. :D Not quite what I had been asking for, but it's definitely close enough for now. Just add in the ability to have comments (private and/or public) for why you 'liked' something and it'll kick ass.

:D :D :D

Link to comment
Share on other sites

Hi there, my site is moving to IPBoard in the next few months, but for the past couple of months, we've been using the "Like" feature from vBSEO for our forum posts. When IPBoard uses a Like system for the forums, any idea if it will be able to import like data from vBSEO's system? If not sure, could this be a request to do so? :-)

Looking forward to moving the site to IPBoard!

Link to comment
Share on other sites



Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...