/** * Returns a list of date archives that can be included. * * @since 4.1.3 * * @return array The date archives. */ public function archives() { $result = aioseo()->core->db ->start( 'posts', false, 'SELECT DISTINCT' ) ->select( 'YEAR(post_date) AS year, MONTH(post_date) AS month' ) ->where( 'post_type', 'post' ) ->where( 'post_status', 'publish' ) ->whereRaw( "post_password=''" ) ->orderBy( '`year` DESC, `month` DESC' ) ->run() ->result(); $dates = []; foreach ( $result as $date ) { $dates[ $date->year ][ $date->month ] = 1; } return $dates; } /** * Returns the publish date for a given term. * This is the publish date of the oldest post that is assigned to the term. * * @since 4.1.3 * * @param int $termId The term ID. * @return int The publish date timestamp. */ public function getTermPublishDate( $termId ) { $termRelationshipsTable = aioseo()->core->db->db->prefix . 'term_relationships'; $post = aioseo()->core->db ->start( 'posts as p' ) ->select( 'MIN(`p`.`post_date_gmt`) as publish_date' ) ->whereRaw( " ( `p`.`ID` IN ( SELECT `tr`.`object_id` FROM `$termRelationshipsTable` as tr WHERE `tr`.`term_taxonomy_id` = '$termId' ) )" ) ->run() ->result(); return ! empty( $post[0]->publish_date ) ? strtotime( $post[0]->publish_date ) : 0; } /** * Returns a comma-separated string of excluded object IDs. * * @since 4.1.3 * * @param array $attributes The attributes. * @param boolean $posts Whether the objects are posts. * @return string The excluded object IDs. */ private function getExcludedObjects( $attributes, $posts = true ) { $excludedObjects = $posts ? aioseo()->sitemap->helpers->excludedPosts() : aioseo()->sitemap->helpers->excludedTerms(); $key = $posts ? 'excluded_posts' : 'excluded_terms'; if ( ! empty( $attributes[ $key ] ) ) { $ids = explode( ',', $excludedObjects ); $extraIds = []; if ( is_array( $attributes[ $key ] ) ) { $extraIds = $attributes[ $key ]; } if ( is_string( $attributes[ $key ] ) ) { $extraIds = array_map( 'trim', explode( ',', $attributes[ $key ] ) ); } $ids = array_filter( array_merge( $ids, $extraIds ), 'is_numeric' ); $excludedObjects = esc_sql( implode( ', ', $ids ) ); } return $excludedObjects; } }