|string|null $type - private/public or array of index/follow/archtive,...
* @return string HTML
*/
public function metaRobots(array|string|null $type = null): string {
$meta = Configure::read('Config.robots');
if ($type === null && $meta !== null) {
$type = $meta;
}
if ($type === null) {
$type = ['noindex', 'nofollow', 'noarchive'];
}
if (is_array($type)) {
$robots = $type;
} elseif ($type === 'public') {
$robots = ['index', 'follow', 'noarchive'];
} else {
$robots = ['noindex', 'nofollow', 'noarchive'];
}
$return = '';
return $return;
}
/**
* Convenience method for clean meta name tags
*
* @param string|null $name Author, date, generator, revisit-after, language
* @param array|string|null $content If array, it will be separated by commas
* @return string HTML Markup
*/
public function metaName(?string $name = null, array|string|null $content = null): string {
if (!$name || !$content) {
return '';
}
$content = (array)$content;
$return = '';
return $return;
}
/**
* Convenience method for meta description
*
* @param string $content
* @param string|null $language (iso2: de, en-us, ...)
* @param array $options Additional options
* @return string HTML Markup
*/
public function metaDescription(string $content, ?string $language = null, array $options = []): string {
if ($language) {
$options['lang'] = mb_strtolower($language);
} elseif ($language !== false) {
$options['lang'] = Configure::read('Config.locale');
}
return $this->Html->meta('description', $content, $options);
}
/**
* Convenience method to output meta keywords
*
* @param array|string|null $keywords
* @param string|null $language (iso2: de, en-us, ...)
* @param bool $escape
* @return string HTML Markup
*/
public function metaKeywords(array|string|null $keywords = null, ?string $language = null, bool $escape = true): string {
if ($keywords === null) {
$keywords = Configure::read('Config.keywords');
}
if (is_array($keywords)) {
$keywords = implode(', ', $keywords);
}
if ($escape) {
$keywords = h($keywords);
}
$options = [];
if (!empty($language)) {
$options['lang'] = mb_strtolower($language);
} elseif ($language !== false) {
$options['lang'] = Configure::read('Config.locale');
}
return $this->Html->meta('keywords', $keywords, $options);
}
/**
* Convenience function for "canonical" SEO links
*
* @param array|string|null $url
* @param bool $full
* @return string HTML Markup
*/
public function metaCanonical(array|string|null $url = null, bool $full = false): string {
$canonical = $this->Url->build($url, ['fullBase' => $full]);
$options = ['rel' => 'canonical', 'link' => $canonical];
return $this->Html->meta($options);
}
/**
* Convenience method for "alternate" SEO links
*
* @param array|string|null $url
* @param array|string $lang (lang(iso2) or array of langs)
* lang: language (in ISO 6391-1 format) + optionally the region (in ISO 3166-1 Alpha 2 format)
* - de
* - de-ch
* etc
* @param bool $full
* @return string HTML Markup
*/
public function metaAlternate(array|string|null $url, array|string $lang, bool $full = false): string {
$url = $this->Url->build($url, ['fullBase' => $full]);
$lang = (array)$lang;
$res = [];
foreach ($lang as $language => $countries) {
if (is_numeric($language)) {
$language = '';
} else {
$language .= '-';
}
$countries = (array)$countries;
foreach ($countries as $country) {
$l = $language . $country;
$options = ['rel' => 'alternate', 'hreflang' => $l, 'link' => $url];
$res[] = $this->Html->meta($options) . PHP_EOL;
}
}
return implode('', $res);
}
/**
* Convenience method for META Tags
*
* @param array|string|null $url
* @param string|null $title
* @return string HTML Markup
*/
public function metaRss(array|string|null $url, ?string $title = null): string {
$tags = [
'meta' => '',
];
if (!$title) {
$title = __d('tools', 'Subscribe to this feed');
} else {
$title = h($title);
}
return sprintf($tags['meta'], $title, $this->Url->build($url));
}
/**
* Convenience method for meta tags.
*
* @param string $type
* @param string $value Content
* @param bool $escape
* @return string HTML Markup
*/
public function metaEquiv(string $type, string $value, bool $escape = true): string {
$tags = [
'meta' => '',
];
if ($escape) {
$value = h($value);
}
return sprintf($tags['meta'], $type, ' content="' . $value . '"');
}
}