Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
1.3k views
in Plugins by

I'd like to give users extra points if they include an http link in their comments. (Specifically, a link to the official documentation website in our company.)  How can I make this happen with a plugin? (Or can it be done without a plugin?)

I was able to write an "event" plugin (code below) and have two questions:

  • How do I add the points to the user?
  • How do I add a new type of points (say, called "Doc Link Points") to the Points Administration Page, and retrieve those points in the plugin?

Plugin code is:

class extrapoints {
  function process_event($event, $userid, $handle, $cookieid, $params) {
    if ($event == 'c_post'
        && isset($params)
        && isset($params['text'])
        && $this->is_wiki_link($params['text'])) {
      // Retrieve the right number of "Doc Link" points here!                  
      // Add the points for user $userid here!                                 
    }
  }

  function is_wiki_link($text) {
    return preg_match('@http://docs.example.com/@i',
                      $text) > 0;
  }
}

Q2A version: 1.5.1

1 Answer

+3 votes
by

The easy way is just to use the bonus points field to add/remove points from a user, but this will effectively mean that other bonus points are overridden. See qa_db_points_set_bonus(...) in qa-db-points.php.

The hard way is to add a custom column to qa_userpoints via your module's init_queries(...) function and then override qa_db_points_calculations(...) in qa-db-points.php to add in the extra calculation based on that custom column.

by
Thanks. Is there a simple way to retrieve a user's number of bonus points? I see a complicated method in qa-page-user.php calling qa_db_select_with_pending(...).
by
Just use a simple SELECT query on the userpoints table, via qa_db_query_sub.
by
And it was the hard way :) ... Thanks Gideon for all your work! Hope you are good and healthy. Kai
...