Jump to content

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.

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:


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!

  • Create New...