archives();
$this->attributes = $attributes;
if ( 'asc' === strtolower( $this->attributes['order'] ) ) {
$dateArchives = array_reverse( $dateArchives, true );
}
$data = [
'dateArchives' => $dateArchives,
'lines' => ''
];
foreach ( $dateArchives as $year => $months ) {
$data['lines'] .= $this->generateYearLine( $year, $months ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
ob_start();
aioseo()->templates->getTemplate( 'sitemap/html/compact-archive.php', $data );
$output = ob_get_clean();
if ( $echo ) {
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
return $output;
}
// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
/**
* Generates the HTML for a year line.
*
* @since 4.1.3
*
* @param int The year archive.
* @param array The month archives for the current year.
* @return string The HTML code for the year.
*/
protected function generateYearLine( $year, $months ) {
$html = '
' . esc_html( $year ) . ': ';
for ( $month = 1; $month <= 12; $month++ ) {
$html .= $this->generateMonth( $year, $months, $month );
}
$html .= '' . "\n";
return wp_kses_post( $html );
}
/**
* Generates the HTML for a month.
*
* @since 4.1.3
*
* @param int $year The year archive.
* @param array $months All month archives for the current year.
* @param int $month The month archive.
* @return string The HTML code for the month.
*/
public function generateMonth( $year, $months, $month ) {
$hasPosts = isset( $months[ $month ] );
$dummyDate = strtotime( "2009/${month}/25" );
$monthAbbrevation = date_i18n( 'M', $dummyDate );
$html = '' . esc_html( $monthAbbrevation ) . ' ';
if ( $hasPosts ) {
$noFollow = filter_var( $this->attributes['nofollow_links'], FILTER_VALIDATE_BOOLEAN );
$html = sprintf(
'%4$s ',
get_month_link( $year, $month ),
esc_attr( date_i18n( 'F Y', $dummyDate ) ),
$noFollow ? ' rel="nofollow"' : '',
esc_html( $monthAbbrevation )
);
}
return $html;
}
}