Add options to customize the browser title format

This commit is contained in:
Kijin Sung 2016-05-09 22:39:19 +09:00
parent f25e685209
commit 9bdc30b325
11 changed files with 79 additions and 18 deletions

View file

@ -863,14 +863,21 @@ class Context
* Set string to browser title
*
* @param string $site_title Browser title to be set
* @param array $vars
* @return void
*/
public static function setBrowserTitle($title)
public static function setBrowserTitle($title, $vars = array())
{
if(!$title)
if (!$title)
{
return;
}
if (count($vars))
{
$title = preg_replace_callback('/\\$(\w+)/', function($matches) use($vars) {
return isset($vars[strtolower($matches[1])]) ? $vars[strtolower($matches[1])] : $matches[0];
}, $title);
}
self::$_instance->site_title = $title;
}

View file

@ -287,15 +287,21 @@ class ModuleHandler extends Handler
$this->module_info = $module_info;
if ($module_info->mid == $site_module_info->mid)
{
Context::setBrowserTitle(Context::getSiteTitle());
Context::addBrowserTitle(Context::getSiteSubtitle());
$seo_title = config('seo.main_title') ?: '$SITE_TITLE - $SITE_SUBTITLE';
}
else
{
Context::setBrowserTitle(Context::getSiteTitle());
Context::addBrowserTitle($module_info->browser_title);
$seo_title = config('seo.subpage_title') ?: '$SITE_TITLE - $SUBPAGE_TITLE';
}
getController('module')->replaceDefinedLangCode($seo_title);
Context::setBrowserTitle($seo_title, array(
'site_title' => Context::getSiteTitle(),
'site_subtitle' => Context::getSiteSubtitle(),
'subpage_title' => $module_info->browser_title,
'page' => Context::get('page') ?: 1,
));
$module_config = $oModuleModel->getModuleConfig('module');
if ($module_info->meta_keywords)
{

View file

@ -99,6 +99,9 @@ return array(
'allow' => array(),
),
'seo' => array(
'main_title' => '',
'subpage_title' => '',
'document_title' => '',
'og_enabled' => false,
'og_extract_description' => false,
'og_extract_images' => false,

View file

@ -784,6 +784,10 @@ class adminAdminController extends admin
$oModuleController = getController('module');
$oModuleController->updateModuleConfig('module', $args);
Rhymix\Framework\Config::set('seo.main_title', trim(utf8_normalize_spaces($vars->seo_main_title)));
Rhymix\Framework\Config::set('seo.subpage_title', trim(utf8_normalize_spaces($vars->seo_subpage_title)));
Rhymix\Framework\Config::set('seo.document_title', trim(utf8_normalize_spaces($vars->seo_document_title)));
Rhymix\Framework\Config::set('seo.og_enabled', $vars->og_enabled === 'Y');
Rhymix\Framework\Config::set('seo.og_extract_description', $vars->og_extract_description === 'Y');
Rhymix\Framework\Config::set('seo.og_extract_images', $vars->og_extract_images === 'Y');

View file

@ -576,6 +576,11 @@ class adminAdminView extends admin
Context::set('site_meta_keywords', escape($config->meta_keywords));
Context::set('site_meta_description', escape($config->meta_description));
// Titles
Context::set('seo_main_title', escape(Rhymix\Framework\Config::get('seo.main_title') ?: '$SITE_TITLE - $SITE_SUBTITLE'));
Context::set('seo_subpage_title', escape(Rhymix\Framework\Config::get('seo.subpage_title') ?: '$SITE_TITLE - $SUBPAGE_TITLE'));
Context::set('seo_document_title', escape(Rhymix\Framework\Config::get('seo.document_title') ?: '$SITE_TITLE - $DOCUMENT_TITLE'));
// OpenGraph metadata
Context::set('og_enabled', Rhymix\Framework\Config::get('seo.og_enabled'));
Context::set('og_extract_description', Rhymix\Framework\Config::get('seo.og_extract_description'));

View file

@ -143,6 +143,12 @@ $lang->debug_log_filename = 'Log filename';
$lang->about_debug_log_filename = 'YYYYMMDD in the filename will be replaced with the current date.<br>It is recommended to split the log file by date to prevent it from getting too large.';
$lang->msg_debug_log_filename_not_writable = 'Rhymix cannot write log files in the specified path.';
$lang->debug_allowed_ip = 'Allowed IP addresses';
$lang->seo_main_title = 'Main Page Title';
$lang->about_seo_main_title = 'This format will be used for the title of the main page.<br>The following variables are available: <b>$SITE_TITLE</b>, <b>$SITE_SUBTITLE</b>, <b>$SUBPAGE_TITLE</b>.';
$lang->seo_subpage_title = 'Subpage Title';
$lang->about_seo_subpage_title = 'This format will be used for the title of lists and other major components of your website.<br>In additions to the variables above, you can use <b>$PAGE</b>.';
$lang->seo_document_title = 'Document Page Title';
$lang->about_seo_document_title = 'This format will be used for the title of individual documents.<br>In additions to the variables above, you can use <b>$DOCUMENT_TITLE</b>.';
$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';

View file

@ -146,6 +146,12 @@ $lang->debug_log_filename = '디버그 정보 기록 파일';
$lang->about_debug_log_filename = '파일명에 YYYYMMDD가 포함된 경우 날짜별로 파일을 분리하여 기록합니다.<br>파일을 분리하지 않으면 용량이 매우 커질 수 있으니 주의하십시오.';
$lang->msg_debug_log_filename_not_writable = '지정한 경로에 로그 파일을 작성할 수 없습니다.';
$lang->debug_allowed_ip = '디버그 허용 IP';
$lang->seo_main_title = '메인화면 제목';
$lang->about_seo_main_title = '사이트 메인 화면에 표시되는 제목 형태입니다. 아래와 같은 변수를 사용할 수 있습니다.<br><b>$SITE_TITLE</b> (사이트 제목), <b>$SITE_SUBTITLE</b> (사이트 부제목), <b>$SUBPAGE_TITLE</b> (서브페이지 제목)';
$lang->seo_subpage_title = '서브페이지 제목';
$lang->about_seo_subpage_title = '문서 목록, 페이지 등 주요 메뉴를 방문하면 표시되는 제목 형태입니다. 위의 변수들과 함께 <b>$PAGE</b> (페이지)도 사용할 수 있습니다.';
$lang->seo_document_title = '개별 문서 페이지 제목';
$lang->about_seo_document_title = '게시물을 읽는 화면에서 표시되는 제목 형태입니다. 위에 변수들과 함께 <b>$DOCUMENT_TITLE</b> (문서 제목)도 사용할 수 있습니다.';
$lang->site_meta_keywords = 'SEO 키워드';
$lang->about_site_meta_keywords = '별도의 키워드를 지정하지 않은 페이지에서는 이 키워드 목록이 표시됩니다.';
$lang->site_meta_description = 'SEO 설명';

View file

@ -7,6 +7,27 @@
<input type="hidden" name="module" value="admin" />
<input type="hidden" name="act" value="procAdminUpdateSEO" />
<input type="hidden" name="xe_validator_id" value="modules/admin/tpl/config_seo/1" />
<div class="x_control-group">
<label class="x_control-label" for="seo_main_title">{$lang->seo_main_title}</label>
<div class="x_controls">
<input type="text" name="seo_main_title" id="seo_main_title" value="{$seo_main_title}" style="min-width: 80%" class="lang_code" />
<p class="x_help-block">{$lang->about_seo_main_title}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label" for="seo_subpage_title">{$lang->seo_subpage_title}</label>
<div class="x_controls">
<input type="text" name="seo_subpage_title" id="seo_subpage_title" value="{$seo_subpage_title}" style="min-width: 80%" class="lang_code" />
<p class="x_help-block">{$lang->about_seo_subpage_title}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label" for="seo_document_title">{$lang->seo_document_title}</label>
<div class="x_controls">
<input type="text" name="seo_document_title" id="seo_document_title" value="{$seo_document_title}" style="min-width: 80%" class="lang_code" />
<p class="x_help-block">{$lang->about_seo_document_title}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label" for="site_meta_keywords">{$lang->site_meta_keywords}</label>
<div class="x_controls">

View file

@ -1627,7 +1627,7 @@ jQuery(function($){
$textareas.each(function(){
var $this = $(this);
var value = data.langs[$this.data('lang')];
var pattern = /^\$user_lang->/;
var pattern = /^\$user_lang-(?:>|&(?:amp;)?gt;)/;
if(pattern.test(value)){
$this.val('').data('value', '');
@ -1911,7 +1911,7 @@ jQuery(function($){
//var $displayInput = $this.siblings('.lang_code');
if($displayInput.data('active')){
$multilingualWindow.trigger('before-open.g11n', $displayInput.prev('.lang_code').val().replace('$user_lang->', ''));
$multilingualWindow.trigger('before-open.g11n', $displayInput.prev('.lang_code').val().replace(/\$user_lang-(?:>|&(?:amp;)?gt;)/, ''));
}else{
$multilingualWindow.trigger('before-open.g11n');
}
@ -1964,7 +1964,7 @@ jQuery(function($){
// load value
function loadValue(){
reset();
var pattern = /^\$user_lang->/;
var pattern = /^\$user_lang-(?:>|&(?:amp;)?gt;)/;
function on_complete2(data){
if(!data || !data.langs) return;
@ -1977,7 +1977,7 @@ jQuery(function($){
if(pattern.test($displayInput.val())){
$.exec_json('module.getModuleAdminLangCode', {
'name': $displayInput.val().replace('$user_lang->', ''),
'name': $displayInput.val().replace(pattern, ''),
'mid': current_url.getQuery('mid')
}, on_complete2);
}

View file

@ -317,7 +317,16 @@ class boardView extends board
else
{
// add the document title to the browser
Context::addBrowserTitle($oDocument->getTitleText());
Context::setCanonicalURL($oDocument->getPermanentUrl());
$seo_title = config('seo.document_title') ?: '$SITE_TITLE - $DOCUMENT_TITLE';
getController('module')->replaceDefinedLangCode($seo_title);
Context::setBrowserTitle($seo_title, array(
'site_title' => Context::getSiteTitle(),
'site_subtitle' => Context::getSiteSubtitle(),
'subpage_title' => $module_info->browser_title,
'document_title' => $oDocument->getTitleText(),
'page' => Context::get('page') ?: 1,
));
// update the document view count (if the document is not secret)
if(!$oDocument->isSecret() || $oDocument->isGranted())
@ -338,12 +347,6 @@ class boardView extends board
// setup the document oject on context
$oDocument->add('module_srl', $this->module_srl);
Context::set('oDocument', $oDocument);
// set canonical URL
if ($oDocument->document_srl)
{
Context::setCanonicalURL($oDocument->getPermanentUrl());
}
/**
* add javascript filters

View file

@ -1073,7 +1073,7 @@ class moduleController extends module
{
if($isReplaceLangCode)
{
$output = preg_replace_callback('!\$user_lang-(?:>|&(?:amp;)?gt;)([a-z0-9\_]+)!is', array($this,'_replaceLangCode'), $output);
$output = preg_replace_callback('!\$user_lang->([a-z0-9\_]+)!is', array($this,'_replaceLangCode'), $output);
}
}