Advertisement
baliniz

Untitled

Feb 26th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 33.45 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author : Jegtheme
  4.  */
  5. namespace JNews\Single;
  6.  
  7. use JNews\Module\Block\BlockViewAbstract;
  8.  
  9. /**
  10.  * Class Theme SinglePost
  11.  */
  12. Class SinglePost
  13. {
  14.     /**
  15.      * @var SinglePost
  16.      */
  17.     private static $instance;
  18.  
  19.     /**
  20.      * @var \WP_Post
  21.      */
  22.     private $post_id;
  23.  
  24.     /**
  25.      * @return SinglePost
  26.      */
  27.     public static function getInstance()
  28.     {
  29.         if (null === static::$instance)
  30.         {
  31.             static::$instance = new static();
  32.         }
  33.         return static::$instance;
  34.     }
  35.  
  36.     private function __construct()
  37.     {
  38.         $this->post_id = get_the_ID();
  39.         $this->hook();
  40.     }
  41.  
  42.     public function hook()
  43.     {
  44.         add_filter('body_class',  array($this, 'add_body_class'));
  45.         add_filter('the_content', array($this, 'render_inline_related_post'), 10);
  46.  
  47.         add_action('jnews_single_post_after_content', array($this, 'next_prev_content_hook'), 20);
  48.         add_action('jnews_single_post_after_content', array($this, 'author_box_hook'), 30);
  49.         add_action('jnews_single_post_after_content', array($this, 'related_post_hook'), 40);
  50.         add_action('jnews_single_post_after_content', array($this, 'popup_post_hook'), 50);
  51.         add_action('jnews_single_post_after_content', array($this, 'comment_post_hook'), 60);
  52.     }
  53.  
  54.     public function set_post_id($post_id)
  55.     {
  56.         $this->post_id = $post_id;
  57.         return $this;
  58.     }
  59.  
  60.     public function next_prev_content_hook()
  61.     {
  62.         echo "<div class=\"jnews_prev_next_container\">" ;
  63.         $this->prev_next_post();
  64.         echo "</div>";
  65.     }
  66.  
  67.     public function author_box_hook()
  68.     {
  69.         echo "<div class=\"jnews_author_box_container\">";
  70.         $this->author_box();
  71.         echo "</div>";
  72.     }
  73.  
  74.     public function related_post_hook()
  75.     {
  76.         echo "<div class=\"jnews_related_post_container\">";
  77.         echo jnews_sanitize_output($this->related_post(false));
  78.         echo "</div>";
  79.     }
  80.  
  81.     public function popup_post_hook()
  82.     {
  83.         echo "<div class=\"jnews_popup_post_container\">";
  84.         $this->popup_post();
  85.         echo "</div>";
  86.     }
  87.  
  88.     public function comment_post_hook()
  89.     {
  90.         echo "<div class=\"jnews_comment_container\">";
  91.         $this->post_comment();
  92.         echo "</div>";
  93.     }
  94.  
  95.     public function post_comment()
  96.     {
  97.         $show_comment = apply_filters('jnews_single_show_comment', true, $this->post_id);
  98.  
  99.         if($show_comment)
  100.         {
  101.             if ( comments_open() || '0' != jnews_get_comments_number() ) {
  102.                 comments_template();
  103.             }
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * @return string
  109.      */
  110.     public function additional_fs_class()
  111.     {
  112.         $class = array();
  113.         $template = $this->get_template();
  114.  
  115.         if($template === '4' || $template === '5')
  116.         {
  117.             if($this->get_fullscreen_mode()) {
  118.                 $class[] = 'jeg_fs_container';
  119.             }
  120.  
  121.             if($this->get_parallax_mode()) {
  122.                 $class[] = 'jeg_parallax';
  123.             }
  124.         }
  125.  
  126.         echo implode(' ', $class);
  127.     }
  128.  
  129.     public function add_body_class($classes)
  130.     {
  131.         $template = $this->get_template();
  132.  
  133.         switch($template) {
  134.             case '1' :
  135.                 $classes[] = 'jeg_single_tpl_1';
  136.                 break;
  137.             case '2' :
  138.                 $classes[] = 'jeg_single_tpl_2';
  139.                 break;
  140.             case '3' :
  141.                 $classes[] = 'jeg_single_tpl_3';
  142.                 break;
  143.             case '4' :
  144.                 $classes[] = 'jeg_single_tpl_4';
  145.                 if($this->get_fullscreen_mode()) {
  146.                     $classes[] = 'jeg_force_fs';
  147.                 }
  148.                 break;
  149.             case '5' :
  150.                 $classes[] = 'jeg_single_tpl_5';
  151.                 if($this->get_fullscreen_mode()) {
  152.                     $classes[] = 'jeg_force_fs';
  153.                 }
  154.                 break;
  155.             case '6' :
  156.                 $classes[] = 'jeg_single_tpl_6';
  157.                 break;
  158.             case '7' :
  159.                 $classes[] = 'jeg_single_tpl_7';
  160.                 break;
  161.             case '8' :
  162.                 $classes[] = 'jeg_single_tpl_8';
  163.                 break;
  164.             case '9' :
  165.                 $classes[] = 'jeg_single_tpl_9';
  166.                 break;
  167.             case '10' :
  168.                 $classes[] = 'jeg_single_tpl_10';
  169.                 break;
  170.             default :
  171.                 break;
  172.         }
  173.  
  174.  
  175.         $layout = $this->get_layout();
  176.  
  177.         if($layout === 'no-sidebar-narrow')
  178.         {
  179.             $classes[] = 'jeg_single_fullwidth';
  180.         }
  181.  
  182.         return $classes;
  183.     }
  184.  
  185.     public function main_class()
  186.     {
  187.         $layout = $this->get_layout();
  188.  
  189.         if($layout === 'no-sidebar-narrow')
  190.         {
  191.             echo "jeg_sidebar_none";
  192.         }
  193.  
  194.         if($layout === 'left-sidebar')
  195.         {
  196.             echo "jeg_sidebar_left";
  197.         }
  198.     }
  199.  
  200.     public function post_date_format($post)
  201.     {
  202.         $date_format = $this->get_date_format();
  203.  
  204.         if ( $date_format === 'ago' )
  205.         {
  206.             return jnews_ago_time ( human_time_diff( get_the_time('U', $post), current_time('timestamp') ) );
  207.         }
  208.         else if ( $date_format === 'default' )
  209.         {
  210.             return get_the_date(null, $post);
  211.         }
  212.         else if ( $date_format )
  213.         {
  214.             return get_the_date($date_format, $post);
  215.         }
  216.  
  217.         return get_the_date(null, $post);
  218.     }
  219.  
  220.     public function get_template()
  221.     {
  222.         if(vp_metabox('jnews_single_post.override_template', null, $this->post_id))
  223.         {
  224.             $template = vp_metabox('jnews_single_post.override.0.template', '1', $this->post_id);
  225.         } else {
  226.             $template = get_theme_mod('jnews_single_blog_template', '1');
  227.         }
  228.  
  229.         return apply_filters('jnews_single_post_template', $template, $this->post_id);
  230.     }
  231.  
  232.     public function get_fullscreen_mode()
  233.     {
  234.         if(vp_metabox('jnews_single_post.override_template', null, $this->post_id))
  235.         {
  236.             $enable = vp_metabox('jnews_single_post.override.0.fullscreen', true, $this->post_id);
  237.         } else {
  238.             $enable = get_theme_mod('jnews_single_blog_enable_fullscreen', true);
  239.         }
  240.  
  241.         return apply_filters('jnews_single_post_fullscreen', $enable, $this->post_id);
  242.     }
  243.  
  244.     public function get_parallax_mode()
  245.     {
  246.         if(vp_metabox('jnews_single_post.override_template', null, $this->post_id))
  247.         {
  248.             $enable = vp_metabox('jnews_single_post.override.0.parallax', true, $this->post_id);
  249.         } else {
  250.             $enable = get_theme_mod('jnews_single_blog_enable_parallax', true);
  251.         }
  252.  
  253.         return apply_filters('jnews_single_post_parallax', $enable, $this->post_id);
  254.     }
  255.  
  256.     public function get_layout()
  257.     {
  258.         if(vp_metabox('jnews_single_post.override_template', null, $this->post_id))
  259.         {
  260.             $layout = vp_metabox('jnews_single_post.override.0.layout', 'right-sidebar', $this->post_id);
  261.         } else {
  262.             $layout = get_theme_mod('jnews_single_blog_layout', 'right-sidebar');
  263.         }
  264.  
  265.         return apply_filters('jnews_single_post_layout', $layout, $this->post_id);
  266.     }
  267.  
  268.     public function has_sidebar()
  269.     {
  270.         $layout = $this->get_layout();
  271.  
  272.         if($layout === 'left-sidebar' || $layout === 'right-sidebar')
  273.         {
  274.             return true;
  275.         }
  276.         return false;
  277.     }
  278.  
  279.     public function get_sidebar()
  280.     {
  281.         $sidebar = get_theme_mod('jnews_single_sidebar', 'default-sidebar');
  282.  
  283.         if(vp_metabox('jnews_single_post.override_template', null, $this->post_id))
  284.         {
  285.             $sidebar = vp_metabox('jnews_single_post.override.0.sidebar', 'default-sidebar', $this->post_id);
  286.         }
  287.  
  288.         return apply_filters('jnews_single_post_sidebar', $sidebar, $this->post_id);
  289.     }
  290.  
  291.     public function get_sticky_sidebar()
  292.     {
  293.         if ( $this->sticky_sidebar() )
  294.         {
  295.             return 'jeg_sticky_sidebar';
  296.         }
  297.        
  298.         return false;
  299.     }
  300.  
  301.     public function sticky_sidebar()
  302.     {
  303.         $sticky_sidebar = get_theme_mod('jnews_single_sticky_sidebar', true);
  304.  
  305.         if(vp_metabox('jnews_single_post.override_template', null, $this->post_id))
  306.         {
  307.             $sticky_sidebar = vp_metabox('jnews_single_post.override.0.sticky_sidebar', true, $this->post_id);
  308.         }
  309.  
  310.         return apply_filters('jnews_single_post_sticky_sidebar', $sticky_sidebar, $this->post_id);
  311.     }
  312.  
  313.     public function render_sidebar()
  314.     {
  315.         if($this->has_sidebar())
  316.         {
  317.             get_template_part('fragment/post/single-sidebar');
  318.         }
  319.     }
  320.  
  321.     public function main_content_width()
  322.     {
  323.         if($this->has_sidebar()) {
  324.             return 8;
  325.         } else {
  326.             $layout = $this->get_layout();
  327.  
  328.             if($layout === 'no-sidebar-narrow')
  329.             {
  330.                 return $layout;
  331.             } else {
  332.                 return 12;
  333.             }
  334.         }
  335.     }
  336.  
  337.     /**
  338.      * breadcrumb
  339.      */
  340.     public function render_breadcrumb()
  341.     {
  342.         echo jnews_render_breadcrumb();
  343.     }
  344.  
  345.     /**
  346.      * Post Share
  347.      */
  348.  
  349.     public function share_float_additional_class()
  350.     {
  351.         if ( vp_metabox('jnews_single_post.override_template') && vp_metabox('jnews_single_post.override.0.share_position') )
  352.         {
  353.             if ( vp_metabox('jnews_single_post.override.0.share_position') === 'float' || vp_metabox('jnews_single_post.override.0.share_position') === 'floatbottom' )
  354.             {
  355.                 return "with-share";
  356.             }
  357.  
  358.             return "no-share";
  359.         }
  360.  
  361.         if ( get_theme_mod('jnews_single_share_position', 'top') === 'float' || get_theme_mod('jnews_single_share_position', 'top') === 'floatbottom' )
  362.         {
  363.             return "with-share";
  364.         }
  365.  
  366.         return "no-share";
  367.     }
  368.  
  369.     /**
  370.      * Post Share - Float Style
  371.      */
  372.  
  373.     public function share_float_style_class()
  374.     {
  375.         if ( vp_metabox('jnews_single_post.override_template') && vp_metabox('jnews_single_post.override.0.share_float_style') )
  376.         {
  377.             echo vp_metabox('jnews_single_post.override.0.share_float_style');
  378.         } else {
  379.             echo get_theme_mod('jnews_single_share_float_style', 'share-monocrhome');
  380.         }
  381.     }
  382.  
  383.     /**
  384.      * Post Meta
  385.      */
  386.     public function render_post_meta()
  387.     {
  388.         if($this->show_post_meta())
  389.         {
  390.             $template = $this->get_template();
  391.  
  392.             switch($template) {
  393.                 case '1' :
  394.                 case '3' :
  395.                 case '4' :
  396.                 case '6' :
  397.                 case '7' :
  398.                 case '8' :
  399.                 case '9' :
  400.                     get_template_part('fragment/post/meta-post-1');
  401.                     break;
  402.                 case '2' :
  403.                 case '5' :
  404.                 case '10' :
  405.                 default :
  406.                     get_template_part('fragment/post/meta-post-2');
  407.                     break;
  408.             }
  409.         }
  410.     }
  411.  
  412.     public function is_subtitle_empty()
  413.     {
  414.         $subtitle = $this->render_subtitle();
  415.         return empty($subtitle);
  416.     }
  417.  
  418.     public function render_subtitle()
  419.     {
  420.         $subtitle = wp_kses( get_post_meta( $this->post_id, 'post_subtitle', true ), wp_kses_allowed_html() );
  421.         return apply_filters('jnews_single_subtitle', $subtitle, $this->post_id);
  422.     }
  423.  
  424.     public function show_post_meta()
  425.     {
  426.         if ( vp_metabox('jnews_single_post.override_template') )
  427.         {
  428.             $flag = vp_metabox('jnews_single_post.override.0.show_post_meta');
  429.         } else {
  430.             $flag = get_theme_mod('jnews_single_show_post_meta', true);
  431.         }
  432.  
  433.         return apply_filters('jnews_single_show_post_meta', $flag, $this->post_id);
  434.     }
  435.  
  436.     public function show_author_meta_image()
  437.     {
  438.         if ( vp_metabox('jnews_single_post.override_template') )
  439.         {
  440.             $flag = vp_metabox('jnews_single_post.override.0.show_post_author_image');
  441.         } else {
  442.             $flag = get_theme_mod('jnews_single_show_post_author_image', true);
  443.         }
  444.        
  445.         return apply_filters('jnews_single_show_post_author_image', $flag, $this->post_id);
  446.     }
  447.  
  448.     public function show_author_meta()
  449.     {
  450.         if ( vp_metabox('jnews_single_post.override_template') )
  451.         {
  452.             $flag = vp_metabox('jnews_single_post.override.0.show_post_author');
  453.         } else {
  454.             $flag = get_theme_mod('jnews_single_show_post_author', true);
  455.         }
  456.  
  457.         return apply_filters('jnews_single_show_post_author', $flag, $this->post_id);
  458.     }
  459.  
  460.     public function show_date_meta()
  461.     {
  462.         if ( vp_metabox('jnews_single_post.override_template') )
  463.         {
  464.             $flag = vp_metabox('jnews_single_post.override.0.show_post_date');
  465.         } else {
  466.             $flag = get_theme_mod('jnews_single_show_post_date', true);
  467.         }
  468.        
  469.         return apply_filters('jnews_single_show_post_date', $flag, $this->post_id);
  470.     }
  471.  
  472.     public function get_date_format()
  473.     {
  474.         if ( vp_metabox('jnews_single_post.override_template') )
  475.         {
  476.             $format = vp_metabox('jnews_single_post.override.0.post_date_format', 'default');
  477.  
  478.             if ( $format === 'custom' )
  479.             {
  480.                 $format = vp_metabox('jnews_single_post.override.0.post_date_format_custom', 'Y/m/d');
  481.             }
  482.         } else {
  483.             $format = get_theme_mod('jnews_single_post_date_format', 'default');
  484.  
  485.             if ( $format === 'custom' )
  486.             {
  487.                 $format = get_theme_mod('jnews_single_post_date_format_custom', 'Y/m/d');
  488.             }
  489.         }
  490.  
  491.         return apply_filters('jnews_single_show_post_date', $format, $this->post_id);
  492.     }
  493.  
  494.     public function show_category_meta()
  495.     {
  496.         if ( vp_metabox('jnews_single_post.override_template') )
  497.         {
  498.             $flag = vp_metabox('jnews_single_post.override.0.show_post_category');
  499.         } else {
  500.             $flag = get_theme_mod('jnews_single_show_category', true);
  501.         }
  502.        
  503.         return apply_filters('jnews_single_show_category', $flag, $this->post_id);
  504.     }
  505.  
  506.     public function show_comment_meta()
  507.     {
  508.         $flag = get_theme_mod('jnews_single_comment', true);
  509.         return apply_filters('jnews_single_comment', $flag, $this->post_id);
  510.     }
  511.  
  512.     public function post_tag_render()
  513.     {
  514.         if ( vp_metabox('jnews_single_post.override_template') )
  515.         {
  516.             $flag = vp_metabox('jnews_single_post.override.0.show_post_tag');
  517.         } else {
  518.             $flag = get_theme_mod('jnews_single_show_tag', true);
  519.         }
  520.  
  521.         if($flag)
  522.         {
  523.             $this->render_post_tag();
  524.         }
  525.     }
  526.  
  527.     public function render_post_tag()
  528.     {
  529.         echo "<span>" . jnews_return_translation('Tags:', 'jnews', 'tags') . "</span> " . get_the_tag_list('', '', '');
  530.     }
  531.  
  532.     /**
  533.      * Featured Post
  534.      */
  535.     public function render_featured_post_alternate()
  536.     {
  537.         $format = get_post_format();
  538.  
  539.         if($format === 'video' || $format === 'gallery') {
  540.             $this->render_featured_post();
  541.         }
  542.     }
  543.  
  544.     public function render_featured_post()
  545.     {
  546.         if ( vp_metabox('jnews_single_post.override_template') )
  547.         {
  548.             $flag = vp_metabox('jnews_single_post.override.0.show_featured');
  549.         } else {
  550.             $flag = get_theme_mod('jnews_single_show_featured', true);
  551.         }
  552.  
  553.         $current_page   = jnews_get_post_current_page();
  554.         if( $flag && $current_page === 1) $this->feature_post_1();
  555.     }
  556.  
  557.     public function get_featured_post_image_size($size)
  558.     {
  559.         $template = $this->get_template();
  560.  
  561.         if( $template === '1' || $template === '2' || $template === '3' || $template === '4' || $template === '5' ||
  562.             $template === '6' || $template === '7' || $template === '8' || $template === '9' || $template === '10' )
  563.         {
  564.             if($this->has_sidebar())
  565.             {
  566.                 $width_image = false;
  567.             } else {
  568.                 $width_image = true;
  569.             }
  570.         } else {
  571.             $width_image = true;
  572.         }
  573.  
  574.         if($width_image === 'normal')
  575.         {
  576.             switch ($size) {
  577.                 case 'no-crop' :
  578.                     $image_size = 'jnews-featured-750';
  579.                     break;
  580.                 case 'crop-500';
  581.                     $image_size = 'jnews-750x375';
  582.                     break;
  583.                 case 'crop-715':
  584.                     $image_size = 'jnews-750x536';
  585.                     break;
  586.                 default :
  587.                     $image_size = 'jnews-750x375';
  588.             }
  589.         } else {
  590.             switch ($size) {
  591.                 case 'no-crop' :
  592.                     $image_size = 'jnews-featured-1140';
  593.                     break;
  594.                 case 'crop-500';
  595.                     $image_size = 'jnews-1140x570';
  596.                     break;
  597.                 case 'crop-715':
  598.                     $image_size = 'jnews-1140x815';
  599.                     break;
  600.                 default :
  601.                     $image_size = 'jnews-1140x570';
  602.             }
  603.         }
  604.  
  605.         return $image_size;
  606.     }
  607.  
  608.     public function get_single_thumbnail_size()
  609.     {
  610.         if(vp_metabox('jnews_single_post.override_image_size', null, $this->post_id))
  611.         {
  612.             $image_size = vp_metabox('jnews_single_post.image_override.0.single_post_thumbnail_size', 'crop-500', $this->post_id);
  613.         } else {
  614.             $image_size = get_theme_mod('jnews_single_post_thumbnail_size', 'crop-500');
  615.         }
  616.  
  617.         return $this->get_featured_post_image_size($image_size);
  618.     }
  619.  
  620.     public function get_gallery_thumbnail_size()
  621.     {
  622.         if(vp_metabox('jnews_single_post.override_image_size', null, $this->post_id))
  623.         {
  624.             $image_size = vp_metabox('jnews_single_post.image_override.0.single_post_gallery_size', 'crop-500', $this->post_id);
  625.         } else {
  626.             $image_size = get_theme_mod('jnews_single_post_gallery_size', 'crop-500');
  627.         }
  628.  
  629.         return $this->get_featured_post_image_size($image_size);
  630.     }
  631.  
  632.     public function feature_post_1()
  633.     {
  634.         $format = get_post_format();
  635.  
  636.         switch($format) {
  637.             case 'gallery' :
  638.                 $gallery_size = $this->get_gallery_thumbnail_size();
  639.                 $output = $this->featured_gallery($gallery_size);
  640.                 break;
  641.             case 'video' :
  642.                 $output = $this->featured_video();
  643.                 break;
  644.             default :
  645.                 $image_size = $this->get_single_thumbnail_size();
  646.                 $output = $this->featured_image($image_size);
  647.                 break;
  648.         }
  649.  
  650.         echo jnews_sanitize_output($output);
  651.     }
  652.  
  653.     public function featured_gallery($size)
  654.     {
  655.         $size = apply_filters('jnews_featured_gallery_image_size', $size);
  656.         $dimension = jnews_get_image_dimension_by_name($size);
  657.         $output = '';
  658.         $images = get_post_meta($this->post_id, '_format_gallery_images', true);
  659.  
  660.         if($images)
  661.         {
  662.             $output = "<div class=\"jeg_featured thumbnail-container size-{$dimension}\">";
  663.             $output .= "<div class=\"featured_gallery jeg_owlslider owl-carousel\">";
  664.  
  665.             $popup = get_theme_mod('jnews_single_popup_script', 'magnific');
  666.  
  667.             foreach ( $images as $image_id )
  668.             {
  669.                 $image_src = wp_get_attachment_image_src($image_id, 'full');
  670.                 $image = get_post($image_id);
  671.  
  672.                 $output .= ( $popup !== 'disable' ) ? "<a href=\"{$image_src[0]}\">" : "";
  673.                 $output .= apply_filters('jnews_single_image_lazy_owl', $image_id, $size);
  674.  
  675.                 if(!empty($image->post_excerpt))
  676.                 {
  677.                     $output .= "<p class=\"wp-caption-text\">" .  $image->post_excerpt . "</p>";
  678.                 }
  679.                 $output .= ( $popup !== 'disable' ) ? "</a>" : "";
  680.             }
  681.  
  682.             $output .= "</div>";
  683.             $output .= "</div>";
  684.  
  685.         }
  686.  
  687.         return apply_filters('jnews_featured_gallery', $output, $this->post_id);
  688.     }
  689.  
  690.  
  691.     public function featured_image($size)
  692.     {
  693.         $output = "<div class=\"jeg_featured featured_image\">";
  694.  
  695.         $popup              = get_theme_mod('jnews_single_popup_script', 'magnific');
  696.         $image_src          = $this->get_featured_image_src('full');
  697.  
  698.         if(has_post_thumbnail())
  699.         {
  700.             $output .= ( $popup !== 'disable' ) ? "<a href=\"{$image_src}\">" : "";
  701.             $output .= apply_filters('jnews_image_thumbnail_unwrap', $this->post_id, $size);
  702.             $output .= ( $popup !== 'disable' ) ? "</a>" : "";
  703.         }
  704.  
  705.         $output .= "</div>";
  706.         return apply_filters('jnews_featured_image', $output, $this->post_id);
  707.     }
  708.  
  709.     public function get_featured_image_src($size)
  710.     {
  711.         $post_thumbnail_id  = get_post_thumbnail_id( $this->post_id );
  712.         $image              = wp_get_attachment_image_src($post_thumbnail_id, $size);
  713.  
  714.         return $image[0];
  715.     }
  716.  
  717.     public function featured_video()
  718.     {
  719.         $output = "<div class=\"jeg_featured featured_video\">";
  720.  
  721.         $video_url      = get_post_meta( $this->post_id, '_format_video_embed', true );
  722.         $video_format   = strtolower( pathinfo( $video_url, PATHINFO_EXTENSION ) );
  723.         $featured_img   = jnews_get_image_src( get_post_thumbnail_id( $this->post_id ), 'jnews-featured-750' );
  724.  
  725.         if( jnews_check_video_type($video_url) === 'youtube' )
  726.         {
  727.             $output .=
  728.                 "<div data-src=\"". esc_url( $video_url ) . "\" data-type=\"youtube\" data-repeat=\"false\" data-autoplay=\"false\" class=\"youtube-class clearfix\">
  729.                    <div class=\"jeg_video_container\"></div>
  730.                </div>";
  731.         } else if( jnews_check_video_type($video_url) === 'vimeo' )
  732.         {
  733.             $output .=
  734.                 "<div data-src=\"" . esc_url( $video_url ) . "\" data-repeat=\"false\" data-autoplay=\"false\" data-type=\"vimeo\" class=\"vimeo-class clearfix\">
  735.                    <div class=\"jeg_video_container\"></div>
  736.                </div>";
  737.         } else if( $video_format == 'mp4' )
  738.         {
  739.             $output .=
  740.                 "<video width=\"640\" height=\"360\" style=\"width: 100%; height: 100%;\" poster=\"" . esc_attr( $featured_img ) . "\" preload=\"none\">
  741.                    <source type=\"video/mp4\" src=\"" . esc_url( $video_url ) . "\">
  742.                </video>";
  743.         } else if ( wp_oembed_get( $video_url ) )
  744.         {
  745.             $output .= "<div class=\"jeg_video_container\">" . wp_oembed_get( $video_url ) . "</div>";
  746.         }
  747.  
  748.         $output .= "</div>";
  749.  
  750.         return apply_filters('jnews_featured_video', $output, $this->post_id);
  751.     }
  752.  
  753.     /**
  754.      * Next Prev Post
  755.      */
  756.     public function prev_next_post()
  757.     {
  758.         if ( vp_metabox('jnews_single_post.override_template') )
  759.         {
  760.             $flag = vp_metabox('jnews_single_post.override.0.show_prev_next_post');
  761.         } else {
  762.             $flag = get_theme_mod('jnews_single_show_prev_next_post', true);
  763.         }
  764.  
  765.         $show_prev_next = apply_filters('jnews_single_show_prev_next_post', $flag, $this->post_id);
  766.        
  767.         if($show_prev_next) {
  768.             get_template_part('fragment/post/prev-next-post');
  769.         }
  770.     }
  771.  
  772.     /**
  773.      * Popup Post
  774.      */
  775.     public function popup_post()
  776.     {
  777.         if ( vp_metabox('jnews_single_post.override_template') )
  778.         {
  779.             $flag   = vp_metabox('jnews_single_post.override.0.show_popup_post');
  780.             $number = vp_metabox('jnews_single_post.override.0.number_popup_post');
  781.         } else {
  782.             $flag   = get_theme_mod('jnews_single_show_popup_post', true);
  783.             $number = get_theme_mod('jnews_single_number_popup_post', 1);
  784.         }
  785.  
  786.         $show_popup_post = apply_filters('jnews_single_show_popup_post', $flag, $this->post_id);
  787.  
  788.         if ( $show_popup_post )
  789.         {
  790.             set_query_var( 'number_popup_post', $number );
  791.             get_template_part('fragment/post/popup-post');
  792.         }
  793.     }
  794.  
  795.     /**
  796.      * Author Box
  797.      */
  798.     public function author_box()
  799.     {
  800.         if ( vp_metabox('jnews_single_post.override_template') )
  801.         {
  802.             $flag = vp_metabox('jnews_single_post.override.0.show_author_box');
  803.         } else {
  804.             $flag = get_theme_mod('jnews_single_show_author_box', false);
  805.         }
  806.  
  807.  
  808.         $show_author_box = apply_filters('jnews_single_show_author_box', $flag, $this->post_id);
  809.  
  810.         if($show_author_box) {
  811.             get_template_part('fragment/post/author-box');
  812.         }
  813.     }
  814.  
  815.     public function recursive_category($categories, &$result)
  816.     {
  817.         foreach($categories as $category)
  818.         {
  819.             $result[] = $category;
  820.             $children = get_categories ( array( 'parent' => $category->term_id ) );
  821.  
  822.             if( ! empty( $children ) ) {
  823.                 $this->recursive_category($children, $result);
  824.             }
  825.         }
  826.     }
  827.  
  828.     /**
  829.      * Check if we can render related post
  830.      *
  831.      * @return boolean
  832.      */
  833.     public function can_render_related_post()
  834.     {
  835.         if(apply_filters('jnews_force_disable_related_post', true)) return false;
  836.  
  837.         if ( vp_metabox('jnews_single_post.override_template') )
  838.         {
  839.             $flag = vp_metabox('jnews_single_post.override.0.show_post_related');
  840.         } else {
  841.             $flag = get_theme_mod('jnews_single_show_post_related', false);
  842.         }
  843.  
  844.         return $flag;
  845.     }
  846.  
  847.     /**
  848.      * Check if we can render inline related post
  849.      *
  850.      * @return boolean
  851.      */
  852.     public function can_render_inline_related_post()
  853.     {
  854.         if ( apply_filters('jnews_force_disable_inline_related_post', false) ) return false;
  855.  
  856.         if ( vp_metabox('jnews_single_post.override_template') )
  857.         {
  858.             $flag = vp_metabox('jnews_single_post.override.0.show_inline_post_related');
  859.         } else {
  860.             $flag = get_theme_mod('jnews_single_post_show_inline_related', false);
  861.         }
  862.  
  863.         return $flag;
  864.     }
  865.  
  866.     /**
  867.      * @param bool|true $echo
  868.      * @return array|string
  869.      */
  870.     public function related_post($echo = true)
  871.     {
  872.         if($this->can_render_related_post())
  873.         {
  874.             $content_width = is_numeric($this->main_content_width()) ? $this->main_content_width() : 8;
  875.  
  876.             do_action('jnews_module_set_width', $content_width);
  877.             $post_per_page = get_theme_mod('jnews_single_number_post_related', 6);
  878.  
  879.             $match = get_theme_mod('jnews_single_post_related_match', 'category');
  880.             $category = $tag = $result = array();
  881.             if($match === 'category')
  882.             {
  883.                 $this->recursive_category(get_the_category(), $result);
  884.  
  885.                 if($result) {
  886.                     foreach($result as $cat) {
  887.                         $category[] = $cat->term_id;
  888.                     }
  889.                 }
  890.             } else if($match === 'tag')
  891.             {
  892.                 $tags = get_the_tags();
  893.                 if($tags) {
  894.                     foreach($tags as $cat) {
  895.                         $tag[] = $cat->term_id;
  896.                     }
  897.                 }
  898.             }
  899.  
  900.             $attr = array(
  901.                 'first_title' => jnews_return_translation('Related', 'jnews', 'related'),
  902.                 'second_title' => jnews_return_translation(' Posts', 'jnews', 'posts'),
  903.                 'header_type' => get_theme_mod('jnews_single_post_related_header', 'heading_6'),
  904.                 'date_format' => get_theme_mod('jnews_single_post_related_date', 'default'),
  905.                 'date_format_custom' => get_theme_mod('jnews_single_post_related_date_custom', 'Y/m/d'),
  906.                 'excerpt_length' => get_theme_mod('jnews_single_post_related_excerpt', 20),
  907.                 'pagination_number_post' => $post_per_page,
  908.                 'number_post' => $post_per_page,
  909.                 'include_category' => implode(',', $category),
  910.                 'include_tag' => implode(',', $tag),
  911.                 'exclude_post' => $this->post_id,
  912.                 'sort_by' => 'latest',
  913.                 'pagination_mode' => get_theme_mod('jnews_single_post_pagination_related', 'disable'),
  914.                 'pagination_scroll_limit' => get_theme_mod('jnews_single_post_auto_load_related', 3),
  915.                 'paged' => 1,
  916.             );
  917.  
  918.             $name = 'JNews_Block_' . get_theme_mod('jnews_single_post_related_template', '22');
  919.             $name = jnews_get_view_class_from_shortcode( $name );
  920.  
  921.             /** @var $content_instance BlockViewAbstract */
  922.             $content_instance = jnews_get_module_instance($name);
  923.             $result = $content_instance->build_module($attr);
  924.  
  925.             if($echo) {
  926.                 echo jnews_sanitize_output($result);
  927.             } else {
  928.                 return $result;
  929.             }
  930.         }
  931.     }
  932.  
  933.     public function render_inline_related_post( $content )
  934.     {
  935.         if ( get_post_type() === 'post' && is_single() && ! is_admin() )
  936.         {
  937.             if ( $this->can_render_inline_related_post() )
  938.             {
  939.                 $pnumber    = explode( '<p>', $content );
  940.                 $paragraph  = get_theme_mod('jnews_single_post_inline_related_paragraph', 2);
  941.                 $random     = get_theme_mod('jnews_single_post_inline_related_random', false);
  942.                 $class      = get_theme_mod('jnews_single_post_inline_related_float', 'left');
  943.                 $fullwidth  = get_theme_mod('jnews_single_post_inline_related_fullwidth', false);
  944.  
  945.                 if ( $random )
  946.                 {
  947.                     $maxparagraph = count($pnumber) - 2;
  948.                     $paragraph    = rand( $paragraph, $maxparagraph );
  949.                 }
  950.  
  951.                 if ( ! $fullwidth )
  952.                 {
  953.                     $class .= ' half';
  954.                 }
  955.  
  956.                 $related_content =
  957.                     "<div class='jnews_inline_related_post_wrapper {$class}'>
  958.                        " . $this->build_inline_related_post() . "
  959.                    </div>";
  960.  
  961.                 $content = $this->prefix_insert_after_paragraph($related_content, $paragraph, $content);
  962.             }
  963.         }
  964.  
  965.         return $content;
  966.     }
  967.  
  968.     public function build_inline_related_post()
  969.     {
  970.         $match          = get_theme_mod('jnews_single_post_inline_related_match', 'category');
  971.         $related_width  = get_theme_mod('jnews_single_post_inline_related_fullwidth', false) ? 8 : 4;
  972.         $post_per_page  = get_theme_mod('jnews_single_post_inline_related_number', 3);
  973.         $tag = $category = $result = array();
  974.  
  975.         do_action('jnews_module_set_width', $related_width);
  976.  
  977.         if ( $match === 'category' )
  978.         {
  979.             $this->recursive_category( get_the_category(), $result );
  980.  
  981.             if ( $result )
  982.             {
  983.                 foreach($result as $cat)
  984.                 {
  985.                     $category[] = $cat->term_id;
  986.                 }
  987.             }
  988.         }
  989.         else if ( $match === 'tag' )
  990.         {
  991.             $tags = get_the_tags();
  992.             if ( $tags )
  993.             {
  994.                 foreach ( $tags as $cat )
  995.                 {
  996.                     $tag[] = $cat->term_id;
  997.                 }
  998.             }
  999.         }
  1000.  
  1001.         $attr = array(
  1002.             'first_title'               => get_theme_mod('jnews_single_post_inline_related_ftitle', 'Related'),
  1003.             'second_title'              => get_theme_mod('jnews_single_post_inline_related_stitle', 'Posts'),
  1004.             'header_type'               => get_theme_mod('jnews_single_post_inline_related_header', 'heading_6'),
  1005.             'date_format'               => get_theme_mod('jnews_single_post_inline_related_date', 'default'),
  1006.             'date_format_custom'        => get_theme_mod('jnews_single_post_inline_related_date_custom', 'Y/m/d'),
  1007.             'pagination_number_post'    => $post_per_page,
  1008.             'number_post'               => $post_per_page,
  1009.             'include_category'          => implode(',', $category),
  1010.             'include_tag'               => implode(',', $tag),
  1011.             'exclude_post'              => $this->post_id,
  1012.             'sort_by'                   => 'latest',
  1013.             'pagination_mode'           => get_theme_mod('jnews_single_post_inline_related_pagination', 'nextprev'),
  1014.             'paged' => 1,
  1015.         );
  1016.  
  1017.         $name = 'JNews_Block_' . get_theme_mod('jnews_single_post_inline_related_template', '29') ;
  1018.         $name = jnews_get_view_class_from_shortcode( $name );
  1019.  
  1020.         /** @var $content_instance BlockViewAbstract */
  1021.         $content_instance = jnews_get_module_instance($name);
  1022.         $result = $content_instance->build_module($attr);
  1023.  
  1024.         $output =
  1025.             "<div class='jnews_inline_related_post'>
  1026.                {$result}
  1027.            </div>";
  1028.  
  1029.         return $output;
  1030.     }
  1031.  
  1032.     protected function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content )
  1033.     {
  1034.         $begin_p = '</p>';
  1035.         $paragraphs = explode( $begin_p, $content );
  1036.  
  1037.         if ($paragraph_id == 0 ) {
  1038.             return $insertion . $content;
  1039.         }
  1040.  
  1041.         foreach ($paragraphs as $index => $paragraph) {
  1042.             if ( ($paragraph_id - 1 ) == $index ) {
  1043.                 $paragraphs[$index] .= $insertion;
  1044.             }
  1045.             if ( trim( $paragraph ) ) {
  1046.                 $paragraphs[$index] .= $begin_p;
  1047.             }
  1048.         }
  1049.         return implode( '', $paragraphs );
  1050.     }
  1051. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement