]> git.agnieray.net Git - galette.git/blob - galette/includes/dependencies.php
Rework lang selector
[galette.git] / galette / includes / dependencies.php
1 <?php
2 /**
3 * Dependency injection configuration
4 *
5 * PHP version 5
6 *
7 * Copyright © 2003-2018 The Galette Team
8 *
9 * This file is part of Galette (http://galette.tuxfamily.org).
10 *
11 * Galette is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * Galette is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * @category Functions
25 * @package Galette
26 *
27 * @author Frédéric Jaqcuot <unknown@unknow.com>
28 * @author Georges Khaznadar (password encryption, images) <unknown@unknow.com>
29 * @author Johan Cwiklinski <johan@x-tnd.be>
30 * @copyright 2003-2018 The Galette Team
31 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
32 * @link http://galette.tuxfamily.org
33 */
34
35 use Galette\Entity\PdfModel;
36
37 $container = $app->getContainer();
38
39 // -----------------------------------------------------------------------------
40 // Error handling
41 // -----------------------------------------------------------------------------
42
43 $container['errorHandler'] = function ($c) {
44 return new Galette\Handlers\Error($c['view'], true);
45 };
46
47 $container['phpErrorHandler'] = function ($c) {
48 return new Galette\Handlers\PhpError($c['view'], true);
49 };
50
51 $container['notFoundHandler'] = function ($c) {
52 return new Galette\Handlers\NotFound($c['view']);
53 };
54
55 // -----------------------------------------------------------------------------
56 // Service providers
57 // -----------------------------------------------------------------------------
58
59 // Register Smarty View helper
60 $container['view'] = function ($c) {
61 $view = new \Slim\Views\Smarty(
62 rtrim(GALETTE_ROOT . GALETTE_TPL_SUBDIR, DIRECTORY_SEPARATOR),
63 [
64 'cacheDir' => rtrim(GALETTE_CACHE_DIR, DIRECTORY_SEPARATOR),
65 'compileDir' => rtrim(GALETTE_COMPILE_DIR, DIRECTORY_SEPARATOR),
66 'pluginsDir' => [
67 GALETTE_ROOT . 'includes/smarty_plugins'
68 ]
69 ]
70 );
71
72 // Add Slim specific plugins
73 $basepath = str_replace(
74 'index.php',
75 '',
76 $c['request']->getUri()->getBasePath()
77 );
78 $view->addSlimPlugins($c['router'], $basepath);
79
80 $smarty = $view->getSmarty();
81 $smarty->inheritance_merge_compiled_includes = false;
82
83 $smarty->assign('flash', $c->get('flash'));
84
85 $smarty->assign('login', $c->login);
86 $smarty->assign('logo', $c->logo);
87 $smarty->assign('tpl', $smarty);
88 $smarty->assign('headers', $c->plugins->getTplHeaders());
89 $smarty->assign('plugin_actions', $c->plugins->getTplAdhActions());
90 $smarty->assign(
91 'plugin_batch_actions',
92 $c->plugins->getTplAdhBatchActions()
93 );
94 $smarty->assign(
95 'plugin_detailled_actions',
96 $c->plugins->getTplAdhDetailledActions()
97 );
98 $smarty->assign('scripts_dir', 'js/');
99 $smarty->assign('jquery_dir', 'js/jquery/');
100 $smarty->assign('jquery_version', JQUERY_VERSION);
101 $smarty->assign('jquery_migrate_version', JQUERY_MIGRATE_VERSION);
102 $smarty->assign('jquery_ui_version', JQUERY_UI_VERSION);
103 $smarty->assign('jquery_markitup_version', JQUERY_MARKITUP_VERSION);
104 $smarty->assign('jquery_jqplot_version', JQUERY_JQPLOT_VERSION);
105 $smarty->assign('PAGENAME', basename($_SERVER['SCRIPT_NAME']));
106 $smarty->assign('galette_base_path', './');
107 $smarty->assign('GALETTE_VERSION', GALETTE_VERSION);
108 $smarty->assign('GALETTE_MODE', GALETTE_MODE);
109 $smarty->assign('GALETTE_DISPLAY_ERRORS', GALETTE_DISPLAY_ERRORS);
110 $smarty->assign('_CURRENT_THEME_PATH', _CURRENT_THEME_PATH);
111
112 /*if ($this->parserConfigDir) {
113 $instance->setConfigDir($this->parserConfigDir);
114 }*/
115
116 $smarty->assign('template_subdir', GALETTE_THEME);
117 foreach ($c->plugins->getTplAssignments() as $k => $v) {
118 $smarty->assign($k, $v);
119 }
120 /** galette_lang should be removed and languages used instead */
121 $smarty->assign('galette_lang', $c->i18n->getAbbrev());
122 $smarty->assign('galette_lang_name', $c->i18n->getName());
123 $smarty->assign('languages', $c->i18n->getList());
124 $smarty->assign('plugins', $c->plugins);
125 $smarty->assign('preferences', $c->preferences);
126 $smarty->assign('pref_slogan', $c->preferences->pref_slogan);
127 $smarty->assign('pref_theme', $c->preferences->pref_theme);
128 $smarty->assign('pref_statut', $c->preferences->pref_statut);
129 $smarty->assign(
130 'pref_editor_enabled',
131 $c->preferences->pref_editor_enabled
132 );
133 $smarty->assign('pref_mail_method', $c->preferences->pref_mail_method);
134 $smarty->assign('existing_mailing', $c->get('session')->mailing !== null);
135 $smarty->assign('require_tabs', null);
136 $smarty->assign('contentcls', null);
137 $smarty->assign('require_cookie', false);
138 $smarty->assign('additionnal_html_class', null);
139 $smarty->assign('require_calendar', null);
140 $smarty->assign('head_redirect', null);
141 $smarty->assign('error_detected', null);
142 $smarty->assign('warning_detected', null);
143 $smarty->assign('success_detected', null);
144 $smarty->assign('color_picker', null);
145 $smarty->assign('require_sorter', null);
146 $smarty->assign('require_dialog', null);
147 $smarty->assign('require_tree', null);
148 $smarty->assign('html_editor', null);
149 $smarty->assign('require_charts', null);
150 $smarty->assign('require_mass', null);
151 if ($c->login->isAdmin() && $c->preferences->pref_telemetry_date) {
152 $now = new \DateTime();
153 $sent = new \DateTime($c->preferences->pref_telemetry_date);
154 $sent->add(new \DateInterval('P1Y'));// ask to resend telemetry after one year
155 if ($now > $sent && !$_COOKIE['renew_telemetry']) {
156 $smarty->assign('renew_telemetry', true);
157 }
158 }
159
160 foreach ($c->get('plugins')->getModules() as $module_id => $module) {
161 $smarty->addTemplateDir(
162 $module['root'] . '/templates/' . $c->get('preferences')->pref_theme,
163 $module['route']
164 );
165 }
166 return $view;
167 };
168
169 // Flash messages
170 $container['flash'] = function ($c) {
171 return new \Slim\Flash\Messages;
172 };
173
174 $container['plugins'] = function ($c) use ($app) {
175 $plugins = new Galette\Core\Plugins();
176 $i18n = $c->get('i18n');
177 $plugins->loadModules($c->preferences, GALETTE_PLUGINS_PATH, $i18n->getLongID());
178 return $plugins;
179 };
180
181 $container['i18n'] = function ($c) {
182 $i18n = $c->get('session')->i18n;
183 if (!$i18n || !$i18n->getId()) {
184 $i18n = new Galette\Core\I18n();
185 $c->get('session')->i18n = $i18n;
186 }
187 return $i18n;
188 };
189
190 $container['zdb'] = function ($c) {
191 $zdb = new Galette\Core\Db();
192 return $zdb;
193 };
194
195 $container['preferences'] = function ($c) {
196 return new Galette\Core\Preferences($c->zdb);
197 };
198
199 $container['login'] = function ($c) {
200 $login = $c->get('session')->login;
201 if (!$login) {
202 $login = new Galette\Core\Login(
203 $c->get('zdb'),
204 $c->get('i18n'),
205 $c->get('session')
206 );
207 }
208 return $login;
209 };
210
211 $container['session'] = function ($c) {
212 $session = new \RKA\Session();
213 return $session;
214 };
215
216 $container['logo'] = function ($c) {
217 return new Galette\Core\Logo();
218 };
219
220 $container['print_logo'] = function ($c) {
221 return new Galette\Core\PrintLogo();
222 };
223
224
225 $container['history'] = function ($c) {
226 return new Galette\Core\History($c->get('zdb'), $c->get('login'));
227 };
228
229 $container['acls'] = function ($c) {
230 $acls = [
231 'preferences' => 'admin',
232 'store-preferences' => 'admin',
233 'testEmail' => 'admin',
234 'dashboard' => 'member',
235 'sysinfos' => 'staff',
236 'charts' => 'staff',
237 'plugins' => 'admin',
238 'pluginInitDb' => 'admin',
239 'pluginsActivation' => 'admin',
240 'history' => 'staff',
241 'history_filter' => 'staff',
242 'flushHistory' => 'staff',
243 'doFlushHistory' => 'staff',
244 'members' => 'groupmanager',
245 'filter-memberslist'=> 'groupmanager',
246 'advanced-search' => 'groupmanager',
247 'batch-memberslist' => 'groupmanager',
248 'mailing' => 'staff',
249 'doMailing' => 'staff',
250 'mailingPreview' => 'staff',
251 'previewAttachment' => 'staff',
252 'mailingRecipients' => 'staff',
253 'csv-memberslist' => 'staff',
254 'groups' => 'groupmanager',
255 'me' => 'member',
256 'member' => 'member',
257 'pdf-members-cards' => 'member',
258 'pdf-members-labels'=> 'groupmanager',
259 'mailings' => 'staff',
260 'mailings_filter' => 'staff',
261 'removeMailing' => 'staff',
262 'doRemoveMailing' => 'staff',
263 'contributions' => 'member',
264 'transactions' => 'staff',
265 'payments_filter' => 'member',
266 'editmember' => 'member',
267 'impersonate' => 'superadmin',
268 'unimpersonate' => 'member',
269 'reminders' => 'staff',
270 'doReminders' => 'staff',
271 'reminders-filter' => 'staff',
272 'export' => 'staff',
273 'doExport' => 'staff',
274 'removeCsv' => 'staff',
275 'doRemoveCsv' => 'staff',
276 'getCsv' => 'staff',
277 'import' => 'staff',
278 'doImport' => 'staff',
279 'importModel' => 'staff',
280 'getImportModel' => 'staff',
281 'storeImportModel' => 'staff',
282 'uploadImportFile' => 'staff',
283 'pdfModels' => 'staff',
284 'titles' => 'staff',
285 'removeTitle' => 'staff',
286 'doRemoveTitle' => 'staff',
287 'editTitle' => 'staff',
288 'texts' => 'staff',
289 'changeText' => 'staff',
290 'transaction' => 'staff',
291 'doEditTransaction' => 'staff',
292 'contribution' => 'staff',
293 'contributionDates' => 'staff',
294 'contributionMembers' => 'staff',
295 'attendance_sheet_details' => 'groupmanager',
296 'attendance_sheet' => 'groupmanager',
297 'entitleds' => 'staff',
298 'editEntitled' => 'staff',
299 'removeEntitled' => 'staff',
300 'doRemoveEntitled' => 'staff',
301 'dynamicTranslations' => 'staff',
302 'editDynamicTranslation' => 'staff',
303 'printContribution' => 'staff',
304 'attach_contribution' => 'staff',
305 'detach_contribution' => 'staff',
306 'removeContribution' => 'staff',
307 'removeContributions' => 'staff',
308 'pdf_groups' => 'groupmanager',
309 'ajax_group' => 'groupmanager',
310 'ajax_groups' => 'groupmanager',
311 'ajax_groupname_unique' => 'groupmanager',
312 'ajax_groups_reorder' => 'admin',
313 'add_group' => 'staff',
314 'removeGroup' => 'staff',
315 'doRemoveGroup' => 'staff',
316 'doEditGroup' => 'groupmanager',
317 'adhesionForm' => 'member',
318 'removeMember' => 'staff',
319 'removeMembers' => 'staff',
320 'doRemoveMember' => 'staff',
321 'doRemoveContribution' => 'staff',
322 'configureCoreFields' => 'admin',
323 'configureDynamicFields' => 'admin',
324 'storeCoreFieldsConfig' => 'admin',
325 'editDynamicField' => 'admin',
326 'doEditDynamicField' => 'admin',
327 'moveDynamicField' => 'admin',
328 'removeDynamicField' => 'admin',
329 'doRemoveDynamicField' => 'admin',
330 'photoDnd' => 'staff',
331 'ajaxMembers' => 'groupmanager',
332 'ajaxGroupMembers' => 'staff',
333 'getDynamicFile' => 'member',
334 'fakeData' => 'superadmin',
335 'doFakeData' => 'superadmin',
336 'adminTools' => 'superadmin',
337 'doAdminTools' => 'superadmin',
338 'telemetryInfos' => 'admin',
339 'telemetrySend' => 'admin',
340 'setRegistered' => 'admin',
341 'masschangeMembers' => 'groupmanager',
342 'massstoremembers' => 'groupmanager',
343 'masschangeMembersReview' => 'groupmanager',
344 'duplicateMember' => 'staff',
345 'paymentTypes' => 'staff',
346 'removePaymentType' => 'staff',
347 'doRemovePaymentType' => 'staff',
348 'editPaymentType' => 'staff',
349 'searches' => 'member',
350 'removeSearch' => 'member',
351 'removeSearches' => 'member',
352 'doRemoveSearch' => 'member',
353 'loadSearch' => 'member'
354 ];
355
356 foreach ($c['plugins']->getModules() as $plugin) {
357 $acls[$plugin['route'] . 'Info'] = 'member';
358 }
359
360 //load user defined ACLs
361 if (file_exists(GALETTE_CONFIG_PATH . 'local_acls.inc.php')) {
362 $acls = array_merge($acls, $local_acls);
363 }
364
365 return $acls;
366 };
367
368 $container['texts_fields'] = function ($c) {
369 include_once GALETTE_ROOT . 'includes/fields_defs/texts_fields.php';
370 return $texts_fields;
371 };
372
373 $container['members_fields'] = function ($c) {
374 include_once GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
375 return $members_fields;
376 };
377
378 $container['members_fields_cats'] = function ($c) {
379 include_once GALETTE_ROOT . 'includes/fields_defs/members_fields_cats.php';
380 return $members_fields_cats;
381 };
382
383 $container['pdfmodels_fields'] = function ($c) {
384 //include_once GALETTE_ROOT . 'includes/fields_defs/pdfmodels_fields.php';
385 $pdfmodels_fields = array(
386 array(
387 'model_id' => PdfModel::MAIN_MODEL,
388 'model_name' => '_T("Main")',
389 'model_title' => null,
390 'model_type' => PdfModel::MAIN_MODEL,
391 'model_header' => '<table>
392 <tr>
393 <td id="pdf_assoname"><strong id="asso_name">{ASSO_NAME}</strong><br/>{ASSO_SLOGAN}</td>
394 <td id="pdf_logo">{ASSO_LOGO}</td>
395 </tr>
396 </table>',
397 'model_footer' => '<div id="pdf_footer">
398 _T("Association") {ASSO_NAME} - {ASSO_ADDRESS}<br/>
399 {ASSO_WEBSITE}
400 </div>',
401 'model_body' => null,
402 'model_styles' => 'div#pdf_title {
403 font-size: 1.4em;
404 font-wieght:bold;
405 text-align: center;
406 }
407
408 div#pdf_subtitle {
409 text-align: center;
410 }
411
412 div#pdf_footer {
413 text-align: center;
414 font-size: 0.7em;
415 }
416
417 td#pdf_assoname {
418 width: 75%;
419 font-size: 1.1em;
420 }
421
422 strong#asso_name {
423 font-size: 1.6em;
424 }
425
426 td#pdf_logo {
427 text-align: right;
428 width: 25%;
429 }',
430 'model_parent' => null
431 ),
432 array(
433 'model_id' => PdfModel::INVOICE_MODEL,
434 'model_name' => '_T("Invoice")',
435 'model_title' => '_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}',
436 'model_type' => PdfModel::INVOICE_MODEL,
437 'model_header' => null,
438 'model_footer' => null,
439 'model_body' => '<table>
440 <tr>
441 <td width="300"></td>
442 <td><strong>{NAME_ADH}</strong><br/>
443 {ADDRESS_ADH}<br/>
444 <strong>{ZIP_ADH} {TOWN_ADH}</strong>
445 </td>
446 </tr>
447 <tr>
448 <td height="100"></td>
449 </tr>
450 <tr>
451 <td colspan="2">
452 <table>
453 <thead>
454 <tr>
455 <th>_T("Label")</th>
456 <th>_T("Amount")</th>
457 </tr>
458 </thead>
459 <tbody>
460 <tr>
461 <td>
462 {CONTRIBUTION_LABEL} (_T("on") {CONTRIBUTION_DATE})<br/>
463 _T("from") {CONTRIBUTION_BEGIN_DATE} _T("to") {CONTRIBUTION_END_DATE}<br/>
464 {CONTRIBUTION_PAYMENT_TYPE}<br/>
465 {CONTRIBUTION_COMMENT}
466 </td>
467 <td>{CONTRIBUTION_AMOUNT}</td>
468 </tr>
469 </tbody>
470 </table>
471 </td>
472 </tr>
473 </table>',
474 'model_styles' => null,
475 'model_parent' => PdfModel::MAIN_MODEL
476 ),
477 array(
478 'model_id' => PdfModel::RECEIPT_MODEL,
479 'model_name' => '_T("Receipt")',
480 'model_title' => '_T("Receipt") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}',
481 'model_type' => PdfModel::RECEIPT_MODEL,
482 'model_header' => null,
483 'model_footer' => null,
484 'model_body' => '<table>
485 <tr>
486 <td width="300"></td>
487 <td><strong>{NAME_ADH}</strong><br/>
488 {ADDRESS_ADH}<br/>
489 <strong>{ZIP_ADH} {TOWN_ADH}</strong>
490 </td>
491 </tr>
492 <tr>
493 <td height="100"></td>
494 </tr>
495 <tr>
496 <td colspan="2">
497 <table>
498 <thead>
499 <tr>
500 <th>_T("Label")</th>
501 <th>_T("Amount")</th>
502 </tr>
503 </thead>
504 <tbody>
505 <tr>
506 <td>
507 {CONTRIBUTION_LABEL} (_T("on") {CONTRIBUTION_DATE})<br/>
508 _T("from") {CONTRIBUTION_BEGIN_DATE} _T("to") {CONTRIBUTION_END_DATE}<br/>
509 {CONTRIBUTION_PAYMENT_TYPE}<br/>
510 {CONTRIBUTION_COMMENT}
511 </td>
512 <td>{CONTRIBUTION_AMOUNT}</td>
513 </tr>
514 </tbody>
515 </table>
516 </td>
517 </tr>
518 </table>',
519 'model_styles' => null,
520 'model_parent' => PdfModel::MAIN_MODEL
521 ),
522 array(
523 'model_id' => PdfModel::ADHESION_FORM_MODEL,
524 'model_name' => '_T("Adhesion form")',
525 'model_title' => '_T("Adhesion form")',
526 'model_type' => PdfModel::ADHESION_FORM_MODEL,
527 'model_header' => null,
528 'model_footer' => null,
529 'model_body' => '<hr/>
530 <div class="infos">_T("Complete the following form and send it with your funds, in order to complete your subscription.")</div>
531 <table>
532 <tr>
533 <td width="50%"></td>
534 <td width="50%">{ASSO_ADDRESS_MULTI}</td>
535 </tr>
536 </table>
537 <hr/>
538 <table>
539 <tr>
540 <td height="30"></td>
541 </tr>
542 <tr>
543 <td>_T("Required membership:")
544 <form action="none">
545 <input type="radio" class="box" name="cotisation" value="none1">_T("Active member")
546 <input type="radio" class="box" name="cotisation" value="none2">_T("Benefactor member")
547 <input type="radio" class="box" name="cotisation" value="none3">_T("Donation")
548 <div class="infos">_T("The minimum contribution for each type of membership are defined on the website of the association. The amount of donations are free to be decided by the generous donor.") </div>
549 </form>
550 </td>
551 </tr>
552 <tr>
553 <td height="30"></td>
554 </tr>
555 </table>
556 <table class="member">
557 <tr>
558 <td class="label">_T("Politeness")</td>
559 <td class="input">{TITLE_ADH}</td>
560 </tr>
561 <tr>
562 <td class="label">_T("Name")</td>
563 <td class="input">{LAST_NAME_ADH}</td>
564 </tr>
565 <tr>
566 <td class="label">_T("First name")</td>
567 <td class="input">{FIRST_NAME_ADH}</td>
568 </tr>
569 <tr>
570 <td class="label">_T("Company name") *</td>
571 <td class="input">{COMPANY_ADH}</td>
572 </tr>
573 <tr>
574 <td class="label">_T("Address")</td>
575 <td class="input">{ADDRESS_ADH}</td>
576 </tr>
577 <tr>
578 <td class="label"></td>
579 <td class="input"></td>
580 </tr>
581 <tr>
582 <td class="label"></td>
583 <td class="input"></td>
584 </tr>
585 <tr>
586 <td class="label">_T("Zip Code")</td>
587 <td class="cpinput">{ZIP_ADH}</td>
588 <td class="label">_T("City")</td>
589 <td class="towninput">{TOWN_ADH}</td>
590 </tr>
591 <tr>
592 <td class="label">_T("Country")</td>
593 <td class="input">{COUNTRY_ADH}</td>
594 </tr>
595 <tr>
596 <td class="label">_T("Email address")</td>
597 <td class="input">{EMAIL_ADH}</td>
598 </tr>
599 <tr>
600 <td class="label">_T("Username") **</td>
601 <td class="input">{LOGIN_ADH}</td>
602 </tr>
603 <tr>
604 <td colspan="2" height="10"></td>
605 </tr>
606 <tr>
607 <td class="label">_T("Amount")</td>
608 <td class="input"></td>
609 </tr>
610 </table>
611 <p>str_replace(\'%s\', \'{ASSO_NAME}\', \'_T("Hereby, I agree to comply to %s association statutes and its rules.")\')</p><p>_T("At ................................................")</p><p>_T("On .......... / .......... / .......... ")</p><p>_T("Signature")</p>
612 <p class="notes">_T("* Only for compagnies")<br/>_T("** Galette identifier, if applicable")</p>',
613 'model_styles' => 'td.label {
614 width: 20%;
615 font-weight: bold;
616 }
617 td.input {
618 width: 80%;
619 border-bottom: 1px dotted black;
620 }
621
622 td.cpinput {
623 width: 10%;
624 border-bottom: 1px dotted black;
625 }
626
627 td.towninput {
628 width: 50%;
629 border-bottom: 1px dotted black;
630 }
631
632 div.infos {
633 font-size: .8em;
634 }
635
636 p.notes {
637 font-size: 0.6em;
638 text-align: right;
639 }
640
641 .member td {
642 line-height: 20px;
643 height: 20px;
644 }',
645 'model_parent' => PdfModel::MAIN_MODEL
646 )
647 );
648 return $pdfmodels_fields;
649 };
650
651 // -----------------------------------------------------------------------------
652 // Service factories
653 // -----------------------------------------------------------------------------
654
655 // monolog
656 $container['logger'] = function ($c) {
657 $settings = $c->get('settings');
658 $logger = new \Monolog\Logger($settings['logger']['name']);
659 $logger->pushProcessor(new \Monolog\Processor\UidProcessor());
660 $logger->pushHandler(new \Monolog\Handler\StreamHandler($settings['logger']['path'], $setting['logger']['level']));
661 return $logger;
662 };
663
664 $container['fields_config'] = function ($c) {
665 $fc = new Galette\Entity\FieldsConfig(
666 $c->get('zdb'),
667 Galette\Entity\Adherent::TABLE,
668 $c->get('members_fields'),
669 $c->get('members_fields_cats')
670 );
671 return $fc;
672 };
673
674 $container['cache'] = function ($c) {
675 $adapter = null;
676 if (function_exists('wincache_ucache_add')) {
677 //since APCu is not known to work on windows
678 $adapter = 'wincache';
679 } elseif (function_exists('apcu_fetch')) {
680 $adapter = 'apcu';
681 }
682 if ($adapter !== null) {
683 $uuid = $c->get('mode') !== 'INSTALL' ? $c->get('preferences')->pref_instance_uuid : '_install';
684 $cache = Zend\Cache\StorageFactory::factory([
685 'adapter' => $adapter,
686 'options' => [
687 'namespace' => str_replace(
688 ['%version', '%uuid'],
689 [GALETTE_VERSION, $uuid],
690 'galette_%version_%uuid'
691 )
692 ]
693 ]);
694 return $cache;
695 }
696 return null;
697 };
698
699 $container['translator'] = function ($c) {
700 $translator = new Galette\Core\Translator();
701
702 $domains = ['galette'];
703 foreach ($domains as $domain) {
704 //load translation file for domain
705 $translator->addTranslationFilePattern(
706 'gettext',
707 GALETTE_ROOT . '/lang/',
708 '/%s/LC_MESSAGES/' . $domain . '.mo',
709 $domain
710 );
711
712 //check if a local lang file exists and load it
713 $translator->addTranslationFilePattern(
714 'phparray',
715 GALETTE_ROOT . '/lang/',
716 $domain . '_%s_local_lang.php',
717 $domain
718 );
719 }
720
721 $translator->setLocale($c->get('i18n')->getLongID());
722 if (!isset($container['mode']) || $c->get('mode') !== 'INSTALL' && $c->get('mode') !== 'NEED_UPDATE') {
723 $translator->setCache($c->get('cache'));
724 }
725 return $translator;
726 };
727
728 //For bad existing globals can be used...
729 if (!isset($container['mode']) || $container['mode'] !== 'INSTALL' && $container['mode'] !== 'NEED_UPDATE') {
730 $hist = $container['history'];
731 $login = $container['login'];
732 $zdb = $container['zdb'];
733 }
734 $i18n = $container['i18n'];
735 $translator = $container['translator'];
736
737 require_once GALETTE_ROOT . 'includes/i18n.inc.php';