qa-external-users.php 23.7 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-external-example/qa-external-users.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Example of how to integrate with your own user database


	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.
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26
	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
*/

Gideon Greenspan committed
27

Gideon Greenspan committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/*
	=========================================================================
	THIS FILE ALLOWS YOU TO INTEGRATE WITH AN EXISTING USER MANAGEMENT SYSTEM
	=========================================================================

	It is used if QA_EXTERNAL_USERS is set to true in qa-config.php.
*/

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


	function qa_get_mysql_user_column_type()
	{
/*
	==========================================================================
	     YOU MUST MODIFY THIS FUNCTION *BEFORE* Q2A CREATES ITS DATABASE
	==========================================================================

	You should return the appropriate MySQL column type to use for the userid,
	for smooth integration with your existing users. Allowed options are:
51

Gideon Greenspan committed
52 53 54 55 56 57 58 59 60 61
	SMALLINT, SMALLINT UNSIGNED, MEDIUMINT, MEDIUMINT UNSIGNED, INT, INT UNSIGNED,
	BIGINT, BIGINT UNSIGNED or VARCHAR(x) where x is the maximum length.
*/

	//	Set this before anything else

		return null;

	/*
		Example 1 - suitable if:
62

Gideon Greenspan committed
63 64 65 66
		* You use textual user identifiers with a maximum length of 32

		return 'VARCHAR(32)';
	*/
67

Gideon Greenspan committed
68 69
	/*
		Example 2 - suitable if:
70

Gideon Greenspan committed
71
		* You use unsigned numerical user identifiers in an INT UNSIGNED column
72

Gideon Greenspan committed
73 74 75 76 77 78 79 80 81 82 83 84 85
		return 'INT UNSIGNED';
	*/
	}


	function qa_get_login_links($relative_url_prefix, $redirect_back_to_url)
/*
	===========================================================================
	YOU MUST MODIFY THIS FUNCTION, BUT CAN DO SO AFTER Q2A CREATES ITS DATABASE
	===========================================================================

	You should return an array containing URLs for the login, register and logout pages on
	your site. These URLs will be used as appropriate within the Q2A site.
86

Gideon Greenspan committed
87 88
	You may return absolute or relative URLs for each page. If you do not want one of the links
	to show, omit it from the array, or use null or an empty string.
89

Gideon Greenspan committed
90 91 92 93 94
	If you use absolute URLs, then return an array with the URLs in full (see example 1 below).

	If you use relative URLs, the URLs should start with $relative_url_prefix, followed by the
	relative path from the root of the Q2A site to your login page. Like in example 2 below, if
	the Q2A site is in a subdirectory, $relative_url_prefix.'../' refers to your site root.
95

Gideon Greenspan committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
	Now, about $redirect_back_to_url. Let's say a user is viewing a page on the Q2A site, and
	clicks a link to the login URL that you returned from this function. After they log in using
	the form on your main site, they want to automatically go back to the page on the Q2A site
	where they came from. This can be done with an HTTP redirect, but how does your login page
	know where to redirect the user to? The solution is $redirect_back_to_url, which is the URL
	of the page on the Q2A site where you should send the user once they've successfully logged
	in. To implement this, you can add $redirect_back_to_url as a parameter to the login URL
	that you return from this function. Your login page can then read it in from this parameter,
	and redirect the user back to the page after they've logged in. The same applies for your
	register and logout pages. Note that the URL you are given in $redirect_back_to_url is
	relative to the root of the Q2A site, so you may need to add something.
*/
	{

	//	Until you edit this function, don't show login, register or logout links

		return array(
			'login' => null,
			'register' => null,
			'logout' => null
		);

	/*
		Example 1 - using absolute URLs, suitable if:
120

Gideon Greenspan committed
121 122 123 124
		* Your Q2A site:       http://qa.mysite.com/
		* Your login page:     http://www.mysite.com/login
		* Your register page:  http://www.mysite.com/register
		* Your logout page:    http://www.mysite.com/logout
125

Gideon Greenspan committed
126 127 128 129 130
		return array(
			'login' => 'http://www.mysite.com/login',
			'register' => 'http://www.mysite.com/register',
			'logout' => 'http://www.mysite.com/logout',
		);
131

Gideon Greenspan committed
132
	*/
133

Gideon Greenspan committed
134 135
	/*
		Example 2 - using relative URLs, suitable if:
136

Gideon Greenspan committed
137 138 139 140
		* Your Q2A site:       http://www.mysite.com/qa/
		* Your login page:     http://www.mysite.com/login.php
		* Your register page:  http://www.mysite.com/register.php
		* Your logout page:    http://www.mysite.com/logout.php
141

Gideon Greenspan committed
142 143 144 145 146 147
		return array(
			'login' => $relative_url_prefix.'../login.php',
			'register' => $relative_url_prefix.'../register.php',
			'logout' => $relative_url_prefix.'../logout.php',
		);
	*/
148

Gideon Greenspan committed
149 150
	/*
		Example 3 - using relative URLs, and implementing $redirect_back_to_url
151

Gideon Greenspan committed
152 153 154
		In this example, your pages login.php, register.php and logout.php should read in the
		parameter $_GET['redirect'], and redirect the user to the page specified by that
		parameter once they have successfully logged in, registered or logged out.
155

Gideon Greenspan committed
156 157 158 159 160 161 162 163
		return array(
			'login' => $relative_url_prefix.'../login.php?redirect='.urlencode('qa/'.$redirect_back_to_url),
			'register' => $relative_url_prefix.'../register.php?redirect='.urlencode('qa/'.$redirect_back_to_url),
			'logout' => $relative_url_prefix.'../logout.php?redirect='.urlencode('qa/'.$redirect_back_to_url),
		);
	*/

	}
164

Gideon Greenspan committed
165 166 167 168 169 170 171 172

	function qa_get_logged_in_user()
/*
	===========================================================================
	YOU MUST MODIFY THIS FUNCTION, BUT CAN DO SO AFTER Q2A CREATES ITS DATABASE
	===========================================================================

	qa_get_logged_in_user()
173

Gideon Greenspan committed
174 175 176 177 178 179
	You should check (using $_COOKIE, $_SESSION or whatever is appropriate) whether a user is
	currently logged in. If not, return null. If so, return an array with the following elements:

	* userid: a user id appropriate for your response to qa_get_mysql_user_column_type()
	* publicusername: a user description you are willing to show publicly, e.g. the username
	* email: the logged in user's email address
Gideon Greenspan committed
180
	* passsalt: (optional) password salt specific to this user, used for form security codes
Gideon Greenspan committed
181
	* level: one of the QA_USER_LEVEL_* values below to denote the user's privileges:
182

Gideon Greenspan committed
183
	QA_USER_LEVEL_BASIC, QA_USER_LEVEL_EDITOR, QA_USER_LEVEL_ADMIN, QA_USER_LEVEL_SUPER
184

Gideon Greenspan committed
185 186
	To indicate that the user is blocked you can also add an element 'blocked' with the value true.
	Blocked users are not allowed to perform any write actions such as voting or posting.
187

Gideon Greenspan committed
188 189 190 191 192
	The result of this function will be passed to your other function qa_get_logged_in_user_html()
	so you may add any other elements to the returned array if they will be useful to you.

	Call qa_db_connection() to get the connection to the Q2A database. If your database is shared with
	Q2A, you can use this with PHP's MySQL functions such as mysql_query() to run queries.
193

Gideon Greenspan committed
194 195 196 197
	In order to access the admin interface of your Q2A site, ensure that the array element 'level'
	contains QA_USER_LEVEL_ADMIN or QA_USER_LEVEL_SUPER when you are logged in.
*/
	{
198

Gideon Greenspan committed
199
	//	Until you edit this function, nobody is ever logged in
200

Gideon Greenspan committed
201
		return null;
202

Gideon Greenspan committed
203 204
	/*
		Example 1 - suitable if:
205

Gideon Greenspan committed
206 207 208 209 210
		* You store the login state and user in a PHP session
		* You use textual user identifiers that also serve as public usernames
		* Your database is shared with the Q2A site
		* Your database has a users table that contains emails
		* The administrator has the user identifier 'admin'
211

Gideon Greenspan committed
212 213 214 215 216 217
		session_start();

		if ($_SESSION['is_logged_in']) {
			$userid=$_SESSION['logged_in_userid'];

			$qa_db_connection=qa_db_connection();
218

Gideon Greenspan committed
219 220 221 222 223 224
			$result=mysql_fetch_assoc(
				mysql_query(
					"SELECT email FROM users WHERE userid='".mysql_real_escape_string($userid, $qa_db_connection)."'",
					$qa_db_connection
				)
			);
225

Gideon Greenspan committed
226 227 228 229 230 231 232 233
			if (is_array($result))
				return array(
					'userid' => $userid,
					'publicusername' => $userid,
					'email' => $result['email'],
					'level' => ($userid=='admin') ? QA_USER_LEVEL_ADMIN : QA_USER_LEVEL_BASIC
				);
		}
234

Gideon Greenspan committed
235 236
		return null;
	*/
237

Gideon Greenspan committed
238 239
	/*
		Example 2 - suitable if:
240

Gideon Greenspan committed
241 242 243 244 245
		* You store a session ID inside a cookie
		* You use numerical user identifiers
		* Your database is shared with the Q2A site
		* Your database has a sessions table that maps session IDs to users
		* Your database has a users table that contains usernames, emails and a flag for admin privileges
246

Gideon Greenspan committed
247 248
		if ($_COOKIE['sessionid']) {
			$qa_db_connection=qa_db_connection();
249

Gideon Greenspan committed
250 251 252 253 254 255 256
			$result=mysql_fetch_assoc(
				mysql_query(
					"SELECT userid, username, email, admin_flag FROM users WHERE userid=".
					"(SELECT userid FROM sessions WHERE sessionid='".mysql_real_escape_string($_COOKIE['session_id'], $qa_db_connection)."')",
					$qa_db_connection
				)
			);
257

Gideon Greenspan committed
258 259 260 261 262 263 264 265
			if (is_array($result))
				return array(
					'userid' => $result['userid'],
					'publicusername' => $result['username'],
					'email' => $result['email'],
					'level' => $result['admin_flag'] ? QA_USER_LEVEL_ADMIN : QA_USER_LEVEL_BASIC
				);
		}
266

Gideon Greenspan committed
267 268
		return null;
	*/
269

Gideon Greenspan committed
270 271
	}

272

Gideon Greenspan committed
273 274 275 276 277 278 279
	function qa_get_user_email($userid)
/*
	===========================================================================
	YOU MUST MODIFY THIS FUNCTION, BUT CAN DO SO AFTER Q2A CREATES ITS DATABASE
	===========================================================================

	qa_get_user_email($userid)
280

Gideon Greenspan committed
281
	Return the email address for user $userid, or null if you don't know it.
282

Gideon Greenspan committed
283 284 285 286 287 288 289 290 291 292 293
	Call qa_db_connection() to get the connection to the Q2A database. If your database is shared with
	Q2A, you can use this with PHP's MySQL functions such as mysql_query() to run queries.
*/
	{

	//	Until you edit this function, always return null

		return null;

	/*
		Example 1 - suitable if:
294

Gideon Greenspan committed
295 296
		* Your database is shared with the Q2A site
		* Your database has a users table that contains emails
297

Gideon Greenspan committed
298
		$qa_db_connection=qa_db_connection();
299

Gideon Greenspan committed
300 301 302 303 304 305
		$result=mysql_fetch_assoc(
			mysql_query(
				"SELECT email FROM users WHERE userid='".mysql_real_escape_string($userid, $qa_db_connection)."'",
				$qa_db_connection
			)
		);
306

Gideon Greenspan committed
307 308
		if (is_array($result))
			return $result['email'];
309

Gideon Greenspan committed
310 311 312 313
		return null;
	*/

	}
314

Gideon Greenspan committed
315 316 317 318 319 320 321 322

	function qa_get_userids_from_public($publicusernames)
/*
	===========================================================================
	YOU MUST MODIFY THIS FUNCTION, BUT CAN DO SO AFTER Q2A CREATES ITS DATABASE
	===========================================================================

	qa_get_userids_from_public($publicusernames)
323

Gideon Greenspan committed
324
	You should take the array of public usernames in $publicusernames, and return an array which
Gideon Greenspan committed
325 326 327
	maps valid usernames to internal user ids. For each element of this array, the username should be
	in the key, with the corresponding user id in the value. If your usernames are case- or accent-
	insensitive, keys should contain the usernames as stored, not necessarily as in $publicusernames.
328

Gideon Greenspan committed
329 330 331 332 333 334 335 336 337 338 339 340
	Call qa_db_connection() to get the connection to the Q2A database. If your database is shared with
	Q2A, you can use this with PHP's MySQL functions such as mysql_query() to run queries. If you
	access this database or any other, try to use a single query instead of one per user.
*/
	{

	//	Until you edit this function, always return null

		return null;

	/*
		Example 1 - suitable if:
341

Gideon Greenspan committed
342 343 344
		* You use textual user identifiers that are also shown publicly

		$publictouserid=array();
345

Gideon Greenspan committed
346 347
		foreach ($publicusernames as $publicusername)
			$publictouserid[$publicusername]=$publicusername;
348

Gideon Greenspan committed
349 350 351 352 353
		return $publictouserid;
	*/

	/*
		Example 2 - suitable if:
354

Gideon Greenspan committed
355 356 357
		* You use numerical user identifiers
		* Your database is shared with the Q2A site
		* Your database has a users table that contains usernames
358

Gideon Greenspan committed
359
		$publictouserid=array();
360

Gideon Greenspan committed
361 362
		if (count($publicusernames)) {
			$qa_db_connection=qa_db_connection();
363

Gideon Greenspan committed
364 365 366
			$escapedusernames=array();
			foreach ($publicusernames as $publicusername)
				$escapedusernames[]="'".mysql_real_escape_string($publicusername, $qa_db_connection)."'";
367

Gideon Greenspan committed
368 369 370 371
			$results=mysql_query(
				'SELECT username, userid FROM users WHERE username IN ('.implode(',', $escapedusernames).')',
				$qa_db_connection
			);
372

Gideon Greenspan committed
373 374 375
			while ($result=mysql_fetch_assoc($results))
				$publictouserid[$result['username']]=$result['userid'];
		}
376

Gideon Greenspan committed
377 378 379 380 381 382 383 384 385 386 387 388 389
		return $publictouserid;
	*/

	}


	function qa_get_public_from_userids($userids)
/*
	===========================================================================
	YOU MUST MODIFY THIS FUNCTION, BUT CAN DO SO AFTER Q2A CREATES ITS DATABASE
	===========================================================================

	qa_get_public_from_userids($userids)
390

Gideon Greenspan committed
391
	This is exactly like qa_get_userids_from_public(), but works in the other direction.
392

Gideon Greenspan committed
393 394
	You should take the array of user identifiers in $userids, and return an array which maps valid
	userids to public usernames. For each element of this array, the userid you were given should
Gideon Greenspan committed
395
	be in the key, with the corresponding username in the value.
396

Gideon Greenspan committed
397 398 399 400 401 402 403 404 405 406 407 408
	Call qa_db_connection() to get the connection to the Q2A database. If your database is shared with
	Q2A, you can use this with PHP's MySQL functions such as mysql_query() to run queries. If you
	access this database or any other, try to use a single query instead of one per user.
*/
	{

	//	Until you edit this function, always return null

		return null;

	/*
		Example 1 - suitable if:
409

Gideon Greenspan committed
410 411 412
		* You use textual user identifiers that are also shown publicly

		$useridtopublic=array();
413

Gideon Greenspan committed
414 415
		foreach ($userids as $userid)
			$useridtopublic[$userid]=$userid;
416

Gideon Greenspan committed
417 418 419 420 421
		return $useridtopublic;
	*/

	/*
		Example 2 - suitable if:
422

Gideon Greenspan committed
423 424 425
		* You use numerical user identifiers
		* Your database is shared with the Q2A site
		* Your database has a users table that contains usernames
426

Gideon Greenspan committed
427
		$useridtopublic=array();
428

Gideon Greenspan committed
429 430
		if (count($userids)) {
			$qa_db_connection=qa_db_connection();
431

Gideon Greenspan committed
432 433 434
			$escapeduserids=array();
			foreach ($userids as $userid)
				$escapeduserids[]="'".mysql_real_escape_string($userid, $qa_db_connection)."'";
435

Gideon Greenspan committed
436 437 438 439
			$results=mysql_query(
				'SELECT username, userid FROM users WHERE userid IN ('.implode(',', $escapeduserids).')',
				$qa_db_connection
			);
440

Gideon Greenspan committed
441 442 443
			while ($result=mysql_fetch_assoc($results))
				$useridtopublic[$result['userid']]=$result['username'];
		}
444

Gideon Greenspan committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
		return $useridtopublic;
	*/

	}


	function qa_get_logged_in_user_html($logged_in_user, $relative_url_prefix)
/*
	==========================================================================
	     YOU MAY MODIFY THIS FUNCTION, BUT THE DEFAULT BELOW WILL WORK OK
	==========================================================================

	qa_get_logged_in_user_html($logged_in_user, $relative_url_prefix)

	You should return HTML code which identifies the logged in user, to be displayed next to the
	logout link on the Q2A pages. This HTML will only be shown to the logged in user themselves.

	$logged_in_user is the array that you returned from qa_get_logged_in_user(). Hopefully this
	contains enough information to generate the HTML without another database query, but if not,
	call qa_db_connection() to get the connection to the Q2A database.

	$relative_url_prefix is a relative URL to the root of the Q2A site, which may be useful if
	you want to include a link that uses relative URLs. If the Q2A site is in a subdirectory of
	your site, $relative_url_prefix.'../' refers to your site root (see example 1).

	If you don't know what to display for a user, you can leave the default below. This will
	show the public username, linked to the Q2A profile page for the user.
*/
	{
474

Gideon Greenspan committed
475 476 477
	//	By default, show the public username linked to the Q2A profile page for the user

		$publicusername=$logged_in_user['publicusername'];
478

Gideon Greenspan committed
479
		return '<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.htmlspecialchars($publicusername).'</a>';
Gideon Greenspan committed
480 481 482

	/*
		Example 1 - suitable if:
483

Gideon Greenspan committed
484 485
		* Your Q2A site:       http://www.mysite.com/qa/
		* Your user pages:     http://www.mysite.com/user/[username]
486

Gideon Greenspan committed
487
		$publicusername=$logged_in_user['publicusername'];
488

Gideon Greenspan committed
489 490
		return '<a href="'.htmlspecialchars($relative_url_prefix.'../user/'.urlencode($publicusername)).
			'" class="qa-user-link">'.htmlspecialchars($publicusername).'</a>';
Gideon Greenspan committed
491 492 493 494
	*/

	/*
		Example 2 - suitable if:
495

Gideon Greenspan committed
496 497 498
		* Your Q2A site:       http://qa.mysite.com/
		* Your user pages:     http://www.mysite.com/[username]/
		* 16x16 user photos:   http://www.mysite.com/[username]/photo-small.jpeg
499

Gideon Greenspan committed
500
		$publicusername=$logged_in_user['publicusername'];
501

Gideon Greenspan committed
502 503 504
		return '<a href="http://www.mysite.com/'.htmlspecialchars(urlencode($publicusername)).'/" class="qa-user-link">'.
			'<img src="http://www.mysite.com/'.htmlspecialchars(urlencode($publicusername)).'/photo-small.jpeg" '.
			'style="width:16px; height:16px; border:none; margin-right:4px;">'.htmlspecialchars($publicusername).'</a>';
Gideon Greenspan committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
	*/

	}


	function qa_get_users_html($userids, $should_include_link, $relative_url_prefix)
/*
	==========================================================================
	     YOU MAY MODIFY THIS FUNCTION, BUT THE DEFAULT BELOW WILL WORK OK
	==========================================================================

	qa_get_users_html($userids, $should_include_link, $relative_url_prefix)

	You should return an array of HTML to display for each user in $userids. For each element of
	this array, the userid should be in the key, with the corresponding HTML in the value.
520

Gideon Greenspan committed
521 522 523
	Call qa_db_connection() to get the connection to the Q2A database. If your database is shared with
	Q2A, you can use this with PHP's MySQL functions such as mysql_query() to run queries. If you
	access this database or any other, try to use a single query instead of one per user.
524

Gideon Greenspan committed
525 526
	If $should_include_link is true, the HTML may include links to user profile pages.
	If $should_include_link is false, links should not be included in the HTML.
527

Gideon Greenspan committed
528 529 530
	$relative_url_prefix is a relative URL to the root of the Q2A site, which may be useful if
	you want to include links that uses relative URLs. If the Q2A site is in a subdirectory of
	your site, $relative_url_prefix.'../' refers to your site root (see example 1).
531

Gideon Greenspan committed
532 533 534 535 536 537 538 539
	If you don't know what to display for a user, you can leave the default below. This will
	show the public username, linked to the Q2A profile page for each user.
*/
	{

	//	By default, show the public username linked to the Q2A profile page for each user

		$useridtopublic=qa_get_public_from_userids($userids);
540

Gideon Greenspan committed
541 542 543 544
		$usershtml=array();

		foreach ($userids as $userid) {
			$publicusername=$useridtopublic[$userid];
545

Gideon Greenspan committed
546
			$usershtml[$userid]=htmlspecialchars($publicusername);
547

Gideon Greenspan committed
548
			if ($should_include_link)
Gideon Greenspan committed
549
				$usershtml[$userid]='<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.$usershtml[$userid].'</a>';
Gideon Greenspan committed
550
		}
551

Gideon Greenspan committed
552 553 554 555
		return $usershtml;

	/*
		Example 1 - suitable if:
556

Gideon Greenspan committed
557 558
		* Your Q2A site:       http://www.mysite.com/qa/
		* Your user pages:     http://www.mysite.com/user/[username]
559

Gideon Greenspan committed
560
		$useridtopublic=qa_get_public_from_userids($userids);
561

Gideon Greenspan committed
562 563
		foreach ($userids as $userid) {
			$publicusername=$useridtopublic[$userid];
564

Gideon Greenspan committed
565
			$usershtml[$userid]=htmlspecialchars($publicusername);
566

Gideon Greenspan committed
567
			if ($should_include_link)
Gideon Greenspan committed
568 569
				$usershtml[$userid]='<a href="'.htmlspecialchars($relative_url_prefix.'../user/'.urlencode($publicusername)).
					'" class="qa-user-link">'.$usershtml[$userid].'</a>';
Gideon Greenspan committed
570
		}
571

Gideon Greenspan committed
572 573 574 575 576
		return $usershtml;
	*/

	/*
		Example 2 - suitable if:
577

Gideon Greenspan committed
578 579 580
		* Your Q2A site:       http://qa.mysite.com/
		* Your user pages:     http://www.mysite.com/[username]/
		* User photos (16x16): http://www.mysite.com/[username]/photo-small.jpeg
581

Gideon Greenspan committed
582
		$useridtopublic=qa_get_public_from_userids($userids);
583

Gideon Greenspan committed
584 585
		foreach ($userids as $userid) {
			$publicusername=$useridtopublic[$userid];
586

Gideon Greenspan committed
587 588
			$usershtml[$userid]='<img src="http://www.mysite.com/'.htmlspecialchars(urlencode($publicusername)).'/photo-small.jpeg" '.
				'style="width:16px; height:16px; border:0; margin-right:4px;">'.htmlspecialchars($publicusername);
589

Gideon Greenspan committed
590
			if ($should_include_link)
Gideon Greenspan committed
591 592
				$usershtml[$userid]='<a href="http://www.mysite.com/'.htmlspecialchars(urlencode($publicusername)).
					'/" class="qa-user-link">'.$usershtml[$userid].'</a>';
Gideon Greenspan committed
593
		}
594

Gideon Greenspan committed
595 596 597 598 599 600
		return $usershtml;
	*/

	}


Gideon Greenspan committed
601 602 603 604 605
	function qa_avatar_html_from_userid($userid, $size, $padding)
/*
	==========================================================================
	     YOU MAY MODIFY THIS FUNCTION, BUT THE DEFAULT BELOW WILL WORK OK
	==========================================================================
606

Gideon Greenspan committed
607
	qa_avatar_html_from_userid($userid, $size, $padding)
608

Gideon Greenspan committed
609 610
	You should return some HTML for displaying the avatar of $userid on the page.
	If you do not wish to show an avatar for this user, return null.
611

Gideon Greenspan committed
612 613 614 615 616 617
	$size contains the maximum width and height of the avatar to be displayed, in pixels.

	If $padding is true, the HTML you return should render to a square of $size x $size pixels,
	even if the avatar is not square. This can be achieved using CSS padding - see function
	qa_get_avatar_blob_html(...) in qa-app-format.php for an example. If $padding is false,
	the HTML can render to anything which would fit inside a square of $size x $size pixels.
618

Gideon Greenspan committed
619 620 621 622 623 624 625 626 627 628 629
	Note that this function may be called many times to render an individual page, so it is not
	a good idea to perform a database query each time it is called. Instead, you can use the fact
	that before qa_avatar_html_from_userid(...) is called, qa_get_users_html(...) will have been
	called with all the relevant users in the array $userids. So you can pull out the information
	you need in qa_get_users_html(...) and cache it in a global variable, for use in this function.
*/
	{
		return null; // show no avatars by default

	/*
		Example 1 - suitable if:
630

Gideon Greenspan committed
631 632 633
		* All your avatars are square
		* Your Q2A site:       http://www.mysite.com/qa/
		* Your avatar images:  http://www.mysite.com/avatar/[userid]-[size]x[size].jpg
634

Gideon Greenspan committed
635
		$htmlsize=(int)$size;
636

Gideon Greenspan committed
637 638
		return '<img src="http://www.mysite.com/avatar/'.htmlspecialchars($userid).'-'.$htmlsize.'x'.$htmlsize.'.jpg" '.
			'width="'.$htmlsize.'" height="'.$htmlsize.'" class="qa-avatar-image" alt=""/>';
Gideon Greenspan committed
639 640 641
	*/

	}
642 643


Gideon Greenspan committed
644 645 646 647 648 649 650 651 652 653
	function qa_user_report_action($userid, $action)
/*
	==========================================================================
	     YOU MAY MODIFY THIS FUNCTION, BUT THE DEFAULT BELOW WILL WORK OK
	==========================================================================

	qa_user_report_action($userid, $action)

	Informs you about an action by user $userid that modified the database, such as posting,
	voting, etc... If you wish, you may use this to log user activity or monitor for abuse.
654

Gideon Greenspan committed
655 656
	Call qa_db_connection() to get the connection to the Q2A database. If your database is shared with
	Q2A, you can use this with PHP's MySQL functions such as mysql_query() to run queries.
657

Gideon Greenspan committed
658 659 660
	$action will be a string (such as 'q_edit') describing the action. These strings will match the
	first $event parameter passed to the process_event(...) function in event modules. In fact, you might
	be better off just using a plugin with an event module instead, since you'll get more information.
661

Gideon Greenspan committed
662 663 664 665 666 667 668 669 670 671
	FYI, you can get the IP address of the user from qa_remote_ip_address().
*/
	{
		// do nothing by default
	}


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