-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathextension.driver.php
129 lines (100 loc) · 3.42 KB
/
extension.driver.php
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
if (!defined('__IN_SYMPHONY__')) {
die('<h2>Symphony Error</h2><p>You cannot directly access this file</p>');
}
require_once EXTENSIONS . '/languages/lib/class.languages.php';
class Extension_Languages extends Extension {
public $field_table = 'tbl_fields_languages';
/*------------------------------------------------------------------------------------------------*/
/* Installation */
/*------------------------------------------------------------------------------------------------*/
public function install() {
return Symphony::Database()->query(sprintf(
"CREATE TABLE `%s` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`field_id` INT(11) UNSIGNED NOT NULL,
`available_codes` VARCHAR(255) NULL,
`allow_multiple_selection` enum('yes','no') NOT NULL default 'no',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
$this->field_table
));
}
public function uninstall() {
try {
Symphony::Database()->query(sprintf(
"DROP TABLE `%s`",
$this->field_table
));
} catch (DatabaseException $dbe) {
// table doesn't exist
}
}
/*------------------------------------------------------------------------------------------------*/
/* Delegates */
/*------------------------------------------------------------------------------------------------*/
public function getSubscribedDelegates() {
return array(
array(
'page' => '/frontend/',
'delegate' => 'ManageEXSLFunctions',
'callback' => 'dManageEXSLFunctions'
),
);
}
public function dManageEXSLFunctions($context) {
$context['manager']->addFunction(
'Extension_Languages::fileExists',
'extension_languages',
'fileExists'
);
}
/*------------------------------------------------------------------------------------------------*/
/* Public interface */
/*------------------------------------------------------------------------------------------------*/
public static function fileExists($code) {
return is_file(Languages::local()->getFileName($code)) ? 1 : 0;
}
/**
* Get language options for in desired language. Useful to build a Select widget.
*
* @param array|string|int $selected - An array of language codes to mark as selected
* @param array $pool (optional) - An array of language codes to be displayed. Leave null to show all.
* @param string $lang (optional) - Get language names for this language.
*
* @return array
*/
public static function findOptions($selected = array(), $pool = null, $lang = null) {
if (!is_array($selected)) {
$selected = array($selected);
}
$native = Languages::all()->listAll('name');
if (is_array($pool)) {
$native = array_intersect_key($native, array_flip($pool));
}
if ($lang === null) {
$lang = Lang::get();
}
// try to get languages in author language
$local = Languages::local()->listAll($lang);
// if languages not found, use english ones
if ($local === false) {
$local = Languages::local()->listAll();
}
$options = array();
foreach ($native as $code => $info) {
$options[] = array(
$code,
in_array($code, $selected),
sprintf(
"[%s] %s%s",
strtoupper($code),
isset($local[$code]) ? $local[$code] . ' || ' : '',
$info['name']
),
);
}
return $options;
}
}