template.lib.php 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
  4. use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
  5. use Chamilo\UserBundle\Entity\User;
  6. /**
  7. * Class Template.
  8. *
  9. * @author Julio Montoya <gugli100@gmail.com>
  10. *
  11. * @todo better organization of the class, methods and variables
  12. */
  13. class Template
  14. {
  15. /**
  16. * The Template folder name see main/template.
  17. *
  18. * @var string
  19. */
  20. public $templateFolder = 'default';
  21. /**
  22. * The theme that will be used: chamilo, public_admin, chamilo_red, etc
  23. * This variable is set from the database.
  24. *
  25. * @var string
  26. */
  27. public $theme = '';
  28. /**
  29. * @var string
  30. */
  31. public $preview_theme = '';
  32. public $title = null;
  33. public $show_header;
  34. public $show_footer;
  35. public $help;
  36. public $menu_navigation = []; //Used in the userportal.lib.php function: return_navigation_course_links()
  37. public $show_learnpath = false; // This is a learnpath section or not?
  38. public $plugin = null;
  39. public $course_id = null;
  40. public $user_is_logged_in = false;
  41. public $twig = null;
  42. /* Loads chamilo plugins */
  43. public $load_plugins = false;
  44. public $params = [];
  45. public $force_plugin_load = false;
  46. public $responseCode = 0;
  47. private $themeDir;
  48. /**
  49. * @param string $title
  50. * @param bool $show_header
  51. * @param bool $show_footer
  52. * @param bool $show_learnpath
  53. * @param bool $hide_global_chat
  54. * @param bool $load_plugins
  55. * @param int $responseCode
  56. * @param bool $sendHeaders send http headers or not
  57. */
  58. public function __construct(
  59. $title = '',
  60. $show_header = true,
  61. $show_footer = true,
  62. $show_learnpath = false,
  63. $hide_global_chat = false,
  64. $load_plugins = true,
  65. $sendHeaders = true,
  66. $responseCode = 0
  67. ) {
  68. // Page title
  69. $this->title = $title;
  70. $this->show_learnpath = $show_learnpath;
  71. $this->setResponseCode($responseCode);
  72. if (empty($this->show_learnpath)) {
  73. $origin = api_get_origin();
  74. if ($origin === 'learnpath') {
  75. $this->show_learnpath = true;
  76. $show_footer = false;
  77. $show_header = false;
  78. }
  79. }
  80. $this->hide_global_chat = $hide_global_chat;
  81. $this->load_plugins = $load_plugins;
  82. $template_paths = [
  83. api_get_path(SYS_CODE_PATH).'template/overrides', // user defined templates
  84. api_get_path(SYS_CODE_PATH).'template', //template folder
  85. api_get_path(SYS_PLUGIN_PATH), // plugin folder
  86. ];
  87. $urlId = api_get_current_access_url_id();
  88. $cache_folder = api_get_path(SYS_ARCHIVE_PATH).'twig/'.$urlId.'/';
  89. if (!is_dir($cache_folder)) {
  90. mkdir($cache_folder, api_get_permissions_for_new_directories(), true);
  91. }
  92. $loader = new Twig_Loader_Filesystem($template_paths);
  93. $isTestMode = api_get_setting('server_type') === 'test';
  94. //Setting Twig options depending on the server see http://twig.sensiolabs.org/doc/api.html#environment-options
  95. if ($isTestMode) {
  96. $options = [
  97. //'cache' => api_get_path(SYS_ARCHIVE_PATH), //path to the cache folder
  98. 'autoescape' => false,
  99. 'debug' => true,
  100. 'auto_reload' => true,
  101. 'optimizations' => 0,
  102. // turn on optimizations with -1
  103. 'strict_variables' => false,
  104. //If set to false, Twig will silently ignore invalid variables
  105. ];
  106. } else {
  107. $options = [
  108. 'cache' => $cache_folder,
  109. //path to the cache folder
  110. 'autoescape' => false,
  111. 'debug' => false,
  112. 'auto_reload' => false,
  113. 'optimizations' => -1,
  114. // turn on optimizations with -1
  115. 'strict_variables' => false,
  116. //If set to false, Twig will silently ignore invalid variables
  117. ];
  118. }
  119. $this->twig = new Twig_Environment($loader, $options);
  120. if ($isTestMode) {
  121. $this->twig->addExtension(new Twig_Extension_Debug());
  122. }
  123. // Twig filters setup
  124. $filters = [
  125. 'var_dump',
  126. 'get_plugin_lang',
  127. 'get_lang',
  128. 'api_get_path',
  129. 'api_get_local_time',
  130. 'api_convert_and_format_date',
  131. 'api_is_allowed_to_edit',
  132. 'api_get_user_info',
  133. 'api_get_configuration_value',
  134. 'api_get_setting',
  135. [
  136. 'name' => 'return_message',
  137. 'callable' => 'Display::return_message_and_translate',
  138. ],
  139. [
  140. 'name' => 'display_page_header',
  141. 'callable' => 'Display::page_header_and_translate',
  142. ],
  143. [
  144. 'name' => 'display_page_subheader',
  145. 'callable' => 'Display::page_subheader_and_translate',
  146. ],
  147. [
  148. 'name' => 'icon',
  149. 'callable' => 'Display::get_icon_path',
  150. ],
  151. [
  152. 'name' => 'img',
  153. 'callable' => 'Display::get_image',
  154. ],
  155. [
  156. 'name' => 'format_date',
  157. 'callable' => 'api_format_date',
  158. ],
  159. [
  160. 'name' => 'get_template',
  161. 'callable' => 'api_find_template',
  162. ],
  163. [
  164. 'name' => 'date_to_time_ago',
  165. 'callable' => 'Display::dateToStringAgoAndLongDate',
  166. ],
  167. ];
  168. foreach ($filters as $filter) {
  169. if (is_array($filter)) {
  170. $this->twig->addFilter(new Twig_SimpleFilter($filter['name'], $filter['callable']));
  171. } else {
  172. $this->twig->addFilter(new Twig_SimpleFilter($filter, $filter));
  173. }
  174. }
  175. $functions = [
  176. ['name' => 'get_tutors_names', 'callable' => 'Template::returnTutorsNames'],
  177. ['name' => 'get_teachers_names', 'callable' => 'Template::returnTeachersNames'],
  178. ];
  179. foreach ($functions as $function) {
  180. $this->twig->addFunction(new Twig_SimpleFunction($function['name'], $function['callable']));
  181. }
  182. // Setting system variables
  183. $this->set_system_parameters();
  184. // Setting user variables
  185. $this->set_user_parameters();
  186. // Setting course variables
  187. $this->set_course_parameters();
  188. // Setting administrator variables
  189. $this->setAdministratorParams();
  190. //$this->setCSSEditor();
  191. // Header and footer are showed by default
  192. $this->set_footer($show_footer);
  193. $this->set_header($show_header);
  194. $this->set_header_parameters($sendHeaders);
  195. $this->set_footer_parameters();
  196. $defaultStyle = api_get_configuration_value('default_template');
  197. if (!empty($defaultStyle)) {
  198. $this->templateFolder = $defaultStyle;
  199. }
  200. $this->assign('template', $this->templateFolder);
  201. $this->assign('locale', api_get_language_isocode());
  202. $this->assign('login_class', null);
  203. $allow = api_get_configuration_value('show_language_selector_in_menu');
  204. if ($allow) {
  205. $this->assign('language_form', api_display_language_form());
  206. }
  207. // Chamilo plugins
  208. if ($this->show_header) {
  209. if ($this->load_plugins) {
  210. $this->plugin = new AppPlugin();
  211. //1. Showing installed plugins in regions
  212. $pluginRegions = $this->plugin->get_plugin_regions();
  213. foreach ($pluginRegions as $region) {
  214. $this->set_plugin_region($region);
  215. }
  216. //2. Loading the course plugin info
  217. global $course_plugin;
  218. if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
  219. //Load plugin get_langs
  220. $this->plugin->load_plugin_lang_variables($course_plugin);
  221. }
  222. }
  223. }
  224. }
  225. /**
  226. * Return the item's url key:.
  227. *
  228. * c_id=xx&id=xx
  229. *
  230. * @param object $item
  231. *
  232. * @return string
  233. */
  234. public static function key($item)
  235. {
  236. $id = isset($item->id) ? $item->id : null;
  237. $c_id = isset($item->c_id) ? $item->c_id : null;
  238. $result = '';
  239. if ($c_id) {
  240. $result = "c_id=$c_id";
  241. }
  242. if ($id) {
  243. if ($result) {
  244. $result .= "&amp;id=$id";
  245. } else {
  246. $result .= "&amp;id=$id";
  247. }
  248. }
  249. return $result;
  250. }
  251. /**
  252. * @param string $helpInput
  253. */
  254. public function setHelp($helpInput = null)
  255. {
  256. if (!empty($helpInput)) {
  257. $help = $helpInput;
  258. } else {
  259. $help = $this->help;
  260. }
  261. $content = '';
  262. if (api_get_setting('enable_help_link') == 'true') {
  263. if (!empty($help)) {
  264. $help = Security::remove_XSS($help);
  265. $content = '<div class="help">';
  266. $content .= Display::url(
  267. Display::return_icon('help.large.png', get_lang('Help')),
  268. api_get_path(WEB_CODE_PATH).'help/help.php?open='.$help,
  269. [
  270. 'class' => 'ajax',
  271. 'data-title' => get_lang('Help'),
  272. ]
  273. );
  274. $content .= '</div>';
  275. }
  276. }
  277. $this->assign('help_content', $content);
  278. }
  279. /**
  280. * Use template system to parse the actions menu.
  281. *
  282. * @todo finish it!
  283. */
  284. public function set_actions($actions)
  285. {
  286. $action_string = '';
  287. if (!empty($actions)) {
  288. foreach ($actions as $action) {
  289. $action_string .= $action;
  290. }
  291. }
  292. $this->assign('actions', $actions);
  293. }
  294. /**
  295. * Shortcut to display a 1 col layout (index.php).
  296. * */
  297. public function display_one_col_template()
  298. {
  299. $tpl = $this->get_template('layout/layout_1_col.tpl');
  300. $this->display($tpl);
  301. }
  302. /**
  303. * Shortcut to display a 2 col layout (userportal.php).
  304. */
  305. public function display_two_col_template()
  306. {
  307. $tpl = $this->get_template('layout/layout_2_col.tpl');
  308. $this->display($tpl);
  309. }
  310. /**
  311. * Displays an empty template.
  312. */
  313. public function display_blank_template()
  314. {
  315. $tpl = $this->get_template('layout/blank.tpl');
  316. $this->display($tpl);
  317. }
  318. /**
  319. * Displays an empty template.
  320. */
  321. public function displayBlankTemplateNoHeader()
  322. {
  323. $tpl = $this->get_template('layout/blank_no_header.tpl');
  324. $this->display($tpl);
  325. }
  326. /**
  327. * Displays an empty template.
  328. */
  329. public function display_no_layout_template()
  330. {
  331. $tpl = $this->get_template('layout/no_layout.tpl');
  332. $this->display($tpl);
  333. }
  334. /**
  335. * Sets the footer visibility.
  336. *
  337. * @param bool true if we show the footer
  338. */
  339. public function set_footer($status)
  340. {
  341. $this->show_footer = $status;
  342. $this->assign('show_footer', $status);
  343. }
  344. /**
  345. * return true if toolbar has to be displayed for user.
  346. *
  347. * @return bool
  348. */
  349. public static function isToolBarDisplayedForUser()
  350. {
  351. //Toolbar
  352. $show_admin_toolbar = api_get_setting('show_admin_toolbar');
  353. $show_toolbar = false;
  354. switch ($show_admin_toolbar) {
  355. case 'do_not_show':
  356. break;
  357. case 'show_to_admin':
  358. if (api_is_platform_admin()) {
  359. $show_toolbar = true;
  360. }
  361. break;
  362. case 'show_to_admin_and_teachers':
  363. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  364. $show_toolbar = true;
  365. }
  366. break;
  367. case 'show_to_all':
  368. $show_toolbar = true;
  369. break;
  370. }
  371. return $show_toolbar;
  372. }
  373. /**
  374. * Sets the header visibility.
  375. *
  376. * @param bool true if we show the header
  377. */
  378. public function set_header($status)
  379. {
  380. $this->show_header = $status;
  381. $this->assign('show_header', $status);
  382. $show_toolbar = 0;
  383. if (self::isToolBarDisplayedForUser()) {
  384. $show_toolbar = 1;
  385. }
  386. $this->assign('show_toolbar', $show_toolbar);
  387. // Only if course is available
  388. $courseToolBar = '';
  389. $show_course_navigation_menu = '';
  390. if (!empty($this->course_id) && $this->user_is_logged_in) {
  391. if (api_get_setting('show_toolshortcuts') != 'false') {
  392. // Course toolbar
  393. $courseToolBar = CourseHome::show_navigation_tool_shortcuts();
  394. }
  395. if (api_get_setting('show_navigation_menu') != 'false') {
  396. // Course toolbar
  397. $show_course_navigation_menu = CourseHome::show_navigation_menu();
  398. }
  399. }
  400. $this->assign('show_course_shortcut', $courseToolBar);
  401. $this->assign('show_course_navigation_menu', $show_course_navigation_menu);
  402. }
  403. /**
  404. * Returns the sub-folder and filename for the given tpl file.
  405. *
  406. * If template not found in overrides/ or custom template folder, the default template will be used.
  407. *
  408. * @param string $name
  409. *
  410. * @return string
  411. */
  412. public static function findTemplateFilePath($name)
  413. {
  414. $sysTemplatePath = api_get_path(SYS_TEMPLATE_PATH);
  415. // Check if the tpl file is present in the main/template/overrides/ dir
  416. // Overrides is a special directory meant for temporary template
  417. // customization. It must be taken into account before anything else
  418. if (is_readable($sysTemplatePath."overrides/$name")) {
  419. return "overrides/$name";
  420. }
  421. $defaultFolder = api_get_configuration_value('default_template');
  422. // If a template folder has been manually defined, search for the right
  423. // file, and if not found, go for the same file in the default template
  424. if ($defaultFolder && $defaultFolder != 'default') {
  425. // Avoid missing template error, use the default file.
  426. if (file_exists($sysTemplatePath."$defaultFolder/$name")) {
  427. return "$defaultFolder/$name";
  428. }
  429. }
  430. return "default/$name";
  431. }
  432. /**
  433. * Call non-static for Template::findTemplateFilePath.
  434. *
  435. * @see Template::findTemplateFilePath()
  436. *
  437. * @param string $name
  438. *
  439. * @return string
  440. */
  441. public function get_template($name)
  442. {
  443. return api_find_template($name);
  444. }
  445. /**
  446. * Get CSS themes sub-directory.
  447. *
  448. * @param string $theme
  449. *
  450. * @return string with a trailing slash, e.g. 'themes/chamilo_red/'
  451. */
  452. public static function getThemeDir($theme)
  453. {
  454. $themeDir = 'themes/'.$theme.'/';
  455. $virtualTheme = api_get_configuration_value('virtual_css_theme_folder');
  456. if (!empty($virtualTheme)) {
  457. $virtualThemeList = api_get_themes(true);
  458. $isVirtualTheme = in_array($theme, array_keys($virtualThemeList));
  459. if ($isVirtualTheme) {
  460. $themeDir = 'themes/'.$virtualTheme.'/'.$theme.'/';
  461. }
  462. }
  463. return $themeDir;
  464. }
  465. /**
  466. * Set system parameters from api_get_configuration into _s array for use in TPLs
  467. * Also fills the _p array from getWebPaths().
  468. *
  469. * @uses \self::getWebPaths()
  470. */
  471. public function set_system_parameters()
  472. {
  473. // Get the interface language from global.inc.php
  474. global $language_interface;
  475. $this->theme = api_get_visual_theme();
  476. if (!empty($this->preview_theme)) {
  477. $this->theme = $this->preview_theme;
  478. }
  479. $this->themeDir = self::getThemeDir($this->theme);
  480. // Setting app paths/URLs
  481. $this->assign('_p', $this->getWebPaths());
  482. // Here we can add system parameters that can be use in any template
  483. $_s = [
  484. 'software_name' => api_get_configuration_value('software_name'),
  485. 'system_version' => api_get_configuration_value('system_version'),
  486. 'site_name' => api_get_setting('siteName'),
  487. 'institution' => api_get_setting('Institution'),
  488. 'date' => api_format_date('now', DATE_FORMAT_LONG),
  489. 'timezone' => api_get_timezone(),
  490. 'gamification_mode' => api_get_setting('gamification_mode'),
  491. 'language_interface' => $language_interface,
  492. ];
  493. $this->assign('_s', $_s);
  494. }
  495. /**
  496. * Set theme, include mainstream CSS files.
  497. *
  498. * @see setCssCustomFiles() for additional CSS sheets
  499. */
  500. public function setCssFiles()
  501. {
  502. global $disable_js_and_css_files;
  503. $css = [];
  504. // Default CSS Bootstrap
  505. $bowerCSSFiles = [
  506. 'fontawesome/css/font-awesome.min.css',
  507. 'jquery-ui/themes/smoothness/theme.css',
  508. 'jquery-ui/themes/smoothness/jquery-ui.min.css',
  509. 'mediaelement/build/mediaelementplayer.min.css',
  510. 'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.css',
  511. 'bootstrap/dist/css/bootstrap.min.css',
  512. 'jquery.scrollbar/jquery.scrollbar.css',
  513. 'bootstrap-daterangepicker/daterangepicker.css',
  514. 'bootstrap-select/dist/css/bootstrap-select.min.css',
  515. 'select2/dist/css/select2.min.css',
  516. 'mediaelement/plugins/vrview/vrview.css',
  517. ];
  518. $hide = api_get_configuration_value('hide_flag_language_switcher');
  519. if ($hide === false) {
  520. $bowerCSSFiles[] = 'flag-icon-css/css/flag-icon.min.css';
  521. }
  522. $features = api_get_configuration_value('video_features');
  523. $defaultFeatures = [
  524. 'playpause',
  525. 'current',
  526. 'progress',
  527. 'duration',
  528. 'tracks',
  529. 'volume',
  530. 'fullscreen',
  531. 'vrview',
  532. 'markersrolls',
  533. ];
  534. if (!empty($features) && isset($features['features'])) {
  535. foreach ($features['features'] as $feature) {
  536. if ($feature === 'vrview') {
  537. continue;
  538. }
  539. $bowerCSSFiles[] = "mediaelement/plugins/$feature/$feature.css";
  540. $defaultFeatures[] = $feature;
  541. }
  542. }
  543. foreach ($bowerCSSFiles as $file) {
  544. $css[] = api_get_cdn_path(api_get_path(WEB_PUBLIC_PATH).'assets/'.$file);
  545. }
  546. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
  547. if (api_is_global_chat_enabled()) {
  548. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
  549. }
  550. $css_file_to_string = '';
  551. foreach ($css as $file) {
  552. $css_file_to_string .= api_get_css($file);
  553. }
  554. if (!$disable_js_and_css_files) {
  555. $this->assign('css_static_file_to_string', $css_file_to_string);
  556. }
  557. $defaultFeatures = implode("','", $defaultFeatures);
  558. $this->assign('video_features', $defaultFeatures);
  559. }
  560. /**
  561. * Prepare custom CSS to be added at the very end of the <head> section.
  562. *
  563. * @see setCssFiles() for the mainstream CSS files
  564. */
  565. public function setCssCustomFiles()
  566. {
  567. global $disable_js_and_css_files;
  568. // Base CSS
  569. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
  570. if ($this->show_learnpath) {
  571. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'scorm.css');
  572. if (is_file(api_get_path(SYS_CSS_PATH).$this->themeDir.'learnpath.css')) {
  573. $css[] = api_get_path(WEB_CSS_PATH).$this->themeDir.'learnpath.css';
  574. }
  575. }
  576. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->themeDir.'default.css');
  577. $css[] = api_get_cdn_path(ChamiloApi::getEditorBlockStylePath());
  578. $css_file_to_string = null;
  579. foreach ($css as $file) {
  580. $css_file_to_string .= api_get_css($file);
  581. }
  582. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  583. if (SHOW_TEXT_NEAR_ICONS == true) {
  584. //hack in order to fix the actions buttons
  585. $css_file_to_string .= '<style>
  586. .td_actions a {
  587. float:left;
  588. width:100%;
  589. }
  590. .forum_message_left a {
  591. float:left;
  592. width:100%;
  593. }
  594. </style>';
  595. }
  596. $navigator_info = api_get_navigator();
  597. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  598. $css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
  599. }
  600. if (!$disable_js_and_css_files) {
  601. $this->assign('css_custom_file_to_string', $css_file_to_string);
  602. $style_print = '';
  603. if (is_readable(api_get_path(SYS_CSS_PATH).$this->theme.'/print.css')) {
  604. $style_print = api_get_css(
  605. api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/print.css'),
  606. 'print'
  607. );
  608. }
  609. $this->assign('css_style_print', $style_print);
  610. }
  611. // Logo
  612. $logo = return_logo($this->theme);
  613. $logoPdf = return_logo($this->theme, false);
  614. $this->assign('logo', $logo);
  615. $this->assign('logo_pdf', $logoPdf);
  616. $this->assign('show_media_element', 1);
  617. }
  618. /**
  619. * Declare and define the template variable that will be used to load
  620. * javascript libraries in the header.
  621. */
  622. public function set_js_files()
  623. {
  624. global $disable_js_and_css_files, $htmlHeadXtra;
  625. $isoCode = api_get_language_isocode();
  626. $selectLink = 'bootstrap-select/dist/js/i18n/defaults-'.$isoCode.'_'.strtoupper($isoCode).'.min.js';
  627. if ($isoCode == 'en') {
  628. $selectLink = 'bootstrap-select/dist/js/i18n/defaults-'.$isoCode.'_US.min.js';
  629. }
  630. // JS files
  631. $js_files = [
  632. 'chosen/chosen.jquery.min.js',
  633. ];
  634. if (api_get_setting('accessibility_font_resize') === 'true') {
  635. $js_files[] = 'fontresize.js';
  636. }
  637. $js_file_to_string = '';
  638. $bowerJsFiles = [
  639. 'modernizr/modernizr.js',
  640. 'jquery/dist/jquery.min.js',
  641. 'bootstrap/dist/js/bootstrap.min.js',
  642. 'jquery-ui/jquery-ui.min.js',
  643. 'jqueryui-touch-punch/jquery.ui.touch-punch.min.js',
  644. 'moment/min/moment-with-locales.js',
  645. 'bootstrap-daterangepicker/daterangepicker.js',
  646. 'jquery-timeago/jquery.timeago.js',
  647. 'mediaelement/build/mediaelement-and-player.min.js',
  648. 'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
  649. 'image-map-resizer/js/imageMapResizer.min.js',
  650. 'jquery.scrollbar/jquery.scrollbar.min.js',
  651. 'readmore-js/readmore.min.js',
  652. 'bootstrap-select/dist/js/bootstrap-select.min.js',
  653. $selectLink,
  654. 'select2/dist/js/select2.min.js',
  655. "select2/dist/js/i18n/$isoCode.js",
  656. 'mediaelement/plugins/vrview/vrview.js',
  657. 'js-cookie/src/js.cookie.js',
  658. 'mediaelement/plugins/markersrolls/markersrolls.min.js',
  659. ];
  660. $viewBySession = api_get_setting('my_courses_view_by_session') === 'true';
  661. if ($viewBySession || api_is_global_chat_enabled()) {
  662. // Do not include the global chat in LP
  663. if ($this->show_learnpath == false &&
  664. $this->show_footer == true &&
  665. $this->hide_global_chat == false
  666. ) {
  667. $js_files[] = 'chat/js/chat.js';
  668. $bowerJsFiles[] = 'linkifyjs/linkify.js';
  669. $bowerJsFiles[] = 'linkifyjs/linkify-jquery.js';
  670. }
  671. }
  672. $features = api_get_configuration_value('video_features');
  673. if (!empty($features) && isset($features['features'])) {
  674. foreach ($features['features'] as $feature) {
  675. if ($feature === 'vrview') {
  676. continue;
  677. }
  678. $bowerJsFiles[] = "mediaelement/plugins/$feature/$feature.js";
  679. }
  680. }
  681. if (CHAMILO_LOAD_WYSIWYG === true) {
  682. $bowerJsFiles[] = 'ckeditor/ckeditor.js';
  683. }
  684. if (api_get_setting('include_asciimathml_script') === 'true') {
  685. $bowerJsFiles[] = 'MathJax/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  686. }
  687. // If not English and the language is supported by timepicker, localize
  688. $assetsPath = api_get_path(SYS_PUBLIC_PATH).'assets/';
  689. if ($isoCode != 'en') {
  690. if (is_file($assetsPath.'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-'.$isoCode.'.js') && is_file($assetsPath.'jquery-ui/ui/minified/i18n/datepicker-'.$isoCode.'.min.js')) {
  691. $bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-'.$isoCode.'.js';
  692. $bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-'.$isoCode.'.min.js';
  693. }
  694. }
  695. foreach ($bowerJsFiles as $file) {
  696. $js_file_to_string .= '<script type="text/javascript" src="'.api_get_cdn_path(api_get_path(WEB_PUBLIC_PATH).'assets/'.$file).'"></script>'."\n";
  697. }
  698. foreach ($js_files as $file) {
  699. $js_file_to_string .= api_get_js($file);
  700. }
  701. // Loading email_editor js
  702. if (!api_is_anonymous() && api_get_setting('allow_email_editor') === 'true') {
  703. $template = $this->get_template('mail_editor/email_link.js.tpl');
  704. $js_file_to_string .= $this->fetch($template);
  705. }
  706. if (!$disable_js_and_css_files) {
  707. $this->assign('js_file_to_string', $js_file_to_string);
  708. $extraHeaders = '<script>var _p = '.json_encode($this->getWebPaths(), JSON_PRETTY_PRINT).'</script>';
  709. // Adding jquery ui by default
  710. $extraHeaders .= api_get_jquery_ui_js();
  711. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  712. foreach ($htmlHeadXtra as &$this_html_head) {
  713. $extraHeaders .= $this_html_head."\n";
  714. }
  715. }
  716. $ajax = api_get_path(WEB_AJAX_PATH);
  717. $courseId = api_get_course_id();
  718. if (empty($courseId)) {
  719. $courseLogoutCode = '
  720. <script>
  721. function courseLogout() {
  722. }
  723. </script>';
  724. } else {
  725. $courseLogoutCode = "
  726. <script>
  727. var logOutUrl = '".$ajax."course.ajax.php?a=course_logout&".api_get_cidreq()."';
  728. function courseLogout() {
  729. $.ajax({
  730. async : false,
  731. url: logOutUrl,
  732. success: function (data) {
  733. return 1;
  734. }
  735. });
  736. }
  737. </script>";
  738. }
  739. $extraHeaders .= $courseLogoutCode;
  740. $this->assign('extra_headers', $extraHeaders);
  741. }
  742. }
  743. /**
  744. * Special function to declare last-minute JS libraries which depend on
  745. * other things to be declared first. In particular, it might be useful
  746. * under IE9 with compatibility mode, which for some reason is getting
  747. * upset when a variable is used in a function (even if not used yet)
  748. * when this variable hasn't been defined yet.
  749. */
  750. public function set_js_files_post()
  751. {
  752. global $disable_js_and_css_files;
  753. $js_files = [];
  754. $bower = '';
  755. if (api_is_global_chat_enabled()) {
  756. //Do not include the global chat in LP
  757. if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
  758. $js_files[] = 'chat/js/chat.js';
  759. $bower .= '<script type="text/javascript" src="'.api_get_path(WEB_PUBLIC_PATH).'assets/linkifyjs/linkify.js"></script>';
  760. $bower .= '<script type="text/javascript" src="'.api_get_path(WEB_PUBLIC_PATH).'assets/linkifyjs/linkify-jquery.js"></script>';
  761. }
  762. }
  763. $js_file_to_string = '';
  764. foreach ($js_files as $js_file) {
  765. $js_file_to_string .= api_get_js($js_file);
  766. }
  767. if (!$disable_js_and_css_files) {
  768. $this->assign('js_file_to_string_post', $js_file_to_string.$bower);
  769. }
  770. }
  771. /**
  772. * Show header template.
  773. */
  774. public function show_header_template()
  775. {
  776. $tpl = $this->get_template('layout/show_header.tpl');
  777. $this->display($tpl);
  778. }
  779. /**
  780. * Show footer template.
  781. */
  782. public function show_footer_template()
  783. {
  784. $tpl = $this->get_template('layout/show_footer.tpl');
  785. $this->display($tpl);
  786. }
  787. /**
  788. * Sets the plugin content in a template variable.
  789. *
  790. * @param string $pluginRegion
  791. */
  792. public function set_plugin_region($pluginRegion)
  793. {
  794. if (!empty($pluginRegion)) {
  795. $regionContent = $this->plugin->load_region(
  796. $pluginRegion,
  797. $this,
  798. $this->force_plugin_load
  799. );
  800. $pluginList = $this->plugin->get_installed_plugins();
  801. foreach ($pluginList as $plugin_name) {
  802. // The plugin_info variable is available inside the plugin index
  803. $pluginInfo = $this->plugin->getPluginInfo($plugin_name);
  804. if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) {
  805. $courseInfo = api_get_course_info();
  806. if (!empty($courseInfo)) {
  807. if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof Plugin) {
  808. /** @var Plugin $plugin */
  809. $plugin = $pluginInfo['obj'];
  810. $regionContent .= $plugin->renderRegion($pluginRegion);
  811. }
  812. }
  813. } else {
  814. continue;
  815. }
  816. }
  817. if (!empty($regionContent)) {
  818. $this->assign('plugin_'.$pluginRegion, $regionContent);
  819. } else {
  820. $this->assign('plugin_'.$pluginRegion, null);
  821. }
  822. }
  823. return null;
  824. }
  825. /**
  826. * @param string $template
  827. *
  828. * @return string
  829. */
  830. public function fetch($template = null)
  831. {
  832. $template = $this->twig->loadTemplate($template);
  833. return $template->render($this->params);
  834. }
  835. /**
  836. * @param string $variable
  837. * @param mixed $value
  838. */
  839. public function assign($variable, $value = '')
  840. {
  841. $this->params[$variable] = $value;
  842. }
  843. /**
  844. * Render the template.
  845. *
  846. * @param string $template The template path
  847. * @param bool $clearFlashMessages Clear the $_SESSION variables for flash messages
  848. */
  849. public function display($template, $clearFlashMessages = true)
  850. {
  851. $this->assign('flash_messages', Display::getFlashToString());
  852. if ($clearFlashMessages) {
  853. Display::cleanFlashMessages();
  854. }
  855. echo $this->twig->render($template, $this->params);
  856. }
  857. /**
  858. * Adds a body class for login pages.
  859. */
  860. public function setLoginBodyClass()
  861. {
  862. $this->assign('login_class', 'section-login');
  863. }
  864. /**
  865. * The theme that will be used if the database is not working.
  866. *
  867. * @return string
  868. */
  869. public static function getThemeFallback()
  870. {
  871. $theme = api_get_configuration_value('theme_fallback');
  872. if (empty($theme)) {
  873. $theme = 'chamilo';
  874. }
  875. return $theme;
  876. }
  877. /**
  878. * @param bool|true $setLoginForm
  879. */
  880. public function setLoginForm($setLoginForm = true)
  881. {
  882. global $loginFailed;
  883. $userId = api_get_user_id();
  884. if (!($userId) || api_is_anonymous($userId)) {
  885. // Only display if the user isn't logged in.
  886. $this->assign(
  887. 'login_language_form',
  888. api_display_language_form(true, true)
  889. );
  890. if ($setLoginForm) {
  891. $this->assign('login_form', $this->displayLoginForm());
  892. if ($loginFailed) {
  893. $this->assign('login_failed', $this::handleLoginFailed());
  894. }
  895. }
  896. }
  897. }
  898. /**
  899. * @return string
  900. */
  901. public function handleLoginFailed()
  902. {
  903. $message = get_lang('InvalidId');
  904. if (!isset($_GET['error'])) {
  905. if (api_is_self_registration_allowed()) {
  906. $message = get_lang('InvalidForSelfRegistration');
  907. }
  908. } else {
  909. switch ($_GET['error']) {
  910. case '':
  911. if (api_is_self_registration_allowed()) {
  912. $message = get_lang('InvalidForSelfRegistration');
  913. }
  914. break;
  915. case 'account_expired':
  916. $message = get_lang('AccountExpired');
  917. break;
  918. case 'account_inactive':
  919. $message = get_lang('AccountInactive');
  920. if (api_get_setting('allow_registration') === 'confirmation') {
  921. $message = get_lang('AccountNotConfirmed').PHP_EOL;
  922. $message .= Display::url(
  923. get_lang('ReSendConfirmationMail'),
  924. api_get_path(WEB_PATH).'main/auth/resend_confirmation_mail.php',
  925. ['class' => 'alert-link']
  926. );
  927. }
  928. break;
  929. case 'user_password_incorrect':
  930. $message = get_lang('InvalidId');
  931. break;
  932. case 'access_url_inactive':
  933. $message = get_lang('AccountURLInactive');
  934. break;
  935. case 'wrong_captcha':
  936. $message = get_lang('TheTextYouEnteredDoesNotMatchThePicture');
  937. break;
  938. case 'blocked_by_captcha':
  939. $message = get_lang('AccountBlockedByCaptcha');
  940. break;
  941. case 'multiple_connection_not_allowed':
  942. $message = get_lang('MultipleConnectionsAreNotAllow');
  943. break;
  944. case 'unrecognize_sso_origin':
  945. //$message = get_lang('SSOError');
  946. break;
  947. }
  948. }
  949. return Display::return_message($message, 'error', false);
  950. }
  951. /**
  952. * @return string
  953. */
  954. public function displayLoginForm()
  955. {
  956. $form = new FormValidator(
  957. 'form-login',
  958. 'POST',
  959. null,
  960. null,
  961. null,
  962. FormValidator::LAYOUT_BOX_NO_LABEL
  963. );
  964. $params = [
  965. 'id' => 'login',
  966. 'autofocus' => 'autofocus',
  967. 'icon' => 'user fa-fw',
  968. 'placeholder' => get_lang('UserName'),
  969. ];
  970. $browserAutoCapitalize = false;
  971. // Avoid showing the autocapitalize option if the browser doesn't
  972. // support it: this attribute is against the HTML5 standard
  973. if (api_browser_support('autocapitalize')) {
  974. $browserAutoCapitalize = false;
  975. $params['autocapitalize'] = 'none';
  976. }
  977. $form->addText(
  978. 'login',
  979. get_lang('UserName'),
  980. true,
  981. $params
  982. );
  983. $params = [
  984. 'id' => 'password',
  985. 'icon' => 'lock fa-fw',
  986. 'placeholder' => get_lang('Pass'),
  987. ];
  988. if ($browserAutoCapitalize) {
  989. $params['autocapitalize'] = 'none';
  990. }
  991. $form->addElement(
  992. 'password',
  993. 'password',
  994. get_lang('Pass'),
  995. $params
  996. );
  997. // Captcha
  998. $captcha = api_get_setting('allow_captcha');
  999. $allowCaptcha = $captcha === 'true';
  1000. if ($allowCaptcha) {
  1001. $useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null;
  1002. if ($useCaptcha) {
  1003. $ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
  1004. $options = [
  1005. 'width' => 250,
  1006. 'height' => 90,
  1007. 'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
  1008. 'sessionVar' => basename(__FILE__, '.php'),
  1009. 'imageOptions' => [
  1010. 'font_size' => 20,
  1011. 'font_path' => api_get_path(SYS_FONTS_PATH).'opensans/',
  1012. 'font_file' => 'OpenSans-Regular.ttf',
  1013. //'output' => 'gif'
  1014. ],
  1015. ];
  1016. // Minimum options using all defaults (including defaults for Image_Text):
  1017. //$options = array('callback' => 'qfcaptcha_image.php');
  1018. $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
  1019. $form->addHtml(get_lang('ClickOnTheImageForANewOne'));
  1020. $form->addElement(
  1021. 'text',
  1022. 'captcha',
  1023. get_lang('EnterTheLettersYouSee')
  1024. );
  1025. $form->addRule(
  1026. 'captcha',
  1027. get_lang('EnterTheCharactersYouReadInTheImage'),
  1028. 'required',
  1029. null,
  1030. 'client'
  1031. );
  1032. $form->addRule(
  1033. 'captcha',
  1034. get_lang('TheTextYouEnteredDoesNotMatchThePicture'),
  1035. 'CAPTCHA',
  1036. $captcha_question
  1037. );
  1038. }
  1039. }
  1040. $form->addButton(
  1041. 'submitAuth',
  1042. get_lang('LoginEnter'),
  1043. null,
  1044. 'primary',
  1045. null,
  1046. 'btn-block'
  1047. );
  1048. $html = $form->returnForm();
  1049. if (api_get_setting('openid_authentication') == 'true') {
  1050. include_once api_get_path(SYS_CODE_PATH).'auth/openid/login.php';
  1051. $html .= '<div>'.openid_form().'</div>';
  1052. }
  1053. $pluginKeycloak = api_get_plugin_setting('keycloak', 'tool_enable') === 'true';
  1054. $plugin = null;
  1055. if ($pluginKeycloak) {
  1056. $pluginUrl = api_get_path(WEB_PLUGIN_PATH).'keycloak/start.php?sso';
  1057. $pluginUrl = Display::url('Keycloak', $pluginUrl, ['class' => 'btn btn-primary']);
  1058. $html .= '<div>'.$pluginUrl.'</div>';
  1059. }
  1060. $html .= '<div></div>';
  1061. return $html;
  1062. }
  1063. /**
  1064. * Returns the tutors names for the current course in session
  1065. * Function to use in Twig templates.
  1066. *
  1067. * @return string
  1068. */
  1069. public static function returnTutorsNames()
  1070. {
  1071. $em = Database::getManager();
  1072. $tutors = $em
  1073. ->createQuery('
  1074. SELECT u FROM ChamiloUserBundle:User u
  1075. INNER JOIN ChamiloCoreBundle:SessionRelCourseRelUser scu WITH u.id = scu.user
  1076. WHERE scu.status = :teacher_status AND scu.session = :session AND scu.course = :course
  1077. ')
  1078. ->setParameters([
  1079. 'teacher_status' => SessionRelCourseRelUser::STATUS_COURSE_COACH,
  1080. 'session' => api_get_session_id(),
  1081. 'course' => api_get_course_int_id(),
  1082. ])
  1083. ->getResult();
  1084. $names = [];
  1085. /** @var User $tutor */
  1086. foreach ($tutors as $tutor) {
  1087. $names[] = $tutor->getCompleteName();
  1088. }
  1089. return implode(CourseManager::USER_SEPARATOR, $names);
  1090. }
  1091. /*s
  1092. * Returns the teachers name for the current course
  1093. * Function to use in Twig templates
  1094. * @return string
  1095. */
  1096. public static function returnTeachersNames()
  1097. {
  1098. $em = Database::getManager();
  1099. $teachers = $em
  1100. ->createQuery('
  1101. SELECT u FROM ChamiloUserBundle:User u
  1102. INNER JOIN ChamiloCoreBundle:CourseRelUser cu WITH u.id = cu.user
  1103. WHERE cu.status = :teacher_status AND cu.course = :course
  1104. ')
  1105. ->setParameters([
  1106. 'teacher_status' => User::COURSE_MANAGER,
  1107. 'course' => api_get_course_int_id(),
  1108. ])
  1109. ->getResult();
  1110. $names = [];
  1111. /** @var User $teacher */
  1112. foreach ($teachers as $teacher) {
  1113. $names[] = $teacher->getCompleteName();
  1114. }
  1115. return implode(CourseManager::USER_SEPARATOR, $names);
  1116. }
  1117. /**
  1118. * @param int $code
  1119. */
  1120. public function setResponseCode($code)
  1121. {
  1122. $this->responseCode = $code;
  1123. }
  1124. /**
  1125. * @param string $code
  1126. */
  1127. public function getResponseCode()
  1128. {
  1129. return $this->responseCode;
  1130. }
  1131. /**
  1132. * Assign HTML code to the 'bug_notification' template variable for the side tabs to report issues.
  1133. *
  1134. * @return bool Always return true because there is always a string, even if empty
  1135. */
  1136. public function assignBugNotification()
  1137. {
  1138. //@todo move this in the template
  1139. $rightFloatMenu = '';
  1140. $iconBug = Display::return_icon(
  1141. 'bug.png',
  1142. get_lang('ReportABug'),
  1143. [],
  1144. ICON_SIZE_LARGE
  1145. );
  1146. if (api_get_setting('show_link_bug_notification') === 'true' && $this->user_is_logged_in) {
  1147. $rightFloatMenu = '<div class="report">
  1148. <a href="https://github.com/chamilo/chamilo-lms/wiki/How-to-report-issues" target="_blank">
  1149. '.$iconBug.'
  1150. </a>
  1151. </div>';
  1152. }
  1153. if (api_get_setting('show_link_ticket_notification') === 'true' &&
  1154. $this->user_is_logged_in
  1155. ) {
  1156. // by default is project_id = 1
  1157. $defaultProjectId = 1;
  1158. $iconTicket = Display::return_icon(
  1159. 'help.png',
  1160. get_lang('Ticket'),
  1161. [],
  1162. ICON_SIZE_LARGE
  1163. );
  1164. $courseInfo = api_get_course_info();
  1165. $courseParams = '';
  1166. if (!empty($courseInfo)) {
  1167. $courseParams = api_get_cidreq();
  1168. }
  1169. $url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams;
  1170. $allow = TicketManager::userIsAllowInProject(api_get_user_info(), $defaultProjectId);
  1171. if ($allow) {
  1172. $rightFloatMenu .= '<div class="help">
  1173. <a href="'.$url.'" target="_blank">
  1174. '.$iconTicket.'
  1175. </a>
  1176. </div>';
  1177. }
  1178. }
  1179. $this->assign('bug_notification', $rightFloatMenu);
  1180. return true;
  1181. }
  1182. /**
  1183. * Prepare the _c array for template files. The _c array contains
  1184. * information about the current course.
  1185. */
  1186. private function set_course_parameters()
  1187. {
  1188. //Setting course id
  1189. $course = api_get_course_info();
  1190. if (empty($course)) {
  1191. $this->assign('course_is_set', false);
  1192. return;
  1193. }
  1194. $this->assign('course_is_set', true);
  1195. $this->course_id = $course['id'];
  1196. $_c = [
  1197. 'id' => $course['real_id'],
  1198. 'code' => $course['code'],
  1199. 'title' => $course['name'],
  1200. 'visibility' => $course['visibility'],
  1201. 'language' => $course['language'],
  1202. 'directory' => $course['directory'],
  1203. 'session_id' => api_get_session_id(),
  1204. 'user_is_teacher' => api_is_course_admin(),
  1205. 'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'),
  1206. ];
  1207. $this->assign('course_code', $course['code']);
  1208. $this->assign('_c', $_c);
  1209. }
  1210. /**
  1211. * Prepare the _u array for template files. The _u array contains
  1212. * information about the current user, as returned by
  1213. * api_get_user_info().
  1214. */
  1215. private function set_user_parameters()
  1216. {
  1217. $user_info = [];
  1218. $user_info['logged'] = 0;
  1219. $this->user_is_logged_in = false;
  1220. if (api_user_is_login()) {
  1221. $user_info = api_get_user_info(api_get_user_id(), true);
  1222. $user_info['logged'] = 1;
  1223. $user_info['is_admin'] = 0;
  1224. if (api_is_platform_admin()) {
  1225. $user_info['is_admin'] = 1;
  1226. }
  1227. $user_info['messages_count'] = MessageManager::getCountNewMessages();
  1228. $this->user_is_logged_in = true;
  1229. }
  1230. // Setting the $_u array that could be use in any template
  1231. $this->assign('_u', $user_info);
  1232. }
  1233. /**
  1234. * Get an array of all the web paths available (e.g. 'web' => 'https://my.chamilo.site/').
  1235. *
  1236. * @return array
  1237. */
  1238. private function getWebPaths()
  1239. {
  1240. $queryString = empty($_SERVER['QUERY_STRING']) ? '' : $_SERVER['QUERY_STRING'];
  1241. $requestURI = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
  1242. return [
  1243. 'web' => api_get_path(WEB_PATH),
  1244. 'web_url' => api_get_web_url(),
  1245. 'web_relative' => api_get_path(REL_PATH),
  1246. 'web_course' => api_get_path(WEB_COURSE_PATH),
  1247. 'web_main' => api_get_path(WEB_CODE_PATH),
  1248. 'web_css' => api_get_path(WEB_CSS_PATH),
  1249. 'web_css_theme' => api_get_path(WEB_CSS_PATH).$this->themeDir,
  1250. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  1251. 'web_img' => api_get_path(WEB_IMG_PATH),
  1252. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  1253. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  1254. 'web_upload' => api_get_path(WEB_UPLOAD_PATH),
  1255. 'web_self' => api_get_self(),
  1256. 'self_basename' => basename(api_get_self()),
  1257. 'web_query_vars' => api_htmlentities($queryString),
  1258. 'web_self_query_vars' => api_htmlentities($requestURI),
  1259. 'web_cid_query' => api_get_cidreq(),
  1260. 'web_rel_code' => api_get_path(REL_CODE_PATH),
  1261. ];
  1262. }
  1263. /**
  1264. * Set header parameters.
  1265. *
  1266. * @param bool $sendHeaders send headers
  1267. */
  1268. private function set_header_parameters($sendHeaders)
  1269. {
  1270. global $httpHeadXtra, $interbreadcrumb, $language_file, $_configuration, $this_section;
  1271. $_course = api_get_course_info();
  1272. $nameTools = $this->title;
  1273. $navigation = return_navigation_array();
  1274. $this->menu_navigation = $navigation['menu_navigation'];
  1275. $this->assign('system_charset', api_get_system_encoding());
  1276. if (isset($httpHeadXtra) && $httpHeadXtra) {
  1277. foreach ($httpHeadXtra as &$thisHttpHead) {
  1278. header($thisHttpHead);
  1279. }
  1280. }
  1281. // Get language iso-code for this page - ignore errors
  1282. $this->assign('document_language', api_get_language_isocode());
  1283. $course_title = isset($_course['name']) ? $_course['name'] : null;
  1284. $title_list = [];
  1285. $title_list[] = api_get_setting('Institution');
  1286. $title_list[] = api_get_setting('siteName');
  1287. if (!empty($course_title)) {
  1288. $title_list[] = $course_title;
  1289. }
  1290. if ($nameTools != '') {
  1291. $title_list[] = $nameTools;
  1292. }
  1293. $title_string = '';
  1294. for ($i = 0; $i < count($title_list); $i++) {
  1295. $title_string .= $title_list[$i];
  1296. if (isset($title_list[$i + 1])) {
  1297. $item = trim($title_list[$i + 1]);
  1298. if (!empty($item)) {
  1299. $title_string .= ' - ';
  1300. }
  1301. }
  1302. }
  1303. $this->assign('title_string', $title_string);
  1304. // Setting the theme and CSS files
  1305. $this->setCssFiles();
  1306. $this->set_js_files();
  1307. $this->setCssCustomFiles();
  1308. $browser = api_browser_support('check_browser');
  1309. if ($browser[0] == 'Internet Explorer' && $browser[1] >= '11') {
  1310. $browser_head = '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />';
  1311. $this->assign('browser_specific_head', $browser_head);
  1312. }
  1313. // Implementation of prefetch.
  1314. // See http://cdn.chamilo.org/main/img/online.png for details
  1315. $prefetch = '';
  1316. if (!empty($_configuration['cdn_enable'])) {
  1317. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  1318. foreach ($_configuration['cdn'] as $host => $exts) {
  1319. $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
  1320. }
  1321. }
  1322. $this->assign('prefetch', $prefetch);
  1323. $this->assign('text_direction', api_get_text_direction());
  1324. $this->assign('section_name', 'section-'.$this_section);
  1325. $this->assignFavIcon();
  1326. $this->setHelp();
  1327. $this->assignBugNotification(); //Prepare the 'bug_notification' var for the template
  1328. $this->assignAccessibilityBlock(); //Prepare the 'accessibility' var for the template
  1329. // Preparing values for the menu
  1330. // Logout link
  1331. $hideLogout = api_get_setting('hide_logout_button');
  1332. if ($hideLogout === 'true') {
  1333. $this->assign('logout_link', null);
  1334. } else {
  1335. $this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&uid='.api_get_user_id());
  1336. }
  1337. // Profile link
  1338. if (api_get_setting('allow_social_tool') == 'true') {
  1339. $profile_url = api_get_path(WEB_CODE_PATH).'social/home.php';
  1340. } else {
  1341. $profile_url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
  1342. }
  1343. $this->assign('profile_url', $profile_url);
  1344. //Message link
  1345. $message_link = null;
  1346. $message_url = null;
  1347. if (api_get_setting('allow_message_tool') == 'true') {
  1348. $message_url = api_get_path(WEB_CODE_PATH).'messages/inbox.php';
  1349. $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
  1350. }
  1351. $this->assign('message_link', $message_link);
  1352. $this->assign('message_url', $message_url);
  1353. $pendingSurveyLink = '';
  1354. $show = api_get_configuration_value('show_pending_survey_in_menu');
  1355. if ($show) {
  1356. $pendingSurveyLink = api_get_path(WEB_CODE_PATH).'survey/pending.php';
  1357. }
  1358. $this->assign('pending_survey_url', $pendingSurveyLink);
  1359. // Certificate Link
  1360. $allow = api_get_configuration_value('hide_my_certificate_link');
  1361. if ($allow === false) {
  1362. $certificateUrl = api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php';
  1363. $certificateLink = Display::url(
  1364. get_lang('MyCertificates'),
  1365. $certificateUrl
  1366. );
  1367. $this->assign('certificate_link', $certificateLink);
  1368. $this->assign('certificate_url', $certificateUrl);
  1369. }
  1370. $institution = api_get_setting('Institution');
  1371. $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
  1372. $this->assign('portal_name', $portal_name);
  1373. //Menu
  1374. $menu = menuArray();
  1375. $this->assign('menu', $menu);
  1376. $breadcrumb = '';
  1377. // Hide breadcrumb in LP
  1378. if ($this->show_learnpath == false) {
  1379. $breadcrumb = return_breadcrumb(
  1380. $interbreadcrumb,
  1381. $language_file,
  1382. $nameTools
  1383. );
  1384. }
  1385. $this->assign('breadcrumb', $breadcrumb);
  1386. //Extra content
  1387. $extra_header = null;
  1388. if (!api_is_platform_admin()) {
  1389. $extra_header = trim(api_get_setting('header_extra_content'));
  1390. }
  1391. $this->assign('header_extra_content', $extra_header);
  1392. if ($sendHeaders) {
  1393. header('Content-Type: text/html; charset='.api_get_system_encoding());
  1394. header(
  1395. 'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1)
  1396. );
  1397. self::addHTTPSecurityHeaders();
  1398. $responseCode = $this->getResponseCode();
  1399. if (!empty($responseCode)) {
  1400. switch ($responseCode) {
  1401. case '404':
  1402. header("HTTP/1.0 404 Not Found");
  1403. break;
  1404. }
  1405. }
  1406. }
  1407. $this->assignSocialMeta();
  1408. }
  1409. /**
  1410. * Set footer parameters.
  1411. */
  1412. private function set_footer_parameters()
  1413. {
  1414. if (api_get_setting('show_administrator_data') === 'true') {
  1415. $firstName = api_get_setting('administratorName');
  1416. $lastName = api_get_setting('administratorSurname');
  1417. if (!empty($firstName) && !empty($lastName)) {
  1418. $name = api_get_person_name($firstName, $lastName);
  1419. } else {
  1420. $name = $lastName;
  1421. if (empty($lastName)) {
  1422. $name = $firstName;
  1423. }
  1424. }
  1425. $adminName = '';
  1426. // Administrator name
  1427. if (!empty($name)) {
  1428. $adminName = get_lang('Manager').' : ';
  1429. $adminName .= Display::encrypted_mailto_link(
  1430. api_get_setting('emailAdministrator'),
  1431. $name,
  1432. '',
  1433. true
  1434. );
  1435. }
  1436. $this->assign('administrator_name', $adminName);
  1437. }
  1438. // Loading footer extra content
  1439. if (!api_is_platform_admin()) {
  1440. $extra_footer = trim(api_get_setting('footer_extra_content'));
  1441. if (!empty($extra_footer)) {
  1442. $this->assign('footer_extra_content', $extra_footer);
  1443. }
  1444. }
  1445. // Tutor name
  1446. if (api_get_setting('show_tutor_data') == 'true') {
  1447. // Course manager
  1448. $courseId = api_get_course_int_id();
  1449. $id_session = api_get_session_id();
  1450. if (!empty($courseId)) {
  1451. $tutor_data = '';
  1452. if ($id_session != 0) {
  1453. $coachs_email = CourseManager::get_email_of_tutor_to_session(
  1454. $id_session,
  1455. $courseId
  1456. );
  1457. $email_link = [];
  1458. foreach ($coachs_email as $coach) {
  1459. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  1460. }
  1461. if (count($coachs_email) > 1) {
  1462. $tutor_data .= get_lang('Coachs').' : ';
  1463. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  1464. } elseif (count($coachs_email) == 1) {
  1465. $tutor_data .= get_lang('Coach').' : ';
  1466. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  1467. } elseif (count($coachs_email) == 0) {
  1468. $tutor_data .= '';
  1469. }
  1470. }
  1471. $this->assign('session_teachers', $tutor_data);
  1472. }
  1473. }
  1474. if (api_get_setting('show_teacher_data') == 'true') {
  1475. // course manager
  1476. $courseId = api_get_course_int_id();
  1477. if (!empty($courseId)) {
  1478. $teacher_data = '';
  1479. $mail = CourseManager::get_emails_of_tutors_to_course($courseId);
  1480. if (!empty($mail)) {
  1481. $teachers_parsed = [];
  1482. foreach ($mail as $value) {
  1483. foreach ($value as $email => $name) {
  1484. $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
  1485. }
  1486. }
  1487. $label = get_lang('Teacher');
  1488. if (count($mail) > 1) {
  1489. $label = get_lang('Teachers');
  1490. }
  1491. $teacher_data .= $label.' : '.array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
  1492. }
  1493. $this->assign('teachers', $teacher_data);
  1494. }
  1495. }
  1496. }
  1497. /**
  1498. * Set administrator variables.
  1499. */
  1500. private function setAdministratorParams()
  1501. {
  1502. $_admin = [
  1503. 'email' => api_get_setting('emailAdministrator'),
  1504. 'surname' => api_get_setting('administratorSurname'),
  1505. 'name' => api_get_setting('administratorName'),
  1506. 'telephone' => api_get_setting('administratorTelephone'),
  1507. ];
  1508. $this->assign('_admin', $_admin);
  1509. }
  1510. /**
  1511. * Manage specific HTTP headers security.
  1512. */
  1513. private function addHTTPSecurityHeaders()
  1514. {
  1515. // Implementation of HTTP headers security, as suggested and checked
  1516. // by https://securityheaders.io/
  1517. // Enable these settings in configuration.php to use them on your site
  1518. // Strict-Transport-Security
  1519. $setting = api_get_configuration_value('security_strict_transport');
  1520. if (!empty($setting)) {
  1521. header('Strict-Transport-Security: '.$setting);
  1522. }
  1523. // Content-Security-Policy
  1524. $setting = api_get_configuration_value('security_content_policy');
  1525. if (!empty($setting)) {
  1526. header('Content-Security-Policy: '.$setting);
  1527. }
  1528. $setting = api_get_configuration_value('security_content_policy_report_only');
  1529. if (!empty($setting)) {
  1530. header('Content-Security-Policy-Report-Only: '.$setting);
  1531. }
  1532. // Public-Key-Pins
  1533. $setting = api_get_configuration_value('security_public_key_pins');
  1534. if (!empty($setting)) {
  1535. header('Public-Key-Pins: '.$setting);
  1536. }
  1537. $setting = api_get_configuration_value('security_public_key_pins_report_only');
  1538. if (!empty($setting)) {
  1539. header('Public-Key-Pins-Report-Only: '.$setting);
  1540. }
  1541. // X-Frame-Options
  1542. $setting = api_get_configuration_value('security_x_frame_options');
  1543. if (!empty($setting)) {
  1544. header('X-Frame-Options: '.$setting);
  1545. }
  1546. // X-XSS-Protection
  1547. $setting = api_get_configuration_value('security_xss_protection');
  1548. if (!empty($setting)) {
  1549. header('X-XSS-Protection: '.$setting);
  1550. }
  1551. // X-Content-Type-Options
  1552. $setting = api_get_configuration_value('security_x_content_type_options');
  1553. if (!empty($setting)) {
  1554. header('X-Content-Type-Options: '.$setting);
  1555. }
  1556. // Referrer-Policy
  1557. $setting = api_get_configuration_value('security_referrer_policy');
  1558. if (!empty($setting)) {
  1559. header('Referrer-Policy: '.$setting);
  1560. }
  1561. // end of HTTP headers security block
  1562. }
  1563. /**
  1564. * Assign favicon to the 'favico' template variable.
  1565. *
  1566. * @return bool Always return true because there is always at least one correct favicon.ico
  1567. */
  1568. private function assignFavIcon()
  1569. {
  1570. // Default root chamilo favicon
  1571. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  1572. //Added to verify if in the current Chamilo Theme exist a favicon
  1573. $favicoThemeUrl = api_get_path(SYS_CSS_PATH).$this->themeDir.'images/';
  1574. //If exist pick the current chamilo theme favicon
  1575. if (is_file($favicoThemeUrl.'favicon.ico')) {
  1576. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_CSS_PATH).$this->themeDir.'images/favicon.ico" type="image/x-icon" />';
  1577. }
  1578. if (api_is_multiple_url_enabled()) {
  1579. $access_url_id = api_get_current_access_url_id();
  1580. if ($access_url_id != -1) {
  1581. $url_info = api_get_access_url($access_url_id);
  1582. $url = api_remove_trailing_slash(
  1583. preg_replace('/https?:\/\//i', '', $url_info['url'])
  1584. );
  1585. $clean_url = api_replace_dangerous_char($url);
  1586. $clean_url = str_replace('/', '-', $clean_url);
  1587. $clean_url .= '/';
  1588. $homep = api_get_path(WEB_HOME_PATH).$clean_url; //homep for Home Path
  1589. $icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
  1590. //we create the new dir for the new sites
  1591. if (is_file($icon_real_homep.'favicon.ico')) {
  1592. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  1593. }
  1594. }
  1595. }
  1596. $this->assign('favico', $favico);
  1597. return true;
  1598. }
  1599. /**
  1600. * Assign HTML code to the 'accessibility' template variable (usually shown above top menu).
  1601. *
  1602. * @return bool Always return true (even if empty string)
  1603. */
  1604. private function assignAccessibilityBlock()
  1605. {
  1606. $resize = '';
  1607. if (api_get_setting('accessibility_font_resize') == 'true') {
  1608. $resize .= '<div class="resize_font">';
  1609. $resize .= '<div class="btn-group">';
  1610. $resize .= '<a title="'.get_lang('DecreaseFontSize').'" href="#" class="decrease_font btn btn-default"><em class="fa fa-font"></em></a>';
  1611. $resize .= '<a title="'.get_lang('ResetFontSize').'" href="#" class="reset_font btn btn-default"><em class="fa fa-font"></em></a>';
  1612. $resize .= '<a title="'.get_lang('IncreaseFontSize').'" href="#" class="increase_font btn btn-default"><em class="fa fa-font"></em></a>';
  1613. $resize .= '</div>';
  1614. $resize .= '</div>';
  1615. }
  1616. $this->assign('accessibility', $resize);
  1617. return true;
  1618. }
  1619. /**
  1620. * Assign HTML code to the 'social_meta' template variable (usually shown above top menu).
  1621. *
  1622. * @return bool Always return true (even if empty string)
  1623. */
  1624. private function assignSocialMeta()
  1625. {
  1626. $socialMeta = '';
  1627. $metaTitle = api_get_setting('meta_title');
  1628. if (!empty($metaTitle)) {
  1629. $socialMeta .= '<meta name="twitter:card" content="summary" />'."\n";
  1630. $metaSite = api_get_setting('meta_twitter_site');
  1631. if (!empty($metaSite)) {
  1632. $socialMeta .= '<meta name="twitter:site" content="'.$metaSite.'" />'."\n";
  1633. $metaCreator = api_get_setting('meta_twitter_creator');
  1634. if (!empty($metaCreator)) {
  1635. $socialMeta .= '<meta name="twitter:creator" content="'.$metaCreator.'" />'."\n";
  1636. }
  1637. }
  1638. // The user badge page emits its own meta tags, so if this is
  1639. // enabled, ignore the global ones
  1640. $userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
  1641. $skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
  1642. if (!$userId && !$skillId) {
  1643. // no combination of user and skill ID has been defined,
  1644. // so print the normal or course-specific OpenGraph meta tags
  1645. // Check for a course ID
  1646. $courseId = api_get_course_int_id();
  1647. // Check session ID from session/id/about (see .htaccess)
  1648. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  1649. if ($courseId != false) {
  1650. // If we are inside a course (even if within a session), publish info about the course
  1651. $course = api_get_course_entity($courseId);
  1652. // @TODO: support right-to-left in title
  1653. $socialMeta .= '<meta property="og:title" content="'.$course->getTitle().' - '.$metaTitle.'" />'."\n";
  1654. $socialMeta .= '<meta property="twitter:title" content="'.$course->getTitle().' - '.$metaTitle.'" />'."\n";
  1655. $socialMeta .= '<meta property="og:url" content="'.api_get_course_url($course->getCode()).'" />'."\n";
  1656. $metaDescription = api_get_setting('meta_description');
  1657. if (!empty($course->getDescription())) {
  1658. $socialMeta .= '<meta property="og:description" content="'.strip_tags($course->getDescription()).'" />'."\n";
  1659. $socialMeta .= '<meta property="twitter:description" content="'.strip_tags($course->getDescription()).'" />'."\n";
  1660. } elseif (!empty($metaDescription)) {
  1661. $socialMeta .= '<meta property="og:description" content="'.$metaDescription.'" />'."\n";
  1662. $socialMeta .= '<meta property="twitter:description" content="'.$metaDescription.'" />'."\n";
  1663. }
  1664. $picture = CourseManager::getPicturePath($course, true);
  1665. if (!empty($picture)) {
  1666. $socialMeta .= '<meta property="og:image" content="'.$picture.'" />'."\n";
  1667. $socialMeta .= '<meta property="twitter:image" content="'.$picture.'" />'."\n";
  1668. $socialMeta .= '<meta property="twitter:image:alt" content="'.$course->getTitle().' - '.$metaTitle.'" />'."\n";
  1669. } else {
  1670. $socialMeta .= $this->getMetaPortalImagePath($metaTitle);
  1671. }
  1672. } elseif ($sessionId !== 0) {
  1673. // If we are on a session "about" screen, publish info about the session
  1674. $em = Database::getManager();
  1675. $session = $em->find('ChamiloCoreBundle:Session', $sessionId);
  1676. $socialMeta .= '<meta property="og:title" content="'.$session->getName().' - '.$metaTitle.'" />'."\n";
  1677. $socialMeta .= '<meta property="twitter:title" content="'.$session->getName().' - '.$metaTitle.'" />'."\n";
  1678. $socialMeta .= '<meta property="og:url" content="'.api_get_path(WEB_PATH)."session/{$session->getId()}/about/".'" />'."\n";
  1679. $sessionValues = new ExtraFieldValue('session');
  1680. $sessionImage = $sessionValues->get_values_by_handler_and_field_variable($session->getId(), 'image')['value'];
  1681. $sessionImageSysPath = api_get_path(SYS_UPLOAD_PATH).$sessionImage;
  1682. if (!empty($sessionImage) && is_file($sessionImageSysPath)) {
  1683. $sessionImagePath = api_get_path(WEB_UPLOAD_PATH).$sessionImage;
  1684. $socialMeta .= '<meta property="og:image" content="'.$sessionImagePath.'" />'."\n";
  1685. $socialMeta .= '<meta property="twitter:image" content="'.$sessionImagePath.'" />'."\n";
  1686. $socialMeta .= '<meta property="twitter:image:alt" content="'.$session->getName().' - '.$metaTitle.'" />'."\n";
  1687. } else {
  1688. $socialMeta .= $this->getMetaPortalImagePath($metaTitle);
  1689. }
  1690. } else {
  1691. // Otherwise (not a course nor a session, nor a user, nor a badge), publish portal info
  1692. $socialMeta .= '<meta property="og:title" content="'.$metaTitle.'" />'."\n";
  1693. $socialMeta .= '<meta property="twitter:title" content="'.$metaTitle.'" />'."\n";
  1694. $socialMeta .= '<meta property="og:url" content="'.api_get_path(WEB_PATH).'" />'."\n";
  1695. $metaDescription = api_get_setting('meta_description');
  1696. if (!empty($metaDescription)) {
  1697. $socialMeta .= '<meta property="og:description" content="'.$metaDescription.'" />'."\n";
  1698. $socialMeta .= '<meta property="twitter:description" content="'.$metaDescription.'" />'."\n";
  1699. }
  1700. $socialMeta .= $this->getMetaPortalImagePath($metaTitle);
  1701. }
  1702. }
  1703. }
  1704. $this->assign('social_meta', $socialMeta);
  1705. return true;
  1706. }
  1707. /**
  1708. * Get platform meta image tag (check meta_image_path setting, then use the logo).
  1709. *
  1710. * @param string $imageAlt The alt attribute for the image
  1711. *
  1712. * @return string The meta image HTML tag, or empty
  1713. */
  1714. private function getMetaPortalImagePath($imageAlt = '')
  1715. {
  1716. // Load portal meta image if defined
  1717. $metaImage = api_get_setting('meta_image_path');
  1718. $metaImageSysPath = api_get_path(SYS_PATH).$metaImage;
  1719. $metaImageWebPath = api_get_path(WEB_PATH).$metaImage;
  1720. $portalImageMeta = '';
  1721. if (!empty($metaImage)) {
  1722. if (is_file($metaImageSysPath)) {
  1723. $portalImageMeta = '<meta property="og:image" content="'.$metaImageWebPath.'" />'."\n";
  1724. $portalImageMeta .= '<meta property="twitter:image" content="'.$metaImageWebPath.'" />'."\n";
  1725. $portalImageMeta .= '<meta property="twitter:image:alt" content="'.$imageAlt.'" />'."\n";
  1726. }
  1727. } else {
  1728. $logo = ChamiloApi::getPlatformLogoPath($this->theme);
  1729. if (!empty($logo)) {
  1730. $portalImageMeta = '<meta property="og:image" content="'.$logo.'" />'."\n";
  1731. $portalImageMeta .= '<meta property="twitter:image" content="'.$logo.'" />'."\n";
  1732. $portalImageMeta .= '<meta property="twitter:image:alt" content="'.$imageAlt.'" />'."\n";
  1733. }
  1734. }
  1735. return $portalImageMeta;
  1736. }
  1737. }