1
|
|
|
<?php |
2
|
|
|
class Intraface_Factory |
3
|
|
|
{ |
4
|
|
|
protected $config; |
5
|
|
|
|
6
|
|
|
function __construct($config = null) |
7
|
|
|
{ |
8
|
|
|
$this->config = $config; |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
function new_k_TemplateFactory($c) |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
return new Intraface_TemplateFactory(null); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
function new_MDB2($c) |
17
|
|
|
{ |
18
|
|
|
return $this->new_MDB2_Driver_Common($c); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
function new_MDB2_Driver_Common($container) |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$db = MDB2::singleton(DB_DSN, array('persistent' => true)); |
24
|
|
|
if (PEAR::isError($db)) { |
25
|
|
|
throw new Exception($db->getMessage() . $db->getUserInfo()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$db->setFetchMode(MDB2_FETCHMODE_ASSOC); |
29
|
|
|
$db->query('SET NAMES utf8'); |
30
|
|
|
$res = $db->setCharset('utf8'); |
31
|
|
|
|
32
|
|
|
$db->setOption('debug', MDB2_DEBUG); |
33
|
|
|
$db->setOption('portability', MDB2_PORTABILITY_NONE); |
34
|
|
|
|
35
|
|
|
if (PEAR::isError($res)) { |
36
|
|
|
throw new Exception($res->getUserInfo()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
if ($db->getOption('debug')) { |
40
|
|
|
$db->setOption('log_line_break', "\n\n\n\n\t"); |
41
|
|
|
|
42
|
|
|
$my_debug_handler = new MDB2_Debug_ExplainQueries($db); |
43
|
|
|
$db->setOption('debug_handler', array($my_debug_handler, 'collectInfo')); |
44
|
|
|
|
45
|
|
|
register_shutdown_function(array($my_debug_handler, 'executeAndExplain')); |
46
|
|
|
register_shutdown_function(array($my_debug_handler, 'dumpInfo')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $db; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function new_DB_Sql($container) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$db = new DB_Sql(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
55
|
|
|
$db->query('SET NAMES utf8'); |
56
|
|
|
return $db; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function new_Translation2() |
60
|
|
|
{ |
61
|
|
|
// set the parameters to connect to your db |
62
|
|
|
$dbinfo = array( |
63
|
|
|
'hostspec' => DB_HOST, |
64
|
|
|
'database' => DB_NAME, |
65
|
|
|
'phptype' => 'mysql', |
66
|
|
|
'username' => DB_USER, |
67
|
|
|
'password' => DB_PASS |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
if (!defined('LANGUAGE_TABLE_PREFIX')) { |
71
|
|
|
define('LANGUAGE_TABLE_PREFIX', 'core_translation_'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$params = array( |
75
|
|
|
'langs_avail_table' => LANGUAGE_TABLE_PREFIX.'langs', |
76
|
|
|
'strings_default_table' => LANGUAGE_TABLE_PREFIX.'i18n' |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$translation = Translation2::factory('MDB2', $dbinfo, $params); |
80
|
|
|
//always check for errors. In this examples, error checking is omitted |
81
|
|
|
//to make the example concise. |
82
|
|
|
if (PEAR::isError($translation)) { |
83
|
|
|
throw new Exception('Could not start Translation ' . $translation->getMessage()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// set the group of strings you want to fetch from |
87
|
|
|
// $translation->setPageID($page_id); |
|
|
|
|
88
|
|
|
|
89
|
|
|
// add a Lang decorator to provide a fallback language |
90
|
|
|
// $translation = $translation->getDecorator('Lang'); |
|
|
|
|
91
|
|
|
// $translation->setOption('fallbackLang', 'uk'); |
|
|
|
|
92
|
|
|
// $translation = $translation->getDecorator('LogMissingTranslation'); |
|
|
|
|
93
|
|
|
// $translation->setOption('logger', array(new ErrorHandler_Observer_File(ERROR_LOG), 'update')); |
|
|
|
|
94
|
|
|
$translation = $translation->getDecorator('DefaultText'); |
95
|
|
|
|
96
|
|
|
// %stringID% will be replaced with the stringID |
97
|
|
|
// %pageID_url% will be replaced with the pageID |
98
|
|
|
// %stringID_url% will replaced with a urlencoded stringID |
99
|
|
|
// %url% will be replaced with the targeted url |
100
|
|
|
//$this->translation->outputString = '%stringID% (%pageID_url%)'; //default: '%stringID%' |
|
|
|
|
101
|
|
|
$translation->outputString = '%stringID%'; |
102
|
|
|
$translation->url = ''; //same as default |
103
|
|
|
$translation->emptyPrefix = ''; //default: empty string |
|
|
|
|
104
|
|
|
$translation->emptyPostfix = ''; //default: empty string |
|
|
|
|
105
|
|
|
return $translation; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function new_Translation2_Cache() |
109
|
|
|
{ |
110
|
|
|
$options = array( |
111
|
|
|
"cacheDir" => PATH_CACHE.'translation/', |
112
|
|
|
"lifeTime" => 3600 |
113
|
|
|
); |
114
|
|
|
return new Cache_Lite($options); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
function new_Intraface_Auth($container) |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
return new Intraface_Auth(session_id()); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
function new_Doctrine_Connection_Common() |
123
|
|
|
{ |
124
|
|
|
$connection = Doctrine_Manager::connection(DB_DSN); |
125
|
|
|
$connection->setCharset('utf8'); |
126
|
|
|
return $connection; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
function new_Swift_Message($c) |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
return Swift_Message::newInstance(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
function new_Swift_Mailer($c) |
135
|
|
|
{ |
136
|
|
|
return Swift_Mailer::newInstance($this->new_Swift_Transport($c)); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
function new_Swift_Transport() |
140
|
|
|
{ |
141
|
|
|
return Swift_MailTransport::newInstance(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
function new_Cache_Lite() |
145
|
|
|
{ |
146
|
|
|
$options = array( |
147
|
|
|
'cacheDir' => PATH_CACHE, |
148
|
|
|
'lifeTime' => 3600 |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
return new Cache_Lite($options); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.