Guest User

Untitled

a guest
Jan 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.77 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">' . __td('By', TD_THEME_NAME) . ' ';
  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 .= ' - ';
  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, shot it first
  208. if ( ! empty( $td_parent_cat_obj->name ) ) {
  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 = $this->readableColour($term_params['color']);
  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. /**
  272. * calculate the contrast of a color and return:
  273. * @param $bg - string (ex. #23f100)
  274. * @return string - #000 - for light background - #fff - for dark background
  275. */
  276. function readableColour($bg){
  277. $r = hexdec(substr($bg,1,2));
  278. $g = hexdec(substr($bg,3,2));
  279. $b = hexdec(substr($bg,5,2));
  280.  
  281. $contrast = sqrt(
  282. $r * $r * .241 +
  283. $g * $g * .691 +
  284. $b * $b * .068
  285. );
  286.  
  287. if($contrast > 200){
  288. return '#000';
  289. }else{
  290. return '#fff';
  291. }
  292. }
  293.  
  294.  
  295.  
  296.  
  297.  
  298. function get_comments() {
  299. $buffy = '';
  300. if (td_util::get_option('tds_p_show_comments') != 'hide') {
  301. $buffy .= '<div class="td-post-comments">';
  302. $buffy .= '<a href="' . get_comments_link($this->post->ID) . '"><i class="td-icon-comments"></i>';
  303. $buffy .= get_comments_number($this->post->ID);
  304. $buffy .= '</a>';
  305. $buffy .= '</div>';
  306. }
  307.  
  308. return $buffy;
  309. }
  310.  
  311. function get_views() {
  312. $buffy = '';
  313. if (td_util::get_option('tds_p_show_views') != 'hide') {
  314. $buffy .= '<div class="td-post-views">';
  315. $buffy .= '<i class="td-icon-views"></i>';
  316. // WP-Post Views Counter
  317. if (function_exists('the_views')) {
  318. $post_views = the_views(false);
  319. $buffy .= $post_views;
  320. }
  321. // Default Theme Views Counter
  322. else {
  323. $buffy .= '<span class="td-nr-views-' . $this->post->ID . '">' . td_page_views::get_page_views($this->post->ID) .'</span>';
  324. }
  325.  
  326. $buffy .= '</div>';
  327. }
  328. return $buffy;
  329. }
  330.  
  331.  
  332. /**
  333. * the content of a single post or single post type
  334. * @return mixed|string|void
  335. */
  336. function get_content() {
  337.  
  338. /* ----------------------------------------------------------------------------
  339. Prepare the content
  340. */
  341. $content = get_the_content(__td('Continue', TD_THEME_NAME));
  342. $content = apply_filters('the_content', $content);
  343. $content = str_replace(']]>', ']]&gt;', $content);
  344.  
  345.  
  346.  
  347. /** ----------------------------------------------------------------------------
  348. * Smart list support. class_exists and new object WORK VIA AUTOLOAD
  349. * @see td_autoload_classes::loading_classes
  350. */
  351. //$td_smart_list = get_post_meta($this->post->ID, 'td_smart_list', true);
  352. $td_smart_list = get_post_meta($this->post->ID, 'td_post_theme_settings', true);
  353. if (!empty($td_smart_list['smart_list_template'])) {
  354.  
  355. $td_smart_list_class = $td_smart_list['smart_list_template'];
  356. if (class_exists($td_smart_list_class)) {
  357. /**
  358. * @var $td_smart_list_obj td_smart_list
  359. */
  360. $td_smart_list_obj = new $td_smart_list_class(); // make the class from string * magic :)
  361.  
  362. // prepare the settings for the smart list
  363. $smart_list_settings = array(
  364. 'post_content' => $content,
  365. 'counting_order_asc' => false,
  366. 'td_smart_list_h' => 'h3',
  367. 'extract_first_image' => td_api_smart_list::get_key($td_smart_list_class, 'extract_first_image')
  368. );
  369.  
  370. if (!empty($td_smart_list['td_smart_list_order'])) {
  371. $smart_list_settings['counting_order_asc'] = true;
  372. }
  373.  
  374. if (!empty($td_smart_list['td_smart_list_h'])) {
  375. $smart_list_settings['td_smart_list_h'] = $td_smart_list['td_smart_list_h'];
  376. }
  377. return $td_smart_list_obj->render_from_post_content($smart_list_settings);
  378. } else {
  379. // there was an error?
  380. td_util::error(__FILE__, 'Missing smart list: ' . $td_smart_list_class . '. Did you disabled a tagDiv plugin?');
  381. }
  382. }
  383. /* ----------------------------------------------------------------------------
  384. end smart list - if we have a list, the function returns above
  385. */
  386.  
  387.  
  388. $allowed_tags = array('tag1','tag2','tag3','tag4');
  389. if (has_tag($allowed_tags, $this->post->ID)){
  390. $new_tag= true;
  391. }
  392.  
  393.  
  394. /* ----------------------------------------------------------------------------
  395. ad support on content
  396. */
  397.  
  398. //read the current ad settings
  399. $tds_inline_ad_paragraph = td_util::get_option('tds_inline_ad_paragraph');
  400. $tds_inline_ad_align = td_util::get_option('tds_inline_ad_align');
  401.  
  402.  
  403. //add the inline ad
  404. if (td_util::is_ad_spot_enabled('content_inline') and is_single() and $new_tag) {
  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'));
  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'));
  430. break;
  431.  
  432. default:
  433. $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline'));
  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. //add the top ad
  447. if (td_util::is_ad_spot_enabled('content_top') and is_single() and $new_tag) {
  448. $content = td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_top')) . $content;
  449. }
  450.  
  451.  
  452. //add bottom ad
  453. if (td_util::is_ad_spot_enabled('content_bottom') and is_single() and $new_tag) {
  454. $content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_bottom'));
  455. }
  456.  
  457.  
  458. return $content;
  459. }
  460.  
  461.  
  462. /**
  463. * returns the item scope for single pages. If we have an article or a review
  464. * @return string
  465. */
  466. function get_item_scope() {
  467. //show the review meta only on single posts that are reviews, the rest have to be article (in article lists)
  468. if ($this->is_review && is_single()) {
  469. return 'itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Review"';
  470. } else {
  471. return 'itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Article"';
  472. }
  473. }
  474.  
  475.  
  476. /**
  477. * This method outputs the item scope for SINGLE templates. If you are looking for the modules @see td_module::get_item_scope_meta()
  478. * @updated 23 july 2015
  479. * - 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
  480. * us to output normal module item scope insted of no item scope like it was before this update
  481. * @updated 16 december 2015
  482. * - removed structured data from modules, now it displays only on single and it returns the current post data
  483. * - no more interference with the itemprop's coming from modules
  484. * - all single structured data is now gathered here
  485. * @return string
  486. */
  487. function get_item_scope_meta() {
  488.  
  489. // don't display meta on pages
  490. if (!is_single()) {
  491. return '';
  492. }
  493.  
  494. // determine publisher name - use author name if there's no blog name
  495. $td_publisher_name = get_bloginfo('name');
  496. if (empty($td_publisher_name)){
  497. $td_publisher_name = esc_attr(get_the_author_meta('display_name', $this->post->post_author));
  498. }
  499. // determine publisher logo
  500. $td_publisher_logo = td_util::get_option('tds_logo_upload');
  501.  
  502. $buffy = ''; //the vampire slayer
  503.  
  504. // author
  505. $buffy .= '<span style="display: none;" itemprop="author" itemscope itemtype="https://schema.org/Person">' ;
  506. $buffy .= '<meta itemprop="name" content="' . esc_attr(get_the_author_meta('display_name', $this->post->post_author)) . '">' ;
  507. $buffy .= '</span>' ;
  508.  
  509. // datePublished
  510. $td_article_date_unix = get_the_time('U', $this->post->ID);
  511. $buffy .= '<meta itemprop="datePublished" content="' . date(DATE_W3C, $td_article_date_unix) . '">';
  512.  
  513. // dateModified
  514. $buffy .= '<meta itemprop="dateModified" content="' . the_modified_date('c', '', '', false) . '">';
  515.  
  516. // mainEntityOfPage
  517. $buffy .= '<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="' . get_permalink($this->post->ID) .'"/>';
  518.  
  519. // publisher
  520. $buffy .= '<span style="display: none;" itemprop="publisher" itemscope itemtype="https://schema.org/Organization">';
  521. $buffy .= '<span style="display: none;" itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">';
  522. $buffy .= '<meta itemprop="url" content="' . $td_publisher_logo . '">';
  523. $buffy .= '</span>';
  524. $buffy .= '<meta itemprop="name" content="' . $td_publisher_name . '">';
  525. $buffy .= '</span>';
  526.  
  527. // headline @todo we may improve this one to use the subtitle or excerpt? - We could not find specs about what it should be.
  528. $buffy .= '<meta itemprop="headline " content="' . esc_attr( $this->post->post_title) . '">';
  529.  
  530. // featured image
  531. $td_image = array();
  532. if (!is_null($this->post_thumb_id)) {
  533. /**
  534. * from google documentation:
  535. * A URL, or list of URLs pointing to the representative image file(s). Images must be
  536. * at least 160x90 pixels and at most 1920x1080 pixels.
  537. * We recommend images in .jpg, .png, or. gif formats.
  538. * https://developers.google.com/structured-data/rich-snippets/articles
  539. */
  540. $td_image = wp_get_attachment_image_src($this->post_thumb_id, 'full');
  541.  
  542. } else {
  543. // when the post has no image use the placeholder
  544. $td_image[0] = get_template_directory_uri() . '/images/no-thumb/td_meta_replacement.png';
  545. $td_image[1] = '1068';
  546. $td_image[2] = '580';
  547. }
  548.  
  549. // ImageObject meta
  550. if (!empty($td_image[0])) {
  551. $buffy .= '<span style="display: none;" itemprop="image" itemscope itemtype="https://schema.org/ImageObject">';
  552. $buffy .= '<meta itemprop="url" content="' . $td_image[0] . '">';
  553. $buffy .= '<meta itemprop="width" content="' . $td_image[1] . '">';
  554. $buffy .= '<meta itemprop="height" content="' . $td_image[2] . '">';
  555. $buffy .= '</span>';
  556. }
  557.  
  558. // if we have a review, we must add additional stuff
  559. if ($this->is_review) {
  560.  
  561. // the item that is reviewd
  562. $buffy .= '<span style="display: none;" itemprop="itemReviewed" itemscope itemtype="https://schema.org/Thing">';
  563. $buffy .= '<meta itemprop="name " content = "' . $this->title_attribute . '">';
  564. $buffy .= '</span>';
  565.  
  566. if (!empty($this->td_review['review'])) {
  567. $buffy .= '<meta itemprop="reviewBody" content = "' . esc_attr($this->td_review['review']) . '">';
  568. } else {
  569. //we have no review text :| get a excerpt for the about meta thing
  570. if ($this->post->post_excerpt != '') {
  571. $td_post_excerpt = $this->post->post_excerpt;
  572. } else {
  573. $td_post_excerpt = td_util::excerpt($this->post->post_content, 45);
  574. }
  575. $buffy .= '<meta itemprop="reviewBody" content = "' . esc_attr($td_post_excerpt) . '">';
  576. }
  577.  
  578. // review rating
  579. $buffy .= '<span style="display: none;" class="td-page-meta" itemprop="reviewRating" itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Rating">';
  580. $buffy .= '<meta itemprop="worstRating" content = "1">';
  581. $buffy .= '<meta itemprop="bestRating" content = "5">';
  582. $buffy .= '<meta itemprop="ratingValue" content = "' . td_review::calculate_total_stars($this->td_review) . '">';
  583. $buffy .= ' </span>';
  584. }
  585. return $buffy;
  586. }
  587.  
  588. /**
  589. * returns the review at the bottom of single posts and single posts types
  590. * @return string
  591. */
  592. function get_review() {
  593. if (!$this->is_single) {
  594. return '';
  595. }
  596.  
  597. if ($this->is_review) {
  598. //print_r($this->td_review);
  599. $buffy = '';
  600. $buffy .= td_review::render_table($this->td_review);
  601.  
  602.  
  603.  
  604. return $buffy;
  605. }
  606.  
  607. }
  608.  
  609.  
  610. /**
  611. * gets the source and via spot on single posts and single custom post types
  612. * @return string|void
  613. */
  614. function get_source_and_via() {
  615. if (!$this->is_single) {
  616. return;
  617. }
  618.  
  619.  
  620. $buffy ='';
  621.  
  622. //via and source
  623. if (!empty($this->td_post_theme_settings['td_source']) or !empty($this->td_post_theme_settings['td_via'])) {
  624. $via_url = '#';
  625. $source_url = '#';
  626.  
  627. // used to check is post have tags to align the source and via container
  628. $td_no_tags = '';
  629. if (!has_tag()) {
  630. $td_no_tags = 'td-no-tags';
  631. }
  632.  
  633. if (!empty($this->td_post_theme_settings['td_via_url'])) {
  634. $via_url = $this->td_post_theme_settings['td_via_url'];
  635. }
  636.  
  637. if (!empty($this->td_post_theme_settings['td_source_url'])) {
  638. $source_url = $this->td_post_theme_settings['td_source_url'];
  639. }
  640.  
  641. $buffy .= '<div class="td-post-source-via ' . $td_no_tags . '">';
  642. if (!empty($this->td_post_theme_settings['td_via'])) {
  643. $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>';
  644. }
  645.  
  646. if (!empty($this->td_post_theme_settings['td_source'])) {
  647. $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>';
  648. }
  649. $buffy .= '</div>';
  650. }
  651.  
  652.  
  653. return $buffy;
  654. }
  655.  
  656.  
  657. /**
  658. * get the tags spot of the single post or single custom post type
  659. * @return string
  660. */
  661. function get_the_tags() {
  662. if (td_util::get_option('tds_show_tags') == 'hide') {
  663. return '';
  664. }
  665.  
  666. $buffy = '';
  667.  
  668. $terms_ui_array = array();
  669. $tags_spot_text = __td('TAGS', TD_THEME_NAME); // the default text for tags - on CPT we can overwrite this via the panel
  670.  
  671. if ($this->post->post_type != 'post') {
  672. // on custom post types we need to read what to show in the tag spot from the panel
  673. $tag_spot_taxonomy = td_util::get_ctp_option($this->post->post_type, 'tds_tag_spot_taxonomy');
  674. $terms_for_tag_spot = wp_get_post_terms($this->post->ID, $tag_spot_taxonomy);
  675. foreach ($terms_for_tag_spot as $term_for_tag_spot) {
  676. $term_for_tag_spot_url = get_term_link($term_for_tag_spot, $tag_spot_taxonomy);
  677. if (!is_wp_error($term_for_tag_spot_url)) {
  678. $terms_ui_array[ $term_for_tag_spot->name ] = array(
  679. 'url' => $term_for_tag_spot_url,
  680. );
  681. }
  682. }
  683.  
  684. // also update the default tag spot text if it's set in the theme's panel
  685. $new_tag_spot_text = td_util::get_ctp_option($this->post->post_type, 'tds_tag_spot_text');
  686. if (!empty($new_tag_spot_text)) {
  687. $tags_spot_text = $new_tag_spot_text;
  688. }
  689. } else {
  690. // on single posts we deal with tags
  691. $td_post_tags = get_the_tags();
  692. if (!empty($td_post_tags)) {
  693. foreach ($td_post_tags as $tag) {
  694. $terms_ui_array[$tag->name] = array (
  695. 'url' => get_tag_link($tag->term_id)
  696. );
  697. }
  698. }
  699. }
  700.  
  701.  
  702.  
  703. /**
  704. * output stage
  705. * we go in with an array of
  706. * array (
  707. * $terms_ui_array[tag_name] = array (
  708. * 'url' => '',
  709. * )
  710. * )
  711. */
  712. if (!empty($terms_ui_array)) {
  713. $buffy .= '<ul class="td-tags td-post-small-box clearfix">';
  714. $buffy .= '<li><span>' . $tags_spot_text . '</span></li>';
  715. foreach ($terms_ui_array as $term_name => $term_params) {
  716. $buffy .= '<li><a href="' . $term_params['url'] . '">' . $term_name . '</a></li>';
  717. }
  718. $buffy .= '</ul>';
  719. }
  720.  
  721. return $buffy;
  722. }
  723.  
  724.  
  725. /**
  726. * get the next and previous links on single posts and single custom post types
  727. * @return string
  728. */
  729. function get_next_prev_posts() {
  730. if (!$this->is_single) {
  731. return '';
  732. }
  733.  
  734. if (td_util::get_option('tds_show_next_prev') == 'hide') {
  735. return '';
  736. }
  737.  
  738. $buffy = '';
  739.  
  740. $next_post = get_next_post();
  741. $prev_post = get_previous_post();
  742.  
  743. if (!empty($next_post) or !empty($prev_post)) {
  744. $buffy .= '<div class="td-block-row td-post-next-prev">';
  745. if (!empty($prev_post)) {
  746. $buffy .= '<div class="td-block-span6 td-post-prev-post">';
  747. $buffy .= '<div class="td-post-next-prev-content"><span>' .__td('Previous article', TD_THEME_NAME) . '</span>';
  748. $buffy .= '<a href="' . esc_url(get_permalink($prev_post->ID)) . '">' . get_the_title( $prev_post->ID ) . '</a>';
  749. $buffy .= '</div>';
  750. $buffy .= '</div>';
  751. } else {
  752. $buffy .= '<div class="td-block-span6 td-post-prev-post">';
  753. $buffy .= '</div>';
  754. }
  755. $buffy .= '<div class="td-next-prev-separator"></div>';
  756. if (!empty($next_post)) {
  757. $buffy .= '<div class="td-block-span6 td-post-next-post">';
  758. $buffy .= '<div class="td-post-next-prev-content"><span>' .__td('Next article', TD_THEME_NAME) . '</span>';
  759. $buffy .= '<a href="' . esc_url(get_permalink($next_post->ID)) . '">' . get_the_title( $next_post->ID ) . '</a>';
  760. $buffy .= '</div>';
  761. $buffy .= '</div>';
  762. }
  763. $buffy .= '</div>'; //end fluid row
  764. }
  765.  
  766. return $buffy;
  767. }
  768.  
  769.  
  770. /**
  771. * gets the author on single posts and single custom post types
  772. * @param string $author_id
  773. * @return string|void
  774. */
  775. function get_author_box($author_id = '') {
  776.  
  777. if (!$this->is_single) {
  778. return '';
  779. }
  780.  
  781.  
  782. if (empty($author_id)) {
  783. $author_id = $this->post->post_author;
  784. }
  785.  
  786. // add the author as hidden for google and return if the author box is set to disabled
  787. if (td_util::get_option('tds_show_author_box') == 'hide') {
  788. $buffy = '<div class="td-author-name vcard author" style="display: none"><span class="fn">';
  789. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' . get_the_author_meta('display_name', $author_id) . '</a>' ;
  790. $buffy .= '</span></div>';
  791. return $buffy;
  792. }
  793.  
  794.  
  795. $buffy = '';
  796.  
  797. $hideAuthor = td_util::get_option('hide_author');
  798.  
  799. if (empty($hideAuthor)) {
  800.  
  801. $buffy .= '<div class="author-box-wrap">';
  802. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' ;
  803. $buffy .= get_avatar(get_the_author_meta('email', $author_id), '96');
  804. $buffy .= '</a>';
  805.  
  806.  
  807. $buffy .= '<div class="desc">';
  808. $buffy .= '<div class="td-author-name vcard author"><span class="fn">';
  809. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' . get_the_author_meta('display_name', $author_id) . '</a>' ;
  810. $buffy .= '</span></div>';
  811.  
  812. if (get_the_author_meta('user_url', $author_id) != '') {
  813. $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>';
  814. }
  815.  
  816. $buffy .= '<div class="td-author-description">';
  817. $buffy .= get_the_author_meta('description', $author_id);
  818. $buffy .= '</div>';
  819.  
  820.  
  821. $buffy .= '<div class="td-author-social">';
  822. foreach (td_social_icons::$td_social_icons_array as $td_social_id => $td_social_name) {
  823. //echo get_the_author_meta($td_social_id) . '<br>';
  824. $authorMeta = get_the_author_meta($td_social_id);
  825. if (!empty($authorMeta)) {
  826.  
  827. //the theme can use the twitter id instead of the full url. This avoids problems with yoast plugin
  828. if ($td_social_id == 'twitter') {
  829. if(filter_var($authorMeta, FILTER_VALIDATE_URL)){
  830.  
  831. } else {
  832. $authorMeta = str_replace('@', '', $authorMeta);
  833. $authorMeta = 'http://twitter.com/' . $authorMeta;
  834. }
  835. }
  836. $buffy .= td_social_icons::get_icon($authorMeta, $td_social_id, 4);
  837. }
  838. }
  839. $buffy .= '</div>';
  840.  
  841.  
  842.  
  843. $buffy .= '<div class="clearfix"></div>';
  844.  
  845. $buffy .= '</div>'; ////desc
  846. $buffy .= '</div>'; //author-box-wrap
  847. }
  848.  
  849.  
  850. return $buffy;
  851. }
  852.  
  853.  
  854. /**
  855. * 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
  856. * blocks do not support custom taxonomies as of 15 july 2015
  857. * @param string $force_sidebar_position - allows us to overwrite the sidebar position. Useful on templates where the related
  858. * articles appear outside of the loop - sidebar grid (like on the top)
  859. * @return string
  860. */
  861. function related_posts($force_sidebar_position = '') {
  862. global $post;
  863. if ($post->post_type != 'post') {
  864. return '';
  865. }
  866.  
  867. if (td_util::get_option('tds_similar_articles') == 'hide') {
  868. return '';
  869. }
  870.  
  871.  
  872.  
  873.  
  874.  
  875. //td_global::$cur_single_template_sidebar_pos;
  876.  
  877. //cur_post_same_tags
  878. //cur_post_same_author
  879. //cur_post_same_categories
  880.  
  881. if (td_util::get_option('tds_similar_articles_type') == 'by_tag') {
  882. $td_related_ajax_filter_type = 'cur_post_same_tags';
  883. } else {
  884. $td_related_ajax_filter_type = 'cur_post_same_categories';
  885. }
  886.  
  887.  
  888. // the number of rows to show. this number will be multiplied with the hardcoded limit
  889. $tds_similar_articles_rows = td_util::get_option('tds_similar_articles_rows');
  890. if (empty($tds_similar_articles_rows)) {
  891. $tds_similar_articles_rows = 1;
  892. }
  893.  
  894. if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar' or $force_sidebar_position === 'no_sidebar') {
  895. $td_related_limit = 5 * $tds_similar_articles_rows;
  896. $td_related_class = 'td-related-full-width';
  897. $td_column_number = 5;
  898. } else {
  899. $td_related_limit = 3 * $tds_similar_articles_rows;
  900. $td_related_class = '';
  901. $td_column_number = 3;
  902. }
  903.  
  904.  
  905.  
  906. /**
  907. * 'td_ajax_filter_type' => 'td_custom_related' - this ajax filter type overwrites the live filter via ajax @see td_ajax::on_ajax_block
  908. */
  909. $td_block_args = array (
  910. 'limit' => $td_related_limit,
  911. 'ajax_pagination' => 'next_prev',
  912. 'live_filter' => $td_related_ajax_filter_type, //live atts - this is the default setting for this block
  913. 'td_ajax_filter_type' => 'td_custom_related', //this filter type can overwrite the live filter @see
  914. 'class' => $td_related_class,
  915. 'td_column_number' => $td_column_number
  916. );
  917.  
  918.  
  919. /**
  920. * @see td_block_related_posts
  921. */
  922. return td_global_blocks::get_instance('td_block_related_posts')->render($td_block_args);
  923.  
  924. }
  925.  
  926.  
  927. }
Advertisement
Add Comment
Please, Sign In to add comment