4 use vars qw($title $body $bodyopts $head %GET %POST);
5 use LJ::Portal::Config;
7 my $disabled = $LJ::DISABLED{'portal'};
9 my $remote = LJ::get_remote();
11 if (ref $disabled eq "CODE") {
12 $disabled = $disabled->($remote);
17 $body = 'Sorry, the portal is disabled at this time.';
21 my $remote = LJ::get_remote;
23 $title = BML::ml('.pagetitle', { 'sitenameabbrev' => $LJ::SITENAMEABBREV });
27 # browser caching causes lots of issues
28 $head = '<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">';
32 $body = "<?needlogin?>";
38 BML::set_content_type('text/javascript; charset=utf-8');
44 # include the default style:
45 LJ::need_res('stc/portal/MainStyle.css');
47 LJ::need_res('stc/lj_base.css');
49 LJ::need_res('js/core.js');
50 LJ::need_res('js/dom.js');
51 LJ::need_res('js/hourglass.js');
52 LJ::need_res('js/x/x_core.js');
53 LJ::need_res('js/x/x_dom.js');
54 LJ::need_res('js/portal.js');
55 LJ::need_res('js/x/x_event.js');
56 LJ::need_res('js/commentmanage.js');
58 # get the current scheme and load the correct style
59 my $scheme = BML::get_scheme();
60 if ($scheme eq 'dystopia' && -e "$LJ::HOME/htdocs/stc/portal/Dystopia.css") {
61 LJ::need_res('stc/portal/Dystopia.css');
62 } elsif (-e "$LJ::HOME/htdocs/stc/portal/XColibur.css") {
63 LJ::need_res('stc/portal/XColibur.css');
66 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
68 # this is the url to do XML HTTP posts to
69 my $selflink = $LJ::SITEROOT . BML::get_uri();
70 $selflink =~ s/\?.*//;
72 # fading special effects?
73 my $doFadeDefault = 1;
74 my $doFade = $LJ::DISABLED{'portal_fade'} ? 0 : $doFadeDefault;
76 # parameters for portal.js
78 <script language="JavaScript">
82 Site.postUrl = "$selflink";
83 Site.doFade = $doFade;
89 $LJ::PORTAL_DEBUG_CONTENT = '';
91 # do profiling? requires siteadmin portal priv
92 my $profile = $GET{'profile'} + 0 && LJ::check_priv($remote, 'siteadmin', 'portal') ;
93 $profile = $profile > 9999999 ? 9999999 : $profile;
95 my $portalconfig = LJ::Portal::Config->new($remote, $profile);
96 return unless $portalconfig; # should never happen!
98 # if profiling, add debug box
99 $portalconfig->add_box('Debug', 'R') if $profile;
101 # see if there was a request to be handled by a module:
102 my $portalboxaction = ($POST{'portalboxaction'} || $GET{'portalboxaction'}) + 0;
103 my $actionbox = $portalconfig->get_box_by_id($portalboxaction);
105 # verify it's a action for a valid module
106 if ($portalboxaction && $actionbox && LJ::check_referer('/portal')) {
107 if ($actionbox->can('handle_request')) {
108 my $returncode = $actionbox->handle_request(\%GET, \%POST);
109 return $returnjs->($returncode) if $returncode;
111 # if it was a post then return update
112 my $updatescript = LJ::Portal->get_portal_box_update_script($portalconfig, $actionbox);
113 return $returnjs->($updatescript) if $POST{'portalboxaction'};
117 # super-secret add hidden module URL option:
118 if ($GET{'addmodule'}) {
119 my $module = $GET{'addmodule'};
121 LJ::Portal->addbox($portalconfig, $module, 'R');
124 # firstly process any box changes:
125 my @actions = ('addbox', 'configbox', 'delbox', 'getmenu', 'movebox',
126 'resetbox', 'saveconfig', 'updatebox', 'resetalldo');
130 # if a POST request then it was an XML HTTP request. Do processing and return
131 # to the client info.
132 # if it was a GET, then the client cannot do XML HTTP requests. Do processing
133 # and display the new page.
135 # did they do a POST or GET?
136 my $didpost = $POST{$_} ? 1 : undef;
137 my $didget = $GET{$_} ? 1 : undef;
140 if (($didget || $didpost) && LJ::check_referer('/portal')) {
141 # request to create a new box
142 if ($action eq 'addbox') {
143 my $boxtype = $POST{'boxtype'} || $GET{'boxtype'};
144 my $boxcol = $POST{'boxcol'} || $GET{'boxcol'};
146 my $returncode = LJ::Portal->addbox($portalconfig, $boxtype, $boxcol);
147 return $returnjs->($returncode) if $returncode && $didpost;
150 # request to get a dialog box for configuring box props
151 if ($action eq 'configbox') {
152 my $pboxid = ($POST{'pboxid'} || $GET{'pboxid'}) + 0;
153 my $jsmode = $POST{'jsmode'};
155 my ($returncode, $configboxhtml) = LJ::Portal->configbox($pboxid, $portalconfig, $jsmode);
157 if ($didget && $configboxhtml) {
158 # just print out the config box for non-JS people
159 my $box = $portalconfig->get_box_by_id($pboxid);
161 $title = "Configure " . $box->box_name;
162 $body = $configboxhtml;
163 my $returnlinktext = BML::ml('.returnlink',
164 { 'sitenameabbrev' => $LJ::SITENAMEABBREV });
165 $body .= "<div class='PortalReturn'><b><a href=\"$LJ::SITEROOT/portal\">$returnlinktext</a></b></div>";
168 $body = "Could not load box.";
173 return $returnjs->($returncode);
175 # request to move a box
176 if ($action eq 'movebox') {
177 my $pboxid = ($POST{'pboxid'} || $GET{'pboxid'})+ 0;
178 my $boxcol = $POST{'boxcol'} || $GET{'boxcol'};
179 my $boxcolpos = ($POST{'boxcolpos'} || $GET{'boxcolpos'}) + 0;
180 my $moveUp = $POST{'up'} || $GET{'up'};
181 my $moveDown = $POST{'down'} || $GET{'down'};
183 my $returncode = LJ::Portal->movebox($pboxid, $portalconfig, $boxcol,
184 $boxcolpos, $moveUp, $moveDown);
186 return $returnjs->($returncode) if $returncode && $didpost;
188 # request to retreive a config menu
189 if ($action eq 'getmenu') {
190 my $menu = $POST{'menu'} || $GET{'menu'};
192 my $returncode = LJ::Portal->getmenu($portalconfig, $menu);
195 return $returnjs->($returncode);
197 if ($menu eq 'addbox') {
198 $title = 'Add Module';
202 my $returnlinktext = BML::ml('.returnlink',
203 { 'sitenameabbrev' => $LJ::SITENAMEABBREV });
204 $body .= "<div class='PortalReturn'><b><a href=\"$LJ::SITEROOT/portal\">$returnlinktext</a></b></div>";
208 # reset default box settings
209 if ($action eq 'resetbox') {
210 my $pboxid = ($POST{'pboxid'} || $GET{'pboxid'}) + 0;
211 my $returncode = LJ::Portal->resetbox($pboxid, $portalconfig);
212 return $returnjs->($returncode) if $returncode && $didpost;
214 # request to save box props
216 if ($action eq 'saveconfig' && $didpost) {
217 my $pboxid = $POST{'pboxid'} + 0;
219 # was this submitted by an actual form instead of a XML
220 # HTTP request? if so then don't return XML.
221 my $realform = $POST{'realform'} + 0;
223 # there has got to be a better way to do this instead of passing POST
224 my $returncode = LJ::Portal->saveconfig($portalconfig, $pboxid, $realform, \%POST);
225 return $returnjs->($returncode) if !$realform;
227 # request to delete a box
228 if ($action eq 'delbox') {
229 my $pboxid = ($POST{'pboxid'} || $GET{'pboxid'}) + 0;
232 $returncode = LJ::Portal->delbox($portalconfig, $pboxid);
233 return $returnjs->($returncode) if $didpost && $returncode;
235 # request to get code to update the contents of a box
237 if ($action eq 'updatebox' && $didpost) {
238 my $pboxid = $POST{'pboxid'} + 0;
239 my $box = $portalconfig->get_box_by_id($pboxid);
241 return $returnjs->(LJ::Portal->get_portal_box_update_script($portalconfig, $box));
243 return $returnjs->('alert("Box not found.");');
246 # reset entire portal?
248 if ($action eq 'resetalldo' && $didpost && $POST{'resetyes'}) {
249 $portalconfig->reset_all;
251 # tell browser to reload now that everything's finished resetting
252 # (if we're using JS)
253 if ($POST{'jsmode'}) {
254 return $returnjs->( qq {
256 window.location.href = Site.postUrl;
261 # make sure we're at /portal/ because of referral checking
262 BML::redirect($selflink);
266 # create the hidden menu at the top
267 my $configmenu = qq {
268 <span id="PortalConfigMenuBar">
269 <div id="AddPortalMenuButton" class="midalign PortalMenuItem" onclick="return showAddPortalBoxMenu();">
270 <a href="$selflink?getmenu=1&menu=addbox" class="PortalMenuItem">Add Content Module</a></div>
274 # user pressed "reset all"
276 if ($POST{'resetall'}) {
277 my $returnlinktext = BML::ml('.returnlink',
278 { 'sitenameabbrev' => $LJ::SITENAMEABBREV });
279 $title = BML::ml('.resetalltitle', { 'sitenameabbrev' => $LJ::SITENAMEABBREV });
281 <p><?_ml .resetall _ml?></p>
282 <div class="standout">
283 <form action="$selflink" method="POST">
284 <input type="hidden" name="resetalldo" value="1" />
285 <input type="Submit" name="resetyes" value="Yes" />
286 <input type="Submit" name="resetno" value="No" />
289 <b><a href=\"$LJ::SITEROOT/portal\">$returnlinktext</a></b>
292 } elsif ($GET{'mode'} eq 'config') {
294 # the config page for non-JS users
295 my $returnlinktext = BML::ml('.returnlink',
296 { 'sitenameabbrev' => $LJ::SITENAMEABBREV });
297 $title = BML::ml('.configtitle', { 'sitenameabbrev' => $LJ::SITENAMEABBREV });
298 $body .= "<ul><li><a href=\"$selflink?getmenu=1&menu=addbox\"><?_ml .addbox _ml?></a></li></ul>";
299 $body .= "<b><a href=\"$LJ::SITEROOT/portal\">$returnlinktext</a></b>";
301 $body .= $configmenu;
303 $body .= '<div id="PortalContentContainer">';
305 # print out each column with boxes
307 map { $cols->{$_} = 1 if $_ } $portalconfig->get_cols;
309 foreach my $col (keys %$cols) {
312 my @colboxes = $portalconfig->get_col_boxes($col);
313 $body .= "<div id='PortalCol$col'>";
314 foreach my $box (@colboxes) {
317 # if it's the debug module, generate it last
318 if ($box->box_class eq 'Debug') {
323 # get the contents of the box
324 $body .= $portalconfig->generate_box_with_container($box->pboxid);
330 # print out columns that didn't have boxes so you can move boxes around
333 $body .= "<div id='PortalCol$_'></div>";
337 $body .= '<div class="clearing" /> </div></div>';
340 $body .= "<div style=\"z-index: 5; position: absolute; width: 80%; height: 300; overflow-Y: auto;\"> ";
341 my $debug = $portalconfig->generate_box_with_container($debugbox->pboxid);
346 %LJ::PORTAL_PROFILED_BOX = ();
350 #_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
355 title=><?_code return $title; _code?>
357 <?_c TODO: configurable meta tags could go here? _c?>
358 <?_code return $head; _code?>
359 <?_code return (! LJ::get_remote() &&
361 ! $LJ::REQ_HEAD_HAS{'chalresp_js'}++) ?
362 $LJ::COMMON_CODE{'chalresp_js'} : "";
365 bodyopts=><?_code return $bodyopts; _code?>
366 body=><?_code return $body; _code?>