/**
* Build the `<url>` tag for a given URL.
*
* Public access for backwards compatibility reasons.
*
* @param array $url Array of parts that make up this entry.
*
* @return string
*/
public function sitemap_url($url)
{
$date = null;
if (!empty($url['mod'])) {
// Create a DateTime object date in the correct timezone.
$date = $this->timezone->format_date($url['mod']);
}
$url['loc'] = htmlspecialchars($url['loc']);
$output = "\t<url>\n";
$output .= "\t\t<loc>" . $this->encode_url_rfc3986($url['loc']) . "</loc>\n";
$output .= empty($date) ? '' : "\t\t<lastmod>" . htmlspecialchars($date) . "</lastmod>\n";
$output .= "\t\t<changefreq>" . $url['chf'] . "</changefreq>\n";
$output .= "\t\t<priority>" . str_replace(',', '.', $url['pri']) . "</priority>\n";
if (empty($url['images'])) {
$url['images'] = array();
}
foreach ($url['images'] as $img) {
if (empty($img['src'])) {
continue;
}
$output .= "\t\t<image:image>\n";
$output .= "\t\t\t<image:loc>" . esc_html($this->encode_url_rfc3986($img['src'])) . "</image:loc>\n";
if (!empty($img['title'])) {
$title = $img['title'];
if ($this->needs_conversion) {
$title = mb_convert_encoding($title, $this->output_charset, $this->charset);
}
$title = _wp_specialchars(html_entity_decode($title, ENT_QUOTES, $this->output_charset));
$output .= "\t\t\t<image:title><![CDATA[{$title}]]></image:title>\n";
}
if (!empty($img['alt'])) {
$alt = $img['alt'];
if ($this->needs_conversion) {
$alt = mb_convert_encoding($alt, $this->output_charset, $this->charset);
}
$alt = _wp_specialchars(html_entity_decode($alt, ENT_QUOTES, $this->output_charset));
$output .= "\t\t\t<image:caption><![CDATA[{$alt}]]></image:caption>\n";
}
$output .= "\t\t</image:image>\n";
}
unset($img, $title, $alt);
$output .= "\t</url>\n";
/**
* Filters the output for the sitemap url tag.
*
* @api string $output The output for the sitemap url tag.
*
* @param array $url The sitemap url array on which the output is based.
*/
return apply_filters('wpseo_sitemap_url', $output, $url);
}