• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP guest_user函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中guest_user函数的典型用法代码示例。如果您正苦于以下问题:PHP guest_user函数的具体用法?PHP guest_user怎么用?PHP guest_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了guest_user函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: game_showusers

function game_showusers($game)
{
    global $CFG, $USER, $DB;
    $users = array();
    $context = get_context_instance(CONTEXT_COURSE, $game->course);
    $groupid = optional_param('groupid', 0, PARAM_INT);
    $sql = "SELECT DISTINCT ra.userid,u.lastname,u.firstname FROM {role_assignments} ra, {user} u " . " WHERE ra.contextid={$context->id} AND ra.userid=u.id";
    if ($groupid != 0) {
        $sql .= " AND ra.userid IN (SELECT gm.userid FROM {groups_members} gm WHERE gm.groupid={$groupid})";
    }
    if ($recs = $DB->get_records_sql($sql)) {
        foreach ($recs as $rec) {
            $users[$rec->userid] = $rec->lastname . ' ' . $rec->firstname;
        }
    }
    if ($guest = guest_user()) {
        $users[$guest->id] = fullname($guest);
    }
    ?>
            <script type="text/javascript">
                function onselectuser()
                {
                    window.location.href = "<?php 
    echo $CFG->wwwroot . '/mod/game/showattempts.php?q=' . $game->id . '&userid=';
    ?>
" + document.getElementById('menuuser').value + '&groupid=' + document.getElementById('menugroup').value;
                }
            </script>
        <?php 
    $attributes = 'onchange="javascript:onselectuser();"';
    $name = 'user';
    $id = 'menu' . $name;
    $class = 'menu' . $name;
    $class = 'select ' . $class;
    /// Add 'select' selector always
    $nothing = get_string("allparticipants");
    $nothingvalue = '0';
    $options = $users;
    $selected = optional_param('userid', 0, PARAM_INT);
    $output = '<select id="' . $id . '" class="' . $class . '" name="' . $name . '" ' . $attributes . '>' . "\n";
    $output .= '   <option value="' . s($nothingvalue) . '"' . "\n";
    if ($nothingvalue === $selected) {
        $output .= ' selected="selected"';
    }
    $output .= '>' . $nothing . '</option>' . "\n";
    if (!empty($options)) {
        foreach ($options as $value => $label) {
            $output .= '   <option value="' . s($value) . '"';
            if ((string) $value == (string) $selected || is_array($selected) && in_array($value, $selected)) {
                $output .= ' selected="selected"';
            }
            if ($label === '') {
                $output .= '>' . $value . '</option>' . "\n";
            } else {
                $output .= '>' . $label . '</option>' . "\n";
            }
        }
    }
    echo $output . '</select>' . "\n";
}
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:60,代码来源:showattempts.php


示例2: game_showusers

function game_showusers($game)
{
    global $CFG, $USER;
    $users = array();
    $context = get_context_instance(CONTEXT_COURSE, $game->course);
    if ($courseusers = get_enrolled_users($context)) {
        foreach ($courseusers as $courseuser) {
            $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context));
        }
    }
    if ($guest = guest_user()) {
        $users[$guest->id] = fullname($guest);
    }
    ?>
        <script type="text/javascript">
            function onselectuser()
            {
                window.location.href = "<?php 
    echo $CFG->wwwroot . '/mod/game/showanswers.php?q=' . $game->id . '&userid=';
    ?>
" + document.getElementById('menuuser').value;
            }
        </script>
    <?php 
    //choose_from_menu($users, 'user', $USER->id, get_string("allparticipants"), 'javascript:onselectuser();');
    //function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
    //                           $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
    //                           $id='', $listbox=false, $multiple=false, $class='')
    $attributes = 'onchange="javascript:onselectuser();"';
    $name = 'user';
    $id = 'menu' . $name;
    $class = 'menu' . $name;
    $class = 'select ' . $class;
    /// Add 'select' selector always
    $nothing = get_string("allparticipants");
    $nothingvalue = '0';
    $options = $users;
    $selected = optional_param('userid', $USER->id, PARAM_INT);
    $output = '<select id="' . $id . '" class="' . $class . '" name="' . $name . '" ' . $attributes . '>' . "\n";
    $output .= '   <option value="' . s($nothingvalue) . '"' . "\n";
    if ($nothingvalue === $selected) {
        $output .= ' selected="selected"';
    }
    $output .= '>' . $nothing . '</option>' . "\n";
    if (!empty($options)) {
        foreach ($options as $value => $label) {
            $output .= '   <option value="' . s($value) . '"';
            if ((string) $value == (string) $selected || is_array($selected) && in_array($value, $selected)) {
                $output .= ' selected="selected"';
            }
            if ($label === '') {
                $output .= '>' . $value . '</option>' . "\n";
            } else {
                $output .= '>' . $label . '</option>' . "\n";
            }
        }
    }
    echo $output . '</select>' . "\n";
}
开发者ID:nfreear,项目名称:moodle-mod_game,代码行数:59,代码来源:showanswers.php


示例3: rss_get_url

/**
 * This function returns the URL for the RSS XML file.
 *
 * @param int    $contextid      the course id
 * @param int    $userid         the current user id
 * @param string $componentname  the name of the current component. For example "forum"
 * @param string $additionalargs For modules, module instance id
 * @return string the url of the RSS feed
 */
function rss_get_url($contextid, $userid, $componentname, $additionalargs)
{
    global $CFG;
    if (empty($userid)) {
        $userid = guest_user()->id;
    }
    $usertoken = rss_get_token($userid);
    $url = '/rss/file.php';
    return moodle_url::make_file_url($url, '/' . $contextid . '/' . $usertoken . '/' . $componentname . '/' . $additionalargs . '/rss.xml');
}
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:rsslib.php


示例4: rss_get_url

/**
 * This function returns the URL for the RSS XML file.
 *
 * @param int    $contextid      the course id
 * @param int    $userid         the current user id
 * @param string $componentname  the name of the current component. For example "forum"
 * @param string $additionalargs For modules, module instance id
 * @return string the url of the RSS feed
 */
function rss_get_url($contextid, $userid, $componentname, $additionalargs)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    if (empty($userid)) {
        $userid = guest_user()->id;
    }
    $usertoken = rss_get_token($userid);
    return get_file_url($contextid . '/' . $usertoken . '/' . $componentname . '/' . $additionalargs . '/rss.xml', null, 'rssfile');
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:19,代码来源:rsslib.php


示例5: assignsubmission_comments_comment_display

/**
 * Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking.
 *
 * @param array $comments
 * @param stdClass $options
 * @return array
 * @throws comment_exception
 */
function assignsubmission_comments_comment_display($comments, $options)
{
    global $CFG, $DB, $USER;
    if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') {
        throw new comment_exception('invalidcommentarea');
    }
    if (!($submission = $DB->get_record('assign_submission', array('id' => $options->itemid)))) {
        throw new comment_exception('invalidcommentitemid');
    }
    $context = $options->context;
    $cm = $options->cm;
    $course = $options->courseid;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    $assignment = new assign($context, $cm, $course);
    if ($assignment->get_instance()->id != $submission->assignment) {
        throw new comment_exception('invalidcontext');
    }
    if ($assignment->is_blind_marking() && !empty($comments)) {
        // Blind marking is being used, may need to map unique anonymous ids to the comments.
        $usermappings = array();
        $hiddenuserstr = trim(get_string('hiddenuser', 'assign'));
        $guestuser = guest_user();
        foreach ($comments as $comment) {
            // Anonymize the comments.
            if (empty($usermappings[$comment->userid])) {
                // The blind-marking information for this commenter has not been generated; do so now.
                $anonid = $assignment->get_uniqueid_for_user($comment->userid);
                $commenter = new stdClass();
                $commenter->firstname = $hiddenuserstr;
                $commenter->lastname = $anonid;
                $commenter->picture = 0;
                $commenter->id = $guestuser->id;
                $commenter->email = $guestuser->email;
                $commenter->imagealt = $guestuser->imagealt;
                // Temporarily store blind-marking information for use in later comments if necessary.
                $usermappings[$comment->userid]->fullname = fullname($commenter);
                $usermappings[$comment->userid]->avatar = $assignment->get_renderer()->user_picture($commenter, array('size' => 18, 'link' => false));
            }
            // Set blind-marking information for this comment.
            $comment->fullname = $usermappings[$comment->userid]->fullname;
            $comment->avatar = $usermappings[$comment->userid]->avatar;
            $comment->profileurl = null;
        }
    }
    return $comments;
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:54,代码来源:lib.php


示例6: initialise_user_session


//.........这里部分代码省略.........
         // Verify timeout first.
         $maxlifetime = $CFG->sessiontimeout;
         $timeout = false;
         if (isguestuser($userid) or empty($userid)) {
             // Ignore guest and not-logged in timeouts, there is very little risk here.
             $timeout = false;
         } else {
             if ($record->timemodified < time() - $maxlifetime) {
                 $timeout = true;
                 $authsequence = get_enabled_auth_plugins();
                 // Auths, in sequence.
                 foreach ($authsequence as $authname) {
                     $authplugin = get_auth_plugin($authname);
                     if ($authplugin->ignore_timeout_hook($_SESSION['USER'], $record->sid, $record->timecreated, $record->timemodified)) {
                         $timeout = false;
                         break;
                     }
                 }
             }
         }
         if ($timeout) {
             session_regenerate_id(true);
             $_SESSION = array();
             $DB->delete_records('sessions', array('id' => $record->id));
         } else {
             // Update session tracking record.
             $update = new \stdClass();
             $updated = false;
             if ($record->userid != $userid) {
                 $update->userid = $record->userid = $userid;
                 $updated = true;
             }
             $ip = getremoteaddr();
             if ($record->lastip != $ip) {
                 $update->lastip = $record->lastip = $ip;
                 $updated = true;
             }
             $updatefreq = empty($CFG->session_update_timemodified_frequency) ? 20 : $CFG->session_update_timemodified_frequency;
             if ($record->timemodified == $record->timecreated) {
                 // Always do first update of existing record.
                 $update->timemodified = $record->timemodified = time();
                 $updated = true;
             } else {
                 if ($record->timemodified < time() - $updatefreq) {
                     // Update the session modified flag only once every 20 seconds.
                     $update->timemodified = $record->timemodified = time();
                     $updated = true;
                 }
             }
             if ($updated) {
                 $update->id = $record->id;
                 $DB->update_record('sessions', $update);
             }
             return;
         }
     } else {
         if ($record) {
             // This happens when people switch session handlers...
             session_regenerate_id(true);
             $_SESSION = array();
             $DB->delete_records('sessions', array('id' => $record->id));
         }
     }
     unset($record);
     $timedout = false;
     if (!isset($_SESSION['SESSION'])) {
         $_SESSION['SESSION'] = new \stdClass();
         if (!$newsid) {
             $timedout = true;
         }
     }
     $user = null;
     if (!empty($CFG->opentogoogle)) {
         if (\core_useragent::is_web_crawler()) {
             $user = guest_user();
         }
         $referer = get_local_referer(false);
         if (!empty($CFG->guestloginbutton) and !$user and !empty($referer)) {
             // Automatically log in users coming from search engine results.
             if (strpos($referer, 'google') !== false) {
                 $user = guest_user();
             } else {
                 if (strpos($referer, 'altavista') !== false) {
                     $user = guest_user();
                 }
             }
         }
     }
     // Setup $USER and insert the session tracking record.
     if ($user) {
         self::set_user($user);
         self::add_session_record($user->id);
     } else {
         self::init_empty_session();
         self::add_session_record(0);
     }
     if ($timedout) {
         $_SESSION['SESSION']->has_timed_out = true;
     }
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:manager.php


示例7: forum_subscribed_users

/**
 * Returns list of user objects that are subscribed to this forum
 */
function forum_subscribed_users($course, $forum, $groupid = 0)
{
    global $CFG;
    if ($groupid) {
        $grouptables = ", {$CFG->prefix}groups_members gm ";
        $groupselect = "AND gm.groupid = {$groupid} AND u.id = gm.userid";
    } else {
        $grouptables = '';
        $groupselect = '';
    }
    if (forum_is_forcesubscribed($forum)) {
        $context = get_context_instance(CONTEXT_COURSE, $course->id);
        $sort = "u.email ASC";
        $fields = "u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest, u.emailstop, u.imagealt,\n                  u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.theme, u.lang, u.trackforums, u.mnethostid";
        $results = get_users_by_capability($context, 'mod/forum:initialsubscriptions', $fields, $sort, '', '', '', '', false, true);
    } else {
        $results = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest, u.emailstop, u.imagealt,\n                                   u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.theme, u.lang, u.trackforums, u.mnethostid\n                              FROM {$CFG->prefix}user u,\n                                   {$CFG->prefix}forum_subscriptions s {$grouptables}\n                             WHERE s.forum = '{$forum->id}'\n                               AND s.userid = u.id\n                               AND u.deleted = 0  {$groupselect}\n                          ORDER BY u.email ASC");
    }
    static $guestid = null;
    if (is_null($guestid)) {
        if ($guest = guest_user()) {
            $guestid = $guest->id;
        } else {
            $guestid = 0;
        }
    }
    // Guest user should never be subscribed to a forum.
    unset($results[$guestid]);
    return $results;
}
开发者ID:r007,项目名称:PMoodle,代码行数:33,代码来源:lib.php


示例8: add_message

 /**
  * Adds a new chat message.
  * <b>Note:</b> if the $author parameter is omitted or invalid, then the function will attempt to use the {@link SloodleUser} member
  * of the current {@link SloodleSession} object;
  * If that is unavailable, then it will try to use the user currently 'logged-in' to the VLE (i.e. the $USER variable in Moodle).
  * If all else fails, it will attempt to attribute the message to the guest user.
  * @param string $message The text of the message.
  * @param mixed $user The user who wrote the message -- either a VLE user ID or (preferably) a {@link SloodleUser} object. If null, then the user in the current SloodleSession object will be used. If that fails, then the guest user is used if possible.
  * @param int $timestamp Timestamp of the message. If omitted or <= 0 then the current timestamp is used
  * @return bool True if successful, or false otherwise
  */
 function add_message($message, $user = null, $timestamp = null)
 {
     // Ignore empty messages
     if (empty($message)) {
         return false;
     }
     // Make sure the message is safe
     $message = addslashes(clean_text(stripslashes($message)));
     // We need to get the user ID for the message
     $userid = 0;
     // Has a user object been provided?
     if (is_object($user)) {
         // Yes - grab the user ID
         $userid = $user->get_user_id();
     } else {
         if ($user != null) {
             // May be an ID
             $userid = (int) $user;
         }
     }
     // Did we end up with a valid user ID?
     if ((int) $userid <= 0) {
         // No - do we have a user in the session parameter?
         if (isset($this->_session->user)) {
             // Store the user ID
             $userid = $this->_session->user->get_user_id();
         }
     }
     // Are we still lacking a valid user?
     if ((int) $userid <= 0) {
         // Yes - user the guest user
         $guest = guest_user();
         if ($guest) {
             $userid = $guest->id;
         }
     }
     // Prepare the timestamp variable if necessary
     if (is_null($timestamp)) {
         $timestamp = time();
     }
     // Create a chat message record object
     $rec = new stdClass();
     $rec->chatid = $this->moodle_chat_instance->id;
     $rec->userid = $userid;
     $rec->message = $message;
     $rec->timestamp = $timestamp;
     // Attempt to insert the chat message
     $result = insert_record('chat_messages', $rec);
     if (!$result) {
         // Insertion failed.
         // If possible, add an appropriate side effect code to our response
         if (isset($this->_session->response)) {
             $this->_session->response->add_side_effect(-10101);
         }
     }
     // We successfully added a chat message
     // If possible, add an appropriate side effect code to our response
     if (isset($this->_session->response)) {
         $this->_session->response->add_side_effect(10101);
     }
     return true;
 }
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:73,代码来源:module_chat.php


示例9: Synch_restoreMergedBackupFromRemoteHost

function Synch_restoreMergedBackupFromRemoteHost($id, $hostUrl, $sessionId, $fileName)
{
    global $SynchManager, $USER;
    $USER = guest_user();
    return $SynchManager->restoreMergedBackupFromRemoteHost($id, $hostUrl, $sessionId, $fileName);
}
开发者ID:r007,项目名称:PMoodle,代码行数:6,代码来源:service.php


示例10: forum_extend_settings_navigation


//.........这里部分代码省略.........
                // 0
                $allowchoice->action = null;
                $allowchoice->add_class('activesetting');
                $allowchoice->icon = new pix_icon('t/selected', '', 'mod_forum');
                break;
            case FORUM_FORCESUBSCRIBE:
                // 1
                $forceforever->action = null;
                $forceforever->add_class('activesetting');
                $forceforever->icon = new pix_icon('t/selected', '', 'mod_forum');
                break;
            case FORUM_INITIALSUBSCRIBE:
                // 2
                $forceinitially->action = null;
                $forceinitially->add_class('activesetting');
                $forceinitially->icon = new pix_icon('t/selected', '', 'mod_forum');
                break;
            case FORUM_DISALLOWSUBSCRIBE:
                // 3
                $disallowchoice->action = null;
                $disallowchoice->add_class('activesetting');
                $disallowchoice->icon = new pix_icon('t/selected', '', 'mod_forum');
                break;
        }
    } else {
        if ($activeenrolled) {
            switch ($subscriptionmode) {
                case FORUM_CHOOSESUBSCRIBE:
                    // 0
                    $notenode = $forumnode->add(get_string('subscriptionoptional', 'forum'));
                    break;
                case FORUM_FORCESUBSCRIBE:
                    // 1
                    $notenode = $forumnode->add(get_string('subscriptionforced', 'forum'));
                    break;
                case FORUM_INITIALSUBSCRIBE:
                    // 2
                    $notenode = $forumnode->add(get_string('subscriptionauto', 'forum'));
                    break;
                case FORUM_DISALLOWSUBSCRIBE:
                    // 3
                    $notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum'));
                    break;
            }
        }
    }
    if ($cansubscribe) {
        if (\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject, null, $PAGE->cm)) {
            $linktext = get_string('unsubscribe', 'forum');
        } else {
            $linktext = get_string('subscribe', 'forum');
        }
        $url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'sesskey' => sesskey()));
        $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
        if (isset($discussionid)) {
            if (\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject, $discussionid, $PAGE->cm)) {
                $linktext = get_string('unsubscribediscussion', 'forum');
            } else {
                $linktext = get_string('subscribediscussion', 'forum');
            }
            $url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'sesskey' => sesskey(), 'd' => $discussionid, 'returnurl' => $PAGE->url->out()));
            $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
        }
    }
    if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/forum/subscribers.php', array('id' => $forumobject->id));
        $forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
    }
    if ($enrolled && forum_tp_can_track_forums($forumobject)) {
        // keep tracking info for users with suspended enrolments
        if ($forumobject->trackingtype == FORUM_TRACKING_OPTIONAL || !$CFG->forum_allowforcedreadtracking && $forumobject->trackingtype == FORUM_TRACKING_FORCED) {
            if (forum_tp_is_tracked($forumobject)) {
                $linktext = get_string('notrackforum', 'forum');
            } else {
                $linktext = get_string('trackforum', 'forum');
            }
            $url = new moodle_url('/mod/forum/settracking.php', array('id' => $forumobject->id, 'sesskey' => sesskey()));
            $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
        }
    }
    if (!isloggedin() && $PAGE->course->id == SITEID) {
        $userid = guest_user()->id;
    } else {
        $userid = $USER->id;
    }
    $hascourseaccess = $PAGE->course->id == SITEID || can_access_course($PAGE->course, $userid);
    $enablerssfeeds = !empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds);
    if ($enablerssfeeds && $forumobject->rsstype && $forumobject->rssarticles && $hascourseaccess) {
        if (!function_exists('rss_get_url')) {
            require_once "{$CFG->libdir}/rsslib.php";
        }
        if ($forumobject->rsstype == 1) {
            $string = get_string('rsssubscriberssdiscussions', 'forum');
        } else {
            $string = get_string('rsssubscriberssposts', 'forum');
        }
        $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "mod_forum", $forumobject->id));
        $forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
    }
}
开发者ID:rezaies,项目名称:moodle,代码行数:101,代码来源:lib.php


示例11: check_user_initialised

 /**
  * Initialise $USER object, handles google access
  * and sets up not logged in user properly.
  *
  * @return void
  */
 protected function check_user_initialised()
 {
     global $CFG;
     if (isset($_SESSION['USER']->id)) {
         // already set up $USER
         return;
     }
     $user = null;
     if (!empty($CFG->opentogoogle) and !NO_MOODLE_COOKIES) {
         if (is_web_crawler()) {
             $user = guest_user();
         }
         if (!empty($CFG->guestloginbutton) and !$user and !empty($_SERVER['HTTP_REFERER'])) {
             // automaticaly log in users coming from search engine results
             if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false) {
                 $user = guest_user();
             } else {
                 if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false) {
                     $user = guest_user();
                 }
             }
         }
     }
     if (!$user) {
         $user = new stdClass();
         $user->id = 0;
         // to enable proper function of $CFG->notloggedinroleid hack
         if (isset($CFG->mnet_localhost_id)) {
             $user->mnethostid = $CFG->mnet_localhost_id;
         } else {
             $user->mnethostid = 1;
         }
     }
     session_set_user($user);
 }
开发者ID:neogic,项目名称:moodle,代码行数:41,代码来源:sessionlib.php


示例12: test_apply_concurrent_login_limit

 public function test_apply_concurrent_login_limit()
 {
     global $DB;
     $this->resetAfterTest();
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $guest = guest_user();
     $record = new \stdClass();
     $record->state = 0;
     $record->sessdata = null;
     $record->userid = $user1->id;
     $record->timemodified = time();
     $record->firstip = $record->lastip = '10.0.0.1';
     $record->sid = md5('hokus1');
     $record->timecreated = 20;
     $DB->insert_record('sessions', $record);
     $record->sid = md5('hokus2');
     $record->timecreated = 10;
     $DB->insert_record('sessions', $record);
     $record->sid = md5('hokus3');
     $record->timecreated = 30;
     $DB->insert_record('sessions', $record);
     $record->userid = $user2->id;
     $record->sid = md5('pokus1');
     $record->timecreated = 20;
     $DB->insert_record('sessions', $record);
     $record->sid = md5('pokus2');
     $record->timecreated = 10;
     $DB->insert_record('sessions', $record);
     $record->sid = md5('pokus3');
     $record->timecreated = 30;
     $DB->insert_record('sessions', $record);
     $record->timecreated = 10;
     $record->userid = $guest->id;
     $record->sid = md5('g1');
     $DB->insert_record('sessions', $record);
     $record->sid = md5('g2');
     $DB->insert_record('sessions', $record);
     $record->sid = md5('g3');
     $DB->insert_record('sessions', $record);
     $record->userid = 0;
     $record->sid = md5('nl1');
     $DB->insert_record('sessions', $record);
     $record->sid = md5('nl2');
     $DB->insert_record('sessions', $record);
     $record->sid = md5('nl3');
     $DB->insert_record('sessions', $record);
     set_config('limitconcurrentlogins', 0);
     $this->assertCount(12, $DB->get_records('sessions'));
     \core\session\manager::apply_concurrent_login_limit($user1->id);
     \core\session\manager::apply_concurrent_login_limit($user2->id);
     \core\session\manager::apply_concurrent_login_limit($guest->id);
     \core\session\manager::apply_concurrent_login_limit(0);
     $this->assertCount(12, $DB->get_records('sessions'));
     set_config('limitconcurrentlogins', -1);
     \core\session\manager::apply_concurrent_login_limit($user1->id);
     \core\session\manager::apply_concurrent_login_limit($user2->id);
     \core\session\manager::apply_concurrent_login_limit($guest->id);
     \core\session\manager::apply_concurrent_login_limit(0);
     $this->assertCount(12, $DB->get_records('sessions'));
     set_config('limitconcurrentlogins', 2);
     \core\session\manager::apply_concurrent_login_limit($user1->id);
     $this->assertCount(11, $DB->get_records('sessions'));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 20)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 30)));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 10)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10)));
     set_config('limitconcurrentlogins', 2);
     \core\session\manager::apply_concurrent_login_limit($user2->id, md5('pokus2'));
     $this->assertCount(10, $DB->get_records('sessions'));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10)));
     \core\session\manager::apply_concurrent_login_limit($guest->id);
     \core\session\manager::apply_concurrent_login_limit(0);
     $this->assertCount(10, $DB->get_records('sessions'));
     set_config('limitconcurrentlogins', 1);
     \core\session\manager::apply_concurrent_login_limit($user1->id, md5('grrr'));
     $this->assertCount(9, $DB->get_records('sessions'));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 20)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 30)));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 10)));
     \core\session\manager::apply_concurrent_login_limit($user1->id);
     $this->assertCount(9, $DB->get_records('sessions'));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 20)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 30)));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 10)));
     \core\session\manager::apply_concurrent_login_limit($user2->id, md5('pokus2'));
     $this->assertCount(8, $DB->get_records('sessions'));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20)));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10)));
     \core\session\manager::apply_concurrent_login_limit($user2->id);
     $this->assertCount(8, $DB->get_records('sessions'));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20)));
     $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30)));
     $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10)));
     \core\session\manager::apply_concurrent_login_limit($guest->id);
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:session_manager_test.php


示例13: get_group_taginstance_userid

 /**
  * Check user can save a new group tag instance as these have a unique key
  * If not, will use - admin user (0), guest user (1), other admin user (2+)
  * @param int $groupid
  * @param int $tagid
  * @param int $start default -1 for current user.
  * @return int user id
  * @throws moodle_exception If out of users
  */
 private static function get_group_taginstance_userid($groupid, $tagid, $start = -1)
 {
     global $DB, $USER;
     $userid = $USER->id;
     $nexttry = 0;
     if ($start == 0) {
         $userid = get_admin()->id;
         $nexttry = 1;
     } else {
         if ($start == 1) {
             $userid = guest_user()->id;
             $nexttry = 2;
         } else {
             if ($start >= 2) {
                 $admins = get_admins();
                 if (count($admins) < $start) {
                     throw new moodle_exception('Cannot add tag instance - duplicate value, max possible reached.');
                 }
                 $keys = array_keys($admins);
                 // Get keys (user id's).
                 $userid = $keys[$start - 1];
                 $nexttry = $start;
                 $nexttry++;
             }
         }
     }
     if (!$DB->record_exists('tag_instance', array('itemtype' => 'groups', 'itemid' => $groupid, 'tiuserid' => $userid, 'tagid' => $tagid))) {
         // No existing record, safe to proceed.
         return $userid;
     }
     // Try and find another userid.
     return self::get_group_taginstance_userid($groupid, $tagid, $nexttry);
 }
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:42,代码来源:mod_forumng.php


示例14: forum_subscribed_users

/**
 * Returns list of user objects that are subscribed to this forum
 *
 * @global object
 * @global object
 * @param object $course the course
 * @param forum $forum the forum
 * @param integer $groupid group id, or 0 for all.
 * @param object $context the forum context, to save re-fetching it where possible.
 * @param string $fields requested user fields (with "u." table prefix)
 * @return array list of users.
 */
function forum_subscribed_users($course, $forum, $groupid = 0, $context = null, $fields = null)
{
    global $CFG, $DB;
    $params = array($forum->id);
    if ($groupid) {
        $grouptables = ", {groups_members} gm ";
        $groupselect = "AND gm.groupid = ? AND u.id = gm.userid";
        $params[] = $groupid;
    } else {
        $grouptables = '';
        $groupselect = '';
    }
    if (empty($fields)) {
        $fields = "u.id,\n                  u.username,\n                  u.firstname,\n                  u.lastname,\n                  u.maildisplay,\n                  u.mailformat,\n                  u.maildigest,\n                  u.imagealt,\n                  u.email,\n                  u.city,\n                  u.country,\n                  u.lastaccess,\n                  u.lastlogin,\n                  u.picture,\n                  u.timezone,\n                  u.theme,\n                  u.lang,\n                  u.trackforums,\n                  u.mnethostid";
    }
    if (forum_is_forcesubscribed($forum)) {
        if (empty($context)) {
            $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
        }
        $sort = "u.email ASC";
        $results = forum_get_potential_subscribers($context, $groupid, $fields, $sort);
    } else {
        $results = $DB->get_records_sql("SELECT {$fields}\n                              FROM {user} u,\n                                   {forum_subscriptions} s {$grouptables}\n                             WHERE s.forum = ?\n                               AND s.userid = u.id\n                               AND u.deleted = 0  {$groupselect}\n                          ORDER BY u.email ASC", $params);
    }
    static $guestid = null;
    if (is_null($guestid)) {
        if ($guest = guest_user()) {
            $guestid = $guest->id;
        } else {
            $guestid = 0;
        }
    }
    // Guest user should never be subscribed to a forum.
    unset($results[$guestid]);
    return $results;
}
开发者ID:hitphp,项目名称:moodle,代码行数:49,代码来源:lib.php


示例15: hsuforum_is_anonymous_user

/**
 * @param $user
 * @return bool
 * @author Mark Nielsen
 */
function hsuforum_is_anonymous_user($user)
{
    static $guest = null;
    if (is_null($guest)) {
        $guest = guest_user();
    }
    return $user->id == $guest->id;
}
开发者ID:cdsmith-umn,项目名称:moodle-mod_hsuforum,代码行数:13,代码来源:lib.php


示例16: guest_user

            }
        }
        if (empty($_SESSION['USER']) and !empty($_SERVER['HTTP_REFERER'])) {
            if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false) {
                $USER = guest_user();
            } else {
                if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false) {
                    $USER = guest_user();
                }
            }
        }
    }
}
/// Populates an empty $USER if is empty
if (empty($USER) || !isset($USER->ident)) {
    $USER = guest_user();
}
/// backwards compatibility
fill_legacy_user_session($USER);
//////
////// Load some core libraries
//////
require_once $CFG->dirroot . "lib/templates.php";
require_once $CFG->dirroot . "lib/displaylib.php";
//////
////// Init templating basics
//////
if (!isset($CFG->templatestore)) {
    $CFG->templatestore = 'db';
}
if (!isset($CFG->templatesroot)) {
开发者ID:BackupTheBerlios,项目名称:clavel-svn,代码行数:31,代码来源:setup.php


示例17: search_parse_keywords

            $userid = $this->customdata['current_user'];
            $formdata['hidden']['userid'] = $userid;
        }

        // Generate search SQL
        $keywords = search_parse_keywords($query);
        $fields = array('firstname', 'lastname', 'email');
        list($searchsql, $params) = search_get_keyword_where_clause($keywords, $fields);

        $search_info->fullname = $DB->sql_fullname('firstname', 'lastname');
        if ($canviewemail) {
            $search_info->email = 'email';
        }

        // exclude deleted, guest users and self
        $guest = guest_user();

        $search_info->sql = "
            FROM
                {user}
            WHERE
                {$searchsql}
                AND deleted = 0
                AND suspended = 0
                AND id != ?
        ";
        $params[] = $guest->id;

        if (isset($this->customdata['current_user'])) {
            $search_info->sql .= " AND id <> ?";
            $params[] = $userid;
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:31,代码来源:search.php


示例18: check_user_initialised

 /**
  * Initialise $USER object, handles google access
  * and sets up not logged in user properly.
  *
  * @return void
  */
 protected function check_user_initialised()
 {
     if (isset($_SESSION['USER']->id)) {
         // already set up $USER
         return;
     }
     $user = null;
     if (!empty($CFG->opentogoogle) and !NO_MOODLE_COOKIES) {
         if (!empty($_SERVER['HTTP_USER_AGENT'])) {
             // allow web spiders in as guest users
             if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false) {
                 $user = guest_user();
             } else {
                 if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false) {
                     // Google
                     $user = guest_user();
                 } e 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP guid函数代码示例发布时间:2022-05-15
下一篇:
PHP guess_image_type函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap