Skip to content

roine/q2a-badges

 
 

Repository files navigation

Question2Answer Badges

Description

This is a plugin for Question2Answer that provides basic badge functionality.

Features

  • currently 57 badges implemented (see Badge List below)
  • badges are categorized into types (e.g. gold, silver, bronze)
  • badge notification system triggers jquery notice when awardee accesses the site
  • option to notify users of badge awarding by email (fully customizable)
  • public badge page displays awardable badges
  • awarded badges may be shown in individual profile pages, with links to source (if available)
  • awarded badge may be shown as medals in individual posts and on global users lists
  • badge names and requirements are modifiable via admin page
  • badge system may be deactivated via admin page
  • badges may be individually deactivated via admin page
  • logs badge awarding if event logging is enabled (integrates with history plugin)
  • recent badges widget (requires event logging to database)
  • full translation table available (see Translation below)
  • all css fully customizable
  • ability to add custom badges via plugin (see Custom Badges below)

Installation

  1. Install Question2Answer
  2. Get the source code for this plugin from github, either using git, or downloading directly:
    • To download using git, install git and then type git clone git://github.com/NoahY/q2a-badges.git badges at the command prompt (on Linux, Windows is a bit different)
    • To download directly, go to the project page and click Download
  3. navigate to your site and check your database to make sure the ^userbadges table was created
  4. Go to Admin -> Plugins on your q2a install and select the 'Activate badges' option, then 'Save Changes'.

Translation

The translation file is qa-lang-badges.php. Copy this file to the qa-lang/<your-language>/ directory. Edit the right-hand side strings in this file with notepad2, notepad++, etc. (don't ever use Window's Notepad. For anything. Ever.), for example, changing:

'good_question'=>'Good Question',

to

'good_question'=>'Swali nzuri',

for Swahili. Don't edit the string on the left-hand side or bad things will happen.

Once you've completed the translation, don't forget to set the site language in the admin control panel... to Swahili.

Custom Badges

Custom badges may be implemented in any plugin module in a similar way as option_default. Steps are as follows:

1. create a function in your module class called custom_badges(). It should return an array of badges with the badge slugs as indexes for nested arrays with var (default requirement) and type (bronze=0,silver=1,gold=2) indexes. Here is an example from the bookmarks plugin: :: function custom_badges() { return array( 'bookmarker' => array('var'=>1, 'type'=>0), 'bookkeeper' => array('var'=>8, 'type'=>1), 'bookworm' => array('var'=>20, 'type'=>2) ); }

2. create a function in your module class called custom_badges_rebuild() that will award badges when rebuilding via admin/plugins and return the number of badges awarded. Here is an example from the bookmarks plugin: :: function custom_badges_rebuild() { $awarded = 0;

$userq = qa_db_query_sub(

'SELECT user_id, meta_value FROM ^usermeta WHERE meta_key=$', 'max_bookmarks'

); while ( ($user=qa_db_read_one_assoc($userq,true)) !== null ) { $badges = array('bookmarker','bookkeeper','bookworm'); $awarded += count(qa_badge_award_check($badges,(int)$user['meta_value'],$user['user_id'],null,2)); } return $awarded;

}

3. in your module class's option_default() function, return two default variables for each badge: badges/<slug> and badges/<slug>_desc. Here is an example from the bookmarks plugin: :: function option_default($option) {

switch($option) {
case 'bookmarks_plugin_title':

return 'Bookmarks';

case 'bookmarks_plugin_bookmark':

return 'Bookmark this question';

case 'bookmarks_plugin_unbookmark':

return 'Unbookmark this question';

case 'ajax_bookmark_popup_notice_text':

return 'Question bookmarked.&nbsp; Visit your profile to see bookmarked questions.';

case 'ajax_bookmark_popup_un_notice_text':

return 'Bookmark removed.';

case 'badges/bookmarker':

return 'Bookmarker';

case 'badges/bookkeeper':

return 'Bookkeeper';

case 'badges/bookworm':

return 'Bookworm';

case 'badges/bookmarker_desc': case 'badges/bookkeeper_desc': case 'badges/bookworm_desc': return 'Bookmarked # ^post^posts'; default: return null;

}

}

4. Create your own mechanism for awarding badges - see some examples in the badges plugin code, or the bookmark plugin. Make sure to test for both qa_opt('badge_active'), which makes sure the badge plugin is active, and qa_opt('badge_custom_badges') to make sure the badge plugin version supports custom badges. Use the function qa_badge_award_check() to check for badges, where $badges is an array of badge slugs, $var is the number to test against the badges, $oid is the postid (if any), $notify = 0 for no notification, 1 for email and popup, 2 for just popup. You should probably check if this function exists as well, in case the badge plugin has been deleted while active. Here is an example from the bookmarks plugin: :: if(function_exists('qa_badge_award_check') && qa_opt('badge_active') && qa_opt('badge_custom_badges')) $awarded = count(qa_badge_award_check(array('bookmarker','bookworm','bookkeeper'), $var, $uid, NULL, 2));

Disclaimer

This is beta code. It is probably okay for production environments, but may not work exactly as expected. Refunds will not be given. If it breaks, you get to keep both parts.

Release

All code herein is Copylefted.

About q2A

Question2Answer is a free and open source platform for Q&A sites. For more information, visit:

http://www.question2answer.org/

Badge List

Level1 Title Description ========== ================= ======================================== 1 Verified Human Successfully verified email address 1 Autobiographer Filled out all profile fields 1 Photogenic Uploaded an avatar image

1 Nice Question Question received +# upvote 2 Good Question Question received +# upvote 3 Great Question Question received +# upvote

1 Notable Question Asked question received # views 2 Popular Question Asked question received # views 3 Famous Question Asked question received # views

1 Nice Answer Answer received +# upvote 2 Good Answer Answer received +# upvote 3 Great Answer Answer received +# upvote

1 Renewal Received "Nice Answer" badge in response to a question more than # days old 2 Revival Received "Good Answer" badge in response to a question more than # days old 3 Ressurection Received "Great Answer" badge in response to a question more than # days old

1 Gifted # answers selected as best answer 2 Wise # answers selected as best answer 3 Enlightened # answers selected as best answer

1 Grateful Selected # answers as best answer 2 Respectful Selected # answers as best answer 3 Reverential Selected # answers as best answer

1 Liked Received # total upvotes 2 Loved Received # total upvotes 3 Revered Received # total upvotes

1 Asker Asked # questions 2 Questioner Asked # questions 3 Inquisitor Asked # questions

1 Answerer Posted # answers 2 Lecturer Posted # answers 3 Preacher Posted # answers

1 Commenter Posted # comments 2 Commentator Posted # comments 3 Annotator Posted # comments

1 Voter Voted # times 2 Avid Voter Voted # times 3 Devoted Voter Voted # times

1 Editor Performed total of # edits 2 Copy Editor Performed total of # edits 3 Senior Editor Performed total of # edits

1 Watchdog Flagged # posts as inappropriate 2 Bloodhound Flagged # posts as inappropriate 3 Pitbull Flagged # posts as inappropriate

1 Reader Read total of # questions 2 Avid Reader Read total of # questions 3 Devoted Reader Read total of # questions

1 Dedicated Visited every day for # consecutive days 2 Devoted Visited every day for # consecutive days 3 Zealous Visited every day for # consecutive days

1 Visitor Visited site on total of # days 2 Trouper Visited site on total of # days 3 Veteran Visited site on total of # days

1 Regular First visited more than # days ago 2 Old Timer First visited more than # days ago 3 ancestor First visited more than # days ago

1 100 Club Received total of # points 2 1,000 Club Received total of # points 3 10,000 Club Received total of # points

1 Medalist Received total of # badges 2 Champion Received total of # badges 3 Olympian Received total of # badges ========== ================= ========================================


  1. Level refers to difficulty level (e.g. gold, silver, bronze).

About

Badges plugin for Question2Answer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published