Guest User

Newspaper Theme ACF issue

a guest
Jan 7th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.05 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class td_module_blog extends td_module {
  5.  
  6. var $td_post_theme_settings;
  7.  
  8. var $is_single; //true if we are on a single page
  9.  
  10.  
  11.  
  12. function __construct($post = '') {
  13. // construct the class without the post object, used in the author template for the box
  14. if (empty($post)) {
  15. return;
  16. }
  17.  
  18. parent::__construct($post);
  19.  
  20. //read post settings
  21. $this->td_post_theme_settings = get_post_meta($post->ID, 'td_post_theme_settings', true);
  22.  
  23. $this->is_single = is_single();
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30. function get_social_sharing() {
  31. $social_sharing = 1;
  32. $closing_class_tags = 'td-tags-and-social-wrapper-box-bottom-line';
  33.  
  34. if (!$this->is_single) {
  35. return;
  36. }
  37.  
  38. $buffy = $this_post_tags = $wrapper_post_tags = '';
  39.  
  40. if (td_util::get_option('tds_social_show') == 'hide') {
  41. $social_sharing = 0;
  42. } else {
  43. $closing_class_tags = '';
  44. }
  45.  
  46. //if the post has tags
  47. $this_post_tags = $this->get_the_tags();
  48. if(!empty($this_post_tags)) {
  49. $wrapper_post_tags = '<div class="td-tags-and-social-wrapper-box ' . $closing_class_tags . '"> ' . $this_post_tags . '</div>';
  50. }
  51.  
  52.  
  53. $buffy .= '
  54. <div class="td-social-sharing">
  55. ' . $wrapper_post_tags;
  56.  
  57. if($social_sharing == 1) {
  58.  
  59. $image = wp_get_attachment_image_src( get_post_thumbnail_id( $this->post->ID ), 'single-post-thumbnail' );
  60.  
  61. $twetter_user = td_util::get_option('tds_tweeter_username');
  62.  
  63. $buffy .= '
  64. <div class="td-tags-and-social-wrapper-box td-tags-and-social-wrapper-box-bottom-line">
  65. <a class="td-social-sharing-buttons td-social-twitter" href="https://twitter.com/intent/tweet?text=' . urlencode($this->title) . '&url=' . urlencode(get_permalink()) . '&via=' . urlencode($twetter_user ? $twetter_user : get_bloginfo('name')) .'" onclick="if(!document.getElementById(\'td_social_networks_buttons\')){window.open(this.href, \'mywin\',\'left=50,top=50,width=600,height=350,toolbar=0\'); return false;}" ><div class="td-sp td-sp-share-twitter"></div><div class="td-social-but-text">Twitter</div></a>
  66. <a class="td-social-sharing-buttons td-social-facebook" href="http://www.facebook.com/sharer.php?u=' . urlencode(get_permalink()) . '" onclick="window.open(this.href, \'mywin\',\'left=50,top=50,width=600,height=350,toolbar=0\'); return false;"><div class="td-sp td-sp-share-facebook"></div><div class="td-social-but-text">Facebook</div></a>
  67. <a class="td-social-sharing-buttons td-social-google" href="http://plus.google.com/share?url=' . get_permalink() . '" onclick="window.open(this.href, \'mywin\',\'left=50,top=50,width=600,height=350,toolbar=0\'); return false;"><div class="td-sp td-sp-share-google"></div><div class="td-social-but-text">Google +</div></a>
  68. <a class="td-social-sharing-buttons td-social-pinterest" href="http://pinterest.com/pin/create/button/?url=' . get_permalink() . '&amp;media=' . (!empty($image[0]) ? $image[0] : '') . '" onclick="window.open(this.href, \'mywin\',\'left=50,top=50,width=600,height=350,toolbar=0\'); return false;"><div class="td-sp td-sp-share-pinterest"></div><div class="td-social-but-text">Pinterest</div></a>
  69. </div>';
  70. }
  71.  
  72. return $buffy . '</div>';
  73. }
  74.  
  75.  
  76.  
  77.  
  78. function get_social_like_tweet() {
  79. if (!$this->is_single) {
  80. return;
  81. }
  82.  
  83. if (td_util::get_option('tds_like_tweet_show') != 'show') {
  84. return;
  85. }
  86.  
  87. $buffy = '';
  88. $buffy .= '<div id="td_social_networks_buttons" class="td-social-like-tweet">';
  89. $buffy .= '<ul>';
  90. $buffy .= '<li class="td-like-tweet-twitter">';
  91. $buffy .= '<a href="https://twitter.com/share" class="twitter-share-button" data-url="' . $this->href . '" data-text="' . $this->title . '" data-via="' . td_util::get_option('tds_' . 'social_twitter') . '" data-lang="en">tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
  92. $buffy .= '</li>';
  93.  
  94. $buffy .= '<li class="td-like-tweet-facebook">';
  95. $buffy .= '<iframe src="http://www.facebook.com/plugins/like.php?href=' . $this->href . '&amp;layout=button_count&amp;show_faces=false&amp;width=105&amp;action=like&amp;colorscheme=light&amp;height=21" style="border:none; overflow:hidden; width:105px; height:21px; background-color:transparent;"></iframe>';
  96. $buffy .= '</li>';
  97.  
  98. $buffy .= '<li class="td-like-tweet-google">';
  99. $buffy .= '
  100. <div class="g-plusone" data-size="medium" data-href="' . $this->href . '"></div>
  101. <script type="text/javascript">
  102. (function() {
  103. var po = document.createElement("script"); po.type = "text/javascript"; po.async = true;
  104. po.src = "https://apis.google.com/js/plusone.js";
  105. var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s);
  106. })();
  107. </script>
  108. ';
  109. $buffy .= '</li>';
  110. $buffy .= '</ul>';
  111. $buffy .= '</div>';
  112. return $buffy;
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119. function get_post_pagination() {
  120. if (!$this->is_single) {
  121. return;
  122. }
  123.  
  124.  
  125. return wp_link_pages(array(
  126. 'before' => '<div class="page-nav page-nav-post">',
  127. 'after' => '</div>',
  128. 'link_before' => '<span>',
  129. 'link_after' => '</span>',
  130. 'echo' => false,
  131. 'nextpagelink' => ' ' . __td('Next') . ' <img width="6" class="td-retina right-arrow" src="' . get_template_directory_uri() . '/images/icons/similar-right.png" alt=""/>',
  132. 'previouspagelink' => '<img width="6" class="td-retina left-arrow" src="' . get_template_directory_uri() . '/images/icons/similar-left.png" alt=""/> ' . __td('Prev')
  133. ));
  134. }
  135.  
  136. function get_title($excerpt_lenght = '') {
  137. //just use h1 instead of h3
  138. $var_single = 0;
  139. if (is_single()) {
  140. $var_single = 1;
  141. }
  142.  
  143. $buffy = '';
  144. $buffy .= '<h1 itemprop="name" class="entry-title">';
  145.  
  146. if ($var_single == 0) {
  147. $buffy .='<a itemprop="url" href="' . $this->href . '" rel="bookmark" title="' . $this->title_attribute . '">';
  148. }
  149.  
  150. $buffy .= $this->title;
  151.  
  152. if ($var_single == 0) {
  153. $buffy .='</a>';
  154. }
  155.  
  156. $buffy .= '</h1>';
  157. return $buffy;
  158. }
  159.  
  160. //$show_stars_on_review - not used
  161. function get_author($show_stars_on_review = '') {
  162. $buffy = '';
  163. $buffy .='<div class="td-clear-author"></div>';
  164. $buffy .= parent::get_author(false);
  165. return $buffy;
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172. /**
  173. * get_image v010 - modified on wp_010 - returns the featured image of a single post
  174. * @param $thumbType
  175. * @return string
  176. */
  177. function get_image($thumbType) {
  178. global $page;
  179.  
  180. //show only on the first page when we have posts with pages
  181. if (!empty($page) and $page > 1) {
  182. return;
  183. }
  184.  
  185. //do not show the featured image if the global setting is set to hide - show the video preview regardless of the setting
  186. if (td_util::get_option('tds_show_featured_image') == 'hide' and get_post_format($this->post->ID) != 'video') {
  187. return;
  188. }
  189.  
  190. //do not show the featured image on gallery post format
  191. if (get_post_format($this->post->ID) == 'gallery') {
  192. return;
  193. }
  194.  
  195. //handle video post format
  196. if (get_post_format($this->post->ID) == 'video') {
  197. //if it's a video post...
  198. $td_post_video = get_post_meta($this->post->ID, 'td_post_video', true);
  199. $td_video_support = new td_video_support();
  200.  
  201. //render the video if the post has a video in the featured video section of the post
  202. if (!empty($td_post_video['td_video'])) {
  203. return $td_video_support->renderVideo($td_post_video['td_video']);
  204. }
  205. } else {
  206. //if it's a normal post, show the default thumb
  207.  
  208. if ($this->post_has_thumb) {
  209. //get the featured image id + full info about the 640px wide one
  210. $featured_image_id = get_post_thumbnail_id($this->post->ID);
  211. $featured_image_info = td_util::attachment_get_full_info($featured_image_id, $thumbType);
  212.  
  213. //get the full size for the popup
  214. $featured_image_full_size_src = td_util::attachment_get_src($featured_image_id, 'full');
  215.  
  216. $buffy = '';
  217.  
  218. $show_td_modal_image = td_util::get_option('tds_featured_image_view_setting') ;
  219.  
  220. if (is_single()) {
  221. if ($show_td_modal_image != 'no_modal') {
  222. //wrap the image_html with a link + add td-modal-image class
  223. $image_html = '<a href="' . $featured_image_full_size_src['src'] . '" data-caption="' . htmlentities($featured_image_info['caption'], ENT_QUOTES) . '">';
  224. $image_html .= '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb td-modal-image" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/>';
  225. $image_html .= '</a>';
  226. } else { //no_modal
  227. $image_html = '<img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/>';
  228. }
  229. } else {
  230. //on blog index page
  231. $image_html = '<a href="' . $this->href . '"><img width="' . $featured_image_info['width'] . '" height="' . $featured_image_info['height'] . '" itemprop="image" class="entry-thumb" src="' . $featured_image_info['src'] . '" alt="' . $featured_image_info['alt'] . '" title="' . $featured_image_info['title'] . '"/></a>';
  232. }
  233.  
  234.  
  235. $buffy .= '<div class="td-post-featured-image">';
  236.  
  237. // caption - put html5 wrapper on when we have a caption
  238. if (!empty($featured_image_info['caption'])) {
  239. $buffy .= '<figure>';
  240. $buffy .= $image_html;
  241.  
  242. $buffy .= '<figcaption class="wp-caption-text">' . $featured_image_info['caption'] . '</figcaption>';
  243. $buffy .= '</figure>';
  244. } else {
  245. $buffy .= $image_html;
  246. }
  247.  
  248. $buffy .= '</div>';
  249.  
  250.  
  251. return $buffy;
  252. } else {
  253. return ''; //the post has no thumb
  254. }
  255. }
  256. }
  257.  
  258.  
  259. function get_category() {
  260.  
  261. $buffy = '';
  262.  
  263. $buffy .= '<ul class="td-category">';
  264. $categories = get_the_category($this->post->ID);
  265. $cat_array = array();
  266.  
  267. if($categories){
  268. foreach($categories as $category) {
  269. if ($category->name != TD_FEATURED_CAT) { //ignore the featured category name
  270. //get the parent of this cat
  271. $td_parent_cat_obj = get_category($category->category_parent);
  272.  
  273. //if we have a parent, shot it first
  274. if (!empty($td_parent_cat_obj->name)) {
  275. $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');
  276. $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');
  277. $cat_array[$td_parent_cat_obj->name] = array(
  278. 'color' => $tax_meta__color_parent,
  279. 'link' => get_category_link($td_parent_cat_obj->cat_ID),
  280. 'hide_on_post' => $tax_meta__hide_on_post_parent
  281. );
  282. }
  283.  
  284. //show the category, only if we didn't already showed the parent
  285. $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');
  286. $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');
  287. $cat_array[$category->name] = array(
  288. 'color' => $tax_meta_color,
  289. 'link' => get_category_link($category->cat_ID),
  290. 'hide_on_post' => $tax_meta__hide_on_post_parent
  291. );
  292. }
  293. }
  294. }
  295.  
  296. foreach ($cat_array as $td_cat_name => $td_cat_parms) {
  297. if ($td_cat_parms['hide_on_post'] == 'hide') {
  298. continue;
  299. }
  300.  
  301. if (!empty($td_cat_parms['color'])) {
  302. $td_cat_color = ' style="background-color:' . $td_cat_parms['color'] . ';"';
  303. } else {
  304. $td_cat_color = '';
  305. }
  306.  
  307.  
  308. $buffy .= '<li class="entry-category"><a ' . $td_cat_color . ' href="' . $td_cat_parms['link'] . '">' . $td_cat_name . '</a></li>';
  309. }
  310. $buffy .= '</ul>';
  311.  
  312. return $buffy;
  313. }
  314.  
  315.  
  316.  
  317.  
  318. function get_item_scope() {
  319. //show the review meta only on single posts that are reviews, the rest have to be article (in article lists)
  320. if (td_review::has_review($this->td_review) and is_single()) {
  321. return 'itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Review"';
  322. } else {
  323. return 'itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Article"';
  324. }
  325. }
  326.  
  327.  
  328. function get_item_scope_meta() {
  329. $buffy = ''; //the vampire slayer
  330.  
  331.  
  332. $author_id = $this->post->post_author;
  333.  
  334. $buffy .= '<meta itemprop="author" content = "' . get_the_author_meta('display_name', $author_id) . '">';
  335.  
  336. $authorMetaGoogle = get_the_author_meta('googleplus', $author_id);
  337. if (!empty($authorMetaGoogle)) {
  338. echo '<a href="' . $authorMetaGoogle . '?rel=author"></a>';
  339. }
  340.  
  341.  
  342. if (td_review::has_review($this->td_review) and is_single()) { //show the review meta only on single posts that are reviews, the rest have to be article (in article lists)
  343. $td_article_date_unix = get_the_time('U', $this->post->ID);
  344.  
  345. if (!empty($this->td_review['review'])) {
  346. $buffy .= '<meta itemprop="about" content = "' . $this->td_review['review'] . '">';
  347. } else {
  348. //we have no review :|
  349. $buffy .= '<meta itemprop="about" content = "' . $this->get_excerpt(25) . '">';
  350. }
  351.  
  352. $buffy .= '<meta itemprop="itemreviewed" content = "' . $this->title . '">';
  353. $buffy .= '<meta itemprop="datePublished" content="' . date(DATE_W3C, $td_article_date_unix) . '">';
  354.  
  355.  
  356.  
  357.  
  358.  
  359. //$buffy .= '<meta itemprop="url" rel="author" content = "' . get_author_posts_url($author_id) . '">';
  360.  
  361. $buffy .= '<span class="td-page-meta" itemprop="reviewRating" itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Rating">';
  362. $buffy .= '<meta itemprop="worstRating" content = "1">';
  363. $buffy .= '<meta itemprop="bestRating" content = "5">';
  364. $buffy .= '<meta itemprop="ratingValue" content = "' . td_review::calculate_total_stars($this->td_review) . '">';
  365. $buffy .= ' </span>';
  366. }
  367. return $buffy;
  368. }
  369.  
  370. /* ----------------------------------------------------------------------------
  371. To add Version, Price, Download under advert
  372. ----------------------------------------------------------------------------*/
  373. function get_single_top(){
  374. $singletopcontent="";
  375. $field_name = "author_name";
  376. $field = get_field_object($field_name);
  377. $price = get_field_object('theme_price');
  378. $discount = get_field_object('our_discount');
  379. $current_version = get_field_object('current_version');
  380.  
  381. $coupon_code = get_field_object('coupon_code');
  382. $coupon_validity = get_field_object('coupon_validity');
  383. $coupon_discount = get_field_object('coupon_discount');
  384.  
  385. // if ($field['value'] != '' && $price['value']!='' && $discount['value']!='' && $current_version['value']!='') {
  386. if($discount){
  387. $discounted_price = ($discount['value']/100 ) * $price['value'];
  388. $finalprice = $price['value'] - $discounted_price;
  389. $count = get_field_object('download_count');
  390. }
  391. $singletopcontent = '<div class="single-top one-full" style="float:left; width: 100%;margin-bottom:20px;">';
  392. if($current_version['value']!=''){
  393. if($count['value']){
  394. if(strpos($count['value'],'http://')===false){
  395. $singletopcontent = $singletopcontent . '<div class="grid one-third col1">Version: '.$current_version['value'].'</div><div class="grid one-third col1">Price: $'.$price['value'].'</div><div class="grid one-third col2 last">Downloads: '.$count['value'].' </div>';
  396. } else {
  397. $singletopcontent = $singletopcontent . '<div class="grid one-third col1">Version: '.$current_version['value'].'</div><div class="grid one-third col1">Price: $'.$price['value'].'</div><div class="grid one-third col2 last">Downloads: '. do_shortcode('[wpws url="'.$count['value'].'" selector=".sidebar-stats__item:first-child .sidebar-stats__number"]').'</div>';
  398. }
  399. } else {
  400. $singletopcontent = $singletopcontent . '<div class="grid one-third col1">Version: '.$current_version['value'].'</div><div class="grid one-third col1">Price: $'.$price['value'].'</div><div class="grid one-third col2 last">Downloads: </div>';
  401. }
  402. }
  403.  
  404. if($coupon_code['value']!=''){
  405.  
  406. $singletopcontent = $singletopcontent . '<div class="grid one-third col1">'.$coupon_code['label'].': '.$coupon_code['value'].'</div>
  407. <div class="grid one-third col1">'.$coupon_validity['label'].': '.$coupon_validity['value'].'</div>
  408. <div class="grid one-third col2 last">'.$coupon_discount['label'].': '.$coupon_discount['value'].'</div>';
  409.  
  410. }
  411.  
  412.  
  413. //echo '<div class="grid one-third col1">Version: '.$current_version['value'].'</div><div class="grid one-third col1">Price: $'.$price['value'].'</div><div class="grid one-third col2 last">After '.$discount['value'].'% discount</div>';
  414. /* if($count['value']){
  415. echo '<div class="grid one-third col1">Downloads: '. do_shortcode('[wpws url="'.$count['value'].'" selector=".sidebar-stats__item:eq(0) .sidebar-stats__number"]').'</div><div class="grid one-third col1">Get it for $'.$finalprice.'</div><div class="grid one-third col2 last">You save $'.$discounted_price.'</div>';
  416. } else {
  417. echo '<div class="grid one-third col1">Downloads:</div><div class="grid one-third col1">Get it for $'.$finalprice.'</div><div class="grid one-third col2 last">You save $'.$discounted_price.'</div>';
  418. }*/
  419. $singletopcontent = $singletopcontent . '</div>';
  420. return $singletopcontent;
  421. }
  422.  
  423. function get_content() {
  424. /* ----------------------------------------------------------------------------
  425. To add Version, Price, Download under advert
  426. ----------------------------------------------------------------------------*/
  427. if(!in_category(array('blog'))) {
  428. $singletopcontent = $this->get_single_top();
  429. }else{
  430. $singletopcontent = "" ;
  431. }
  432.  
  433.  
  434. /* ----------------------------------------------------------------------------
  435. Prepare the content
  436. */
  437. $content = get_the_content(__td('Continue', TD_THEME_NAME));
  438. $content = apply_filters('the_content', $content);
  439. $content = str_replace(']]>', ']]&gt;', $content);
  440.  
  441.  
  442.  
  443. /* ----------------------------------------------------------------------------
  444. Smart list support @todo reorganizare partea asta
  445. */
  446. $td_smart_list = get_post_meta($this->post->ID, 'td_smart_list', true);
  447. if (!empty($td_smart_list['smart_list_template'])) {
  448.  
  449. switch ($td_smart_list['smart_list_template']) {
  450. case 'td_smart_list_1':
  451. $td_smart_list_obj = new td_smart_list_1();
  452. break;
  453.  
  454. case 'td_smart_list_2':
  455. $td_smart_list_obj = new td_smart_list_2();
  456. break;
  457.  
  458. case 'td_smart_list_3':
  459. $td_smart_list_obj = new td_smart_list_3();
  460. break;
  461.  
  462. case 'td_smart_list_4':
  463. $td_smart_list_obj = new td_smart_list_4();
  464. break;
  465.  
  466. }
  467.  
  468.  
  469.  
  470. if (isset($td_smart_list_obj)) {
  471. return $td_smart_list_obj->render_from_post_content($content);
  472. } else {
  473. //there was an error?
  474. }
  475. }
  476. /* ----------------------------------------------------------------------------
  477. end smart list - if we have a list, the function returns above
  478. */
  479.  
  480.  
  481.  
  482.  
  483.  
  484. /* ----------------------------------------------------------------------------
  485. ad support on content
  486. */
  487.  
  488.  
  489.  
  490. $tds_inline_ad_paragraph = td_util::get_option('tds_inline_ad_paragraph');
  491. $tds_inline_ad_align = td_util::get_option('tds_inline_ad_align');
  492.  
  493. /* ----------------------------------------------------------------------------*/
  494. /* Enable/Disable Content inline ads based on http://goo.gl/NGYNQz via ACF */
  495. /* -------------------------------------------------------------------------- */
  496.  
  497. if (td_util::is_ad_spot_enabled('content_inline') and is_single() and !get_field('content_inline_advert') ) {
  498.  
  499. if (empty($tds_inline_ad_paragraph)) {
  500. $tds_inline_ad_paragraph = 0;
  501. }
  502.  
  503.  
  504. $content_buffer = ''; // we replace the content with this buffer at the end
  505.  
  506. $content_parts = preg_split('/(<p.*>)/U', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  507.  
  508. //print_r($content_parts);
  509. //die;
  510. //$content_parts = explode('<p>', $content);
  511. foreach ($content_parts as $content_part_index => $content_part) {
  512. if (!empty($content_part)) {
  513.  
  514. if ($tds_inline_ad_paragraph == $content_part_index / 2) { //we have 0 = > <p> 1 => content - that's why we have to divide by 2
  515. //it's time to show the ad
  516. switch ($tds_inline_ad_align) {
  517. case 'left':
  518. $content_buffer .= td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'left'));
  519. break;
  520.  
  521. case 'right':
  522. $content_buffer .= td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'right'));
  523. break;
  524.  
  525. default:
  526. $content_buffer .= td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'content_inline'));
  527. break;
  528. }
  529.  
  530. }
  531. $content_buffer .= $content_part;
  532. }
  533. } //end foreach
  534. $content = $content_buffer;
  535. }
  536.  
  537. /* -------------------------------------------------------------------------------*/
  538. /* Enable/Disable Content Top/Bottom ads based on http://goo.gl/NGYNQz via ACF */
  539. /* ------------------------------------------------------------------------------ */
  540.  
  541. //add the top ad
  542. if (td_util::is_ad_spot_enabled('content_top') and is_single() and !get_field('content_top_advert')) {
  543. $content = td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'content_top')) . $singletopcontent . $content;
  544. }
  545.  
  546.  
  547. //add bottom ad
  548. if (td_util::is_ad_spot_enabled('content_bottom') and is_single() and !get_field('content_bottom_advert')) {
  549. $content = $content . td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'content_bottom'));
  550. }
  551.  
  552.  
  553. return $content;
  554. }
  555.  
  556.  
  557. /* ----------------------------------------------------------------------------
  558. Single page
  559. */
  560. function get_review() {
  561. if (!$this->is_single) {
  562. return;
  563. }
  564.  
  565. if (td_review::has_review($this->td_review)) {
  566. //print_r($this->td_review);
  567. $buffy = '';
  568. $buffy .= td_review::render_table($this->td_review);
  569.  
  570.  
  571.  
  572. return $buffy;
  573. }
  574. }
  575.  
  576. function get_source_and_via() {
  577. if (!$this->is_single) {
  578. return;
  579. }
  580.  
  581.  
  582. $buffy ='';
  583.  
  584. //via and sourcet
  585. if (!empty($this->td_post_theme_settings['td_source']) or !empty($this->td_post_theme_settings['td_source_2']) or !empty($this->td_post_theme_settings['td_via']) or !empty($this->td_post_theme_settings['td_via_2'])) {
  586. $buffy .= '<div class="post-source-via">';
  587.  
  588. if (!empty($this->td_post_theme_settings['td_via']) or !empty($this->td_post_theme_settings['td_via_2'])) {
  589. $buffy .= '<div class="post-via"><span>' . __td('VIA') . '</span>';
  590. if (!empty($this->td_post_theme_settings['td_via'])) {
  591. $buffy .= ' <a rel="nofollow" href="' . $this->td_post_theme_settings['td_via_url'] . '">' . $this->td_post_theme_settings['td_via'] . '</a>';
  592. }
  593. if (!empty($this->td_post_theme_settings['td_via_2'])) {
  594. $buffy .= ' <a rel="nofollow" href="' . $this->td_post_theme_settings['td_via_2_url'] . '">' . $this->td_post_theme_settings['td_via_2'] . '</a>';
  595. }
  596.  
  597. $buffy .= '</div>';
  598. }
  599.  
  600. if (!empty($this->td_post_theme_settings['td_source']) or !empty($this->td_post_theme_settings['td_source_2'])) {
  601. $buffy .= '<div class="post-via"><span>' . __td('SOURCE') . '</span>';
  602. if (!empty($this->td_post_theme_settings['td_source'])) {
  603. $buffy .= ' <a rel="nofollow" href="' . $this->td_post_theme_settings['td_source_url'] . '">' . $this->td_post_theme_settings['td_source'] . '</a>';
  604. }
  605. if (!empty($this->td_post_theme_settings['td_source_2'])) {
  606. $buffy .= ' <a rel="nofollow" href="' . $this->td_post_theme_settings['td_source_2_url'] . '">' . $this->td_post_theme_settings['td_source_2'] . '</a>';
  607. }
  608.  
  609. $buffy .= '</div>';
  610. }
  611.  
  612. $buffy .= '</div>';
  613. }
  614.  
  615.  
  616. return $buffy;
  617. }
  618.  
  619.  
  620. function get_the_tags() {
  621. if (!$this->is_single) {
  622. return;
  623. }
  624.  
  625. if (td_util::get_option('tds_show_tags') == 'hide') {
  626. return;
  627. }
  628.  
  629.  
  630. $buffy = '';
  631.  
  632. $td_post_tags = get_the_tags();
  633. if ($td_post_tags) {
  634. $buffy .= '<ul class="td-tags clearfix"><li><span class="td-tag-black">' . __td('TAGS') . '</span></li>';
  635. foreach ($td_post_tags as $tag) {
  636. $buffy .= '<li><a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a></li>';
  637. }
  638. $buffy .= '</ul>';
  639. }
  640.  
  641. return $buffy;
  642. }
  643.  
  644. function get_next_prev_posts() {
  645. if (!$this->is_single) {
  646. return;
  647. }
  648.  
  649. if (td_util::get_option('tds_show_next_prev') == 'hide') {
  650. return;
  651. }
  652.  
  653. $buffy = '';
  654.  
  655. $next_post = get_next_post();
  656. $prev_post = get_previous_post();
  657.  
  658. if (!empty($next_post) or !empty($prev_post)) {
  659. $buffy .= '<div class="wpb_row row-fluid next-prev">';
  660. if (!empty($prev_post)) {
  661. $buffy .= '<div class="span6 prev-post">';
  662. $buffy .= '<div><img width="6" class="td-retina" src="' . get_template_directory_uri() .
  663. '/images/icons/similar-left.png" alt=""/>' . __td('Previous article', TD_THEME_NAME) . '</div>';
  664. $buffy .= '<a href="' . get_permalink($prev_post->ID) . '">' . $prev_post->post_title . '</a>';
  665. $buffy .= '</div>';
  666. } else {
  667. $buffy .= '<div class="span6 prev-post">';
  668. $buffy .= '</div>';
  669. }
  670.  
  671. if (!empty($next_post)) {
  672. $buffy .= '<div class="span6 next-post">';
  673. $buffy .= '<div>' . __td('Next article', TD_THEME_NAME) . '<img width="6" class="td-retina" src="' .
  674. get_template_directory_uri() . '/images/icons/similar-right.png" alt=""/></div>';
  675. $buffy .= '<a href="' . get_permalink($next_post->ID) . '">' . $next_post->post_title . '</a>';
  676. $buffy .= '</div>';
  677. }
  678. $buffy .= '</div>'; //end fluid row
  679. }
  680.  
  681. return $buffy;
  682. }
  683.  
  684. function get_author_box($author_id = '') {
  685.  
  686. if (!$this->is_single) {
  687. return;
  688. }
  689.  
  690. if (td_util::get_option('tds_show_author_box') == 'hide') {
  691. $buffy = '<div class="td-author-name vcard author" style="display: none"><span class="fn">';
  692. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' . get_the_author_meta('display_name', $author_id) . '</a>' ;
  693. $buffy .= '</span></div>';
  694. return $buffy;
  695. }
  696.  
  697. if (empty($author_id)) {
  698. $author_id = $this->post->post_author;
  699. }
  700.  
  701.  
  702. $buffy = '';
  703.  
  704. $authorDescription = get_the_author_meta('description');
  705. $hideAuthor = td_util::get_option('hide_author');
  706.  
  707. if (empty($hideAuthor)) {
  708.  
  709. $buffy .= '<div class="author-box-wrap">';
  710. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' ;
  711. $buffy .= get_avatar(get_the_author_meta('email', $author_id), '106');
  712. $buffy .= '</a>';
  713.  
  714.  
  715. $buffy .= '<div class="desc">';
  716. $buffy .= '<div class="td-author-name vcard author"><span class="fn">';
  717. $buffy .= '<a href="' . get_author_posts_url($author_id) . '">' . get_the_author_meta('display_name', $author_id) . '</a>' ;
  718. $buffy .= '</span></div>';
  719.  
  720.  
  721.  
  722. $buffy .= '<div>';
  723. $buffy .= get_the_author_meta('description', $author_id);
  724. $buffy .= '</div>';
  725.  
  726.  
  727. $buffy .= '<div class="td-author-social">';
  728. foreach (td_social_icons::$td_social_icons_array as $td_social_id => $td_social_name) {
  729. //echo get_the_author_meta($td_social_id) . '<br>';
  730. $authorMeta = get_the_author_meta($td_social_id);
  731. if (!empty($authorMeta)) {
  732.  
  733. //the theme can use the twitter id instead of the full url. This avoids problems with yoast plugin
  734. if ($td_social_id == 'twitter') {
  735. if(filter_var($authorMeta, FILTER_VALIDATE_URL)){
  736.  
  737. } else {
  738. $authorMeta = str_replace('@', '', $authorMeta);
  739. $authorMeta = 'http://twitter.com/' . $authorMeta;
  740. }
  741. }
  742. $buffy .= td_social_icons::get_icon($authorMeta, $td_social_id, 4, 16);
  743. }
  744. }
  745. $buffy .= '</div>';
  746.  
  747.  
  748.  
  749. $buffy .= '<div class="clearfix"></div>';
  750.  
  751. $buffy .= '</div>'; ////desc
  752. $buffy .= '</div>'; //author-box-wrap
  753. }
  754.  
  755.  
  756. return $buffy;
  757. }
  758.  
  759.  
  760. function related_posts() {
  761.  
  762. global $post; //this is used by the loop down
  763.  
  764. if (!$this->is_single) {
  765. return;
  766. }
  767.  
  768.  
  769. if (td_util::get_option('tds_similar_articles') == 'hide') {
  770. return;
  771. }
  772.  
  773. if (td_util::get_option('tds_similar_articles_count') == '') {
  774. $tds_similar_articles_count = 2;
  775. } else {
  776. $tds_similar_articles_count = td_util::get_option('tds_similar_articles_count');
  777. }
  778.  
  779. if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  780. $tds_similar_articles_count = 3;
  781. }
  782.  
  783.  
  784.  
  785. $buffy = '';
  786. $buffy .= '<div class="art-img-text-down similar-articles">';
  787.  
  788.  
  789. $args = array();
  790.  
  791. switch (td_util::get_option('tds_similar_articles_type')) {
  792.  
  793. //by tag
  794. case 'by_tag':
  795. $tags = wp_get_post_tags($this->post->ID);
  796. if ($tags) {
  797. $taglist = array();
  798. for ($i = 0; $i <= 4; $i++) {
  799. if (!empty($tags[$i])) {
  800. $taglist[] = $tags[$i]->term_id;
  801. } else {
  802. break;
  803. }
  804. }
  805. $args = array(
  806. 'tag__in' => $taglist,
  807. 'post__not_in' => array($this->post->ID),
  808. 'showposts' => $tds_similar_articles_count,
  809. 'ignore_sticky_posts' => 1
  810. );
  811. }
  812. break;
  813.  
  814.  
  815. //by title
  816. case 'by_auth':
  817. $args = array(
  818. 'author' => $this->post->post_author,
  819. 'post__not_in' => array($this->post->ID),
  820. 'showposts' => $tds_similar_articles_count,
  821. 'ignore_sticky_posts' => 1
  822. );
  823. break;
  824.  
  825.  
  826. //by category
  827. default:
  828. $args = array(
  829. 'category__in' => wp_get_post_categories($this->post->ID),
  830. 'post__not_in' => array($this->post->ID),
  831. 'showposts' => $tds_similar_articles_count,
  832. 'ignore_sticky_posts' => 1
  833. );
  834. break;
  835. }
  836.  
  837.  
  838.  
  839. if (!empty($args)) {
  840. //do the query
  841. $my_query = new WP_Query($args);
  842. if ($my_query->have_posts()) {
  843. $buffy .= '<h4 class="block-title"><span>' . __td('SIMILAR ARTICLES') . '</span></h4>';
  844.  
  845. $td_template_layout = new td_template_layout(''); //invalid sidebar position, it will default to 2 + 1
  846.  
  847. if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  848. $td_template_layout->set_columns(3);
  849. } else {
  850. $td_template_layout->set_columns(2);
  851. }
  852.  
  853.  
  854. while ($my_query->have_posts()) : $my_query->the_post();
  855.  
  856. $buffy .= $td_template_layout->layout_open_element();
  857. $td_module_6 = new td_module_6($post);
  858. $buffy .= $td_module_6->render();
  859. $buffy .= $td_template_layout->layout_close_element();
  860.  
  861. $td_template_layout->layout_next();
  862. endwhile;
  863.  
  864. $buffy .= $td_template_layout->close_all_tags();
  865. }
  866. }
  867.  
  868.  
  869.  
  870.  
  871. $buffy .= '</div>';
  872.  
  873. wp_reset_query();
  874.  
  875. return $buffy;
  876. }
  877.  
  878.  
  879.  
  880.  
  881. }
Advertisement
Add Comment
Please, Sign In to add comment