Jump to content

Thinking about a Like/Recommend button module


landitus
 Share

Recommended Posts

Hi! I was looking into learning to code a module for PW. I must admit I'm not very savvy with PHP, but somehow I can get some things done :)

I was thinking about doing something simple, but something I would need for my projects. I came up with the idea of a Like button that would let any registered user to like a page. Maybe the module can have some configuration options, like the user roles allowed and which templates should get this functionality. 

I've made some quick evaluation of how easy/difficult this would be, and maybe it's too big of a task for me right now. Either way I wanted to share it with all of you. 

This is more or less the functionality I've laid out:

  • A Likes.module with the main function "like($page)".
  • A code for the button to place it where ever on the page template to trigger the like.
  • A way to trigger this function via a jQuery call > This I have no idea how to accomplish.
  • A configuration section for the plugin: Templates allowed and user roles allowed (maybe later...)
  • An admin section inside Setup with a table that displays all liked pages.

I've been struggling with how to accomplish this since I want to attach a "like" to a page but I don't want this to be a field displayed in the editor, since this is more like a metadata attached to the page, but not editable by the admin. I guess this is possible, right? 

Maybe someone can send me into the right direction. BTW, isn't this similar to the Recommend button down at the modules section of PW?

Link to comment
Share on other sites

I think this would actually be quite easy to implement, and yes you might well be able to make use of the code that is used for the module recommend button. In fact, here is the javascript that is used for that recommendation button:

http://modules.processwire.com/site/modules/FieldtypeLikes/likes.js

The "number_of_likes" field could have its visibility set to "Hidden, not shown in the editor". I actually think a new option to show field values, but make them read-only would be really nice in the admin (but I digress).

You could make use of diogo's http://modules.processwire.com/modules/process-admin-custom-pages/ module to easily create the table of liked pages.

Before we go reinventing things, let's see what Ryan says about handing over the php code that processes the ajax call from the likes.js file.

  • Like 1
Link to comment
Share on other sites

What you see on modules.processwire.com is part of a new Fieldtype module I've been developing on and off to support "like" buttons or star ratings by users. The implementation you see on the modules site enables anyone to anonymously "recommend" (like) a module, though the module itself does support limiting access to roles. When it comes to anonymous voting, the system prevents duplicates by both cookies and IP addresses, which isn't foolproof, but it's the best you can do short of having an authenticated user. It also requires Javascript and uses some cookie tricks, to keep the crawlers from voting. I put it up there a few days ago without mentioning it, and am surprised already at how much "recommending" has been going on, good to see. I'm also glad to hear there is interest in a module like this. I will keep working on it! It will also come with a Process module (under Setup) that lets you browse the liked pages in your admin 

For the star ratings part, I feel like this really is best kept to authenticated users (since one can also down-vote), so am looking into ways to limiting rating to those with PW user accounts and/or Twitter/Facebook/Linkedin accounts. I might ultimately just make the star ratings one a separate module, but still dwelling on it. 

I actually think a new option to show field values, but make them read-only would be really nice in the admin (but I digress).

Good idea, I will add this to the core. 

  • Like 8
Link to comment
Share on other sites

Ryan, this sounds great!! I'm glad you're working on it! 

BTW, do you think it would be interesting to have a module tutorial/process/dissection of some sort. Like, from the planning stage to the actual coding. Preferably a module that dwells into many aspects like this one (javascript, sessions, an admin process)? I know it would be time consuming but I think I've learned coding by looking at screencasts or reading at step by steps tutorials. That's just me cause I'm come from a design background.

Link to comment
Share on other sites

That may be a good idea, but this module probably isn't the right one for it. I'm using some techniques with it that wouldn't seem to be applicable to situations other than this module. The FieldtypeMapMarker (which also includes its own Inputfield) is one I originally made as a tutorial on how to make your own Fieldtypes/Inputfields. I still think it's one of the best examples, though there may be others that are equally good or better now. But without knowing of one, I'd still suggest the MapMarker Fieldtype as a good example. 

  • Like 1
Link to comment
Share on other sites

  • 11 months later...

@landitus

Ryan's module is not so cheap. Maybe it is not such a bad idea to actually make a module like that (maybe not as complicated as Ryan's). I can see using it in many places but can't see myself paying $50 for that (i guess same numbers look different from different parts of the globe). It is always good to have a free alternative.

I was thinking about a site profile using "liking and starring" functionality. And there is no way to include a paid module in site profile.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...