Guest User

Untitled

a guest
Jul 27th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.49 KB | None | 0 0
  1. <?php
  2. class td_block_ad_box extends td_block {
  3.  
  4.  
  5. function render($atts, $content = null) {
  6.  
  7. extract(shortcode_atts(
  8. array(
  9. 'spot_id' => '', //header / sidebar etc
  10. 'align' => '', //align left or right in inline content,
  11. 'spot_title' => '',
  12. ), $atts));
  13.  
  14.  
  15.  
  16. if (empty($spot_id) or (is_page())) {
  17. return;
  18. }
  19.  
  20. $ad_array = td_util::get_td_ads($spot_id);
  21.  
  22. // return if the ad for a specific spot id is empty
  23. if (empty($ad_array[$spot_id]['ad_code'])) {
  24. return;
  25. }
  26.  
  27.  
  28. $buffy = '';
  29.  
  30. if (!empty($spot_title)) {
  31. $buffy .= '<div class="td-adspot-title">' . $spot_title . '</div>';
  32. }
  33.  
  34. if (!empty($ad_array[$spot_id]['current_ad_type'])) {
  35.  
  36.  
  37. switch ($ad_array[$spot_id]['current_ad_type']) {
  38.  
  39. case 'other':
  40. //render the normal ads
  41. $buffy .= $this->render_ads($ad_array[$spot_id], $atts);
  42. break;
  43.  
  44. case 'google':
  45. //render the magic google ads :)
  46. $buffy .= $this->render_google_ads($ad_array[$spot_id], $atts);
  47. break;
  48.  
  49. }
  50. }
  51.  
  52.  
  53. //print_r($ad_array);
  54.  
  55. return $buffy;
  56.  
  57. }
  58.  
  59.  
  60. /**
  61. * This function renders and returns a google ad.
  62. * @param $ad_array - uses an ad array of the form:
  63. - current_ad_type - google or other
  64. - ad_code - the full ad code as entered by the user
  65. - disable_m - disable on monitor
  66. - disable_tp - disable on tablet p
  67. - disable_p - disable on phones
  68. - g_data_ad_client - the google ad client id (ca-pub-etc)
  69. - g_data_ad_slot - the google ad slot id
  70. * 'm_w' => '', // big monitor - width
  71. 'm_h' => '', // big monitor - height
  72. 'tp_w' => '', // tablet_portrait width
  73. 'tp_h' => '', // tablet_portrait height
  74. 'p_w' => '', // phone width
  75. 'p_h' => '' // phone height
  76. * @param $atts test
  77. * @return the full rendered ad
  78. */
  79. // tagDiv google responsive renderer
  80. // copyright 2014 tagDiv
  81. function render_google_ads($ad_array, $atts) {
  82.  
  83.  
  84. $spot_id = ''; //the spot id header / sidebar etc we read it from shortcode
  85.  
  86. extract(shortcode_atts(
  87. array(
  88. 'spot_id' => '', //header / sidebar etc
  89. 'align' => '', //align left or right in inline content
  90. ), $atts));
  91.  
  92.  
  93. //echo ($p_w);
  94.  
  95. //print_r($ad_array);
  96.  
  97. $default_ad_sizes = array (
  98. 'header' => array (
  99. 'm_w' => '728', // big monitor - width
  100. 'm_h' => '90', // big monitor - height
  101.  
  102. 'tl_w' => '468', // tablet_landscape width
  103. 'tl_h' => '60', // tablet_landscape height
  104.  
  105. 'tp_w' => '468', // tablet_portrait width
  106. 'tp_h' => '60', // tablet_portrait height
  107.  
  108. 'p_w' => '320', // phone width
  109. 'p_h' => '50' // phone height
  110. ),
  111. 'sidebar' => array (
  112. 'm_w' => '300', // big monitor - width
  113. 'm_h' => '250', // big monitor - height
  114.  
  115. 'tl_w' => '300', // tablet_landscape width
  116. 'tl_h' => '250', // tablet_landscape height
  117.  
  118. 'tp_w' => '200', // tablet_portrait width
  119. 'tp_h' => '200', // tablet_portrait height
  120.  
  121. 'p_w' => '300', // phone width
  122. 'p_h' => '250' // phone height
  123. ),
  124.  
  125.  
  126. 'content_inline' => array (
  127. 'm_w' => '468', // big monitor - width
  128. 'm_h' => '60', // big monitor - height
  129.  
  130. 'tl_w' => '468', // tablet_landscape width
  131. 'tl_h' => '60', // tablet_landscape height
  132.  
  133. 'tp_w' => '468', // tablet_portrait width
  134. 'tp_h' => '60', // tablet_portrait height
  135.  
  136. 'p_w' => '320', // phone width
  137. 'p_h' => '50' // phone height
  138. ),
  139.  
  140. 'content_top' => array (
  141. 'm_w' => '468', // big monitor - width
  142. 'm_h' => '60', // big monitor - height
  143.  
  144. 'tl_w' => '468', // tablet_landscape width
  145. 'tl_h' => '60', // tablet_landscape height
  146.  
  147. 'tp_w' => '468', // tablet_portrait width
  148. 'tp_h' => '60', // tablet_portrait height
  149.  
  150. 'p_w' => '300', // phone width
  151. 'p_h' => '250' // phone height
  152. ),
  153.  
  154. 'content_bottom' => array (
  155. 'm_w' => '468', // big monitor - width
  156. 'm_h' => '60', // big monitor - height
  157.  
  158. 'tl_w' => '468', // tablet_landscape width
  159. 'tl_h' => '60', // tablet_landscape height
  160.  
  161. 'tp_w' => '468', // tablet_portrait width
  162. 'tp_h' => '60', // tablet_portrait height
  163.  
  164. 'p_w' => '300', // phone width
  165. 'p_h' => '250' // phone height
  166. ),
  167.  
  168. 'post_style_1' => array (
  169. 'm_w' => '300', // big monitor - width
  170. 'm_h' => '250', // big monitor - height
  171.  
  172. 'tl_w' => '300', // tablet_landscape width
  173. 'tl_h' => '250', // tablet_landscape height
  174.  
  175. 'tp_w' => '200', // tablet_portrait width
  176. 'tp_h' => '200', // tablet_portrait height
  177.  
  178. 'p_w' => '300', // phone width
  179. 'p_h' => '250' // phone height
  180. ),
  181.  
  182. 'post_style_11' => array (
  183. 'm_w' => '300', // big monitor - width
  184. 'm_h' => '250', // big monitor - height
  185.  
  186. 'tl_w' => '300', // tablet_landscape width
  187. 'tl_h' => '250', // tablet_landscape height
  188.  
  189. 'tp_w' => '320', // tablet_portrait width
  190. 'tp_h' => '50', // tablet_portrait height
  191.  
  192. 'p_w' => '300', // phone width
  193. 'p_h' => '250' // phone height
  194. ),
  195.  
  196. 'footer_top' => array (
  197. 'm_w' => '728', // big monitor - width
  198. 'm_h' => '90', // big monitor - height
  199.  
  200. 'tl_w' => '728', // tablet_landscape width
  201. 'tl_h' => '90', // tablet_landscape height
  202.  
  203. 'tp_w' => '728', // tablet_portrait width
  204. 'tp_h' => '90', // tablet_portrait height
  205.  
  206. 'p_w' => '300', // phone width
  207. 'p_h' => '250' // phone height
  208. ),
  209.  
  210. 'custom_ad_1' => array (
  211. 'm_w' => '300', // big monitor - width
  212. 'm_h' => '250', // big monitor - height
  213.  
  214. 'tl_w' => '300', // tablet_landscape width
  215. 'tl_h' => '250', // tablet_landscape height
  216.  
  217. 'tp_w' => '200', // tablet_portrait width
  218. 'tp_h' => '200', // tablet_portrait height
  219.  
  220. 'p_w' => '300', // phone width
  221. 'p_h' => '250' // phone height
  222. ),
  223.  
  224. 'custom_ad_2' => array (
  225. 'm_w' => '300', // big monitor - width
  226. 'm_h' => '250', // big monitor - height
  227.  
  228. 'tl_w' => '300', // tablet_landscape width
  229. 'tl_h' => '250', // tablet_landscape height
  230.  
  231. 'tp_w' => '200', // tablet_portrait width
  232. 'tp_h' => '200', // tablet_portrait height
  233.  
  234. 'p_w' => '300', // phone width
  235. 'p_h' => '250' // phone height
  236. ),
  237.  
  238. 'custom_ad_3' => array (
  239. 'm_w' => '300', // big monitor - width
  240. 'm_h' => '250', // big monitor - height
  241.  
  242. 'tl_w' => '300', // tablet_landscape width
  243. 'tl_h' => '250', // tablet_landscape height
  244.  
  245. 'tp_w' => '200', // tablet_portrait width
  246. 'tp_h' => '200', // tablet_portrait height
  247.  
  248. 'p_w' => '300', // phone width
  249. 'p_h' => '250' // phone height
  250. ),
  251.  
  252. 'custom_ad_4' => array (
  253. 'm_w' => '300', // big monitor - width
  254. 'm_h' => '250', // big monitor - height
  255.  
  256. 'tl_w' => '300', // tablet_landscape width
  257. 'tl_h' => '250', // tablet_landscape height
  258.  
  259. 'tp_w' => '200', // tablet_portrait width
  260. 'tp_h' => '200', // tablet_portrait height
  261.  
  262. 'p_w' => '300', // phone width
  263. 'p_h' => '250' // phone height
  264. ),
  265.  
  266. 'custom_ad_5' => array (
  267. 'm_w' => '300', // big monitor - width
  268. 'm_h' => '250', // big monitor - height
  269.  
  270. 'tl_w' => '300', // tablet_landscape width
  271. 'tl_h' => '250', // tablet_landscape height
  272.  
  273. 'tp_w' => '200', // tablet_portrait width
  274. 'tp_h' => '200', // tablet_portrait height
  275.  
  276. 'p_w' => '300', // phone width
  277. 'p_h' => '250' // phone height
  278. )
  279. );
  280.  
  281.  
  282. if ($align == 'left') {
  283. $default_ad_sizes['content_inline'] = array (
  284. 'm_w' => '300', // big monitor - width
  285. 'm_h' => '250', // big monitor - height
  286.  
  287. 'tl_w' => '300', // tablet_landscape width
  288. 'tl_h' => '250', // tablet_landscape height
  289.  
  290. 'tp_w' => '200', // tablet_portrait width
  291. 'tp_h' => '200', // tablet_portrait height
  292.  
  293. 'p_w' => '300', // phone width
  294. 'p_h' => '250' // phone height
  295. );
  296. }
  297. elseif ($align == 'right') {
  298. $default_ad_sizes['content_inline'] = array (
  299. 'm_w' => '300', // big monitor - width
  300. 'm_h' => '250', // big monitor - height
  301.  
  302. 'tl_w' => '300', // tablet_landscape width
  303. 'tl_h' => '250', // tablet_landscape height
  304.  
  305. 'tp_w' => '200', // tablet_portrait width
  306. 'tp_h' => '200', // tablet_portrait height
  307.  
  308. 'p_w' => '300', // phone width
  309. 'p_h' => '250' // phone height
  310. );
  311. }
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319. //overwrite the default values if we have some
  320.  
  321. //monitor big ad
  322. if (!empty($ad_array['m_size'])) {
  323. $ad_size_parts = explode(' x ', $ad_array['m_size']);
  324. $default_ad_sizes[$spot_id]['m_w'] = $ad_size_parts[0];
  325. $default_ad_sizes[$spot_id]['m_h'] = $ad_size_parts[1];
  326. }
  327.  
  328.  
  329. //tablet landscape
  330. if (!empty($ad_array['tl_size'])) {
  331. $ad_size_parts = explode(' x ', $ad_array['tl_size']);
  332. $default_ad_sizes[$spot_id]['tl_w'] = $ad_size_parts[0];
  333. $default_ad_sizes[$spot_id]['tl_h'] = $ad_size_parts[1];
  334. }
  335.  
  336.  
  337. //tablet portrait
  338. if (!empty($ad_array['tp_size'])) {
  339. $ad_size_parts = explode(' x ', $ad_array['tp_size']);
  340. $default_ad_sizes[$spot_id]['tp_w'] = $ad_size_parts[0];
  341. $default_ad_sizes[$spot_id]['tp_h'] = $ad_size_parts[1];
  342. }
  343.  
  344.  
  345. //phone
  346. if (!empty($ad_array['p_size'])) {
  347. $ad_size_parts = explode(' x ', $ad_array['p_size']);
  348. $default_ad_sizes[$spot_id]['p_w'] = $ad_size_parts[0];
  349. $default_ad_sizes[$spot_id]['p_h'] = $ad_size_parts[1];
  350. }
  351.  
  352.  
  353.  
  354.  
  355.  
  356. //init the disable variables
  357. if (!empty($ad_array['disable_m']) and $ad_array['disable_m'] == 'yes') {
  358. $default_ad_sizes[$spot_id]['disable_m'] = true;
  359. } else {
  360. $default_ad_sizes[$spot_id]['disable_m'] = false;
  361. }
  362.  
  363. if (!empty($ad_array['disable_tl']) and $ad_array['disable_tl'] == 'yes') {
  364. $default_ad_sizes[$spot_id]['disable_tl'] = true;
  365. } else {
  366. $default_ad_sizes[$spot_id]['disable_tl'] = false;
  367. }
  368.  
  369. if (!empty($ad_array['disable_tp']) and $ad_array['disable_tp'] == 'yes') {
  370. $default_ad_sizes[$spot_id]['disable_tp'] = true;
  371. } else {
  372. $default_ad_sizes[$spot_id]['disable_tp'] = false;
  373. }
  374.  
  375. if (!empty($ad_array['disable_p']) and $ad_array['disable_p'] == 'yes') {
  376. $default_ad_sizes[$spot_id]['disable_p'] = true;
  377. } else {
  378. $default_ad_sizes[$spot_id]['disable_p'] = false;
  379. }
  380.  
  381.  
  382.  
  383.  
  384. $buffy = "\n <!-- A generated by theme --> \n\n";
  385.  
  386. //google async script
  387. $buffy .= '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>';
  388.  
  389. $buffy .= '<div class="td-g-rec td-g-rec-id-' . $spot_id . $align . '">' . "\n";
  390. $buffy .= '<script type="text/javascript">' . "\n";
  391.  
  392.  
  393. //$buffy .= 'var td_a_g_custom_size = ' . json_encode($default_ad_sizes[$spot_id]) . ';' . "\n";
  394.  
  395.  
  396. $buffy .= 'var td_screen_width = document.body.clientWidth;' . "\n";
  397.  
  398.  
  399. if ($default_ad_sizes[$spot_id]['disable_m'] == false and !empty($default_ad_sizes[$spot_id]['m_w']) and !empty($default_ad_sizes[$spot_id]['m_h'])) {
  400. $buffy .= '
  401. if ( td_screen_width >= 1140 ) {
  402. /* large monitors */
  403. document.write(\'<ins class="adsbygoogle" style="display:inline-block;width:' . $default_ad_sizes[$spot_id]['m_w'] . 'px;height:' . $default_ad_sizes[$spot_id]['m_h'] . 'px" data-ad-client="' . $ad_array['g_data_ad_client'] . '" data-ad-slot="' . $ad_array['g_data_ad_slot'] . '"></ins>\');
  404. (adsbygoogle = window.adsbygoogle || []).push({});
  405. }
  406. ';
  407. }
  408.  
  409.  
  410. if ($default_ad_sizes[$spot_id]['disable_tl'] == false and !empty($default_ad_sizes[$spot_id]['tl_w']) and !empty($default_ad_sizes[$spot_id]['tl_h'])) {
  411. $buffy .= '
  412. if ( td_screen_width >= 1019 && td_screen_width < 1140 ) {
  413. /* landscape tablets */
  414. document.write(\'<ins class="adsbygoogle" style="display:inline-block;width:' . $default_ad_sizes[$spot_id]['m_w'] . 'px;height:' . $default_ad_sizes[$spot_id]['m_h'] . 'px" data-ad-client="' . $ad_array['g_data_ad_client'] . '" data-ad-slot="' . $ad_array['g_data_ad_slot'] . '"></ins>\');
  415. (adsbygoogle = window.adsbygoogle || []).push({});
  416. }
  417. ';
  418. }
  419.  
  420.  
  421. if ($default_ad_sizes[$spot_id]['disable_tp'] == false and !empty($default_ad_sizes[$spot_id]['tp_w']) and !empty($default_ad_sizes[$spot_id]['tp_h'])) {
  422. $buffy .= '
  423. if ( td_screen_width >= 768 && td_screen_width < 1019 ) {
  424. /* portrait tablets */
  425. document.write(\'<ins class="adsbygoogle" style="display:inline-block;width:' . $default_ad_sizes[$spot_id]['tp_w'] . 'px;height:' . $default_ad_sizes[$spot_id]['tp_h'] . 'px" data-ad-client="' . $ad_array['g_data_ad_client'] . '" data-ad-slot="' . $ad_array['g_data_ad_slot'] . '"></ins>\');
  426. (adsbygoogle = window.adsbygoogle || []).push({});
  427. }
  428. ';
  429. }
  430.  
  431. if ($default_ad_sizes[$spot_id]['disable_p'] == false and !empty($default_ad_sizes[$spot_id]['p_w']) and !empty($default_ad_sizes[$spot_id]['p_h'])) {
  432. $buffy .= '
  433. if ( td_screen_width < 768 ) {
  434. /* Phones */
  435. document.write(\'<ins class="adsbygoogle" style="display:inline-block;width:' . $default_ad_sizes[$spot_id]['p_w'] . 'px;height:' . $default_ad_sizes[$spot_id]['p_h'] . 'px" data-ad-client="' . $ad_array['g_data_ad_client'] . '" data-ad-slot="' . $ad_array['g_data_ad_slot'] . '"></ins>\');
  436. (adsbygoogle = window.adsbygoogle || []).push({});
  437. }
  438. ';
  439. }
  440.  
  441.  
  442. //$buffy .= 'console.log(td_a_g_custom_size)';
  443.  
  444. $buffy .= '</script>' . "\n";
  445.  
  446. $buffy .= '</div>' . "\n";
  447. $buffy .= "\n <!-- end A --> \n\n";
  448. return $buffy;
  449. }
  450.  
  451.  
  452. /**
  453. * This function renders and returns a normal ad.
  454. * @param $ad_array - uses an ad array of the form:
  455. - current_ad_type - google or other
  456. - ad_code - the full ad code as entered by the user
  457. - disable_m - disable on monitor
  458. - disable_tp - disable on tablet p
  459. - disable_p - disable on phones
  460. - g_data_ad_client - the google ad client id (ca-pub-etc)
  461. - g_data_ad_slot - the google ad slot id
  462. *
  463. * @return the full rendered ad
  464. */
  465. function render_ads($ad_array, $atts) {
  466.  
  467. $spot_id = ''; //the spot id header / sidebar etc we read it from shortcode
  468.  
  469. extract(shortcode_atts(
  470. array(
  471. 'spot_id' => '', //header / sidebar etc
  472. 'align' => '', //align left or right in inline content
  473.  
  474. ), $atts));
  475.  
  476.  
  477. $buffy = '';
  478.  
  479.  
  480.  
  481.  
  482. $buffy .= '<div class="td-a-rec td-a-rec-id-' . $spot_id . $align . ' '
  483. . ((!empty($ad_array['disable_m'])) ? ' td-rec-hide-on-m' : '')
  484. . ((!empty($ad_array['disable_tl'])) ? ' td-rec-hide-on-tl' : '')
  485. . ((!empty($ad_array['disable_tp'])) ? ' td-rec-hide-on-tp' : '')
  486. . ((!empty($ad_array['disable_p'])) ? ' td-rec-hide-on-p' : '')
  487. . '">';
  488. $buffy .= do_shortcode(stripslashes($ad_array['ad_code']));
  489. $buffy .= '</div>';
  490.  
  491.  
  492. //print_r($ad_array);
  493. return $buffy;
  494. }
  495. }
Advertisement
Add Comment
Please, Sign In to add comment