esc_html__( 'Mini List - Left Thumb', 'aamla' ), 'list-r-m' => esc_html__( 'Mini List - Right Thumb', 'aamla' ), 'list-l-l' => esc_html__( 'Large List - Left Thumb', 'aamla' ), 'list-r-l' => esc_html__( 'Large List - Right Thumb', 'aamla' ), 'grid-default' => esc_html__( 'Default Grid', 'aamla' ), 'grid-t' => esc_html__( 'Only Thumb-Title Grid', 'aamla' ), 'only-content' => esc_html__( 'Only Full content', 'aamla' ), ]; return $styles; } /** * Register widget display posts entry classes. * * @param str $classes Comma separated entry posts classes. * @param array $instance Settings for the current widget instance. * @param Object $widget The widget instance. * @return str Entry posts classes. */ public function dp_classes( $classes, $instance, $widget ) { $classes .= ' index-view'; if ( in_array( $instance['styles'], [ 'grid-default', 'grid-t' ], true ) ) { $classes .= ' dp-grid'; } return $classes; } /** * Display widget content to front-end. * * @param array $args Widget display arguments. * @param array $instance Settings for the current widget instance. * @param Object $widget The widget instance. */ public function dp_entry( $args, $instance, $widget ) { $display = $this->get_style_args( $instance['styles'] ); if ( $display[0] ) { $this->title(); } if ( $display[1] ) { $this->meta( $display[1] ); } if ( $display[2] ) { $this->featured( $this->get_thumb_size( $instance['styles'] ) ); } if ( $display[3] ) { $this->main_content( $display[3] ); } } /** * Enqueue scripts and styles to front-end. * * @since 1.0.1 */ public function enqueue_front() { wp_enqueue_style( 'aamla_display_posts_style', get_template_directory_uri() . '/add-on/display-posts/assets/displayposts.css', [], false, 'all' ); wp_enqueue_script( 'aamla_display_posts_js', get_template_directory_uri() . '/add-on/display-posts/assets/displayposts.js', [], '1.0.0', true ); } /** * Enqueue scripts and styles to admin. * * @since 1.0.1 */ public function enqueue_admin() { $screen = get_current_screen(); if ( ! in_array( $screen->id, array( 'page', 'widgets', 'customize' ), true ) ) { return; } wp_enqueue_style( 'aamla_display_posts_admin_style', get_template_directory_uri() . '/add-on/display-posts/admin/displayposts.css', array(), false, 'all' ); wp_enqueue_script( 'aamla_display_posts_admin_js', get_template_directory_uri() . '/add-on/display-posts/admin/displayposts.js', [ 'jquery' ], '1.0.0', true ); } /** * Get args for displaying elements for specific dp style. * * @param str $style Style for this widget instance. * @return array */ public function get_style_args( $style ) { $t = true; $f = false; /* * Default element display instructions. * Instructions array to display particular entry element. * [ 'title', [ 'date', 'author' ], ['thumbnail'], [ 'title', [ 'date', 'author', 'category' ], 'excerpt', 'content' ] ] */ switch ( $style ) { case 'list-l-m': case 'list-r-m': $d = [ $f, $f, $t, [ $t, [ $t, $t, $f ], $f, $f ] ]; break; case 'list-l-l': case 'list-r-l': $d = [ $f, $f, $t, [ $t, [ $f, $f, $t ], $t, $f ] ]; break; case 'grid-default': $d = [ $f, $f, $t, [ $t, $f, $t, $f ] ]; break; case 'grid-t': $d = [ $f, $f, $t, [ $t, $f, $f, $f ] ]; break; case 'only-content': $d = [ $f, $f, $f, [ $f, $f, $f, $t ] ]; break; default: $d = [ $f, $f, $t, [ $t, [ $t, $t, $f ], $t, $f ] ]; } return apply_filters( 'aamla_dp_style_args', $d, $style ); } /** * Get post thumbnail size. * * @param str $style Style for this widget instance. * @return str */ public function get_thumb_size( $style ) { $thumb_size = 'aamla-medium'; if ( 'list-l-m' === $style || 'list-r-m' === $style ) { $thumb_size = 'thumbnail'; } return apply_filters( 'aamla_dp_thumb_size', $thumb_size, $style ); } /** * Display post entry title. * * @since 1.0.1 */ public function title() { if ( get_the_title() ) { the_title( sprintf( '
' ); } } /** * Display post entry meta. * * @since 1.0.1 * * @param array $instruct Date and author display instruction. */ public function meta( $instruct ) { $date = ''; $author = ''; if ( $instruct[0] ) { $date = sprintf( '', esc_attr( get_the_date( DATE_W3C ) ), esc_html( get_the_date( 'M j, Y' ) ) ); } if ( $instruct[1] ) { $author = sprintf( '', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_html( get_the_author_meta( 'display_name' ) ) ); } printf( '', $author, $date ); // WPCS xss ok. Contains HTML, other values escaped. } /** * Display post featured content. * * @since 1.0.1 * * @param str $size Thumbanil Size. */ public function featured( $size ) { if ( has_post_thumbnail() || aamla_get_mod( 'aamla_thumbnail_placeholder', 'none' ) ) { aamla_markup( 'dp-featured-content', [ [ [ $this, 'thumbnail' ], $size ], [ 'aamla_get_template_partial', 'template-parts/meta', 'meta-permalink' ], ] ); } } /** * Display post entry thumbnail. * * @since 1.0.1 * * @param str $size Thumbanil Size. */ public function thumbnail( $size ) { echo '