1
|
|
|
<? |
|
|
|
|
2
|
|
|
|
3
|
|
|
Loader::load('collector', array( |
4
|
|
|
'image/AlbumCollector', |
5
|
|
|
'waterfall/LogCollector')); |
6
|
|
|
Loader::load('controller', 'waterfalls/DefaultPageController'); |
7
|
|
|
|
8
|
|
|
final class LogController extends DefaultPageController |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
private static $AUTHOR = 'Jacob Emerick'; |
12
|
|
|
private static $AUTHOR_URL = 'https://home.jacobemerick.com/'; |
13
|
|
|
private static $JOURNAL_DIRECTORY = 'journal'; |
14
|
|
|
|
15
|
|
|
private static $FULL_IMAGE_LINK = '/photo/%s/%s-size-standard.jpg'; |
16
|
|
|
private static $THUMB_IMAGE_NODE = '<img src="/photo/%s/%s-size-thumb.jpg" alt="%s" height="%s" width="%s" />'; |
17
|
|
|
private static $MEDIUM_IMAGE_NODE = '<img src="/photo/%s/%s-size-small.jpg" alt="%s" height="375" width="500" />'; |
18
|
|
|
|
19
|
|
|
private $log; |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
parent::__construct(); |
24
|
|
|
|
25
|
|
|
$log_path = URLDecode::getPiece(2); |
26
|
|
|
|
27
|
|
|
$this->log = LogCollector::getByAlias($log_path); |
28
|
|
|
if(!$this->log) |
29
|
|
|
$this->eject(); |
30
|
|
|
|
31
|
|
|
$this->parent_navigation_item = 'journal'; |
|
|
|
|
32
|
|
|
|
33
|
|
|
$this->handle_comment_submit( |
34
|
|
|
self::$WATERFALL_SITE_ID, |
35
|
|
|
$this->log->alias, |
36
|
|
|
Loader::getRootUrl('waterfalls') . self::$JOURNAL_DIRECTORY . '/' . $this->log->alias . '/', |
37
|
|
|
$this->log->title); |
38
|
|
|
|
39
|
|
|
$this->add_waterfall_js(); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function set_head_data() |
43
|
|
|
{ |
44
|
|
|
parent::set_head_data(); |
45
|
|
|
|
46
|
|
|
$this->set_title("{$this->log->title} | " . self::$WEBSITE_TITLE); |
47
|
|
|
$this->set_description($this->log->introduction); |
48
|
|
|
|
49
|
|
|
$keyword_array = array(); |
50
|
|
|
$tag_result = LogCollector::getTagListForLog($this->log->id); |
51
|
|
|
foreach($tag_result as $tag) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$keyword_array[] = $tag->name; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->set_keywords($keyword_array); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function set_body_data($page_type = 'normal') |
60
|
|
|
{ |
61
|
|
|
parent::set_body_data($page_type); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->set_body('view', 'Log'); |
64
|
|
|
|
65
|
|
|
$body_data = array_merge( |
66
|
|
|
$this->get_formatted_log(), |
67
|
|
|
[ |
68
|
|
|
'comment_array' => $this->get_comment_array( |
69
|
|
|
'waterfallsofthekeweenaw.com', |
70
|
|
|
"journal/{$this->log->alias}" |
71
|
|
|
), |
72
|
|
|
'sidebar' => $this->get_sidebar(), |
73
|
|
|
'series' => $this->get_series(), |
74
|
|
|
'album' => $this->get_album(), |
75
|
|
|
] |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->set_body('data', $body_data); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
private function get_formatted_log() |
82
|
|
|
{ |
83
|
|
|
$formatted_log = array(); |
84
|
|
|
|
85
|
|
|
$formatted_log['introduction'] = $this->get_log_introduction($this->log); |
86
|
|
|
$formatted_log['title'] = $this->log->title; |
87
|
|
|
$formatted_log['url'] = Loader::getRootURL('waterfalls') . self::$JOURNAL_DIRECTORY . '/' . $this->log->alias . '/'; |
88
|
|
|
|
89
|
|
|
$formatted_log['body'] = $this->get_formatted_log_body(); |
90
|
|
|
|
91
|
|
|
return $formatted_log; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
private function get_log_introduction($log) |
95
|
|
|
{ |
96
|
|
|
return array( |
97
|
|
|
'title' => $log->title, |
98
|
|
|
'url' => Loader::getRootURL('waterfalls') . self::$JOURNAL_DIRECTORY . '/' . $log->alias . '/', |
99
|
|
|
'date' => $this->get_parsed_date($log->date), |
100
|
|
|
'publish_date' => $this->get_parsed_date($log->publish_date), |
101
|
|
|
'introduction' => $log->introduction, |
102
|
|
|
'image' => sprintf( |
103
|
|
|
self::$MEDIUM_IMAGE_NODE, |
104
|
|
|
$log->image_category, |
105
|
|
|
$log->image_name, |
106
|
|
|
$log->image_description), |
107
|
|
|
'author' => self::$AUTHOR, |
108
|
|
|
'author_url' => self::$AUTHOR_URL, |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// @todo - link things up |
113
|
|
|
private function get_formatted_log_body() |
114
|
|
|
{ |
115
|
|
|
$body = $this->log->body; |
116
|
|
|
|
117
|
|
|
$body = Content::instance('FixPhoto', $body)->activate(false, 'standard'); |
118
|
|
|
$body = Content::instance('FixInternalLink', $body)->activate(); |
119
|
|
|
|
120
|
|
|
return $body; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
private function get_series() |
124
|
|
|
{ |
125
|
|
|
$series = array( |
126
|
|
|
'previous' => array(), |
127
|
|
|
'next' => array()); |
128
|
|
|
|
129
|
|
|
$previous_log = LogCollector::getPreviousLog($this->log->id); |
130
|
|
View Code Duplication |
if($previous_log != false) |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
$series['previous'] = (object) array( |
133
|
|
|
'path' => '/' . self::$JOURNAL_DIRECTORY . '/' . $previous_log->alias . '/', |
134
|
|
|
'title' => $previous_log->title, |
135
|
|
|
'date' => $previous_log->date); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$next_log = LogCollector::getNextLog($this->log->id); |
139
|
|
View Code Duplication |
if($next_log != false) |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$series['next'] = (object) array( |
142
|
|
|
'path' => '/' . self::$JOURNAL_DIRECTORY . '/' . $next_log->alias . '/', |
143
|
|
|
'title' => $next_log->title, |
144
|
|
|
'date' => $next_log->date); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $series; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
private function get_sidebar() |
151
|
|
|
{ |
152
|
|
|
$sidebar = array(); |
153
|
|
|
|
154
|
|
|
$sidebar['companion_list'] = array(); |
155
|
|
|
$companions = LogCollector::getCompanionListForLog($this->log->id); |
156
|
|
|
foreach($companions as $companion) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$sidebar['companion_list'][] = (object) array( |
159
|
|
|
'title' => $companion->name, |
160
|
|
|
'path' => "/companion/{$companion->alias}/"); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$sidebar['tag_list'] = array(); |
164
|
|
|
$tags = LogCollector::getTagListForLog($this->log->id); |
165
|
|
|
foreach($tags as $tag) |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
$sidebar['tag_list'][] = (object) array( |
168
|
|
|
'title' => $tag->name, |
169
|
|
|
'path' => "/journal/tag/{$tag->alias}/"); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$sidebar['waterfall_list'] = array(); |
173
|
|
|
$waterfalls = LogCollector::getWaterfallListForLog($this->log->id); |
174
|
|
|
foreach($waterfalls as $waterfall) |
|
|
|
|
175
|
|
|
{ |
176
|
|
|
$sidebar['waterfall_list'][] = (object) array( |
177
|
|
|
'title' => $waterfall->name, |
178
|
|
|
'path' => "/{$waterfall->watercourse_alias}/{$waterfall->alias}/"); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $sidebar; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
View Code Duplication |
private function get_album() |
|
|
|
|
185
|
|
|
{ |
186
|
|
|
$album = array(); |
187
|
|
|
|
188
|
|
|
if($this->log->album == 0) |
189
|
|
|
return $album; |
190
|
|
|
|
191
|
|
|
$photo_list = AlbumCollector::getPhotoListForAlbum($this->log->album); |
192
|
|
|
foreach($photo_list as $photo) |
|
|
|
|
193
|
|
|
{ |
194
|
|
|
$photo_array = array(); |
195
|
|
|
$photo_array['full_link'] = sprintf(self::$FULL_IMAGE_LINK, $photo->category, $photo->name); |
196
|
|
|
$photo_array['description'] = $photo->description; |
197
|
|
|
|
198
|
|
|
if($photo->height < $photo->width) |
199
|
|
|
list($height, $width) = array(75, 100); |
200
|
|
|
else |
201
|
|
|
list($height, $width) = array(100, 75); |
202
|
|
|
|
203
|
|
|
$photo_array['image_node'] = sprintf( |
204
|
|
|
self::$THUMB_IMAGE_NODE, |
205
|
|
|
$photo->category, |
206
|
|
|
$photo->name, |
207
|
|
|
$photo->description, |
208
|
|
|
$height, |
209
|
|
|
$width); |
210
|
|
|
|
211
|
|
|
$album[] = (object) $photo_array; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
return $album; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
} |
218
|
|
|
|
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php
.