|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Defines the StaffPage page type. |
|
4
|
|
|
*/ |
|
5
|
|
|
class SlidePage extends Page |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
public static $db = array( |
|
8
|
|
|
'Caption' => 'Text', |
|
9
|
|
|
); |
|
10
|
|
|
|
|
11
|
|
|
public static $has_one = array( |
|
12
|
|
|
'Photo' => 'Image', |
|
13
|
|
|
'InternalPage' => 'SiteTree', |
|
14
|
|
|
); |
|
15
|
|
|
|
|
16
|
|
|
public static $allowed_children = 'none'; |
|
17
|
|
|
|
|
18
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
19
|
|
|
'ShowInMenus' => false, |
|
20
|
|
|
'ShowInSearch' => false, |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
public function getThumbnail2() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->InternalPage()->getPortletImage()->CMSThumbnail()->Tag; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getCMSFields() |
|
29
|
|
|
{ |
|
30
|
|
|
Requirements::javascript('slider/javascript/slideredit.js'); |
|
31
|
|
|
|
|
32
|
|
|
$fields = parent::getCMSFields(); |
|
33
|
|
|
$existing_photo = null; |
|
34
|
|
|
$photo_field = null; |
|
|
|
|
|
|
35
|
|
|
$internal_page = $this->InternalPage(); |
|
36
|
|
|
|
|
37
|
|
|
if ($internal_page instanceof RenderableAsPortlet) { |
|
|
|
|
|
|
38
|
|
|
error_log('Class implements renderable as a portlet'); |
|
39
|
|
|
$existing_photo = $this->InternalPage()->getPortletImage(); |
|
40
|
|
|
} else { |
|
41
|
|
|
// check parents recursively |
|
42
|
|
|
$parents = class_parents($internal_page); |
|
43
|
|
|
error_log(print_r($parents, 1)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$fields->addFieldToTab('Root.Main', |
|
47
|
|
|
new TreeDropdownField('InternalPageID', _t('SlidePage.CHOOSE_INTERNAL_LINK', 'Select a page on the website to link to'), 'SiteTree')); |
|
48
|
|
|
|
|
49
|
|
|
$composite_photoField = null; |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
if (!$existing_photo) { |
|
52
|
|
|
$photo_field = new UploadField('Photo', _t('SlidePage.PHOTO', 'Photo')); |
|
53
|
|
|
$photo_info = new LiteralField('PhotoInfo', _t('Slide.PHOTO_INFO', 'If the page you choose to link to has an image already it will appear here'), 'Photo'); |
|
|
|
|
|
|
54
|
|
|
$composite_photoField = CompositeField::create($photo_field, $photo_info); |
|
55
|
|
|
} else { |
|
56
|
|
|
// FIXME, find a cleaner way of doing this |
|
57
|
|
|
$composite_photoField = new LiteralField('Thumbnail2', '<div id="Thumbnail2" class="field readonly"> |
|
58
|
|
|
<label class="left" for="Form_EditForm_Thumbnail2">Photo</label> |
|
59
|
|
|
<div class="middleColumn"> |
|
60
|
|
|
<span id="Form_EditForm_Thumbnail2" class="readonly"> |
|
61
|
|
|
<img src="'.$existing_photo->SetWidth(400)->URL.'" alt="'.$existing_photo->Title.'" /> |
|
62
|
|
|
</span> |
|
63
|
|
|
</div> |
|
64
|
|
|
</div>'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$composite_photoField->setTitle('Photo'); |
|
68
|
|
|
$fields->addFieldToTab('Root.Main', $composite_photoField); |
|
69
|
|
|
$fields->addFieldToTab('Root.Main', new TextField('Caption', _t('SlidePage.CAPTION', 'Caption'))); |
|
70
|
|
|
$fields->renameField('Title', 'Slide Title'); |
|
71
|
|
|
|
|
72
|
|
|
$fields->removeFieldFromTab('Root.Main', 'Content'); |
|
73
|
|
|
|
|
74
|
|
|
return $fields; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/* |
|
78
|
|
|
Accessible from templates as $PortletImage |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getPortletImage() |
|
81
|
|
|
{ |
|
82
|
|
|
$image = null; |
|
|
|
|
|
|
83
|
|
|
if ($this->InternalPage() instanceof RenderableAsPortlet) { |
|
|
|
|
|
|
84
|
|
|
$image = $this->InternalPage()->getPortletImage(); |
|
85
|
|
|
} else { |
|
86
|
|
|
$image = $this->Photo(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $image; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function getThumbnail() |
|
93
|
|
|
{ |
|
94
|
|
|
if ($Image = $this->Photo()) { |
|
95
|
|
|
return $Image->CMSThumbnail(); |
|
96
|
|
|
} else { |
|
97
|
|
|
return '(No Image)'; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function getWebsiteAddress() |
|
102
|
|
|
{ |
|
103
|
|
|
$result = '#"'; |
|
104
|
|
|
|
|
105
|
|
|
if ($this->InternalPageID) { |
|
106
|
|
|
$targetPage = DataObject::get_by_id('Page', $this->InternalPageID); |
|
107
|
|
|
if ($targetPage) { |
|
108
|
|
|
$result = $targetPage->Link(); |
|
109
|
|
|
} else { |
|
110
|
|
|
$result = '#'; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $result; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
class SlidePage_Controller extends Page_Controller |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
private static $allowed_actions = array('newpageselected' => true); |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
/* |
|
123
|
|
|
When a new item is selected return JSON containing the title and image |
|
124
|
|
|
*/ |
|
125
|
|
|
public function newpageselected(SS_HTTPRequest $request) |
|
126
|
|
|
{ |
|
127
|
|
|
$sitetree_id = $request->param('ID'); |
|
128
|
|
|
$page = SiteTree::get_by_id($sitetree_id); |
|
129
|
|
|
$result = array(); |
|
130
|
|
|
if ($page) { |
|
131
|
|
|
$result['Title'] = $page->Title; |
|
132
|
|
|
} |
|
133
|
|
|
return json_encode($result); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
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.