Пример #1
0
function oauth_upload($comment, $data)
{
    global $messages, $error;
    if (!isset($_SESSION['osm_token']) || !isset($_SESSION['osm_secret'])) {
        $error = _('OAuth token was lost, please relogin.');
        oauth_logout();
        return false;
    }
    try {
        $stage = 'login';
        $oauth = new OAuth(CLIENT_ID, CLIENT_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
        $oauth->setToken($_SESSION['osm_token'], $_SESSION['osm_secret']);
        $change_data = create_changeset($data, $comment);
        $xml_content = array('Content-Type' => 'application/xml');
        $stage = 'create';
        // note: this call works instead of returning 401 because of $xml_content
        $oauth->fetch(OSM_API_URL . 'changeset/create', $change_data, OAUTH_HTTP_METHOD_PUT, $xml_content);
        if (!preg_match('/\\d+/', $oauth->getLastResponse(), $m)) {
            $error = _('Could not aquire changeset id for a new changeset.');
            return false;
        }
        $changeset = $m[0];
        $osc = create_osc($data, $changeset);
        $stage = 'upload';
        $oauth->fetch(OSM_API_URL . 'changeset/' . $changeset . '/upload', $osc, OAUTH_HTTP_METHOD_POST, $xml_content);
        // todo: parse response and renumber created objects?
        $stage = 'close';
        $oauth->fetch(OSM_API_URL . 'changeset/' . $changeset . '/close', array(), OAUTH_HTTP_METHOD_PUT);
        $chlink = '<a href="https://www.openstreetmap.org/changeset/' . $changeset . '" target="_blank">' . $changeset . '</a>';
        // todo: replace %d with %s and $chlink, removing str_replace
        $messages[] = '!' . str_replace($changeset, $chlink, sprintf(_('Changeset %d was uploaded successfully.'), $changeset));
        return true;
    } catch (OAuthException $E) {
        if ($stage == 'upload' && $E->getCode() == 409) {
            $error = sprintf(_('Conflict while uploading changeset %d: %s.'), $changeset, $oauth->getLastResponse());
            // todo: process conflict
            // http://wiki.openstreetmap.org/wiki/API_0.6#Error_codes_9
        } else {
            print_r($E);
            $msg = $oauth->getLastResponse();
            $error = sprintf(_('OAuth error %d at stage "%s": %s.'), $E->getCode(), $stage, $msg ? $msg : $E->getMessage());
        }
    }
    return false;
}
Пример #2
0
 /**
  * 退出登录
  */
 public function outAction()
 {
     $oauthconfig = $this->loadOauth();
     if ($oauthconfig) {
         oauth_logout();
     }
     if ($this->session->is_set('member_id')) {
         $this->session->unset_userdata('member_id');
     }
     if ($this->session->is_set('oauth_openid')) {
         $this->session->unset_userdata('oauth_openid');
     }
     if ($this->session->is_set('oauth_name')) {
         $this->session->unset_userdata('oauth_name');
     }
     if (get_cookie('member_id')) {
         set_cookie('member_id', 0);
     }
     if (get_cookie('member_code')) {
         set_cookie('member_code', 0);
     }
     $this->memberMsg(lang('m-log-11') . ($this->memberconfig['uc_use'] == 1 ? uc_user_synlogout() : ''), SITE_URL, 1);
 }
Пример #3
0
parse_text($text);
// Now process actions
if ($action == 'login' || isset($_REQUEST['login'])) {
    if ($loggedin) {
        $error = _('Yor are already logged in.');
    } else {
        if (count($userdata) || count($basedata)) {
            $_SESSION['l0id'] = $l0id;
            store_user($text);
        }
        oauth_login();
    }
} elseif ($action == 'callback') {
    oauth_callback();
} elseif ($action == 'logout' || isset($_REQUEST['logout'])) {
    oauth_logout();
    $loggedin = false;
} elseif (isset($_REQUEST['add']) || isset($_REQUEST['replace']) || isset($_REQUEST['url']) && strlen($_REQUEST['url']) > 0) {
    if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
        if ($_FILES['file']['error'] > 0) {
            $errors = array('OK', _('too big'), _('bigger than MAX_FILE_SIZE'), _('partial upload'), _('no file'), '', _('nowhere to store'), _('failed to write'), _('extension error'));
            $error = sprintf(_('Error uploading file: %s.'), $errors[$_FILES['file']['error']]);
        } else {
            $url = $_FILES['file']['tmp_name'];
        }
    } elseif (isset($_REQUEST['url']) && strlen($_REQUEST['url']) > 0) {
        $url = url_to_api($_REQUEST['url']);
        if ($url === false) {
            $error = _('Could not parse the URL.');
        }
    } else {