attributes = $attributes;
$this->settings = $settings;
$this->active_year = '';
}
/**
* Renders the timeline Single Story.
*
* @param int $index Index value of current post.
* @param object $post Current Post object.
*
* @since 0.0.1
*/
public function ctl_render( $index, $post ) {
$output = '';
$post_id = absint( is_object( $post ) && isset( $post->ID ) ? $post->ID : get_the_ID() );
if ( $post_id <= 0 ) {
return '';
}
$classes = array( 'ctl-story' );
$attributes = $this->attributes;
$layout = $attributes['layout'];
$animation = 'horizontal' === $layout ? 'none' : $attributes['config']['animation'];
$icons_disabled = isset( $attributes['icons'] ) && 'no' === strtolower( $attributes['icons'] );
if ( $icons_disabled ) {
$classes[] = 'ctl-story-dot-icon';
} else {
$classes[] = 'ctl-story-icon';
};
if ( 'horizontal' === $layout ) {
$classes[] = 'swiper-slide';
$classes[] = 0 === $index % 2 ? 'even' : 'odd';
} else {
// dynamic alternate class.
$condition = 0 === $index % 2;
$classes[] = $condition ? 'even' : 'odd';
if ( isset( $this->settings['first_story_position'] ) && 'left' === $this->settings['first_story_position'] ) {
$condition = 0 !== $index % 2;
}
if ( $condition ) {
$classes[] = 'one-side' !== $this->attributes['layout'] ? 'ctl-story-left' : 'ctl-story-right';
} else {
$classes[] = 'ctl-story-right';
}
}
// Get Year label.
if ( $this->settings['year_label'] && ( 'one-side' === $layout || 'default' === $layout ) ) {
$output .= $this->ctl_get_year_label( $post_id );
}
$output .= '
';
if ( 'compact' !== $layout ) {
$output .= $this->ctl_get_date( $post_id, $attributes['date-format'] );
}
if ( $icons_disabled ) {
$output .= '
';
} else {
$output .= '' . $this->ctl_get_icon( $post_id );
}
if ( 'compact' === $layout || 'horizontal' === $layout || 'clean' !== $attributes['skin'] ) {
$output .= '
';
}
$output .= '
';
$output .= $this->ctl_get_title( $post_id );
// Grabing story content based upon content type.
if ( 'horizontal' !== $layout ) {
$output .= $this->ctl_get_featured_image( $post_id );
}
if ( 'compact' === $layout ) {
$output .= $this->ctl_get_date( $post_id, $attributes['date-format'] );
}
if ( 'horizontal' !== $layout ) {
$output .= $this->ctl_get_content();
}
$output .= '
';
if ( 'horizontal' === $layout ) {
$output .= $this->ctl_minimal_content();
}
$output .= '
';
return $output;
}
/**
* Get Story Title
*
* @param int $post_id Current Post ID.
*/
public function ctl_get_title( $post_id ) {
$output = '';
if ( ! empty( get_the_title() ) ) {
$layout = $this->attributes['layout'];
$title_class = 'story-' . $post_id;
$re_more = ( ( isset( $this->settings['display_readmore'] ) && 'yes' === $this->settings['display_readmore'] ) || 'horizontal' === $layout );
$output .= '';
$output .= $re_more ? $this->get_story_link( $post_id ) : '';
$output .= esc_html( get_the_title( $post_id ) );
$output .= $re_more ? '' : '';
if ( ( isset( $this->settings['display_readmore'] ) && 'yes' === $this->settings['display_readmore'] ) && 'horizontal' === $layout ) {
$output .= $re_more ? $this->get_story_link( $post_id ) : '';
$output .= '
' . __( 'Read More', 'cool-timeline' ) . '
';
$output .= $re_more ? '' : '';
}
$output .= '
';
}
return $output;
}
/**
* Get Timeline Story links
*
* @param int $post_id Current Post ID.
*/
public function get_story_link( $post_id ) {
$attributes = $this->attributes;
$story_link = '';
$url = '';
// Get custom link settings.
if ( 'horizontal' === $attributes['layout'] ) {
$story_link = '';
}
return $story_link;
}
/**
* Get Story Date
*
* @param int $post_id Current Post ID.
* @param string $date_formats Timeline date format.
* @return string Formatted date HTML output.
*/
public function ctl_get_date( $post_id, $date_formats ) {
$ctl_story_type = get_post_meta( $post_id, 'story_type', true );
$ctl_story_date = '';
if ( is_array( $ctl_story_type ) && isset( $ctl_story_type['ctl_story_date'] ) ) {
$ctl_story_date = $ctl_story_type['ctl_story_date'];
}
$layout = $this->attributes['layout'];
$re_more = ( ( isset( $this->settings['display_readmore'] ) && 'yes' === $this->settings['display_readmore'] ) && 'horizontal' === $layout );
$output = '';
$posted_date = '';
if ( $ctl_story_date ) {
if ( strtotime( $ctl_story_date ) !== false ) {
$posted_date = date_i18n( $date_formats, strtotime( $ctl_story_date ) );
} else {
$ctl_story_date = trim( str_ireplace( array( 'am', 'pm' ), '', $ctl_story_date ) );
$dateobj = DateTime::createFromFormat( 'm/d/Y H:i', $ctl_story_date, wp_timezone() );
if ( $dateobj ) {
$posted_date = $dateobj->format( $date_formats );
}
}
if ( ! empty( $posted_date ) ) {
$output .= '';
$output .= '
';
$output .= $re_more ? $this->get_story_link( $post_id ) : '';
$output .= esc_html( $posted_date ); // Escape date output
$output .= $re_more ? '' : '';
$output .= '
';
$output .= '
';
}
}
return $output;
}
/**
* Get stories content
*/
public function ctl_get_content() {
$attributes = $this->attributes;
$output = '';
$content = '';
if ( 'full' === $attributes['story-content'] ) {
global $post;
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$content .= apply_filters( 'the_content', $post->post_content );
} else {
$content .= CTL_Helpers::ctl_get_excerpt( $this->settings );
}
if ( ! empty( $content ) ) {
// Remove non-http/https iframe src URLs.
$content = preg_replace_callback(
'#