如何将 Question2Answer 集成到 Typo3 中?

如何将 Question2Answer 集成到 Typo3 中?

问题到答案提供实施选项单点登录。我想将其集成到现有的 Typo3 安装中(针对 Typo3 前端用户)。我的问题有:

  • 我是否需要特定的 Typo3 插件来实现 SSO?
  • 如何实施 Q2Aqa-外部用户.php看起来像 Typo3 吗?

答案1

首次尝试qa_*qa-外部用户.phpt3_*现在只需调用以下脚本中的相应函数。

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;
}

?>

相关内容