/
HomePagePlugin.pm
131 lines (99 loc) · 3.95 KB
/
HomePagePlugin.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
=pod
---+ package Foswiki::Plugins::HomePagePlugin
=cut
package Foswiki::Plugins::HomePagePlugin;
use strict;
use warnings;
use Foswiki::Func ();
use Foswiki::Plugins ();
our $VERSION = '1.23';
our $RELEASE = '1.23';
our $SHORTDESCRIPTION = 'Allow User specified home pages - on login';
our $NO_PREFS_IN_TOPIC = 1;
sub initPlugin {
#my ( $topic, $web, $user, $installWeb ) = @_;
return 1;
}
sub initializeUserHandler {
my ( $loginName, $url, $pathInfo ) = @_;
return
unless ( $Foswiki::Plugins::SESSION->inContext('view')
|| $Foswiki::Plugins::SESSION->inContext('login') );
return
if ( $Foswiki::Plugins::SESSION->inContext('command_line') );
# Don't override web/topic if specified by url param.
return
if ( $Foswiki::Plugins::SESSION->{request}->param('defaultweb')
|| $Foswiki::Plugins::SESSION->{request}->param('topic') );
my $gotoOnLogin =
( $Foswiki::cfg{HomePagePlugin}{GotoHomePageOnLogin}
and $Foswiki::Plugins::SESSION->inContext('login') );
if ($gotoOnLogin) {
my $test = $Foswiki::Plugins::SESSION->{request}->param('username');
$loginName = $test if defined($test);
# pre-load the origurl with the 'login' url which forces
# templatelogin to use the requested web&topic
$Foswiki::Plugins::SESSION->{request}->param(
-name => 'origurl',
-value => $Foswiki::Plugins::SESSION->{request}->url()
);
}
# we don't know the user at this point so can only set up the
# site wide default
my $path_info =
Foswiki::urlDecode( $Foswiki::Plugins::SESSION->{request}->path_info() );
return
unless ( ( $path_info eq '' or $path_info eq '/' )
or ($gotoOnLogin) );
my $siteDefault = $Foswiki::cfg{HomePagePlugin}{SiteDefaultTopic};
#$Foswiki::cfg{HomePagePlugin}{HostnameMapping}
my $hostName = lc( Foswiki::Func::getUrlHost() );
if (
defined( $Foswiki::cfg{HomePagePlugin}{HostnameMapping}->{$hostName} ) )
{
$siteDefault =
$Foswiki::cfg{HomePagePlugin}{HostnameMapping}->{$hostName};
}
my $wikiName = Foswiki::Func::getWikiName($loginName);
if ( ( defined $wikiName )
and
Foswiki::Func::topicExists( $Foswiki::cfg{UsersWebName}, $wikiName ) )
{
my ( $meta, $text ) =
Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, $wikiName );
# TODO: make fieldname a setting.
my $field = $meta->get( 'FIELD', 'HomePage' );
my $userHomePage;
$userHomePage = $field->{value} if ( defined($field) );
$siteDefault = $userHomePage
if ( $userHomePage and ( $userHomePage ne '' ) );
}
if ( Foswiki::Func::webExists($siteDefault) ) {
# if they only set a webname, dwim
$siteDefault .= '.' . $Foswiki::cfg{HomeTopicName};
}
return unless defined $siteDefault;
my ( $web, $topic ) =
$Foswiki::Plugins::SESSION->normalizeWebTopicName( '', $siteDefault );
if ( Foswiki::Func::isValidWebName($web)
&& Foswiki::Func::isValidTopicName( $topic, 1 ) )
{
$Foswiki::Plugins::SESSION->{webName} = $web;
$Foswiki::Plugins::SESSION->{topicName} = $topic;
}
return;
}
1;
__END__
Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (c) 2009-2011 Sven Dowideit, SvenDowideit@fosiki.com
Copyright (c) 2012-2015 Foswiki Contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU 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 General Public License for more details, published at
http://www.gnu.org/copyleft/gpl.html