Php
如何將 Question2Answer 集成到 Typo3 中?
Question2Answer提供了實現Single Sign On的選項。我想將它集成到 Typo3 的現有安裝中(對於 Typo3 前端使用者)。我的問題:
- SSO 需要特定的 Typo3 外掛嗎?
- 對於 Typo3 ,Q2A 的qa-external-users.php的實現如何?
第一次嘗試:qa-external-users.php
qa_*
的函式現在只需呼叫以下腳本中的相應函式。t3_*
錯字3.php:
<?php function connect() { static $t3_db_connection = null; if (!$t3_db_connection) { $conf = include '/YOUR/PATH/TO/TYPO3/typo3conf/LocalConfiguration.php'; $t3_db_connection = mysql_connect( $conf['DB']['host'], $conf['DB']['username'], $conf['DB']['password'] ); if(!$t3_db_connection) { die('Could not connect: ' . mysql_error()); } mysql_select_db($conf['DB']['database']); } return $t3_db_connection; } function logged_in_userid() { $con = connect(); $cookie = $_COOKIE["fe_typo_user"]; $result = mysql_fetch_assoc(mysql_query("SELECT ses_userid FROM fe_sessions WHERE ses_id = '$cookie'", $con)); return $result['ses_userid']; } function t3_get_logged_in_user() { $con = connect(); $userid = logged_in_userid(); $result = mysql_fetch_assoc(mysql_query("SELECT * FROM fe_users WHERE uid = '$userid' AND deleted = 0", $con)); $username = $result['username']; $usergroup = $result['usergroup']; $blocked = $result['disable']; $publicusername = $result['name']; $email = $result['email']; $groups = explode(',', $usergroup); return !$userid ? null : array( 'userid' => $userid, 'publicusername' => $publicusername, 'email' => $email, //'passsalt' => ?????, 'level' => in_array(6, $groups) ? QA_USER_LEVEL_SUPER : QA_USER_LEVEL_BASIC, // TODO add other group ids 'blocked' => $blocked ); } function t3_get_user_email($userid) { $con = connect(); $result = mysql_fetch_assoc(mysql_query("SELECT email FROM fe_users WHERE uid = '$userid' AND deleted = 0", $con)); $email = $result['email']; return !$email ? null : $email; } function t3_get_userids_from_public($publicusernames) { $publictouserid = array(); if (count($publicusernames)) { $con = connect(); $escapedusernames = array(); foreach ($publicusernames as $publicusername) $escapedusernames[] = "'".mysql_real_escape_string($publicusername, $con)."'"; $results = mysql_query( 'SELECT name, uid FROM fe_users WHERE name IN ('.implode(',', $escapedusernames).')', $con); while ($result = mysql_fetch_assoc($results)) $publictouserid[$result['name']] = $result['uid']; } return $publictouserid; } function t3_get_public_from_userids($userids) { $useridtopublic = array(); if (count($userids)) { $con = connect(); $escapeduserids = array(); foreach ($userids as $userid) $escapeduserids[] = "'".mysql_real_escape_string($userid, $con)."'"; $results = mysql_query( 'SELECT name, uid FROM fe_users WHERE uid IN ('.implode(',', $escapeduserids).')', $con); while ($result = mysql_fetch_assoc($results)) $useridtopublic[$result['uid']] = $result['name']; } return $useridtopublic; } ?>