PageRenderTime 67ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/dt-chocolate/functions/12_like_buttons.php

https://bitbucket.org/sweetperceptions/nyey-everyday
PHP | 174 lines | 137 code | 37 blank | 0 comment | 29 complexity | 7a27a08db545cfb58871dd9057431ff2 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. function dt_get_soc_link_script( $type = 'twitter' ) {
  3. ob_start();
  4. ?>
  5. <!-- twitter -->
  6. <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>
  7. <?php
  8. $twitter = ob_get_clean();
  9. ob_start();
  10. ?>
  11. <!-- google plus -->
  12. <script type="text/javascript">
  13. (function() {
  14. var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  15. po.src = 'https://apis.google.com/js/plusone.js';
  16. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  17. })();
  18. </script>
  19. <?php
  20. $google_plus = ob_get_clean();
  21. ob_start();
  22. ?>
  23. <!-- faceboock SDK -->
  24. <div id="fb-root"></div>
  25. <script>(function(d, s, id) {
  26. var js, fjs = d.getElementsByTagName(s)[0];
  27. if (d.getElementById(id)) return;
  28. js = d.createElement(s); js.id = id;
  29. js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  30. fjs.parentNode.insertBefore(js, fjs);
  31. }(document, 'script', 'facebook-jssdk'));</script>
  32. <?php
  33. $faceboock = ob_get_clean();
  34. if( isset($$type) )
  35. return $$type;
  36. return '';
  37. }
  38. function dt_get_like_button( $type = 'twitter', $post_id = null, $echo = true ) {
  39. global $post;
  40. if( !$post_id && $post )
  41. $post_id = $post->ID;
  42. $url_params = array(
  43. 'twitter' => ' data-url="%s"',
  44. 'faceboock' => ' data-href="%s"',
  45. 'google_plus' => ' data-href="%s"'
  46. );
  47. $buttons = array(
  48. 'twitter' => '<a href="https://twitter.com/share" class="twitter-share-button" data-lang="en"%s>Tweet</a>',
  49. 'faceboock' => '<div class="fb-like" data-send="false" data-width="120" data-show-faces="false" data-layout="button_count"%s></div>',
  50. 'google_plus' => '<div class="g-plusone" data-size="medium" data-annotation="inline" data-width="120"%s></div>'
  51. );
  52. $button = $url_param = $permalink = '';
  53. if( dt_get_theme_options($type.'_lb') && isset($buttons[$type]) ) {
  54. if( $permalink = get_permalink($post_id) )
  55. $url_param = sprintf($url_params[$type], $permalink);
  56. $button = sprintf($buttons[$type], $url_param);
  57. $button = dt_get_soc_link_script( $type ). $button;
  58. }
  59. if( $echo ) {
  60. echo $button;
  61. return false;
  62. }
  63. return $button;
  64. }
  65. function is_lb_enabled( $type = '' ) {
  66. $options = dt_get_theme_options();
  67. if( !$options )
  68. return false;
  69. if( $type ) {
  70. if( isset($options[$type.'_lb']) && $options[$type.'_lb'] )
  71. return true;
  72. return false;
  73. }
  74. if( (isset($options['twitter_lb']) && $options['twitter_lb']) ||
  75. (isset($options['faceboock_lb']) && $options['faceboock_lb']) ||
  76. (isset($options['google_plus_lb']) && $options['google_plus_lb']) ||
  77. (isset($options['use_custom_likes']) && $options['use_custom_likes']) )
  78. return true;
  79. return false;
  80. }
  81. function dt_get_custom_like_buttons( $post_id = null, $echo = true ) {
  82. global $post;
  83. if( !$post_id && $post )
  84. $post_id = $post->ID;
  85. ob_start();
  86. include dirname(dirname(__FILE__)). '/socials_code.php';
  87. $html = ob_get_clean();
  88. $links = str_replace( array('%POST_PERMALINK%'), array(get_permalink($post_id)), $html );
  89. if( $echo ) {
  90. echo $links;
  91. return false;
  92. }
  93. return $links;
  94. }
  95. function dt_get_like_buttons( $post_id = null, $wrap = '', $echo = true ) {
  96. if( !$wrap )
  97. $wrap = '<div class="dt-social-buttons">%s</div><style>.article{overflow: visible !important;}</style>';
  98. if( !dt_get_theme_options('use_custom_likes') ) {
  99. $links = dt_get_like_button('faceboock', $post_id, false);
  100. $links .= dt_get_like_button('twitter', $post_id, false);
  101. $links .= dt_get_like_button('google_plus', $post_id, false);
  102. }else {
  103. $links = dt_get_custom_like_buttons( $post_id, false );
  104. }
  105. $links = sprintf( $wrap, $links );
  106. if( $echo ) {
  107. echo $links;
  108. return false;
  109. }
  110. return $links;
  111. }
  112. function dt_get_like_window( $args = array(), $echo = true ) {
  113. if( !is_array($args) )
  114. $args = array();
  115. if( is_lb_enabled('twitter') )
  116. $args['tw'] = 1;
  117. if( is_lb_enabled('faceboock') )
  118. $args['fb'] = 1;
  119. if( is_lb_enabled('google_plus') )
  120. $args['gp'] = 1;
  121. if( dt_get_theme_options('use_custom_likes') )
  122. $args['use_custom'] = 1;
  123. $href = add_query_arg( $args, get_template_directory_uri().'/like_window.php' );
  124. ob_start();
  125. ?>
  126. <div class="dt-social-buttons dt-window-link">
  127. <a href="<?php echo esc_url($href); ?>" target="_blank" rel="nofollow" onClick="popupWin = window.open(this.href, 'like window', 'location,width=465,height=320,top=0'); popupWin.focus(); return false;"><?php _e('Like!', LANGUAGE_ZONE); ?></a>
  128. </div>
  129. <?php
  130. $html = ob_get_clean();
  131. if( $echo ) {
  132. echo $html;
  133. return false;
  134. }
  135. return $html;
  136. }
  137. ?>