]> git.uio.no Git - usit-rt.git/blame - lib/RT/URI/fsck_com_article.pm
Putting 4.2.0 on top of 4.0.17
[usit-rt.git] / lib / RT / URI / fsck_com_article.pm
CommitLineData
84fb5b46
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
403d7b0b 5# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
84fb5b46
MKG
6# <sales@bestpractical.com>
7#
8# (Except where explicitly superseded by other copyright notices)
9#
10#
11# LICENSE:
12#
13# This work is made available to you under the terms of Version 2 of
14# the GNU General Public License. A copy of that license should have
15# been provided with this software, but in any event can be snarfed
16# from www.gnu.org.
17#
18# This work is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21# General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26# 02110-1301 or visit their web page on the internet at
27# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28#
29#
30# CONTRIBUTION SUBMISSION POLICY:
31#
32# (The following paragraph is not intended to limit the rights granted
33# to you to modify and distribute this software under the terms of
34# the GNU General Public License and is only of importance to you if
35# you choose to contribute your changes and enhancements to the
36# community by submitting them to Best Practical Solutions, LLC.)
37#
38# By intentionally submitting any modifications, corrections or
39# derivatives to this work, or any other work intended for use with
40# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41# you are the copyright holder for those contributions and you grant
42# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43# royalty-free, perpetual, license to use, copy, create derivative
44# works based on those contributions, and sublicense and distribute
45# those contributions and any derivatives thereof.
46#
47# END BPS TAGGED BLOCK }}}
48
49package RT::URI::fsck_com_article;
50
51use strict;
52use warnings;
53no warnings 'redefine';
54
84fb5b46 55use base qw/RT::URI::base/;
af59614d 56use RT::Article;
84fb5b46
MKG
57
58=head2 LocalURIPrefix
59
60Returns the prefix for a local article URI
61
62=cut
63
64sub LocalURIPrefix {
65 my $self = shift;
66 my $prefix = $self->Scheme. "://". RT->Config->Get('Organization')
67 . "/article/";
68 return ($prefix);
69}
70
71=head2 URIForObject RT::article
72
73Returns the RT URI for a local RT::article object
74
75=cut
76
77sub URIForObject {
78
79 my $self = shift;
80
81 my $obj = shift;
82 return ($self->LocalURIPrefix. $obj->Id);
83}
84
85
86=head2 ParseObject $ArticleObj
87
88When handed an L<RT::Article> object, figure out its URI
89
90=cut
91
92=head2 ParseURI URI
93
94When handed an fsck.com-article URI, figures out things like whether its a local article
95and what its ID is
96
97=cut
98
99sub ParseURI {
100 my $self = shift;
101 my $uri = shift;
102
af59614d
MKG
103 my $article;
104
105 if ($uri =~ /^(\d+)$/) {
106 $article = RT::Article->new($self->CurrentUser);
107 $article->Load($uri);
108 $self->{'uri'} = $article->URI;
109 }
110 else {
111 $self->{'uri'} = $uri;
112 }
113
84fb5b46
MKG
114 #If it's a local URI, load the article object and return its URI
115 if ( $self->IsLocal) {
84fb5b46 116 my $local_uri_prefix = $self->LocalURIPrefix;
af59614d
MKG
117 if ($self->{'uri'} =~ /^$local_uri_prefix(\d+)$/) {
118 my $id = $1;
119 $article = RT::Article->new( $self->CurrentUser );
120 $article->Load($id);
121
122 #If we couldn't find a article, return undef.
123 unless ( defined $article->Id ) {
124 return undef;
125 }
126 } else {
127 return undef;
128 }
84fb5b46 129 }
af59614d
MKG
130
131 $self->{'object'} = $article;
132 return ($article->Id);
84fb5b46
MKG
133}
134
135=head2 IsLocal
136
137Returns true if this URI is for a local article.
138Returns undef otherwise.
139
140=cut
141
142sub IsLocal {
af59614d
MKG
143 my $self = shift;
144 my $local_uri_prefix = $self->LocalURIPrefix;
145 if ($self->{'uri'} =~ /^$local_uri_prefix/) {
146 return 1;
147 }
148 else {
149 return undef;
84fb5b46 150 }
84fb5b46
MKG
151}
152
153
154
155=head2 Object
156
157Returns the object for this URI, if it's local. Otherwise returns undef.
158
159=cut
160
161sub Object {
162 my $self = shift;
163 return ($self->{'object'});
164
165}
166
167=head2 Scheme
168
169Return the URI scheme for RT articles
170
171=cut
172
173sub Scheme {
174 my $self = shift;
af59614d 175 return "fsck.com-article";
84fb5b46
MKG
176}
177
178=head2 HREF
179
180If this is a local article, return an HTTP url to it.
181Otherwise, return its URI
182
183=cut
184
185sub HREF {
186 my $self = shift;
187 if ($self->IsLocal && $self->Object) {
b5747ff2 188 return ( RT->Config->Get('WebURL') . "Articles/Article/Display.html?id=".$self->Object->Id);
84fb5b46
MKG
189 }
190 else {
191 return ($self->URI);
192 }
193}
194
195=head2 AsString
196
197Return "Article 23"
198
199=cut
200
201sub AsString {
202 my $self = shift;
af59614d
MKG
203 if ($self->IsLocal && ( my $object = $self->Object )) {
204 if ( $object->Name ) {
205 return $self->loc('Article #[_1]: [_2]', $object->id, $object->Name);
206 } else {
207 return $self->loc('Article #[_1]', $object->id);
208 }
84fb5b46
MKG
209 } else {
210 return $self->SUPER::AsString(@_);
211 }
212
213}
214
215
2161;