当前位置: 首页>>代码示例>>PHP>>正文


PHP url_parts函数代码示例

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


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

示例1: setLoginCookie

/**
 * Sets the login cookie and session based on the id_member and password passed.
 *
 * What it does:
 * - password should be already encrypted with the cookie salt.
 * - logs the user out if id_member is zero.
 * - sets the cookie and session to last the number of seconds specified by cookie_length.
 * - when logging out, if the globalCookies setting is enabled, attempts to clear the subdomain's cookie too.
 *
 * @package Authorization
 * @param int $cookie_length
 * @param int $id The id of the member
 * @param string $password = ''
 */
function setLoginCookie($cookie_length, $id, $password = '')
{
    global $cookiename, $boardurl, $modSettings;
    // If changing state force them to re-address some permission caching.
    $_SESSION['mc']['time'] = 0;
    // Let's be sure it is an int to simplify the regexp used to validate the cookie
    $id = (int) $id;
    // The cookie may already exist, and have been set with different options.
    $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
    if (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\\{i:0;i:\\d{1,8};i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\\d{1,14};(i:3;i:\\d;)?\\}$~', $_COOKIE[$cookiename]) === 1) {
        $array = @unserialize($_COOKIE[$cookiename]);
        // Out with the old, in with the new!
        if (isset($array[3]) && $array[3] != $cookie_state) {
            $cookie_url = url_parts($array[3] & 1 > 0, $array[3] & 2 > 0);
            elk_setcookie($cookiename, serialize(array(0, '', 0)), time() - 3600, $cookie_url[1], $cookie_url[0]);
        }
    }
    // Get the data and path to set it on.
    $data = serialize(empty($id) ? array(0, '', 0) : array($id, $password, time() + $cookie_length, $cookie_state));
    $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
    // Set the cookie, $_COOKIE, and session variable.
    elk_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
    // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
    if (empty($id) && !empty($modSettings['globalCookies'])) {
        elk_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
    }
    // Any alias URLs?  This is mainly for use with frames, etc.
    if (!empty($modSettings['forum_alias_urls'])) {
        $aliases = explode(',', $modSettings['forum_alias_urls']);
        $temp = $boardurl;
        foreach ($aliases as $alias) {
            // Fake the $boardurl so we can set a different cookie.
            $alias = strtr(trim($alias), array('http://' => '', 'https://' => ''));
            $boardurl = 'http://' . $alias;
            $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
            if ($cookie_url[0] == '') {
                $cookie_url[0] = strtok($alias, '/');
            }
            elk_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
        }
        $boardurl = $temp;
    }
    $_COOKIE[$cookiename] = $data;
    // Make sure the user logs in with a new session ID.
    if (!isset($_SESSION['login_' . $cookiename]) || $_SESSION['login_' . $cookiename] !== $data) {
        // We need to meddle with the session.
        require_once SOURCEDIR . '/Session.php';
        // Backup the old session.
        $oldSessionData = $_SESSION;
        // Remove the old session data and file / db entry
        $_SESSION = array();
        session_destroy();
        // Recreate and restore the new session.
        loadSession();
        // Get a new session id, and load it with the data
        session_regenerate_id();
        $_SESSION = $oldSessionData;
        $_SESSION['login_' . $cookiename] = $data;
    }
}
开发者ID:KeiroD,项目名称:Elkarte,代码行数:74,代码来源:Auth.subs.php

示例2: ProcessRefferalLink

function ProcessRefferalLink()
{
    global $modSettings, $db_prefix, $sourcedir;
    if (!isset($_REQUEST['refferedby']) && !isset($_REQUEST['referredby'])) {
        return;
    }
    if (isset($_REQUEST['referredby'])) {
        $refferedBy = (int) $_REQUEST['referredby'];
    }
    if (isset($_REQUEST['refferedby'])) {
        $refferedBy = (int) $_REQUEST['refferedby'];
    }
    if (empty($refferedBy) && isset($_COOKIE['refferedby'])) {
        $refferedBy = (int) $_COOKIE['refferedby'];
    }
    if (empty($refferedBy) && isset($_SESSION['refferedby'])) {
        $refferedBy = (int) $_SESSION['refferedby'];
    }
    if (!empty($refferedBy) && !isset($_COOKIE['refferedby']) && !isset($_SESSION['refferedby'])) {
        // Track hits??
        if ($modSettings['ref_trackcookiehits']) {
            db_query("\n\t\t\tUPDATE {$db_prefix}members\n\t\t\tSET referrals_hits = referrals_hits + 1\n\t\t\tWHERE ID_MEMBER =  " . $refferedBy, __FILE__, __LINE__);
        }
        require_once $sourcedir . '/Subs-Auth.php';
        // Set cookie
        $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCooki0es']));
        setcookie('refferedby', $refferedBy, time() + $modSettings['ref_cookietrackdays'] * 24 * 60 * 60, $cookie_url[1], $cookie_url[0], 0);
        $_SESSION['refferedby'] = $refferedBy;
    }
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:30,代码来源:refferals.php

示例3: build_url

/**
 * Returns the complete url according to $base
 *
 * @since ADD MVC 0.5
 */
function build_url($base, $url)
{
    $base_parts = url_parts($base);
    if ($url[0] === '/') {
        return rtrim($base_parts['protocol_domain'], '/') . $url;
    }
    if ($url[0] === '?') {
        if (!$base_parts['pathname']) {
            $base_parts['pathname'] = '/';
        }
        return $base_parts['protocol_domain'] . $base_parts['pathname'] . $url;
    }
    if ($url[0] === '#') {
    }
    if (preg_match('/^https?\\:\\/+/', $url)) {
        return $url;
    }
    return rtrim($base_parts['protocol_domain'], "/") . $base_parts['path'] . $url;
}
开发者ID:google-code-backups,项目名称:add-mvc-framework,代码行数:24,代码来源:url.functions.php

示例4: build_url

/**
 * Returns the complete url according to $base
 *
 * @param string $base
 * @param string $url
 *
 * @since ADD MVC 0.5
 *
 * @version 0.1
 */
function build_url($base, $url)
{
    $base_parts = url_parts($base);
    # https://code.google.com/p/add-mvc-framework/issues/detail?id=81
    if (preg_match('/^javascript\\:/', $url)) {
        return $url;
    }
    if ($url[0] === '/') {
        return rtrim($base_parts['protocol_domain'], '/') . $url;
    }
    if ($url[0] === '?') {
        if (!$base_parts['pathname']) {
            $base_parts['pathname'] = '/';
        }
        return $base_parts['protocol_domain'] . $base_parts['pathname'] . $url;
    }
    if ($url[0] === '#') {
    }
    if (preg_match('/^https?\\:\\/+/', $url)) {
        return $url;
    }
    return rtrim($base_parts['protocol_domain'], "/") . $base_parts['path'] . $url;
}
开发者ID:google-code-backups,项目名称:add-mvc-framework,代码行数:33,代码来源:url.functions.php

示例5: is_not_banned


//.........这里部分代码省略.........
                        }
                    }
                }
            }
            $smcFunc['db_free_result']($request);
        }
        // Mark the cannot_access and cannot_post bans as being 'hit'.
        if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
            log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
        }
        // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
        if ($user_info['id'] && ($user_settings['is_activated'] >= 10 && !$flag_is_activated || $user_settings['is_activated'] < 10 && $flag_is_activated)) {
            require_once $sourcedir . '/ManageBans.php';
            updateBanMembers();
        }
    }
    // Hey, I know you! You're ehm...
    if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) {
        $bans = explode(',', $_COOKIE[$cookiename . '_']);
        foreach ($bans as $key => $value) {
            $bans[$key] = (int) $value;
        }
        $request = $smcFunc['db_query']('', '
			SELECT bi.id_ban, bg.reason
			FROM {db_prefix}ban_items AS bi
				INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group)
			WHERE bi.id_ban IN ({array_int:ban_list})
				AND (bg.expire_time IS NULL OR bg.expire_time > {int:current_time})
				AND bg.cannot_access = {int:cannot_access}
			LIMIT ' . count($bans), array('cannot_access' => 1, 'ban_list' => $bans, 'current_time' => time()));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $_SESSION['ban']['cannot_access']['ids'][] = $row['id_ban'];
            $_SESSION['ban']['cannot_access']['reason'] = $row['reason'];
        }
        $smcFunc['db_free_result']($request);
        // My mistake. Next time better.
        if (!isset($_SESSION['ban']['cannot_access'])) {
            require_once $sourcedir . '/Subs-Auth.php';
            $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
            setcookie($cookiename . '_', '', time() - 3600, $cookie_url[1], $cookie_url[0], 0);
        }
    }
    // If you're fully banned, it's end of the story for you.
    if (isset($_SESSION['ban']['cannot_access'])) {
        // We don't wanna see you!
        if (!$user_info['is_guest']) {
            $smcFunc['db_query']('', '
				DELETE FROM {db_prefix}log_online
				WHERE id_member = {int:current_member}', array('current_member' => $user_info['id']));
        }
        // 'Log' the user out.  Can't have any funny business... (save the name!)
        $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
        $user_info['name'] = '';
        $user_info['username'] = '';
        $user_info['is_guest'] = true;
        $user_info['is_admin'] = false;
        $user_info['permissions'] = array();
        $user_info['id'] = 0;
        $context['user'] = array('id' => 0, 'username' => '', 'name' => $txt['guest_title'], 'is_guest' => true, 'is_logged' => false, 'is_admin' => false, 'is_mod' => false, 'can_mod' => false, 'language' => $user_info['language']);
        // A goodbye present.
        require_once $sourcedir . '/Subs-Auth.php';
        $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
        setcookie($cookiename . '_', implode(',', $_SESSION['ban']['cannot_access']['ids']), time() + 3153600, $cookie_url[1], $cookie_url[0], 0);
        // Don't scare anyone, now.
        $_GET['action'] = '';
        $_GET['board'] = '';
        $_GET['topic'] = '';
        writeLog(true);
        // You banned, sucka!
        fatal_error(sprintf($txt['your_ban'], $old_name) . (empty($_SESSION['ban']['cannot_access']['reason']) ? '' : '<br />' . $_SESSION['ban']['cannot_access']['reason']) . '<br />' . (!empty($_SESSION['ban']['expire_time']) ? sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)) : $txt['your_ban_expires_never']), 'user');
        // If we get here, something's gone wrong.... but let's try anyway.
        trigger_error('Hacking attempt...', E_USER_ERROR);
    } elseif (isset($_SESSION['ban']['cannot_login']) && !$user_info['is_guest']) {
        // We don't wanna see you!
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}log_online
			WHERE id_member = {int:current_member}', array('current_member' => $user_info['id']));
        // 'Log' the user out.  Can't have any funny business... (save the name!)
        $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
        $user_info['name'] = '';
        $user_info['username'] = '';
        $user_info['is_guest'] = true;
        $user_info['is_admin'] = false;
        $user_info['permissions'] = array();
        $user_info['id'] = 0;
        $context['user'] = array('id' => 0, 'username' => '', 'name' => $txt['guest_title'], 'is_guest' => true, 'is_logged' => false, 'is_admin' => false, 'is_mod' => false, 'can_mod' => false, 'language' => $user_info['language']);
        // SMF's Wipe 'n Clean(r) erases all traces.
        $_GET['action'] = '';
        $_GET['board'] = '';
        $_GET['topic'] = '';
        writeLog(true);
        require_once $sourcedir . '/LogInOut.php';
        Logout(true, false);
        fatal_error(sprintf($txt['your_ban'], $old_name) . (empty($_SESSION['ban']['cannot_login']['reason']) ? '' : '<br />' . $_SESSION['ban']['cannot_login']['reason']) . '<br />' . (!empty($_SESSION['ban']['expire_time']) ? sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)) : $txt['your_ban_expires_never']) . '<br />' . $txt['ban_continue_browse'], 'user');
    }
    // Fix up the banning permissions.
    if (isset($user_info['permissions'])) {
        banPermissions();
    }
}
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:101,代码来源:Security.php

示例6: Vote


//.........这里部分代码省略.........
                if ($guestvoted[0] == $row['id_poll']) {
                    break;
                }
            }
            // Has the poll been reset since guest voted?
            if ($row['reset_poll'] > $guestvoted[1]) {
                // Remove the poll info from the cookie to allow guest to vote again
                unset($guestinfo[$i]);
                if (!empty($guestinfo)) {
                    $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
                } else {
                    unset($_COOKIE['guest_poll_vote']);
                }
            } else {
                fatal_lang_error('poll_error', false);
            }
            unset($guestinfo, $guestvoted, $i);
        }
    }
    // Is voting locked or has it expired?
    if (!empty($row['voting_locked']) || !empty($row['expire_time']) && time() > $row['expire_time']) {
        fatal_lang_error('poll_error', false);
    }
    // If they have already voted and aren't allowed to change their vote - hence they are outta here!
    if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) {
        fatal_lang_error('poll_error', false);
    } elseif (!empty($row['change_vote']) && !$user_info['is_guest']) {
        checkSession('request');
        $pollOptions = array();
        // Find out what they voted for before.
        $request = smf_db_query('
			SELECT id_choice
			FROM {db_prefix}log_polls
			WHERE id_member = {int:current_member}
				AND id_poll = {int:id_poll}', array('current_member' => $user_info['id'], 'id_poll' => $row['id_poll']));
        while ($choice = mysql_fetch_row($request)) {
            $pollOptions[] = $choice[0];
        }
        mysql_free_result($request);
        // Just skip it if they had voted for nothing before.
        if (!empty($pollOptions)) {
            // Update the poll totals.
            smf_db_query('
				UPDATE {db_prefix}poll_choices
				SET votes = votes - 1
				WHERE id_poll = {int:id_poll}
					AND id_choice IN ({array_int:poll_options})
					AND votes > {int:votes}', array('poll_options' => $pollOptions, 'id_poll' => $row['id_poll'], 'votes' => 0));
            // Delete off the log.
            smf_db_query('
				DELETE FROM {db_prefix}log_polls
				WHERE id_member = {int:current_member}
					AND id_poll = {int:id_poll}', array('current_member' => $user_info['id'], 'id_poll' => $row['id_poll']));
        }
        // Redirect back to the topic so the user can vote again!
        if (empty($_POST['options'])) {
            redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
        }
    }
    checkSession('request');
    // Make sure the option(s) are valid.
    if (empty($_POST['options'])) {
        fatal_lang_error('didnt_select_vote', false);
    }
    // Too many options checked!
    if (count($_REQUEST['options']) > $row['max_votes']) {
        fatal_lang_error('poll_too_many_votes', false, array($row['max_votes']));
    }
    $pollOptions = array();
    $inserts = array();
    foreach ($_REQUEST['options'] as $id) {
        $id = (int) $id;
        $pollOptions[] = $id;
        $inserts[] = array($row['id_poll'], $user_info['id'], $id);
    }
    // Add their vote to the tally.
    smf_db_insert('insert', '{db_prefix}log_polls', array('id_poll' => 'int', 'id_member' => 'int', 'id_choice' => 'int'), $inserts, array('id_poll', 'id_member', 'id_choice'));
    smf_db_query('
		UPDATE {db_prefix}poll_choices
		SET votes = votes + 1
		WHERE id_poll = {int:id_poll}
			AND id_choice IN ({array_int:poll_options})', array('poll_options' => $pollOptions, 'id_poll' => $row['id_poll']));
    // If it's a guest don't let them vote again.
    if ($user_info['is_guest'] && count($pollOptions) > 0) {
        // Time is stored in case the poll is reset later, plus what they voted for.
        $_COOKIE['guest_poll_vote'] = empty($_COOKIE['guest_poll_vote']) ? '' : $_COOKIE['guest_poll_vote'];
        // ;id,timestamp,[vote,vote...]; etc
        $_COOKIE['guest_poll_vote'] .= ';' . $row['id_poll'] . ',' . time() . ',' . (count($pollOptions) > 1 ? explode(',' . $pollOptions) : $pollOptions[0]);
        // Increase num guest voters count by 1
        smf_db_query('
			UPDATE {db_prefix}polls
			SET num_guest_voters = num_guest_voters + 1
			WHERE id_poll = {int:id_poll}', array('id_poll' => $row['id_poll']));
        require_once $sourcedir . '/lib/Subs-Auth.php';
        $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
        setcookie('guest_poll_vote', $_COOKIE['guest_poll_vote'], time() + 2500000, $cookie_url[1], $cookie_url[0], 0);
    }
    // Return to the post...
    redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
}
开发者ID:norv,项目名称:EosAlpha,代码行数:101,代码来源:Poll.php

示例7: setLoginCookie

function setLoginCookie($cookie_length, $id, $password = '')
{
    global $cookiename, $boardurl, $modSettings;
    // If changing state force them to re-address some permission caching.
    $_SESSION['mc']['time'] = 0;
    // The cookie may already exist, and have been set with different options.
    $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
    if (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\\{i:0;(i:\\d{1,6}|s:[1-8]:"\\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\\d{1,14};(i:3;i:\\d;)?\\}$~', $_COOKIE[$cookiename]) === 1) {
        $array = @unserialize($_COOKIE[$cookiename]);
        // Out with the old, in with the new!
        if (isset($array[3]) && $array[3] != $cookie_state) {
            $cookie_url = url_parts($array[3] & 1 > 0, $array[3] & 2 > 0);
            setcookie($cookiename, serialize(array(0, '', 0)), time() - 3600, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies']));
        }
    }
    // Get the data and path to set it on.
    $data = serialize(empty($id) ? array(0, '', 0) : array($id, $password, time() + $cookie_length, $cookie_state));
    $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
    // Set the cookie, $_COOKIE, and session variable.
    setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies']));
    // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
    if (empty($id) && !empty($modSettings['globalCookies'])) {
        setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '', !empty($modSettings['secureCookies']));
    }
    // Any alias URLs?  This is mainly for use with frames, etc.
    if (!empty($modSettings['forum_alias_urls'])) {
        $aliases = explode(',', $modSettings['forum_alias_urls']);
        $temp = $boardurl;
        foreach ($aliases as $alias) {
            // Fake the $boardurl so we can set a different cookie.
            $alias = strtr(trim($alias), array('http://' => '', 'https://' => ''));
            $boardurl = 'http://' . $alias;
            $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
            if ($cookie_url[0] == '') {
                $cookie_url[0] = strtok($alias, '/');
            }
            setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies']));
        }
        $boardurl = $temp;
    }
    $_COOKIE[$cookiename] = $data;
    // Make sure the user logs in with a new session ID.
    if (!isset($_SESSION['login_' . $cookiename]) || $_SESSION['login_' . $cookiename] !== $data) {
        // Backup and remove the old session.
        $oldSessionData = $_SESSION;
        $_SESSION = array();
        session_destroy();
        // Recreate and restore the new session.
        loadSession();
        session_regenerate_id();
        $_SESSION = $oldSessionData;
        // Version 4.3.2 didn't store the cookie of the new session.
        if (version_compare(PHP_VERSION, '4.3.2') === 0) {
            $sessionCookieLifetime = @ini_get('session.cookie_lifetime');
            setcookie(session_name(), session_id(), time() + (empty($sessionCookieLifetime) ? $cookie_length : $sessionCookieLifetime), $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies']));
        }
        $_SESSION['login_' . $cookiename] = $data;
    }
}
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:59,代码来源:Subs-Auth.php

示例8: ssi_pollVote

function ssi_pollVote()
{
    global $context, $db_prefix, $user_info, $sc, $smcFunc, $sourcedir, $modSettings;
    if (!isset($_POST[$context['session_var']]) || $_POST[$context['session_var']] != $sc || empty($_POST['options']) || !isset($_POST['poll'])) {
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript"><!-- // --><![CDATA[
		history.go(-1);
	// ]]></script>
</head>
<body>&laquo;</body>
</html>';
        return;
    }
    // This can cause weird errors! (ie. copyright missing.)
    checkSession();
    $_POST['poll'] = (int) $_POST['poll'];
    // Check if they have already voted, or voting is locked.
    $request = $smcFunc['db_query']('', '
		SELECT
			p.id_poll, p.voting_locked, p.expire_time, p.max_votes, p.guest_vote,
			t.id_topic,
			IFNULL(lp.id_choice, -1) AS selected
		FROM {db_prefix}polls AS p
			INNER JOIN {db_prefix}topics AS t ON (t.id_poll = {int:current_poll})
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
			LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member = {int:current_member})
		WHERE p.id_poll = {int:current_poll}
			AND {query_see_board}' . ($modSettings['postmod_active'] ? '
			AND t.approved = {int:is_approved}' : '') . '
		LIMIT 1', array('current_member' => $user_info['id'], 'current_poll' => $_POST['poll'], 'is_approved' => 1));
    if ($smcFunc['db_num_rows']($request) == 0) {
        die;
    }
    $row = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);
    if (!empty($row['voting_locked']) || $row['selected'] != -1 && !$user_info['is_guest'] || !empty($row['expire_time']) && time() > $row['expire_time']) {
        redirectexit('topic=' . $row['id_topic'] . '.0');
    }
    // Too many options checked?
    if (count($_REQUEST['options']) > $row['max_votes']) {
        redirectexit('topic=' . $row['id_topic'] . '.0');
    }
    // It's a guest who has already voted?
    if ($user_info['is_guest']) {
        // Guest voting disabled?
        if (!$row['guest_vote']) {
            redirectexit('topic=' . $row['id_topic'] . '.0');
        } elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) {
            redirectexit('topic=' . $row['id_topic'] . '.0');
        }
    }
    $options = array();
    $inserts = array();
    foreach ($_REQUEST['options'] as $id) {
        $id = (int) $id;
        $options[] = $id;
        $inserts[] = array($_POST['poll'], $user_info['id'], $id);
    }
    // Add their vote in to the tally.
    $smcFunc['db_insert']('insert', $db_prefix . 'log_polls', array('id_poll' => 'int', 'id_member' => 'int', 'id_choice' => 'int'), $inserts, array('id_poll', 'id_member', 'id_choice'));
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}poll_choices
		SET votes = votes + 1
		WHERE id_poll = {int:current_poll}
			AND id_choice IN ({array_int:option_list})', array('option_list' => $options, 'current_poll' => $_POST['poll']));
    // Track the vote if a guest.
    if ($user_info['is_guest']) {
        $_COOKIE['guest_poll_vote'] = !empty($_COOKIE['guest_poll_vote']) ? $_COOKIE['guest_poll_vote'] . ',' . $row['id_poll'] : $row['id_poll'];
        require_once $sourcedir . '/lib/Subs-Auth.php';
        $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
        setcookie('guest_poll_vote', $_COOKIE['guest_poll_vote'], time() + 2500000, $cookie_url[1], $cookie_url[0], 0);
    }
    redirectexit('topic=' . $row['id_topic'] . '.0');
}
开发者ID:norv,项目名称:EosAlpha,代码行数:76,代码来源:SSI.php

示例9: action_vote


//.........这里部分代码省略.........
 {
     global $topic, $user_info, $modSettings;
     require_once SUBSDIR . '/Poll.subs.php';
     // Make sure you can vote.
     isAllowedTo('poll_vote');
     loadLanguage('Post');
     // Check if they have already voted, or voting is locked.
     $row = checkVote($topic);
     if (empty($row)) {
         fatal_lang_error('poll_error', false);
     }
     // If this is a guest can they vote?
     if ($user_info['is_guest']) {
         // Guest voting disabled?
         if (!$row['guest_vote']) {
             fatal_lang_error('guest_vote_disabled');
         } elseif (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $row['id_poll'] . ',') !== false) {
             // ;id,timestamp,[vote,vote...]; etc
             $guestinfo = explode(';', $_COOKIE['guest_poll_vote']);
             // Find the poll we're after.
             foreach ($guestinfo as $i => $guestvoted) {
                 $guestvoted = explode(',', $guestvoted);
                 if ($guestvoted[0] == $row['id_poll']) {
                     break;
                 }
             }
             // Has the poll been reset since guest voted?
             if (isset($guestvoted[1]) && $row['reset_poll'] > $guestvoted[1]) {
                 // Remove the poll info from the cookie to allow guest to vote again
                 unset($guestinfo[$i]);
                 if (!empty($guestinfo)) {
                     $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
                 } else {
                     unset($_COOKIE['guest_poll_vote']);
                 }
             } else {
                 fatal_lang_error('poll_error', false);
             }
             unset($guestinfo, $guestvoted, $i);
         }
     }
     // Is voting locked or has it expired?
     if (!empty($row['voting_locked']) || !empty($row['expire_time']) && time() > $row['expire_time']) {
         fatal_lang_error('poll_error', false);
     }
     // If they have already voted and aren't allowed to change their vote - hence they are outta here!
     if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) {
         fatal_lang_error('poll_error', false);
     } elseif (!empty($row['change_vote']) && !$user_info['is_guest'] && empty($_POST['options'])) {
         checkSession('request');
         // Find out what they voted for before.
         $pollOptions = determineVote($user_info['id'], $row['id_poll']);
         // Just skip it if they had voted for nothing before.
         if (!empty($pollOptions)) {
             // Update the poll totals.
             decreaseVoteCounter($row['id_poll'], $pollOptions);
             // Delete off the log.
             removeVote($user_info['id'], $row['id_poll']);
         }
         // Redirect back to the topic so the user can vote again!
         if (empty($_POST['options'])) {
             redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
         }
     }
     checkSession('request');
     // Make sure the option(s) are valid.
     if (empty($_POST['options'])) {
         fatal_lang_error('didnt_select_vote', false);
     }
     // Too many options checked!
     if (count($_REQUEST['options']) > $row['max_votes']) {
         fatal_lang_error('poll_too_many_votes', false, array($row['max_votes']));
     }
     $pollOptions = array();
     $inserts = array();
     foreach ($_REQUEST['options'] as $id) {
         $id = (int) $id;
         $pollOptions[] = $id;
         $inserts[] = array($row['id_poll'], $user_info['id'], $id);
     }
     // Add their vote to the tally.
     addVote($inserts);
     increaseVoteCounter($row['id_poll'], $pollOptions);
     // If it's a guest don't let them vote again.
     if ($user_info['is_guest'] && count($pollOptions) > 0) {
         // Time is stored in case the poll is reset later, plus what they voted for.
         $_COOKIE['guest_poll_vote'] = empty($_COOKIE['guest_poll_vote']) ? '' : $_COOKIE['guest_poll_vote'];
         // ;id,timestamp,[vote,vote...]; etc
         $_COOKIE['guest_poll_vote'] .= ';' . $row['id_poll'] . ',' . time() . ',' . (count($pollOptions) > 1 ? implode(',', $pollOptions) : $pollOptions[0]);
         // Increase num guest voters count by 1
         increaseGuestVote($row['id_poll']);
         require_once SUBSDIR . '/Auth.subs.php';
         $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
         elk_setcookie('guest_poll_vote', $_COOKIE['guest_poll_vote'], time() + 2500000, $cookie_url[1], $cookie_url[0], false, false);
     }
     // Maybe let a social networking mod log this, or something?
     call_integration_hook('integrate_poll_vote', array(&$row['id_poll'], &$pollOptions));
     // Return to the post...
     redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
 }
开发者ID:KeiroD,项目名称:Elkarte,代码行数:101,代码来源:Poll.controller.php

示例10: is_not_banned

function is_not_banned($forceCheck = false)
{
    global $txt, $db_prefix, $ID_MEMBER, $modSettings, $context, $user_info;
    global $sourcedir, $cookiename, $user_settings;
    // You cannot be banned if you are an admin - doesn't help if you log out.
    if ($user_info['is_admin']) {
        return;
    }
    // Only check the ban every so often. (to reduce load.)
    if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || $_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated'] || $_SESSION['ban']['ID_MEMBER'] != $ID_MEMBER || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']) {
        // Innocent until proven guilty.  (but we know you are! :P)
        $_SESSION['ban'] = array('last_checked' => time(), 'ID_MEMBER' => $ID_MEMBER, 'ip' => $user_info['ip'], 'ip2' => $user_info['ip2'], 'email' => $user_info['email']);
        $ban_query = array();
        $flag_is_activated = false;
        // Check both IP addresses.
        foreach (array('ip', 'ip2') as $ip_number) {
            // Check if we have a valid IP address.
            if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $user_info[$ip_number], $ip_parts) == 1) {
                $ban_query[] = "(({$ip_parts['1']} BETWEEN bi.ip_low1 AND bi.ip_high1)\n\t\t\t\t\t\t\tAND ({$ip_parts['2']} BETWEEN bi.ip_low2 AND bi.ip_high2)\n\t\t\t\t\t\t\tAND ({$ip_parts['3']} BETWEEN bi.ip_low3 AND bi.ip_high3)\n\t\t\t\t\t\t\tAND ({$ip_parts['4']} BETWEEN bi.ip_low4 AND bi.ip_high4))";
                // IP was valid, maybe there's also a hostname...
                if (empty($modSettings['disableHostnameLookup'])) {
                    $hostname = host_from_ip($user_info[$ip_number]);
                    if (strlen($hostname) > 0) {
                        $ban_query[] = "('" . addslashes($hostname) . "' LIKE bi.hostname)";
                    }
                }
            } elseif ($user_info[$ip_number] == 'unknown') {
                $ban_query[] = "(bi.ip_low1 = 255 AND bi.ip_high1 = 255\n\t\t\t\t\t\t\tAND bi.ip_low2 = 255 AND bi.ip_high2 = 255\n\t\t\t\t\t\t\tAND bi.ip_low3 = 255 AND bi.ip_high3 = 255\n\t\t\t\t\t\t\tAND bi.ip_low4 = 255 AND bi.ip_high4 = 255)";
            }
        }
        // Is their email address banned?
        if (strlen($user_info['email']) != 0) {
            $ban_query[] = "('" . addslashes($user_info['email']) . "' LIKE bi.email_address)";
        }
        // How about this user?
        if (!$user_info['is_guest'] && !empty($ID_MEMBER)) {
            $ban_query[] = "bi.ID_MEMBER = {$ID_MEMBER}";
        }
        // Check the ban, if there's information.
        if (!empty($ban_query)) {
            $restrictions = array('cannot_access', 'cannot_login', 'cannot_post', 'cannot_register');
            $request = db_query("\n\t\t\t\tSELECT bi.ID_BAN, bi.email_address, bi.ID_MEMBER, bg.cannot_access, bg.cannot_register,\n\t\t\t\t\tbg.cannot_post, bg.cannot_login, bg.reason\n\t\t\t\tFROM ({$db_prefix}ban_groups AS bg, {$db_prefix}ban_items AS bi)\n\t\t\t\tWHERE bg.ID_BAN_GROUP = bi.ID_BAN_GROUP\n\t\t\t\t\tAND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ")\n\t\t\t\t\tAND (" . implode(' OR ', $ban_query) . ')', __FILE__, __LINE__);
            // Store every type of ban that applies to you in your session.
            while ($row = mysql_fetch_assoc($request)) {
                foreach ($restrictions as $restriction) {
                    if (!empty($row[$restriction])) {
                        $_SESSION['ban'][$restriction]['reason'] = $row['reason'];
                        $_SESSION['ban'][$restriction]['ids'][] = $row['ID_BAN'];
                        if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['ID_MEMBER'] == $ID_MEMBER || $row['email_address'] == $user_info['email'])) {
                            $flag_is_activated = true;
                        }
                    }
                }
            }
            mysql_free_result($request);
        }
        // Mark the cannot_access and cannot_post bans as being 'hit'.
        if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post'])) {
            log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array()));
        }
        // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
        if ($ID_MEMBER && ($user_settings['is_activated'] >= 10 && !$flag_is_activated || $user_settings['is_activated'] < 10 && $flag_is_activated)) {
            require_once $sourcedir . '/ManageBans.php';
            updateBanMembers();
        }
    }
    // Hey, I know you! You're ehm...
    if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) {
        $bans = explode(',', $_COOKIE[$cookiename . '_']);
        foreach ($bans as $key => $value) {
            $bans[$key] = (int) $value;
        }
        $request = db_query("\n\t\t\tSELECT bi.ID_BAN, bg.reason\n\t\t\tFROM ({$db_prefix}ban_items AS bi, {$db_prefix}ban_groups AS bg)\n\t\t\tWHERE bg.ID_BAN_GROUP = bi.ID_BAN_GROUP\n\t\t\t\tAND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ")\n\t\t\t\tAND bg.cannot_access = 1\n\t\t\t\tAND bi.ID_BAN IN (" . implode(', ', $bans) . ")\n\t\t\tLIMIT " . count($bans), __FILE__, __LINE__);
        while ($row = mysql_fetch_assoc($request)) {
            $_SESSION['ban']['cannot_access']['ids'][] = $row['ID_BAN'];
            $_SESSION['ban']['cannot_access']['reason'] = $row['reason'];
        }
        mysql_free_result($request);
        // My mistake. Next time better.
        if (!isset($_SESSION['ban']['cannot_access'])) {
            require_once $sourcedir . '/Subs-Auth.php';
            $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
            setcookie($cookiename . '_', '', time() - 3600, $cookie_url[1], $cookie_url[0], 0);
        }
    }
    // If you're fully banned, it's end of the story for you.
    if (isset($_SESSION['ban']['cannot_access'])) {
        // We don't wanna see you!
        if (!$user_info['is_guest']) {
            db_query("\n\t\t\t\tDELETE FROM {$db_prefix}log_online\n\t\t\t\tWHERE ID_MEMBER = {$ID_MEMBER}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
        // 'Log' the user out.  Can't have any funny business... (save the name!)
        $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt[28];
        $user_info['name'] = '';
        $user_info['username'] = '';
        $user_info['is_guest'] = true;
        $user_info['is_admin'] = false;
        $user_info['permissions'] = array();
        $ID_MEMBER = 0;
        $context['user'] = array('id' => 0, 'username' => '', 'name' => $txt[28], 'is_guest' => true, 'is_logged' => false, 'is_admin' => false, 'is_mod' => false, 'language' => $user_info['language']);
//.........这里部分代码省略.........
开发者ID:alencarmo,项目名称:OCF,代码行数:101,代码来源:Security.php

示例11: setActiveFromUrl

 /**
  * Set all relevant children active based on the current request's URL.
  *
  * /, /about, /contact => request to /about will set the about link active.
  *
  * /en, /en/about, /en/contact => request to /en won't set /en active if the
  *                                request root is set to /en.
  *
  * @param string $url The current request url.
  * @param string $root If the link's URL is an exact match with the request
  *                     root, the link won't be set active. This behavior is
  *                     to avoid having home links active on every request.
  *
  * @return $this
  */
 public function setActiveFromUrl($url, $root = '/')
 {
     $this->applyToAll(function (Menu $menu) use($url, $root) {
         $menu->setActiveFromUrl($url, $root);
     });
     $requestUrl = url_parts($url);
     $requestRoot = strip_trailing_slashes($root, '/');
     $this->applyToAll(function ($item) use($requestUrl, $requestRoot) {
         // Not using a magic typehint since we need to do two instance checks
         if (!$item instanceof HasUrl || !$item instanceof Activatable) {
             return;
         }
         $url = url_parts($item->getUrl());
         // If the menu item is on a different host it can't be active.
         if ($url['host'] !== '' && $url['host'] !== $requestUrl['host']) {
             return;
         }
         // If the request url or the link url is on the root, only set exact matches active.
         if ($requestUrl['path'] === $requestRoot || $url['path'] === $requestRoot) {
             if ($url['path'] === $requestUrl['path']) {
                 $item->setActive();
             }
             return;
         }
         // If the request path is empty and it isn't the root, there's most likely a
         // configuration error, and the item isn't active.
         if (empty($url['path'])) {
             return;
         }
         // The menu item is active if it's path starts with the request path.
         if (strpos($requestUrl['path'], $url['path']) === 0) {
             $item->setActive();
         }
     });
     return $this;
 }
开发者ID:awatbayazidi,项目名称:foundation,代码行数:51,代码来源:Menu.php


注:本文中的url_parts函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。