78 lines
3.0 KiB
PHP
78 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* Project Card Component
|
|
*
|
|
* Renders one project card. Used by front-page (Recent Projects) and
|
|
* archive-projects. Expects $post (WP_Post) in scope.
|
|
*
|
|
* @package KsPortfolio
|
|
*/
|
|
|
|
namespace KsPortfolio;
|
|
|
|
if ( ! isset( $post ) || ! ( $post instanceof \WP_Post ) ) {
|
|
return;
|
|
}
|
|
|
|
$project_id = (int) $post->ID;
|
|
$type_label = '';
|
|
$type_terms = get_the_terms( $project_id, 'project-type' );
|
|
if ( ! empty( $type_terms ) && ! is_wp_error( $type_terms ) ) {
|
|
$type_label = strtoupper( $type_terms[0]->name );
|
|
}
|
|
$release_url = Projects::get_release_url( $project_id );
|
|
$repo_url = Projects::get_repo_browse_url( $project_id );
|
|
$repo_data = Projects::get_repo_data( $project_id );
|
|
$language = is_array( $repo_data ) && ! empty( $repo_data['language'] ) ? (string) $repo_data['language'] : '';
|
|
$stars = is_array( $repo_data ) && isset( $repo_data['stargazers_count'] ) ? (int) $repo_data['stargazers_count'] : 0;
|
|
$excerpt = has_excerpt( $project_id ) ? get_the_excerpt( $project_id ) : wp_trim_words( wp_strip_all_tags( $post->post_content ), 30, '…' );
|
|
$card_classes = 'project-card group';
|
|
?>
|
|
|
|
<article class="<?php echo esc_attr( $card_classes ); ?>" aria-labelledby="project-<?php echo esc_attr( (string) $project_id ); ?>-title">
|
|
<header class="project-card__head">
|
|
<?php if ( $type_label ) : ?>
|
|
<span class="project-card__type"><?php echo esc_html( $type_label ); ?></span>
|
|
<?php endif; ?>
|
|
<span class="project-card__provider" aria-hidden="true">
|
|
<?php echo esc_html( Projects::get_provider_label( $project_id ) ); ?>
|
|
</span>
|
|
</header>
|
|
|
|
<h3 id="project-<?php echo esc_attr( (string) $project_id ); ?>-title" class="project-card__title">
|
|
<a class="project-card__title-link" href="<?php echo esc_url( get_permalink( $project_id ) ); ?>">
|
|
<?php echo esc_html( get_the_title( $project_id ) ); ?>
|
|
</a>
|
|
</h3>
|
|
|
|
<?php if ( $excerpt ) : ?>
|
|
<p class="project-card__excerpt"><?php echo esc_html( $excerpt ); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<footer class="project-card__foot">
|
|
<?php if ( $language || $stars > 0 ) : ?>
|
|
<div class="project-card__meta">
|
|
<?php if ( $language ) : ?>
|
|
<span class="project-card__lang"><?php echo esc_html( $language ); ?></span>
|
|
<?php endif; ?>
|
|
<?php if ( $stars > 0 ) : ?>
|
|
<span class="project-card__stars" aria-label="<?php echo esc_attr( $stars . ' stars' ); ?>">★ <?php echo esc_html( (string) $stars ); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="project-card__actions">
|
|
<?php if ( $release_url ) : ?>
|
|
<a class="project-card__action project-card__action--primary" href="<?php echo esc_url( Projects::get_download_url( $project_id ) ); ?>" rel="nofollow">
|
|
<?php echo esc_html__( 'Download', 'ks-portfolio' ); ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php if ( $repo_url ) : ?>
|
|
<a class="project-card__action project-card__action--secondary" href="<?php echo esc_url( $repo_url ); ?>" target="_blank" rel="noopener noreferrer">
|
|
<?php echo esc_html__( 'View Repo', 'ks-portfolio' ); ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</footer>
|
|
</article>
|