/**
* @author : Jegtheme
*/
namespace JNews\Sidefeed;
use JNews\Module\ModuleQuery;
/**
* Class Theme JNews SideFeed
*/
Class Sidefeed
{
private $attr;
public function __construct()
{
$this->side_feed_query();
}
public function can_render()
{
return apply_filters('jnews_enable_sidefeed', get_theme_mod('jnews_sidefeed_enable', false));
}
public function as_sidebar() {
return apply_filters( 'jnews_widgets_sidefeed_enable', get_theme_mod( 'jnews_widgets_sidefeed_enable', false ) );
}
public function build_response()
{
$data = $_REQUEST['data'];
$response = $this->request_ajax( $data );
wp_send_json( $response );
}
public function render_side_feed_tab()
{
$latest_active = $this->attr['sort_by'] === 'latest' ? 'active' : '';
$popular_active = $this->attr['sort_by'] === 'popular_post' ? 'active' : '';
$sort_by = get_theme_mod('jnews_sidefeed_trending_range', 'popular_post');
$output = "" . jnews_return_translation('Latest', 'jnews', 'latest') . " ";
if(get_theme_mod('jnews_sidefeed_show_trending', false)) :
$output .= " " . jnews_return_translation('Trending', 'jnews', 'trending') . " ";
endif;
return $output;
}
public function render_side_feed_category_button()
{
if(get_theme_mod('jnews_sidefeed_show_category', false)) {
$output =
"" . $this->render_side_feed_list() . "
";
return $output;
}
return null;
}
public function request_ajax($attr)
{
$this->attr = $attr;
return $this->get_side_feed_content(true);
}
public function render_side_feed_list()
{
$category_list = '';
$categories = get_theme_mod('jnews_sidefeed_category', '');
if ( !empty($categories) && is_array($categories) )
{
foreach($categories as $category) {
$cat = get_category($category);
if(!$cat instanceof \WP_Error && !is_null($cat)) {
$cat_active = ( $this->attr['include_category'] == $cat->term_id ) ? "active" : "";
$category_list .= "term_id}\">{$cat->name} ";
}
}
} else {
return null;
}
$all_active = empty($this->attr['include_category']) ? "active" : "";
$output =
"" . jnews_return_translation('Filter', 'jnews', 'filter') ."
";
return $output;
}
public function side_feed_query()
{
global $wp_query;
$this->attr['paged'] = 1;
$this->attr['post_type'] = 'post';
$this->attr['exclude_post'] = is_single() ? $wp_query->post->ID : null;;
$this->attr['include_category'] = '';
$this->attr['sort_by'] = 'latest';
$this->attr['post_offset'] = 0;
$this->attr['number_post'] = $this->attr['pagination_number_post'] = get_theme_mod('jnews_sidefeed_number_post', 12);
}
public function render_side_feed_script()
{
$json_attr = wp_json_encode($this->attr);
return "";
}
public function render_side_feed_content()
{
$result = $this->get_side_feed_content();
return $result['content'];
}
public function get_side_feed_content($ajax = false)
{
if ( !$this->as_sidebar() ) {
$this->attr['pagination_mode'] = 'loadmore';
$query_result = ModuleQuery::do_query( $this->attr );
$result = $query_result['result'];
if ( $this->attr['paged'] == 1 && ! empty( $this->attr['exclude_post'] ) && $this->attr['sort_by'] === 'latest' && empty( $this->attr['include_category'] ) ) {
$current = get_post( $this->attr['exclude_post'] );
$result = array_merge( array( $current ), $result );
}
$content = $this->generate_side_feed_content( $result, $ajax );
$content_result = array(
'next' => $query_result['next'],
'prev' => $query_result['prev'],
'content' => $content
);
} else {
$content_result = array(
'widget_area_top' => get_theme_mod('jnews_widgets_sidefeed', 'default-sidebar'),
'widget_area_bottom' => get_theme_mod('jnews_widgets_footer_sidefeed', 'default-sidebar')
);
}
return $content_result;
}
public function format_date($post)
{
$date_format = get_theme_mod('jnews_feed_date_format');
if($date_format === 'ago') {
return jnews_ago_time ( human_time_diff( get_the_time('U', $post), current_time('timestamp')) );
} else if ($date_format === 'custom') {
return jeg_get_post_date(get_theme_mod('jnews_feed_date_format_custom'), $post);
} else if ($date_format) {
return jeg_get_post_date('', $post);
}
return jeg_get_post_date('', $post);
}
public function render_meta($post)
{
$output = '';
if(get_theme_mod('jnews_show_block_meta', true))
{
if (jnews_is_review($post->ID)) {
$output .= get_theme_mod('jnews_show_block_meta_rating', true) ? jnews_generate_rating($post->ID, 'jeg_live_search_review') : "";
} else {
$output .= "";
$output .= get_theme_mod('jnews_show_block_meta_date', true) ? "
{$this->format_date($post)}
" : "";
$output .= "
";
}
}
return $output;
}
public function generate_side_feed_content($result, $ajax)
{
$output = $active_id = '';
$sequence = get_theme_mod('jnews_ads_sidefeed_sequence', '3');
if($ajax) {
} else {
if (is_single()) {
reset($result);
$active_index = key($result);
$active_id = $result[$active_index]->ID;
}
}
foreach($result as $index => $post)
{
$active_class = ( $post->ID === $active_id ) ? "active" : "";
if($index == $sequence)
{
$side_ads = $this->get_sidefeed_ads();
$output .= "{$side_ads}
";
}
if($index === 0) {
$thumbnail = apply_filters('jnews_image_thumbnail', $post->ID, 'jnews-360x180');
$additional_class = (!has_post_thumbnail($post->ID)) ? ' no_thumbnail' : '';
$output .=
"ID}\" data-sequence=\"{$index}\">
{$this->render_meta($post)}
";
} else {
$thumbnail = apply_filters('jnews_image_thumbnail', $post->ID, 'jnews-75x75');
$additional_class = (!has_post_thumbnail($post->ID)) ? ' no_thumbnail' : '';
$output .=
"ID}\" data-sequence=\"{$index}\">
{$this->render_meta($post)}
";
}
}
return $output;
}
public function get_sidefeed_ads()
{
ob_start();
do_action('jnews_sidefeed_ads') ;
return ob_get_clean();
}
}
Post navigation
/**
* The template for displaying comments.
*
* The area of the page that contains both current comments
* and the comment form.
*
* @package WP FanZone
*/
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without loading the comments.
*/
if ( post_password_required() ) {
return;
}
?>