コード例 #1
0
ファイル: tp-author.php プロジェクト: nataliepo/Claire
 function Author($params)
 {
     // Allow creationg of empty Author to allow
     // other services to override it.
     if (!array_key_exists('xid', $params) && !array_key_exists('json', $params) && !array_key_exists('username', $params)) {
         return;
     }
     $identifier = array();
     // otherwise, remember the unique identifier for this user.
     if (array_key_exists('xid', $params)) {
         $identifier['value'] = $params['xid'];
         $identifier['source'] = 'xid';
     } else {
         if (array_key_exists('json', $params)) {
             $identfier['value'] = $params['json']->urlId;
             $identifier['source'] = 'json';
         } else {
             $identifier['value'] = $params['username'];
             $identifier['source'] = 'username';
         }
     }
     if (!array_key_exists('json', $params)) {
         $params['json'] = pull_json(get_author_api_url($identifier['value']));
     }
     // in case the API request couldn't find that user, return.
     if (!$params['json']) {
         debug("[Author::Author] The user identified by " . $identifier['source'] . "'" . $identifier['value'] . "' was not found.");
         return;
     }
     // At this point, we should have valid JSON.
     $this->xid = $params['json']->urlId;
     $this->display_name = $params['json']->displayName;
     $this->profile_url = $params['json']->profilePageUrl;
     $this->username = $params['json']->preferredUsername;
     $this->avatar = get_resized_avatar($params['json'], 35);
 }
コード例 #2
0
ファイル: tp-oauth.php プロジェクト: nataliepo/Claire
 function update_author_record()
 {
     // Throw the extra 1 as a parameter since this is an authorized request.
     $typepad_url = get_author_api_url('@self', 1);
     $response = $this->make_authorized_request($typepad_url);
     $this->author = new Author(array('json' => $response));
     // this writes the Author record to the db.
     $oauth_user_id = remember_author($this->author);
     // Also create a cookie out of this author if one does not already exist.
     if (!array_key_exists(COOKIE_NAME, $_COOKIE)) {
         //setcookie(COOKIE_NAME, $oauth_user_id);
         setcookie(COOKIE_NAME, get_session_id_from_user_id($oauth_user_id));
     }
     // this is important for other services using this obj...
     $this->user_id = $oauth_user_id;
     // When you begin the sign-on process, you're given a temporary user record
     // without its TypePad XID -- even if you already existed.  This block
     // makes the temporary request/access token your actual request/access tokens.
     if (get_user_id_from_session_id($_COOKIE[COOKIE_NAME]) != $oauth_user_id && $oauth_user_id) {
         // store the temporary user_id
         $old_oauth_id = get_user_id_from_session_id($_COOKIE[COOKIE_NAME]);
         debug("Replacing temporary oauth_oauthor credentials...");
         // Update the OAuth table to user our author lookup.
         replace_oauth_author($old_oauth_id, $oauth_user_id);
         // Correct your active cookie.
         debug("Setting active cookie...");
         $session_id = get_session_id_from_user_id($oauth_user_id);
         debug("[update_author_record] session_id={$session_id} when user_id = {$oauth_user_id}");
         setcookie(COOKIE_NAME, get_session_id_from_user_id($oauth_user_id));
         // Remove the temporary user.
         debug("Removing temporary author record...");
         delete_author($old_oauth_id);
     }
 }