forked from OpenStackweb/openstack-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomePage.php
More file actions
325 lines (271 loc) · 11.7 KB
/
Copy pathHomePage.php
File metadata and controls
325 lines (271 loc) · 11.7 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php
/**
* Copyright 2014 Openstack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* testing
**/
/**
* Defines the HomePage page type
*/
class HomePage extends Page
{
static $db = array(
'FeedData' => 'HTMLText',
'EventDate' => 'Date',
'VideoCurrentlyPlaying' => 'Text',
'PromoIntroMessage' => 'Text',
'PromoButtonText' => 'Text',
'PromoButtonUrl' => 'Text',
"PromoDatesText" => 'Text',
"PromoHeroCredit" => 'Text',
"PromoHeroCreditUrl" => 'Text',
"SummitMode" => 'Boolean',
"NextPresentationStartTime" => 'HTMLText',
"NextPresentationStartDate" => 'Text',
"LiveStreamURL" => 'Text'
);
private static $has_one = array(
'PromoImage' => 'BetterImage',
);
function getCMSFields()
{
$fields = parent::getCMSFields();
// Summit Video Stream
$VideoLiveField = new OptionSetField('VideoCurrentlyPlaying', 'Is the video live streaming at the moment?', array(
'Yes' => 'Video is being streamed.',
'No' => 'No video playing.'
));
$fields->addFieldToTab("Root.Main", new TextField('LiveStreamURL', 'URL of Live Stream Feed'));
$SummitModeField = new OptionSetField('SummitMode', 'Homepage mode:', array(
0 => 'Normal Mode',
1 => 'Summit Mode'
));
$fields->addFieldToTab("Root.Main", new TextField('NextPresentationStartTime', 'Next Presentation Start Time'));
$fields->addFieldToTab("Root.Main", new TextField('NextPresentationStartDate', 'Next Presentation Start Date'));
$fields->addFieldToTab("Root.Main", $VideoLiveField, 'Content');
$fields->addFieldToTab("Root.Main", $SummitModeField, 'Content');
// Countdown Date
$EventStartDate = new DateField('EventDate', 'First Day of Event (for counting down)');
$EventStartDate->setConfig('showcalendar', true);
$EventStartDate->setConfig('showdropdown', true);
$fields->addFieldToTab('Root.Main', $EventStartDate, 'Content');
// remove unneeded fields
$fields->removeFieldFromTab("Root.Main", "Content");
$promo_hero_image = new CustomUploadField('PromoImage', 'Promo Hero Image');
$promo_hero_image->setFolderName('homepage');
$promo_hero_image->setAllowedFileCategories('image');
$fields->addFieldToTab("Root.IntroHeader", $promo_hero_image);
$fields->addFieldToTab("Root.IntroHeader", new TextareaField('PromoIntroMessage', 'Promo Intro Message'));
$fields->addFieldToTab("Root.IntroHeader", new TextareaField('PromoButtonText', 'Promo Button Text'));
$fields->addFieldToTab("Root.IntroHeader", new TextareaField('PromoButtonUrl', 'Promo Button Url'));
$fields->addFieldToTab("Root.IntroHeader", new TextareaField('PromoDatesText', 'Promo Dates Text'));
$fields->addFieldToTab("Root.IntroHeader", new TextareaField('PromoHeroCredit', 'Hero Credit'));
$fields->addFieldToTab("Root.IntroHeader", new TextareaField('PromoHeroCreditUrl', 'Hero Credit Url'));
return $fields;
}
public function getHeroImageUrl(){
$image = $this->PromoImage();
if(!is_null($image) && $image->exists())
return $image->Link();
return '/assets/homepage/homepage-parissummit.png';
}
public function getPromoIntroMessage(){
$value = $this->getField('PromoIntroMessage');
return !empty($value)? $value : self::PromoIntroMessageDefault;
}
public function getPromoButtonText(){
$value = $this->getField('PromoButtonText');
return !empty($value)? $value : self::PromoButtonTextDefault;
}
public function getPromoButtonUrl(){
$value = $this->getField('PromoButtonUrl');
return !empty($value)? $value : self::PromoButtonUrlDefault;
}
public function getPromoDatesText(){
$value = $this->getField('PromoDatesText');
return !empty($value)? $value : self::PromoDatesTextDefault;
}
public function getPromoHeroCredit(){
$value = $this->getField('PromoHeroCredit');
return !empty($value)? $value : self::PromoHeroCreditDefault;
}
public function getPromoHeroCreditUrl(){
$value = $this->getField('PromoHeroCreditUrl');
return !empty($value)? $value : self::PromoHeroCreditUrlDefault;
}
const PromoIntroMessageDefault = '"OpenStack has a true community around it."';
const PromoButtonTextDefault = 'See how @WalmartLabs puts 100,000 cores to work';
const PromoButtonUrlDefault = 'http://awe.sm/jM31y';
const PromoDatesTextDefault = '...we plan to contribute aggressively to the open source community.';
const PromoHeroCreditDefault = 'Photo by Claire Massey';
const PromoHeroCreditUrlDefault = 'https://www.flickr.com/groups/1574695@N22/';
}
class HomePage_Controller extends Page_Controller
{
static $allowed_actions = array(
'Video',
'LatestNews',
'handleIndex'
);
static $url_handlers = array(
'' => 'handleIndex',
);
// checks to see if the hompeage is in summit mode (if so, changes template used)
public function handleIndex(){
$getVars = $this->request->getVars();
// turn the video on if set in a URL parameter
if(isset($getVars['video'])) $this->VideoCurrentlyPlaying = 'Yes';
if ($this->SummitMode == TRUE || isset($getVars['summit'])) {
return $this->renderWith(array('HomePage_Summit', 'HomePage', 'Page'));
} else {
return $this;
}
}
function init()
{
parent::init();
// Set default currency unless this is a returning visitor
$VisitorCookie = new Cookie;
if (!$VisitorCookie->get('ReturningVisitor')) {
$VisitorCookie->set('ReturningVisitor', TRUE);
}
}
/**
* @param string $url
* @param int $expiry
* @param null $collection
* @param null $element
* @return ArrayList
*/
private function queryExternalSource($url, $expiry=3600, $collection = NULL, $element = NULL){
$output = new ArrayList();
try {
$feed = new RestfulService($url, $expiry);
$response = $feed->request();
if ($response->getStatusCode() == 200) {
$body = $response->getBody();
$output = $feed->getValues($body, $collection, $element);
}
}
catch(Exception $ex){
SS_Log::log($ex, SS_Log::WARN);
}
return $output;
}
function UpcomingEvents($limit = 1)
{
$events_array = new ArrayList();
Versioned::reading_stage('Live');
$pulled_events = EventPage::get()->where("EventEndDate >= now()")->sort('EventStartDate', 'ASC')->limit($limit)->toArray();
$events_array->merge($pulled_events);
$output = '';
$events = $events_array->sort('EventStartDate', 'ASC')->limit($limit,0)->toArray();
if ($events) {
foreach ($events as $key => $event) {
$first = ($key == 0);
$data = array('IsEmpty' => 0, 'IsFirst' => $first);
$output .= $event->renderWith('EventHolder_event', $data);
}
} else {
$data = array('IsEmpty' => 1);
$event = new EventPage();
$output .= $event->renderWith('EventHolder_event', $data);
}
return $output;
}
function DisplayVideo()
{
$getVars = $this->request->getVars();
return ($this->VideoCurrentlyPlaying == 'Yes' || isset($getVars['video']));
}
function Video()
{
//Detect special conditions devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'], "iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'], "iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'], "iPad");
//do something with this information
if ($iPod || $iPhone || $iPad) {
$this->redirect('http://itechsherpalive2.live-s.cdn.bitgravity.com/cdn-live-s1/_definst_/itechsherpalive2/live/OSS13/playlist.m3u8');
} else {
return $this->renderWith(array('HomePage_Video', 'HomePage', 'Page'));
}
}
function NewsItems($limit = 20)
{
$news_repository = new SapphireNewsRepository();
$repository = new SapphireRssNewsRepository();
$tx_manager = SapphireTransactionManager::getInstance();
$rss_news_manager = new RssNewsManager(
$repository,
$tx_manager
);
$return_array = new ArrayList();
$group_array = $rss_news_manager->getNewsItemsFromDatabaseGroupedByCategory();
if(isset($group_array[RssNews::SuperUser])) {
for ($i = 0; $i < 7 && $i < count($group_array[RssNews::SuperUser]); $i++) {
$item = $group_array[RssNews::SuperUser][$i];
$return_array->push(array(
'type' => $item->Category,
'link' => $item->Link,
'title' => $item->Headline,
'pubdate' => date('D, M jS Y', strtotime($item->Date)),
'rawpubdate' => $item->Date
));
}
}
if(isset($group_array[RssNews::Planet])) {
for ($i = 0; $i < 3 && $i < count($group_array[RssNews::Planet]); $i++) {
$item = $group_array[RssNews::Planet][$i];
$return_array->push(array(
'type' => $item->Category,
'link' => $item->Link,
'title' => $item->Headline,
'pubdate' => date('D, M jS Y', strtotime($item->Date)),
'rawpubdate' => $item->Date
));
}
}
/*for ($i = 0; $i < 3 && $i < count($group_array[RssNews::Blog]); $i++ ) {
$item = $group_array[RssNews::Blog][$i];
$return_array->push(array('type' => $item->Category, 'link' => $item->Link, 'title' => $item->Headline,
'pubdate' => date('D, M jS Y', strtotime($item->Date)), 'rawpubdate' => $item->Date));
}*/
$rss_count = $return_array->count();
$openstack_news = $news_repository->getAllNews()->limit($limit - $rss_count)->toArray();
foreach ($openstack_news as $item) {
$art_link = 'news/view/' . $item->ID . '/' . $item->HeadlineForUrl;
$return_array->push(array('type' => 'News', 'link' => $art_link, 'title' => $item->Headline,
'pubdate' => date('D, M jS Y', strtotime($item->DateEmbargo)), 'rawpubdate' => $item->DateEmbargo));
}
return $return_array->sort('rawpubdate', 'DESC')->limit($limit,0);
}
function PastEvents($num = 1)
{
return EventPage::get()->where("EventEndDate <= now()")->sort('EventStartDate')->limit($num);
}
function ReturningVisitor()
{
$VisitorCookie = new Cookie;
return ($VisitorCookie->get('ReturningVisitor') == TRUE);
}
function CompanyCount()
{
$DisplayedCompanies = Company::get()->filter('DisplayOnSite', 1);
$Count = $DisplayedCompanies->Count();
return $Count;
}
function DaysUntil()
{
$date = $this->EventDate;
return (isset($date)) ? floor((strtotime($date) - time()) / 60 / 60 / 24) : FALSE;
}
}