Browse Source

Add title formats settings

pull/700/head
danpros 1 year ago
parent
commit
59645f6b06
4 changed files with 208 additions and 11 deletions
  1. +16
    -0
      config/config.ini.example
  2. +136
    -0
      system/admin/views/config-metatags.html.php
  3. +12
    -0
      system/configList.json
  4. +44
    -11
      system/includes/functions.php

+ 16
- 0
config/config.ini.example View File

@ -164,6 +164,22 @@ toc.automatic = "false"
; Automatically insert the TOC after x paragraph
toc.position = "1"
; Title formats
home.title.format = "%blog_title% - %blog_tagline%"
post.title.format = "%post_title% - %blog_title%"
page.title.format = "%page_title% - %blog_title%"
category.title.format = "%category_title% - %blog_title%"
tag.title.format = "%tag_title% - %blog_title%"
archive.title.format = "%archive_title% - %blog_title%"
search.title.format = "%search_title% - %blog_title%"
type.title.format = "%type_title% - %blog_title%"
profile.title.format = "%author_name% - %blog_title%"
blog.title.format = "Blog - %blog_title%"
default.title.format = "%page_title% - %blog_title%"
; Default image for Open Graph
default.image = ""
; Set the theme here
views.root = "themes/twentysixteen"


+ 136
- 0
system/admin/views/config-metatags.html.php View File

@ -5,6 +5,52 @@ $array = array();
if (file_exists($config_file)) {
$array = parse_ini_file($config_file, true);
}
$homeFormat = config('home.title.format');
if (empty($homeFormat)) {
$homeFormat = '%blog_title% - %blog_tagline%';
}
$postFormat = config('post.title.format');
if (empty($postFormat)) {
$postFormat = '%post_title% - %blog_title%';
}
$pageFormat = config('page.title.format');
if (empty($pageFormat)) {
$pageFormat = '%page_title% - %blog_title%';
}
$categoryFormat = config('category.title.format');
if (empty($categoryFormat)) {
$categoryFormat = '%category_title% - %blog_title%';
}
$tagFormat = config('tag.title.format');
if (empty($tagFormat)) {
$tagFormat = '%tag_title% - %blog_title%';
}
$searchFormat = config('search.title.format');
if (empty($searchFormat)) {
$searchFormat = '%search_title% - %blog_title%';
}
$archiveFormat = config('archive.title.format');
if (empty($archiveFormat)) {
$archiveFormat = '%archive_title% - %blog_title%';
}
$typeFormat = config('type.title.format');
if (empty($typeFormat)) {
$typeFormat = '%type_title% - %blog_title%';
}
$blogFormat = config('blog.title.format');
if (empty($blogFormat)) {
$blogFormat = 'Blog - %blog_title%';
}
$profileFormat = config('profile.title.format');
if (empty($profileFormat)) {
$profileFormat = '%author_name% - %blog_title%';
}
$defaultFormat = config('default.title.format');
if (empty($defaultFormat)) {
$defaultFormat = '%page_title% - %blog_title%';
}
?>
<h2><?php echo i18n('Metatags_Settings');?></h2>
<br>
@ -21,6 +67,96 @@ if (file_exists($config_file)) {
<br><br>
<form method="POST">
<input type="hidden" name="csrf_token" value="<?php echo get_csrf(); ?>">
<div class="form-group row">
<label for="default.image" class="col-sm-2 col-form-label"><?php echo i18n('default');?> Image</label>
<div class="col-sm-10">
<input type="text" name="-config-default.image" class="form-control" id="default.image" value="<?php echo config('default.image');?>" placeholder="<?php echo site_url();?>resources/images/logo-big.png">
</div>
</div>
<br>
<h4>Title formats</h4>
<hr>
<style>.title-format {margin-top:5px;font-size:95%} .title-format code {display:inline-block;margin-left:10px; margin-bottom:5px;color: #333; background: #fbf7f0; padding: 5px; border-radius: .25rem; border: 1px solid #e4e4e4;}</style>
<div class="form-group row">
<label for="home.title.format" class="col-sm-2 col-form-label"><?php echo i18n('home');?></label>
<div class="col-sm-10">
<input type="text" name="-config-home.title.format" class="form-control" id="home.title.format" value="<?php echo $homeFormat;?>" placeholder="%blog_title% - %blog_tagline%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="post.title.format" class="col-sm-2 col-form-label"><?php echo i18n('posts');?></label>
<div class="col-sm-10">
<input type="text" name="-config-post.title.format" class="form-control" id="post.title.format" value="<?php echo $postFormat;?>" placeholder="%post_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%post_title%</code> <code>%post_description%</code> <code>%post_category%</code> <code>%post_tag%</code> <code>%post_author%</code> <code>%post_type%</code></p>
</div>
</div>
<div class="form-group row">
<label for="page.title.format" class="col-sm-2 col-form-label"><?php echo i18n('static_page');?></label>
<div class="col-sm-10">
<input type="text" name="-config-page.title.format" class="form-control" id="page.title.format" value="<?php echo $pageFormat;?>" placeholder="%page_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%page_title%</code> <code>%page_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="category.title.format" class="col-sm-2 col-form-label"><?php echo i18n('category');?></label>
<div class="col-sm-10">
<input type="text" name="-config-category.title.format" class="form-control" id="category.title.format" value="<?php echo $categoryFormat;?>" placeholder="%category_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%category_title%</code> <code>%category_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="tag.title.format" class="col-sm-2 col-form-label"><?php echo i18n('tag');?></label>
<div class="col-sm-10">
<input type="text" name="-config-tag.title.format" class="form-control" id="tag.title.format" value="<?php echo $tagFormat;?>" placeholder="%tag_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%tag_title%</code> <code>%tag_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="archive.title.format" class="col-sm-2 col-form-label"><?php echo i18n('archives');?></label>
<div class="col-sm-10">
<input type="text" name="-config-archive.title.format" class="form-control" id="archive.title.format" value="<?php echo $archiveFormat;?>" placeholder="%archive_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%archive_title%</code> <code>%archive_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="search.title.format" class="col-sm-2 col-form-label"><?php echo i18n('search');?></label>
<div class="col-sm-10">
<input type="text" name="-config-search.title.format" class="form-control" id="search.title.format" value="<?php echo $searchFormat;?>" placeholder="%search_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%search_title%</code> <code>%search_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="type.title.format" class="col-sm-2 col-form-label">Type</label>
<div class="col-sm-10">
<input type="text" name="-config-type.title.format" class="form-control" id="type.title.format" value="<?php echo $typeFormat;?>" placeholder="%type_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%type_title%</code> <code>%type_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="profile.title.format" class="col-sm-2 col-form-label"><?php echo i18n('author');?></label>
<div class="col-sm-10">
<input type="text" name="-config-profile.title.format" class="form-control" id="profile.title.format" value="<?php echo $profileFormat;?>" placeholder="%author_name% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%author_name%</code> <code>%author_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="blog.title.format" class="col-sm-2 col-form-label">Blog</label>
<div class="col-sm-10">
<input type="text" name="-config-blog.title.format" class="form-control" id="blog.title.format" value="<?php echo $blogFormat;?>" placeholder="Blog - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code></p>
</div>
</div>
<div class="form-group row">
<label for="default.title.format" class="col-sm-2 col-form-label"><?php echo i18n('default');?></label>
<div class="col-sm-10">
<input type="text" name="-config-default.title.format" class="form-control" id="default.title.format" value="<?php echo $defaultFormat;?>" placeholder="%page_title% - %blog_title%">
<p class="title-format">Available shortcode: <code>%blog_title%</code> <code>%blog_tagline%</code> <code>%blog_description%</code> <code>%page_title%</code></p>
</div>
</div>
<br>
<h4>Miscellaneous</h4>
<hr>
<div class="form-group row">
<label class="col-sm-2 col-form-label"><?php echo i18n('Permalink');?></label>
<div class="col-sm-10">


+ 12
- 0
system/configList.json View File

@ -72,6 +72,18 @@
"toc.style",
"toc.automatic",
"toc.position",
"home.title.format",
"post.title.format",
"page.title.format",
"category.title.format",
"tag.title.format",
"archive.title.format",
"search.title.format",
"type.title.format",
"profile.title.format",
"blog.title.format",
"default.title.format",
"default.image",
"views.root",
"views.layout"
]

+ 44
- 11
system/includes/functions.php View File

@ -3714,57 +3714,90 @@ function automatic_toc($content, $id)
function generate_title($type = null, $object = null)
{
if ($type == 'is_front') {
$format = '%blog_title% - %blog_tagline%';
$format = config('home.title.format');
if (empty($format)) {
$format = '%blog_title% - %blog_tagline%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description());
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_post') {
$format = '%post_title% - %blog_title%';
$format = config('post.title.format');
if (empty($format)) {
$format = '%post_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%post_title%' => $object->title, '%post_description%' => $object->description, '%post_category%' => $object->categoryTitle, '%post_tag%' => $object->tag, '%post_author%' => $object->authorName, '%post_type%' => ucfirst($object->type));
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_page' || $type == 'is_subpage') {
$format = '%page_title% - %blog_title%';
$format = config('page.title.format');
if (empty($format)) {
$format = '%page_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%page_title%' => $object->title, '%page_description%' => $object->description);
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_profile') {
$format = '%author_name% - %blog_title%';
$format = config('profile.title.format');
if (empty($format)) {
$format = '%author_name% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%author_name%' => $object->title, '%author_description%' => $object->description);
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_category') {
$format = '%category_title% - %blog_title%';
$format = config('category.title.format');
if (empty($format)) {
$format = '%category_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%category_title%' => $object->title, '%category_description%' => $object->description);
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_tag') {
$format = '%tag_title% - %blog_title%';
$format = config('tag.title.format');
if (empty($format)) {
$format = '%tag_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%tag_title%' => $object->title, '%tag_description%' => $object->description);
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_archive') {
$format = '%archive_title% - %blog_title%';
$format = config('archive.title.format');
if (empty($format)) {
$format = '%archive_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%archive_title%' => $object->title, '%archive_description%' => $object->description);
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_search') {
$format = '%search_title% - %blog_title%';
$format = config('search.title.format');
if (empty($format)) {
$format = '%search_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%search_title%' => $object->title, '%search_description%' => $object->description);
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_type') {
$format = '%type_title% - %blog_title%';
$format = config('type.title.format');
if (empty($format)) {
$format = '%type_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%type_title%' => $object->title, '%type_description%' => $object->description);
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_blog') {
$format = 'Blog - %blog_title%';
$format = config('blog.title.format');
if (empty($format)) {
$format = 'Blog - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description());
$var = strtr($format, $var_map);
return strip_tags($var);
} elseif ($type == 'is_default') {
$format = '%page_title% - %blog_title%';
$format = config('default.title.format');
if (empty($format)) {
$format = '%page_title% - %blog_title%';
}
$var_map = array('%blog_title%' => blog_title(), '%blog_tagline%' => blog_tagline(), '%blog_description%' => blog_description(), '%page_title%' => $object);
$var = strtr($format, $var_map);
return strip_tags($var);


Loading…
Cancel
Save