format_date() public method

Format arbitrary UTC datetime string to desired form in site's time zone.
public format_date ( string $datetime_string, string $format = 'c' ) : string
$datetime_string string The input datetime string in UTC time zone.
$format string Date format to use.
return string
 /**
  * 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);
 }
Beispiel #2
0
 /**
  * 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));
 }