コード例 #1
0
ファイル: hawthornlib.php プロジェクト: quen/hawthorn
/**
 * Creates a new Hawthorn object.
 * @param object $course Moodle course object. If not supplied, uses $COURSE.
 *   Only required field is ->id.
 */
function get_hawthorn($course = null)
{
    global $USER, $COURSE, $CFG;
    if ($course == null) {
        $course = $COURSE;
    }
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    // Work out user permissions
    $permissions = '';
    if (has_capability('block/hawthorn:chat', $context)) {
        $permissions .= 'rw';
    }
    if (has_capability('block/hawthorn:moderate', $context)) {
        $permissions .= 'm';
    }
    if (has_capability('block/hawthorn:admin', $context)) {
        $permissions .= 'a';
    }
    // Get user picture URL
    $userpic = print_user_picture($USER, $COURSE->id, NULL, 0, true, false);
    $userpic = preg_replace('~^.*src="([^"]*)".*$~', '$1', $userpic);
    // Decide key expiry (ms). Usually 1 hour, unless session timeout is lower.
    $keyExpiry = 3600000;
    if ($CFG->sessiontimeout * 1000 < $keyExpiry) {
        // Set expiry to session timeout (note that the JS will make a re-acquire
        // request 5 minutes before this)
        $keyExpiry = $CFG->sessiontimeout * 1000;
    }
    // Get server list
    $servers = empty($CFG->block_hawthorn_servers) ? array() : explode(',', $CFG->block_hawthorn_servers);
    $magicnumber = empty($CFG->block_hawthorn_magicnumber) ? 'xxx' : $CFG->block_hawthorn_magicnumber;
    // Construct Hawthorn object
    return new hawthorn($magicnumber, $servers, hawthorn::escapeId($USER->username), fullname($USER), $userpic, $permissions, $CFG->wwwroot . '/blocks/hawthorn/hawthorn.js', $CFG->wwwroot . '/blocks/hawthorn/popup.php', $CFG->wwwroot . '/blocks/hawthorn/reacquire.php', false, $keyExpiry);
}
コード例 #2
0
ファイル: reacquire.php プロジェクト: quen/hawthorn
<?php

/*
Copyright 2009 Samuel Marshall

This file is part of Hawthorn.
http://www.leafdigital.com/software/hawthorn/

Hawthorn 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 3 of the License, or
(at your option) any later version.

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

You should have received a copy of the GNU General Public License
along with Hawthorn.  If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'hawthorn.php';
// This script should now check that the user is authorised to chat and has
// the specified permissions. (Or ignore permissions/user etc in the request
// and generate them afresh.) In this test version, we assume that the user
// is authorised.
$hawthorn = new hawthorn('23d70acbe28943b3548e500e297afb16', array('http://192.168.0.100:13370/'), $_GET['user'], $_GET['displayname'], $_GET['extra'], $_GET['permissions'], 'hawthorn.js', 'popup.html', 'reacquire.php');
// Allow access
$hawthorn->reAcquireAllow($_GET['id'], $_GET['channel']);
コード例 #3
0
ファイル: test.php プロジェクト: quen/hawthorn
<p><strong>This script must not be deployed on a live server.</strong> It
allows anyone to obtain any permissions on the Hawthorn server.</p>

<?php 
require_once 'hawthorn.php';
if (array_key_exists('user', $_GET)) {
    // In a real system you would fill the values in here from:
    // 1) Magic number from your system's configuration, which would be set to
    //    match the Hawthorn server's magic number. (Do not use this example
    //    magic number on any live system!)
    // 2) User and display name from your system's user database, based on
    //    the current authenticated user.
    // 3) Permissions from your system's user database, based on permission
    //    information your system stores ("rw" for normal users).
    // 4) Hawthorn server URL(s) from your system's configuration.
    $hawthorn = new hawthorn('23d70acbe28943b3548e500e297afb16', array('http://192.168.0.100:13370/'), $_GET['user'], $_GET['displayname'], $_GET['extra'], $_GET['permissions'], 'hawthorn.js', 'popup.html', 'reacquire.php');
    // This test uses a load test channel in case you want to watch a load test.
    // To show it working, just get the auth key and display it.
    $hawthorn->getAuthKey('loadtestchan3', $hawthornKey, $hawthornKeyTime);
    ?>
<p>Ok, got past init again. Key is <?php 
    print $hawthornKey;
    ?>
, time
<?php 
    print $hawthornKeyTime;
    ?>
.</p>
<?php 
    // Print JS code that causes recent messages to be displayed.
    print $hawthorn->recent('loadtestchan3');