123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023 |
- <?php
- $mtime = microtime();
- $mtime = explode(" ", $mtime);
- $mtime = $mtime[1] + $mtime[0];
- $starttime = $mtime;
- define('START', $starttime);
- $includePath = dirname(__FILE__);
- $main_configuration_file_path = $includePath.'/conf/configuration.php';
- $configurationYML = $includePath.'/conf/configuration.yml';
- $already_installed = false;
- if (file_exists($main_configuration_file_path)) {
- require_once $main_configuration_file_path;
- $already_installed = true;
- } else {
- $_configuration = array();
- }
- if (file_exists($configurationYML)) {
- $already_installed = true;
- }
- require_once $includePath.'/lib/main_api.lib.php';
- $default_username_length = 40;
- if (api_get_setting('login_is_email') == 'true') {
- $default_username_length = 100;
- }
- define('USERNAME_MAX_LENGTH', $default_username_length);
- $lib_path = api_get_path(LIBRARY_PATH);
- api_request_uri();
- ini_set('include_path', api_create_include_path_setting());
- ini_set('auto_detect_line_endings', '1');
- define('HTMLPURIFIER_PREFIX', $lib_path.'htmlpurifier/library');
- define("_MPDF_TEMP_PATH", api_get_path(SYS_ARCHIVE_PATH));
- define('_MPDF_PATH', api_get_path(LIBRARY_PATH).'mpdf/');
- require_once __DIR__.'../../../vendor/autoload.php';
- use Silex\Application;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpKernel\Exception\HttpException;
- use Symfony\Component\Yaml\Parser;
- $app = new Application();
- if (file_exists($configurationYML)) {
- $yaml = new Parser();
- $_configuration = $yaml->parse(file_get_contents($configurationYML));
- }
- if (!isset($GLOBALS['_configuration'])) {
- $GLOBALS['_configuration'] = $_configuration;
- }
- if (empty($_configuration['system_version'])) {
- $_configuration['system_version'] = (!empty($_configuration['dokeos_version']) ? $_configuration['dokeos_version'] : '');
- $_configuration['system_stable'] = (!empty($_configuration['dokeos_stable']) ? $_configuration['dokeos_stable'] : '');
- $_configuration['software_url'] = 'http://www.chamilo.org/';
- }
- $_configuration['dokeos_version'] = $_configuration['system_version'];
- $_configuration['dokeos_stable'] = $_configuration['system_stable'];
- $userPasswordCrypted = (!empty($_configuration['password_encryption']) ? $_configuration['password_encryption'] : 'sha1');
- $app['configuration_file'] = $main_configuration_file_path;
- $app['configuration_yml_file'] = $configurationYML;
- $app['configuration'] = $_configuration;
- $app['languages_file'] = array();
- $app['installed'] = $already_installed;
- require_once __DIR__.'/../../resources/config/dev.php';
- $app->register(new Silex\Provider\UrlGeneratorServiceProvider());
- $app->register(new Silex\Provider\ValidatorServiceProvider());
- $app->register(new Silex\Provider\TranslationServiceProvider(), array(
- 'locale' => 'en',
- 'locale_fallback' => 'en'
- ));
- $app['classic_layout'] = false;
- $app['breadcrumb'] = array();
- $app->register(new Silex\Provider\FormServiceProvider());
- $app['allowed'] = true;
- $app->register(
- new Silex\Provider\TwigServiceProvider(),
- array(
- 'twig.path' => array(
- api_get_path(SYS_CODE_PATH).'template',
- api_get_path(SYS_PLUGIN_PATH)
- ),
- 'twig.form.templates' => array('form_div_layout.html.twig', 'default/form/form_custom_template.tpl'),
- 'twig.options' => array(
- 'debug' => $app['debug'],
- 'charset' => 'utf-8',
- 'strict_variables' => false,
- 'autoescape' => false,
- 'cache' => $app['debug'] ? false : $app['twig.cache.path'],
- 'optimizations' => -1,
- )
- )
- );
- $app['twig'] = $app->share(
- $app->extend('twig', function ($twig, $app) {
- $twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
- $twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
- $twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
- $twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
- $twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
- $twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate'));
- $twig->addFilter(
- 'display_page_subheader',
- new Twig_Filter_Function('Display::page_subheader_and_translate')
- );
- $twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path'));
- $twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
- return $twig;
- })
- );
- $app->register(new Silex\Provider\ServiceControllerServiceProvider());
- if (is_writable($app['cache.path'])) {
-
- $app->register(
- new Silex\Provider\MonologServiceProvider(),
- array(
- 'monolog.logfile' => $app['chamilo.log'],
- 'monolog.name' => 'chamilo',
- )
- );
-
-
- }
- if (isset($_configuration['main_database'])) {
- $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
- 'db.options' => array(
- 'driver' => 'pdo_mysql',
- 'dbname' => $_configuration['main_database'],
- 'user' => $_configuration['db_user'],
- 'password' => $_configuration['db_password'],
- 'host' => $_configuration['db_host'],
- 'driverOptions' => array(
- 1002 => 'SET NAMES utf8'
- )
- )
- ));
-
- $app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array(
- 'orm.auto_generate_proxies' => true,
- "orm.proxies_dir" => $app['db.orm.proxies_dir'],
-
- "orm.em.options" => array(
- "mappings" => array(
- array(
- "type" => "annotation",
- "namespace" => "Entity",
- "path" => api_get_path(INCLUDE_PATH).'Entity',
- )
- ),
- ),
- ));
-
- $timestampableListener = new \Gedmo\Timestampable\TimestampableListener();
- $app['db.event_manager']->addEventSubscriber($timestampableListener);
- $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
- $app['db.event_manager']->addEventSubscriber($sluggableListener);
- $sortableListener = new \Gedmo\Sortable\SortableListener();
- $app['db.event_manager']->addEventSubscriber($sortableListener);
- }
- $app['is_admin'] = false;
- use Silex\ServiceProviderInterface;
- class ChamiloServiceProvider implements ServiceProviderInterface
- {
- public function register(Application $app)
- {
-
- $app['template'] = $app->share(function () use ($app) {
- $template = new Template(null, $app);
- return $template;
- });
- }
- public function boot(Application $app)
- {
- }
- }
- $app->register(new ChamiloServiceProvider(), array());
- $app->error(
- function (\Exception $e, $code) use ($app) {
- if ($app['debug']) {
-
- }
- if (isset($code)) {
- switch ($code) {
- case 404:
- $message = 'The requested page could not be found.';
- break;
- default:
-
- $message = $e->getMessage();
- }
- } else {
- $code = null;
- $message = null;
- }
-
- $app['template']->assign('error_code', $code);
- $app['template']->assign('error_message', $message);
- $response = $app['template']->render_layout('error.tpl');
- return new Response($response);
- }
- );
- if ($app['debug'] && isset($_configuration['main_database'])) {
- $logger = new Doctrine\DBAL\Logging\DebugStack();
- $app['db.config']->setSQLLogger($logger);
- $app->after(function() use ($app, $logger) {
-
- foreach ( $logger->queries as $query ) {
- $app['monolog']->debug($query['sql'], array('params' =>$query['params'], 'types' => $query['types']));
- }
- });
- }
- $app['template.show_header'] = true;
- $app['template.show_footer'] = true;
- $app['template.show_learnpath'] = true;
- $app['template.hide_global_chat'] = true;
- $app['template.load_plugins'] = true;
- $app['template_style'] = 'default';
- $app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
- require_once $lib_path.'database.constants.inc.php';
- require_once $lib_path.'text.lib.php';
- require_once $lib_path.'array.lib.php';
- require_once $lib_path.'events.lib.inc.php';
- require_once $lib_path.'online.inc.php';
- global $database_connection;
- if (!($conn_return = @Database::connect(
- array(
- 'server' => $_configuration['db_host'],
- 'username' => $_configuration['db_user'],
- 'password' => $_configuration['db_password'],
- 'persistent' => $_configuration['db_persistent_connection']
-
- )
- ))
- ) {
-
- }
- if (!empty($_configuration['multiple_access_urls'])) {
- $_configuration['access_url'] = 1;
- $access_urls = api_get_access_urls();
- $protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
- $request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
- $request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
- foreach ($access_urls as & $details) {
- if ($request_url1 == $details['url'] or $request_url2 == $details['url']) {
- $_configuration['access_url'] = $details['id'];
- }
- }
- } else {
- $_configuration['access_url'] = 1;
- }
- $charset = 'UTF-8';
- $checkConnection = false;
- if (isset($_configuration['main_database'])) {
-
- Database::query("set session sql_mode='';");
- $checkConnection = @Database::select_db($_configuration['main_database'], $database_connection);
- if ($checkConnection) {
-
- Database::query("SET SESSION character_set_server='utf8';");
- Database::query("SET SESSION collation_server='utf8_general_ci';");
-
-
-
-
- if (api_is_utf8($charset)) {
-
- Database::query("SET NAMES 'utf8';");
- } else {
- Database::query("SET CHARACTER SET '".Database::to_db_encoding($charset)."';");
- }
- Database::query("SET NAMES 'utf8';");
- }
- }
- $charset_initial_value = $charset;
- api_initialize_internationalization();
- api_set_internationalization_default_encoding($charset);
- Chamilo::session()->start($already_installed);
- if ($already_installed && $checkConnection) {
- $settings_refresh_info = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
- $settings_latest_update = $settings_refresh_info ? $settings_refresh_info['selected_value'] : null;
- $_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
- $_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
- if (empty($_setting)) {
- api_set_settings_and_plugins();
- } else {
- if (isset($_setting['settings_latest_update']) && $_setting['settings_latest_update'] != $settings_latest_update) {
- api_set_settings_and_plugins();
- $_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
- $_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
- }
- }
- }
- require_once $lib_path.'formvalidator/Rule/allowed_tags.inc.php';
- $app['this_section'] = SECTION_GLOBAL;
- require $includePath.'/local.inc.php';
- $administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com';
- $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';
- if ($already_installed) {
- $mail_conf = api_get_path(CONFIGURATION_PATH).'mail.conf.php';
- if (file_exists($mail_conf)) {
- require_once $mail_conf;
- }
- }
- $app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
- 'swiftmailer.options' => array(
- 'host' => isset($platform_email['SMTP_HOST']) ? $platform_email['SMTP_HOST'] : null,
- 'port' => isset($platform_email['SMTP_PORT']) ? $platform_email['SMTP_PORT'] : null,
- 'username' => isset($platform_email['SMTP_USER']) ? $platform_email['SMTP_USER'] : null,
- 'password' => isset($platform_email['SMTP_PASS']) ? $platform_email['SMTP_PASS'] : null,
- 'encryption' => null,
- 'auth_mode' => null
- )
- ));
- $app['mailer'] = $app->share(function ($app) {
- return new \Swift_Mailer($app['swiftmailer.transport']);
- });
- if ($already_installed && !$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {
- LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : '');
- }
- $user_language = api_get_user_language();
- $app['this_script'] = isset($this_script) ? $this_script : null;
- if ($already_installed) {
- $app['language_interface'] = $language_interface = api_get_language_interface();
- } else {
- $app['language_interface'] = $language_interface = 'english';
- }
- $language_interface_initial_value = $language_interface;
- $langPath = api_get_path(SYS_LANG_PATH);
- $this_script = $app['this_script'];
- $language_interface = $app['language_interface'];
- if (isset($this_script) && $this_script == 'sub_language') {
- require_once api_get_path(SYS_CODE_PATH).'admin/sub_language.class.php';
-
- $language_files_to_load = SubLanguageManager:: get_lang_folder_files_list(
- api_get_path(SYS_LANG_PATH).'english',
- true
- );
-
- $languageId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
- $parent_language = SubLanguageManager::get_all_information_of_language($languageId);
- $subLanguageId = isset($_REQUEST['sub_language_id']) ? $_REQUEST['sub_language_id'] : null;
-
- $sub_language = SubLanguageManager::get_all_information_of_language($subLanguageId);
- $english_language_array = $parent_language_array = $sub_language_array = array();
- if (!empty($language_files_to_load))
- foreach ($language_files_to_load as $language_file_item) {
- $lang_list_pre = array_keys($GLOBALS);
-
- $path = $langPath.'english/'.$language_file_item.'.inc.php';
- if (file_exists($path)) {
- include $path;
- }
- $lang_list_post = array_keys($GLOBALS);
- $lang_list_result = array_diff($lang_list_post, $lang_list_pre);
- unset($lang_list_pre);
-
- $english_language_array[$language_file_item] = compact($lang_list_result);
-
- foreach ($lang_list_result as $item) {
- unset(${$item});
- }
- $parent_file = $langPath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
- if (file_exists($parent_file) && is_file($parent_file)) {
- include_once $parent_file;
- }
-
- $parent_language_array[$language_file_item] = compact($lang_list_result);
-
- foreach ($lang_list_result as $item) {
- unset(${$item});
- }
- if (!empty($sub_language)) {
- $sub_file = $langPath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
- if (file_exists($sub_file) && is_file($sub_file)) {
- include $sub_file;
- }
- }
-
- $sub_language_array[$language_file_item] = compact($lang_list_result);
-
- foreach ($lang_list_result as $item) {
- unset(${$item});
- }
- }
- }
- $language_files = array();
- $language_files[] = 'trad4all';
- $language_files[] = 'notification';
- $language_files[] = 'accessibility';
- $language_files[] = 'index';
- $language_files[] = 'courses';
- if (isset($language_file)) {
- if (!is_array($language_file)) {
- $language_files[] = $language_file;
- } else {
- $language_files = array_merge($language_files, $language_file);
- }
- }
- if (isset($app['languages_file'])) {
- $language_files = array_merge($language_files, $app['languages_file']);
- }
- if (is_array($language_files)) {
-
- if (api_get_setting('allow_use_sub_language') == 'true') {
- require_once api_get_path(SYS_CODE_PATH).'admin/sub_language.class.php';
- $parent_path = SubLanguageManager::get_parent_language_path($language_interface);
- foreach ($language_files as $index => $language_file) {
-
- include $langPath.'english/'.$language_file.'.inc.php';
-
- $lang_file = $langPath.$language_interface.'/'.$language_file.'.inc.php';
- $parent_lang_file = $langPath.$parent_path.'/'.$language_file.'.inc.php';
-
- if (file_exists($parent_lang_file)) {
- include $parent_lang_file;
- }
-
- if (file_exists($lang_file)) {
- include $lang_file;
- }
- }
- } else {
-
-
- foreach ($language_files as $index => $language_file) {
-
- include $langPath.'english/'.$language_file.'.inc.php';
-
- $langFile = $langPath.$language_interface.'/'.$language_file.'.inc.php';
- if (file_exists($langFile)) {
- include $langFile;
- }
- }
- }
- }
- error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
- if (api_get_setting('server_type') == 'test') {
-
- } else {
-
-
-
- }
- $app->before(
- function () use ($app, $checkConnection) {
- if (!file_exists($app['configuration_file']) && !file_exists($app['configuration_yml_file'])) {
- return new RedirectResponse(api_get_path(WEB_CODE_PATH).'install');
- $app->abort(500, "Incorrect PHP version");
- }
-
- if (api_check_php_version() == false) {
- $app->abort(500, "Incorrect PHP version");
- }
- if ($checkConnection == false) {
- $app->abort(500, "Database not available");
- }
- if (!is_writable(api_get_path(SYS_ARCHIVE_PATH))) {
- $app->abort(500, "archive folder must be writeable");
- }
-
-
- }
- );
- $app->finish(
- function () use ($app) {
-
- $mtime = microtime();
- $mtime = explode(" ", $mtime);
- $mtime = $mtime[1] + $mtime[0];
- $message = "Page loaded in:".($mtime - START);
- $app['monolog']->addInfo($message);
- $message = "memory_get_usage: ".format_file_size(memory_get_usage(true));
- $app['monolog']->addInfo($message);
- $message = "memory_get_peak_usage: ".format_file_size(memory_get_peak_usage(true));
- $app['monolog']->addInfo($message);
- }
- );
- $charset = $charset_initial_value;
- $text_dir = api_get_text_direction();
- if (!isset($_SESSION['login_as']) && isset($_user)) {
-
- $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
- $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".$_user["user_id"]."' ORDER BY login_date DESC LIMIT 0,1";
- $q_last_connection = Database::query($sql_last_connection);
- if (Database::num_rows($q_last_connection) > 0) {
- $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
-
- $sql_logout_date = "SELECT logout_date FROM $tbl_track_login WHERE login_id=$i_id_last_connection";
- $q_logout_date = Database::query($sql_logout_date);
- $res_logout_date = convert_sql_date(Database::result($q_logout_date, 0, 'logout_date'));
- if ($res_logout_date < time() - $_configuration['session_lifetime']) {
-
- event_login();
-
- $q_last_connection = Database::query($sql_last_connection);
- $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
- }
- $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
- Database::query($s_sql_update_logout_date);
- }
- }
- if (isset($_configuration['language_measure_frequency']) && $_configuration['language_measure_frequency'] == 1) {
- require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
- $langstats = new langstats();
- }
- $default_quota = api_get_setting('default_document_quotum');
- if (empty($default_quota)) {
- $default_quota = 100000000;
- }
- define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
- $app['pages.controller'] = $app->share(function () use ($app) {
- return new PagesController($app['pages.repository']);
- });
- $app['index.controller'] = $app->share(function () use ($app) {
- return new ChamiloLMS\Controller\IndexController();
- });
- $app['userportal.controller'] = $app->share(function () use ($app) {
- return new ChamiloLMS\Controller\UserPortalController();
- });
- $app['learnpath.controller'] = $app->share(function () use ($app) {
- return new ChamiloLMS\Controller\LearnpathController();
- });
- $app->get('/', 'index.controller:classicAction');
- $app->post('/', 'index.controller:classicAction');
- $app->get('/index', 'index.controller:indexAction')->bind('index');
- $app->get('/userportal', 'userportal.controller:indexAction');
- $app->get('/logout', 'index.controller:logoutAction');
- $app->match('/learnpath/subscribe_users/{lpId}', 'learnpath.controller:indexAction', 'GET|POST')->bind('subscribe_users');
- return $app;
|