'widget_portfolio_recently_viewed',
'description' => __( 'Display a list of recently viewed portfolio items.', 'a3-portfolio' )
);
parent::__construct('widget_a3_portfolio_recently_viewed', __('a3 Portfolios Recently Viewed', 'a3-portfolio' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo $this->show_portfolio_recently_viewed();
echo $after_widget;
}
function show_portfolio_recently_viewed() {
global $post;
$result_html = '';
$current_lang = '';
if ( class_exists('SitePress') ) {
$current_lang = ICL_LANGUAGE_CODE;
}
do_action( 'a3_portfolio_before_recently_widget' );
if ( isset($_COOKIE['portfolio_recentviews' . $current_lang ]) && is_array(json_decode($_COOKIE['portfolio_recentviews' . $current_lang ])) && count(json_decode($_COOKIE['portfolio_recentviews' . $current_lang ])) > 0 ) {
$result_html .= '
';
$portfolio_recently_viewed = array_reverse(json_decode($_COOKIE['portfolio_recentviews' . $current_lang ]));
foreach ( $portfolio_recently_viewed as $portfolio_id ) {
$_blank = a3_portfolio_get_image_blank();
$portfolio_gallery = a3_portfolio_get_gallery( $portfolio_id );
if ( $portfolio_gallery ) {
$thumb = wp_get_attachment_image_src( $portfolio_gallery[0], 'portfolio-gallery-thumbnail-image', true );
$thumb_srcset = wp_get_attachment_image_srcset( $portfolio_gallery[0], 'portfolio-gallery-thumbnail-image' );
$thumb_sizes = wp_get_attachment_image_srcset( $portfolio_gallery[0], 'portfolio-gallery-thumbnail-image' );
if ( $thumb_srcset === false ) {
$thumb_srcset = '';
} else {
$thumb_srcset = 'srcset="' . esc_attr( $thumb_srcset ) . '"';
}
if ( $thumb_sizes === false ) {
$thumb_sizes = '';
} else {
$thumb_sizes = 'sizes="' . esc_attr( $thumb_sizes ) . '"';
}
$alt = get_post_meta( $portfolio_gallery[0], '_wp_attachment_image_alt', true );
if ( empty( $alt ) ) {
$alt = get_the_title( $portfolio_id );
}
$img = '
';
} else {
$thumb = a3_portfolio_no_image();
$img = '
';
}
$result_html .= '- '.$img.'
';
}
$result_html .= '
';
$result_html .= '
';
$result_html .= '
';
} else {
$result_html = '' . a3_portfolio_ei_ict_t__( 'Recently Widget - No Portfolio', __( 'No Portfolio Recently Viewed !', 'a3-portfolio' ) ). '
';
}
do_action( 'a3_portfolio_after_recently_widget' );
return $result_html;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = esc_attr($new_instance['title']);
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = esc_attr($instance['title']);
?>