1###############################################################################
2#
3# <p>���ꤷ���ڡ������⤷���ϻ���ڡ����λ���ѥ饰��դ����롼�ɤ��ޤ���</p>
4# <p>
5#   �ڡ������Τ����롼�ɤ�����ϰ����˥ڡ���̾����ꤷ�ޤ���
6# </p>
7# <pre>
8# {{include �ڡ���̾}}
9# </pre>
10# <p>
11#   ����ڡ���������Υѥ饰��դ����롼�ɤ������
12#   �ڡ���̾��³�����裲�����˥ѥ饰���̾����ꤷ�ޤ���
13# </p>
14# <pre>
15# {{include �ڡ���̾,�ѥ饰���̾}}
16# </pre>
17#
18###############################################################################
19package plugin::core::Include;
20use strict;
21#==============================================================================
22# �����ȥ饯��
23#==============================================================================
24sub new {
25	my $class = shift;
26	my $self = {};
27	return bless $self,$class;
28}
29
30#==============================================================================
31# �ѥ饰��մؿ�
32#==============================================================================
33sub paragraph {
34	my $self   = shift;
35	my $wiki   = shift;
36	my $page   = shift;
37	my $para   = shift;
38	my $cgi    = $wiki->get_CGI;
39
40	# ���顼�����å�
41	if($self->{count}++ > 50){
42		return &Util::paragraph_error("include�ץ饰����¿�����ޤ���","WIKI");
43	}
44	if($page eq ""){
45		return &Util::paragraph_error("�ڡ��������ꤵ��Ƥ��ޤ���","WIKI");
46	}
47	if(!$wiki->page_exists($page)){
48		return &Util::paragraph_error("�ڡ�����¸�ߤ��ޤ���","WIKI");
49	}
50	if(!$wiki->can_show($page)){
51		return &Util::paragraph_error("�ڡ����λ��ȸ��¤�����ޤ���","WIKI");
52	}
53	if($page eq $cgi->param("page")){
54		return &Util::paragraph_error("Ʊ��Υڡ�����include�Ǥ��ޤ���","WIKI");
55	}
56	foreach my $incpage (@{$self->{stack}}){
57		if($incpage eq $page){
58			return &Util::paragraph_error("Ʊ��Υڡ�����include�Ǥ��ޤ���","WIKI");
59		}
60	}
61
62	# �����������
63	my $source = $wiki->get_page($page);
64
65	# �ѥ饰��դ����ꤵ��Ƥ������ϥѥ饰��դ��ڤ�Ф�
66	$para = quotemeta(Util::trim($para));
67	if($para ne ""){
68		if($source =~ /(\n|^)!!!\s*$para\s*(\n!!!|$)/){
69			return &Util::paragraph_error("�ѥ饰��դ���ʸ��¸�ߤ��ޤ���","WIKI");
70		} elsif($source =~ /(\n|^)!!!\s*$para\s*\n((.|\s|\r|\n)*?)\s*(\n!!!|$)/){
71			$source = $2;
72		} elsif($source =~ /(\n|^)!!\s*$para\s*(\n!!|$)/){
73			return &Util::paragraph_error("�ѥ饰��դ���ʸ��¸�ߤ��ޤ���","WIKI");
74		} elsif($source =~ /(\n|^)!!\s*$para\s*\n((.|\s|\r|\n)*?)\s*(\n!!|$)/){
75			$source = $2;
76		} elsif($source =~ /(\n|^)!\s*$para\s*(\n!|$)/){
77			return &Util::paragraph_error("�ѥ饰��դ���ʸ��¸�ߤ��ޤ���","WIKI");
78		} elsif($source =~ /(\n|^)!\s*$para\s*\n((.|\s|\r|\n)*?)\s*(\n!|$)/){
79			$source = $2;
80		} else {
81			return &Util::paragraph_error("�ڡ�����¸�ߤ��ޤ���","WIKI");
82		}
83	}
84
85	# �����å��ˤĤ��̵�¥롼���ɻ��ѡ�
86	push(@{$self->{stack}},$page);
87
88	# ����ä�΢��
89	my $pagetmp = $cgi->param("page");
90	$cgi->param("page",$page);
91	$self->{parser}->parse($source);
92	$cgi->param("page",$pagetmp);
93
94	# �����������
95	pop(@{$self->{stack}});
96
97	return undef;
98}
99
1001;
101