<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 RemotesubscribeAction extends Action {
	
	function handle($args) {
		
		parent::handle($args);

		if (common_logged_in()) {
			common_user_error(_t('You can use the local subscription!'));
		    return;
		}

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			$this->remote_subscription();
		} else {
			$this->show_form();
		}
	}

	function show_form($err=NULL) {
		$nickname = $this->trimmed('nickname');
		common_show_header(_t('Remote subscribe'));
		if ($err) {
			common_element('div', 'error', $err);
		}
		common_element_start('form', array('id' => 'remotesubscribe', 'method' => 'POST',
										   'action' => common_local_url('remotesubscribe')));
		common_input('nickname', _t('User nickname'), $nickname);
		common_input('profile', _t('Profile URL'));
		common_submit('submit', _t('Subscribe'));
		common_element_end('form');
		common_show_footer();
	}
	
	function remote_subscription() {
		$user = $this->get_user();
		
		if (!$user) {
			$this->show_form(_t('No such user!'));
			return;
		}
		
		$profile = $this->trimmed('profile');
		
		if (!$profile) {
			$this->show_form(_t('No such user!'));
			return;
		}
		
		if (!Validate::uri($profile, array('allowed_schemes' => array('http', 'https')))) {
			$this->show_form(_t('Invalid profile URL (bad format)'));
			return;
		}
		
		$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
		$yadis = Auth_Yadis_Yadis::discover($profile, $fetcher);
		
		if (!$yadis) {
			$this->show_form(_t('Not a valid profile URL (no YADIS document).'));<commit_msg>check to see if XRDS discovery failed<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 RemotesubscribeAction extends Action {
	
	function handle($args) {
		
		parent::handle($args);

		if (common_logged_in()) {
			common_user_error(_t('You can use the local subscription!'));
		    return;
		}

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			$this->remote_subscription();
		} else {
			$this->show_form();
		}
	}

	function show_form($err=NULL) {
		$nickname = $this->trimmed('nickname');
		common_show_header(_t('Remote subscribe'));
		if ($err) {
			common_element('div', 'error', $err);
		}
		common_element_start('form', array('id' => 'remotesubscribe', 'method' => 'POST',
										   'action' => common_local_url('remotesubscribe')));
		common_input('nickname', _t('User nickname'), $nickname);
		common_input('profile', _t('Profile URL'));
		common_submit('submit', _t('Subscribe'));
		common_element_end('form');
		common_show_footer();
	}
	
	function remote_subscription() {
		$user = $this->get_user();
		
		if (!$user) {
			$this->show_form(_t('No such user!'));
			return;
		}
		
		$profile = $this->trimmed('profile');
		
		if (!$profile) {
			$this->show_form(_t('No such user!'));
			return;
		}
		
		if (!Validate::uri($profile, array('allowed_schemes' => array('http', 'https')))) {
			$this->show_form(_t('Invalid profile URL (bad format)'));
			return;
		}
		
		$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
		$yadis = Auth_Yadis_Yadis::discover($profile, $fetcher);
		
		if (!$yadis || $yadis->fail) {
			$this->show_form(_t('Not a valid profile URL (no YADIS document).'));
{'fraction_non_alphanumeric': 0.15376782077393075, 'fraction_numerical': 0.002443991853360489, 'mean_word_length': 4.292025862068965, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 32, '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': '785728', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1561, 'n_words': 434}