<commit_before><?php
/*
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2008, Controlez-Vous, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

if (!defined('LACONICA')) { exit(1); }

require_once(INSTALLDIR.'/lib/omb.php');
require_once('Auth/Yadis/Yadis.php');

class FinishremotesubscribeAction extends Action {
	
	function handle($args) {
		
		parent::handle($args);

		if (common_logged_in()) {
			common_user_error(_t('You can use the local subscription!'));
		    return;
		}
		
		$omb = $_SESSION['oauth_authorization_request'];
		
		if (!$omb) {
			common_user_error(_t('Not expecting this response!'));
			return;
		}

		$req = OAuthRequest::from_request();

		$token = $req->get_parameter('oauth_token');

		# I think this is the success metric
		
		if ($token != $omb['token']) {
			common_user_error(_t('Not authorized.'));
			return;
		}
		
		$version = $req->get_parameter('omb_version');
		
		if ($version != OMB_VERSION_01) {
			common_user_error(_t('Unknown version of OMB protocol.'));
			return;
		}
		
		$nickname = $req->get_parameter('omb_listener_nickname');
		
		if (!$nickname) {
			common_user_error(_t('No nickname provided by remote server.'));
			return;
		}

		$profile_url = $req->get_parameter('omb_listener_profile');
		
		if (!$profile_url) {
			common_user_error(_t('No profile URL returned by server.'));
			return;
		}

		if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) {
			common_user_error(_t('Invalid profile URL returned by server.'));
			return;
		}

		$user = User::staticGet('uri', $omb['listenee']);
		
		if (!$user) {
			common_user_error(_t('User being listened to doesn\'t exist.'));
			return;
		}
		
		$fullname = $req->get_parameter('omb_listener_fullname');
		$homepage = $req->get_parameter('omb_listener_homepage');
		$bio = $req->get_parameter('omb_listener_bio');
		$location = $req->get_parameter('omb_listener_location');
		$avatar_url = $req->get_parameter('omb_listener_avatar');

		list($newtok, $newsecret) = $this->access_token($omb);
		
		if (!$newtok || !$newsecret) {
			common_user_error(_t('Couldn\'t convert request tokens to access tokens.'));<commit_msg>debugging info on finished remote subscribe<commit_after><?php
/*
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2008, Controlez-Vous, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

if (!defined('LACONICA')) { exit(1); }

require_once(INSTALLDIR.'/lib/omb.php');
require_once('Auth/Yadis/Yadis.php');

class FinishremotesubscribeAction extends Action {
	
	function handle($args) {
		
		parent::handle($args);

		if (common_logged_in()) {
			common_user_error(_t('You can use the local subscription!'));
		    return;
		}
		
		$omb = $_SESSION['oauth_authorization_request'];
		
		if (!$omb) {
			common_user_error(_t('Not expecting this response!'));
			return;
		}

		common_debug('stored request: '.print_r($omb,true), __FILE__);
		
		$req = OAuthRequest::from_request();

		$token = $req->get_parameter('oauth_token');

		# I think this is the success metric
		
		if ($token != $omb['token']) {
			common_user_error(_t('Not authorized.'));
			return;
		}
		
		$version = $req->get_parameter('omb_version');
		
		if ($version != OMB_VERSION_01) {
			common_user_error(_t('Unknown version of OMB protocol.'));
			return;
		}
		
		$nickname = $req->get_parameter('omb_listener_nickname');
		
		if (!$nickname) {
			common_user_error(_t('No nickname provided by remote server.'));
			return;
		}

		$profile_url = $req->get_parameter('omb_listener_profile');
		
		if (!$profile_url) {
			common_user_error(_t('No profile URL returned by server.'));
			return;
		}

		if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) {
			common_user_error(_t('Invalid profile URL returned by server.'));
			return;
		}

		common_debug('listenee: "'.$omb['listenee'].'"', __FILE__);
		
		$user = User::staticGet('uri', $omb['listenee']);
		
		if (!$user) {
			common_user_error(_t('User being listened to doesn\'t exist.'));
			return;
		}
		
		$fullname = $req->get_parameter('omb_listener_fullname');
		$homepage = $req->get_parameter('omb_listener_homepage');
		$bio = $req->get_parameter('omb_listener_bio');
		$location = $req->get_parameter('omb_listener_location');
		$avatar_url = $req->get_parameter('omb_listener_avatar');

		list($newtok, $newsecret) = $this->access_token($omb);
		
		if (!$newtok || !$newsecret) {
			common_user_error(_t('Couldn\'t convert request tokens to access tokens.'));
{'fraction_non_alphanumeric': 0.1411602685488036, 'fraction_numerical': 0.002754346703391289, 'mean_word_length': 4.37962962962963, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '951306', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1788, 'n_words': 493}