Guest User

Untitled

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