/** * Get the modification date for the last modified post in the post type: * * @param array $post_types Post types to get the last modification date for. * * @return string */ function get_last_modified($post_types) { global $wpdb; if (!is_array($post_types)) { $post_types = array($post_types); } // We need to do this only once, as otherwise we'd be doing a query for each post type. if (!is_array($this->post_type_dates)) { $this->post_type_dates = array(); $query = "SELECT post_type, MAX(post_modified_gmt) AS date FROM {$wpdb->posts} WHERE post_status IN ('publish','inherit') AND post_type IN ('" . implode("','", get_post_types(array('public' => true))) . "') GROUP BY post_type ORDER BY post_modified_gmt DESC"; $results = $wpdb->get_results($query); foreach ($results as $obj) { $this->post_type_dates[$obj->post_type] = $obj->date; } unset($query, $results, $obj); } if (count($post_types) === 1 && isset($this->post_type_dates[$post_types[0]])) { $result = $this->post_type_dates[$post_types[0]]; } else { $result = null; foreach ($post_types as $post_type) { if (isset($this->post_type_dates[$post_type]) && strtotime($this->post_type_dates[$post_type]) > $result) { $result = $this->post_type_dates[$post_type]; } } unset($post_type); } return $this->timezone->get_datetime_with_timezone($result); }
/** * 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); }
/** * Get the modification date for the last modified post in the post type. * * @param array $post_types Post types to get the last modification date for. * * @return string */ public function get_last_modified($post_types) { return $this->timezone->format_date(self::get_last_modified_gmt($post_types)); }