diff --git a/classes/display/HTMLDisplayHandler.php b/classes/display/HTMLDisplayHandler.php index d498e738a..749f83e0c 100644 --- a/classes/display/HTMLDisplayHandler.php +++ b/classes/display/HTMLDisplayHandler.php @@ -35,6 +35,11 @@ class HTMLDisplayHandler '@\beditor/skins/xpresseditor/js/xe_textarea\.(?:min\.)?js@' => 'editor/skins/ckeditor/js/xe_textarea.js', ); + /** + * Image type information for SEO + */ + protected $_image_type = 'none'; + /** * Produce HTML compliant content given a module object.\n * @param ModuleObject $oModule the module object @@ -163,10 +168,14 @@ class HTMLDisplayHandler } } - // Add OpenGraph metadata + // Add OpenGraph and Twitter metadata if (config('seo.og_enabled') && Context::get('module') !== 'admin') { $this->_addOpenGraphMetadata(); + if (config('seo.twitter_enabled')) + { + $this->_addTwitterMetadata(); + } } // set icon @@ -400,7 +409,6 @@ class HTMLDisplayHandler /** * Add OpenGraph metadata tags. * - * @param string $output * @return void */ function _addOpenGraphMetadata() @@ -528,6 +536,7 @@ class HTMLDisplayHandler Context::addOpenGraphData('og:image', Rhymix\Framework\URL::getCurrentDomainURL($first_image['filepath'])); Context::addOpenGraphData('og:image:width', $first_image['width']); Context::addOpenGraphData('og:image:height', $first_image['height']); + $this->_image_type = 'document'; } elseif ($default_image = getAdminModel('admin')->getSiteDefaultImageUrl($site_module_info->domain_srl, $width, $height)) { @@ -537,6 +546,11 @@ class HTMLDisplayHandler Context::addOpenGraphData('og:image:width', $width); Context::addOpenGraphData('og:image:height', $height); } + $this->_image_type = 'site'; + } + else + { + $this->_image_type = 'none'; } // Add tags and hashtags for articles. @@ -571,6 +585,33 @@ class HTMLDisplayHandler Context::addOpenGraphData('og:article:modified_time', $oDocument->getUpdate('c')); } } + + /** + * Add Twitter metadata tags. + * + * @return void + */ + function _addTwitterMetadata() + { + $card_type = $this->_image_type === 'document' ? 'summary_large_image' : 'summary'; + Context::addMetaTag('twitter:card', $card_type); + + foreach(Context::getOpenGraphData() as $val) + { + if ($val['property'] === 'og:title') + { + Context::addMetaTag('twitter:title', $val['content']); + } + if ($val['property'] === 'og:description') + { + Context::addMetaTag('twitter:description', $val['content']); + } + if ($val['property'] === 'og:image' && $this->_image_type === 'document') + { + Context::addMetaTag('twitter:image', $val['content']); + } + } + } /** * import basic .js files. diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index e9c802290..a30c38745 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -958,6 +958,7 @@ class adminAdminController extends admin Rhymix\Framework\Config::set('seo.og_extract_images', $vars->og_extract_images === 'Y'); Rhymix\Framework\Config::set('seo.og_extract_hashtags', $vars->og_extract_hashtags === 'Y'); Rhymix\Framework\Config::set('seo.og_use_timestamps', $vars->og_use_timestamps === 'Y'); + Rhymix\Framework\Config::set('seo.twitter_enabled', $vars->twitter_enabled === 'Y'); // Save if (!Rhymix\Framework\Config::save()) diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index 61aea67a6..277000aee 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -643,6 +643,7 @@ class adminAdminView extends admin Context::set('og_extract_images', Rhymix\Framework\Config::get('seo.og_extract_images')); Context::set('og_extract_hashtags', Rhymix\Framework\Config::get('seo.og_extract_hashtags')); Context::set('og_use_timestamps', Rhymix\Framework\Config::get('seo.og_use_timestamps')); + Context::set('twitter_enabled', Rhymix\Framework\Config::get('seo.twitter_enabled')); $this->setTemplateFile('config_seo'); } diff --git a/modules/admin/lang/en.php b/modules/admin/lang/en.php index ebed0f298..605727c1b 100644 --- a/modules/admin/lang/en.php +++ b/modules/admin/lang/en.php @@ -249,6 +249,7 @@ $lang->site_meta_keywords = 'SEO Keywords'; $lang->about_site_meta_keywords = 'These keywords will be used on pages that do not have their own keywords.'; $lang->site_meta_description = 'SEO Description'; $lang->about_site_meta_description = 'This description will be used on pages that do not have their own description.'; +$lang->twitter_enabled = 'Add Twitter Meta Tags'; $lang->og_enabled = 'Add OpenGraph Tags'; $lang->og_extract_description = 'Extract Description from Document'; $lang->og_extract_description_fallback = 'Use general description only'; diff --git a/modules/admin/lang/ko.php b/modules/admin/lang/ko.php index ecd6ba522..e6c880e37 100644 --- a/modules/admin/lang/ko.php +++ b/modules/admin/lang/ko.php @@ -245,6 +245,7 @@ $lang->site_meta_keywords = 'SEO 키워드'; $lang->about_site_meta_keywords = '별도의 키워드를 지정하지 않은 페이지에서는 이 키워드 목록이 표시됩니다.'; $lang->site_meta_description = 'SEO 설명'; $lang->about_site_meta_description = '별도의 설명을 지정하지 않은 페이지에서는 이 설명이 표시됩니다.'; +$lang->twitter_enabled = '트위터 메타 태그 사용'; $lang->og_enabled = 'OpenGraph 태그 사용'; $lang->og_extract_description = '본문에서 설명 추출'; $lang->og_extract_description_fallback = '모듈 또는 사이트 전체 설명만 사용'; diff --git a/modules/admin/tpl/config_seo.html b/modules/admin/tpl/config_seo.html index d0004c903..68640f101 100644 --- a/modules/admin/tpl/config_seo.html +++ b/modules/admin/tpl/config_seo.html @@ -52,6 +52,13 @@ +