@@ -17,133 +17,133 @@ |
||
17 | 17 | */ |
18 | 18 | class PopulateThemeSampleDataTask extends BuildTask |
19 | 19 | { |
20 | - protected $title = 'Populate sample data for theme demo'; |
|
21 | - |
|
22 | - protected $description = 'Populates some sample data for showcasing the functionality of the ' |
|
23 | - . 'starter and Wātea themes'; |
|
24 | - |
|
25 | - /** |
|
26 | - * A series of method calls to create sample data |
|
27 | - * |
|
28 | - * @param HTTPRequest $request |
|
29 | - */ |
|
30 | - public function run($request) |
|
31 | - { |
|
32 | - $this->handleContactForm(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Decide whether to create a contact user defined form, and call it to be be created if so |
|
37 | - * |
|
38 | - * @return $this |
|
39 | - */ |
|
40 | - protected function handleContactForm() |
|
41 | - { |
|
42 | - if (!$this->getContactFormExists()) { |
|
43 | - $this->createContactForm(); |
|
44 | - } |
|
45 | - return $this; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Determine whether a "contact us" userform exists yet |
|
50 | - * |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - protected function getContactFormExists() |
|
54 | - { |
|
55 | - $exists = false; |
|
56 | - foreach (UserDefinedForm::get()->column('ID') as $formId) { |
|
57 | - $count = Versioned::get_all_versions(UserDefinedForm::class, $formId) |
|
58 | - ->filter('URLSegment', 'contact') |
|
59 | - ->count(); |
|
60 | - |
|
61 | - if ($count >= 1) { |
|
62 | - $exists = true; |
|
63 | - break; |
|
64 | - } |
|
65 | - } |
|
66 | - return $exists; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Create a "contact us" userform. Please note that this form does not have any recipients by default, so |
|
71 | - * no emails will be sent. To add recipients - edit the page in the CMS and add a recipient via the "Recipients" |
|
72 | - * tab. |
|
73 | - * |
|
74 | - * @return $this |
|
75 | - */ |
|
76 | - protected function createContactForm() |
|
77 | - { |
|
78 | - $form = UserDefinedForm::create(array( |
|
79 | - 'Title' => 'Contact', |
|
80 | - 'URLSegment' => 'contact', |
|
81 | - 'Content' => '<p>$UserDefinedForm</p>', |
|
82 | - 'SubmitButtonText' => 'Submit', |
|
83 | - 'ClearButtonText' => 'Clear', |
|
84 | - 'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>", |
|
85 | - 'EnableLiveValidation' => true |
|
86 | - )); |
|
87 | - |
|
88 | - $form->write(); |
|
89 | - |
|
90 | - // Add form fields |
|
91 | - $fields = array( |
|
92 | - EditableFormStep::create([ |
|
93 | - 'Title' => _t( |
|
94 | - 'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFormStep.TITLE_FIRST', |
|
95 | - 'First Page' |
|
96 | - ) |
|
97 | - ]), |
|
98 | - EditableTextField::create([ |
|
99 | - 'Title' => 'Name', |
|
100 | - 'Required' => true, |
|
101 | - 'RightTitle' => 'Please enter your first and last name' |
|
102 | - ]), |
|
103 | - EditableEmailField::create([ |
|
104 | - 'Title' => Email::class, |
|
105 | - 'Required' => true, |
|
106 | - 'Placeholder' => '[email protected]' |
|
107 | - ]), |
|
108 | - EditableTextField::create([ |
|
109 | - 'Title' => 'Subject' |
|
110 | - ]), |
|
111 | - EditableTextField::create([ |
|
112 | - 'Title' => 'Message', |
|
113 | - 'Required' => true, |
|
114 | - 'Rows' => 5 |
|
115 | - ]) |
|
116 | - ); |
|
117 | - |
|
118 | - foreach ($fields as $field) { |
|
119 | - $field->write(); |
|
120 | - $form->Fields()->add($field); |
|
121 | - $field->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
|
122 | - } |
|
123 | - |
|
124 | - $form->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
|
125 | - $form->flushCache(); |
|
126 | - |
|
127 | - $this->output(' + Created "contact" UserDefinedForm page'); |
|
128 | - |
|
129 | - return $this; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Output a message either to the console or browser |
|
134 | - * |
|
135 | - * @param string $message |
|
136 | - * @return $this |
|
137 | - */ |
|
138 | - protected function output($message) |
|
139 | - { |
|
140 | - if (Director::is_cli()) { |
|
141 | - $message .= PHP_EOL; |
|
142 | - } else { |
|
143 | - $message = sprintf('<p>%s</p>', $message); |
|
144 | - } |
|
145 | - echo $message; |
|
146 | - |
|
147 | - return $this; |
|
148 | - } |
|
20 | + protected $title = 'Populate sample data for theme demo'; |
|
21 | + |
|
22 | + protected $description = 'Populates some sample data for showcasing the functionality of the ' |
|
23 | + . 'starter and Wātea themes'; |
|
24 | + |
|
25 | + /** |
|
26 | + * A series of method calls to create sample data |
|
27 | + * |
|
28 | + * @param HTTPRequest $request |
|
29 | + */ |
|
30 | + public function run($request) |
|
31 | + { |
|
32 | + $this->handleContactForm(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Decide whether to create a contact user defined form, and call it to be be created if so |
|
37 | + * |
|
38 | + * @return $this |
|
39 | + */ |
|
40 | + protected function handleContactForm() |
|
41 | + { |
|
42 | + if (!$this->getContactFormExists()) { |
|
43 | + $this->createContactForm(); |
|
44 | + } |
|
45 | + return $this; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Determine whether a "contact us" userform exists yet |
|
50 | + * |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + protected function getContactFormExists() |
|
54 | + { |
|
55 | + $exists = false; |
|
56 | + foreach (UserDefinedForm::get()->column('ID') as $formId) { |
|
57 | + $count = Versioned::get_all_versions(UserDefinedForm::class, $formId) |
|
58 | + ->filter('URLSegment', 'contact') |
|
59 | + ->count(); |
|
60 | + |
|
61 | + if ($count >= 1) { |
|
62 | + $exists = true; |
|
63 | + break; |
|
64 | + } |
|
65 | + } |
|
66 | + return $exists; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Create a "contact us" userform. Please note that this form does not have any recipients by default, so |
|
71 | + * no emails will be sent. To add recipients - edit the page in the CMS and add a recipient via the "Recipients" |
|
72 | + * tab. |
|
73 | + * |
|
74 | + * @return $this |
|
75 | + */ |
|
76 | + protected function createContactForm() |
|
77 | + { |
|
78 | + $form = UserDefinedForm::create(array( |
|
79 | + 'Title' => 'Contact', |
|
80 | + 'URLSegment' => 'contact', |
|
81 | + 'Content' => '<p>$UserDefinedForm</p>', |
|
82 | + 'SubmitButtonText' => 'Submit', |
|
83 | + 'ClearButtonText' => 'Clear', |
|
84 | + 'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>", |
|
85 | + 'EnableLiveValidation' => true |
|
86 | + )); |
|
87 | + |
|
88 | + $form->write(); |
|
89 | + |
|
90 | + // Add form fields |
|
91 | + $fields = array( |
|
92 | + EditableFormStep::create([ |
|
93 | + 'Title' => _t( |
|
94 | + 'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFormStep.TITLE_FIRST', |
|
95 | + 'First Page' |
|
96 | + ) |
|
97 | + ]), |
|
98 | + EditableTextField::create([ |
|
99 | + 'Title' => 'Name', |
|
100 | + 'Required' => true, |
|
101 | + 'RightTitle' => 'Please enter your first and last name' |
|
102 | + ]), |
|
103 | + EditableEmailField::create([ |
|
104 | + 'Title' => Email::class, |
|
105 | + 'Required' => true, |
|
106 | + 'Placeholder' => '[email protected]' |
|
107 | + ]), |
|
108 | + EditableTextField::create([ |
|
109 | + 'Title' => 'Subject' |
|
110 | + ]), |
|
111 | + EditableTextField::create([ |
|
112 | + 'Title' => 'Message', |
|
113 | + 'Required' => true, |
|
114 | + 'Rows' => 5 |
|
115 | + ]) |
|
116 | + ); |
|
117 | + |
|
118 | + foreach ($fields as $field) { |
|
119 | + $field->write(); |
|
120 | + $form->Fields()->add($field); |
|
121 | + $field->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
|
122 | + } |
|
123 | + |
|
124 | + $form->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
|
125 | + $form->flushCache(); |
|
126 | + |
|
127 | + $this->output(' + Created "contact" UserDefinedForm page'); |
|
128 | + |
|
129 | + return $this; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Output a message either to the console or browser |
|
134 | + * |
|
135 | + * @param string $message |
|
136 | + * @return $this |
|
137 | + */ |
|
138 | + protected function output($message) |
|
139 | + { |
|
140 | + if (Director::is_cli()) { |
|
141 | + $message .= PHP_EOL; |
|
142 | + } else { |
|
143 | + $message = sprintf('<p>%s</p>', $message); |
|
144 | + } |
|
145 | + echo $message; |
|
146 | + |
|
147 | + return $this; |
|
148 | + } |
|
149 | 149 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | //if base url YML is defined in YML, use that |
87 | 87 | if (Config::inst()->get(BasePage::class, 'pdf_base_url')) { |
88 | - $pdfBaseUrl = Config::inst()->get(BasePage::class, 'pdf_base_url').'/'; |
|
88 | + $pdfBaseUrl = Config::inst()->get(BasePage::class, 'pdf_base_url') . '/'; |
|
89 | 89 | //otherwise, if we are CWP use the secure domain |
90 | 90 | } elseif (Environment::getEnv('CWP_SECURE_DOMAIN')) { |
91 | 91 | $pdfBaseUrl = Environment::getEnv('CWP_SECURE_DOMAIN') . '/'; |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | if ($results) { |
274 | 274 | $response = $response |
275 | 275 | ->customise($results) |
276 | - ->customise(array( 'Results' => $results->getResults() )); |
|
276 | + ->customise(array('Results' => $results->getResults())); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | // Render |
@@ -23,329 +23,329 @@ |
||
23 | 23 | |
24 | 24 | class BasePageController extends ContentController |
25 | 25 | { |
26 | - private static $allowed_actions = [ |
|
27 | - 'downloadpdf', |
|
28 | - 'SearchForm', |
|
29 | - 'results', |
|
30 | - ]; |
|
31 | - |
|
32 | - /** |
|
33 | - * How many search results should be shown per-page? |
|
34 | - * @var int |
|
35 | - */ |
|
36 | - public static $results_per_page = 10; |
|
37 | - |
|
38 | - public static $search_index_class = CwpSolrIndex::class; |
|
39 | - |
|
40 | - /** |
|
41 | - * If spelling suggestions for searches are given, enable |
|
42 | - * suggested searches to be followed immediately |
|
43 | - * |
|
44 | - * @config |
|
45 | - * @var bool |
|
46 | - */ |
|
47 | - private static $search_follow_suggestions = true; |
|
48 | - |
|
49 | - /** |
|
50 | - * Which classes should be queried when searching? |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - public static $classes_to_search = [ |
|
54 | - [ |
|
55 | - 'class' => 'Page', |
|
56 | - 'includeSubclasses' => true, |
|
57 | - ] |
|
58 | - ]; |
|
59 | - |
|
60 | - /** |
|
61 | - * Serve the page rendered as PDF. |
|
62 | - */ |
|
63 | - public function downloadpdf() |
|
64 | - { |
|
65 | - if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
66 | - return false; |
|
67 | - } |
|
68 | - |
|
69 | - // We only allow producing live pdf. There is no way to secure the draft files. |
|
70 | - Versioned::set_stage(Versioned::LIVE); |
|
71 | - |
|
72 | - $path = $this->dataRecord->getPdfFilename(); |
|
73 | - if (!file_exists($path)) { |
|
74 | - $this->generatePDF(); |
|
75 | - } |
|
76 | - |
|
77 | - return HTTPRequest::send_file(file_get_contents($path), basename($path), 'application/pdf'); |
|
78 | - } |
|
79 | - |
|
80 | - /* |
|
26 | + private static $allowed_actions = [ |
|
27 | + 'downloadpdf', |
|
28 | + 'SearchForm', |
|
29 | + 'results', |
|
30 | + ]; |
|
31 | + |
|
32 | + /** |
|
33 | + * How many search results should be shown per-page? |
|
34 | + * @var int |
|
35 | + */ |
|
36 | + public static $results_per_page = 10; |
|
37 | + |
|
38 | + public static $search_index_class = CwpSolrIndex::class; |
|
39 | + |
|
40 | + /** |
|
41 | + * If spelling suggestions for searches are given, enable |
|
42 | + * suggested searches to be followed immediately |
|
43 | + * |
|
44 | + * @config |
|
45 | + * @var bool |
|
46 | + */ |
|
47 | + private static $search_follow_suggestions = true; |
|
48 | + |
|
49 | + /** |
|
50 | + * Which classes should be queried when searching? |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + public static $classes_to_search = [ |
|
54 | + [ |
|
55 | + 'class' => 'Page', |
|
56 | + 'includeSubclasses' => true, |
|
57 | + ] |
|
58 | + ]; |
|
59 | + |
|
60 | + /** |
|
61 | + * Serve the page rendered as PDF. |
|
62 | + */ |
|
63 | + public function downloadpdf() |
|
64 | + { |
|
65 | + if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
66 | + return false; |
|
67 | + } |
|
68 | + |
|
69 | + // We only allow producing live pdf. There is no way to secure the draft files. |
|
70 | + Versioned::set_stage(Versioned::LIVE); |
|
71 | + |
|
72 | + $path = $this->dataRecord->getPdfFilename(); |
|
73 | + if (!file_exists($path)) { |
|
74 | + $this->generatePDF(); |
|
75 | + } |
|
76 | + |
|
77 | + return HTTPRequest::send_file(file_get_contents($path), basename($path), 'application/pdf'); |
|
78 | + } |
|
79 | + |
|
80 | + /* |
|
81 | 81 | * This will return either pdf_base_url from YML, CWP_SECURE_DOMAIN |
82 | 82 | * from _ss_environment, or blank. In that order of importance. |
83 | 83 | */ |
84 | - public function getPDFBaseURL() |
|
85 | - { |
|
86 | - //if base url YML is defined in YML, use that |
|
87 | - if (Config::inst()->get(BasePage::class, 'pdf_base_url')) { |
|
88 | - $pdfBaseUrl = Config::inst()->get(BasePage::class, 'pdf_base_url').'/'; |
|
89 | - //otherwise, if we are CWP use the secure domain |
|
90 | - } elseif (Environment::getEnv('CWP_SECURE_DOMAIN')) { |
|
91 | - $pdfBaseUrl = Environment::getEnv('CWP_SECURE_DOMAIN') . '/'; |
|
92 | - //or if neither, leave blank |
|
93 | - } else { |
|
94 | - $pdfBaseUrl = ''; |
|
95 | - } |
|
96 | - return $pdfBaseUrl; |
|
97 | - } |
|
98 | - |
|
99 | - /* |
|
84 | + public function getPDFBaseURL() |
|
85 | + { |
|
86 | + //if base url YML is defined in YML, use that |
|
87 | + if (Config::inst()->get(BasePage::class, 'pdf_base_url')) { |
|
88 | + $pdfBaseUrl = Config::inst()->get(BasePage::class, 'pdf_base_url').'/'; |
|
89 | + //otherwise, if we are CWP use the secure domain |
|
90 | + } elseif (Environment::getEnv('CWP_SECURE_DOMAIN')) { |
|
91 | + $pdfBaseUrl = Environment::getEnv('CWP_SECURE_DOMAIN') . '/'; |
|
92 | + //or if neither, leave blank |
|
93 | + } else { |
|
94 | + $pdfBaseUrl = ''; |
|
95 | + } |
|
96 | + return $pdfBaseUrl; |
|
97 | + } |
|
98 | + |
|
99 | + /* |
|
100 | 100 | * Don't use the proxy if the pdf domain is the CWP secure domain |
101 | 101 | * Or if we aren't on a CWP server |
102 | 102 | */ |
103 | - public function getPDFProxy($pdfBaseUrl) |
|
104 | - { |
|
105 | - if (!Environment::getEnv('CWP_SECURE_DOMAIN') |
|
106 | - || $pdfBaseUrl == Environment::getEnv('CWP_SECURE_DOMAIN') . '/' |
|
107 | - ) { |
|
108 | - $proxy = ''; |
|
109 | - } else { |
|
110 | - $proxy = ' --proxy ' . Environment::getEnv('SS_OUTBOUND_PROXY') |
|
111 | - . ':' . Environment::getEnv('SS_OUTBOUND_PROXY_PORT'); |
|
112 | - } |
|
113 | - return $proxy; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Render the page as PDF using wkhtmltopdf. |
|
118 | - */ |
|
119 | - public function generatePDF() |
|
120 | - { |
|
121 | - if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
122 | - return false; |
|
123 | - } |
|
124 | - |
|
125 | - $binaryPath = Config::inst()->get(BasePage::class, 'wkhtmltopdf_binary'); |
|
126 | - if (!$binaryPath || !is_executable($binaryPath)) { |
|
127 | - if (Environment::getEnv('WKHTMLTOPDF_BINARY') |
|
128 | - && is_executable(Environment::getEnv('WKHTMLTOPDF_BINARY')) |
|
129 | - ) { |
|
130 | - $binaryPath = Environment::getEnv('WKHTMLTOPDF_BINARY'); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - if (!$binaryPath) { |
|
135 | - user_error('Neither WKHTMLTOPDF_BINARY nor BasePage.wkhtmltopdf_binary are defined', E_USER_ERROR); |
|
136 | - } |
|
137 | - |
|
138 | - if (Versioned::get_reading_mode() == 'Stage.Stage') { |
|
139 | - user_error('Generating PDFs on draft is not supported', E_USER_ERROR); |
|
140 | - } |
|
141 | - |
|
142 | - set_time_limit(60); |
|
143 | - |
|
144 | - // prepare the paths |
|
145 | - $pdfFile = $this->dataRecord->getPdfFilename(); |
|
146 | - $bodyFile = str_replace('.pdf', '_pdf.html', $pdfFile); |
|
147 | - $footerFile = str_replace('.pdf', '_pdffooter.html', $pdfFile); |
|
148 | - |
|
149 | - // make sure the work directory exists |
|
150 | - if (!file_exists(dirname($pdfFile))) { |
|
151 | - Filesystem::makeFolder(dirname($pdfFile)); |
|
152 | - } |
|
153 | - |
|
154 | - //decide the domain to use in generation |
|
155 | - $pdfBaseUrl = $this->getPDFBaseURL(); |
|
156 | - |
|
157 | - // Force http protocol on CWP - fetching from localhost without using the proxy, SSL terminates on gateway. |
|
158 | - if (Environment::getEnv('CWP_ENVIRONMENT')) { |
|
159 | - Config::modify()->set(Director::class, 'alternate_protocol', 'http'); |
|
160 | - //only set alternate protocol if CWP_SECURE_DOMAIN is defined OR pdf_base_url is |
|
161 | - if ($pdfBaseUrl) { |
|
162 | - Config::modify()->set(Director::class, 'alternate_base_url', 'http://' . $pdfBaseUrl); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - $bodyViewer = $this->getViewer('pdf'); |
|
167 | - |
|
168 | - // write the output of this page to HTML, ready for conversion to PDF |
|
169 | - file_put_contents($bodyFile, $bodyViewer->process($this)); |
|
170 | - |
|
171 | - // get the viewer for the current template with _pdffooter |
|
172 | - $footerViewer = $this->getViewer('pdffooter'); |
|
173 | - |
|
174 | - // write the output of the footer template to HTML, ready for conversion to PDF |
|
175 | - file_put_contents($footerFile, $footerViewer->process($this)); |
|
176 | - |
|
177 | - //decide what the proxy should look like |
|
178 | - $proxy = $this->getPDFProxy($pdfBaseUrl); |
|
179 | - |
|
180 | - // finally, generate the PDF |
|
181 | - $command = $binaryPath . $proxy . ' --outline -B 40pt -L 20pt -R 20pt -T 20pt --encoding utf-8 ' |
|
182 | - . '--orientation Portrait --disable-javascript --quiet --print-media-type '; |
|
183 | - $retVal = 0; |
|
184 | - $output = array(); |
|
185 | - exec( |
|
186 | - $command . " --footer-html \"$footerFile\" \"$bodyFile\" \"$pdfFile\" &> /dev/stdout", |
|
187 | - $output, |
|
188 | - $retVal |
|
189 | - ); |
|
190 | - |
|
191 | - // remove temporary file |
|
192 | - unlink($bodyFile); |
|
193 | - unlink($footerFile); |
|
194 | - |
|
195 | - // output any errors |
|
196 | - if ($retVal != 0) { |
|
197 | - user_error('wkhtmltopdf failed: ' . implode("\n", $output), E_USER_ERROR); |
|
198 | - } |
|
199 | - |
|
200 | - // serve the generated file |
|
201 | - return HTTPRequest::send_file(file_get_contents($pdfFile), basename($pdfFile), 'application/pdf'); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Site search form |
|
206 | - */ |
|
207 | - public function SearchForm() |
|
208 | - { |
|
209 | - $searchText = $this->getRequest()->getVar('Search'); |
|
210 | - |
|
211 | - $fields = FieldList::create( |
|
212 | - TextField::create('Search', false, $searchText) |
|
213 | - ); |
|
214 | - $actions = FieldList::create( |
|
215 | - FormAction::create('results', _t('SilverStripe\\CMS\\Search\\SearchForm.GO', 'Go')) |
|
216 | - ); |
|
217 | - |
|
218 | - $form = SearchForm::create($this, SearchForm::class, $fields, $actions); |
|
219 | - $form->setFormAction('search/SearchForm'); |
|
220 | - |
|
221 | - return $form; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Get search form with _header suffix |
|
226 | - * |
|
227 | - * @return SearchForm |
|
228 | - */ |
|
229 | - public function HeaderSearchForm() |
|
230 | - { |
|
231 | - return $this->SearchForm()->setTemplate('SearchForm_header'); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Process and render search results. |
|
236 | - * |
|
237 | - * @param array $data The raw request data submitted by user |
|
238 | - * @param SearchForm $form The form instance that was submitted |
|
239 | - * @param HTTPRequest $request Request generated for this action |
|
240 | - * @return DBHTMLText |
|
241 | - */ |
|
242 | - public function results($data, $form, $request) |
|
243 | - { |
|
244 | - // Check parameters for terms, pagination, and if we should follow suggestions |
|
245 | - $keywords = empty($data['Search']) ? '' : $data['Search']; |
|
246 | - $start = isset($data['start']) ? $data['start'] : 0; |
|
247 | - $suggestions = isset($data['suggestions']) |
|
248 | - ? $data['suggestions'] |
|
249 | - : $this->config()->search_follow_suggestions; |
|
250 | - |
|
251 | - $results = CwpSearchEngine::create() |
|
252 | - ->search( |
|
253 | - $keywords, |
|
254 | - $this->getClassesToSearch(), |
|
255 | - $this->getSearchIndex(), |
|
256 | - $this->getSearchPageSize(), |
|
257 | - $start, |
|
258 | - $suggestions |
|
259 | - ); |
|
260 | - |
|
261 | - // Customise content with these results |
|
262 | - $properties = [ |
|
263 | - 'MetaTitle' => _t(__CLASS__ . '.MetaTitle', 'Search {keywords}', ['keywords' => $keywords]), |
|
264 | - 'NoSearchResults' => _t(__CLASS__ . '.NoResult', 'Sorry, your search query did not return any results.'), |
|
265 | - 'EmptySearch' => _t(__CLASS__ . '.EmptySearch', 'Search field empty, please enter your search query.'), |
|
266 | - 'PdfLink' => '', |
|
267 | - 'Title' => _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results'), |
|
268 | - ]; |
|
269 | - $this->extend('updateSearchResults', $results, $properties); |
|
270 | - |
|
271 | - // Customise page |
|
272 | - $response = $this->customise($properties); |
|
273 | - if ($results) { |
|
274 | - $response = $response |
|
275 | - ->customise($results) |
|
276 | - ->customise(array( 'Results' => $results->getResults() )); |
|
277 | - } |
|
278 | - |
|
279 | - // Render |
|
280 | - $templates = $this->getResultsTemplate($request); |
|
281 | - return $response->renderWith($templates); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Select the template to render search results with |
|
286 | - * |
|
287 | - * @param HTTPRequest $request |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - protected function getResultsTemplate($request) |
|
291 | - { |
|
292 | - $templates = [Page::class . '_results', Page::class]; |
|
293 | - if ($request->getVar('format') == 'rss') { |
|
294 | - array_unshift($templates, 'Page_results_rss'); |
|
295 | - } |
|
296 | - if ($request->getVar('format') == 'atom') { |
|
297 | - array_unshift($templates, 'Page_results_atom'); |
|
298 | - } |
|
299 | - return $templates; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Provide current year. |
|
304 | - */ |
|
305 | - public function CurrentDatetime() |
|
306 | - { |
|
307 | - return DBDatetime::now(); |
|
308 | - } |
|
309 | - |
|
310 | - public function getRSSLink() |
|
311 | - { |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Get the search index registered for this application |
|
316 | - * |
|
317 | - * @return CwpSearchIndex |
|
318 | - */ |
|
319 | - protected function getSearchIndex() |
|
320 | - { |
|
321 | - // Will be a service name in 2.0 and returned via injector |
|
322 | - /** @var CwpSearchIndex $index */ |
|
323 | - $index = null; |
|
324 | - if (self::$search_index_class) { |
|
325 | - $index = Injector::inst()->get(self::$search_index_class); |
|
326 | - } |
|
327 | - return $index; |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Gets the list of configured classes to search |
|
332 | - * |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected function getClassesToSearch() |
|
336 | - { |
|
337 | - // Will be private static config in 2.0 |
|
338 | - return self::$classes_to_search; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Get page size for search |
|
343 | - * |
|
344 | - * @return int |
|
345 | - */ |
|
346 | - protected function getSearchPageSize() |
|
347 | - { |
|
348 | - // Will be private static config in 2.0 |
|
349 | - return self::$results_per_page; |
|
350 | - } |
|
103 | + public function getPDFProxy($pdfBaseUrl) |
|
104 | + { |
|
105 | + if (!Environment::getEnv('CWP_SECURE_DOMAIN') |
|
106 | + || $pdfBaseUrl == Environment::getEnv('CWP_SECURE_DOMAIN') . '/' |
|
107 | + ) { |
|
108 | + $proxy = ''; |
|
109 | + } else { |
|
110 | + $proxy = ' --proxy ' . Environment::getEnv('SS_OUTBOUND_PROXY') |
|
111 | + . ':' . Environment::getEnv('SS_OUTBOUND_PROXY_PORT'); |
|
112 | + } |
|
113 | + return $proxy; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Render the page as PDF using wkhtmltopdf. |
|
118 | + */ |
|
119 | + public function generatePDF() |
|
120 | + { |
|
121 | + if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
122 | + return false; |
|
123 | + } |
|
124 | + |
|
125 | + $binaryPath = Config::inst()->get(BasePage::class, 'wkhtmltopdf_binary'); |
|
126 | + if (!$binaryPath || !is_executable($binaryPath)) { |
|
127 | + if (Environment::getEnv('WKHTMLTOPDF_BINARY') |
|
128 | + && is_executable(Environment::getEnv('WKHTMLTOPDF_BINARY')) |
|
129 | + ) { |
|
130 | + $binaryPath = Environment::getEnv('WKHTMLTOPDF_BINARY'); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + if (!$binaryPath) { |
|
135 | + user_error('Neither WKHTMLTOPDF_BINARY nor BasePage.wkhtmltopdf_binary are defined', E_USER_ERROR); |
|
136 | + } |
|
137 | + |
|
138 | + if (Versioned::get_reading_mode() == 'Stage.Stage') { |
|
139 | + user_error('Generating PDFs on draft is not supported', E_USER_ERROR); |
|
140 | + } |
|
141 | + |
|
142 | + set_time_limit(60); |
|
143 | + |
|
144 | + // prepare the paths |
|
145 | + $pdfFile = $this->dataRecord->getPdfFilename(); |
|
146 | + $bodyFile = str_replace('.pdf', '_pdf.html', $pdfFile); |
|
147 | + $footerFile = str_replace('.pdf', '_pdffooter.html', $pdfFile); |
|
148 | + |
|
149 | + // make sure the work directory exists |
|
150 | + if (!file_exists(dirname($pdfFile))) { |
|
151 | + Filesystem::makeFolder(dirname($pdfFile)); |
|
152 | + } |
|
153 | + |
|
154 | + //decide the domain to use in generation |
|
155 | + $pdfBaseUrl = $this->getPDFBaseURL(); |
|
156 | + |
|
157 | + // Force http protocol on CWP - fetching from localhost without using the proxy, SSL terminates on gateway. |
|
158 | + if (Environment::getEnv('CWP_ENVIRONMENT')) { |
|
159 | + Config::modify()->set(Director::class, 'alternate_protocol', 'http'); |
|
160 | + //only set alternate protocol if CWP_SECURE_DOMAIN is defined OR pdf_base_url is |
|
161 | + if ($pdfBaseUrl) { |
|
162 | + Config::modify()->set(Director::class, 'alternate_base_url', 'http://' . $pdfBaseUrl); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + $bodyViewer = $this->getViewer('pdf'); |
|
167 | + |
|
168 | + // write the output of this page to HTML, ready for conversion to PDF |
|
169 | + file_put_contents($bodyFile, $bodyViewer->process($this)); |
|
170 | + |
|
171 | + // get the viewer for the current template with _pdffooter |
|
172 | + $footerViewer = $this->getViewer('pdffooter'); |
|
173 | + |
|
174 | + // write the output of the footer template to HTML, ready for conversion to PDF |
|
175 | + file_put_contents($footerFile, $footerViewer->process($this)); |
|
176 | + |
|
177 | + //decide what the proxy should look like |
|
178 | + $proxy = $this->getPDFProxy($pdfBaseUrl); |
|
179 | + |
|
180 | + // finally, generate the PDF |
|
181 | + $command = $binaryPath . $proxy . ' --outline -B 40pt -L 20pt -R 20pt -T 20pt --encoding utf-8 ' |
|
182 | + . '--orientation Portrait --disable-javascript --quiet --print-media-type '; |
|
183 | + $retVal = 0; |
|
184 | + $output = array(); |
|
185 | + exec( |
|
186 | + $command . " --footer-html \"$footerFile\" \"$bodyFile\" \"$pdfFile\" &> /dev/stdout", |
|
187 | + $output, |
|
188 | + $retVal |
|
189 | + ); |
|
190 | + |
|
191 | + // remove temporary file |
|
192 | + unlink($bodyFile); |
|
193 | + unlink($footerFile); |
|
194 | + |
|
195 | + // output any errors |
|
196 | + if ($retVal != 0) { |
|
197 | + user_error('wkhtmltopdf failed: ' . implode("\n", $output), E_USER_ERROR); |
|
198 | + } |
|
199 | + |
|
200 | + // serve the generated file |
|
201 | + return HTTPRequest::send_file(file_get_contents($pdfFile), basename($pdfFile), 'application/pdf'); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Site search form |
|
206 | + */ |
|
207 | + public function SearchForm() |
|
208 | + { |
|
209 | + $searchText = $this->getRequest()->getVar('Search'); |
|
210 | + |
|
211 | + $fields = FieldList::create( |
|
212 | + TextField::create('Search', false, $searchText) |
|
213 | + ); |
|
214 | + $actions = FieldList::create( |
|
215 | + FormAction::create('results', _t('SilverStripe\\CMS\\Search\\SearchForm.GO', 'Go')) |
|
216 | + ); |
|
217 | + |
|
218 | + $form = SearchForm::create($this, SearchForm::class, $fields, $actions); |
|
219 | + $form->setFormAction('search/SearchForm'); |
|
220 | + |
|
221 | + return $form; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Get search form with _header suffix |
|
226 | + * |
|
227 | + * @return SearchForm |
|
228 | + */ |
|
229 | + public function HeaderSearchForm() |
|
230 | + { |
|
231 | + return $this->SearchForm()->setTemplate('SearchForm_header'); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Process and render search results. |
|
236 | + * |
|
237 | + * @param array $data The raw request data submitted by user |
|
238 | + * @param SearchForm $form The form instance that was submitted |
|
239 | + * @param HTTPRequest $request Request generated for this action |
|
240 | + * @return DBHTMLText |
|
241 | + */ |
|
242 | + public function results($data, $form, $request) |
|
243 | + { |
|
244 | + // Check parameters for terms, pagination, and if we should follow suggestions |
|
245 | + $keywords = empty($data['Search']) ? '' : $data['Search']; |
|
246 | + $start = isset($data['start']) ? $data['start'] : 0; |
|
247 | + $suggestions = isset($data['suggestions']) |
|
248 | + ? $data['suggestions'] |
|
249 | + : $this->config()->search_follow_suggestions; |
|
250 | + |
|
251 | + $results = CwpSearchEngine::create() |
|
252 | + ->search( |
|
253 | + $keywords, |
|
254 | + $this->getClassesToSearch(), |
|
255 | + $this->getSearchIndex(), |
|
256 | + $this->getSearchPageSize(), |
|
257 | + $start, |
|
258 | + $suggestions |
|
259 | + ); |
|
260 | + |
|
261 | + // Customise content with these results |
|
262 | + $properties = [ |
|
263 | + 'MetaTitle' => _t(__CLASS__ . '.MetaTitle', 'Search {keywords}', ['keywords' => $keywords]), |
|
264 | + 'NoSearchResults' => _t(__CLASS__ . '.NoResult', 'Sorry, your search query did not return any results.'), |
|
265 | + 'EmptySearch' => _t(__CLASS__ . '.EmptySearch', 'Search field empty, please enter your search query.'), |
|
266 | + 'PdfLink' => '', |
|
267 | + 'Title' => _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results'), |
|
268 | + ]; |
|
269 | + $this->extend('updateSearchResults', $results, $properties); |
|
270 | + |
|
271 | + // Customise page |
|
272 | + $response = $this->customise($properties); |
|
273 | + if ($results) { |
|
274 | + $response = $response |
|
275 | + ->customise($results) |
|
276 | + ->customise(array( 'Results' => $results->getResults() )); |
|
277 | + } |
|
278 | + |
|
279 | + // Render |
|
280 | + $templates = $this->getResultsTemplate($request); |
|
281 | + return $response->renderWith($templates); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Select the template to render search results with |
|
286 | + * |
|
287 | + * @param HTTPRequest $request |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + protected function getResultsTemplate($request) |
|
291 | + { |
|
292 | + $templates = [Page::class . '_results', Page::class]; |
|
293 | + if ($request->getVar('format') == 'rss') { |
|
294 | + array_unshift($templates, 'Page_results_rss'); |
|
295 | + } |
|
296 | + if ($request->getVar('format') == 'atom') { |
|
297 | + array_unshift($templates, 'Page_results_atom'); |
|
298 | + } |
|
299 | + return $templates; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Provide current year. |
|
304 | + */ |
|
305 | + public function CurrentDatetime() |
|
306 | + { |
|
307 | + return DBDatetime::now(); |
|
308 | + } |
|
309 | + |
|
310 | + public function getRSSLink() |
|
311 | + { |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Get the search index registered for this application |
|
316 | + * |
|
317 | + * @return CwpSearchIndex |
|
318 | + */ |
|
319 | + protected function getSearchIndex() |
|
320 | + { |
|
321 | + // Will be a service name in 2.0 and returned via injector |
|
322 | + /** @var CwpSearchIndex $index */ |
|
323 | + $index = null; |
|
324 | + if (self::$search_index_class) { |
|
325 | + $index = Injector::inst()->get(self::$search_index_class); |
|
326 | + } |
|
327 | + return $index; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Gets the list of configured classes to search |
|
332 | + * |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected function getClassesToSearch() |
|
336 | + { |
|
337 | + // Will be private static config in 2.0 |
|
338 | + return self::$classes_to_search; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Get page size for search |
|
343 | + * |
|
344 | + * @return int |
|
345 | + */ |
|
346 | + protected function getSearchPageSize() |
|
347 | + { |
|
348 | + // Will be private static config in 2.0 |
|
349 | + return self::$results_per_page; |
|
350 | + } |
|
351 | 351 | } |
@@ -7,57 +7,57 @@ |
||
7 | 7 | |
8 | 8 | class EventHolder extends DatedUpdateHolder |
9 | 9 | { |
10 | - private static $description = 'Container page for Event Pages, provides event filtering and pagination'; |
|
11 | - |
|
12 | - private static $allowed_children = [ |
|
13 | - EventPage::class, |
|
14 | - ]; |
|
15 | - |
|
16 | - private static $default_child = EventPage::class; |
|
17 | - |
|
18 | - private static $update_name = 'Events'; |
|
19 | - |
|
20 | - private static $update_class = EventPage::class; |
|
21 | - |
|
22 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_holder.png'; |
|
23 | - |
|
24 | - private static $singular_name = 'Event Holder'; |
|
25 | - |
|
26 | - private static $plural_name = 'Event Holders'; |
|
27 | - |
|
28 | - private static $table_name = 'EventHolder'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Find all site's news items, based on some filters. |
|
32 | - * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | - * |
|
34 | - * @param string $className The name of the class to fetch. |
|
35 | - * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | - * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | - * @param string $dateFrom The beginning of a date filter range. |
|
38 | - * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | - * @param int $year Numeric value of the year to show. |
|
40 | - * @param int $monthNumber Numeric value of the month to show. |
|
41 | - * |
|
42 | - * @returns DataList|PaginatedList |
|
43 | - */ |
|
44 | - public static function AllUpdates( |
|
45 | - $className = 'Events', |
|
46 | - $parentID = null, |
|
47 | - $tagID = null, |
|
48 | - $dateFrom = null, |
|
49 | - $dateTo = null, |
|
50 | - $year = null, |
|
51 | - $monthNumber = null |
|
52 | - ) { |
|
53 | - return parent::AllUpdates( |
|
54 | - $className, |
|
55 | - $parentID, |
|
56 | - $tagID, |
|
57 | - $dateFrom, |
|
58 | - $dateTo, |
|
59 | - $year, |
|
60 | - $monthNumber |
|
61 | - )->Sort('Date', 'ASC'); |
|
62 | - } |
|
10 | + private static $description = 'Container page for Event Pages, provides event filtering and pagination'; |
|
11 | + |
|
12 | + private static $allowed_children = [ |
|
13 | + EventPage::class, |
|
14 | + ]; |
|
15 | + |
|
16 | + private static $default_child = EventPage::class; |
|
17 | + |
|
18 | + private static $update_name = 'Events'; |
|
19 | + |
|
20 | + private static $update_class = EventPage::class; |
|
21 | + |
|
22 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_holder.png'; |
|
23 | + |
|
24 | + private static $singular_name = 'Event Holder'; |
|
25 | + |
|
26 | + private static $plural_name = 'Event Holders'; |
|
27 | + |
|
28 | + private static $table_name = 'EventHolder'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Find all site's news items, based on some filters. |
|
32 | + * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | + * |
|
34 | + * @param string $className The name of the class to fetch. |
|
35 | + * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | + * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | + * @param string $dateFrom The beginning of a date filter range. |
|
38 | + * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | + * @param int $year Numeric value of the year to show. |
|
40 | + * @param int $monthNumber Numeric value of the month to show. |
|
41 | + * |
|
42 | + * @returns DataList|PaginatedList |
|
43 | + */ |
|
44 | + public static function AllUpdates( |
|
45 | + $className = 'Events', |
|
46 | + $parentID = null, |
|
47 | + $tagID = null, |
|
48 | + $dateFrom = null, |
|
49 | + $dateTo = null, |
|
50 | + $year = null, |
|
51 | + $monthNumber = null |
|
52 | + ) { |
|
53 | + return parent::AllUpdates( |
|
54 | + $className, |
|
55 | + $parentID, |
|
56 | + $tagID, |
|
57 | + $dateFrom, |
|
58 | + $dateTo, |
|
59 | + $year, |
|
60 | + $monthNumber |
|
61 | + )->Sort('Date', 'ASC'); |
|
62 | + } |
|
63 | 63 | } |
@@ -7,50 +7,50 @@ |
||
7 | 7 | |
8 | 8 | class NewsHolder extends DatedUpdateHolder |
9 | 9 | { |
10 | - private static $description = 'Container page for News Pages, provides news filtering and pagination'; |
|
11 | - |
|
12 | - private static $allowed_children = [ |
|
13 | - NewsPage::class, |
|
14 | - ]; |
|
15 | - |
|
16 | - private static $default_child = NewsPage::class; |
|
17 | - |
|
18 | - private static $update_name = 'News'; |
|
19 | - |
|
20 | - private static $update_class = NewsPage::class; |
|
21 | - |
|
22 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/news_listing.png'; |
|
23 | - |
|
24 | - private static $singular_name = 'News Holder'; |
|
25 | - |
|
26 | - private static $plural_name = 'News Holders'; |
|
27 | - |
|
28 | - private static $table_name = 'NewsHolder'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Find all site's news items, based on some filters. |
|
32 | - * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | - * |
|
34 | - * @param string $className The name of the class to fetch. |
|
35 | - * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | - * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | - * @param string $dateFrom The beginning of a date filter range. |
|
38 | - * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | - * @param int $year Numeric value of the year to show. |
|
40 | - * @param int $monthNumber Numeric value of the month to show. |
|
41 | - * |
|
42 | - * @returns DataList|PaginatedList |
|
43 | - */ |
|
44 | - public static function AllUpdates( |
|
45 | - $className = NewsPage::class, |
|
46 | - $parentID = null, |
|
47 | - $tagID = null, |
|
48 | - $dateFrom = null, |
|
49 | - $dateTo = null, |
|
50 | - $year = null, |
|
51 | - $monthNumber = null |
|
52 | - ) { |
|
53 | - return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber) |
|
54 | - ->Sort('Date', 'DESC'); |
|
55 | - } |
|
10 | + private static $description = 'Container page for News Pages, provides news filtering and pagination'; |
|
11 | + |
|
12 | + private static $allowed_children = [ |
|
13 | + NewsPage::class, |
|
14 | + ]; |
|
15 | + |
|
16 | + private static $default_child = NewsPage::class; |
|
17 | + |
|
18 | + private static $update_name = 'News'; |
|
19 | + |
|
20 | + private static $update_class = NewsPage::class; |
|
21 | + |
|
22 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/news_listing.png'; |
|
23 | + |
|
24 | + private static $singular_name = 'News Holder'; |
|
25 | + |
|
26 | + private static $plural_name = 'News Holders'; |
|
27 | + |
|
28 | + private static $table_name = 'NewsHolder'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Find all site's news items, based on some filters. |
|
32 | + * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | + * |
|
34 | + * @param string $className The name of the class to fetch. |
|
35 | + * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | + * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | + * @param string $dateFrom The beginning of a date filter range. |
|
38 | + * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | + * @param int $year Numeric value of the year to show. |
|
40 | + * @param int $monthNumber Numeric value of the month to show. |
|
41 | + * |
|
42 | + * @returns DataList|PaginatedList |
|
43 | + */ |
|
44 | + public static function AllUpdates( |
|
45 | + $className = NewsPage::class, |
|
46 | + $parentID = null, |
|
47 | + $tagID = null, |
|
48 | + $dateFrom = null, |
|
49 | + $dateTo = null, |
|
50 | + $year = null, |
|
51 | + $monthNumber = null |
|
52 | + ) { |
|
53 | + return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber) |
|
54 | + ->Sort('Date', 'DESC'); |
|
55 | + } |
|
56 | 56 | } |
@@ -19,53 +19,53 @@ |
||
19 | 19 | */ |
20 | 20 | class EventHolderController extends DatedUpdateHolderController |
21 | 21 | { |
22 | - public function getUpdateName() |
|
23 | - { |
|
24 | - $params = $this->parseParams(); |
|
25 | - if ($params['upcomingOnly']) { |
|
26 | - return _t('CWP\\CWP\\PageTypes\\EventHolder.Upcoming', 'Upcoming events'); |
|
27 | - } |
|
22 | + public function getUpdateName() |
|
23 | + { |
|
24 | + $params = $this->parseParams(); |
|
25 | + if ($params['upcomingOnly']) { |
|
26 | + return _t('CWP\\CWP\\PageTypes\\EventHolder.Upcoming', 'Upcoming events'); |
|
27 | + } |
|
28 | 28 | |
29 | - return 'Events'; |
|
30 | - } |
|
29 | + return 'Events'; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Parse URL parameters. |
|
34 | - * |
|
35 | - * @param boolean $produceErrorMessages Set to false to omit session messages. |
|
36 | - */ |
|
37 | - public function parseParams($produceErrorMessages = true) |
|
38 | - { |
|
39 | - $params = parent::parseParams($produceErrorMessages); |
|
32 | + /** |
|
33 | + * Parse URL parameters. |
|
34 | + * |
|
35 | + * @param boolean $produceErrorMessages Set to false to omit session messages. |
|
36 | + */ |
|
37 | + public function parseParams($produceErrorMessages = true) |
|
38 | + { |
|
39 | + $params = parent::parseParams($produceErrorMessages); |
|
40 | 40 | |
41 | - // We need to set whether or not we're supposed to be displaying only upcoming events or all events. |
|
42 | - $params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']); |
|
41 | + // We need to set whether or not we're supposed to be displaying only upcoming events or all events. |
|
42 | + $params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']); |
|
43 | 43 | |
44 | - return $params; |
|
45 | - } |
|
44 | + return $params; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get the events based on the current query. |
|
49 | - */ |
|
50 | - public function FilteredUpdates($pageSize = 20) |
|
51 | - { |
|
52 | - $params = $this->parseParams(); |
|
47 | + /** |
|
48 | + * Get the events based on the current query. |
|
49 | + */ |
|
50 | + public function FilteredUpdates($pageSize = 20) |
|
51 | + { |
|
52 | + $params = $this->parseParams(); |
|
53 | 53 | |
54 | - $items = $this->Updates( |
|
55 | - $params['tag'], |
|
56 | - $params['from'], |
|
57 | - $params['to'], |
|
58 | - $params['year'], |
|
59 | - $params['month'] |
|
60 | - ); |
|
54 | + $items = $this->Updates( |
|
55 | + $params['tag'], |
|
56 | + $params['from'], |
|
57 | + $params['to'], |
|
58 | + $params['year'], |
|
59 | + $params['month'] |
|
60 | + ); |
|
61 | 61 | |
62 | - if ($params['upcomingOnly']) { |
|
63 | - $items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]); |
|
64 | - } |
|
62 | + if ($params['upcomingOnly']) { |
|
63 | + $items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]); |
|
64 | + } |
|
65 | 65 | |
66 | - // Apply pagination |
|
67 | - $list = PaginatedList::create($items, $this->getRequest()); |
|
68 | - $list->setPageLength($pageSize); |
|
69 | - return $list; |
|
70 | - } |
|
66 | + // Apply pagination |
|
67 | + $list = PaginatedList::create($items, $this->getRequest()); |
|
68 | + $list->setPageLength($pageSize); |
|
69 | + return $list; |
|
70 | + } |
|
71 | 71 | } |
@@ -12,81 +12,81 @@ |
||
12 | 12 | |
13 | 13 | class EventPage extends DatedUpdatePage |
14 | 14 | { |
15 | - private static $description = 'Describes an event occurring on a specific date.'; |
|
16 | - |
|
17 | - private static $default_parent = EventHolder::class; |
|
18 | - |
|
19 | - private static $can_be_root = false; |
|
20 | - |
|
21 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png'; |
|
22 | - |
|
23 | - private static $singular_name = 'Event Page'; |
|
24 | - |
|
25 | - private static $plural_name = 'Event Pages'; |
|
26 | - |
|
27 | - private static $db = [ |
|
28 | - 'StartTime' => 'Time', |
|
29 | - 'EndTime' => 'Time', |
|
30 | - 'Location' => 'Text', |
|
31 | - ]; |
|
32 | - |
|
33 | - private static $table_name = 'EventPage'; |
|
34 | - |
|
35 | - public function fieldLabels($includerelations = true) |
|
36 | - { |
|
37 | - $labels = parent::fieldLabels($includerelations); |
|
38 | - $labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time'); |
|
39 | - $labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time'); |
|
40 | - $labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location'); |
|
41 | - |
|
42 | - return $labels; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Add the default for the Date being the current day. |
|
47 | - */ |
|
48 | - public function populateDefaults() |
|
49 | - { |
|
50 | - if (!isset($this->Date) || $this->Date === null) { |
|
51 | - $this->Date = DBDatetime::now()->Format('y-MM-dd'); |
|
52 | - } |
|
53 | - |
|
54 | - if (!isset($this->StartTime) || $this->StartTime === null) { |
|
55 | - $this->StartTime = '09:00:00'; |
|
56 | - } |
|
57 | - |
|
58 | - if (!isset($this->EndTime) || $this->EndTime === null) { |
|
59 | - $this->EndTime = '17:00:00'; |
|
60 | - } |
|
61 | - |
|
62 | - parent::populateDefaults(); |
|
63 | - } |
|
64 | - |
|
65 | - public function getCMSFields() |
|
66 | - { |
|
67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
68 | - $fields->removeByName('Date'); |
|
69 | - |
|
70 | - $dateTimeFields = array(); |
|
71 | - |
|
72 | - $dateTimeFields[] = $dateField = DateField::create('Date', 'Date'); |
|
73 | - $dateTimeFields[] = $startTimeField = TimeField::create( |
|
74 | - 'StartTime', |
|
75 | - ' ' . $this->fieldLabel('StartTime') |
|
76 | - ); |
|
77 | - $dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime')); |
|
78 | - |
|
79 | - $fields->addFieldsToTab('Root.Main', [ |
|
80 | - $dateTimeField = FieldGroup::create('Date and time', $dateTimeFields), |
|
81 | - $locationField = TextareaField::create('Location', $this->fieldLabel('Location')) |
|
82 | - ], 'Abstract'); |
|
83 | - $locationField->setRows(4); |
|
84 | - }); |
|
85 | - return parent::getCMSFields(); |
|
86 | - } |
|
87 | - |
|
88 | - public function NiceLocation() |
|
89 | - { |
|
90 | - return nl2br(Convert::raw2xml($this->Location), true); |
|
91 | - } |
|
15 | + private static $description = 'Describes an event occurring on a specific date.'; |
|
16 | + |
|
17 | + private static $default_parent = EventHolder::class; |
|
18 | + |
|
19 | + private static $can_be_root = false; |
|
20 | + |
|
21 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png'; |
|
22 | + |
|
23 | + private static $singular_name = 'Event Page'; |
|
24 | + |
|
25 | + private static $plural_name = 'Event Pages'; |
|
26 | + |
|
27 | + private static $db = [ |
|
28 | + 'StartTime' => 'Time', |
|
29 | + 'EndTime' => 'Time', |
|
30 | + 'Location' => 'Text', |
|
31 | + ]; |
|
32 | + |
|
33 | + private static $table_name = 'EventPage'; |
|
34 | + |
|
35 | + public function fieldLabels($includerelations = true) |
|
36 | + { |
|
37 | + $labels = parent::fieldLabels($includerelations); |
|
38 | + $labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time'); |
|
39 | + $labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time'); |
|
40 | + $labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location'); |
|
41 | + |
|
42 | + return $labels; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Add the default for the Date being the current day. |
|
47 | + */ |
|
48 | + public function populateDefaults() |
|
49 | + { |
|
50 | + if (!isset($this->Date) || $this->Date === null) { |
|
51 | + $this->Date = DBDatetime::now()->Format('y-MM-dd'); |
|
52 | + } |
|
53 | + |
|
54 | + if (!isset($this->StartTime) || $this->StartTime === null) { |
|
55 | + $this->StartTime = '09:00:00'; |
|
56 | + } |
|
57 | + |
|
58 | + if (!isset($this->EndTime) || $this->EndTime === null) { |
|
59 | + $this->EndTime = '17:00:00'; |
|
60 | + } |
|
61 | + |
|
62 | + parent::populateDefaults(); |
|
63 | + } |
|
64 | + |
|
65 | + public function getCMSFields() |
|
66 | + { |
|
67 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
68 | + $fields->removeByName('Date'); |
|
69 | + |
|
70 | + $dateTimeFields = array(); |
|
71 | + |
|
72 | + $dateTimeFields[] = $dateField = DateField::create('Date', 'Date'); |
|
73 | + $dateTimeFields[] = $startTimeField = TimeField::create( |
|
74 | + 'StartTime', |
|
75 | + ' ' . $this->fieldLabel('StartTime') |
|
76 | + ); |
|
77 | + $dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime')); |
|
78 | + |
|
79 | + $fields->addFieldsToTab('Root.Main', [ |
|
80 | + $dateTimeField = FieldGroup::create('Date and time', $dateTimeFields), |
|
81 | + $locationField = TextareaField::create('Location', $this->fieldLabel('Location')) |
|
82 | + ], 'Abstract'); |
|
83 | + $locationField->setRows(4); |
|
84 | + }); |
|
85 | + return parent::getCMSFields(); |
|
86 | + } |
|
87 | + |
|
88 | + public function NiceLocation() |
|
89 | + { |
|
90 | + return nl2br(Convert::raw2xml($this->Location), true); |
|
91 | + } |
|
92 | 92 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | |
65 | 65 | public function getCMSFields() |
66 | 66 | { |
67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
67 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
68 | 68 | $fields->removeByName('Date'); |
69 | 69 | |
70 | 70 | $dateTimeFields = array(); |
@@ -9,55 +9,55 @@ |
||
9 | 9 | |
10 | 10 | class NewsPage extends DatedUpdatePage |
11 | 11 | { |
12 | - private static $description = 'Describes an item of news'; |
|
12 | + private static $description = 'Describes an item of news'; |
|
13 | 13 | |
14 | - private static $default_parent = 'NewsHolderPage'; |
|
14 | + private static $default_parent = 'NewsHolderPage'; |
|
15 | 15 | |
16 | - private static $can_be_root = false; |
|
16 | + private static $can_be_root = false; |
|
17 | 17 | |
18 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png'; |
|
18 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png'; |
|
19 | 19 | |
20 | - private static $singular_name = 'News Page'; |
|
20 | + private static $singular_name = 'News Page'; |
|
21 | 21 | |
22 | - private static $plural_name = 'News Pages'; |
|
22 | + private static $plural_name = 'News Pages'; |
|
23 | 23 | |
24 | - private static $db = [ |
|
25 | - 'Author' => 'Varchar(255)', |
|
26 | - ]; |
|
24 | + private static $db = [ |
|
25 | + 'Author' => 'Varchar(255)', |
|
26 | + ]; |
|
27 | 27 | |
28 | - private static $has_one = [ |
|
29 | - 'FeaturedImage' => Image::class, |
|
30 | - ]; |
|
28 | + private static $has_one = [ |
|
29 | + 'FeaturedImage' => Image::class, |
|
30 | + ]; |
|
31 | 31 | |
32 | - private static $table_name = 'NewsPage'; |
|
32 | + private static $table_name = 'NewsPage'; |
|
33 | 33 | |
34 | - public function fieldLabels($includerelations = true) |
|
35 | - { |
|
36 | - $labels = parent::fieldLabels($includerelations); |
|
37 | - $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
38 | - $labels['FeaturedImageID'] = _t( |
|
39 | - 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
40 | - 'Featured Image' |
|
41 | - ); |
|
34 | + public function fieldLabels($includerelations = true) |
|
35 | + { |
|
36 | + $labels = parent::fieldLabels($includerelations); |
|
37 | + $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
38 | + $labels['FeaturedImageID'] = _t( |
|
39 | + 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
40 | + 'Featured Image' |
|
41 | + ); |
|
42 | 42 | |
43 | - return $labels; |
|
44 | - } |
|
43 | + return $labels; |
|
44 | + } |
|
45 | 45 | |
46 | - public function getCMSFields() |
|
47 | - { |
|
48 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
49 | - $fields->addFieldToTab( |
|
50 | - 'Root.Main', |
|
51 | - TextField::create('Author', $this->fieldLabel('Author')), |
|
52 | - 'Abstract' |
|
53 | - ); |
|
46 | + public function getCMSFields() |
|
47 | + { |
|
48 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
49 | + $fields->addFieldToTab( |
|
50 | + 'Root.Main', |
|
51 | + TextField::create('Author', $this->fieldLabel('Author')), |
|
52 | + 'Abstract' |
|
53 | + ); |
|
54 | 54 | |
55 | - $fields->addFieldToTab( |
|
56 | - 'Root.Main', |
|
57 | - UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
58 | - 'Abstract' |
|
59 | - ); |
|
60 | - }); |
|
61 | - return parent::getCMSFields(); |
|
62 | - } |
|
55 | + $fields->addFieldToTab( |
|
56 | + 'Root.Main', |
|
57 | + UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
58 | + 'Abstract' |
|
59 | + ); |
|
60 | + }); |
|
61 | + return parent::getCMSFields(); |
|
62 | + } |
|
63 | 63 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | |
46 | 46 | public function getCMSFields() |
47 | 47 | { |
48 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
48 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
49 | 49 | $fields->addFieldToTab( |
50 | 50 | 'Root.Main', |
51 | 51 | TextField::create('Author', $this->fieldLabel('Author')), |
@@ -7,42 +7,42 @@ |
||
7 | 7 | |
8 | 8 | class SitemapPageController extends PageController |
9 | 9 | { |
10 | - private static $allowed_actions = [ |
|
11 | - 'showpage', |
|
12 | - ]; |
|
13 | - |
|
14 | - private static $url_handlers = [ |
|
15 | - 'page/$ID' => 'showpage', |
|
16 | - ]; |
|
17 | - |
|
18 | - public function showpage($request) |
|
19 | - { |
|
20 | - $id = (int) $request->param('ID'); |
|
21 | - if (!$id) { |
|
22 | - return false; |
|
23 | - } |
|
24 | - $page = SiteTree::get()->byId($id); |
|
25 | - |
|
26 | - // does the page exist? |
|
27 | - if (!($page && $page->exists())) { |
|
28 | - return $this->httpError(404); |
|
29 | - } |
|
30 | - |
|
31 | - // can the page be viewed? |
|
32 | - if (!$page->canView()) { |
|
33 | - return $this->httpError(403); |
|
34 | - } |
|
35 | - |
|
36 | - $viewer = $this->customise([ |
|
37 | - 'IsAjax' => $request->isAjax(), |
|
38 | - 'SelectedPage' => $page, |
|
39 | - 'Children' => $page->Children(), |
|
40 | - ]); |
|
41 | - |
|
42 | - if ($request->isAjax()) { |
|
43 | - return $viewer->renderWith('SitemapNodeChildren'); |
|
44 | - } |
|
45 | - |
|
46 | - return $viewer; |
|
47 | - } |
|
10 | + private static $allowed_actions = [ |
|
11 | + 'showpage', |
|
12 | + ]; |
|
13 | + |
|
14 | + private static $url_handlers = [ |
|
15 | + 'page/$ID' => 'showpage', |
|
16 | + ]; |
|
17 | + |
|
18 | + public function showpage($request) |
|
19 | + { |
|
20 | + $id = (int) $request->param('ID'); |
|
21 | + if (!$id) { |
|
22 | + return false; |
|
23 | + } |
|
24 | + $page = SiteTree::get()->byId($id); |
|
25 | + |
|
26 | + // does the page exist? |
|
27 | + if (!($page && $page->exists())) { |
|
28 | + return $this->httpError(404); |
|
29 | + } |
|
30 | + |
|
31 | + // can the page be viewed? |
|
32 | + if (!$page->canView()) { |
|
33 | + return $this->httpError(403); |
|
34 | + } |
|
35 | + |
|
36 | + $viewer = $this->customise([ |
|
37 | + 'IsAjax' => $request->isAjax(), |
|
38 | + 'SelectedPage' => $page, |
|
39 | + 'Children' => $page->Children(), |
|
40 | + ]); |
|
41 | + |
|
42 | + if ($request->isAjax()) { |
|
43 | + return $viewer->renderWith('SitemapNodeChildren'); |
|
44 | + } |
|
45 | + |
|
46 | + return $viewer; |
|
47 | + } |
|
48 | 48 | } |
@@ -11,117 +11,117 @@ |
||
11 | 11 | |
12 | 12 | class Quicklink extends DataObject |
13 | 13 | { |
14 | - private static $db = [ |
|
15 | - 'Name' => 'Varchar(255)', |
|
16 | - 'ExternalLink' => 'Varchar(255)', |
|
17 | - 'SortOrder' => 'Int', |
|
18 | - ]; |
|
19 | - |
|
20 | - private static $has_one = [ |
|
21 | - 'Parent' => BaseHomePage::class, |
|
22 | - 'InternalLink' => SiteTree::class, |
|
23 | - ]; |
|
24 | - |
|
25 | - private static $summary_fields = [ |
|
26 | - 'Name' => 'Name', |
|
27 | - 'InternalLink.Title' => 'Internal Link', |
|
28 | - 'ExternalLink' => 'External Link', |
|
29 | - ]; |
|
30 | - |
|
31 | - private static $table_name = 'Quicklink'; |
|
32 | - |
|
33 | - public function fieldLabels($includerelations = true) |
|
34 | - { |
|
35 | - $labels = parent::fieldLabels($includerelations); |
|
36 | - $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
37 | - $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
38 | - $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
39 | - $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
40 | - $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
41 | - |
|
42 | - return $labels; |
|
43 | - } |
|
44 | - |
|
45 | - public function getLink() |
|
46 | - { |
|
47 | - if ($this->ExternalLink) { |
|
48 | - $url = parse_url($this->ExternalLink); |
|
49 | - |
|
50 | - // if no scheme set in the link, default to http |
|
51 | - if (!isset($url['scheme'])) { |
|
52 | - return 'http://' . $this->ExternalLink; |
|
53 | - } |
|
54 | - |
|
55 | - return $this->ExternalLink; |
|
56 | - } elseif ($this->InternalLinkID) { |
|
57 | - return $this->InternalLink()->Link(); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - public function canCreate($member = null, $context = []) |
|
62 | - { |
|
63 | - return $this->Parent()->canCreate($member, $context); |
|
64 | - } |
|
65 | - |
|
66 | - public function canEdit($member = null) |
|
67 | - { |
|
68 | - return $this->Parent()->canEdit($member); |
|
69 | - } |
|
70 | - |
|
71 | - public function canDelete($member = null) |
|
72 | - { |
|
73 | - return $this->Parent()->canDelete($member); |
|
74 | - } |
|
75 | - |
|
76 | - public function canView($member = null) |
|
77 | - { |
|
78 | - return $this->Parent()->canView($member); |
|
79 | - } |
|
80 | - |
|
81 | - public function getCMSFields() |
|
82 | - { |
|
83 | - $fields = parent::getCMSFields(); |
|
84 | - |
|
85 | - $fields->removeByName('ParentID'); |
|
86 | - |
|
87 | - $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
88 | - |
|
89 | - $fields->removeByName('ExternalLink'); |
|
90 | - $fields->removeByName('InternalLinkID'); |
|
91 | - $fields->removeByName('SortOrder'); |
|
92 | - $externalLinkField->addExtraClass('noBorder'); |
|
93 | - |
|
94 | - $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
95 | - array( |
|
96 | - TreeDropdownField::create( |
|
97 | - 'InternalLinkID', |
|
98 | - $this->fieldLabel('InternalLinkID'), |
|
99 | - SiteTree::class |
|
100 | - ), |
|
101 | - $externalLinkField, |
|
102 | - $wrap = CompositeField::create( |
|
103 | - $extraLabel = LiteralField::create( |
|
104 | - 'NoteOverride', |
|
105 | - sprintf('<div class="message good notice">%s</div>', _t( |
|
106 | - __CLASS__ . '.Note', |
|
107 | - 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
108 | - )) |
|
109 | - ) |
|
110 | - ) |
|
111 | - ) |
|
112 | - )); |
|
113 | - $fields->insertBefore( |
|
114 | - 'Name', |
|
115 | - LiteralField::create( |
|
116 | - 'Note', |
|
117 | - sprintf('<p>%s</p>', _t( |
|
118 | - __CLASS__ . '.Note2', |
|
119 | - 'Use this to specify a link to a page either on this site ' |
|
120 | - . '(Internal Link) or another site (External Link).' |
|
121 | - )) |
|
122 | - ) |
|
123 | - ); |
|
124 | - |
|
125 | - return $fields; |
|
126 | - } |
|
14 | + private static $db = [ |
|
15 | + 'Name' => 'Varchar(255)', |
|
16 | + 'ExternalLink' => 'Varchar(255)', |
|
17 | + 'SortOrder' => 'Int', |
|
18 | + ]; |
|
19 | + |
|
20 | + private static $has_one = [ |
|
21 | + 'Parent' => BaseHomePage::class, |
|
22 | + 'InternalLink' => SiteTree::class, |
|
23 | + ]; |
|
24 | + |
|
25 | + private static $summary_fields = [ |
|
26 | + 'Name' => 'Name', |
|
27 | + 'InternalLink.Title' => 'Internal Link', |
|
28 | + 'ExternalLink' => 'External Link', |
|
29 | + ]; |
|
30 | + |
|
31 | + private static $table_name = 'Quicklink'; |
|
32 | + |
|
33 | + public function fieldLabels($includerelations = true) |
|
34 | + { |
|
35 | + $labels = parent::fieldLabels($includerelations); |
|
36 | + $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
37 | + $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
38 | + $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
39 | + $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
40 | + $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
41 | + |
|
42 | + return $labels; |
|
43 | + } |
|
44 | + |
|
45 | + public function getLink() |
|
46 | + { |
|
47 | + if ($this->ExternalLink) { |
|
48 | + $url = parse_url($this->ExternalLink); |
|
49 | + |
|
50 | + // if no scheme set in the link, default to http |
|
51 | + if (!isset($url['scheme'])) { |
|
52 | + return 'http://' . $this->ExternalLink; |
|
53 | + } |
|
54 | + |
|
55 | + return $this->ExternalLink; |
|
56 | + } elseif ($this->InternalLinkID) { |
|
57 | + return $this->InternalLink()->Link(); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + public function canCreate($member = null, $context = []) |
|
62 | + { |
|
63 | + return $this->Parent()->canCreate($member, $context); |
|
64 | + } |
|
65 | + |
|
66 | + public function canEdit($member = null) |
|
67 | + { |
|
68 | + return $this->Parent()->canEdit($member); |
|
69 | + } |
|
70 | + |
|
71 | + public function canDelete($member = null) |
|
72 | + { |
|
73 | + return $this->Parent()->canDelete($member); |
|
74 | + } |
|
75 | + |
|
76 | + public function canView($member = null) |
|
77 | + { |
|
78 | + return $this->Parent()->canView($member); |
|
79 | + } |
|
80 | + |
|
81 | + public function getCMSFields() |
|
82 | + { |
|
83 | + $fields = parent::getCMSFields(); |
|
84 | + |
|
85 | + $fields->removeByName('ParentID'); |
|
86 | + |
|
87 | + $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
88 | + |
|
89 | + $fields->removeByName('ExternalLink'); |
|
90 | + $fields->removeByName('InternalLinkID'); |
|
91 | + $fields->removeByName('SortOrder'); |
|
92 | + $externalLinkField->addExtraClass('noBorder'); |
|
93 | + |
|
94 | + $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
95 | + array( |
|
96 | + TreeDropdownField::create( |
|
97 | + 'InternalLinkID', |
|
98 | + $this->fieldLabel('InternalLinkID'), |
|
99 | + SiteTree::class |
|
100 | + ), |
|
101 | + $externalLinkField, |
|
102 | + $wrap = CompositeField::create( |
|
103 | + $extraLabel = LiteralField::create( |
|
104 | + 'NoteOverride', |
|
105 | + sprintf('<div class="message good notice">%s</div>', _t( |
|
106 | + __CLASS__ . '.Note', |
|
107 | + 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
108 | + )) |
|
109 | + ) |
|
110 | + ) |
|
111 | + ) |
|
112 | + )); |
|
113 | + $fields->insertBefore( |
|
114 | + 'Name', |
|
115 | + LiteralField::create( |
|
116 | + 'Note', |
|
117 | + sprintf('<p>%s</p>', _t( |
|
118 | + __CLASS__ . '.Note2', |
|
119 | + 'Use this to specify a link to a page either on this site ' |
|
120 | + . '(Internal Link) or another site (External Link).' |
|
121 | + )) |
|
122 | + ) |
|
123 | + ); |
|
124 | + |
|
125 | + return $fields; |
|
126 | + } |
|
127 | 127 | } |