-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n_selection_page.module
113 lines (100 loc) · 3.59 KB
/
i18n_selection_page.module
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
define('LANGUAGE_NEGOTIATION_SELECTION_PAGE', 'language-selection-page');
// theme settings - numeric values for D6 upgrade purposes
define('I18N_SELECTION_PAGE_TEMPLATE_IN_THEME', 32);
define('I18N_SELECTION_PAGE_TEMPLATE_ONLY', 64);
/**
* Implements hook_menu().
*/
function i18n_selection_page_menu() {
$items = array();
$items['admin/config/regional/language/configure/selection_page'] = array(
'title' => 'Language selection page',
'description' => 'Configure the language selection page behavior',
'page callback' => 'drupal_get_form',
'page arguments' => array('i18n_selection_page_admin'),
'access arguments' => array('administer languages'),
'file' => 'i18n_selection_page.admin.inc',
'type' => MENU_VISIBLE_IN_BREADCRUMB
);
$items['language_selection'] = array(
'description' => 'Language selection page',
'page callback' => 'i18n_selection_page_selection_page',
'access arguments' => array('access content'),
'file' => 'i18n_selection_page.pages.inc',
'type' => MENU_NORMAL_ITEM
);
return $items;
}
/**
* Implements hook_language_negotiation_info().
*
* @return array()
*/
function i18n_selection_page_language_negotiation_info() {
$language_providers[LANGUAGE_NEGOTIATION_SELECTION_PAGE] = array(
'types' => array(LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL),
'callbacks' => array(
'language' => 'i18n_selection_page_language',
'switcher' => 'locale_language_switcher_url',
'url_rewrite' => 'locale_language_url_rewrite_url'
),
'file' => drupal_get_path('module', 'i18n_selection_page') . '/i18n_selection_page.module',
'weight' => 50,
'name' => t('Selection Page'),
'description' => t('Show a language selection page to the visitor for making a language choice.'),
'config' => 'admin/config/regional/language/configure/selection_page'
);
return $language_providers;
}
/**
* Language selection callback method
*/
function i18n_selection_page_language($languages) {
require_once('./includes/locale.inc');
require_once('./includes/path.inc');
require_once('./includes/common.inc');
$lang = locale_language_from_url($languages);
if ($lang) {
return $lang;
}
// Don't run this code on the language selection page itself.
if ($_GET['q'] == 'language_selection') {
return;
}
// Don't run this code if we are on a blacklisted path
/*
$blacklist = variable_get('i18n_selection_page_blacklisted_paths', array());
if ((bool) drupal_match_path($_GET['q'], implode("\r\n", $blacklist))) {
return;
}
*/
// @TODO: document this
if (!isset($_SERVER['SERVER_ADDR'])) {
return;
}
// redirect to the language selection page, with the currently requested page as destination
$query = drupal_get_query_parameters();
$query['destination'] = $_GET['q'] ? $_GET['q'] : '<front>';
$language = $GLOBALS['language'];
drupal_goto('language_selection', array('query' => $query, 'absolute' => FALSE, 'language' => LANGUAGE_NONE));
}
/**
* Implements hook_theme().
*/
function i18n_selection_page_theme() {
return array(
'i18n_selection_page' => array(
'arguments' => array('data' => array()),
'path' => drupal_get_path('module', 'i18n_selection_page') . '/themes',
//'file' => '/i18n_selection_page.pages.inc',
'template' => 'i18n_selection_page'
),
'i18n_selection_page_body' => array(
'arguments' => array('data' => array()),
'path' => drupal_get_path('module', 'i18n_selection_page') . '/themes',
//'file' => 'i18n_selection_page.pages.inc',
'template' => 'i18n_selection_page_body'
)
);
}