qa-event-updates.php 6.13 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-event-updates.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Event module for maintaining events tables


	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.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
	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
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}


	class qa_event_updates {

35
		public function process_event($event, $userid, $handle, $cookieid, $params)
Gideon Greenspan committed
36
		{
Gideon Greenspan committed
37 38
			if (@$params['silent']) // don't create updates about silent edits, and possibly other silent events in future
				return;
Scott Vivian committed
39

Gideon Greenspan committed
40 41 42 43 44 45 46
			require_once QA_INCLUDE_DIR.'qa-db-events.php';
			require_once QA_INCLUDE_DIR.'qa-app-events.php';

			switch ($event) {
				case 'q_post':
					if (isset($params['parent'])) // question is following an answer
						qa_create_event_for_q_user($params['parent']['parentid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid, $params['parent']['userid']);
Scott Vivian committed
47

Gideon Greenspan committed
48 49 50 51
					qa_create_event_for_q_user($params['postid'], $params['postid'], null, $userid);
					qa_create_event_for_tags($params['tags'], $params['postid'], null, $userid);
					qa_create_event_for_category($params['categoryid'], $params['postid'], null, $userid);
					break;
Scott Vivian committed
52

Gideon Greenspan committed
53 54 55 56

				case 'a_post':
					qa_create_event_for_q_user($params['parentid'], $params['postid'], null, $userid, $params['parent']['userid']);
					break;
Scott Vivian committed
57

Gideon Greenspan committed
58 59 60

				case 'c_post':
					$keyuserids=array();
Scott Vivian committed
61

Gideon Greenspan committed
62 63 64
					foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again)
						if (isset($comment['userid']))
							$keyuserids[$comment['userid']]=true;
Scott Vivian committed
65

Gideon Greenspan committed
66
					foreach ($keyuserids as $keyuserid => $dummy)
Gideon Greenspan committed
67 68 69 70 71 72 73 74
						if ($keyuserid != $userid)
							qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid);

					switch ($params['parent']['basetype'])
					{
						case 'Q':
							$updatetype=QA_UPDATE_C_FOR_Q;
							break;
Scott Vivian committed
75

Gideon Greenspan committed
76 77 78
						case 'A':
							$updatetype=QA_UPDATE_C_FOR_A;
							break;
Scott Vivian committed
79

Gideon Greenspan committed
80 81 82 83
						default:
							$updatetype=null;
							break;
					}
Scott Vivian committed
84

Gideon Greenspan committed
85 86
					qa_create_event_for_q_user($params['questionid'], $params['postid'], $updatetype, $userid,
						@$keyuserids[$params['parent']['userid']] ? null : $params['parent']['userid']);
Scott Vivian committed
87
							// give precedence to 'your comment followed' rather than 'your Q/A commented' if both are true
Gideon Greenspan committed
88 89
					break;

Scott Vivian committed
90

Gideon Greenspan committed
91 92 93 94 95 96 97
				case 'q_edit':
					if ($params['titlechanged'] || $params['contentchanged'])
						$updatetype=QA_UPDATE_CONTENT;
					elseif ($params['tagschanged'])
						$updatetype=QA_UPDATE_TAGS;
					else
						$updatetype=null;
Scott Vivian committed
98

Gideon Greenspan committed
99 100 101 102 103 104 105 106
					if (isset($updatetype)) {
						qa_create_event_for_q_user($params['postid'], $params['postid'], $updatetype, $userid, $params['oldquestion']['userid']);

						if ($params['tagschanged'])
							qa_create_event_for_tags($params['tags'], $params['postid'], QA_UPDATE_TAGS, $userid);
					}
					break;

Scott Vivian committed
107

Gideon Greenspan committed
108 109 110 111
				case 'a_select':
					qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_SELECTED, $userid, $params['answer']['userid']);
					break;

Scott Vivian committed
112

Gideon Greenspan committed
113 114 115 116
				case 'q_reopen':
				case 'q_close':
					qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CLOSED, $userid, $params['oldquestion']['userid']);
					break;
Scott Vivian committed
117

Gideon Greenspan committed
118

Gideon Greenspan committed
119 120 121 122
				case 'q_hide':
					if (isset($params['oldquestion']['userid']))
						qa_db_event_create_not_entity($params['oldquestion']['userid'], $params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
					break;
Scott Vivian committed
123

Gideon Greenspan committed
124

Gideon Greenspan committed
125 126 127
				case 'q_reshow':
					qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldquestion']['userid']);
					break;
Scott Vivian committed
128 129


Gideon Greenspan committed
130 131 132 133
				case 'q_move':
					qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CATEGORY, $userid, $params['oldquestion']['userid']);
					qa_create_event_for_category($params['categoryid'], $params['postid'], QA_UPDATE_CATEGORY, $userid);
					break;
Scott Vivian committed
134

Gideon Greenspan committed
135 136 137 138 139

				case 'a_edit':
					if ($params['contentchanged'])
						qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
					break;
Scott Vivian committed
140

Gideon Greenspan committed
141

Gideon Greenspan committed
142 143 144 145
				case 'a_hide':
					if (isset($params['oldanswer']['userid']))
						qa_db_event_create_not_entity($params['oldanswer']['userid'], $params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
					break;
Scott Vivian committed
146

Gideon Greenspan committed
147

Gideon Greenspan committed
148 149 150
				case 'a_reshow':
					qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldanswer']['userid']);
					break;
Scott Vivian committed
151

Gideon Greenspan committed
152 153 154 155 156

				case 'c_edit':
					if ($params['contentchanged'])
						qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldcomment']['userid']);
					break;
Scott Vivian committed
157

Gideon Greenspan committed
158 159 160 161 162 163 164

				case 'a_to_c':
					if ($params['contentchanged'])
						qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
					else
						qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_TYPE, $userid, $params['oldanswer']['userid']);
					break;
Scott Vivian committed
165

Gideon Greenspan committed
166

Gideon Greenspan committed
167 168 169 170
				case 'c_hide':
					if (isset($params['oldcomment']['userid']))
						qa_db_event_create_not_entity($params['oldcomment']['userid'], $params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
					break;
Scott Vivian committed
171

Gideon Greenspan committed
172

Gideon Greenspan committed
173 174 175 176 177
				case 'c_reshow':
					qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldcomment']['userid']);
					break;
			}
		}
Scott Vivian committed
178

Gideon Greenspan committed
179
	}
Scott Vivian committed
180

Gideon Greenspan committed
181 182 183 184

/*
	Omit PHP closing tag to help avoid accidental output
*/