Как интегрировать Question2Answer в Typo3?
http://question2answer.org/ предоставляет возможность реализовать единый вход. Я хочу интегрировать его в существующую установку Typo3 (для пользователей переднего плана Typo3). У меня есть вопросы:
- Нужен ли мне определенный плагин Typo3 для единого входа?
- Как может выглядеть реализация qa-external-users.php Q2A для Typo3?
1 ответ
Рабочая первая попытка: функции qa_*
qa-external-users.php теперь просто вызовите соответствующий t3_*
функции в следующем сценарии.
typo3.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;
}
?>