sp($singular, $pural, $count, $autoTranslate); } /** * Manual pluralizing a word using the Inflection class * //TODO: move to lib or bootstrap * * @param string $singular * @param string $plural * @param int $count * @param bool $autoTranslate * @return string result */ public function sp($singular, $plural, $count, $autoTranslate = false) { if ((int)$count !== 1) { $result = $plural; } else { $result = $singular; } if ($autoTranslate) { $result = __($result); } return $result; } /** * Convenience method for clean ROBOTS allowance * * @param string|null $type - private/public * @return string HTML */ public function metaRobots($type = null) { if ($type === null && ($meta = Configure::read('Config.robots')) !== null) { $type = $meta; } $content = []; if ($type === 'public') { $this->privatePage = false; $content['robots'] = ['index', 'follow', 'noarchive']; } else { $this->privatePage = true; $content['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 mixed|null $content If array, it will be separated by commas * @return string HTML Markup */ public function metaName($name = null, $content = null) { if (empty($name) || empty($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($content, $language = null, $options = []) { if (!empty($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 string|array|null $keywords * @param string|null $language (iso2: de, en-us, ...) * @param bool $escape * @return string HTML Markup */ public function metaKeywords($keywords = null, $language = null, $escape = true) { 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 mixed $url * @param bool $full * @return string HTML Markup */ public function metaCanonical($url = null, $full = false) { $canonical = $this->Url->build($url, $full); $options = ['rel' => 'canonical', 'link' => $canonical]; return $this->Html->meta($options); } /** * Convenience method for "alternate" SEO links * * @param mixed $url * @param mixed $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($url, $lang, $full = false) { //$canonical = $this->Url->build($url, $full); $url = $this->Url->build($url, $full); //return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null)); $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 mixed $url * @param string|null $title * @return string HTML Markup */ public function metaRss($url, $title = null) { $tags = [ 'meta' => '', ]; if (empty($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($type, $value, $escape = true) { $tags = [ 'meta' => '', ]; if ($value === null) { return ''; } if ($escape) { $value = h($value); } return sprintf($tags['meta'], $type, ' content="' . $value . '"'); } }