Skip to content

Commit 770526e

Browse files
committed
[spalenque] - #12832 * add PublishDate to all Pages
1 parent 238c3b1 commit 770526e

10 files changed

Lines changed: 113 additions & 8 deletions

File tree

coa/code/ui/COALandingPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ protected function handleAction($request, $action)
358358
return parent::handleAction($request, $action);
359359
}
360360

361-
public function index(){
361+
public function index(SS_HTTPRequest $request){
362362
Requirements::css('coa/css/coa.css');
363363
Requirements::javascript('coa/js/coa.js');
364364

coa/code/ui/COAVerifyPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function init()
7272
Requirements::javascript('themes/openstack/bower_assets/sweetalert/dist/sweetalert.min.js');
7373
}
7474

75-
public function index(){
75+
public function index(SS_HTTPRequest $request){
7676

7777
return $this->getViewer('index')->process($this);
7878
}

marketplace/code/ui/admin/MarketPlaceAdminPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function init()
211211
}
212212

213213

214-
public function index()
214+
public function index(SS_HTTPRequest $request)
215215
{
216216
if ($this->canAdmin('implementations'))
217217
return $this->getViewer('index')->process($this);

openstack/_config/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ Injector:
2727

2828
Page:
2929
extensions:
30-
- 'PageOpenGraphObjectExtension'
30+
- PageOpenGraphObjectExtension
31+
- FuturePublishDate
32+
33+
Page_Controller:
34+
extensions:
35+
- FuturePublishDateController

openstack/code/Page.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,31 @@ public function init()
387387

388388
}
389389

390+
public function index(SS_HTTPRequest $request) {
391+
return $this->getViewer('index')->process($this);
392+
}
393+
394+
public function Menu($level) {
395+
$items = parent::Menu($level);
396+
397+
$isDraftPreview = 'Stage' === $this->request->getVar('stage');
398+
if ($isDraftPreview) {
399+
return $items;
400+
}
401+
402+
$now = strtotime('now');
403+
$visible = array();
404+
foreach ($items as $page) {
405+
if ($page->PublishDate && strtotime($page->PublishDate) <= $now) {
406+
$visible[] = $page;
407+
} elseif (!$page->PublishDate) {
408+
$visible[] = $page;
409+
}
410+
}
411+
412+
return new ArrayList($visible);
413+
}
414+
390415
public function LoginForm() {
391416

392417
$back_url = '';
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright 2016 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
16+
class FuturePublishDate extends DataExtension
17+
{
18+
private static $db = array(
19+
'PublishDate' => 'SS_DateTime'
20+
);
21+
22+
public function updateCMSFields(FieldList $fields) {
23+
$datetimeField = new DatetimeField( 'PublishDate', 'Publish From (UTC)' );
24+
25+
$dateField = $datetimeField->getDateField();
26+
$dateField->setConfig( 'dateformat', 'yyyy-MM-dd' );
27+
$dateField->setConfig( 'showcalendar', true );
28+
29+
$timeField = $datetimeField->getTimeField();
30+
$timeField->setConfig( 'timeformat', 'H:m:s' );
31+
32+
$fields->insertBefore( $datetimeField, 'Content' );
33+
}
34+
35+
public function populateDefaults() {
36+
$this->owner->PublishDate = SS_Datetime::now();
37+
}
38+
39+
public function onAfterWrite() {
40+
if ($this->owner->ClassName == 'RedirectorPage') {
41+
$page = $this->owner->LinkTo();
42+
$page->PublishDate = $this->owner->PublishDate;
43+
$page->write();
44+
}
45+
46+
parent::onAfterWrite();
47+
}
48+
49+
}
50+
51+
class FuturePublishDateController extends Extension
52+
{
53+
public function beforeCallActionHandler($request, $action) {
54+
if ('index' !== $action || $this->owner->is_a('ErrorPage_Controller')) {
55+
return;
56+
}
57+
58+
$isDraftPreview = 'Stage' === $request->getVar('stage');
59+
60+
if( !$isDraftPreview
61+
&& $this->owner->PublishDate
62+
&& strtotime($this->owner->PublishDate.' UTC') > time()
63+
){
64+
// bug in SS 3.1 in OldPageRedirector
65+
// $this->owner->httpError( 404 );
66+
67+
$response = $request->isMedia() ? null : ErrorPage::response_for(404);
68+
if ($response) {
69+
return $response;
70+
}
71+
72+
throw new SS_HTTPResponse_Exception('404 Not Found', 404);
73+
}
74+
}
75+
}

sangria/code/SangriaPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function init()
5555
self::$default_end_date = date('Y/m/d') . ' 23:59';
5656
}
5757

58-
public function index()
58+
public function index(SS_HTTPRequest $request)
5959
{
6060
$this->extend('onBeforeIndex', $this);
6161
return $this;

software/code/ui/SoftwareHomePage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function init()
110110
Requirements::javascript("software/js/software.js");
111111
}
112112

113-
public function index()
113+
public function index(SS_HTTPRequest $request)
114114
{
115115
$release = $this->getDefaultRelease();
116116
if(is_null($release)) return 'Default Release not set!';

summit/code/pages/SummitAppReviewPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function init()
3939

4040
}
4141

42-
public function index(){
42+
public function index(SS_HTTPRequest $request){
4343

4444
$member = Member::currentUser();
4545

summit/code/pages/SummitConfirmSpeakerPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function init()
4949
parent::init();
5050
}
5151

52-
public function index()
52+
public function index(SS_HTTPRequest $request)
5353
{
5454
$response = new SS_HTTPResponse;
5555
$response->setStatusCode(404);

0 commit comments

Comments
 (0)