示例#1
0
 /**
  * Set session geopositioning
  *
  * @param string $location  Location
  * @param float  $latitude  Latitude
  * @param float  $longitude Longitude
  * @return stdClass
  */
 public function set($location = '', $latitude = 0, $longitude = 0)
 {
     $location = sanitize_string($location);
     $lat = (double) $latitude;
     $long = (double) $longitude;
     if (!$lat || !$long) {
         $latlong = $this->geocode($location);
         if ($latlong) {
             $lat = elgg_extract('lat', $latlong);
             $long = elgg_extract('long', $latlong);
         }
     }
     $geopositioning = array('location' => $location, 'latitude' => $lat, 'longitude' => $long);
     $cookie_value = base64_encode(serialize($geopositioning));
     if (\hypeJunction\Integration::isElggVersionAbove('1.9.0')) {
         $cookie = new \ElggCookie(self::COOKIE_NAME);
         $cookie->value = $cookie_value;
         elgg_set_cookie($cookie);
     } else {
         setcookie(self::COOKIE_NAME, $cookie_value, strtotime("+30days"), "/", "");
     }
     return (object) $geopositioning;
 }
示例#2
0
/**
 * Log the current user out
 *
 * @return bool
 */
function logout()
{
    $session = _elgg_services()->session;
    $user = $session->getLoggedInUser();
    if (!$user) {
        return false;
    }
    // plugins can prevent a logout
    if (!elgg_trigger_event('logout', 'user', $user)) {
        return false;
    }
    // remove remember cookie
    if (isset($_COOKIE['elggperm'])) {
        _elgg_delete_remember_me_cookie(md5($_COOKIE['elggperm']));
        // tell browser to delete cookie
        $cookie = new ElggCookie("elggperm");
        $cookie->setExpiresTime("-30 days");
        $cookie->domain = "/";
        elgg_set_cookie($cookie);
    }
    // pass along any messages into new session
    $old_msg = $session->get('msg');
    $session->invalidate();
    $session->set('msg', $old_msg);
    return true;
}
示例#3
0
/**
 * Reorders the widgets from a widget panel
 *
 * @param string $panelstring1 String of guids of ElggWidget objects separated by ::
 * @param string $panelstring2 String of guids of ElggWidget objects separated by ::
 * @param string $panelstring3 String of guids of ElggWidget objects separated by ::
 * @param string $context      Profile or dashboard
 * @param int    $owner        Owner guid
 *
 * @return void
 * @deprecated 1.8 Don't use.
 */
function reorder_widgets_from_panel($panelstring1, $panelstring2, $panelstring3, $context, $owner)
{
    elgg_deprecated_notice("reorder_widgets_from_panel() is deprecated", 1.8);
    $return = true;
    $mainwidgets = explode('::', $panelstring1);
    $sidewidgets = explode('::', $panelstring2);
    $rightwidgets = explode('::', $panelstring3);
    $handlers = array();
    $guids = array();
    if (is_array($mainwidgets) && sizeof($mainwidgets) > 0) {
        foreach ($mainwidgets as $widget) {
            $guid = (int) $widget;
            if ("{$guid}" == "{$widget}") {
                $guids[1][] = $widget;
            } else {
                $handlers[1][] = $widget;
            }
        }
    }
    if (is_array($sidewidgets) && sizeof($sidewidgets) > 0) {
        foreach ($sidewidgets as $widget) {
            $guid = (int) $widget;
            if ("{$guid}" == "{$widget}") {
                $guids[2][] = $widget;
            } else {
                $handlers[2][] = $widget;
            }
        }
    }
    if (is_array($rightwidgets) && sizeof($rightwidgets) > 0) {
        foreach ($rightwidgets as $widget) {
            $guid = (int) $widget;
            if ("{$guid}" == "{$widget}") {
                $guids[3][] = $widget;
            } else {
                $handlers[3][] = $widget;
            }
        }
    }
    // Reorder existing widgets or delete ones that have vanished
    foreach (array(1, 2, 3) as $column) {
        if ($dbwidgets = get_widgets($owner, $context, $column)) {
            foreach ($dbwidgets as $dbwidget) {
                if (in_array($dbwidget->getGUID(), $guids[1]) || in_array($dbwidget->getGUID(), $guids[2]) || in_array($dbwidget->getGUID(), $guids[3])) {
                    if (in_array($dbwidget->getGUID(), $guids[1])) {
                        $pos = array_search($dbwidget->getGUID(), $guids[1]);
                        $col = 1;
                    } else {
                        if (in_array($dbwidget->getGUID(), $guids[2])) {
                            $pos = array_search($dbwidget->getGUID(), $guids[2]);
                            $col = 2;
                        } else {
                            $pos = array_search($dbwidget->getGUID(), $guids[3]);
                            $col = 3;
                        }
                    }
                    $pos = ($pos + 1) * 10;
                    $dbwidget->column = $col;
                    $dbwidget->order = $pos;
                } else {
                    $dbguid = $dbwidget->getGUID();
                    if (!$dbwidget->delete()) {
                        $return = false;
                    } else {
                        // Remove state cookie
                        $cookie = new ElggCookie("widget{$dbguid}");
                        $cookie->value = NULL;
                        elgg_set_cookie($cookie);
                    }
                }
            }
        }
        // Add new ones
        if (sizeof($guids[$column]) > 0) {
            foreach ($guids[$column] as $key => $guid) {
                if ($guid == 0) {
                    $pos = ($key + 1) * 10;
                    $handler = $handlers[$column][$key];
                    if (!add_widget($owner, $handler, $context, $pos, $column)) {
                        $return = false;
                    }
                }
            }
        }
    }
    return $return;
}
示例#4
0
文件: sessions.php 项目: nogsus/Elgg
/**
 * Log the current user out
 *
 * @return bool
 */
function logout()
{
    global $CONFIG;
    if (isset($_SESSION['user'])) {
        if (!elgg_trigger_event('logout', 'user', $_SESSION['user'])) {
            return false;
        }
        $_SESSION['user']->code = "";
        $_SESSION['user']->save();
    }
    unset($_SESSION['username']);
    unset($_SESSION['name']);
    unset($_SESSION['code']);
    unset($_SESSION['guid']);
    unset($_SESSION['id']);
    unset($_SESSION['user']);
    $cookie = new ElggCookie("elggperm");
    $cookie->setExpire("-30 days");
    $cookie->domain = "/";
    elgg_set_cookie($cookie);
    // pass along any messages
    $old_msg = $_SESSION['msg'];
    session_destroy();
    // starting a default session to store any post-logout messages.
    _elgg_session_boot(NULL, NULL, NULL);
    $_SESSION['msg'] = $old_msg;
    return TRUE;
}