Guest User

Untitled

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