# -*- mode: perl; coding: utf-8 -*-
# keitairc/lib/plugins/20phone
# 電話番号

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

$plugin = {
	name => 'phone',

	message_replace_regexp => '\b(0\d{1,3})([-(]?)(\d{2,4})([-)]?)(\d{4})\b',
	message_replace_imprementation => sub {
		my ($request, $session_id, $p1, $p2, $p3, $p4, $p5) = @_;
		my $ci = new Keitairc::ClientInfo($request);
		if ($ci->is_webkit()) {
			# iPhone では ダイレクトに phone to にして、
			# アプリ側処理に任せる
			sprintf('<a target="_self" class="inline" href="tel:%s%s%s">%s%s%s%s%s</a>',
				$p1, $p3, $p5,
				$p1, $p2, $p3, $p4, $p5);
		} else {
			sprintf('<a target="_self" class="inline" href="%s%s/phone/%s%s%s">%s%s%s%s%s</a>',
				$::cf->web_root(),
				$session_id,
				$p1, $p3, $p5,
				$p1, $p2, $p3, $p4, $p5);
		}
	},

	action_imprementation => sub {
		my ($request, $name, $session_id, $param_string) = @_;
		my $ci = new Keitairc::ClientInfo($request);
		my $view = new Keitairc::View($::cf, $ci);
		return $view->render('phone.html', {
			session_id => $session_id,
			phone => $param_string
			     });
	}
};

1;
