getUserSession(); if ($phpfoxUID > 0) { $phpfox_user["uid"] = $phpfoxUID; //user_name, might want to use full_name but the obvious $phpfox_user["username"] = $phpfoxUSESS["user_name"]; $phpfox_user["email"] = $phpfoxUSESS["email"]; //user_group_id = 1 (admin) else (not admin) $phpfox_user["level"] = $phpfoxUSESS["user_group_id"]; } else { } function qa_get_mysql_user_column_type() { return 'INT UNSIGNED'; } function qa_get_login_links($relative_url_prefix, $redirect_back_to_url) { return array( 'login' => $relative_url_prefix.'../index.php', 'register' => $relative_url_prefix.'../index.php', 'logout' => $relative_url_prefix.'../index.php?do=/user/logout/' ); } function qa_get_logged_in_user() { global $phpfox_user; if (!empty($phpfox_user)) { return array( 'userid' => $phpfox_user["uid"], 'publicusername' => $phpfox_user["username"], 'email' => $phpfox_user['email'], 'level' => ($phpfox_user["uid"]===1 || $phpfox_user["level"]===1) ? QA_USER_LEVEL_ADMIN : QA_USER_LEVEL_BASIC ); } return null; } function qa_get_user_email($userid) { $userObject = Phpfox::getService('user')->getUser($userid); if (!empty($userObject)) return $userObject["email"]; return null; } function qa_get_userids_from_public($publicusernames) { $publictouserid=array(); if (count($publicusernames)) { $qa_db_connection=qa_db_connection(); $escapedusernames=array(); foreach ($publicusernames as $publicusername) $escapedusernames[]="'".mysql_real_escape_string($publicusername, $qa_db_connection)."'"; $aRows = Phpfox::getLib('database')->select('*') ->from('phpfox_user') ->where('user_name IN ('.implode(',', $escapedusernames).')') ->execute('getRows'); foreach ($aRows as $key=>$value) { $publictouserid[$value['user_name']]=$value['user_id']; } } return $publictouserid; } function qa_get_public_from_userids($userids) { $useridtopublic=array(); if (count($userids)) { $qa_db_connection=qa_db_connection(); $escapeduserids=array(); foreach ($userids as $userid) $escapeduserids[]="'".mysql_real_escape_string($userid, $qa_db_connection)."'"; $aRows = Phpfox::getLib('database')->select('*') ->from('phpfox_user') ->where('user_id IN ('.implode(',', $escapeduserids).')') ->execute('getRows'); foreach ($aRows as $key=>$value) { $useridtopublic[$value['user_id']]=$value['user_name']; } } 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. */ { // By default, show the public username linked to the Q2A profile page for the user $publicusername=$logged_in_user['publicusername']; return ''.htmlspecialchars($publicusername).''; /* Example 1 - suitable if: * Your Q2A site: http://www.mysite.com/qa/ * Your user pages: http://www.mysite.com/user/[username] $publicusername=$logged_in_user['publicusername']; return ''.htmlspecialchars($publicusername).''; */ /* Example 2 - suitable if: * 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 $publicusername=$logged_in_user['publicusername']; return ''. ''.htmlspecialchars($publicusername).''; */ } 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. 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. 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. $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). 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); $usershtml=array(); foreach ($userids as $userid) { $publicusername=$useridtopublic[$userid]; $usershtml[$userid]=htmlspecialchars($publicusername); if ($should_include_link) $usershtml[$userid]=''.$usershtml[$userid].''; } return $usershtml; /* Example 1 - suitable if: * Your Q2A site: http://www.mysite.com/qa/ * Your user pages: http://www.mysite.com/user/[username] $useridtopublic=qa_get_public_from_userids($userids); foreach ($userids as $userid) { $publicusername=$useridtopublic[$userid]; $usershtml[$userid]=htmlspecialchars($publicusername); if ($should_include_link) $usershtml[$userid]=''.$usershtml[$userid].''; } return $usershtml; */ /* Example 2 - suitable if: * 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 $useridtopublic=qa_get_public_from_userids($userids); foreach ($userids as $userid) { $publicusername=$useridtopublic[$userid]; $usershtml[$userid]=''.htmlspecialchars($publicusername); if ($should_include_link) $usershtml[$userid]=''.$usershtml[$userid].''; } return $usershtml; */ } function qa_avatar_html_from_userid($userid, $size, $padding) /* ========================================================================== YOU MAY MODIFY THIS FUNCTION, BUT THE DEFAULT BELOW WILL WORK OK ========================================================================== qa_avatar_html_from_userid($userid, $size, $padding) 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. $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. 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: * 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 $htmlsize=(int)$size; return ''; */ } 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. 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. $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. 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 */