Guest User

Untitled

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