|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Nicolaas [at] sunnysideup.co.nz |
|
5
|
|
|
* @package webportfolio |
|
6
|
|
|
* @sub-packages webportfolio |
|
7
|
|
|
* |
|
8
|
|
|
* |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
class WebPortfolioPageTimeLine extends Page |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
private static $icon = "webportfolio/images/treeicons/WebPortfolioPageTimeLine"; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
private static $db = array( |
|
|
|
|
|
|
17
|
|
|
"TimeLineHeader" => "Varchar", |
|
18
|
|
|
"TimeLineIntro" => "HTMLText", |
|
19
|
|
|
"JSON" => "Text" |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
23
|
|
|
"WebPortfolioItems" => "WebPortfolioItem" |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
public function getCMSFields() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$fields = parent::getCMSFields(); |
|
30
|
|
|
$fields->addFieldToTab("Root.Portfolio", new TextField("TimeLineHeader", "Time line header")); |
|
31
|
|
|
$fields->addFieldToTab("Root.Portfolio", new HtmlEditorField("TimeLineIntro", "Time line intro")); |
|
32
|
|
|
$itemOptionSet = WebPortfolioItem::get(); |
|
33
|
|
|
$itemOptionSetMap = ($itemOptionSet->count()) ? $itemOptionSet->map('ID', 'Title')->toArray() : array(); |
|
34
|
|
|
$fields->addFieldsToTab( |
|
35
|
|
|
"Root.Portfolio", |
|
36
|
|
|
array( |
|
37
|
|
|
new LiteralField("UpdatePortfolio", "<h3>Update Portfolio</h3>"), |
|
38
|
|
|
new LiteralField("EditPortfolio", "<p><a href=\"/admin/webportfolio\" target=\"_blank\">edit portfolio</a></p>"), |
|
39
|
|
|
new LiteralField("RefreshPortfolio", "<p><a href=\"".$this->Link("json/?flush=json")."\" target=\"_blank\">clear portfolio cache</a> (portfolio data is cached to incrase loading speed)</p>"), |
|
40
|
|
|
new LiteralField("SelectPortfolio", "<h3>Select Portfolio</h3>"), |
|
41
|
|
|
new CheckboxSetField( |
|
42
|
|
|
$name = "WebPortfolioItems", |
|
43
|
|
|
$title = "Items shown", |
|
44
|
|
|
$source = $itemOptionSetMap |
|
45
|
|
|
) |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
return $fields; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function createJSON() |
|
52
|
|
|
{ |
|
53
|
|
|
SSViewer::set_source_file_comments(false); |
|
|
|
|
|
|
54
|
|
|
$json = ' |
|
55
|
|
|
{ |
|
56
|
|
|
"timeline": |
|
57
|
|
|
{ |
|
58
|
|
|
"headline":'.$this->html2json($this->TimeLineHeader).', |
|
59
|
|
|
"type":"default", |
|
60
|
|
|
"text": '.$this->html2json($this->TimeLineIntro).', |
|
61
|
|
|
"date": ['; |
|
62
|
|
|
//'.$this->html2json($this->TimeLineIntro).'';// |
|
63
|
|
|
//"asset": { |
|
64
|
|
|
// "media":"http://yourdomain_or_socialmedialink_goes_here.jpg", |
|
65
|
|
|
// "credit":"Credit Name Goes Here", |
|
66
|
|
|
// "caption":"Caption text goes here" |
|
67
|
|
|
//}, |
|
68
|
|
|
|
|
69
|
|
|
$data = $this->WebPortfolioItems(); |
|
70
|
|
|
if ($data && $data->count()) { |
|
71
|
|
|
$dayExistsArray = array(); |
|
|
|
|
|
|
72
|
|
|
foreach ($data as $site) { |
|
73
|
|
|
if ($site->StartDate) { |
|
74
|
|
|
$startDateRaw = $site->StartDate; |
|
75
|
|
|
} else { |
|
76
|
|
|
$startDateRaw = $this->Created; |
|
77
|
|
|
} |
|
78
|
|
|
$startDateArray = explode("-", $startDateRaw); |
|
79
|
|
|
$startDate = intval($startDateArray[0]). ",".intval($startDateArray[1]). ",".intval($startDateArray[2]); |
|
80
|
|
|
$headLine = $this->html2json($site->getHeadLine()); |
|
81
|
|
|
$text = $this->html2json($site->renderWith("WebPortfolioPageOneItemTimeline")); // // |
|
82
|
|
|
$json .= ' |
|
83
|
|
|
{ |
|
84
|
|
|
"startDate":"'.$startDate.'", |
|
85
|
|
|
"headline": '.$headLine.', |
|
86
|
|
|
"text": '.$text.' |
|
87
|
|
|
} |
|
88
|
|
|
'; |
|
89
|
|
|
if (!$site->Last()) { |
|
90
|
|
|
$json .= ","; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
/* |
|
|
|
|
|
|
95
|
|
|
"era": [ |
|
96
|
|
|
{ |
|
97
|
|
|
"startDate":"2011,12,10", |
|
98
|
|
|
"endDate":"2011,12,11", |
|
99
|
|
|
"headline":"Headline Goes Here", |
|
100
|
|
|
"text":"<p>Body text goes here, some HTML is OK</p>", |
|
101
|
|
|
"tag":"This is Optional" |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
] |
|
105
|
|
|
*/ |
|
106
|
|
|
$json .=' |
|
107
|
|
|
] |
|
108
|
|
|
} |
|
109
|
|
|
}'; |
|
110
|
|
|
if ($json) { |
|
111
|
|
|
$this->JSON = $json; |
|
112
|
|
|
$this->writeToStage('Stage'); |
|
113
|
|
|
$this->Publish('Stage', 'Live'); |
|
114
|
|
|
$this->Status = "Published"; |
|
115
|
|
|
$this->flushCache(); |
|
116
|
|
|
} |
|
117
|
|
|
return $json; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
protected function html2json($html) |
|
121
|
|
|
{ |
|
122
|
|
|
$html = preg_replace('!\s+!', ' ', $html); |
|
123
|
|
|
if (!trim($html)) { |
|
124
|
|
|
$html = " "; |
|
125
|
|
|
} |
|
126
|
|
|
$json = Convert::raw2json($html); |
|
127
|
|
|
return $json; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
class WebPortfolioPageTimeLine_Controller extends Page_Controller |
|
|
|
|
|
|
132
|
|
|
{ |
|
133
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
134
|
|
|
"json" |
|
135
|
|
|
); |
|
136
|
|
|
|
|
137
|
|
|
private static $ajax_file_location = "webportfolio/javascript/timeline-executive.js"; |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
View Code Duplication |
public function init() |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
parent::init(); |
|
142
|
|
|
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
|
143
|
|
|
if (class_exists("PrettyPhoto")) { |
|
144
|
|
|
PrettyPhoto::include_code(); |
|
145
|
|
|
} else { |
|
146
|
|
|
user_error("It is recommended that you include the PrettyPhoto Module", E_USER_NOTICE); |
|
147
|
|
|
} |
|
148
|
|
|
Requirements::javascript($this->Config()->get("ajax_file_location")); |
|
149
|
|
|
Requirements::javascript("webportfolio/thirdparty/TimelineJS/compiled/js/storyjs-embed.js"); |
|
150
|
|
|
Requirements::themedCSS("WebPortfolioPageTimeLine", "webportfolio"); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function json($request) |
|
|
|
|
|
|
154
|
|
|
{ |
|
155
|
|
|
SSViewer::set_source_file_comments(false); |
|
|
|
|
|
|
156
|
|
|
if (isset($_GET['flush']) || !$this->JSON) { |
|
157
|
|
|
return $this->createJSON(); |
|
158
|
|
|
} |
|
159
|
|
|
return $this->JSON; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function JSONLink() |
|
163
|
|
|
{ |
|
164
|
|
|
return Director::absoluteURL($this->Link("json/")); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.