-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSetlocaleController.php
More file actions
81 lines (71 loc) · 3.1 KB
/
SetlocaleController.php
File metadata and controls
81 lines (71 loc) · 3.1 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
<?php
class Multilanguage_SetlocaleController extends Zend_Controller_Action
{
public function indexAction()
{
$locale = $this->getParam('locale');
if (Zend_Locale::isLocale($locale)) {
$session = new Zend_Session_Namespace('locale');
$session->locale = $locale;
}
// In public front-end, set locale implies interface and content.
$url = null;
// Check if the url has a related record (simple pages, exhibit…) in the
// specified locale, else do a simple redirect for the interface only.
$request = $this->getRequest();
$recordType = $request->getParam('record_type');
switch ($recordType) {
case 'Exhibit':
$recordId = $request->getParam('id');
$record = get_db()->getTable('MultilanguageRelatedRecord')
->findRelatedSourceRecordForLocale($recordType, $recordId, $locale);
if ($record) {
$url = exhibit_builder_exhibit_uri($record);
}
break;
case 'ExhibitPage':
$recordId = $request->getParam('id');
$record = get_db()->getTable('MultilanguageRelatedRecord')
->findRelatedSourceRecordForLocale($recordType, $recordId, $locale);
if ($record) {
$exhibit = get_record_by_id('Exhibit', $record->exhibit_id);
$url = exhibit_builder_exhibit_uri($exhibit, $record);
}
// If the page is not translated, redirect to the summary of the
// translated exhibit, if any.
else {
$record = get_record_by_id('ExhibitPage', $recordId);
$recordType = 'Exhibit';
$recordId = $record->exhibit_id;
$record = get_db()->getTable('MultilanguageRelatedRecord')
->findRelatedSourceRecordForLocale($recordType, $recordId, $locale);
if ($record) {
$url = exhibit_builder_exhibit_uri($record);
}
}
break;
case 'SimplePagesPage':
$recordId = $request->getParam('id');
$record = get_db()->getTable('MultilanguageRelatedRecord')
->findRelatedSourceRecordForLocale($recordType, $recordId, $locale);
if ($record) {
$url = record_url($record);
}
break;
}
if (empty($url)) {
$referer = $request->getHeader('Referer');
$redirect = $this->getParam('redirect', $referer) ?: '/';
// Validation: only accepts relative URLs or from the same domain
$parsedRedirect = parse_url($redirect);
$parsedBase = parse_url(WEB_ROOT);
if (empty($parsedRedirect['host']) ||
$parsedRedirect['host'] === $parsedBase['host']) {
$url = $redirect;
} else {
$url = '/'; // external redirect: go back to the homepage
}
}
$this->getHelper('Redirector')->setPrependBase(false)->goToUrl($url);
}
}