Guest User

Untitled

a guest
Jul 11th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.16 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by ra on 2/20/2015.
  4. */
  5. class td_module_single_base extends td_module {
  6.  
  7. var $td_post_theme_settings;
  8.  
  9. var $is_single; //true if we are on a single page
  10.  
  11.  
  12.  
  13. function __construct($post = '') {
  14.  
  15. //run the parent constructor
  16. parent::__construct($post);
  17.  
  18. //read post settings
  19. $this->td_post_theme_settings = td_util::get_post_meta_array($post->ID, 'td_post_theme_settings');
  20.  
  21. $this->is_single = is_single();
  22. }
  23.  
  24.  
  25.  
  26.  
  27. function get_post_pagination() {
  28. if (!$this->is_single) {
  29. return '';
  30. }
  31. return wp_link_pages(array(
  32. 'before' => '<div class="page-nav page-nav-post td-pb-padding-side">',
  33. 'after' => '</div>',
  34. 'link_before' => '<div>',
  35. 'link_after' => '</div>',
  36. 'echo' => false,
  37. 'nextpagelink' => '<i class="td-icon-menu-right"></i>',
  38. 'previouspagelink' => '<i class="td-icon-menu-left"></i>'
  39. ));
  40. }
  41.  
  42.  
  43. /**
  44. * Gets the article title on single pages and on modules that use this class as a base (module15 on Newsmag for example).
  45. * @param string $cut_at - not used, it's added to maintain strict standards
  46. * @return string
  47. */
  48. function get_title($cut_at = '') {
  49. $buffy = '';
  50. if (!empty($this->title)) {
  51. $buffy .= '<h1 class="entry-title">';
  52. if ($this->is_single === true) {
  53. $buffy .= $this->title;
  54. } else {
  55. $buffy .='<a href="' . $this->href . '" rel="bookmark" title="' . $this->title_attribute . '">';
  56. $buffy .= $this->title;
  57. $buffy .='</a>';
  58. }
  59. $buffy .= '</h1>';
  60. }
  61.  
  62. return $buffy;
  63. }
  64.  
  65. //$show_stars_on_review - not used
  66. function get_author() {
  67. $buffy = '';
  68. if (td_util::get_option('tds_p_show_author_name') != 'hide') {
  69. $buffy .= '<div class="td-post-author-name"><div class="td-author-by">' . __td('By', TD_THEME_NAME) . '</div> ';
  70. $buffy .= '<a href="' . get_author_posts_url($this->post->post_author) . '">' . get_the_author_meta('display_name', $this->post->post_author) . '</a>' ;
  71.  
  72. if (td_util::get_option('tds_p_show_author_name') != 'hide' and td_util::get_option('tds_p_show_date') != 'hide') {
  73. $buffy .= '<div class="td-author-line"> - </div> ';
  74. }
  75. $buffy .= '</div>';
  76. }
  77. return $buffy;
  78. }
  79.  
  80.  
  81. /**
  82. * v3 23 ian 2015
  83. * @param $thumbType
  84. * @return string
  85. */
  86. function get_image($thumbType, $css_image = false) {
  87. global $page;
  88.  
  89.  
  90. // if ( //check to see if the current single template is configured to show the featured image on the second page
  91. // !isset( td_global::$single_templates_list[td_global::$cur_single_template]['show_featured_image_on_all_pages'] )
  92. // or td_global::$single_templates_list[td_global::$cur_single_template]['show_featured_image_on_all_pages'] === false
  93. // ){
  94.  
  95. if (td_api_single_template::_check_show_featured_image_on_all_pages(td_global::$cur_single_template) === false) {
  96. //the post is configured to show the featured image only on the first page
  97. if (!empty($page) and $page > 1) {
  98. return '';
  99. }
  100. }
  101.  
  102.  
  103. //do not show the featured image if the global setting is set to hide - show the video preview regardless of the setting
  104. if (td_util::get_option('tds_show_featured_image') == 'hide' and get_post_format($this->post->ID) != 'video') {
  105. return '';
  106. }
  107.  
  108. //handle video post format
  109. if (get_post_format($this->post->ID) == 'video') {
  110. //if it's a video post...
  111. $td_post_video = td_util::get_post_meta_array($this->post->ID, 'td_post_video');
  112.  
  113. //render the video if the post has a video in the featured video section of the post
  114. if (!empty($td_post_video['td_video'])) {
  115. return td_video_support::render_video($td_post_video['td_video']);
  116. }
  117. } else {
  118. //if it's a normal post, show the default thumb
  119.  
  120. if (!is_null($this->post_thumb_id)) {
  121. //get the featured image id + full info about the 640px wide one
  122. $featured_image_id = get_post_thumbnail_id($this->post->ID);
  123. $featured_image_info = td_util::attachment_get_full_info($featured_image_id, $thumbType);
  124.  
  125. //retina image
  126. $srcset_sizes = td_util::get_srcset_sizes($featured_image_id, $thumbType, $featured_image_info['width'], $featured_image_info['src']);
  127.  
  128. //get the full size for the popup
  129. $featured_image_full_size_src = td_util::attachment_get_src($featured_image_id, 'full');
  130.  
  131. $buffy = '';
  132.  
  133. $show_td_modal_image = td_util::get_option('tds_featured_image_view_setting') ;
  134.  
  135. if (is_single()) {
  136. if ($show_td_modal_image != 'no_modal') {
  137. //wrap the image_html with a link + add td-modal-image class
  138. $image_html = '<a href="' . $featured_image_full_size_src['src'] . '" data-caption="' . esc_attr($featured_image_info['caption'], ENT_QUOTES) . '">';
  139. $image_html .= '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" class="entry-thumb td-modal-image" src="' . $featured_image_info['src'] . '"' . $srcset_sizes . ' alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/>';
  140. $image_html .= '</a>';
  141. } else { //no_modal
  142. $image_html = '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" class="entry-thumb" src="' . $featured_image_info['src'] . '"' . $srcset_sizes . ' alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/>';
  143. }
  144. } else {
  145. //on blog index page
  146. $image_html = '<a href="' . $this->href . '"><img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" class="entry-thumb" src="' . $featured_image_info['src'] . '"' . $srcset_sizes . ' alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/></a>';
  147. }
  148.  
  149.  
  150. $buffy .= '<div class="td-post-featured-image">';
  151.  
  152. // caption - put html5 wrapper on when we have a caption
  153. if (!empty($featured_image_info['caption'])) {
  154. $buffy .= '<figure>';
  155. $buffy .= $image_html;
  156.  
  157. $buffy .= '<figcaption class="wp-caption-text">' . $featured_image_info['caption'] . '</figcaption>';
  158. $buffy .= '</figure>';
  159. } else {
  160. $buffy .= $image_html;
  161. }
  162.  
  163. $buffy .= '</div>';
  164.  
  165.  
  166. return $buffy;
  167. } else {
  168. return ''; //the post has no thumb
  169. }
  170. }
  171. }
  172.  
  173.  
  174. /**
  175. * get the category spot of the single post / single post type
  176. * @return string - the html of the spot
  177. */
  178. function get_category() {
  179. $terms_ui_array = array();
  180.  
  181.  
  182. if ($this->post->post_type != 'post') {
  183.  
  184. // CUSTOM POST TYPES - on custom post types, we retrieve the taxonomy setting from the panel and we show
  185. // only the ones that are selected in wp-admin, just like a normal theme
  186. $category_spot_taxonomy = td_util::get_ctp_option($this->post->post_type, 'tds_category_spot_taxonomy');
  187. $terms_for_category_spot = wp_get_post_terms($this->post->ID, $category_spot_taxonomy);
  188. foreach ($terms_for_category_spot as $term_for_category_spot) {
  189. $term_for_category_spot_url = get_term_link($term_for_category_spot, $category_spot_taxonomy);
  190. if (!is_wp_error($term_for_category_spot_url)) {
  191. $terms_ui_array[ $term_for_category_spot->name ] = array(
  192. 'color' => '',
  193. 'link' => $term_for_category_spot_url,
  194. 'hide_on_post' => ''
  195. );
  196. }
  197. }
  198.  
  199. } else {
  200. // POST TYPE - here we work with categories
  201. // NOTE: due to legacy, the theme also outputs the parent of the first category if available
  202. $categories = get_the_category( $this->post->ID );
  203. if (!empty($categories)) {
  204. foreach ( $categories as $category ) {
  205. if ( $category->name != TD_FEATURED_CAT ) { //ignore the featured category name
  206. //get the parent of this cat
  207. //$td_parent_cat_obj = get_category( $category->category_parent );
  208.  
  209. //if we have a parent and the default category display is disabled show it first
  210. if ( ! empty( $td_parent_cat_obj->name ) and td_util::get_option('tds_default_category_display') != 'true') {
  211. $tax_meta__color_parent = td_util::get_category_option( $td_parent_cat_obj->cat_ID, 'tdc_color' );//swich by RADU A, get_tax_meta($td_parent_cat_obj->cat_ID,'tdc_color');
  212. $tax_meta__hide_on_post_parent = td_util::get_category_option( $td_parent_cat_obj->cat_ID, 'tdc_hide_on_post' );//swich by RADU A, get_tax_meta($td_parent_cat_obj->cat_ID,'tdc_hide_on_post');
  213. $terms_ui_array[ $td_parent_cat_obj->name ] = array(
  214. 'color' => $tax_meta__color_parent,
  215. 'link' => get_category_link( $td_parent_cat_obj->cat_ID ),
  216. 'hide_on_post' => $tax_meta__hide_on_post_parent
  217. );
  218. }
  219.  
  220. //show the category, only if we didn't already showed the parent
  221. $tax_meta_color = td_util::get_category_option( $category->cat_ID, 'tdc_color' );//swich by RADU A, get_tax_meta($category->cat_ID,'tdc_color');
  222. $tax_meta__hide_on_post_parent = td_util::get_category_option( $category->cat_ID, 'tdc_hide_on_post' );//swich by RADU A, get_tax_meta($category->cat_ID,'tdc_hide_on_post');
  223. $terms_ui_array[ $category->name ] = array(
  224. 'color' => $tax_meta_color,
  225. 'link' => get_category_link( $category->cat_ID ),
  226. 'hide_on_post' => $tax_meta__hide_on_post_parent
  227. );
  228. }
  229. }
  230. }
  231. }
  232.  
  233.  
  234. /**
  235. * output stage
  236. * we go in with an array of:
  237. * array (
  238. * $terms_ui_array[category_name] = array (
  239. * 'color' => '',
  240. * 'link' => ''
  241. * 'hide_on_post'
  242. * )
  243. * )
  244. */
  245. $buffy = '';
  246. if (td_util::get_option('tds_p_categories_tags') != 'hide') {
  247. $buffy .= '<ul class="td-category">';
  248.  
  249.  
  250. foreach ( $terms_ui_array as $term_name => $term_params ) {
  251. if ( $term_params['hide_on_post'] == 'hide' ) {
  252. continue;
  253. }
  254.  
  255. if ( ! empty( $term_params['color'] ) ) {
  256. // set title color based on background color contrast
  257. $td_cat_title_color = td_util::readable_colour($term_params['color'], 200, 'rgba(0, 0, 0, 0.9)', '#fff');
  258. $td_cat_color = ' style="background-color:' . $term_params['color'] . '; color:' . $td_cat_title_color . '; border-color:' . $term_params['color'] . ';"';
  259. } else {
  260. $td_cat_color = '';
  261. }
  262.  
  263.  
  264. $buffy .= '<li class="entry-category"><a ' . $td_cat_color . ' href="' . $term_params['link'] . '">' . $term_name . '</a></li>';
  265. }
  266. $buffy .= '</ul>';
  267. }
  268.  
  269. return $buffy;
  270. }
  271.  
  272.  
  273. function get_date($show_stars_on_review = true) {
  274. $visibility_class = '';
  275. if (td_util::get_option('tds_p_show_date') == 'hide') {
  276. $visibility_class = ' td-visibility-hidden';
  277. }
  278.  
  279. $buffy = '';
  280. if ($this->is_review and $show_stars_on_review === true) {
  281. //if review show stars
  282. $buffy .= '<div class="entry-review-stars">';
  283. $buffy .= td_review::render_stars($this->td_review);
  284. $buffy .= '</div>';
  285.  
  286. } else {
  287. if (td_util::get_option('tds_p_show_date') != 'hide') {
  288. $td_article_date_unix = get_the_time('U', $this->post->ID);
  289. $buffy .= '<span class="td-post-date">';
  290. $buffy .= '<time class="entry-date updated td-module-date' . $visibility_class . '" datetime="' . date(DATE_W3C, $td_article_date_unix) . '" >' . get_the_time(get_option('date_format'), $this->post->ID) . '</time>';
  291. $buffy .= '</span>';
  292. }
  293. }
  294.  
  295. return $buffy;
  296. }
  297.  
  298.  
  299. function get_comments() {
  300. $buffy = '';
  301. if (td_util::get_option('tds_p_show_comments') != 'hide') {
  302. $buffy .= '<div class="td-post-comments">';
  303. $buffy .= '<a href="' . get_comments_link($this->post->ID) . '"><i class="td-icon-comments"></i>';
  304. $buffy .= get_comments_number($this->post->ID);
  305. $buffy .= '</a>';
  306. $buffy .= '</div>';
  307. }
  308.  
  309. return $buffy;
  310. }
  311.  
  312. function get_views() {
  313. $buffy = '';
  314. if (td_util::get_option('tds_p_show_views') != 'hide') {
  315. $buffy .= '<div class="td-post-views">';
  316. $buffy .= '<i class="td-icon-views"></i>';
  317. // WP-Post Views Counter
  318. if (function_exists('the_views')) {
  319. $post_views = the_views(false);
  320. $buffy .= $post_views;
  321. }
  322. // Default Theme Views Counter
  323. else {
  324. $buffy .= '<span class="td-nr-views-' . $this->post->ID . '">' . td_page_views::get_page_views($this->post->ID) .'</span>';
  325. }
  326.  
  327. $buffy .= '</div>';
  328. }
  329. return $buffy;
  330. }
  331.  
  332.  
  333. /**
  334. * the content of a single post or single post type
  335. * @return mixed|string|void
  336. */
  337. function get_content() {
  338.  
  339. /* ----------------------------------------------------------------------------
  340. Prepare the content
  341. */
  342. $content = get_the_content(__td('Continue', TD_THEME_NAME));
  343. $content = apply_filters('the_content', $content);
  344. $content = str_replace(']]>', ']]&gt;', $content);
  345.  
  346.  
  347.  
  348. /** ----------------------------------------------------------------------------
  349. * Smart list support. class_exists and new object WORK VIA AUTOLOAD
  350. * @see td_autoload_classes::loading_classes
  351. */
  352. //$td_smart_list = get_post_meta($this->post->ID, 'td_smart_list', true);
  353. $td_post_theme_settings = td_util::get_post_meta_array($this->post->ID, 'td_post_theme_settings');
  354. if (!empty($td_post_theme_settings['smart_list_template'])) {
  355.  
  356. $td_smart_list_class = $td_post_theme_settings['smart_list_template'];
  357. if (class_exists($td_smart_list_class)) {
  358. /**
  359. * @var $td_smart_list_obj td_smart_list
  360. */
  361. $td_smart_list_obj = new $td_smart_list_class(); // make the class from string * magic :)
  362.  
  363. // prepare the settings for the smart list
  364. $smart_list_settings = array(
  365. 'post_content' => $content,
  366. 'counting_order_asc' => false,
  367. 'td_smart_list_h' => 'h3',
  368. 'extract_first_image' => td_api_smart_list::get_key($td_smart_list_class, 'extract_first_image')
  369. );
  370.  
  371. if (!empty($td_post_theme_settings['td_smart_list_order'])) {
  372. $smart_list_settings['counting_order_asc'] = true;
  373. }
  374.  
  375. if (!empty($td_post_theme_settings['td_smart_list_h'])) {
  376. $smart_list_settings['td_smart_list_h'] = $td_post_theme_settings['td_smart_list_h'];
  377. }
  378. return $td_smart_list_obj->render_from_post_content($smart_list_settings);
  379. } else {
  380. // there was an error?
  381. td_util::error(__FILE__, 'Missing smart list: ' . $td_smart_list_class . '. Did you disabled a tagDiv plugin?');
  382. }
  383. }
  384. /* ----------------------------------------------------------------------------
  385. end smart list - if we have a list, the function returns above
  386. */
  387.  
  388.  
  389.  
  390.  
  391. /* ----------------------------------------------------------------------------
  392. ad support on content
  393. */
  394.  
  395. //read the current ad settings
  396. $tds_inline_ad_paragraph = td_util::get_option('tds_inline_ad_paragraph');
  397. $tds_inline_ad_align = td_util::get_option('tds_inline_ad_align');
  398.  
  399. //ads titles
  400. $tds_inline_ad_title = td_util::get_option('tds_content_inline_title');
  401. $tds_bottom_ad_title = td_util::get_option('tds_content_bottom_title');
  402. $tds_top_ad_title = td_util::get_option('tds_content_top_title');
  403.  
  404. //show the inline ad at the last paragraph ( replacing the bottom ad ) whenever there are not as many paragraphs mentioned in After Paragraph field
  405. // ..and the article bottom ad is not active
  406. $show_inline_ad_at_bottom = false;
  407.  
  408. //add the inline ad
  409. if (td_util::is_ad_spot_enabled('content_inline') and is_single()) {
  410. if (empty($tds_inline_ad_paragraph)) {
  411. $tds_inline_ad_paragraph = 0;
  412. }
  413.  
  414. $content_buffer = ''; // we replace the content with this buffer at the end
  415. $content_parts = preg_split('/(<blockquote.*\/blockquote>)/Us', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  416.  
  417. $p_open_tag_count = 0; // count how many <p> tags we have added to the buffer
  418. foreach ($content_parts as $content_part_index => $content_part_value) {
  419. if (!empty($content_part_value)) {
  420.  
  421. //skip <blockquote> parts - look for <p> in the other parts
  422. if (preg_match('/(<blockquote.*>)/U', $content_part_value) !== 1) {
  423. $section_parts = preg_split('/(<p.*>)/U', $content_part_value, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  424.  
  425. foreach ($section_parts as $section_part_index => $section_part_value) {
  426. if (!empty($section_part_value)) {
  427. // Show the ad ONLY IF THE CURRENT PART IS A <p> opening tag and before the <p> -> so we will have <p>content</p> ~ad~ <p>content</p>
  428. // and prevent cases like <p> ~ad~ content</p>
  429. if (preg_match('/(<p.*>)/U', $section_part_value) === 1) {
  430. if ($tds_inline_ad_paragraph == $p_open_tag_count) {
  431. $show_inline_ad_at_bottom = true;
  432. switch ($tds_inline_ad_align) {
  433. case 'left':
  434. $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'left', 'spot_title' => $tds_inline_ad_title ));
  435. break;
  436.  
  437. case 'right':
  438. $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'right', 'spot_title' => $tds_inline_ad_title));
  439. break;
  440.  
  441. default:
  442. $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'spot_title' => $tds_inline_ad_title));
  443. break;
  444. }
  445. }
  446. $p_open_tag_count ++;
  447. }
  448. //add section to buffer
  449. $content_buffer .= $section_part_value;
  450. }
  451. }
  452.  
  453. } else {
  454. //add <blockquote> to buffer
  455. $content_buffer .= $content_part_value;
  456. }
  457. }
  458. }
  459. $content = $content_buffer;
  460. }
  461.  
  462.  
  463. //add the top ad
  464. if (td_util::is_ad_spot_enabled('content_top') && is_single()) {
  465.  
  466. //disable the top ad on post template 1, it breaks the layout, the top image and ad should float on the left side of the content
  467. if (!empty($td_post_theme_settings['td_post_template'])) {
  468. $td_default_site_post_template = $td_post_theme_settings['td_post_template'];
  469.  
  470. //if the post individual template is not set, check the global settings, if template 1 is set disable the top ad
  471. } else {
  472. $td_default_site_post_template = td_util::get_option('td_default_site_post_template');
  473. }
  474.  
  475. //default post template - is empty, check td_api_single_template::_helper_td_global_list_to_metaboxes()
  476. if (empty($td_default_site_post_template)) {
  477. $td_default_site_post_template = 'single_template';
  478. }
  479.  
  480. //check if ad is excluded from current post template
  481. if (td_api_single_template::get_key($td_default_site_post_template, 'exclude_ad_content_top') === false) {
  482. $content = td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_top', 'spot_title' => $tds_top_ad_title)) . $content;
  483. }
  484. }
  485.  
  486.  
  487. //add bottom ad
  488. if (td_util::is_ad_spot_enabled('content_bottom') && is_single()) {
  489. $content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_bottom', 'spot_title' => $tds_bottom_ad_title));
  490. } else {
  491. if ( $show_inline_ad_at_bottom !== true ) {
  492. switch ($tds_inline_ad_align) {
  493. case 'left':
  494. $content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'left', 'spot_title' => $tds_inline_ad_title ));
  495. break;
  496.  
  497. case 'right':
  498. $content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'right', 'spot_title' => $tds_inline_ad_title));
  499. break;
  500.  
  501. default:
  502. $content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'spot_title' => $tds_inline_ad_title));
  503. break;
  504. }
  505. }
  506. }
  507.  
  508. return $content;
  509. }
  510.  
  511.  
  512. /**
  513. * returns the item scope for single pages. If we have an article or a review
  514. * @return string
  515. */
  516. function get_item_scope() {
  517. //show the review meta only on single posts that are reviews, the rest have to be article (in article lists)
  518. if ($this->is_review && is_single()) {
  519. return 'itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Review"';
  520. } else {
  521. return 'itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Article"';
  522. }
  523. }
  524.  
  525.  
  526. /**
  527. * This method outputs the item scope for SINGLE templates. If you are looking for the modules @see td_module::get_item_scope_meta()
  528. * @updated 23 july 2015
  529. * - if the module that uses this class is not on a single page, we use the @see td_module::get_item_scope_meta() this allows
  530. * us to output normal module item scope insted of no item scope like it was before this update
  531. * @updated 16 december 2015
  532. * - removed structured data from modules, now it displays only on single and it returns the current post data
  533. * - no more interference with the itemprop's coming from modules
  534. * - all single structured data is now gathered here
  535. * @return string
  536. */
  537. function get_item_scope_meta() {
  538.  
  539. // don't display meta on pages
  540. if (!is_single()) {
  541. return '';
  542. }
  543.  
  544. // determine publisher name - use author name if there's no blog name
  545. $td_publisher_name = get_bloginfo('name');
  546. if (empty($td_publisher_name)){
  547. $td_publisher_name = esc_attr(get_the_author_meta('display_name', $this->post->post_author));
  548. }
  549. // determine publisher logo
  550. $td_publisher_logo = td_util::get_option('tds_logo_upload');
  551.  
  552. $buffy = ''; //the vampire slayer
  553.  
  554. // author
  555. $buffy .= '<span style="display: none;" itemprop="author" itemscope itemtype="https://schema.org/Person">' ;
  556. $buffy .= '<meta itemprop="name" content="' . esc_attr(get_the_author_meta('display_name', $this->post->post_author)) . '">' ;
  557. $buffy .= '</span>' ;
  558.  
  559. // datePublished
  560. $td_article_date_unix = get_the_time('U', $this->post->ID);
  561. $buffy .= '<meta itemprop="datePublished" content="' . date(DATE_W3C, $td_article_date_unix) . '">';
  562.  
  563. // dateModified
  564. $buffy .= '<meta itemprop="dateModified" content="' . the_modified_date('c', '', '', false) . '">';
  565.  
  566. // mainEntityOfPage
  567. $buffy .= '<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="' . get_permalink($this->post->ID) .'"/>';
  568.  
  569. // publisher
  570. $buffy .= '<span style="display: none;" itemprop="publisher" itemscope itemtype="https://schema.org/Organization">';
  571. $buffy .= '<span style="display: none;" itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">';
  572. $buffy .= '<meta itemprop="url" content="' . $td_publisher_logo . '">';
  573. $buffy .= '</span>';
  574. $buffy .= '<meta itemprop="name" content="' . $td_publisher_name . '">';
  575. $buffy .= '</span>';
  576.  
  577. // headline @todo we may improve this one to use the subtitle or excerpt? - We could not find specs about what it should be.
  578. $buffy .= '<meta itemprop="headline " content="' . esc_attr( $this->post->post_title) . '">';
  579.  
  580. // featured image
  581. $td_image = array();
  582. if (!is_null($this->post_thumb_id)) {
  583. /**
  584. * from google documentation:
  585. * A URL, or list of URLs pointing to the representative image file(s). Images must be
  586. * at least 160x90 pixels and at most 1920x1080 pixels.
  587. * We recommend images in .jpg, .png, or. gif formats.
  588. * https://developers.google.com/structured-data/rich-snippets/articles
  589. */
  590. $td_image = wp_get_attachment_image_src($this->post_thumb_id, 'full');
  591.  
  592. } else {
  593. // when the post has no image use the placeholder
  594. $td_image[0] = get_template_directory_uri() . '/images/no-thumb/td_meta_replacement.png';
  595. $td_image[1] = '1068';
  596. $td_image[2] = '580';
  597. }
  598.  
  599. // ImageObject meta
  600. if (!empty($td_image[0])) {
  601. $buffy .= '<span style="display: none;" itemprop="image" itemscope itemtype="https://schema.org/ImageObject">';
  602. $buffy .= '<meta itemprop="url" content="' . $td_image[0] . '">';
  603. $buffy .= '<meta itemprop="width" content="' . $td_image[1] . '">';
  604. $buffy .= '<meta itemprop="height" content="' . $td_image[2] . '">';
  605. $buffy .= '</span>';
  606. }
  607.  
  608. // if we have a review, we must add additional stuff
  609. if ($this->is_review) {
  610.  
  611. // the item that is reviewd
  612. $buffy .= '<span style="display: none;" itemprop="itemReviewed" itemscope itemtype="https://schema.org/Thing">';
  613. $buffy .= '<meta itemprop="name " content = "' . $this->title_attribute . '">';
  614. $buffy .= '</span>';
  615.  
  616. if (!empty($this->td_review['review'])) {
  617. $buffy .= '<meta itemprop="reviewBody" content = "' . esc_attr($this->td_review['review']) . '">';
  618. } else {
  619. //we have no review text :| get a excerpt for the about meta thing
  620. if ($this->post->post_excerpt != '') {
  621. $td_post_excerpt = $this->post->post_excerpt;
  622. } else {
  623. $td_post_excerpt = td_util::excerpt($this->post->post_content, 45);
  624. }
  625. $buffy .= '<meta itemprop="reviewBody" content = "' . esc_attr($td_post_excerpt) . '">';
  626. }
  627.  
  628. // review rating
  629. $buffy .= '<span style="display: none;" class="td-page-meta" itemprop="reviewRating" itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Rating">';
  630. $buffy .= '<meta itemprop="worstRating" content = "1">';
  631. $buffy .= '<meta itemprop="bestRating" content = "5">';
  632. $buffy .= '<meta itemprop="ratingValue" content = "' . td_review::calculate_total_stars($this->td_review) . '">';
  633. $buffy .= ' </span>';
  634. }
  635. return $buffy;
  636. }
  637.  
  638.  
  639. /**
  640. * returns the review at the bottom of single posts and single posts types
  641. * @return string
  642. */
  643. function get_review() {
  644. if (!$this->is_single) {
  645. return '';
  646. }
  647.  
  648. if ($this->is_review) {
  649. //print_r($this->td_review);
  650. $buffy = '';
  651. $buffy .= td_review::render_table($this->td_review);
  652.  
  653.  
  654.  
  655. return $buffy;
  656. }
  657.  
  658. }
  659.  
  660.  
  661. /**
  662. * gets the source and via spot on single posts and single custom post types
  663. * @return string|void
  664. */
  665. function get_source_and_via() {
  666. if (!$this->is_single) {
  667. return;
  668. }
  669.  
  670.  
  671. $buffy ='';
  672.  
  673. //via and source
  674. if (!empty($this->td_post_theme_settings['td_source']) or !empty($this->td_post_theme_settings['td_via'])) {
  675. $via_url = '#';
  676. $source_url = '#';
  677.  
  678. // used to check is post have tags to align the source and via container
  679. $td_no_tags = '';
  680. if (!has_tag()) {
  681. $td_no_tags = 'td-no-tags';
  682. }
  683.  
  684. if (!empty($this->td_post_theme_settings['td_via_url'])) {
  685. $via_url = $this->td_post_theme_settings['td_via_url'];
  686. }
  687.  
  688. if (!empty($this->td_post_theme_settings['td_source_url'])) {
  689. $source_url = $this->td_post_theme_settings['td_source_url'];
  690. }
  691.  
  692. $buffy .= '<div class="td-post-source-via ' . $td_no_tags . '">';
  693. if (!empty($this->td_post_theme_settings['td_via'])) {
  694. $buffy .= '<div class="td-post-small-box"><span>' . __td('VIA', TD_THEME_NAME) . '</span><a rel="nofollow" href="' . esc_url($via_url) . '">' . $this->td_post_theme_settings['td_via'] . '</a></div>';
  695. }
  696.  
  697. if (!empty($this->td_post_theme_settings['td_source'])) {
  698. $buffy .= '<div class="td-post-small-box"><span>' . __td('SOURCE', TD_THEME_NAME) . '</span><a rel="nofollow" href="' . esc_url($source_url) . '">' . $this->td_post_theme_settings['td_source'] . '</a></div>';
  699. }
  700. $buffy .= '</div>';
  701. }
  702.  
  703.  
  704. return $buffy;
  705. }
  706.  
  707.  
  708. /**
  709. * get the tags spot of the single post or single custom post type
  710. * @return string
  711. */
  712. function get_the_tags() {
  713. if (td_util::get_option('tds_show_tags') == 'hide') {
  714. return '';
  715. }
  716.  
  717. $buffy = '';
  718.  
  719. $terms_ui_array = array();
  720. $tags_spot_text = __td('TAGS', TD_THEME_NAME); // the default text for tags - on CPT we can overwrite this via the panel
  721.  
  722. if ($this->post->post_type != 'post') {
  723. // on custom post types we need to read what to show in the tag spot from the panel
  724. $tag_spot_taxonomy = td_util::get_ctp_option($this->post->post_type, 'tds_tag_spot_taxonomy');
  725. $terms_for_tag_spot = wp_get_post_terms($this->post->ID, $tag_spot_taxonomy);
  726. foreach ($terms_for_tag_spot as $term_for_tag_spot) {
  727. $term_for_tag_spot_url = get_term_link($term_for_tag_spot, $tag_spot_taxonomy);
  728. if (!is_wp_error($term_for_tag_spot_url)) {
  729. $terms_ui_array[ $term_for_tag_spot->name ] = array(
  730. 'url' => $term_for_tag_spot_url,
  731. );
  732. }
  733. }
  734.  
  735. // also update the default tag spot text if it's set in the theme's panel
  736. $new_tag_spot_text = td_util::get_ctp_option($this->post->post_type, 'tds_tag_spot_text');
  737. if (!empty($new_tag_spot_text)) {
  738. $tags_spot_text = $new_tag_spot_text;
  739. }
  740. } else {
  741. // on single posts we deal with tags
  742. $td_post_tags = get_the_tags();
  743. if (!empty($td_post_tags)) {
  744. foreach ($td_post_tags as $tag) {
  745. $terms_ui_array[$tag->name] = array (
  746. 'url' => get_tag_link($tag->term_id)
  747. );
  748. }
  749. }
  750. }
  751.  
  752.  
  753.  
  754. /**
  755. * output stage
  756. * we go in with an array of
  757. * array (
  758. * $terms_ui_array[tag_name] = array (
  759. * 'url' => '',
  760. * )
  761. * )
  762. */
  763. if (!empty($terms_ui_array)) {
  764. $buffy .= '<ul class="td-tags td-post-small-box clearfix">';
  765. $buffy .= '<li><span>' . $tags_spot_text . '</span></li>';
  766. foreach ($terms_ui_array as $term_name => $term_params) {
  767. $buffy .= '<li><a href="' . $term_params['url'] . '">' . $term_name . '</a></li>';
  768. }
  769. $buffy .= '</ul>';
  770. }
  771.  
  772. return $buffy;
  773. }
  774.  
  775.  
  776. /**
  777. * get the next and previous links on single posts and single custom post types
  778. * @return string
  779. */
  780. function get_next_prev_posts() {
  781. if (!$this->is_single) {
  782. return '';
  783. }
  784.  
  785. if (td_util::get_option('tds_show_next_prev') == 'hide') {
  786. return '';
  787. }
  788.  
  789. $buffy = '';
  790.  
  791. $next_post = get_next_post();
  792. $prev_post = get_previous_post();
  793.  
  794. if (!empty($next_post) or !empty($prev_post)) {
  795. $buffy .= '<div class="td-block-row td-post-next-prev">';
  796. if (!empty($prev_post)) {
  797. $buffy .= '<div class="td-block-span6 td-post-prev-post">';
  798. $buffy .= '<div class="td-post-next-prev-content"><span>' .__td('Previous article', TD_THEME_NAME) . '</span>';
  799. $buffy .= '<a href="' . esc_url(get_permalink($prev_post->ID)) . '">' . get_the_title( $prev_post->ID ) . '</a>';
  800. $buffy .= '</div>';
  801. $buffy .= '</div>';
  802. } else {
  803. $buffy .= '<div class="td-block-span6 td-post-prev-post">';
  804. $buffy .= '</div>';
  805. }
  806. $buffy .= '<div class="td-next-prev-separator"></div>';
  807. if (!empty($next_post)) {
  808. $buffy .= '<div class="td-block-span6 td-post-next-post">';
  809. $buffy .= '<div class="td-post-next-prev-content"><span>' .__td('Next article', TD_THEME_NAME) . '</span>';
  810. $buffy .= '<a href="' . esc_url(get_permalink($next_post->ID)) . '">' . get_the_title( $next_post->ID ) . '</a>';
  811. $buffy .= '</div>';
  812. $buffy .= '</div>';
  813. }
  814. $buffy .= '</div>'; //end fluid row
  815. }
  816.  
  817. return $buffy;
  818. }
  819.  
  820.  
  821. /**
  822. * gets the author on single posts and single custom post types
  823. * @param string $author_id
  824. * @return string|void
  825. */
  826. function get_author_box($author_id = '') {
  827.  
  828. if (!$this->is_single) {
  829. return '';
  830. }
  831.  
  832.  
  833. if (empty($author_id)) {
  834. $author_id = $this->post->post_author;
  835. }
  836.  
  837. // add the author as hidden for google and return if the author box is set to disabled
  838. if (td_util::get_option('tds_show_author_box') == 'hide') {
  839. $buffy = '<div class="td-author-name vcard author" style="display: none"><span class="fn">';
  840. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' . get_the_author_meta('display_name', $author_id) . '</a>' ;
  841. $buffy .= '</span></div>';
  842. return $buffy;
  843. }
  844.  
  845.  
  846.  
  847. $buffy = '';
  848.  
  849. $hideAuthor = td_util::get_option('hide_author');
  850.  
  851. if (empty($hideAuthor)) {
  852.  
  853. $buffy .= '<div class="author-box-wrap">';
  854. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' ;
  855. $buffy .= get_avatar(get_the_author_meta('email', $author_id), '96');
  856. $buffy .= '</a>';
  857.  
  858.  
  859. $buffy .= '<div class="desc">';
  860. $buffy .= '<div class="td-author-name vcard author"><span class="fn">';
  861. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' . get_the_author_meta('display_name', $author_id) . '</a>' ;
  862. $buffy .= '</span></div>';
  863.  
  864. if (get_the_author_meta('user_url', $author_id) != '') {
  865. $buffy .= '<div class="td-author-url"><a href="' . get_the_author_meta('user_url', $author_id) . '">' . get_the_author_meta('user_url', $author_id) . '</a></div>';
  866. }
  867.  
  868. $buffy .= '<div class="td-author-description">';
  869. $buffy .= get_the_author_meta('description', $author_id);
  870. $buffy .= '</div>';
  871.  
  872.  
  873. $buffy .= '<div class="td-author-social">';
  874. foreach (td_social_icons::$td_social_icons_array as $td_social_id => $td_social_name) {
  875. //echo get_the_author_meta($td_social_id) . '<br>';
  876. $authorMeta = get_the_author_meta($td_social_id);
  877. if (!empty($authorMeta)) {
  878.  
  879. //the theme can use the twitter id instead of the full url. This avoids problems with yoast plugin
  880. if ($td_social_id == 'twitter') {
  881. if(filter_var($authorMeta, FILTER_VALIDATE_URL)){
  882.  
  883. } else {
  884. $authorMeta = str_replace('@', '', $authorMeta);
  885. $authorMeta = 'http://twitter.com/' . $authorMeta;
  886. }
  887. }
  888. $buffy .= td_social_icons::get_icon($authorMeta, $td_social_id, true);
  889. }
  890. }
  891. $buffy .= '</div>';
  892.  
  893.  
  894.  
  895. $buffy .= '<div class="clearfix"></div>';
  896.  
  897. $buffy .= '</div>'; ////desc
  898. $buffy .= '</div>'; //author-box-wrap
  899. }
  900.  
  901.  
  902. return $buffy;
  903. }
  904.  
  905.  
  906. /**
  907. * gets the related posts ONLY on single posts. Does not run on custom post types because we don't know what taxonomy to choose and the
  908. * blocks do not support custom taxonomies as of 15 july 2015
  909. * @param string $force_sidebar_position - allows us to overwrite the sidebar position. Useful on templates where the related
  910. * articles appear outside of the loop - sidebar grid (like on the top)
  911. * @return string
  912. */
  913. function related_posts($force_sidebar_position = '') {
  914. global $post;
  915. if ($post->post_type != 'post') {
  916. return '';
  917. }
  918.  
  919. if (td_util::get_option('tds_similar_articles') == 'hide') {
  920. return '';
  921. }
  922.  
  923.  
  924.  
  925.  
  926.  
  927. //td_global::$cur_single_template_sidebar_pos;
  928.  
  929. //cur_post_same_tags
  930. //cur_post_same_author
  931. //cur_post_same_categories
  932.  
  933. if (td_util::get_option('tds_similar_articles_type') == 'by_tag') {
  934. $td_related_ajax_filter_type = 'cur_post_same_tags';
  935. } else {
  936. $td_related_ajax_filter_type = 'cur_post_same_categories';
  937. }
  938.  
  939.  
  940. // the number of rows to show. this number will be multiplied with the hardcoded limit
  941. $tds_similar_articles_rows = td_util::get_option('tds_similar_articles_rows');
  942. if (empty($tds_similar_articles_rows)) {
  943. $tds_similar_articles_rows = 1;
  944. }
  945.  
  946. if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar' or $force_sidebar_position === 'no_sidebar') {
  947. $td_related_limit = 5 * $tds_similar_articles_rows;
  948. $td_related_class = 'td-related-full-width';
  949. $td_column_number = 5;
  950. } else {
  951. $td_related_limit = 3 * $tds_similar_articles_rows;
  952. $td_related_class = '';
  953. $td_column_number = 3;
  954. }
  955.  
  956.  
  957.  
  958. /**
  959. * 'td_ajax_filter_type' => 'td_custom_related' - this ajax filter type overwrites the live filter via ajax @see td_ajax::on_ajax_block
  960. */
  961. $td_block_args = array (
  962. 'limit' => $td_related_limit,
  963. 'ajax_pagination' => 'next_prev',
  964. 'live_filter' => $td_related_ajax_filter_type, //live atts - this is the default setting for this block
  965. 'td_ajax_filter_type' => 'td_custom_related', //this filter type can overwrite the live filter @see
  966. 'class' => $td_related_class,
  967. 'td_column_number' => $td_column_number
  968. );
  969.  
  970.  
  971. /**
  972. * @see td_block_related_posts
  973. */
  974. return td_global_blocks::get_instance('td_block_related_posts')->render($td_block_args);
  975.  
  976. }
  977.  
  978.  
  979. }
Advertisement
Add Comment
Please, Sign In to add comment