# -*- mode: perl; coding: utf-8 -*-
# keitairc/lib/plugins/10url
# URL処理

# The line number (1 incremented) and filename below must be
# actual. see perlsyn.
# line 10 "keitairc/lib/plugins/10url"

$plugin = {
	name => 'url',

	message_replace_regexp => '\b(https?://[/!-;=-\177]+|www\.[/!-\177]+)',
	message_replace_imprementation => sub {
		my ($request, $session_id, $param) = @_;
		my $ci = new Keitairc::ClientInfo($request);
		my $url = $param =~ m/^http/ ? $param : 'http://' . $param;
		if ($ci->is_webkit) {
		    return sprintf('<a target="_blank" class="inline" onTouchStart="restore_original(this);" onClick="noreferrer(this);true;" o_href="%s" href="%s">%s</a>',
				   $url, $url, $param);
		} else {
		    return sprintf('<a target="_self" class="inline" href="%s%s/url/%s">%s</a>',
				   $::cf->web_root(),
				   $session_id, $url, $param);
		}
	},

	action_imprementation => sub {
		my ($request, $name, $session_id, $param) = @_;
		my $ci = new Keitairc::ClientInfo($request);
		my $view = new Keitairc::View($::cf, $ci);
		return $view->render('url.html', {
			url => $param,
			session_id => $session_id,
			escaped_url => URI::Escape::uri_escape($param),
			     });
	}
};

1;
