';
}
}
$this->assign('help_content', $content);
}
/**
* Use template system to parse the actions menu.
*
* @todo finish it!
*/
public function set_actions($actions)
{
$action_string = '';
if (!empty($actions)) {
foreach ($actions as $action) {
$action_string .= $action;
}
}
$this->assign('actions', $actions);
}
/**
* Shortcut to display a 1 col layout (index.php).
* */
public function display_one_col_template()
{
$tpl = $this->get_template('layout/layout_1_col.tpl');
$this->display($tpl);
}
/**
* Shortcut to display a 2 col layout (userportal.php).
*/
public function display_two_col_template()
{
$tpl = $this->get_template('layout/layout_2_col.tpl');
$this->display($tpl);
}
/**
* Displays an empty template.
*/
public function display_blank_template()
{
$tpl = $this->get_template('layout/blank.tpl');
$this->display($tpl);
}
/**
* Displays an empty template.
*/
public function displayBlankTemplateNoHeader()
{
$tpl = $this->get_template('layout/blank_no_header.tpl');
$this->display($tpl);
}
/**
* Displays an empty template.
*/
public function display_no_layout_template()
{
$tpl = $this->get_template('layout/no_layout.tpl');
$this->display($tpl);
}
/**
* Sets the footer visibility.
*
* @param bool true if we show the footer
*/
public function set_footer($status)
{
$this->show_footer = $status;
$this->assign('show_footer', $status);
}
/**
* return true if toolbar has to be displayed for user.
*
* @return bool
*/
public static function isToolBarDisplayedForUser()
{
//Toolbar
$show_admin_toolbar = api_get_setting('show_admin_toolbar');
$show_toolbar = false;
switch ($show_admin_toolbar) {
case 'do_not_show':
break;
case 'show_to_admin':
if (api_is_platform_admin()) {
$show_toolbar = true;
}
break;
case 'show_to_admin_and_teachers':
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$show_toolbar = true;
}
break;
case 'show_to_all':
$show_toolbar = true;
break;
}
return $show_toolbar;
}
/**
* Sets the header visibility.
*
* @param bool true if we show the header
*/
public function set_header($status)
{
$this->show_header = $status;
$this->assign('show_header', $status);
$show_toolbar = 0;
if (self::isToolBarDisplayedForUser()) {
$show_toolbar = 1;
}
$this->assign('show_toolbar', $show_toolbar);
//Only if course is available
$show_course_shortcut = null;
$show_course_navigation_menu = null;
if (!empty($this->course_id) && $this->user_is_logged_in) {
if (api_get_setting('show_toolshortcuts') != 'false') {
//Course toolbar
$show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
}
if (api_get_setting('show_navigation_menu') != 'false') {
//Course toolbar
$show_course_navigation_menu = CourseHome::show_navigation_menu();
}
}
$this->assign('show_course_shortcut', $show_course_shortcut);
$this->assign('show_course_navigation_menu', $show_course_navigation_menu);
}
/**
* Returns the sub-folder and filename for the given tpl file.
*
* If template not found in overrides/ or custom template folder, the default template will be used.
*
* @param string $name
*
* @return string
*/
public static function findTemplateFilePath($name)
{
$sysTemplatePath = api_get_path(SYS_TEMPLATE_PATH);
// Check if the tpl file is present in the main/template/overrides/ dir
// Overrides is a special directory meant for temporary template
// customization. It must be taken into account before anything else
if (is_readable($sysTemplatePath."overrides/$name")) {
return "overrides/$name";
}
$defaultFolder = api_get_configuration_value('default_template');
// If a template folder has been manually defined, search for the right
// file, and if not found, go for the same file in the default template
if ($defaultFolder && $defaultFolder != 'default') {
// Avoid missing template error, use the default file.
if (file_exists($sysTemplatePath."$defaultFolder/$name")) {
return "$defaultFolder/$name";
}
}
return "default/$name";
}
/**
* Call non-static for Template::findTemplateFilePath.
*
* @see Template::findTemplateFilePath()
*
* @param string $name
*
* @return string
*/
public function get_template($name)
{
return self::findTemplateFilePath($name);
}
/**
* Get CSS themes sub-directory.
*
* @param string $theme
*
* @return string with a trailing slash, e.g. 'themes/chamilo_red/'
*/
public static function getThemeDir($theme)
{
$themeDir = 'themes/'.$theme.'/';
$virtualTheme = api_get_configuration_value('virtual_css_theme_folder');
if (!empty($virtualTheme)) {
$virtualThemeList = api_get_themes(true);
$isVirtualTheme = in_array($theme, array_keys($virtualThemeList));
if ($isVirtualTheme) {
$themeDir = 'themes/'.$virtualTheme.'/'.$theme.'/';
}
}
return $themeDir;
}
/**
* Set system parameters from api_get_configuration into _s array for use in TPLs
* Also fills the _p array from getWebPaths().
*
* @uses \self::getWebPaths()
*/
public function set_system_parameters()
{
// Get the interface language from global.inc.php
global $language_interface;
$this->theme = api_get_visual_theme();
if (!empty($this->preview_theme)) {
$this->theme = $this->preview_theme;
}
$this->themeDir = self::getThemeDir($this->theme);
// Setting app paths/URLs
$this->assign('_p', $this->getWebPaths());
// Here we can add system parameters that can be use in any template
$_s = [
'software_name' => api_get_configuration_value('software_name'),
'system_version' => api_get_configuration_value('system_version'),
'site_name' => api_get_setting('siteName'),
'institution' => api_get_setting('Institution'),
'date' => api_format_date('now', DATE_FORMAT_LONG),
'timezone' => api_get_timezone(),
'gamification_mode' => api_get_setting('gamification_mode'),
'language_interface' => $language_interface,
];
$this->assign('_s', $_s);
}
/**
* Set theme, include mainstream CSS files.
*
* @see setCssCustomFiles() for additional CSS sheets
*/
public function setCssFiles()
{
global $disable_js_and_css_files;
$css = [];
// Default CSS Bootstrap
$bowerCSSFiles = [
'fontawesome/css/font-awesome.min.css',
'jquery-ui/themes/smoothness/theme.css',
'jquery-ui/themes/smoothness/jquery-ui.min.css',
'mediaelement/build/mediaelementplayer.min.css',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.css',
'bootstrap/dist/css/bootstrap.min.css',
'jquery.scrollbar/jquery.scrollbar.css',
'bootstrap-daterangepicker/daterangepicker.css',
'bootstrap-select/dist/css/bootstrap-select.min.css',
'select2/dist/css/select2.min.css',
'flag-icon-css/css/flag-icon.min.css',
];
$features = api_get_configuration_value('video_features');
$defaultFeatures = ['playpause', 'current', 'progress', 'duration', 'tracks', 'volume', 'fullscreen'];
if (!empty($features) && isset($features['features'])) {
foreach ($features['features'] as $feature) {
$bowerCSSFiles[] = "mediaelement/plugins/$feature/$feature.css";
$defaultFeatures[] = $feature;
}
}
foreach ($bowerCSSFiles as $file) {
$css[] = api_get_path(WEB_PUBLIC_PATH).'assets/'.$file;
}
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
if (api_is_global_chat_enabled()) {
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
}
$css_file_to_string = '';
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
if (!$disable_js_and_css_files) {
$this->assign('css_static_file_to_string', $css_file_to_string);
}
$defaultFeatures = implode("','", $defaultFeatures);
$this->assign('video_features', $defaultFeatures);
}
/**
* Prepare custom CSS to be added at the very end of the section.
*
* @see setCssFiles() for the mainstream CSS files
*/
public function setCssCustomFiles()
{
global $disable_js_and_css_files;
// Base CSS
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
if ($this->show_learnpath) {
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'scorm.css');
if (is_file(api_get_path(SYS_CSS_PATH).$this->themeDir.'learnpath.css')) {
$css[] = api_get_path(WEB_CSS_PATH).$this->themeDir.'learnpath.css';
}
}
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->themeDir.'default.css');
$css[] = api_get_cdn_path(ChamiloApi::getEditorBlockStylePath());
$css_file_to_string = null;
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
// @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
if (SHOW_TEXT_NEAR_ICONS == true) {
//hack in order to fix the actions buttons
$css_file_to_string .= '';
}
$navigator_info = api_get_navigator();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
}
if (!$disable_js_and_css_files) {
$this->assign('css_custom_file_to_string', $css_file_to_string);
$style_print = '';
if (is_readable(api_get_path(SYS_CSS_PATH).$this->theme.'/print.css')) {
$style_print = api_get_css(
api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/print.css'),
'print'
);
}
$this->assign('css_style_print', $style_print);
}
// Logo
$logo = return_logo($this->theme);
$this->assign('logo', $logo);
$this->assign('show_media_element', 1);
}
/**
* Declare and define the template variable that will be used to load
* javascript libraries in the header.
*/
public function set_js_files()
{
global $disable_js_and_css_files, $htmlHeadXtra;
$isoCode = api_get_language_isocode();
$selectLink = 'bootstrap-select/dist/js/i18n/defaults-'.$isoCode.'_'.strtoupper($isoCode).'.min.js';
if ($isoCode == 'en') {
$selectLink = 'bootstrap-select/dist/js/i18n/defaults-'.$isoCode.'_US.min.js';
}
// JS files
$js_files = [
'chosen/chosen.jquery.min.js',
];
$viewBySession = api_get_setting('my_courses_view_by_session') === 'true';
if (api_is_global_chat_enabled() || $viewBySession) {
// Do not include the global chat in LP
if ($this->show_learnpath == false &&
$this->show_footer == true &&
$this->hide_global_chat == false
) {
$js_files[] = 'chat/js/chat.js';
}
}
if (api_get_setting('accessibility_font_resize') == 'true') {
$js_files[] = 'fontresize.js';
}
$js_file_to_string = '';
$bowerJsFiles = [
'modernizr/modernizr.js',
'jquery/dist/jquery.min.js',
'bootstrap/dist/js/bootstrap.min.js',
'jquery-ui/jquery-ui.min.js',
'jqueryui-touch-punch/jquery.ui.touch-punch.min.js',
'moment/min/moment-with-locales.js',
'bootstrap-daterangepicker/daterangepicker.js',
'jquery-timeago/jquery.timeago.js',
'mediaelement/build/mediaelement-and-player.min.js',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
'image-map-resizer/js/imageMapResizer.min.js',
'jquery.scrollbar/jquery.scrollbar.min.js',
'readmore-js/readmore.min.js',
'bootstrap-select/dist/js/bootstrap-select.min.js',
$selectLink,
'select2/dist/js/select2.min.js',
"select2/dist/js/i18n/$isoCode.js",
];
$features = api_get_configuration_value('video_features');
if (!empty($features) && isset($features['features'])) {
foreach ($features['features'] as $feature) {
$bowerJsFiles[] = "mediaelement/plugins/$feature/$feature.js";
}
}
if (CHAMILO_LOAD_WYSIWYG === true) {
$bowerJsFiles[] = 'ckeditor/ckeditor.js';
}
if (api_get_setting('include_asciimathml_script') === 'true') {
$bowerJsFiles[] = 'MathJax/MathJax.js?config=TeX-MML-AM_HTMLorMML';
}
if ($isoCode != 'en') {
$bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-'.$isoCode.'.js';
$bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-'.$isoCode.'.min.js';
}
foreach ($bowerJsFiles as $file) {
$js_file_to_string .= ''."\n";
}
foreach ($js_files as $file) {
$js_file_to_string .= api_get_js($file);
}
// Loading email_editor js
if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
$template = $this->get_template('mail_editor/email_link.js.tpl');
$js_file_to_string .= $this->fetch($template);
}
if (!$disable_js_and_css_files) {
$this->assign('js_file_to_string', $js_file_to_string);
$extra_headers = '';
//Adding jquery ui by default
$extra_headers .= api_get_jquery_ui_js();
//$extra_headers = '';
if (isset($htmlHeadXtra) && $htmlHeadXtra) {
foreach ($htmlHeadXtra as &$this_html_head) {
$extra_headers .= $this_html_head."\n";
}
}
$this->assign('extra_headers', $extra_headers);
}
}
/**
* Special function to declare last-minute JS libraries which depend on
* other things to be declared first. In particular, it might be useful
* under IE9 with compatibility mode, which for some reason is getting
* upset when a variable is used in a function (even if not used yet)
* when this variable hasn't been defined yet.
*/
public function set_js_files_post()
{
global $disable_js_and_css_files;
$js_files = [];
if (api_is_global_chat_enabled()) {
//Do not include the global chat in LP
if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
$js_files[] = 'chat/js/chat.js';
}
}
$js_file_to_string = null;
foreach ($js_files as $js_file) {
$js_file_to_string .= api_get_js($js_file);
}
if (!$disable_js_and_css_files) {
$this->assign('js_file_to_string_post', $js_file_to_string);
}
}
/**
* Show header template.
*/
public function show_header_template()
{
$tpl = $this->get_template('layout/show_header.tpl');
$this->display($tpl);
}
/**
* Show footer template.
*/
public function show_footer_template()
{
$tpl = $this->get_template('layout/show_footer.tpl');
$this->display($tpl);
}
/**
* Sets the plugin content in a template variable.
*
* @param string $pluginRegion
*/
public function set_plugin_region($pluginRegion)
{
if (!empty($pluginRegion)) {
$regionContent = $this->plugin->load_region(
$pluginRegion,
$this,
$this->force_plugin_load
);
$pluginList = $this->plugin->get_installed_plugins();
foreach ($pluginList as $plugin_name) {
// The plugin_info variable is available inside the plugin index
$pluginInfo = $this->plugin->getPluginInfo($plugin_name);
if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) {
$courseInfo = api_get_course_info();
if (!empty($courseInfo)) {
if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof Plugin) {
/** @var Plugin $plugin */
$plugin = $pluginInfo['obj'];
$regionContent .= $plugin->renderRegion($pluginRegion);
}
}
} else {
continue;
}
}
if (!empty($regionContent)) {
$this->assign('plugin_'.$pluginRegion, $regionContent);
} else {
$this->assign('plugin_'.$pluginRegion, null);
}
}
return null;
}
/**
* @param string $template
*
* @return string
*/
public function fetch($template = null)
{
$template = $this->twig->loadTemplate($template);
return $template->render($this->params);
}
/**
* @param string $variable
* @param mixed $value
*/
public function assign($variable, $value = '')
{
$this->params[$variable] = $value;
}
/**
* Render the template.
*
* @param string $template The template path
* @param bool $clearFlashMessages Clear the $_SESSION variables for flash messages
*/
public function display($template, $clearFlashMessages = true)
{
$this->assign('flash_messages', Display::getFlashToString());
if ($clearFlashMessages) {
Display::cleanFlashMessages();
}
echo $this->twig->render($template, $this->params);
}
/**
* Adds a body class for login pages.
*/
public function setLoginBodyClass()
{
$this->assign('login_class', 'section-login');
}
/**
* The theme that will be used if the database is not working.
*
* @return string
*/
public static function getThemeFallback()
{
$theme = api_get_configuration_value('theme_fallback');
if (empty($theme)) {
$theme = 'chamilo';
}
return $theme;
}
/**
* @param bool|true $setLoginForm
*/
public function setLoginForm($setLoginForm = true)
{
global $loginFailed;
$userId = api_get_user_id();
if (!($userId) || api_is_anonymous($userId)) {
// Only display if the user isn't logged in.
$this->assign(
'login_language_form',
api_display_language_form(true, true)
);
if ($setLoginForm) {
$this->assign('login_form', $this->displayLoginForm());
if ($loginFailed) {
$this->assign('login_failed', $this::handleLoginFailed());
}
}
}
}
/**
* @return string
*/
public function handleLoginFailed()
{
$message = get_lang('InvalidId');
if (!isset($_GET['error'])) {
if (api_is_self_registration_allowed()) {
$message = get_lang('InvalidForSelfRegistration');
}
} else {
switch ($_GET['error']) {
case '':
if (api_is_self_registration_allowed()) {
$message = get_lang('InvalidForSelfRegistration');
}
break;
case 'account_expired':
$message = get_lang('AccountExpired');
break;
case 'account_inactive':
$message = get_lang('AccountInactive');
if (api_get_setting('allow_registration') === 'confirmation') {
$message = get_lang('AccountNotConfirmed').PHP_EOL;
$message .= Display::url(
get_lang('ReSendConfirmationMail'),
api_get_path(WEB_PATH).'main/auth/resend_confirmation_mail.php',
['class' => 'alert-link']
);
}
break;
case 'user_password_incorrect':
$message = get_lang('InvalidId');
break;
case 'access_url_inactive':
$message = get_lang('AccountURLInactive');
break;
case 'wrong_captcha':
$message = get_lang('TheTextYouEnteredDoesNotMatchThePicture');
break;
case 'blocked_by_captcha':
$message = get_lang('AccountBlockedByCaptcha');
break;
case 'multiple_connection_not_allowed':
$message = get_lang('MultipleConnectionsAreNotAllow');
break;
case 'unrecognize_sso_origin':
//$message = get_lang('SSOError');
break;
}
}
return Display::return_message($message, 'error', false);
}
/**
* @return string
*/
public function displayLoginForm()
{
$form = new FormValidator(
'form-login',
'POST',
null,
null,
null,
FormValidator::LAYOUT_BOX_NO_LABEL
);
$params = [
'id' => 'login',
'autofocus' => 'autofocus',
'icon' => 'user fa-fw',
'placeholder' => get_lang('UserName'),
];
$browserAutoCapitalize = false;
// Avoid showing the autocapitalize option if the browser doesn't
// support it: this attribute is against the HTML5 standard
if (api_browser_support('autocapitalize')) {
$browserAutoCapitalize = false;
$params['autocapitalize'] = 'none';
}
$form->addText(
'login',
get_lang('UserName'),
true,
$params
);
$params = [
'id' => 'password',
'icon' => 'lock fa-fw',
'placeholder' => get_lang('Pass'),
];
if ($browserAutoCapitalize) {
$params['autocapitalize'] = 'none';
}
$form->addElement(
'password',
'password',
get_lang('Pass'),
$params
);
// Captcha
$captcha = api_get_setting('allow_captcha');
$allowCaptcha = $captcha === 'true';
if ($allowCaptcha) {
$useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null;
if ($useCaptcha) {
$ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
$options = [
'width' => 250,
'height' => 90,
'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
'sessionVar' => basename(__FILE__, '.php'),
'imageOptions' => [
'font_size' => 20,
'font_path' => api_get_path(SYS_FONTS_PATH).'opensans/',
'font_file' => 'OpenSans-Regular.ttf',
//'output' => 'gif'
],
];
// Minimum options using all defaults (including defaults for Image_Text):
//$options = array('callback' => 'qfcaptcha_image.php');
$captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
$form->addHtml(get_lang('ClickOnTheImageForANewOne'));
$form->addElement(
'text',
'captcha',
get_lang('EnterTheLettersYouSee')
);
$form->addRule(
'captcha',
get_lang('EnterTheCharactersYouReadInTheImage'),
'required',
null,
'client'
);
$form->addRule(
'captcha',
get_lang('TheTextYouEnteredDoesNotMatchThePicture'),
'CAPTCHA',
$captcha_question
);
}
}
$form->addButton(
'submitAuth',
get_lang('LoginEnter'),
null,
'primary',
null,
'btn-block'
);
$html = $form->returnForm();
if (api_get_setting('openid_authentication') == 'true') {
include_once api_get_path(SYS_CODE_PATH).'auth/openid/login.php';
$html .= '
'.openid_form().'
';
}
return $html;
}
/**
* Returns the tutors names for the current course in session
* Function to use in Twig templates.
*
* @return string
*/
public static function returnTutorsNames()
{
$em = Database::getManager();
$tutors = $em
->createQuery('
SELECT u FROM ChamiloUserBundle:User u
INNER JOIN ChamiloCoreBundle:SessionRelCourseRelUser scu WITH u.id = scu.user
WHERE scu.status = :teacher_status AND scu.session = :session AND scu.course = :course
')
->setParameters([
'teacher_status' => SessionRelCourseRelUser::STATUS_COURSE_COACH,
'session' => api_get_session_id(),
'course' => api_get_course_int_id(),
])
->getResult();
$names = [];
/** @var User $tutor */
foreach ($tutors as $tutor) {
$names[] = $tutor->getCompleteName();
}
return implode(CourseManager::USER_SEPARATOR, $names);
}
/*s
* Returns the teachers name for the current course
* Function to use in Twig templates
* @return string
*/
public static function returnTeachersNames()
{
$em = Database::getManager();
$teachers = $em
->createQuery('
SELECT u FROM ChamiloUserBundle:User u
INNER JOIN ChamiloCoreBundle:CourseRelUser cu WITH u.id = cu.user
WHERE cu.status = :teacher_status AND cu.course = :course
')
->setParameters([
'teacher_status' => User::COURSE_MANAGER,
'course' => api_get_course_int_id(),
])
->getResult();
$names = [];
/** @var User $teacher */
foreach ($teachers as $teacher) {
$names[] = $teacher->getCompleteName();
}
return implode(CourseManager::USER_SEPARATOR, $names);
}
/**
* @param int $code
*/
public function setResponseCode($code)
{
$this->responseCode = $code;
}
/**
* @param string $code
*/
public function getResponseCode()
{
return $this->responseCode;
}
/**
* Assign HTML code to the 'bug_notification' template variable for the side tabs to report issues.
*
* @return bool Always return true because there is always a string, even if empty
*/
public function assignBugNotification()
{
//@todo move this in the template
$rightFloatMenu = '';
$iconBug = Display::return_icon(
'bug.png',
get_lang('ReportABug'),
[],
ICON_SIZE_LARGE
);
if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) {
$rightFloatMenu = '
';
}
$this->assign('accessibility', $resize);
return true;
}
/**
* Assign HTML code to the 'social_meta' template variable (usually shown above top menu).
*
* @return bool Always return true (even if empty string)
*/
private function assignSocialMeta()
{
$socialMeta = '';
$metaTitle = api_get_setting('meta_title');
if (!empty($metaTitle)) {
$socialMeta .= ''."\n";
$metaSite = api_get_setting('meta_twitter_site');
if (!empty($metaSite)) {
$socialMeta .= ''."\n";
$metaCreator = api_get_setting('meta_twitter_creator');
if (!empty($metaCreator)) {
$socialMeta .= ''."\n";
}
}
// The user badge page emits its own meta tags, so if this is
// enabled, ignore the global ones
$userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
$skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
if (!$userId && !$skillId) {
// no combination of user and skill ID has been defined,
// so print the normal or course-specific OpenGraph meta tags
// Check for a course ID
$courseId = api_get_course_int_id();
// Check session ID from session/id/about (see .htaccess)
$sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
if ($courseId != false) {
// If we are inside a course (even if within a session), publish info about the course
$course = api_get_course_entity($courseId);
// @TODO: support right-to-left in title
$socialMeta .= ''."\n";
$socialMeta .= ''."\n";
$metaDescription = api_get_setting('meta_description');
if (!empty($course->getDescription())) {
$socialMeta .= ''."\n";
} elseif (!empty($metaDescription)) {
$socialMeta .= ''."\n";
}
if (!empty($course->getPicturePath(true))) {
$socialMeta .= ''."\n";
} else {
$socialMeta .= $this->getMetaPortalImagePath();
}
} elseif ($sessionId !== 0) {
// If we are on a session "about" screen, publish info about the session
$em = Database::getManager();
$session = $em->find('ChamiloCoreBundle:Session', $sessionId);
$socialMeta .= ''."\n";
$socialMeta .= 'getId()}/about/".'" />'."\n";
$sessionValues = new ExtraFieldValue('session');
$sessionImage = $sessionValues->get_values_by_handler_and_field_variable($session->getId(), 'image')['value'];
$sessionImageSysPath = api_get_path(SYS_UPLOAD_PATH).$sessionImage;
if (!empty($sessionImage) && is_file($sessionImageSysPath)) {
$sessionImagePath = api_get_path(WEB_UPLOAD_PATH).$sessionImage;
$socialMeta .= ''."\n";
} else {
$socialMeta .= $this->getMetaPortalImagePath();
}
} else {
// Otherwise (not a course nor a session, nor a user, nor a badge), publish portal info
$socialMeta .= ''."\n";
$socialMeta .= ''."\n";
$metaDescription = api_get_setting('meta_description');
if (!empty($metaDescription)) {
$socialMeta .= ''."\n";
}
$socialMeta .= $this->getMetaPortalImagePath();
}
}
}
$this->assign('social_meta', $socialMeta);
return true;
}
/**
* Get platform meta image tag (check meta_image_path setting, then use the logo).
*
* @return string The meta image HTML tag, or empty
*/
private function getMetaPortalImagePath()
{
// Load portal meta image if defined
$metaImage = api_get_setting('meta_image_path');
$metaImageSysPath = api_get_path(SYS_PATH).$metaImage;
$metaImageWebPath = api_get_path(WEB_PATH).$metaImage;
$portalImageMeta = '';
if (!empty($metaImage)) {
if (is_file($metaImageSysPath)) {
$portalImageMeta = ''."\n";
}
} else {
$logo = ChamiloApi::getPlatformLogoPath($this->theme);
if (!empty($logo)) {
$portalImageMeta = ''."\n";
}
}
return $portalImageMeta;
}
}