/admin/shortcode.php

  1. <?php 
  2. /**-----------------------------------------------------------------------------------*/ 
  3. /* Footer Scripting for Short Code 
  4. /**-----------------------------------------------------------------------------------*/ 
  5.  
  6. // Global variable 
  7. $count = 0; 
  8.  
  9. function gl_get_script_footer() { 
  10. global $count; 
  11.  
  12. // General Values 
  13. $general_settings = gl_get_general_settings_values(); 
  14.  
  15. // Configure Urls 
  16. $postID = get_the_ID(); 
  17.  
  18. // Use postID = 0 and count = 1 in admin mode 
  19. if ( is_admin() ) { 
  20. $postID = 0; 
  21. $count = 1; 
  22.  
  23. // Footer Script and Callback Functions 
  24. $script_footer = $script_footer . ' 
  25. <!--  
  26. Creater Script for Google Locker 
  27. Created by WPTP Net 
  28. http://wptp.net 
  29. --> 
  30. '; 
  31.  
  32. // Google & Youtube Callback 
  33. if ( $general_settings[ 'google_active' ] || $general_settings[ 'google_share' ] || $general_settings[ 'youtube_active' ] ) { 
  34. $script_footer = $script_footer . ' 
  35. <script type="text/javascript"> 
  36. window.___gcfg = {lang: "' . $general_settings[ 'short_language' ] .'"}; 
  37.  
  38. (function() { 
  39. var po = document.createElement("script"); po.type = "text/javascript"; po.async = true; 
  40. po.src = "https://apis.google.com/js/platform.js"; 
  41. var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s); 
  42. })(); 
  43. </script> 
  44. <script type="text/javascript"> 
  45. function gl_unlock_g_social() { 
  46. gl_unlocksocial( "google" ); 
  47. }; 
  48. function gl_unlock_g_content() { 
  49. gl_unlockcontent( "google" ); 
  50. }; 
  51.  
  52. function gl_unlock_g_share_start_social( params ) { 
  53. if ( params.type == "confirm" ) 
  54. console.log("start social confirm"); 
  55. else if ( params.type == "hover" ) 
  56. console.log("start social hover"); 
  57. }; 
  58. function gl_unlock_g_share_start_content( params ) { 
  59. if ( params.type == "confirm" ) 
  60. console.log("start content confirm"); 
  61. else if ( params.type == "hover" ) 
  62. console.log("start content hover"); 
  63. }; 
  64.  
  65. function gl_unlock_g_share_end_social( params ) { 
  66. if ( params.type == "confirm" ) 
  67. gl_unlocksocial( "google_share" ); 
  68. else if ( params.type == "hover" ) 
  69. console.log("end social hover"); 
  70. }; 
  71. function gl_unlock_g_share_end_content( params ) { 
  72. if ( params.type == "confirm" ) 
  73. gl_unlockcontent( "google_share" ); 
  74. else if ( params.type == "hover" ) 
  75. console.log("end content hover"); 
  76. }; 
  77. </script> 
  78. <script type="text/javascript"> 
  79. function gl_unlock_y_social( payload ) { 
  80. if (payload.eventType == "subscribe") { 
  81. gl_unlocksocial( "youtube" ); 
  82. }  
  83. }; 
  84. function gl_unlock_y_content( payload ) { 
  85. if (payload.eventType == "subscribe") { 
  86. gl_unlockcontent( "youtube" ); 
  87. }; 
  88. </script> 
  89. '; 
  90.  
  91. // Lock & Unlock script 
  92. $script_footer = $script_footer . ' 
  93. <script type="text/javascript"> 
  94. var glTimerSocial = setInterval ( function() { lock("g-locker-to-lock-social"); }, 100 ); 
  95. var glTimerContent = setInterval ( function() { lock("g-locker-to-lock-content"); }, 100 ); 
  96.  
  97. function gl_unlocksocial( social ) { 
  98. clearInterval(glTimerSocial); 
  99. gl_createCookie("g_locker_social", ' . $general_settings[ 'cookie_days' ] . '); 
  100.  
  101. window.location.reload( true ); 
  102.  
  103. function gl_unlockcontent( social ) { 
  104. clearInterval(glTimerContent); 
  105. gl_createCookie("g_locker_' . $postID . '_content", ' . $general_settings[ 'cookie_days' ] . '); 
  106.  
  107. window.location.reload(true); 
  108.  
  109. function lock(className) { 
  110. var id = ""; 
  111. for ( i = 1; i <= ' . $count . '; i++ ) { 
  112. id = className + "-" + String(i); 
  113. var x = document.getElementById( id ); 
  114. if ( x ) { 
  115. x.style.display = "none"; 
  116. }  
  117. </script>  
  118. '; 
  119.  
  120. // Cookie 
  121. $script_footer = $script_footer . ' 
  122. <script type="text/javascript"> 
  123. function gl_createCookie(id, days) { 
  124. var d = new Date(); 
  125.  
  126. if ( days > 0 ) { 
  127. d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000)); 
  128. else { 
  129. d.setTime(d.getTime() + (24 * 60 * 60 * 1000)); 
  130.  
  131. var expires = "expires=" + d.toGMTString(); 
  132. document.cookie = id + "=true; " + expires; 
  133. </script>  
  134. '; 
  135.  
  136. // Effects 
  137. $script_footer = $script_footer . ' 
  138. <script> 
  139. function effectFadeToggle() { 
  140. jQuery(this).find("#g-locker-effect").stop(true, false).fadeToggle(); 
  141. function effectSlideToggle() { 
  142. jQuery(this).find("#g-locker-effect").stop(true, false).slideToggle(); 
  143. function effectToggle() { 
  144. jQuery(this).find("#g-locker-effect").stop(true, false).toggle("slow"); 
  145.  
  146. // for mouse down 
  147. function effectFadeToggleTimer() { 
  148. jQuery(this).find("#g-locker-effect").fadeToggle(); 
  149. jQuery(this).find("#g-locker-effect").delay( 1800 ).fadeToggle(); 
  150. function effectSlideToggleTimer() { 
  151. jQuery(this).find("#g-locker-effect").slideToggle(); 
  152. jQuery(this).find("#g-locker-effect").delay( 1800 ).slideToggle(); 
  153. function effectToggleTimer() { 
  154. jQuery(this).find("#g-locker-effect").toggle("slow"); 
  155. jQuery(this).find("#g-locker-effect").delay( 1800 ).toggle("slow"); 
  156.  
  157. jQuery( document ).ready( function() { 
  158. '; 
  159.  
  160. for ( $i = 1; $i <= $count; $i++ ) { 
  161. $script_footer = $script_footer . ' 
  162. jQuery( "#g-locker-google-one-fade-' . $i . '" ).hover( effectFadeToggle, effectFadeToggle ); 
  163. jQuery( "#g-locker-google-share-fade-' . $i . '" ).hover( effectFadeToggle, effectFadeToggle );  
  164. jQuery( "#g-locker-youtube-fade-' . $i . '" ).hover( effectFadeToggle, effectFadeToggle ); 
  165.  
  166. jQuery( "#g-locker-google-one-fade-' . $i . '" ).mousedown ( effectFadeToggleTimer ); 
  167. jQuery( "#g-locker-google-share-fade-' . $i . '" ).mousedown ( effectFadeToggleTimer ); 
  168. jQuery( "#g-locker-youtube-fade-' . $i . '" ).mousedown ( effectFadeToggleTimer ); 
  169.  
  170. //slide 
  171. jQuery( "#g-locker-google-one-slide-' . $i . '" ).hover( effectSlideToggle, effectSlideToggle ); 
  172. jQuery( "#g-locker-google-share-slide-' . $i . '" ).hover( effectSlideToggle, effectSlideToggle );  
  173. jQuery( "#g-locker-youtube-slide-' . $i . '" ).hover( effectSlideToggle, effectSlideToggle ); 
  174.  
  175. jQuery( "#g-locker-google-one-slide-' . $i . '" ).mousedown( effectSlideToggleTimer ); 
  176. jQuery( "#g-locker-google-share-slide-' . $i . '" ).mousedown( effectSlideToggleTimer );  
  177. jQuery( "#g-locker-youtube-slide-' . $i . '" ).mousedown( effectSlideToggleTimer ); 
  178.  
  179. //hide 
  180. jQuery( "#g-locker-google-one-hide-' . $i . '" ).hover( effectToggle, effectToggle ); 
  181. jQuery( "#g-locker-google-share-hide-' . $i . '" ).hover( effectToggle, effectToggle );  
  182. jQuery( "#g-locker-youtube-hide-' . $i . '" ).hover( effectToggle, effectToggle); 
  183.  
  184. jQuery( "#g-locker-google-one-hide-' . $i . '" ).mousedown( effectToggleTimer ); 
  185. jQuery( "#g-locker-google-share-hide-' . $i . '" ).mousedown( effectToggleTimer );  
  186. jQuery( "#g-locker-youtube-hide-' . $i . '" ).mousedown( effectToggleTimer ); 
  187. '; 
  188.  
  189. $script_footer = $script_footer . ' 
  190. }); 
  191. </script> 
  192. '; 
  193.  
  194. echo $script_footer; 
  195.  
  196. add_action( 'wp_footer', 'gl_get_script_footer' ); 
  197.  
  198. /**-----------------------------------------------------------------------------------*/ 
  199. /* Current Page Function 
  200. /**-----------------------------------------------------------------------------------*/ 
  201.  
  202. function gl_current_page( ) { 
  203. // Get Post ID and URL 
  204. $postID = get_the_ID(); 
  205. $postURL = get_permalink( $postID ); 
  206. return $postURL; 
  207.  
  208. /**-----------------------------------------------------------------------------------*/ 
  209. /* ShortCode Handler 
  210. /**-----------------------------------------------------------------------------------*/ 
  211.  
  212. function gl_locker_handle( $atts, $content ) { 
  213. // Extract variables from shortcode tag, set defaults 
  214. extract( shortcode_atts( array( 
  215. "type" => 'social' 
  216. ), $atts ) ); 
  217.  
  218. $type = strtolower( $type );  
  219. $postID = get_the_ID(); 
  220.  
  221. // Check Cookies 
  222. if ( $type == 'social' && $_COOKIE["g_locker_social"] == 'true') { 
  223. return do_shortcode( $content ); 
  224. else if ( $type == 'content' && $_COOKIE["g_locker_" . $postID . "_content"] == 'true') { 
  225. return do_shortcode( $content ); 
  226. else { 
  227. // General Values 
  228. $general_settings = gl_get_general_settings_values(); 
  229.  
  230. // Configure Urls 
  231. $youtube_channel = $general_settings[ 'youtube_channel' ]; 
  232. $googleurl = ( ($type == 'social') ? $general_settings[ 'google_url' ] : gl_current_page() ); 
  233. return gl_generate( $content, $type, $googleurl, $youtube_channel ); 
  234.  
  235. /** 
  236. * Generate Google Locker 
  237. */  
  238. function gl_generate( $content, $type, $googleurl, $youtube_channel, $is_preview = false ) { 
  239. // General Values 
  240. $general_settings = gl_get_general_settings_values(); 
  241.  
  242. // Locker Values 
  243. $social_lock_settings = gl_get_social_lock_setting_values(); 
  244. $content_lock_settings = gl_get_content_lock_setting_values(); 
  245.  
  246. $title = $social_lock_settings[ 'sl_title' ]; 
  247. $message = $social_lock_settings[ 'sl_message' ]; 
  248. $style = $social_lock_settings[ 'sl_style' ]; 
  249. $title_color = $social_lock_settings[ 'sl_title_color' ]; 
  250. $message_color = $social_lock_settings[ 'sl_message_color' ]; 
  251. $bg_color = $social_lock_settings[ 'sl_bg_color' ]; 
  252. $shadow_color = $social_lock_settings[ 'sl_shadow_color' ]; 
  253. $button_layout = $social_lock_settings[ 'sl_layout' ]; 
  254. $button_effect = $social_lock_settings[ 'sl_btn_effect' ]; 
  255.  
  256. if ( $type == 'content' ) { 
  257. $title = $content_lock_settings[ 'cl_title' ]; 
  258. $message = $content_lock_settings[ 'cl_message' ]; 
  259. $style = $content_lock_settings[ 'cl_style' ]; 
  260. $title_color = $content_lock_settings[ 'cl_title_color' ]; 
  261. $message_color = $content_lock_settings[ 'cl_message_color' ]; 
  262. $bg_color = $content_lock_settings[ 'cl_bg_color' ]; 
  263. $shadow_color = $content_lock_settings[ 'cl_shadow_color' ]; 
  264. $button_layout = $content_lock_settings[ 'cl_layout' ]; 
  265. $button_effect = $content_lock_settings[ 'cl_btn_effect' ]; 
  266.  
  267. // Layout Button 
  268. if ( $button_layout == 'count' ) { 
  269. $gp_layout = 'medium'; 
  270. $gps_layout = 'bubble'; 
  271. $youtube_layout = 'horizontal'; 
  272. $height_button = 22; 
  273. } else if ( $button_layout == 'box' ) { 
  274. $gp_layout = 'tall'; 
  275. $gps_layout = 'vertical-bubble'; 
  276. $youtube_layout = 'vertical'; 
  277. $height_button = 65; 
  278.  
  279. // Only use "Round Style" with "Count Social Layout" 
  280. if ( $button_layout == 'box' && $style == 'round' ) 
  281. $style = 'corner'; 
  282.  
  283. // Create Locker 
  284. global $count; 
  285. $count = $count + 1;  
  286.  
  287. // Create Button Locks 
  288. if ( $general_settings[ 'google_active' ] ) { 
  289. $btn_locks = $btn_locks . ' 
  290. <div class="g-locker-' . $style . '-box" id="g-locker-google-one-' . $button_effect . '-' . $count . '"> 
  291. <a class="g-locker-' . $style . '-effect" id="g-locker-effect" style="line-height: normal;"> 
  292. <div class="g-locker-' . $style . '-icon-google"></div> 
  293. </a> 
  294. <div class="g-locker-' . $style . '-button" style="line-height: normal; height:' . $height_button .'px;"> 
  295. <div class="g-plusone" data-size="' . $gp_layout . '" data-callback="gl_unlock_g_' . $type . '" data-href="' . $googleurl . '"></div> 
  296. </div> 
  297. </div> 
  298. '; 
  299. if ( $general_settings[ 'google_share' ] ) { 
  300. $btn_locks = $btn_locks . ' 
  301. <div class="g-locker-' . $style . '-box" id="g-locker-google-share-' . $button_effect . '-' . $count . '"> 
  302. <a class="g-locker-' . $style . '-effect" id="g-locker-effect" style="line-height: normal;"> 
  303. <div class="g-locker-' . $style . '-icon-google"></div> 
  304. </a> 
  305. <div class="g-locker-' . $style . '-button" style="line-height: normal; height:' . $height_button .'px;"> 
  306. <div class="g-plus" data-action="share" data-annotation="' . $gps_layout . '" data-onstartinteraction="gl_unlock_g_share_start_' . $type . '" data-onendinteraction="gl_unlock_g_share_end_' . $type . '" data-href="' . $googleurl . '" ></div> 
  307. </div> 
  308. </div> 
  309. '; 
  310. if ( $general_settings[ 'youtube_active' ] ) { 
  311. if ( $youtube_layout == 'vertical') { 
  312. $counter = gl_get_counter_youtube( $youtube_channel ); 
  313. $btn_locks = $btn_locks . ' 
  314. <div class="g-locker-' . $style . '-box" id="g-locker-youtube-' . $button_effect . '-' . $count . '"> 
  315. <a class="g-locker-' . $style . '-effect" id="g-locker-effect" style="line-height: normal;"> 
  316. <div class="g-locker-' . $style . '-icon-youtube"></div> 
  317. </a> 
  318. <div class="g-locker-' . $style . '-button" style="line-height: normal; height:' . $height_button .'px;"> 
  319. <div class="box_counter_ver" style="width: 88px;" ><span id="followers">' . $counter . '</span></div> 
  320. <div class="g-ytsubscribe" data-channel="' . $youtube_channel .'" data-count="hidden" data-onytevent="gl_unlock_y_' . $type . '"></div> 
  321. </div> 
  322. </div> 
  323. '; 
  324. } else { 
  325. $btn_locks = $btn_locks . ' 
  326. <div class="g-locker-' . $style . '-box" id="g-locker-youtube-' . $button_effect . '-' . $count . '"> 
  327. <a class="g-locker-' . $style . '-effect" id="g-locker-effect" style="line-height: normal;"> 
  328. <div class="g-locker-' . $style . '-icon-youtube"></div> 
  329. </a> 
  330. <div class="g-locker-' . $style . '-button" style="line-height: normal; height:' . $height_button .'px;"> 
  331. <div class="g-ytsubscribe" data-channel="' . $youtube_channel .'" data-onytevent="gl_unlock_y_' . $type . '"></div> 
  332. </div> 
  333. </div> 
  334. '; 
  335.  
  336. // Google Locker all 
  337. // before 
  338. $gl_locker = $gl_locker . '<div class="g-locker-' . $type . ' g-locker-' . $style . '" id="g-locker-' . $type . '-' . $count . '" style="background-color:' . $bg_color . '; box-shadow:0 0 40px ' . $shadow_color . '; -webkit-box-shadow:0 0 40px ' . $shadow_color . ';"> 
  339. '; 
  340.  
  341. // buttons locker 
  342. $gl_locker = $gl_locker . ' 
  343. <div class="g-locker-' . $style . '-text"> 
  344. <div class="g-locker-' . $style . '-strong" style="color: ' . $title_color . ';">' . $title . '</div> 
  345. <div class="g-locker-' . $style . '-message" style="color: ' . $message_color . ';">' . $message . '</div> 
  346. </div> 
  347. <div class="g-locker-' . $style . '-buttons"> 
  348. ' . $btn_locks . ' 
  349. </div> 
  350. '; 
  351.  
  352. // after 
  353. $gl_locker = $gl_locker . ' 
  354. </div> 
  355. '; 
  356.  
  357. return $gl_locker; 
  358.  
  359. /** 
  360. * Function convert number to short value with M, B, k 
  361. */ 
  362. function gl_get_number_format($value) { 
  363. if ( $value > 1000000000 ) return round( ($value/1000000000), 1 ).'B'; 
  364. else if ( $value > 1000000 ) return round( ($value/1000000), 1 ).'M'; 
  365. else if ( $value > 1000 ) return round( ($value/1000), 1 ).'k'; 
  366.  
  367. return $value; 
  368.  
  369. /** 
  370. * Function get Subscriber Counter for Youtube 
  371. */  
  372. function gl_get_counter_youtube($user) { 
  373.  
  374. $CHECK_URL_PREFIX = 'https://gdata.youtube.com/feeds/api/users/'; 
  375.  
  376. $check_url = $CHECK_URL_PREFIX . $user . '?alt=json'; 
  377.  
  378. try { 
  379. $response = file_get_contents( $check_url ); 
  380. $result = json_decode( $response, true ); 
  381.  
  382. if (isset( $result['entry']['yt$statistics']['subscriberCount'] )) { 
  383. return gl_get_number_format( $result['entry']['yt$statistics']['subscriberCount'] ); 
  384. else { 
  385. return "0"; 
  386. } catch ( Exception $e ) { 
  387. return "0"; 
  388.  
  389. /** 
  390. * Add the short code to WordPress 
  391. */ 
  392. add_shortcode( "g_locker", "gl_locker_handle" ); 
  393. ?> 
.