From 27604d25b05aef1a4869866dd798d4ab59d137f5 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 2 Apr 2015 22:21:13 -0500 Subject: [PATCH] Implement Twitter Cards and Open Graph meta headers - refs #7536 --- main/inc/lib/template.lib.php | 29 ++++++++++++++++++++ main/install/database.sql | 5 ++++ main/install/migrate-db-1.9.0-1.10.0-pre.sql | 10 ++++++- main/template/default/layout/head.tpl | 1 + 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 64e7388f32..a90cd89cdb 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -885,6 +885,35 @@ class Template 'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1) ); //} + + $socialMeta = ''; + $metaTitle = api_get_setting('meta_title'); + if (!empty($metaTitle)) { + $socialMeta .= '' . "\n"; + $socialMeta .= '' . "\n"; + $socialMeta .= '' . "\n"; + $metaDescription = api_get_setting('meta_description'); + if (!empty($metaDescription)) { + $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"; + } + } + $metaImage = api_get_setting('meta_image_path'); + if (!empty($metaImage)) { + if (is_file(api_get_path(SYS_PATH) . $metaImage)) { + $path = api_get_path(WEB_PATH) . $metaImage; + $socialMeta .= '' . "\n"; + } + } + } + + $this->assign('social_meta', $socialMeta); } /** diff --git a/main/install/database.sql b/main/install/database.sql index 76ca1ac1f5..4f1565b75a 100644 --- a/main/install/database.sql +++ b/main/install/database.sql @@ -887,6 +887,11 @@ VALUES ('prevent_session_admins_to_manage_all_users', NULL, 'radio', 'Session', 'false', 'PreventSessionAdminsToManageAllUsersTitle', 'PreventSessionAdminsToManageAllUsersComment', NULL, NULL, 1), ('documents_default_visibility_defined_in_course', NULL,'radio','Tools','false','DocumentsDefaultVisibilityDefinedInCourseTitle','DocumentsDefaultVisibilityDefinedInCourseComment',NULL, NULL, 1), ('enabled_mathjax', NULL, 'radio', 'Editor', 'false', 'EnableMathJaxTitle', 'EnableMathJaxComment', NULL, NULL, 0), +('meta_twitter_site', NULL, 'textfield', 'Tracking', '', 'MetaTwitterSiteTitle', 'MetaTwitterSiteComment', NULL, NULL, 1), +('meta_twitter_creator', NULL, 'textfield', 'Tracking', '', 'MetaTwitterCreatorTitle', 'MetaTwitterCreatorComment', NULL, NULL, 1), +('meta_title', NULL, 'textfield', 'Tracking', '', 'MetaTitleTitle', 'MetaTitleComment', NULL, NULL, 1), +('meta_description', NULL, 'textfield', 'Tracking', '', 'MetaDescriptionTitle', 'MetaDescriptionComment', NULL, NULL, 1), +('meta_image_path', NULL, 'textfield', 'Tracking', '', 'MetaImagePathTitle', 'MetaImagePathComment', NULL, NULL, 1), ('chamilo_database_version', NULL, 'textfield',NULL, '0', 'DatabaseVersion','', NULL, NULL, 0); UNLOCK TABLES; /*!40000 ALTER TABLE settings_current ENABLE KEYS */; diff --git a/main/install/migrate-db-1.9.0-1.10.0-pre.sql b/main/install/migrate-db-1.9.0-1.10.0-pre.sql index 770cb458ea..04fcd816c9 100644 --- a/main/install/migrate-db-1.9.0-1.10.0-pre.sql +++ b/main/install/migrate-db-1.9.0-1.10.0-pre.sql @@ -104,6 +104,14 @@ ALTER TABLE session MODIFY COLUMN name char(100) NOT NULL DEFAULT ''; ALTER TABLE track_e_default MODIFY COLUMN c_id int default NULL; UPDATE course_field SET field_type = 1 WHERE field_variable = 'special_course'; +-- v1.10.0.34 +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('meta_twitter_site', NULL, 'textfield', 'Tracking', '', 'MetaTwitterSiteTitle', 'MetaTwitterSiteComment', NULL, NULL, 1); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('meta_twitter_creator', NULL, 'textfield', 'Tracking', '', 'MetaTwitterCreatorTitle', 'MetaTwitterCreatorComment', NULL, NULL, 1); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('meta_title', NULL, 'textfield', 'Tracking', '', 'MetaTitleTitle', 'MetaTitleComment', NULL, NULL, 1); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('meta_description', NULL, 'textfield', 'Tracking', '', 'MetaDescriptionTitle', 'MetaDescriptionComment', NULL, NULL, 1); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('meta_image_path', NULL, 'textfield', 'Tracking', '', 'MetaImagePathTitle', 'MetaImagePathComment', NULL, NULL, 1); + + -- Course DB changes (c_*) ALTER TABLE c_survey ADD COLUMN visible_results INT UNSIGNED DEFAULT 0; @@ -123,4 +131,4 @@ CREATE TABLE IF NOT EXISTS c_attendance_calendar_rel_group (id int NOT NULL auto -- Do not move this query -UPDATE settings_current SET selected_value = '1.10.0.33' WHERE variable = 'chamilo_database_version'; +UPDATE settings_current SET selected_value = '1.10.0.34' WHERE variable = 'chamilo_database_version'; diff --git a/main/template/default/layout/head.tpl b/main/template/default/layout/head.tpl index 239a099e50..43b1c6f9ae 100755 --- a/main/template/default/layout/head.tpl +++ b/main/template/default/layout/head.tpl @@ -12,6 +12,7 @@ {# Improve usability in portal devices #} {{ title_string }} +{{ social_meta }} {{ css_static_file_to_string }} {{ js_file_to_string }}