HOWTO: Member popularity example


Item has a rating of 5 (Liked by AdamLiked by Chris GrahamLiked by Jason Verhagen)
#772 (In Topic #158)
Site director
Patrick Schmalstig is in the usergroup ‘Administrators’

This how-to will show you how you can make your site gauge your user's popularity via. the action logs, in the form of a multiplier.

In this tutorial, I will show you how you can make a custom profile field, automatically updated via. cron, that will store a number that gauges a user's activity level. This algorithm takes the activity of all users, via. the action log, and compares it. Thus, the popularity number each user gets is a comparison of how active they have been compared to other users on your website. A popularity of 1 means the user was about average in terms of activity. Above 1 represents a multiplier (2 means the user was twice as active as the average user, 3 is 3X, and so on.). Below 1 represents a fraction (0.5 means user was 1/2 as active as the average user, 0.25 means 1/4 as active, and so on.).

NOTE: A couple of simple script overrides are necessary for this to count forum activity; Composr by default does not log adding of topics and posts in the action logs.

Difficulty to implement: Moderate
Difficulty to use: Easy
Requirements: cns_forum (Conversr), custom profile fields, action log

Make/copy a sources_custom override of sources/cns_posts_action.php… and open the override for editing.

FIND cms_profile_end_for('cns_make_post', '#' . strval($post_id));

(within the cns_make_post function)

Step 3:
AFTER, ADD log_it('ADD_POST', $post_id, $topic_id);

(Save and close)

Step 4:
Make/copy a sources_custom override of sources/cns_topics_action.php… and open the override for editing.

Step 5:
FIND return $topic_id;

(It's at the very bottom of cns_make_topic function)

Step 6:
BEFORE, ADD log_it('ADD_TOPIC', $topic_id, $forum_id);

(save and close)

Step 7:
In your administration panel, go to tools -> members -> Custom Profile fields, and add a new field.

Step 8:
Name it as you wish, such as "Popularity". Add a description as you wish too.
Default value: 0
Do not make it settable by owner. It is your preference whether it's viewable to owner and to public, but I'd recommend it.
Type: A float
Field Options: Leave blank
Required: No
Show on join form: No
Order: You choose
Show with content: Your preference, but I'd recommend it.
Show with summaries of content: Your preference, but I'd recommend it.
Usergroup: Leave blank

Add it.

Step 9:
Now you need to determine the ID number of the field you just created. Go to the edit custom profile field screen and find the field you just created. Then, examine the edit link. The edit link will depend on your rewrite rules, but in my case it is Example Domain . The ID of my field is 44 in this case. You can also hover over the edit link and it should say "Edit #(ID)" and the number is the ID of the field.

Store this number in a note somewhere; you will need it later.

Step 10:
Download the attached star.php file and open it up for editing.


Step 11 (optional):
If you wish to specify a date condition in the cron to prevent it from running except at certain times, uncomment the example at the beginning of the run function and edit to your tastes. Make sure there is "return;" in that if statement… for that is what will stop the cron.

HINT: For websites with a lot of activity and a lot of members, setting some sort of condition to make the CRON run only at the :05 minute intervals, for example, will lessen the chance of the cron hook taking up a lot of load. The cron hook should not ever take up a lot of load unless you have tens of thousands of users or more, but better safe than sorry.

Step 12 (optional):
Edit the $lookbackseconds variable. This variable defines how far back in time activity in the action logs will have weight on a user's popularity… in seconds. The default included is 2592000 , or 30 days.

Step 13:
Edit the $cpf variable. Recall the custom profile field ID number you noted from step 9. Then, edit the $cpf field so it is assigned 'field_(ID)' . For example, if your field ID was 44, you'll edit $cpf to 'field_44'.

Step 14 (optional):
Update the $wherestring variable. This determines which action log types will affect the popularity statistic of users. You will want to leave the date_and_time condition alone. A reasonable default has been provided, but you may wish to tweak it depending on your Composr set-up.

HINT: To see a list of all the current types of entries in the action log, execute the SQL query SELECT DISTINCT the_type FROM (table_prefix)actionlogs . Note, this does NOT provide a definitive list of all the possible types of action log entries… it only returns the types that already exist in the database. So if for example you install the galleries addon, but no one added any galleries yet, ADD_GALLERY will not yet show up in that query until someone does.

Step 15 (optional, advanced):
Scroll down to "Edit the below switch to your taste." and edit the switch list to your taste. This list defines what weight action log types have. So, for example, you can have adding images to a gallery count more towards a user's popularity than sending them a private message. Again, a reasonable default has been provided, but you may wish to edit the weight values to your tastes or add/remove action log types (see hint from step 14).

Step 16:
Save the file.

Step 17:
Create a folder if it does not already exist on your web server… sources_custom/hooks/systems/cron . Upload your new star.php file to that directory.

Step 18:
You're done! It should start working and setting popularity stats for everyone on the next CRON execution (unless you made a date/time condition at the beginning to control when the CRON hook runs, in which case it should populate for the first time when the condition passes).
Online now: No Back to the top
1 guest and 0 members have just viewed this.


Users online:

Philip, Salman, MVLipwig, Manu, gabriel58, amit.nigam

Forum statistics:
  • 1,298 topics, 5,830 posts, 7,065 members
  • Our newest member is raguragavan
Back to Top