qa-event-limits.php 2.77 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-event-limits.php
	Description: Event module for updating per-user limits


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

Scott committed
23 24 25 26 27 28 29 30 31 32
class qa_event_limits
{
	public function process_event($event, $userid, $handle, $cookieid, $params)
	{
		// Don't increment limits or report user actions for events that were delayed. For example, a 'q_post'
		// event sent when a post is approved by the admin, for which a 'q_queue' event was already sent.

		if (isset($params['delayed']))
			return;

Scott committed
33
		require_once QA_INCLUDE_DIR . 'app/limits.php';
Scott committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

		switch ($event) {
			case 'q_queue':
			case 'q_post':
			case 'q_claim':
				qa_limits_increment($userid, QA_LIMIT_QUESTIONS);
				break;

			case 'a_queue':
			case 'a_post':
			case 'a_claim':
				qa_limits_increment($userid, QA_LIMIT_ANSWERS);
				break;

			case 'c_queue':
			case 'c_post':
			case 'c_claim':
			case 'a_to_c':
				qa_limits_increment($userid, QA_LIMIT_COMMENTS);
				break;

			case 'q_vote_up':
			case 'q_vote_down':
			case 'q_vote_nil':
			case 'a_vote_up':
			case 'a_vote_down':
			case 'a_vote_nil':
				qa_limits_increment($userid, QA_LIMIT_VOTES);
				break;

			case 'q_flag':
			case 'a_flag':
			case 'c_flag':
				qa_limits_increment($userid, QA_LIMIT_FLAGS);
				break;

			case 'u_message':
				qa_limits_increment($userid, QA_LIMIT_MESSAGES);
				break;

			case 'u_wall_post':
				qa_limits_increment($userid, QA_LIMIT_WALL_POSTS);
				break;
		}
Scott committed
78

Scott committed
79
		$writeactions = array(
Scott committed
80 81 82 83 84 85
			'_approve', '_claim', '_clearflags', '_delete', '_edit', '_favorite', '_flag', '_hide',
			'_post', '_queue', '_reject', '_reshow', '_unfavorite', '_unflag', '_vote_down', '_vote_nil', '_vote_up',
			'a_select', 'a_to_c', 'a_unselect',
			'q_close', 'q_move', 'q_reopen',
			'u_block', 'u_edit', 'u_level', 'u_message', 'u_password', 'u_save', 'u_unblock',
		);
Scott committed
86

87
		if (is_numeric(array_search(strstr($event, '_'), $writeactions)) ||
Scott committed
88 89 90
			is_numeric(array_search($event, $writeactions))
		) {
			if (isset($userid)) {
91
				require_once QA_INCLUDE_DIR . 'app/users.php';
Scott committed
92

Scott committed
93
				qa_user_report_action($userid, $event);
Scott committed
94

Scott committed
95
			} elseif (isset($cookieid)) {
96
				require_once QA_INCLUDE_DIR . 'app/cookies.php';
Scott committed
97

Scott committed
98
				qa_cookie_report_action($cookieid, $event);
Scott committed
99 100 101
			}
		}
	}
Scott committed
102
}