global.inc.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <?php
  2. /** For licensing terms, see /license.txt */
  3. /**
  4. * This is a bootstrap file that loads all Chamilo dependencies including:
  5. *
  6. * - Chamilo settings config/configuration.yml or config/configuration.php (in this order, using what if finds first)
  7. * - Database (Using Doctrine DBAL/ORM)
  8. * - Templates (Using Twig)
  9. * - Loading language files (Using Symfony component)
  10. * - Loading mail settings (Using SwiftMailer smtp/sendmail/mail)
  11. * - Debug (Using Monolog)
  12. *
  13. * ALL Chamilo scripts must include this file in order to have the $app container
  14. * This script returns a $app Application instance so you have access to all the services.
  15. *
  16. * @package chamilo.include
  17. *
  18. */
  19. use Silex\Application;
  20. use \ChamiloSession as Session;
  21. use Symfony\Component\HttpFoundation\RedirectResponse;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\Yaml\Parser;
  25. use Symfony\Component\Translation\Translator;
  26. use Symfony\Component\Security\Core\SecurityContext;
  27. use Symfony\Component\Translation\Loader\PoFileLoader;
  28. //use Symfony\Component\Translation\Loader\MoFileLoader;
  29. use Symfony\Component\Translation\Dumper\MoFileDumper;
  30. use Symfony\Component\Translation\Loader\XliffFileLoader;
  31. use Symfony\Component\Translation\MessageCatalogue;
  32. use ChamiloLMS\Component\DataFilesystem\DataFilesystem;
  33. use ChamiloLMS\Entity\User;
  34. // Determine the directory path for this file.
  35. $includePath = dirname(__FILE__);
  36. // Start Silex.
  37. $app = new Application();
  38. // @todo add a helper to read the configuration file once!
  39. // Include the main Chamilo platform configuration file.
  40. // @todo use a service provider to load configuration files:
  41. /*
  42. $app->register(new Igorw\Silex\ConfigServiceProvider($settingsFile));
  43. */
  44. /** Reading configuration files */
  45. // Reading configuration file from main/inc/conf/configuration.php or app/config/configuration.yml
  46. $configurationFilePath = $includePath.'/conf/configuration.php';
  47. $configurationYMLFile = $includePath.'/../../config/configuration.yml';
  48. $configurationFileAppPath = $includePath.'/../../config/configuration.php';
  49. $alreadyInstalled = false;
  50. $_configuration = array();
  51. if (file_exists($configurationFilePath) || file_exists($configurationYMLFile) || file_exists($configurationFileAppPath)) {
  52. if (file_exists($configurationFilePath)) {
  53. require_once $configurationFilePath;
  54. }
  55. if (file_exists($configurationFileAppPath)) {
  56. $configurationFilePath = $configurationFileAppPath;
  57. require_once $configurationFileAppPath;
  58. }
  59. $alreadyInstalled = true;
  60. }
  61. // Overwriting $_configuration
  62. if (file_exists($configurationYMLFile)) {
  63. $yaml = new Parser();
  64. $configurationYML = $yaml->parse(file_get_contents($configurationYMLFile));
  65. if (is_array($configurationYML) && !empty($configurationYML)) {
  66. if (isset($_configuration)) {
  67. $_configuration = array_merge($_configuration, $configurationYML);
  68. } else {
  69. $_configuration = $configurationYML;
  70. }
  71. }
  72. }
  73. /** Setting Chamilo paths */
  74. $app['root_sys'] = isset($_configuration['root_sys']) ? $_configuration['root_sys'] : dirname(dirname(__DIR__)).'/';
  75. $app['sys_root'] = $app['root_sys'];
  76. $app['sys_data_path'] = isset($_configuration['sys_data_path']) ? $_configuration['sys_data_path'] : $app['root_sys'].'data/';
  77. $app['sys_config_path'] = isset($_configuration['sys_config_path']) ? $_configuration['sys_config_path'] : $app['root_sys'].'config/';
  78. $app['sys_course_path'] = isset($_configuration['sys_course_path']) ? $_configuration['sys_course_path'] : $app['sys_data_path'].'courses/';
  79. $app['sys_temp_path'] = isset($_configuration['sys_temp_path']) ? $_configuration['sys_temp_path'] : $app['sys_data_path'].'temp/';
  80. $app['sys_log_path'] = isset($_configuration['sys_log_path']) ? $_configuration['sys_log_path'] : $app['root_sys'].'logs/';
  81. /** Loading config files (mail, auth, profile) */
  82. if ($alreadyInstalled) {
  83. $configPath = $app['sys_config_path'];
  84. $confFiles = array(
  85. 'auth.conf.php',
  86. 'events.conf.php',
  87. 'mail.conf.php',
  88. 'portfolio.conf.php',
  89. 'profile.conf.php'
  90. );
  91. foreach ($confFiles as $confFile) {
  92. if (file_exists($configPath.$confFile)) {
  93. require_once $configPath.$confFile;
  94. }
  95. }
  96. // Fixing $_configuration array
  97. // Fixes bug in Chamilo 1.8.7.1 array was not set
  98. $administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com';
  99. $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';
  100. // Code for transitional purposes, it can be removed right before the 1.8.7 release.
  101. /*if (empty($_configuration['system_version'])) {
  102. $_configuration['system_version'] = (!empty($_configuration['dokeos_version']) ? $_configuration['dokeos_version'] : '');
  103. $_configuration['system_stable'] = (!empty($_configuration['dokeos_stable']) ? $_configuration['dokeos_stable'] : '');
  104. $_configuration['software_url'] = 'http://www.chamilo.org/';
  105. }*/
  106. // For backward compatibility.
  107. $_configuration['dokeos_version'] = isset($_configuration['system_version']) ? $_configuration['system_version'] : null;
  108. //$_configuration['dokeos_stable'] = $_configuration['system_stable'];
  109. $userPasswordCrypted = (!empty($_configuration['password_encryption']) ? $_configuration['password_encryption'] : 'sha1');
  110. }
  111. /** End loading config files */
  112. /** Including legacy libs */
  113. require_once $includePath.'/lib/api.lib.php';
  114. // Setting $_configuration['url_append']
  115. $urlInfo = isset($_configuration['root_web']) ? parse_url($_configuration['root_web']) : null;
  116. $_configuration['url_append'] = null;
  117. if (isset($urlInfo['path'])) {
  118. $_configuration['url_append'] = '/'.basename($urlInfo['path']);
  119. }
  120. $libPath = $includePath.'/lib/';
  121. // Database constants
  122. require_once $libPath.'database.constants.inc.php';
  123. // @todo Rewrite the events.lib.inc.php in a class
  124. require_once $libPath.'events.lib.inc.php';
  125. // Load allowed tag definitions for kses and/or HTMLPurifier.
  126. require_once $libPath.'formvalidator/Rule/allowed_tags.inc.php';
  127. // Add the path to the pear packages to the include path
  128. ini_set('include_path', api_create_include_path_setting($includePath));
  129. $app['configuration_file'] = $configurationFilePath;
  130. $app['configuration_yml_file'] = $configurationYMLFile;
  131. $app['languages_file'] = array();
  132. $app['installed'] = $alreadyInstalled;
  133. $app['app.theme'] = 'chamilo';
  134. // Developer options relies in the configuration.php file
  135. $app['debug'] = isset($_configuration['debug']) ? $_configuration['debug'] : false;
  136. $app['show_profiler'] = isset($_configuration['show_profiler']) ? $_configuration['show_profiler'] : false;
  137. // Enables assetic in order to load 1 compressed stylesheet or split files
  138. //$app['assetic.enabled'] = $app['debug'];
  139. // Hardcoded to false by default. Implementation is not finished yet.
  140. $app['assetic.enabled'] = false;
  141. // Dumps assets
  142. $app['assetic.auto_dump_assets'] = false;
  143. // Loading $app settings depending of the debug option
  144. if ($app['debug']) {
  145. require_once __DIR__.'/../../src/ChamiloLMS/Resources/config/dev.php';
  146. } else {
  147. require_once __DIR__.'/../../src/ChamiloLMS/Resources/config/prod.php';
  148. }
  149. // Classic way of render pages or the Controller approach
  150. $app['classic_layout'] = false;
  151. $app['full_width'] = false;
  152. $app['breadcrumb'] = array();
  153. // The script is allowed? This setting is modified when calling api_is_not_allowed()
  154. $app['allowed'] = true;
  155. $app->register(new Silex\Provider\SessionServiceProvider());
  156. // Session settings
  157. $app['session.storage.options'] = array(
  158. 'name' => 'chamilo_session',
  159. //'cookie_lifetime' => 30, //Cookie lifetime
  160. //'cookie_path' => null, //Cookie path
  161. //'cookie_domain' => null, //Cookie domain
  162. //'cookie_secure' => null, //Cookie secure (HTTPS)
  163. 'cookie_httponly' => true //Whether the cookie is http only
  164. );
  165. // Loading chamilo settings
  166. /* @todo create a service provider to load plugins.
  167. Check how bolt add extensions (including twig templates, config with yml)*/
  168. // Template settings loaded in template.lib.php
  169. $app['template.show_header'] = true;
  170. $app['template.show_footer'] = true;
  171. $app['template.show_learnpath'] = false;
  172. $app['template.hide_global_chat'] = true;
  173. $app['template.load_plugins'] = true;
  174. $app['configuration'] = $_configuration;
  175. // Inclusion of internationalization libraries
  176. require_once $libPath.'internationalization.lib.php';
  177. // Functions for internal use behind this API
  178. require_once $libPath.'internationalization_internal.lib.php';
  179. $_plugins = array();
  180. if ($alreadyInstalled) {
  181. /** Including service providers */
  182. require_once 'services.php';
  183. }
  184. $charset = 'UTF-8';
  185. // Preserving the value of the global variable $charset.
  186. $charset_initial_value = $charset;
  187. // Section (tabs in the main Chamilo menu)
  188. $app['this_section'] = SECTION_GLOBAL;
  189. // Manage Chamilo error messages
  190. $app->error(
  191. function (\Exception $e, $code) use ($app) {
  192. if ($app['debug']) {
  193. //return;
  194. }
  195. $message = null;
  196. if (isset($code)) {
  197. switch ($code) {
  198. case 401:
  199. $message = 'Unauthorized';
  200. break;
  201. case 404: // not found
  202. $message = $e->getMessage();
  203. if (empty($message)) {
  204. $message = 'The requested page could not be found.';
  205. }
  206. break;
  207. default:
  208. //$message = 'We are sorry, but something went terribly wrong.';
  209. $message = $e->getMessage();
  210. }
  211. } else {
  212. $code = null;
  213. }
  214. if ($e instanceof PDOException) {
  215. $message = "There's an error with the database.";
  216. if ($app['debug']) {
  217. $message = $e->getMessage();
  218. }
  219. return $message;
  220. }
  221. Session::setSession($app['session']);
  222. $templateStyle = api_get_setting('template');
  223. $templateStyle = isset($templateStyle) && !empty($templateStyle) ? $templateStyle : 'default';
  224. if (!is_dir($app['sys_root'].'main/template/'.$templateStyle)) {
  225. $templateStyle = 'default';
  226. }
  227. $app['template_style'] = $templateStyle;
  228. // Default layout.
  229. $app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
  230. /** @var Template $template */
  231. $template = $app['template'];
  232. $template->setHeader($app['template.show_header']);
  233. $template->setFooter($app['template.show_footer']);
  234. $template->assign('error', array('code' => $code, 'message' => $message));
  235. $response = $template->renderLayout('error.tpl');
  236. return new Response($response);
  237. }
  238. );
  239. // Checking if we have a valid language. If not we set it to the platform language.
  240. $cidReset = null;
  241. /** Silex Middlewares. */
  242. /* A "before" middleware allows you to tweak the Request
  243. * before the controller is executed. */
  244. $app->before(
  245. function () use ($app) {
  246. /** @var Request $request */
  247. $request = $app['request'];
  248. // Checking configuration file. If does not exists redirect to the install folder.
  249. if (!file_exists($app['configuration_file']) && !file_exists($app['configuration_yml_file'])) {
  250. $url = str_replace('web', 'main/install', $request->getBasePath());
  251. return new RedirectResponse($url);
  252. }
  253. // Check data folder
  254. if (!is_writable($app['sys_data_path'])) {
  255. $app->abort(500, "data folder must be writable.");
  256. }
  257. // Checks temp folder permissions.
  258. if (!is_writable($app['sys_temp_path'])) {
  259. $app->abort(500, "data/temp folder must be writable.");
  260. }
  261. // Checking that configuration is loaded
  262. if (!isset($app['configuration'])) {
  263. $app->abort(500, '$configuration array must be set in the configuration.php file.');
  264. }
  265. $configuration = $app['configuration'];
  266. // Check if root_web exists
  267. if (!isset($configuration['root_web'])) {
  268. $app->abort(500, '$configuration[root_web] must be set in the configuration.php file.');
  269. }
  270. // Starting the session for more info see: http://silex.sensiolabs.org/doc/providers/session.html
  271. $session = $request->getSession();
  272. $session->start();
  273. // Setting session obj
  274. Session::setSession($session);
  275. UserManager::setEntityManager($app['orm.em']);
  276. /** @var DataFilesystem $filesystem */
  277. $filesystem = $app['chamilo.filesystem'];
  278. if ($app['debug']) {
  279. // Creates data/temp folders for every request if debug is on.
  280. $filesystem->createFolders($app['temp.paths']->folders);
  281. }
  282. // If Assetic is enabled copy folders from theme inside "web/"
  283. if ($app['assetic.auto_dump_assets']) {
  284. $filesystem->copyFolders($app['temp.paths']->copyFolders);
  285. }
  286. // Check and modify the date of user in the track.e.online table
  287. Online::loginCheck(api_get_user_id());
  288. // Setting access_url id (multiple url feature)
  289. if (api_get_multiple_access_url()) {
  290. $_configuration = $app['configuration'];
  291. $_configuration['access_url'] = 1;
  292. $access_urls = api_get_access_urls();
  293. $protocol = $request->getScheme().'://';
  294. $request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
  295. $request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
  296. foreach ($access_urls as & $details) {
  297. if ($request_url1 == $details['url'] or $request_url2 == $details['url']) {
  298. $_configuration['access_url'] = $details['id'];
  299. }
  300. }
  301. Session::write('url_id', $_configuration['access_url']);
  302. Session::write('url_info', api_get_current_access_url_info($_configuration['access_url']));
  303. } else {
  304. Session::write('url_id', 1);
  305. }
  306. // Loading portal settings from DB.
  307. $settingsRefreshInfo = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
  308. $settingsLatestUpdate = $settingsRefreshInfo ? $settingsRefreshInfo['selected_value'] : null;
  309. $settings = Session::read('_setting');
  310. if (empty($settings)) {
  311. api_set_settings_and_plugins();
  312. } else {
  313. if (isset($settings['settings_latest_update']) && $settings['settings_latest_update'] != $settingsLatestUpdate) {
  314. api_set_settings_and_plugins();
  315. }
  316. }
  317. $app['plugins'] = Session::read('_plugins');
  318. // Default template style.
  319. $templateStyle = api_get_setting('template');
  320. $templateStyle = isset($templateStyle) && !empty($templateStyle) ? $templateStyle : 'default';
  321. if (!is_dir($app['sys_root'].'main/template/'.$templateStyle)) {
  322. $templateStyle = 'default';
  323. }
  324. $app['template_style'] = $templateStyle;
  325. // Default layout.
  326. $app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
  327. // Setting languages.
  328. $app['api_get_languages'] = api_get_languages();
  329. $app['language_interface'] = $language_interface = api_get_language_interface();
  330. // Reconfigure template now that we know the user.
  331. $app['template.hide_global_chat'] = !api_is_global_chat_enabled();
  332. /** Setting the course quota */
  333. // Default quota for the course documents folder
  334. $default_quota = api_get_setting('default_document_quotum');
  335. // Just in case the setting is not correctly set
  336. if (empty($default_quota)) {
  337. $default_quota = 100000000;
  338. }
  339. define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
  340. // Specification for usernames:
  341. // 1. ASCII-letters, digits, "." (dot), "_" (underscore) are acceptable, 40 characters maximum length.
  342. // 2. Empty username is formally valid, but it is reserved for the anonymous user.
  343. // 3. Checking the login_is_email portal setting in order to accept 100 chars maximum
  344. $default_username_length = 40;
  345. if (api_get_setting('login_is_email') == 'true') {
  346. $default_username_length = 100;
  347. }
  348. define('USERNAME_MAX_LENGTH', $default_username_length);
  349. $user = null;
  350. /** Security component. */
  351. /** @var SecurityContext $security */
  352. $security = $app['security'];
  353. if ($security->isGranted('IS_AUTHENTICATED_FULLY')) {
  354. // Checking token in order to get the current user.
  355. $token = $security->getToken();
  356. if (null !== $token) {
  357. /** @var User $user */
  358. $user = $token->getUser();
  359. $filesystem->createMyFilesFolder($user);
  360. }
  361. // For backward compatibility.
  362. $userInfo = api_get_user_info($user->getUserId());
  363. $userInfo['is_anonymous'] = false;
  364. Session::write('_user', $userInfo);
  365. $app['current_user'] = $userInfo;
  366. // Setting admin permissions.
  367. if ($security->isGranted('ROLE_ADMIN')) {
  368. Session::write('is_platformAdmin', true);
  369. }
  370. // Setting teachers permissions.
  371. if ($security->isGranted('ROLE_TEACHER')) {
  372. Session::write('is_allowedCreateCourse', true);
  373. }
  374. } else {
  375. Session::erase('_user');
  376. Session::erase('is_platformAdmin');
  377. Session::erase('is_allowedCreateCourse');
  378. }
  379. /** Translator component. */
  380. $app['translator.cache.enabled'] = false;
  381. $language = api_get_setting('platformLanguage');
  382. $iso = api_get_language_isocode($language);
  383. /** @var Translator $translator */
  384. $translator = $app['translator'];
  385. $translator->setLocale($iso);
  386. // From the login page
  387. $language = $request->get('language');
  388. if (!empty($language)) {
  389. $iso = api_get_language_isocode($language);
  390. $translator->setLocale($iso);
  391. }
  392. // From the user
  393. if ($user && $userInfo) {
  394. // @todo check why this does not works
  395. //$language = $user->getLanguage();
  396. $language = $userInfo['language'];
  397. $iso = api_get_language_isocode($language);
  398. $translator->setLocale($iso);
  399. }
  400. // From the course
  401. $courseInfo = api_get_course_info();
  402. if ($courseInfo && !empty($courseInfo)) {
  403. $iso = api_get_language_isocode($courseInfo['language']);
  404. $translator->setLocale($iso);
  405. }
  406. $app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
  407. $locale = $translator->getLocale();
  408. /** @var Translator $translator */
  409. if ($app['translator.cache.enabled']) {
  410. //$phpFileDumper = new Symfony\Component\Translation\Dumper\PhpFileDumper();
  411. $dumper = new MoFileDumper();
  412. $catalogue = new MessageCatalogue($locale);
  413. $catalogue->add(array('foo' => 'bar'));
  414. $dumper->dump($catalogue, array('path' => $app['sys_temp_path']));
  415. } else {
  416. $translationPath = $app['root_sys'].'src/ChamiloLMS/Resources/translations/';
  417. $translator->addLoader('pofile', new PoFileLoader());
  418. $file = $translationPath.$locale.'.po';
  419. if (file_exists($file)) {
  420. $translator->addResource('pofile', $file, $locale);
  421. }
  422. $customFile = $translationPath.$locale.'.custom.po';
  423. if (file_exists($customFile)) {
  424. $translator->addResource('pofile', $customFile, $locale);
  425. }
  426. // Validators
  427. $file = $app['root_sys'].'vendor/symfony/validator/Symfony/Component/Validator/Resources/translations/validators.'.$locale.'.xlf';
  428. $translator->addLoader('xlf', new XliffFileLoader());
  429. if (file_exists($file)) {
  430. $translator->addResource('xlf', $file, $locale, 'validators');
  431. }
  432. /*$translator->addLoader('mofile', new MoFileLoader());
  433. $filePath = api_get_path(SYS_PATH).'main/locale/'.$locale.'.mo';
  434. if (!file_exists($filePath)) {
  435. $filePath = api_get_path(SYS_PATH).'main/locale/en.mo';
  436. }
  437. $translator->addResource('mofile', $filePath, $locale);*/
  438. return $translator;
  439. }
  440. }));
  441. // Check if we are inside a Chamilo course tool
  442. /*$isCourseTool = (strpos($request->getPathInfo(), 'courses/') === false) ? false : true;
  443. if (!$isCourseTool) {
  444. // @todo add a before in controller in order to load the courses and course_session object
  445. $isCourseTool = (strpos($request->getPathInfo(), 'editor/filemanager') === false) ? false : true;
  446. var_dump($isCourseTool);
  447. var_dump(api_get_course_id());exit;
  448. }*/
  449. $studentView = $request->get('isStudentView');
  450. if (!empty($studentView)) {
  451. if ($studentView == 'true') {
  452. $session->set('studentview', 'studentview');
  453. } else {
  454. $session->set('studentview', 'teacherview');
  455. }
  456. }
  457. }
  458. );
  459. /** An after application middleware allows you to tweak the Response before it is sent to the client */
  460. $app->after(
  461. function (Request $request, Response $response) {
  462. }
  463. );
  464. /** A "finish" application middleware allows you to execute tasks after the Response has been sent to
  465. * the client (like sending emails or logging) */
  466. $app->finish(
  467. function (Request $request) use ($app) {
  468. }
  469. );
  470. // End Silex Middlewares
  471. // The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation.
  472. // So, we have to reassign this variable again in order to keep its value right.
  473. $charset = $charset_initial_value;
  474. // The global variable $text_dir has been defined in the language file trad4all.inc.php.
  475. // For determing text direction correspondent to the current language we use now information from the internationalization library.
  476. $text_dir = api_get_text_direction();
  477. /** Setting the is_admin key */
  478. $app['is_admin'] = false;
  479. /** Including routes */
  480. require_once 'routes.php';
  481. // Setting doctrine2 extensions
  482. if (isset($app['configuration']['main_database']) && isset($app['db.event_manager'])) {
  483. // @todo improvement do not create every time this objects
  484. $sortableGroup = new Gedmo\Mapping\Annotation\SortableGroup(array());
  485. $sortablePosition = new Gedmo\Mapping\Annotation\SortablePosition(array());
  486. $tree = new Gedmo\Mapping\Annotation\Tree(array());
  487. $tree = new Gedmo\Mapping\Annotation\TreeParent(array());
  488. $tree = new Gedmo\Mapping\Annotation\TreeLeft(array());
  489. $tree = new Gedmo\Mapping\Annotation\TreeRight(array());
  490. $tree = new Gedmo\Mapping\Annotation\TreeRoot(array());
  491. $tree = new Gedmo\Mapping\Annotation\TreeLevel(array());
  492. $tree = new Gedmo\Mapping\Annotation\Versioned(array());
  493. $tree = new Gedmo\Mapping\Annotation\Loggable(array());
  494. $tree = new Gedmo\Loggable\Entity\LogEntry();
  495. // Setting Doctrine2 extensions
  496. $timestampableListener = new \Gedmo\Timestampable\TimestampableListener();
  497. // $app['db.event_manager']->addEventSubscriber($timestampableListener);
  498. $app['dbs.event_manager']['db_read']->addEventSubscriber($timestampableListener);
  499. $app['dbs.event_manager']['db_write']->addEventSubscriber($timestampableListener);
  500. $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
  501. // $app['db.event_manager']->addEventSubscriber($sluggableListener);
  502. $app['dbs.event_manager']['db_read']->addEventSubscriber($sluggableListener);
  503. $app['dbs.event_manager']['db_write']->addEventSubscriber($sluggableListener);
  504. $sortableListener = new Gedmo\Sortable\SortableListener();
  505. // $app['db.event_manager']->addEventSubscriber($sortableListener);
  506. $app['dbs.event_manager']['db_read']->addEventSubscriber($sortableListener);
  507. $app['dbs.event_manager']['db_write']->addEventSubscriber($sortableListener);
  508. $treeListener = new \Gedmo\Tree\TreeListener();
  509. //$treeListener->setAnnotationReader($cachedAnnotationReader);
  510. // $app['db.event_manager']->addEventSubscriber($treeListener);
  511. $app['dbs.event_manager']['db_read']->addEventSubscriber($treeListener);
  512. $app['dbs.event_manager']['db_write']->addEventSubscriber($treeListener);
  513. $loggableListener = new \Gedmo\Loggable\LoggableListener();
  514. if (PHP_SAPI != 'cli') {
  515. //$userInfo = api_get_user_info();
  516. if (isset($userInfo) && !empty($userInfo['username'])) {
  517. //$loggableListener->setUsername($userInfo['username']);
  518. }
  519. }
  520. $app['dbs.event_manager']['db_read']->addEventSubscriber($loggableListener);
  521. $app['dbs.event_manager']['db_write']->addEventSubscriber($loggableListener);
  522. }
  523. return $app;