template.lib.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946
  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. $viewBySession = api_get_setting('my_courses_view_by_session') === 'true';
  635. if (api_is_global_chat_enabled() || $viewBySession) {
  636. // Do not include the global chat in LP
  637. if ($this->show_learnpath == false &&
  638. $this->show_footer == true &&
  639. $this->hide_global_chat == false
  640. ) {
  641. $js_files[] = 'chat/js/chat.js';
  642. }
  643. }
  644. if (api_get_setting('accessibility_font_resize') === 'true') {
  645. $js_files[] = 'fontresize.js';
  646. }
  647. $js_file_to_string = '';
  648. $bowerJsFiles = [
  649. 'modernizr/modernizr.js',
  650. 'jquery/dist/jquery.min.js',
  651. 'bootstrap/dist/js/bootstrap.min.js',
  652. 'jquery-ui/jquery-ui.min.js',
  653. 'jqueryui-touch-punch/jquery.ui.touch-punch.min.js',
  654. 'moment/min/moment-with-locales.js',
  655. 'bootstrap-daterangepicker/daterangepicker.js',
  656. 'jquery-timeago/jquery.timeago.js',
  657. 'mediaelement/build/mediaelement-and-player.min.js',
  658. 'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
  659. 'image-map-resizer/js/imageMapResizer.min.js',
  660. 'jquery.scrollbar/jquery.scrollbar.min.js',
  661. 'readmore-js/readmore.min.js',
  662. 'bootstrap-select/dist/js/bootstrap-select.min.js',
  663. $selectLink,
  664. 'select2/dist/js/select2.min.js',
  665. "select2/dist/js/i18n/$isoCode.js",
  666. 'mediaelement/plugins/vrview/vrview.js',
  667. 'js-cookie/src/js.cookie.js',
  668. 'mediaelement/plugins/markersrolls/markersrolls.min.js',
  669. ];
  670. $features = api_get_configuration_value('video_features');
  671. if (!empty($features) && isset($features['features'])) {
  672. foreach ($features['features'] as $feature) {
  673. if ($feature === 'vrview') {
  674. continue;
  675. }
  676. $bowerJsFiles[] = "mediaelement/plugins/$feature/$feature.js";
  677. }
  678. }
  679. if (CHAMILO_LOAD_WYSIWYG === true) {
  680. $bowerJsFiles[] = 'ckeditor/ckeditor.js';
  681. }
  682. if (api_get_setting('include_asciimathml_script') === 'true') {
  683. $bowerJsFiles[] = 'MathJax/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  684. }
  685. // If not English and the language is supported by timepicker, localize
  686. $assetsPath = api_get_path(SYS_PUBLIC_PATH).'assets/';
  687. if ($isoCode != 'en') {
  688. 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')) {
  689. $bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-'.$isoCode.'.js';
  690. $bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-'.$isoCode.'.min.js';
  691. }
  692. }
  693. foreach ($bowerJsFiles as $file) {
  694. $js_file_to_string .= '<script type="text/javascript" src="'.api_get_cdn_path(api_get_path(WEB_PUBLIC_PATH).'assets/'.$file).'"></script>'."\n";
  695. }
  696. foreach ($js_files as $file) {
  697. $js_file_to_string .= api_get_js($file);
  698. }
  699. // Loading email_editor js
  700. if (!api_is_anonymous() && api_get_setting('allow_email_editor') === 'true') {
  701. $template = $this->get_template('mail_editor/email_link.js.tpl');
  702. $js_file_to_string .= $this->fetch($template);
  703. }
  704. if (!$disable_js_and_css_files) {
  705. $this->assign('js_file_to_string', $js_file_to_string);
  706. $extraHeaders = '<script>var _p = '.json_encode($this->getWebPaths(), JSON_PRETTY_PRINT).'</script>';
  707. // Adding jquery ui by default
  708. $extraHeaders .= api_get_jquery_ui_js();
  709. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  710. foreach ($htmlHeadXtra as &$this_html_head) {
  711. $extraHeaders .= $this_html_head."\n";
  712. }
  713. }
  714. $ajax = api_get_path(WEB_AJAX_PATH);
  715. $courseId = api_get_course_id();
  716. if (empty($courseId)) {
  717. $courseLogoutCode = '
  718. <script>
  719. function courseLogout() {
  720. }
  721. </script>';
  722. } else {
  723. $courseLogoutCode = "
  724. <script>
  725. var logOutUrl = '".$ajax."course.ajax.php?a=course_logout&".api_get_cidreq()."';
  726. function courseLogout() {
  727. $.ajax({
  728. async : false,
  729. url: logOutUrl,
  730. success: function (data) {
  731. return 1;
  732. }
  733. });
  734. }
  735. </script>";
  736. }
  737. $extraHeaders .= $courseLogoutCode;
  738. $this->assign('extra_headers', $extraHeaders);
  739. }
  740. }
  741. /**
  742. * Special function to declare last-minute JS libraries which depend on
  743. * other things to be declared first. In particular, it might be useful
  744. * under IE9 with compatibility mode, which for some reason is getting
  745. * upset when a variable is used in a function (even if not used yet)
  746. * when this variable hasn't been defined yet.
  747. */
  748. public function set_js_files_post()
  749. {
  750. global $disable_js_and_css_files;
  751. $js_files = [];
  752. if (api_is_global_chat_enabled()) {
  753. //Do not include the global chat in LP
  754. if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
  755. $js_files[] = 'chat/js/chat.js';
  756. }
  757. }
  758. $js_file_to_string = '';
  759. foreach ($js_files as $js_file) {
  760. $js_file_to_string .= api_get_js($js_file);
  761. }
  762. if (!$disable_js_and_css_files) {
  763. $this->assign('js_file_to_string_post', $js_file_to_string);
  764. }
  765. }
  766. /**
  767. * Show header template.
  768. */
  769. public function show_header_template()
  770. {
  771. $tpl = $this->get_template('layout/show_header.tpl');
  772. $this->display($tpl);
  773. }
  774. /**
  775. * Show footer template.
  776. */
  777. public function show_footer_template()
  778. {
  779. $tpl = $this->get_template('layout/show_footer.tpl');
  780. $this->display($tpl);
  781. }
  782. /**
  783. * Sets the plugin content in a template variable.
  784. *
  785. * @param string $pluginRegion
  786. */
  787. public function set_plugin_region($pluginRegion)
  788. {
  789. if (!empty($pluginRegion)) {
  790. $regionContent = $this->plugin->load_region(
  791. $pluginRegion,
  792. $this,
  793. $this->force_plugin_load
  794. );
  795. $pluginList = $this->plugin->get_installed_plugins();
  796. foreach ($pluginList as $plugin_name) {
  797. // The plugin_info variable is available inside the plugin index
  798. $pluginInfo = $this->plugin->getPluginInfo($plugin_name);
  799. if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) {
  800. $courseInfo = api_get_course_info();
  801. if (!empty($courseInfo)) {
  802. if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof Plugin) {
  803. /** @var Plugin $plugin */
  804. $plugin = $pluginInfo['obj'];
  805. $regionContent .= $plugin->renderRegion($pluginRegion);
  806. }
  807. }
  808. } else {
  809. continue;
  810. }
  811. }
  812. if (!empty($regionContent)) {
  813. $this->assign('plugin_'.$pluginRegion, $regionContent);
  814. } else {
  815. $this->assign('plugin_'.$pluginRegion, null);
  816. }
  817. }
  818. return null;
  819. }
  820. /**
  821. * @param string $template
  822. *
  823. * @return string
  824. */
  825. public function fetch($template = null)
  826. {
  827. $template = $this->twig->loadTemplate($template);
  828. return $template->render($this->params);
  829. }
  830. /**
  831. * @param string $variable
  832. * @param mixed $value
  833. */
  834. public function assign($variable, $value = '')
  835. {
  836. $this->params[$variable] = $value;
  837. }
  838. /**
  839. * Render the template.
  840. *
  841. * @param string $template The template path
  842. * @param bool $clearFlashMessages Clear the $_SESSION variables for flash messages
  843. */
  844. public function display($template, $clearFlashMessages = true)
  845. {
  846. $this->assign('flash_messages', Display::getFlashToString());
  847. if ($clearFlashMessages) {
  848. Display::cleanFlashMessages();
  849. }
  850. echo $this->twig->render($template, $this->params);
  851. }
  852. /**
  853. * Adds a body class for login pages.
  854. */
  855. public function setLoginBodyClass()
  856. {
  857. $this->assign('login_class', 'section-login');
  858. }
  859. /**
  860. * The theme that will be used if the database is not working.
  861. *
  862. * @return string
  863. */
  864. public static function getThemeFallback()
  865. {
  866. $theme = api_get_configuration_value('theme_fallback');
  867. if (empty($theme)) {
  868. $theme = 'chamilo';
  869. }
  870. return $theme;
  871. }
  872. /**
  873. * @param bool|true $setLoginForm
  874. */
  875. public function setLoginForm($setLoginForm = true)
  876. {
  877. global $loginFailed;
  878. $userId = api_get_user_id();
  879. if (!($userId) || api_is_anonymous($userId)) {
  880. // Only display if the user isn't logged in.
  881. $this->assign(
  882. 'login_language_form',
  883. api_display_language_form(true, true)
  884. );
  885. if ($setLoginForm) {
  886. $this->assign('login_form', $this->displayLoginForm());
  887. if ($loginFailed) {
  888. $this->assign('login_failed', $this::handleLoginFailed());
  889. }
  890. }
  891. }
  892. }
  893. /**
  894. * @return string
  895. */
  896. public function handleLoginFailed()
  897. {
  898. $message = get_lang('InvalidId');
  899. if (!isset($_GET['error'])) {
  900. if (api_is_self_registration_allowed()) {
  901. $message = get_lang('InvalidForSelfRegistration');
  902. }
  903. } else {
  904. switch ($_GET['error']) {
  905. case '':
  906. if (api_is_self_registration_allowed()) {
  907. $message = get_lang('InvalidForSelfRegistration');
  908. }
  909. break;
  910. case 'account_expired':
  911. $message = get_lang('AccountExpired');
  912. break;
  913. case 'account_inactive':
  914. $message = get_lang('AccountInactive');
  915. if (api_get_setting('allow_registration') === 'confirmation') {
  916. $message = get_lang('AccountNotConfirmed').PHP_EOL;
  917. $message .= Display::url(
  918. get_lang('ReSendConfirmationMail'),
  919. api_get_path(WEB_PATH).'main/auth/resend_confirmation_mail.php',
  920. ['class' => 'alert-link']
  921. );
  922. }
  923. break;
  924. case 'user_password_incorrect':
  925. $message = get_lang('InvalidId');
  926. break;
  927. case 'access_url_inactive':
  928. $message = get_lang('AccountURLInactive');
  929. break;
  930. case 'wrong_captcha':
  931. $message = get_lang('TheTextYouEnteredDoesNotMatchThePicture');
  932. break;
  933. case 'blocked_by_captcha':
  934. $message = get_lang('AccountBlockedByCaptcha');
  935. break;
  936. case 'multiple_connection_not_allowed':
  937. $message = get_lang('MultipleConnectionsAreNotAllow');
  938. break;
  939. case 'unrecognize_sso_origin':
  940. //$message = get_lang('SSOError');
  941. break;
  942. }
  943. }
  944. return Display::return_message($message, 'error', false);
  945. }
  946. /**
  947. * @return string
  948. */
  949. public function displayLoginForm()
  950. {
  951. $form = new FormValidator(
  952. 'form-login',
  953. 'POST',
  954. null,
  955. null,
  956. null,
  957. FormValidator::LAYOUT_BOX_NO_LABEL
  958. );
  959. $params = [
  960. 'id' => 'login',
  961. 'autofocus' => 'autofocus',
  962. 'icon' => 'user fa-fw',
  963. 'placeholder' => get_lang('UserName'),
  964. ];
  965. $browserAutoCapitalize = false;
  966. // Avoid showing the autocapitalize option if the browser doesn't
  967. // support it: this attribute is against the HTML5 standard
  968. if (api_browser_support('autocapitalize')) {
  969. $browserAutoCapitalize = false;
  970. $params['autocapitalize'] = 'none';
  971. }
  972. $form->addText(
  973. 'login',
  974. get_lang('UserName'),
  975. true,
  976. $params
  977. );
  978. $params = [
  979. 'id' => 'password',
  980. 'icon' => 'lock fa-fw',
  981. 'placeholder' => get_lang('Pass'),
  982. ];
  983. if ($browserAutoCapitalize) {
  984. $params['autocapitalize'] = 'none';
  985. }
  986. $form->addElement(
  987. 'password',
  988. 'password',
  989. get_lang('Pass'),
  990. $params
  991. );
  992. // Captcha
  993. $captcha = api_get_setting('allow_captcha');
  994. $allowCaptcha = $captcha === 'true';
  995. if ($allowCaptcha) {
  996. $useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null;
  997. if ($useCaptcha) {
  998. $ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
  999. $options = [
  1000. 'width' => 250,
  1001. 'height' => 90,
  1002. 'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
  1003. 'sessionVar' => basename(__FILE__, '.php'),
  1004. 'imageOptions' => [
  1005. 'font_size' => 20,
  1006. 'font_path' => api_get_path(SYS_FONTS_PATH).'opensans/',
  1007. 'font_file' => 'OpenSans-Regular.ttf',
  1008. //'output' => 'gif'
  1009. ],
  1010. ];
  1011. // Minimum options using all defaults (including defaults for Image_Text):
  1012. //$options = array('callback' => 'qfcaptcha_image.php');
  1013. $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
  1014. $form->addHtml(get_lang('ClickOnTheImageForANewOne'));
  1015. $form->addElement(
  1016. 'text',
  1017. 'captcha',
  1018. get_lang('EnterTheLettersYouSee')
  1019. );
  1020. $form->addRule(
  1021. 'captcha',
  1022. get_lang('EnterTheCharactersYouReadInTheImage'),
  1023. 'required',
  1024. null,
  1025. 'client'
  1026. );
  1027. $form->addRule(
  1028. 'captcha',
  1029. get_lang('TheTextYouEnteredDoesNotMatchThePicture'),
  1030. 'CAPTCHA',
  1031. $captcha_question
  1032. );
  1033. }
  1034. }
  1035. $form->addButton(
  1036. 'submitAuth',
  1037. get_lang('LoginEnter'),
  1038. null,
  1039. 'primary',
  1040. null,
  1041. 'btn-block'
  1042. );
  1043. $html = $form->returnForm();
  1044. if (api_get_setting('openid_authentication') == 'true') {
  1045. include_once api_get_path(SYS_CODE_PATH).'auth/openid/login.php';
  1046. $html .= '<div>'.openid_form().'</div>';
  1047. }
  1048. $pluginKeycloak = api_get_plugin_setting('keycloak', 'tool_enable') === 'true';
  1049. $plugin = null;
  1050. if ($pluginKeycloak) {
  1051. $pluginUrl = api_get_path(WEB_PLUGIN_PATH).'keycloak/start.php?sso';
  1052. $pluginUrl = Display::url('Keycloak', $pluginUrl, ['class' => 'btn btn-primary']);
  1053. $html .= '<div>'.$pluginUrl.'</div>';
  1054. }
  1055. $html .= '<div></div>';
  1056. return $html;
  1057. }
  1058. /**
  1059. * Returns the tutors names for the current course in session
  1060. * Function to use in Twig templates.
  1061. *
  1062. * @return string
  1063. */
  1064. public static function returnTutorsNames()
  1065. {
  1066. $em = Database::getManager();
  1067. $tutors = $em
  1068. ->createQuery('
  1069. SELECT u FROM ChamiloUserBundle:User u
  1070. INNER JOIN ChamiloCoreBundle:SessionRelCourseRelUser scu WITH u.id = scu.user
  1071. WHERE scu.status = :teacher_status AND scu.session = :session AND scu.course = :course
  1072. ')
  1073. ->setParameters([
  1074. 'teacher_status' => SessionRelCourseRelUser::STATUS_COURSE_COACH,
  1075. 'session' => api_get_session_id(),
  1076. 'course' => api_get_course_int_id(),
  1077. ])
  1078. ->getResult();
  1079. $names = [];
  1080. /** @var User $tutor */
  1081. foreach ($tutors as $tutor) {
  1082. $names[] = $tutor->getCompleteName();
  1083. }
  1084. return implode(CourseManager::USER_SEPARATOR, $names);
  1085. }
  1086. /*s
  1087. * Returns the teachers name for the current course
  1088. * Function to use in Twig templates
  1089. * @return string
  1090. */
  1091. public static function returnTeachersNames()
  1092. {
  1093. $em = Database::getManager();
  1094. $teachers = $em
  1095. ->createQuery('
  1096. SELECT u FROM ChamiloUserBundle:User u
  1097. INNER JOIN ChamiloCoreBundle:CourseRelUser cu WITH u.id = cu.user
  1098. WHERE cu.status = :teacher_status AND cu.course = :course
  1099. ')
  1100. ->setParameters([
  1101. 'teacher_status' => User::COURSE_MANAGER,
  1102. 'course' => api_get_course_int_id(),
  1103. ])
  1104. ->getResult();
  1105. $names = [];
  1106. /** @var User $teacher */
  1107. foreach ($teachers as $teacher) {
  1108. $names[] = $teacher->getCompleteName();
  1109. }
  1110. return implode(CourseManager::USER_SEPARATOR, $names);
  1111. }
  1112. /**
  1113. * @param int $code
  1114. */
  1115. public function setResponseCode($code)
  1116. {
  1117. $this->responseCode = $code;
  1118. }
  1119. /**
  1120. * @param string $code
  1121. */
  1122. public function getResponseCode()
  1123. {
  1124. return $this->responseCode;
  1125. }
  1126. /**
  1127. * Assign HTML code to the 'bug_notification' template variable for the side tabs to report issues.
  1128. *
  1129. * @return bool Always return true because there is always a string, even if empty
  1130. */
  1131. public function assignBugNotification()
  1132. {
  1133. //@todo move this in the template
  1134. $rightFloatMenu = '';
  1135. $iconBug = Display::return_icon(
  1136. 'bug.png',
  1137. get_lang('ReportABug'),
  1138. [],
  1139. ICON_SIZE_LARGE
  1140. );
  1141. if (api_get_setting('show_link_bug_notification') === 'true' && $this->user_is_logged_in) {
  1142. $rightFloatMenu = '<div class="report">
  1143. <a href="https://github.com/chamilo/chamilo-lms/wiki/How-to-report-issues" target="_blank">
  1144. '.$iconBug.'
  1145. </a>
  1146. </div>';
  1147. }
  1148. if (api_get_setting('show_link_ticket_notification') === 'true' &&
  1149. $this->user_is_logged_in
  1150. ) {
  1151. // by default is project_id = 1
  1152. $defaultProjectId = 1;
  1153. $iconTicket = Display::return_icon(
  1154. 'help.png',
  1155. get_lang('Ticket'),
  1156. [],
  1157. ICON_SIZE_LARGE
  1158. );
  1159. $courseInfo = api_get_course_info();
  1160. $courseParams = '';
  1161. if (!empty($courseInfo)) {
  1162. $courseParams = api_get_cidreq();
  1163. }
  1164. $url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams;
  1165. $allow = TicketManager::userIsAllowInProject(api_get_user_info(), $defaultProjectId);
  1166. if ($allow) {
  1167. $rightFloatMenu .= '<div class="help">
  1168. <a href="'.$url.'" target="_blank">
  1169. '.$iconTicket.'
  1170. </a>
  1171. </div>';
  1172. }
  1173. }
  1174. $this->assign('bug_notification', $rightFloatMenu);
  1175. return true;
  1176. }
  1177. /**
  1178. * Prepare the _c array for template files. The _c array contains
  1179. * information about the current course.
  1180. */
  1181. private function set_course_parameters()
  1182. {
  1183. //Setting course id
  1184. $course = api_get_course_info();
  1185. if (empty($course)) {
  1186. $this->assign('course_is_set', false);
  1187. return;
  1188. }
  1189. $this->assign('course_is_set', true);
  1190. $this->course_id = $course['id'];
  1191. $_c = [
  1192. 'id' => $course['real_id'],
  1193. 'code' => $course['code'],
  1194. 'title' => $course['name'],
  1195. 'visibility' => $course['visibility'],
  1196. 'language' => $course['language'],
  1197. 'directory' => $course['directory'],
  1198. 'session_id' => api_get_session_id(),
  1199. 'user_is_teacher' => api_is_course_admin(),
  1200. 'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'),
  1201. ];
  1202. $this->assign('course_code', $course['code']);
  1203. $this->assign('_c', $_c);
  1204. }
  1205. /**
  1206. * Prepare the _u array for template files. The _u array contains
  1207. * information about the current user, as returned by
  1208. * api_get_user_info().
  1209. */
  1210. private function set_user_parameters()
  1211. {
  1212. $user_info = [];
  1213. $user_info['logged'] = 0;
  1214. $this->user_is_logged_in = false;
  1215. if (api_user_is_login()) {
  1216. $user_info = api_get_user_info(api_get_user_id(), true);
  1217. $user_info['logged'] = 1;
  1218. $user_info['is_admin'] = 0;
  1219. if (api_is_platform_admin()) {
  1220. $user_info['is_admin'] = 1;
  1221. }
  1222. $user_info['messages_count'] = MessageManager::getCountNewMessages();
  1223. $this->user_is_logged_in = true;
  1224. }
  1225. // Setting the $_u array that could be use in any template
  1226. $this->assign('_u', $user_info);
  1227. }
  1228. /**
  1229. * Get an array of all the web paths available (e.g. 'web' => 'https://my.chamilo.site/').
  1230. *
  1231. * @return array
  1232. */
  1233. private function getWebPaths()
  1234. {
  1235. $queryString = empty($_SERVER['QUERY_STRING']) ? '' : $_SERVER['QUERY_STRING'];
  1236. $requestURI = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
  1237. return [
  1238. 'web' => api_get_path(WEB_PATH),
  1239. 'web_url' => api_get_web_url(),
  1240. 'web_relative' => api_get_path(REL_PATH),
  1241. 'web_course' => api_get_path(WEB_COURSE_PATH),
  1242. 'web_main' => api_get_path(WEB_CODE_PATH),
  1243. 'web_css' => api_get_path(WEB_CSS_PATH),
  1244. 'web_css_theme' => api_get_path(WEB_CSS_PATH).$this->themeDir,
  1245. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  1246. 'web_img' => api_get_path(WEB_IMG_PATH),
  1247. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  1248. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  1249. 'web_upload' => api_get_path(WEB_UPLOAD_PATH),
  1250. 'web_self' => api_get_self(),
  1251. 'self_basename' => basename(api_get_self()),
  1252. 'web_query_vars' => api_htmlentities($queryString),
  1253. 'web_self_query_vars' => api_htmlentities($requestURI),
  1254. 'web_cid_query' => api_get_cidreq(),
  1255. 'web_rel_code' => api_get_path(REL_CODE_PATH),
  1256. ];
  1257. }
  1258. /**
  1259. * Set header parameters.
  1260. *
  1261. * @param bool $sendHeaders send headers
  1262. */
  1263. private function set_header_parameters($sendHeaders)
  1264. {
  1265. global $httpHeadXtra, $interbreadcrumb, $language_file, $_configuration, $this_section;
  1266. $_course = api_get_course_info();
  1267. $nameTools = $this->title;
  1268. $navigation = return_navigation_array();
  1269. $this->menu_navigation = $navigation['menu_navigation'];
  1270. $this->assign('system_charset', api_get_system_encoding());
  1271. if (isset($httpHeadXtra) && $httpHeadXtra) {
  1272. foreach ($httpHeadXtra as &$thisHttpHead) {
  1273. header($thisHttpHead);
  1274. }
  1275. }
  1276. // Get language iso-code for this page - ignore errors
  1277. $this->assign('document_language', api_get_language_isocode());
  1278. $course_title = isset($_course['name']) ? $_course['name'] : null;
  1279. $title_list = [];
  1280. $title_list[] = api_get_setting('Institution');
  1281. $title_list[] = api_get_setting('siteName');
  1282. if (!empty($course_title)) {
  1283. $title_list[] = $course_title;
  1284. }
  1285. if ($nameTools != '') {
  1286. $title_list[] = $nameTools;
  1287. }
  1288. $title_string = '';
  1289. for ($i = 0; $i < count($title_list); $i++) {
  1290. $title_string .= $title_list[$i];
  1291. if (isset($title_list[$i + 1])) {
  1292. $item = trim($title_list[$i + 1]);
  1293. if (!empty($item)) {
  1294. $title_string .= ' - ';
  1295. }
  1296. }
  1297. }
  1298. $this->assign('title_string', $title_string);
  1299. // Setting the theme and CSS files
  1300. $this->setCssFiles();
  1301. $this->set_js_files();
  1302. $this->setCssCustomFiles();
  1303. $browser = api_browser_support('check_browser');
  1304. if ($browser[0] == 'Internet Explorer' && $browser[1] >= '11') {
  1305. $browser_head = '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />';
  1306. $this->assign('browser_specific_head', $browser_head);
  1307. }
  1308. // Implementation of prefetch.
  1309. // See http://cdn.chamilo.org/main/img/online.png for details
  1310. $prefetch = '';
  1311. if (!empty($_configuration['cdn_enable'])) {
  1312. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  1313. foreach ($_configuration['cdn'] as $host => $exts) {
  1314. $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
  1315. }
  1316. }
  1317. $this->assign('prefetch', $prefetch);
  1318. $this->assign('text_direction', api_get_text_direction());
  1319. $this->assign('section_name', 'section-'.$this_section);
  1320. $this->assignFavIcon();
  1321. $this->setHelp();
  1322. $this->assignBugNotification(); //Prepare the 'bug_notification' var for the template
  1323. $this->assignAccessibilityBlock(); //Prepare the 'accessibility' var for the template
  1324. // Preparing values for the menu
  1325. // Logout link
  1326. $hideLogout = api_get_setting('hide_logout_button');
  1327. if ($hideLogout === 'true') {
  1328. $this->assign('logout_link', null);
  1329. } else {
  1330. $this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&uid='.api_get_user_id());
  1331. }
  1332. // Profile link
  1333. if (api_get_setting('allow_social_tool') == 'true') {
  1334. $profile_url = api_get_path(WEB_CODE_PATH).'social/home.php';
  1335. } else {
  1336. $profile_url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
  1337. }
  1338. $this->assign('profile_url', $profile_url);
  1339. //Message link
  1340. $message_link = null;
  1341. $message_url = null;
  1342. if (api_get_setting('allow_message_tool') == 'true') {
  1343. $message_url = api_get_path(WEB_CODE_PATH).'messages/inbox.php';
  1344. $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
  1345. }
  1346. $this->assign('message_link', $message_link);
  1347. $this->assign('message_url', $message_url);
  1348. $pendingSurveyLink = '';
  1349. $show = api_get_configuration_value('show_pending_survey_in_menu');
  1350. if ($show) {
  1351. $pendingSurveyLink = api_get_path(WEB_CODE_PATH).'survey/pending.php';
  1352. }
  1353. $this->assign('pending_survey_url', $pendingSurveyLink);
  1354. // Certificate Link
  1355. $allow = api_get_configuration_value('hide_my_certificate_link');
  1356. if ($allow === false) {
  1357. $certificateUrl = api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php';
  1358. $certificateLink = Display::url(
  1359. get_lang('MyCertificates'),
  1360. $certificateUrl
  1361. );
  1362. $this->assign('certificate_link', $certificateLink);
  1363. $this->assign('certificate_url', $certificateUrl);
  1364. }
  1365. $institution = api_get_setting('Institution');
  1366. $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
  1367. $this->assign('portal_name', $portal_name);
  1368. //Menu
  1369. $menu = menuArray();
  1370. $this->assign('menu', $menu);
  1371. $breadcrumb = '';
  1372. // Hide breadcrumb in LP
  1373. if ($this->show_learnpath == false) {
  1374. $breadcrumb = return_breadcrumb(
  1375. $interbreadcrumb,
  1376. $language_file,
  1377. $nameTools
  1378. );
  1379. }
  1380. $this->assign('breadcrumb', $breadcrumb);
  1381. //Extra content
  1382. $extra_header = null;
  1383. if (!api_is_platform_admin()) {
  1384. $extra_header = trim(api_get_setting('header_extra_content'));
  1385. }
  1386. $this->assign('header_extra_content', $extra_header);
  1387. if ($sendHeaders) {
  1388. header('Content-Type: text/html; charset='.api_get_system_encoding());
  1389. header(
  1390. 'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1)
  1391. );
  1392. self::addHTTPSecurityHeaders();
  1393. $responseCode = $this->getResponseCode();
  1394. if (!empty($responseCode)) {
  1395. switch ($responseCode) {
  1396. case '404':
  1397. header("HTTP/1.0 404 Not Found");
  1398. break;
  1399. }
  1400. }
  1401. }
  1402. $this->assignSocialMeta();
  1403. }
  1404. /**
  1405. * Set footer parameters.
  1406. */
  1407. private function set_footer_parameters()
  1408. {
  1409. if (api_get_setting('show_administrator_data') === 'true') {
  1410. $firstName = api_get_setting('administratorName');
  1411. $lastName = api_get_setting('administratorSurname');
  1412. if (!empty($firstName) && !empty($lastName)) {
  1413. $name = api_get_person_name($firstName, $lastName);
  1414. } else {
  1415. $name = $lastName;
  1416. if (empty($lastName)) {
  1417. $name = $firstName;
  1418. }
  1419. }
  1420. $adminName = '';
  1421. // Administrator name
  1422. if (!empty($name)) {
  1423. $adminName = get_lang('Manager').' : '.
  1424. Display::encrypted_mailto_link(
  1425. api_get_setting('emailAdministrator'),
  1426. $name
  1427. );
  1428. }
  1429. $this->assign('administrator_name', $adminName);
  1430. }
  1431. // Loading footer extra content
  1432. if (!api_is_platform_admin()) {
  1433. $extra_footer = trim(api_get_setting('footer_extra_content'));
  1434. if (!empty($extra_footer)) {
  1435. $this->assign('footer_extra_content', $extra_footer);
  1436. }
  1437. }
  1438. // Tutor name
  1439. if (api_get_setting('show_tutor_data') == 'true') {
  1440. // Course manager
  1441. $courseId = api_get_course_int_id();
  1442. $id_session = api_get_session_id();
  1443. if (!empty($courseId)) {
  1444. $tutor_data = '';
  1445. if ($id_session != 0) {
  1446. $coachs_email = CourseManager::get_email_of_tutor_to_session(
  1447. $id_session,
  1448. $courseId
  1449. );
  1450. $email_link = [];
  1451. foreach ($coachs_email as $coach) {
  1452. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  1453. }
  1454. if (count($coachs_email) > 1) {
  1455. $tutor_data .= get_lang('Coachs').' : ';
  1456. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  1457. } elseif (count($coachs_email) == 1) {
  1458. $tutor_data .= get_lang('Coach').' : ';
  1459. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  1460. } elseif (count($coachs_email) == 0) {
  1461. $tutor_data .= '';
  1462. }
  1463. }
  1464. $this->assign('session_teachers', $tutor_data);
  1465. }
  1466. }
  1467. if (api_get_setting('show_teacher_data') == 'true') {
  1468. // course manager
  1469. $courseId = api_get_course_int_id();
  1470. if (!empty($courseId)) {
  1471. $teacher_data = '';
  1472. $mail = CourseManager::get_emails_of_tutors_to_course($courseId);
  1473. if (!empty($mail)) {
  1474. $teachers_parsed = [];
  1475. foreach ($mail as $value) {
  1476. foreach ($value as $email => $name) {
  1477. $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
  1478. }
  1479. }
  1480. $label = get_lang('Teacher');
  1481. if (count($mail) > 1) {
  1482. $label = get_lang('Teachers');
  1483. }
  1484. $teacher_data .= $label.' : '.array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
  1485. }
  1486. $this->assign('teachers', $teacher_data);
  1487. }
  1488. }
  1489. }
  1490. /**
  1491. * Set administrator variables.
  1492. */
  1493. private function setAdministratorParams()
  1494. {
  1495. $_admin = [
  1496. 'email' => api_get_setting('emailAdministrator'),
  1497. 'surname' => api_get_setting('administratorSurname'),
  1498. 'name' => api_get_setting('administratorName'),
  1499. 'telephone' => api_get_setting('administratorTelephone'),
  1500. ];
  1501. $this->assign('_admin', $_admin);
  1502. }
  1503. /**
  1504. * Manage specific HTTP headers security.
  1505. */
  1506. private function addHTTPSecurityHeaders()
  1507. {
  1508. // Implementation of HTTP headers security, as suggested and checked
  1509. // by https://securityheaders.io/
  1510. // Enable these settings in configuration.php to use them on your site
  1511. // Strict-Transport-Security
  1512. $setting = api_get_configuration_value('security_strict_transport');
  1513. if (!empty($setting)) {
  1514. header('Strict-Transport-Security: '.$setting);
  1515. }
  1516. // Content-Security-Policy
  1517. $setting = api_get_configuration_value('security_content_policy');
  1518. if (!empty($setting)) {
  1519. header('Content-Security-Policy: '.$setting);
  1520. }
  1521. $setting = api_get_configuration_value('security_content_policy_report_only');
  1522. if (!empty($setting)) {
  1523. header('Content-Security-Policy-Report-Only: '.$setting);
  1524. }
  1525. // Public-Key-Pins
  1526. $setting = api_get_configuration_value('security_public_key_pins');
  1527. if (!empty($setting)) {
  1528. header('Public-Key-Pins: '.$setting);
  1529. }
  1530. $setting = api_get_configuration_value('security_public_key_pins_report_only');
  1531. if (!empty($setting)) {
  1532. header('Public-Key-Pins-Report-Only: '.$setting);
  1533. }
  1534. // X-Frame-Options
  1535. $setting = api_get_configuration_value('security_x_frame_options');
  1536. if (!empty($setting)) {
  1537. header('X-Frame-Options: '.$setting);
  1538. }
  1539. // X-XSS-Protection
  1540. $setting = api_get_configuration_value('security_xss_protection');
  1541. if (!empty($setting)) {
  1542. header('X-XSS-Protection: '.$setting);
  1543. }
  1544. // X-Content-Type-Options
  1545. $setting = api_get_configuration_value('security_x_content_type_options');
  1546. if (!empty($setting)) {
  1547. header('X-Content-Type-Options: '.$setting);
  1548. }
  1549. // Referrer-Policy
  1550. $setting = api_get_configuration_value('security_referrer_policy');
  1551. if (!empty($setting)) {
  1552. header('Referrer-Policy: '.$setting);
  1553. }
  1554. // end of HTTP headers security block
  1555. }
  1556. /**
  1557. * Assign favicon to the 'favico' template variable.
  1558. *
  1559. * @return bool Always return true because there is always at least one correct favicon.ico
  1560. */
  1561. private function assignFavIcon()
  1562. {
  1563. // Default root chamilo favicon
  1564. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  1565. //Added to verify if in the current Chamilo Theme exist a favicon
  1566. $favicoThemeUrl = api_get_path(SYS_CSS_PATH).$this->themeDir.'images/';
  1567. //If exist pick the current chamilo theme favicon
  1568. if (is_file($favicoThemeUrl.'favicon.ico')) {
  1569. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_CSS_PATH).$this->themeDir.'images/favicon.ico" type="image/x-icon" />';
  1570. }
  1571. if (api_is_multiple_url_enabled()) {
  1572. $access_url_id = api_get_current_access_url_id();
  1573. if ($access_url_id != -1) {
  1574. $url_info = api_get_access_url($access_url_id);
  1575. $url = api_remove_trailing_slash(
  1576. preg_replace('/https?:\/\//i', '', $url_info['url'])
  1577. );
  1578. $clean_url = api_replace_dangerous_char($url);
  1579. $clean_url = str_replace('/', '-', $clean_url);
  1580. $clean_url .= '/';
  1581. $homep = api_get_path(WEB_HOME_PATH).$clean_url; //homep for Home Path
  1582. $icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
  1583. //we create the new dir for the new sites
  1584. if (is_file($icon_real_homep.'favicon.ico')) {
  1585. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  1586. }
  1587. }
  1588. }
  1589. $this->assign('favico', $favico);
  1590. return true;
  1591. }
  1592. /**
  1593. * Assign HTML code to the 'accessibility' template variable (usually shown above top menu).
  1594. *
  1595. * @return bool Always return true (even if empty string)
  1596. */
  1597. private function assignAccessibilityBlock()
  1598. {
  1599. $resize = '';
  1600. if (api_get_setting('accessibility_font_resize') == 'true') {
  1601. $resize .= '<div class="resize_font">';
  1602. $resize .= '<div class="btn-group">';
  1603. $resize .= '<a title="'.get_lang('DecreaseFontSize').'" href="#" class="decrease_font btn btn-default"><em class="fa fa-font"></em></a>';
  1604. $resize .= '<a title="'.get_lang('ResetFontSize').'" href="#" class="reset_font btn btn-default"><em class="fa fa-font"></em></a>';
  1605. $resize .= '<a title="'.get_lang('IncreaseFontSize').'" href="#" class="increase_font btn btn-default"><em class="fa fa-font"></em></a>';
  1606. $resize .= '</div>';
  1607. $resize .= '</div>';
  1608. }
  1609. $this->assign('accessibility', $resize);
  1610. return true;
  1611. }
  1612. /**
  1613. * Assign HTML code to the 'social_meta' template variable (usually shown above top menu).
  1614. *
  1615. * @return bool Always return true (even if empty string)
  1616. */
  1617. private function assignSocialMeta()
  1618. {
  1619. $socialMeta = '';
  1620. $metaTitle = api_get_setting('meta_title');
  1621. if (!empty($metaTitle)) {
  1622. $socialMeta .= '<meta name="twitter:card" content="summary" />'."\n";
  1623. $metaSite = api_get_setting('meta_twitter_site');
  1624. if (!empty($metaSite)) {
  1625. $socialMeta .= '<meta name="twitter:site" content="'.$metaSite.'" />'."\n";
  1626. $metaCreator = api_get_setting('meta_twitter_creator');
  1627. if (!empty($metaCreator)) {
  1628. $socialMeta .= '<meta name="twitter:creator" content="'.$metaCreator.'" />'."\n";
  1629. }
  1630. }
  1631. // The user badge page emits its own meta tags, so if this is
  1632. // enabled, ignore the global ones
  1633. $userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
  1634. $skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
  1635. if (!$userId && !$skillId) {
  1636. // no combination of user and skill ID has been defined,
  1637. // so print the normal or course-specific OpenGraph meta tags
  1638. // Check for a course ID
  1639. $courseId = api_get_course_int_id();
  1640. // Check session ID from session/id/about (see .htaccess)
  1641. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  1642. if ($courseId != false) {
  1643. // If we are inside a course (even if within a session), publish info about the course
  1644. $course = api_get_course_entity($courseId);
  1645. // @TODO: support right-to-left in title
  1646. $socialMeta .= '<meta property="og:title" content="'.$course->getTitle().' - '.$metaTitle.'" />'."\n";
  1647. $socialMeta .= '<meta property="twitter:title" content="'.$course->getTitle().' - '.$metaTitle.'" />'."\n";
  1648. $socialMeta .= '<meta property="og:url" content="'.api_get_course_url($course->getCode()).'" />'."\n";
  1649. $metaDescription = api_get_setting('meta_description');
  1650. if (!empty($course->getDescription())) {
  1651. $socialMeta .= '<meta property="og:description" content="'.strip_tags($course->getDescription()).'" />'."\n";
  1652. $socialMeta .= '<meta property="twitter:description" content="'.strip_tags($course->getDescription()).'" />'."\n";
  1653. } elseif (!empty($metaDescription)) {
  1654. $socialMeta .= '<meta property="og:description" content="'.$metaDescription.'" />'."\n";
  1655. $socialMeta .= '<meta property="twitter:description" content="'.$metaDescription.'" />'."\n";
  1656. }
  1657. $picture = CourseManager::getPicturePath($course, true);
  1658. if (!empty($picture)) {
  1659. $socialMeta .= '<meta property="og:image" content="'.$picture.'" />'."\n";
  1660. $socialMeta .= '<meta property="twitter:image" content="'.$picture.'" />'."\n";
  1661. $socialMeta .= '<meta property="twitter:image:alt" content="'.$course->getTitle().' - '.$metaTitle.'" />'."\n";
  1662. } else {
  1663. $socialMeta .= $this->getMetaPortalImagePath($metaTitle);
  1664. }
  1665. } elseif ($sessionId !== 0) {
  1666. // If we are on a session "about" screen, publish info about the session
  1667. $em = Database::getManager();
  1668. $session = $em->find('ChamiloCoreBundle:Session', $sessionId);
  1669. $socialMeta .= '<meta property="og:title" content="'.$session->getName().' - '.$metaTitle.'" />'."\n";
  1670. $socialMeta .= '<meta property="twitter:title" content="'.$session->getName().' - '.$metaTitle.'" />'."\n";
  1671. $socialMeta .= '<meta property="og:url" content="'.api_get_path(WEB_PATH)."session/{$session->getId()}/about/".'" />'."\n";
  1672. $sessionValues = new ExtraFieldValue('session');
  1673. $sessionImage = $sessionValues->get_values_by_handler_and_field_variable($session->getId(), 'image')['value'];
  1674. $sessionImageSysPath = api_get_path(SYS_UPLOAD_PATH).$sessionImage;
  1675. if (!empty($sessionImage) && is_file($sessionImageSysPath)) {
  1676. $sessionImagePath = api_get_path(WEB_UPLOAD_PATH).$sessionImage;
  1677. $socialMeta .= '<meta property="og:image" content="'.$sessionImagePath.'" />'."\n";
  1678. $socialMeta .= '<meta property="twitter:image" content="'.$sessionImagePath.'" />'."\n";
  1679. $socialMeta .= '<meta property="twitter:image:alt" content="'.$session->getName().' - '.$metaTitle.'" />'."\n";
  1680. } else {
  1681. $socialMeta .= $this->getMetaPortalImagePath($metaTitle);
  1682. }
  1683. } else {
  1684. // Otherwise (not a course nor a session, nor a user, nor a badge), publish portal info
  1685. $socialMeta .= '<meta property="og:title" content="'.$metaTitle.'" />'."\n";
  1686. $socialMeta .= '<meta property="twitter:title" content="'.$metaTitle.'" />'."\n";
  1687. $socialMeta .= '<meta property="og:url" content="'.api_get_path(WEB_PATH).'" />'."\n";
  1688. $metaDescription = api_get_setting('meta_description');
  1689. if (!empty($metaDescription)) {
  1690. $socialMeta .= '<meta property="og:description" content="'.$metaDescription.'" />'."\n";
  1691. $socialMeta .= '<meta property="twitter:description" content="'.$metaDescription.'" />'."\n";
  1692. }
  1693. $socialMeta .= $this->getMetaPortalImagePath($metaTitle);
  1694. }
  1695. }
  1696. }
  1697. $this->assign('social_meta', $socialMeta);
  1698. return true;
  1699. }
  1700. /**
  1701. * Get platform meta image tag (check meta_image_path setting, then use the logo).
  1702. *
  1703. * @param string $imageAlt The alt attribute for the image
  1704. *
  1705. * @return string The meta image HTML tag, or empty
  1706. */
  1707. private function getMetaPortalImagePath($imageAlt = '')
  1708. {
  1709. // Load portal meta image if defined
  1710. $metaImage = api_get_setting('meta_image_path');
  1711. $metaImageSysPath = api_get_path(SYS_PATH).$metaImage;
  1712. $metaImageWebPath = api_get_path(WEB_PATH).$metaImage;
  1713. $portalImageMeta = '';
  1714. if (!empty($metaImage)) {
  1715. if (is_file($metaImageSysPath)) {
  1716. $portalImageMeta = '<meta property="og:image" content="'.$metaImageWebPath.'" />'."\n";
  1717. $portalImageMeta .= '<meta property="twitter:image" content="'.$metaImageWebPath.'" />'."\n";
  1718. $portalImageMeta .= '<meta property="twitter:image:alt" content="'.$imageAlt.'" />'."\n";
  1719. }
  1720. } else {
  1721. $logo = ChamiloApi::getPlatformLogoPath($this->theme);
  1722. if (!empty($logo)) {
  1723. $portalImageMeta = '<meta property="og:image" content="'.$logo.'" />'."\n";
  1724. $portalImageMeta .= '<meta property="twitter:image" content="'.$logo.'" />'."\n";
  1725. $portalImageMeta .= '<meta property="twitter:image:alt" content="'.$imageAlt.'" />'."\n";
  1726. }
  1727. }
  1728. return $portalImageMeta;
  1729. }
  1730. }