Advertisement
arie_cristianD

remove tag sting in SinglePost.php

Oct 30th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.71 KB | None | 0 0
  1. <?php
  2. /**
  3. * @author : Jegtheme
  4. */
  5.  
  6. namespace JNews\Single;
  7.  
  8. use JNews\ContentTag;
  9. use JNews\Module\Block\BlockViewAbstract;
  10.  
  11. /**
  12. * Class Theme SinglePost
  13. */
  14. Class SinglePost {
  15. /**
  16. * @var SinglePost
  17. */
  18. private static $instance;
  19.  
  20. /**
  21. * @var \WP_Post
  22. */
  23. private $post_id;
  24.  
  25. /**
  26. * @return SinglePost
  27. */
  28. public static function getInstance() {
  29. if ( null === static::$instance ) {
  30. static::$instance = new static();
  31. }
  32.  
  33. return static::$instance;
  34. }
  35.  
  36. private function __construct() {
  37. $this->post_id = get_the_ID();
  38. $this->hook();
  39. }
  40.  
  41. public function hook() {
  42. add_filter( 'body_class', array( $this, 'add_body_class' ) );
  43. add_filter( 'the_category_list', array( $this, 'hide_category' ), 10, 2 );
  44. add_filter( 'the_content', array( $this, 'render_inline_related_post' ), 99 );
  45. add_filter( 'jnews_ads_global_enable', array( $this, 'ads_post_enable' ), 11, 2 );
  46.  
  47. add_action( 'jnews_render_after_meta_left', array( $this, 'reading_time_meta' ), 10 );
  48.  
  49. add_action( 'jnews_single_post_after_content', array( $this, 'next_prev_content_hook' ), 20 );
  50. add_action( 'jnews_single_post_after_content', array( $this, 'author_box_hook' ), 30 );
  51. add_action( 'jnews_single_post_after_content', array( $this, 'related_post_hook' ), 40 );
  52. add_action( 'jnews_single_post_after_content', array( $this, 'popup_post_hook' ), 50 );
  53. add_action( 'jnews_single_custom_post_after_content', array( $this, 'popup_post_hook' ), 50 );
  54. add_action( 'jnews_single_post_after_content', array( $this, 'comment_post_hook' ), 60 );
  55.  
  56. add_action( 'jnews_render_before_meta_right', array( $this, 'zoom_button_meta' ), 10 );
  57. add_action( 'jnews_render_before_meta_right', array( $this, 'trending_post_meta' ), 5 );
  58. add_action( 'jnews_single_post_before_title', array( $this, 'trending_post_title' ) );
  59.  
  60. add_action( 'jnews_single_post_before_title', array( $this, 'sponsored_post_title' ) );
  61. add_action( 'jnews_single_post_before_content', array( $this, 'sponsored_post_content' ) );
  62.  
  63. add_action( 'jnews_source_via_single_post', array( $this, 'render_source_article' ), 8 );
  64. add_action( 'jnews_source_via_single_post', array( $this, 'render_via_article' ), 9 );
  65.  
  66. add_action( 'wp_footer', array( $this, 'render_reading_progress_bar' ) );
  67. }
  68.  
  69. /**
  70. * Filters the categories before building the category list.
  71. *
  72. * @param \WP_Term[] $categories An array of the post's categories.
  73. * @param int|bool $post_id ID of the post we're retrieving categories for.
  74. * When `false`, we assume the current post in the loop.
  75. */
  76. public function hide_category( $categories, $post_id ) {
  77. if ( is_single() && get_post_type() === 'post' ) {
  78. $_post = get_post( $post_id );
  79. $primary_category = get_post_meta( $_post->ID, 'jnews_primary_category', true );
  80. $hide_category = isset( $primary_category['hide'] ) ? explode( ',', $primary_category['hide'] ) : array();
  81. if ( ! empty( $hide_category ) ) {
  82. foreach ( $categories as $index => $category ) {
  83. if ( in_array( $category->term_id, $hide_category, false ) ) {
  84. unset( $categories[ $index ] );
  85. }
  86. }
  87. }
  88. }
  89. return $categories;
  90. }
  91.  
  92. protected function render_sponsored_post( $post_id ) {
  93. $output = '';
  94. $flag = vp_metabox( 'jnews_single_post.sponsored_post', null, $post_id );
  95.  
  96. if ( $flag ) {
  97. $label = vp_metabox( 'jnews_single_post.sponsored_post_label', null, $post_id );
  98. $name = vp_metabox( 'jnews_single_post.sponsored_post_name', null, $post_id );
  99. $desc = vp_metabox( 'jnews_single_post.sponsored_post_desc', null, $post_id );
  100. $url = vp_metabox( 'jnews_single_post.sponsored_post_url', null, $post_id );
  101.  
  102. $logo_show = vp_metabox( 'jnews_single_post.sponsored_post_logo_enable', null, $post_id );
  103. $logo = vp_metabox( 'jnews_single_post.sponsored_post_logo', null, $post_id );
  104.  
  105. if ( $logo_show ) {
  106. if ( $logo ) {
  107. $logo = wp_get_attachment_image_src( $logo, 'full' );
  108. $logo_url = isset( $logo[0] ) ? $logo[0] : '';
  109. $alt = empty( $name ) ? '' : 'alt="' . $name . '"';
  110. $sponsor = '<img src="' . $logo_url . '" '. $alt .'>';
  111. }
  112. } else {
  113. $sponsor = '<strong>' . $name . '</strong>';
  114. }
  115.  
  116. if ( $label ) {
  117. $label = '<span class="sponsor-label">' . $label . '</span>';
  118. }
  119.  
  120. $output =
  121. '<div class="jeg_meta_sponsor">
  122. ' . $label . '
  123. <a class="sponsor-logo" href="' . $url . '" target="_blank">
  124. ' . $sponsor . '
  125. </a>
  126. <p>' . wp_kses( $desc, 'post' ) . '</p>
  127. </div>';
  128. }
  129.  
  130. return $output;
  131. }
  132.  
  133. public function sponsored_post_content() {
  134. if ( in_array( $this->get_template(), [ '4', '5', '6' ] ) ) {
  135. echo jnews_sanitize_output( $this->render_sponsored_post( get_the_ID() ) );
  136. }
  137. }
  138.  
  139. public function sponsored_post_title( $post_id ) {
  140. if ( in_array( $this->get_template(), [ '1', '2', '3', '7', '8', '9', '10' ] ) ) {
  141. echo jnews_sanitize_output( $this->render_sponsored_post( $post_id ) );
  142. }
  143. }
  144.  
  145. public function render_reading_progress_bar() {
  146.  
  147. if ( is_single() && get_post_type() === 'post' ) {
  148. $output = $this->build_reading_progress_bar();
  149. echo "<div class=\"jeg_read_progress_wrapper\">{$output}</div>";
  150. }
  151. }
  152.  
  153. public function build_reading_progress_bar() {
  154. $output = '';
  155. $position = get_theme_mod( 'jnews_single_show_reading_progress_bar_position', 'bottom' );
  156.  
  157. if ( get_theme_mod( 'jnews_single_show_reading_progress_bar', false ) ) {
  158. $output = "<div class=\"jeg_progress_container {$position}\"><span class=\"progress-bar\"></span></div>";
  159. }
  160.  
  161. return $output;
  162. }
  163.  
  164. public function set_post_id( $post_id ) {
  165. $this->post_id = $post_id;
  166.  
  167. return $this;
  168. }
  169.  
  170. public function render_source_article() {
  171. $name = vp_metabox( 'jnews_single_post.source_name', false, $this->post_id );
  172. $name = apply_filters( 'jnews_single_post_source_name', $name, $this->post_id );
  173. $url = vp_metabox( 'jnews_single_post.source_url', false, $this->post_id );
  174. $url = apply_filters( 'jnews_single_post_source_url', $url, $this->post_id );
  175.  
  176. if ( ! empty( $name ) ) {
  177.  
  178. if ( $url ) {
  179. $url = "href=\"{$url}\"";
  180. }
  181.  
  182. echo "<div class=\"jeg_post_source\">
  183. <span>" . jnews_return_translation( 'Source:', 'jnews', 'source_text' ) . "</span>
  184. <a {$url} rel=\"nofollow\" target='_blank'>{$name}</a>
  185. </div>";
  186. }
  187. }
  188.  
  189. public function render_via_article() {
  190. $name = vp_metabox( 'jnews_single_post.via_name', false, $this->post_id );
  191. $name = apply_filters( 'jnews_single_post_via_name', $name, $this->post_id );
  192. $url = vp_metabox( 'jnews_single_post.via_url', false, $this->post_id );
  193. $url = apply_filters( 'jnews_single_post_via_url', $url, $this->post_id );
  194.  
  195. if ( ! empty( $name ) ) {
  196.  
  197. if ( $url ) {
  198. $url = "href=\"{$url}\"";
  199. }
  200.  
  201. echo "<div class=\"jeg_post_via\">
  202. <span>" . jnews_return_translation( 'Via:', 'jnews', 'via_text' ) . "</span>
  203. <a {$url} rel=\"nofollow\" target='_blank'>{$name}</a>
  204. </div>";
  205. }
  206. }
  207.  
  208. public function next_prev_content_hook() {
  209. echo "<div class=\"jnews_prev_next_container\">";
  210. $this->prev_next_post();
  211. echo "</div>";
  212. }
  213.  
  214. public function author_box_hook() {
  215. $class = $truncate = '';
  216. $show_author_box = $this->check_author_box();
  217. if ( jnews_check_number_authors() > 3 && $show_author_box ) {
  218. $class = 'author-truncate';
  219. $truncate = "<div class='truncate-read-more'><span>" . jnews_return_translation( 'Show More Contributor', 'jnews', 'show_more_contributor' ) . "</span></div>";
  220. }
  221. echo "<div class=\"jnews_author_box_container {$class}\">";
  222. $this->author_box();
  223. echo "{$truncate}";
  224. echo "</div>";
  225. }
  226.  
  227. public function related_post_hook() {
  228. echo "<div class=\"jnews_related_post_container\">";
  229. echo jnews_sanitize_output( $this->related_post( false ) );
  230. echo "</div>";
  231. }
  232.  
  233. public function popup_post_hook() {
  234. echo "<div class=\"jnews_popup_post_container\">";
  235. $this->popup_post();
  236. echo "</div>";
  237. }
  238.  
  239. public function comment_post_hook() {
  240. echo "<div class=\"jnews_comment_container\">";
  241. $this->post_comment();
  242. echo "</div>";
  243. }
  244.  
  245. public function post_comment() {
  246. $show_comment = apply_filters( 'jnews_single_show_comment', true, $this->post_id );
  247.  
  248. if ( $show_comment ) {
  249. if ( comments_open() || '0' != jnews_get_comments_number() ) {
  250. comments_template();
  251. }
  252. }
  253. }
  254.  
  255. /**
  256. * @return string
  257. */
  258. public function additional_fs_class() {
  259. $class = array();
  260. $template = $this->get_template();
  261.  
  262. if ( $template === '4' || $template === '5' ) {
  263. if ( $this->get_fullscreen_mode() ) {
  264. $class[] = 'jeg_fs_container';
  265. }
  266.  
  267. if ( $this->get_parallax_mode() ) {
  268. $class[] = 'jeg_parallax';
  269. }
  270. }
  271.  
  272. echo implode( ' ', $class );
  273. }
  274.  
  275. public function add_body_class( $classes ) {
  276. if ( get_post_type() === 'post' && is_single() ) {
  277. $template = $this->get_template();
  278.  
  279. switch ( $template ) {
  280. case '1' :
  281. $classes[] = 'jeg_single_tpl_1';
  282. break;
  283. case '2' :
  284. $classes[] = 'jeg_single_tpl_2';
  285. break;
  286. case '3' :
  287. $classes[] = 'jeg_single_tpl_3';
  288. break;
  289. case '4' :
  290. $classes[] = 'jeg_single_tpl_4';
  291. if ( $this->get_fullscreen_mode() ) {
  292. $classes[] = 'jeg_force_fs';
  293. }
  294. break;
  295. case '5' :
  296. $classes[] = 'jeg_single_tpl_5';
  297. if ( $this->get_fullscreen_mode() ) {
  298. $classes[] = 'jeg_force_fs';
  299. }
  300. break;
  301. case '6' :
  302. $classes[] = 'jeg_single_tpl_6';
  303. break;
  304. case '7' :
  305. $classes[] = 'jeg_single_tpl_7';
  306. break;
  307. case '8' :
  308. $classes[] = 'jeg_single_tpl_8';
  309. break;
  310. case '9' :
  311. $classes[] = 'jeg_single_tpl_9';
  312. break;
  313. case '10' :
  314. $classes[] = 'jeg_single_tpl_10';
  315. break;
  316. default :
  317. break;
  318. }
  319.  
  320. $layout = $this->get_layout();
  321.  
  322. if ( $layout === 'no-sidebar' ) {
  323. $classes[] = 'jeg_single_fullwidth';
  324. } else if ( $layout === 'no-sidebar-narrow' ) {
  325. $classes[] = 'jeg_single_fullwidth jeg_single_narrow';
  326. }
  327.  
  328. }
  329.  
  330. return $classes;
  331. }
  332.  
  333. public function main_class() {
  334. $layout = $this->get_layout();
  335.  
  336. switch ( $layout ) {
  337. case 'no-sidebar':
  338. case 'no-sidebar-narrow' :
  339. echo "jeg_sidebar_none";
  340. break;
  341.  
  342. case 'left-sidebar' :
  343. echo "jeg_sidebar_left";
  344. break;
  345.  
  346. case 'left-sidebar-narrow' :
  347. echo "jeg_sidebar_left jeg_wide_content";
  348. break;
  349.  
  350. case 'right-sidebar-narrow':
  351. echo "jeg_wide_content";
  352. break;
  353.  
  354. case 'double-sidebar' :
  355. echo "jeg_double_sidebar";
  356. break;
  357.  
  358. case 'double-right-sidebar' :
  359. echo "jeg_double_right_sidebar";
  360. break;
  361.  
  362. default :
  363. break;
  364. }
  365. }
  366.  
  367. public function post_date_format( $post ) {
  368. $date_format = $this->get_date_format();
  369.  
  370. if ( $date_format === 'ago' ) {
  371. return jnews_ago_time( human_time_diff( get_the_time( 'U', $post ), current_time( 'timestamp' ) ) );
  372. } else if ( $date_format === 'default' ) {
  373. return jeg_get_post_date( '', $post );
  374. } else if ( $date_format ) {
  375. return jeg_get_post_date( $date_format, $post );
  376. }
  377.  
  378. return jeg_get_post_date( '', $post );
  379. }
  380.  
  381. public function get_template() {
  382. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  383. $template = vp_metabox( 'jnews_single_post.override.0.template', '1', $this->post_id );
  384. } else {
  385. $template = get_theme_mod( 'jnews_single_blog_template', '1' );
  386. }
  387.  
  388. return apply_filters( 'jnews_single_post_template', $template, $this->post_id );
  389. }
  390.  
  391. public function get_custom_template() {
  392. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  393. $template = vp_metabox( 'jnews_single_post.override.0.single_blog_custom', null, $this->post_id );
  394. } else {
  395. $template = get_theme_mod( 'jnews_single_blog_custom', 'null' );
  396. }
  397.  
  398. return apply_filters( 'jnews_single_post_custom_template', $template, $this->post_id );
  399. }
  400.  
  401. public function get_fullscreen_mode() {
  402. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  403. $enable = vp_metabox( 'jnews_single_post.override.0.fullscreen', false, $this->post_id );
  404. } else {
  405. $enable = get_theme_mod( 'jnews_single_blog_enable_fullscreen', true );
  406. }
  407.  
  408. return apply_filters( 'jnews_single_post_fullscreen', $enable, $this->post_id );
  409. }
  410.  
  411. public function get_parallax_mode() {
  412. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  413. $enable = vp_metabox( 'jnews_single_post.override.0.parallax', false, $this->post_id );
  414. } else {
  415. $enable = get_theme_mod( 'jnews_single_blog_enable_parallax', true );
  416. }
  417.  
  418. return apply_filters( 'jnews_single_post_parallax', $enable, $this->post_id );
  419. }
  420.  
  421. public function get_layout() {
  422. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  423. $layout = vp_metabox( 'jnews_single_post.override.0.layout', 'right-sidebar', $this->post_id );
  424. } else {
  425. $layout = get_theme_mod( 'jnews_single_blog_layout', 'right-sidebar' );
  426. }
  427.  
  428. return apply_filters( 'jnews_single_post_layout', $layout, $this->post_id );
  429. }
  430.  
  431. public function has_sidebar() {
  432. $layout = $this->get_layout();
  433.  
  434. $sidebar = array(
  435. 'left-sidebar',
  436. 'right-sidebar',
  437. 'left-sidebar-narrow',
  438. 'right-sidebar-narrow',
  439. 'double-sidebar',
  440. 'double-right-sidebar'
  441. );
  442.  
  443. if ( in_array( $layout, $sidebar ) ) {
  444. return true;
  445. }
  446.  
  447. return false;
  448. }
  449.  
  450. public function get_sidebar() {
  451. $sidebar = get_theme_mod( 'jnews_single_sidebar', 'default-sidebar' );
  452.  
  453. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  454. $sidebar = vp_metabox( 'jnews_single_post.override.0.sidebar', 'default-sidebar', $this->post_id );
  455. }
  456.  
  457. return apply_filters( 'jnews_single_post_sidebar', $sidebar, $this->post_id );
  458. }
  459.  
  460. public function get_second_sidebar() {
  461. $sidebar = get_theme_mod( 'jnews_single_second_sidebar', 'default-sidebar' );
  462.  
  463. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  464. $sidebar = vp_metabox( 'jnews_single_post.override.0.second_sidebar', 'default-sidebar', $this->post_id );
  465. }
  466.  
  467. return apply_filters( 'jnews_single_post_second_sidebar', $sidebar, $this->post_id );
  468. }
  469.  
  470. public function get_sticky_sidebar() {
  471. if ( $this->sticky_sidebar() ) {
  472. return 'jeg_sticky_sidebar';
  473. }
  474.  
  475. return false;
  476. }
  477.  
  478. public function sticky_sidebar() {
  479. $sticky_sidebar = get_theme_mod( 'jnews_single_sticky_sidebar', true );
  480.  
  481. if ( vp_metabox( 'jnews_single_post.override_template', null, $this->post_id ) ) {
  482. $sticky_sidebar = vp_metabox( 'jnews_single_post.override.0.sticky_sidebar', false, $this->post_id );
  483. }
  484.  
  485. return apply_filters( 'jnews_single_post_sticky_sidebar', $sticky_sidebar, $this->post_id );
  486. }
  487.  
  488. public function render_sidebar() {
  489. if ( $this->has_sidebar() ) {
  490. $layout = $this->get_layout();
  491.  
  492. get_template_part( 'fragment/post/single-sidebar' );
  493.  
  494. if ( $layout === 'double-right-sidebar' || $layout === 'double-sidebar' ) {
  495. set_query_var( 'double_sidebar', true );
  496. get_template_part( 'fragment/post/single-sidebar' );
  497. }
  498. }
  499. }
  500.  
  501. public function get_sidebar_width() {
  502. $layout = $this->get_layout();
  503.  
  504. if ( $layout === 'left-sidebar' || $layout === 'right-sidebar' ) {
  505. return 4;
  506. }
  507.  
  508. return 3;
  509. }
  510.  
  511. public function set_global_content_width($layout)
  512. {
  513. global $content_width;
  514. switch ($layout)
  515. {
  516. case 8:
  517. $content_width = 790;
  518. break;
  519.  
  520. case 6:
  521. $content_width = 585;
  522. break;
  523.  
  524. case 9:
  525. $content_width = 877.5;
  526. break;
  527.  
  528. case 12:
  529. $content_width = 1150;
  530. break;
  531.  
  532. default:
  533. $content_width = 768;
  534. break;
  535. }
  536. }
  537.  
  538.  
  539. public function main_content_width() {
  540. $layout = $this->get_layout();
  541.  
  542. if ( in_array( $layout, array( 'right-sidebar', 'left-sidebar' ) ) ) {
  543. $sidebar = $this->get_sidebar();
  544. if ( ! is_active_sidebar( $sidebar ) ) {
  545. $width = 12;
  546. $this->set_global_content_width( $width );
  547. return $width;
  548. }
  549. }
  550.  
  551. switch ( $layout ) {
  552. case 'left-sidebar':
  553. case 'right-sidebar':
  554. $width = 8;
  555. break;
  556.  
  557. case 'left-sidebar-narrow':
  558. case 'right-sidebar-narrow':
  559. $width = 9;
  560. break;
  561.  
  562. case 'double-sidebar':
  563. case 'double-right-sidebar':
  564. $width = 6;
  565. break;
  566.  
  567. case 'no-sidebar-narrow':
  568. $width = $layout;
  569. break;
  570.  
  571. default:
  572. $width = 12;
  573. break;
  574. }
  575. return $width;
  576. }
  577.  
  578. /**
  579. * breadcrumb
  580. *
  581. * @param bool $render
  582. *
  583. * @return mixed|string
  584. */
  585. public function render_breadcrumb( $render = true ) {
  586. if ( $render ) {
  587. echo jnews_render_breadcrumb();
  588. } else {
  589. return jnews_render_breadcrumb();
  590. }
  591. }
  592.  
  593. /**
  594. * Post Share
  595. */
  596.  
  597. public function share_float_additional_class() {
  598. if ( vp_metabox( 'jnews_single_post.override_template' ) && vp_metabox( 'jnews_single_post.override.0.share_position' ) ) {
  599. if ( vp_metabox( 'jnews_single_post.override.0.share_position' ) === 'float' || vp_metabox( 'jnews_single_post.override.0.share_position' ) === 'floatbottom' ) {
  600. return "with-share";
  601. }
  602.  
  603. return "no-share";
  604. }
  605.  
  606. if ( get_theme_mod( 'jnews_single_share_position', 'top' ) === 'float' || get_theme_mod( 'jnews_single_share_position', 'top' ) === 'floatbottom' ) {
  607. return "with-share";
  608. }
  609.  
  610. return "no-share";
  611. }
  612.  
  613. /**
  614. * Post Share - Float Style
  615. */
  616.  
  617. public function share_float_style_class() {
  618. if ( vp_metabox( 'jnews_single_post.override_template' ) && vp_metabox( 'jnews_single_post.override.0.share_float_style' ) ) {
  619. echo vp_metabox( 'jnews_single_post.override.0.share_float_style' );
  620. } else {
  621. echo get_theme_mod( 'jnews_single_share_float_style', 'share-monocrhome' );
  622. }
  623. }
  624.  
  625. /**
  626. * Post Meta
  627. */
  628. public function render_post_meta() {
  629. if ( $this->show_post_meta() ) {
  630. $template = $this->get_template();
  631.  
  632. switch ( $template ) {
  633. case '1' :
  634. case '3' :
  635. case '4' :
  636. case '6' :
  637. case '7' :
  638. case '8' :
  639. case '9' :
  640. get_template_part( 'fragment/post/meta-post-1' );
  641. break;
  642. case '2' :
  643. case '5' :
  644. case '10' :
  645. default :
  646. get_template_part( 'fragment/post/meta-post-2' );
  647. break;
  648. }
  649. }
  650. }
  651.  
  652. public function is_subtitle_empty() {
  653. $subtitle = $this->render_subtitle();
  654.  
  655. return empty( $subtitle );
  656. }
  657.  
  658. public function render_subtitle() {
  659. $subtitle = wp_kses( get_post_meta( $this->post_id, 'post_subtitle', true ), wp_kses_allowed_html() );
  660.  
  661. return apply_filters( 'jnews_single_subtitle', $subtitle, $this->post_id );
  662. }
  663.  
  664. public function show_post_meta() {
  665. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  666. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_meta' );
  667. } else {
  668. $flag = get_theme_mod( 'jnews_single_show_post_meta', true );
  669. }
  670.  
  671. return apply_filters( 'jnews_single_show_post_meta', $flag, $this->post_id );
  672. }
  673.  
  674. public function show_author_meta_image() {
  675. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  676. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_author_image' );
  677. } else {
  678. $flag = get_theme_mod( 'jnews_single_show_post_author_image', true );
  679. }
  680.  
  681. return apply_filters( 'jnews_single_show_post_author_image', $flag, $this->post_id );
  682. }
  683.  
  684. public function show_author_meta() {
  685. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  686. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_author' );
  687. } else {
  688. $flag = get_theme_mod( 'jnews_single_show_post_author', true );
  689. }
  690.  
  691. return apply_filters( 'jnews_single_show_post_author', $flag, $this->post_id );
  692. }
  693.  
  694. public function show_date_meta() {
  695. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  696. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_date' );
  697. } else {
  698. $flag = get_theme_mod( 'jnews_single_show_post_date', true );
  699. }
  700.  
  701. return apply_filters( 'jnews_single_show_post_date', $flag, $this->post_id );
  702. }
  703.  
  704. public function get_date_format() {
  705. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  706. $format = vp_metabox( 'jnews_single_post.override.0.post_date_format', 'default' );
  707.  
  708. if ( $format === 'custom' ) {
  709. $format = vp_metabox( 'jnews_single_post.override.0.post_date_format_custom', 'Y/m/d' );
  710. }
  711. } else {
  712. $format = get_theme_mod( 'jnews_single_post_date_format', 'default' );
  713.  
  714. if ( $format === 'custom' ) {
  715. $format = get_theme_mod( 'jnews_single_post_date_format_custom', 'Y/m/d' );
  716. }
  717. }
  718.  
  719. return apply_filters( 'jnews_single_post_date_format_custom', $format, $this->post_id );
  720. }
  721.  
  722. public function show_category_meta() {
  723. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  724. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_category' );
  725. } else {
  726. $flag = get_theme_mod( 'jnews_single_show_category', true );
  727. }
  728.  
  729. return apply_filters( 'jnews_single_show_category', $flag, $this->post_id );
  730. }
  731.  
  732. public function show_comment_meta() {
  733. $flag = get_theme_mod( 'jnews_single_comment', true );
  734.  
  735. return apply_filters( 'jnews_single_comment', $flag, $this->post_id );
  736. }
  737.  
  738. public function show_reading_time_meta() {
  739. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  740. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_reading_time' );
  741. } else {
  742. $flag = get_theme_mod( 'jnews_single_reading_time', false );
  743. }
  744.  
  745. return apply_filters( 'jnews_single_show_reading_time', $flag, $this->post_id );
  746. }
  747.  
  748. public function show_zoom_button_meta() {
  749. $flag = jnews_show_zoom_button();
  750.  
  751. return apply_filters( 'jnews_single_show_zoom_button', $flag, $this->post_id );
  752. }
  753.  
  754. public function zoom_button_meta() {
  755. if ( $this->show_zoom_button_meta() && is_single() ) {
  756. $output = '';
  757.  
  758. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  759. $zoom_out_step = vp_metabox( 'jnews_single_post.override.0.zoom_button_out_step', 2 );
  760. $zoom_in_step = vp_metabox( 'jnews_single_post.override.0.zoom_button_in_step', 3 );
  761. } else {
  762. $zoom_out_step = get_theme_mod( 'jnews_single_zoom_button_out_step', 2 );
  763. $zoom_in_step = get_theme_mod( 'jnews_single_zoom_button_in_step', 3 );
  764. }
  765.  
  766. $output = '<div class="jeg_meta_zoom" data-in-step="'. $zoom_in_step .'" data-out-step="'. $zoom_out_step .'">
  767. <div class="zoom-dropdown">
  768. <div class="zoom-icon">
  769. <span class="zoom-icon-small">A</span>
  770. <span class="zoom-icon-big">A</span>
  771. </div>
  772. <div class="zoom-item-wrapper">
  773. <div class="zoom-item">
  774. <button class="zoom-out"><span>A</span></button>
  775. <button class="zoom-in"><span>A</span></button>
  776. <div class="zoom-bar-container">
  777. <div class="zoom-bar"></div>
  778. </div>
  779. <button class="zoom-reset"><span>'. jnews_return_translation( 'Reset', 'jnews', 'zoom_reset' ) .'</span></button>
  780. </div>
  781. </div>
  782. </div>
  783. </div>';
  784.  
  785. echo jnews_sanitize_by_pass( $output );
  786. }
  787. }
  788.  
  789. public function reading_time_meta() {
  790.  
  791. if ( $this->show_reading_time_meta() ) {
  792.  
  793. $output = '';
  794.  
  795. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  796. $wpm = (int) vp_metabox( 'jnews_single_post.override.0.post_reading_time_wpm' );
  797. } else {
  798. $wpm = (int) get_theme_mod( 'jnews_single_reading_time_wpm', 300 );
  799. }
  800.  
  801. $content = get_post_field( 'post_content', $this->post_id );
  802.  
  803. if ( $content && $wpm ) {
  804. $content = strip_shortcodes( $content );
  805. $word_count = str_word_count( $content );
  806. $word_count = ceil( $word_count / $wpm );
  807. $reading_time = jnews_return_translation( 'Reading Time: ', 'jnews', 'reading_time' );
  808. if ( defined( 'JNEWS_FRONT_TRANSLATION' ) ) {
  809. $reading_time .= sprintf( _n( jnews_return_translation( '%d min read', 'jnews', 'min_read_s' ), jnews_return_translation( '%d mins read', 'jnews', 'min_read_p', 'jnews' ), $word_count ), $word_count );
  810. } else {
  811. $reading_time .= sprintf( _n( '%d min read', '%d mins read', $word_count, 'jnews' ), $word_count );
  812. }
  813.  
  814. if ( $word_count ) {
  815. $output =
  816. "<div class=\"jeg_meta_reading_time\">
  817. <span>
  818. " . $reading_time . "
  819. </span>
  820. </div>";
  821. }
  822. }
  823.  
  824. echo jnews_sanitize_by_pass( $output );
  825. }
  826. }
  827.  
  828. public function trending_post_meta( $post_id ) {
  829. if ( $this->get_template() === 'custom' ) {
  830. return false;
  831. }
  832.  
  833. $output = '';
  834. $flag = vp_metabox( 'jnews_single_post.trending_post', null, $post_id );
  835. $position = vp_metabox( 'jnews_single_post.trending_post_position', 'meta', $post_id );
  836.  
  837. if ( $flag && $position === 'meta' ) {
  838. $output = "<div class=\"jeg_meta_trending\"><i class=\"fa fa-bolt\"></i></div>";
  839. }
  840.  
  841. echo jnews_sanitize_by_pass( $output );
  842. }
  843.  
  844. public function trending_post_title( $post_id ) {
  845. if ( $this->get_template() === 'custom' ) {
  846. return false;
  847. }
  848.  
  849. $output = '';
  850. $flag = vp_metabox( 'jnews_single_post.trending_post', null, $post_id );
  851. $position = vp_metabox( 'jnews_single_post.trending_post_position', 'meta', $post_id );
  852.  
  853. if ( $flag && $position === 'title' ) {
  854. $label = $position === 'title' ? '<strong>' . vp_metabox( 'jnews_single_post.trending_post_label', '', $post_id ) . '</strong>' : '';
  855. $output = "<div class=\"jeg_meta_trending\"><i class=\"fa fa-bolt\"></i>{$label}</div>";
  856. }
  857.  
  858. echo jnews_sanitize_by_pass( $output );
  859. }
  860.  
  861. public function post_tag_render() {
  862. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  863. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_tag' );
  864. } else {
  865. $flag = get_theme_mod( 'jnews_single_show_tag', true );
  866. }
  867.  
  868. if ( $flag ) {
  869. $this->render_post_tag();
  870. }
  871. }
  872.  
  873. public function render_post_tag() {
  874. echo get_the_tag_list( '', '', '' );
  875. }
  876.  
  877. /**
  878. * Featured Post
  879. */
  880. public function render_featured_post_alternate() {
  881. $format = get_post_format();
  882.  
  883. if ( $format === 'video' || $format === 'gallery' ) {
  884. $this->render_featured_post();
  885. }
  886. }
  887.  
  888. public function render_featured_post() {
  889. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  890. $flag = vp_metabox( 'jnews_single_post.override.0.show_featured' );
  891. } else {
  892. if ( get_theme_mod( 'jnews_single_show_featured', true ) ) {
  893. $format = get_post_format();
  894. switch ($format) {
  895. case 'video':
  896. $flag = get_theme_mod( 'jnews_single_show_featured_video', true );
  897. break;
  898. case 'gallery':
  899. $flag = get_theme_mod( 'jnews_single_show_featured_gallery', true );
  900. break;
  901. default:
  902. $flag = get_theme_mod( 'jnews_single_show_featured_image', true );
  903. }
  904. } else {
  905. $flag = false;
  906. }
  907. }
  908.  
  909. $current_page = jnews_get_post_current_page();
  910. if ( $flag && ( $current_page === 1 || ! apply_filters( 'jnews_single_first_split_featured', false, $this->post_id ) ) ) {
  911. $this->feature_post_1();
  912. }
  913. }
  914.  
  915. public function get_featured_post_image_size( $size ) {
  916. $template = $this->get_template();
  917.  
  918. if ( $template === '1' || $template === '2' || $template === '4' || $template === '5' || $template === '6' || $template === '8' || $template === '10' ) {
  919. if ( $this->has_sidebar() ) {
  920. $width_image = false;
  921. } else {
  922. $width_image = true;
  923. }
  924. } else {
  925. $width_image = true;
  926. }
  927.  
  928. if ( ! $width_image ) {
  929. switch ( $size ) {
  930. case 'no-crop' :
  931. $image_size = 'jnews-featured-750';
  932. break;
  933. case 'crop-500';
  934. $image_size = 'jnews-750x375';
  935. break;
  936. case 'crop-715':
  937. $image_size = 'jnews-750x536';
  938. break;
  939. default :
  940. $image_size = 'jnews-750x375';
  941. }
  942. } else {
  943. switch ( $size ) {
  944. case 'no-crop' :
  945. $image_size = 'jnews-featured-1140';
  946. break;
  947. case 'crop-500';
  948. $image_size = 'jnews-1140x570';
  949. break;
  950. case 'crop-715':
  951. $image_size = 'jnews-1140x815';
  952. break;
  953. default :
  954. $image_size = 'jnews-1140x570';
  955. }
  956. }
  957.  
  958. return $image_size;
  959. }
  960.  
  961. public function get_single_thumbnail_size() {
  962. if ( vp_metabox( 'jnews_single_post.override_image_size', null, $this->post_id ) ) {
  963. $image_size = vp_metabox( 'jnews_single_post.image_override.0.single_post_thumbnail_size', 'crop-500', $this->post_id );
  964. } else {
  965. $image_size = get_theme_mod( 'jnews_single_post_thumbnail_size', 'crop-500' );
  966. }
  967.  
  968. return $this->get_featured_post_image_size( $image_size );
  969. }
  970.  
  971. public function get_gallery_thumbnail_size() {
  972. if ( vp_metabox( 'jnews_single_post.override_image_size', null, $this->post_id ) ) {
  973. $image_size = vp_metabox( 'jnews_single_post.image_override.0.single_post_gallery_size', 'crop-500', $this->post_id );
  974. } else {
  975. $image_size = get_theme_mod( 'jnews_single_post_gallery_size', 'crop-500' );
  976. }
  977.  
  978. return $this->get_featured_post_image_size( $image_size );
  979. }
  980.  
  981. public function feature_post_1( $image_size = null, $gallery_size = null, $id = null, $class = null ) {
  982. $format = get_post_format();
  983.  
  984. switch ( $format ) {
  985. case 'gallery' :
  986. if ( $gallery_size === null ) {
  987. $gallery_size = $this->get_gallery_thumbnail_size();
  988. }
  989. $output = $this->featured_gallery( $gallery_size, $id, $class );
  990. break;
  991. case 'video' :
  992. $output = "<div {$id} class='jeg_feature_video_wrapper {$class}'>" . $this->featured_video() . "</div>";
  993. break;
  994. default :
  995. if ( $image_size === null ) {
  996. $image_size = $this->get_single_thumbnail_size();
  997. }
  998. $output = $this->featured_image( $image_size, $id, $class );
  999. break;
  1000. }
  1001.  
  1002. echo jnews_sanitize_output( $output );
  1003. }
  1004.  
  1005. public function featured_gallery( $size, $id = null, $class = null ) {
  1006. $size = apply_filters( 'jnews_featured_gallery_image_size', $size );
  1007. $dimension = jnews_get_image_dimension_by_name( $size );
  1008. $output = '';
  1009. $images = get_post_meta( $this->post_id, '_format_gallery_images', true );
  1010.  
  1011. if ( $images ) {
  1012. if ( ( SCRIPT_DEBUG || get_theme_mod( 'jnews_load_necessary_asset', false ) ) && ! is_user_logged_in() ) {
  1013. $frontend_assets = \JNews\Asset\FrontendAsset::getInstance();
  1014. $frontend_assets->load_style();
  1015. $frontend_assets->load_script();
  1016. }
  1017. $output = "<div {$id} class=\"jeg_featured thumbnail-container jeg_owlslider size-{$dimension} {$class}\">";
  1018. $output .= "<div class=\"featured_gallery\">";
  1019.  
  1020. $popup = get_theme_mod( 'jnews_single_popup_script', 'magnific' );
  1021.  
  1022. foreach ( $images as $key => $image_id ) {
  1023. $image = wp_get_attachment_image_src( $image_id, 'full' );
  1024. $image_url = isset( $image[0] ) ? $image[0] : '';
  1025.  
  1026. $output .= ( $popup !== 'disable' ) ? "<a href=\"{$image_url}\">" : "";
  1027. $image_mechanism = ! get_theme_mod( 'jnews_single_post_thumbnail_force_normal_load', false ) ? 'jnews_single_image_lazy_owl' : 'jnews_single_image_owl';
  1028. if ( 'jnews_single_image_owl' === $image_mechanism && 0 >= $key ) {
  1029. $output .= \JNews\Image\ImageNormalLoad::getInstance()->owl_single_image( $image_id, $size );
  1030. } else {
  1031. $output .= apply_filters( 'jnews_single_image_lazy_owl', $image_id, $size );
  1032. }
  1033. $output .= ( $popup !== 'disable' ) ? "</a>" : "";
  1034. }
  1035.  
  1036. $output .= "</div>";
  1037. $output .= "</div>";
  1038. if ( ( SCRIPT_DEBUG || get_theme_mod( 'jnews_load_necessary_asset', false ) ) && ! is_user_logged_in() ) {
  1039. wp_print_styles('jnews-global-slider');
  1040. wp_print_scripts('tiny-slider-noconflict');
  1041. }
  1042. }
  1043.  
  1044. return apply_filters( 'jnews_featured_gallery', $output, $this->post_id );
  1045. }
  1046.  
  1047.  
  1048. public function featured_image( $size, $id = null, $class = null ) {
  1049. $output = "<div {$id} class=\"jeg_featured featured_image {$class}\">";
  1050.  
  1051. $popup = get_theme_mod( 'jnews_single_popup_script', 'magnific' );
  1052. $image_src = $this->get_featured_image_src( 'full' );
  1053.  
  1054. if ( has_post_thumbnail() ) {
  1055. $output .= ( $popup !== 'disable' ) ? "<a href=\"{$image_src}\">" : "";
  1056. if ( ! get_theme_mod( 'jnews_single_post_thumbnail_force_normal_load', false ) ) {
  1057. $output .= apply_filters( 'jnews_image_thumbnail_unwrap', $this->post_id, $size );
  1058. } else {
  1059. $output .= \JNews\Image\ImageNormalLoad::getInstance()->image_thumbnail_unwrap( $this->post_id, $size );
  1060. }
  1061. $output .= ( $popup !== 'disable' ) ? "</a>" : "";
  1062. }
  1063.  
  1064. $output .= "</div>";
  1065.  
  1066. return apply_filters( 'jnews_featured_image', $output, $this->post_id );
  1067. }
  1068.  
  1069. public function get_featured_image_src( $size ) {
  1070. $post_thumbnail_id = get_post_thumbnail_id( $this->post_id );
  1071. $image = wp_get_attachment_image_src( $post_thumbnail_id, $size );
  1072.  
  1073. return isset( $image[0] ) ? $image[0] : false;
  1074. }
  1075.  
  1076. public function featured_video() {
  1077. $following = defined( 'JNEWS_AUTOLOAD_POST' ) ? false : get_theme_mod( 'jnews_single_following_video', false );
  1078. $position = get_theme_mod( 'jnews_single_following_video_position', 'top_right' );
  1079. $output = "<div class=\"jeg_featured featured_video {$position}\" data-following='{$following}' data-position='{$position}'><div class='jeg_featured_video_wrapper'>";
  1080.  
  1081. $video_url = get_post_meta( $this->post_id, '_format_video_embed', true );
  1082. if ( class_exists( '\JNews\Paywall\Truncater\Truncater' ) ) {
  1083. if ( \JNews\Paywall\Truncater\Truncater::instance()->check_status() ) {
  1084. if ( jeg_metabox( 'jnews_paywall_metabox.enable_preview_video', false, $this->post_id ) ) {
  1085. $video_url = jeg_metabox( 'jnews_paywall_metabox.video_preview_url', '', $this->post_id );
  1086. }
  1087. }
  1088. }
  1089. $video_format = strtolower( pathinfo( $video_url, PATHINFO_EXTENSION ) );
  1090. $featured_img = jnews_get_image_src( get_post_thumbnail_id( $this->post_id ), 'jnews-featured-750' );
  1091.  
  1092. if ( $video_url=== '' ) {
  1093. $output .= "<div class=\"jeg_video_container\" style=\"display: none;\"></div>";
  1094. } else if ( jnews_check_video_type( $video_url ) === 'youtube' ) {
  1095. $output .=
  1096. "<div data-src=\"" . esc_url( $video_url ) . "\" data-type=\"youtube\" data-repeat=\"false\" data-autoplay=\"false\" class=\"youtube-class clearfix\">
  1097. <div class=\"jeg_video_container\"></div>
  1098. </div>";
  1099. } else if ( jnews_check_video_type( $video_url ) === 'vimeo' ) {
  1100. $output .=
  1101. "<div data-src=\"" . esc_url( $video_url ) . "\" data-repeat=\"false\" data-autoplay=\"false\" data-type=\"vimeo\" class=\"vimeo-class clearfix\">
  1102. <div class=\"jeg_video_container\"></div>
  1103. </div>";
  1104. } else if ( jnews_check_video_type( $video_url ) === 'dailymotion' ) {
  1105. $output .=
  1106. "<div data-src=\"" . esc_url( $video_url ) . "\" data-repeat=\"false\" data-autoplay=\"false\" data-type=\"dailymotion\" class=\"dailymotion-class clearfix\">
  1107. <div class=\"jeg_video_container\"></div>
  1108. </div>";
  1109. } else if ( $video_format == 'mp4' ) {
  1110. $output .=
  1111. "<div class=\"jeg_video_container\">
  1112. <video width=\"640\" height=\"360\" style=\"width: 100%; height: 100%;\" poster=\"" . esc_attr( $featured_img ) . "\" controls preload=\"none\" >
  1113. <source type=\"video/mp4\" src=\"" . esc_url( $video_url ) . "\">
  1114. </video>
  1115. </div>";
  1116. } else if ( wp_oembed_get( $video_url ) ) {
  1117. $output .= "<div class=\"jeg_video_container\">" . wp_oembed_get( $video_url ) . "</div>";
  1118. } else {
  1119. $output .= "<div class=\"jeg_video_container\">" . $video_url . "</div>";
  1120. }
  1121.  
  1122. $output .= "<div class='floating_close'></div></div></div>";
  1123.  
  1124. return apply_filters( 'jnews_featured_video', $output, $this->post_id );
  1125. }
  1126.  
  1127. /**
  1128. * Next Prev Post
  1129. */
  1130. public function prev_next_post() {
  1131. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  1132. $flag = vp_metabox( 'jnews_single_post.override.0.show_prev_next_post' );
  1133. } else {
  1134. $flag = get_theme_mod( 'jnews_single_show_prev_next_post', true );
  1135. }
  1136.  
  1137. $show_prev_next = apply_filters( 'jnews_single_show_prev_next_post', $flag, $this->post_id );
  1138.  
  1139. if ( $show_prev_next ) {
  1140. get_template_part( 'fragment/post/prev-next-post' );
  1141. }
  1142. }
  1143.  
  1144. /**
  1145. * Popup Post
  1146. */
  1147. public function popup_post() {
  1148. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  1149. $flag = vp_metabox( 'jnews_single_post.override.0.show_popup_post' );
  1150. $number = vp_metabox( 'jnews_single_post.override.0.number_popup_post' );
  1151. } else {
  1152. $flag = get_theme_mod( 'jnews_single_show_popup_post', true );
  1153. $number = get_theme_mod( 'jnews_single_number_popup_post', 1 );
  1154. }
  1155.  
  1156. $show_popup_post = apply_filters( 'jnews_single_show_popup_post', $flag, $this->post_id );
  1157.  
  1158. if ( $show_popup_post ) {
  1159. set_query_var( 'number_popup_post', $number );
  1160. get_template_part( 'fragment/post/popup-post' );
  1161. }
  1162. }
  1163.  
  1164. /**
  1165. * Check author box option
  1166. *
  1167. * @return bool|mixed|void
  1168. */
  1169. public function check_author_box() {
  1170. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  1171. $flag = vp_metabox( 'jnews_single_post.override.0.show_author_box' );
  1172. } else {
  1173. $flag = get_theme_mod( 'jnews_single_show_author_box', false );
  1174. }
  1175.  
  1176. return apply_filters( 'jnews_single_show_author_box', $flag, $this->post_id );
  1177. }
  1178.  
  1179. /**
  1180. * Author Box
  1181. */
  1182. public function author_box() {
  1183. $show_author_box = $this->check_author_box();
  1184.  
  1185. if ( $show_author_box ) {
  1186. get_template_part( 'fragment/post/author-box' );
  1187. }
  1188. }
  1189.  
  1190. public function recursive_category( $categories, &$result ) {
  1191. foreach ( $categories as $category ) {
  1192. $result[] = $category;
  1193. $children = get_categories( array( 'parent' => $category->term_id ) );
  1194.  
  1195. if ( ! empty( $children ) ) {
  1196. $this->recursive_category( $children, $result );
  1197. }
  1198. }
  1199. }
  1200.  
  1201. /**
  1202. * Check if we can render related post
  1203. *
  1204. * @return boolean
  1205. */
  1206. public function can_render_related_post() {
  1207. if ( apply_filters( 'jnews_force_disable_related_post', true ) ) {
  1208. return false;
  1209. }
  1210.  
  1211. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  1212. $flag = vp_metabox( 'jnews_single_post.override.0.show_post_related' );
  1213. } else {
  1214. $flag = get_theme_mod( 'jnews_single_show_post_related', false );
  1215. }
  1216.  
  1217. return $flag;
  1218. }
  1219.  
  1220. /**
  1221. * Check if we can render inline related post
  1222. *
  1223. * @return boolean
  1224. */
  1225. public function can_render_inline_related_post() {
  1226. if ( apply_filters( 'jnews_force_disable_inline_related_post', false ) ) {
  1227. return false;
  1228. }
  1229.  
  1230. if ( function_exists( 'is_amp_endpoint' ) ) {
  1231. if ( is_amp_endpoint() ) {
  1232. return false;
  1233. }
  1234. }
  1235.  
  1236. if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  1237. $flag = vp_metabox( 'jnews_single_post.override.0.show_inline_post_related' );
  1238. } else {
  1239. $flag = get_theme_mod( 'jnews_single_post_show_inline_related', false );
  1240. }
  1241.  
  1242. return $flag;
  1243. }
  1244.  
  1245. /**
  1246. * @param bool|true $echo
  1247. *
  1248. * @return array|string
  1249. */
  1250. public function related_post( $echo = true ) {
  1251. if ( $this->can_render_related_post() ) {
  1252. $content_width = is_numeric( $this->main_content_width() ) ? $this->main_content_width() : 8;
  1253.  
  1254. do_action( 'jnews_module_set_width', $content_width );
  1255. $post_per_page = get_theme_mod( 'jnews_single_number_post_related', 6 );
  1256.  
  1257. $match = get_theme_mod( 'jnews_single_post_related_match', 'category' );
  1258. $category = $tag = $result = array();
  1259. if ( $match === 'category' ) {
  1260. $this->recursive_category( get_the_category(), $result );
  1261.  
  1262. if ( $result ) {
  1263. foreach ( $result as $cat ) {
  1264. $category[] = $cat->term_id;
  1265. }
  1266. }
  1267. } else if ( $match === 'tag' ) {
  1268. $tags = get_the_tags();
  1269. if ( $tags ) {
  1270. foreach ( $tags as $cat ) {
  1271. $tag[] = $cat->term_id;
  1272. }
  1273. }
  1274. }
  1275.  
  1276. $attr = array(
  1277. 'first_title' => get_theme_mod( 'jnews_single_post_related_override_title', false ) ? get_theme_mod( 'jnews_single_post_related_ftitle', 'Related' ) : jnews_return_translation( 'Related', 'jnews', 'related' ),
  1278. 'second_title' => get_theme_mod( 'jnews_single_post_related_override_title', false ) ? get_theme_mod( 'jnews_single_post_related_stitle', 'Posts' ) : jnews_return_translation( ' Posts', 'jnews', 'posts' ),
  1279. 'header_type' => get_theme_mod( 'jnews_single_post_related_header', 'heading_6' ),
  1280. 'date_format' => get_theme_mod( 'jnews_single_post_related_date', 'default' ),
  1281. 'date_format_custom' => get_theme_mod( 'jnews_single_post_related_date_custom', 'Y/m/d' ),
  1282. 'excerpt_length' => get_theme_mod( 'jnews_single_post_related_excerpt', 20 ),
  1283. 'pagination_number_post' => $post_per_page,
  1284. 'number_post' => $post_per_page,
  1285. 'unique_content' => get_theme_mod( 'jnews_single_post_related_unique_content', 'disable' ),
  1286. 'include_category' => implode( ',', $category ),
  1287. 'include_tag' => implode( ',', $tag ),
  1288. 'exclude_post' => $this->post_id,
  1289. 'sort_by' => get_theme_mod( 'jnews_single_post_related_sort_by', 'latest' ),
  1290. 'pagination_mode' => get_theme_mod( 'jnews_single_post_pagination_related', 'disable' ),
  1291. 'pagination_scroll_limit' => get_theme_mod( 'jnews_single_post_auto_load_related', 3 ),
  1292. 'paged' => 1,
  1293. );
  1294.  
  1295. $name = 'JNews_Block_' . get_theme_mod( 'jnews_single_post_related_template', '22' );
  1296. $name = jnews_get_view_class_from_shortcode( $name );
  1297.  
  1298. /** @var $content_instance BlockViewAbstract */
  1299. $content_instance = jnews_get_module_instance( $name );
  1300. $result = $content_instance->build_module( $attr );
  1301.  
  1302. if ( $echo ) {
  1303. echo jnews_sanitize_output( $result );
  1304. } else {
  1305. return $result;
  1306. }
  1307. }
  1308. }
  1309.  
  1310. public function render_inline_related_post( $content ) {
  1311. if ( get_post_type() === 'post' && is_single() && ! is_admin() ) {
  1312. if ( $this->can_render_inline_related_post() ) {
  1313. $tag = new ContentTag( $content );
  1314. $pnumber = $tag->total( 'p' );
  1315.  
  1316. $paragraph = get_theme_mod( 'jnews_single_post_inline_related_paragraph', 2 );
  1317. $random = get_theme_mod( 'jnews_single_post_inline_related_random', false );
  1318. $class = get_theme_mod( 'jnews_single_post_inline_related_float', 'left' );
  1319. $fullwidth = get_theme_mod( 'jnews_single_post_inline_related_fullwidth', false );
  1320.  
  1321. if ( $random && is_array( $pnumber ) ) {
  1322. $maxparagraph = count( $pnumber ) - 2;
  1323. $paragraph = rand( $paragraph, $maxparagraph );
  1324. }
  1325.  
  1326. if ( ! $fullwidth ) {
  1327. $class .= ' half';
  1328. }
  1329.  
  1330. $related_content =
  1331. "<div class='jnews_inline_related_post_wrapper {$class}'>
  1332. " . $this->build_inline_related_post() . "
  1333. </div>";
  1334.  
  1335. $content = $this->prefix_insert_after_paragraph( $related_content, $paragraph, $tag );
  1336. }
  1337. }
  1338.  
  1339. return $content;
  1340. }
  1341.  
  1342. public function build_inline_related_post() {
  1343. $match = get_theme_mod( 'jnews_single_post_inline_related_match', 'category' );
  1344. $related_width = get_theme_mod( 'jnews_single_post_inline_related_fullwidth', false ) ? 8 : 4;
  1345. $post_per_page = get_theme_mod( 'jnews_single_post_inline_related_number', 3 );
  1346. $tag = $category = $result = array();
  1347.  
  1348. do_action( 'jnews_module_set_width', $related_width );
  1349.  
  1350. if ( $match === 'category' ) {
  1351. $this->recursive_category( get_the_category(), $result );
  1352.  
  1353. if ( $result ) {
  1354. foreach ( $result as $cat ) {
  1355. $category[] = $cat->term_id;
  1356. }
  1357. }
  1358. } else if ( $match === 'tag' ) {
  1359. $tags = get_the_tags();
  1360. if ( $tags ) {
  1361. foreach ( $tags as $cat ) {
  1362. $tag[] = $cat->term_id;
  1363. }
  1364. }
  1365. }
  1366.  
  1367. $attr = array(
  1368. 'first_title' => get_theme_mod( 'jnews_single_post_inline_related_ftitle', 'Related' ),
  1369. 'second_title' => get_theme_mod( 'jnews_single_post_inline_related_stitle', 'Posts' ),
  1370. 'header_type' => get_theme_mod( 'jnews_single_post_inline_related_header', 'heading_6' ),
  1371. 'date_format' => get_theme_mod( 'jnews_single_post_inline_related_date', 'default' ),
  1372. 'date_format_custom' => get_theme_mod( 'jnews_single_post_inline_related_date_custom', 'Y/m/d' ),
  1373. 'pagination_number_post' => $post_per_page,
  1374. 'number_post' => $post_per_page,
  1375. 'unique_content' => get_theme_mod( 'jnews_single_post_inline_related_unique_content', 'disable' ),
  1376. 'include_category' => implode( ',', $category ),
  1377. 'include_tag' => implode( ',', $tag ),
  1378. 'exclude_post' => $this->post_id,
  1379. 'sort_by' => get_theme_mod( 'jnews_single_post_inline_related_sort_by', 'latest' ),
  1380. 'pagination_mode' => get_theme_mod( 'jnews_single_post_inline_related_pagination', 'nextprev' ),
  1381. 'paged' => 1,
  1382. );
  1383.  
  1384. $name = 'JNews_Block_' . get_theme_mod( 'jnews_single_post_inline_related_template', '29' );
  1385. $name = jnews_get_view_class_from_shortcode( $name );
  1386.  
  1387. /** @var $content_instance BlockViewAbstract */
  1388. $content_instance = jnews_get_module_instance( $name );
  1389. $result = $content_instance->build_module( $attr );
  1390.  
  1391. $output =
  1392. "<div class='jnews_inline_related_post'>
  1393. {$result}
  1394. </div>";
  1395.  
  1396. return $output;
  1397. }
  1398.  
  1399. /**
  1400. * Filter jnews_ads_global_enable
  1401. *
  1402. * @param boolean $flag Flag of ads.
  1403. * @param int|false $post_id The ID of the current item in the WordPress Loop. False if $post is not set.
  1404. *
  1405. * @return boolean
  1406. */
  1407. public function ads_post_enable( $flag, $post_id ) {
  1408. if ( get_post_type() === 'post' && is_single() && $flag ) {
  1409. return ! vp_metabox( 'jnews_single_post.disable_ad', false, $post_id );
  1410. }
  1411. return $flag;
  1412. }
  1413.  
  1414. /**
  1415. * @param $insertion
  1416. * @param $paragraph_id
  1417. * @param $tag ContentTag
  1418. *
  1419. * @return string
  1420. */
  1421. protected function prefix_insert_after_paragraph( $insertion, $paragraph_id, $tag ) {
  1422. $end = get_theme_mod( 'jnews_single_post_inline_related_overflow', 'top' ) === 'top' ? false : true;
  1423. $line = $tag->find( 'p', $paragraph_id, $end );
  1424.  
  1425. return jeg_string_insert( $tag->get_content(), $insertion, $line );
  1426. }
  1427. }
  1428.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement