Guest User

wp_w3all_phpbb_iframe_short

a guest
Sep 28th, 2023
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | Photo | 0 0
  1. <?php defined( 'ABSPATH' ) or die( 'forbidden' );
  2. // 2022 -> @axew3.com //
  3.  
  4. // START (MAY) DO NOT MODIFY
  5.  
  6. if(defined("W3PHPBBCONFIG")){
  7. // detect if it is the uid2 in phpBB
  8. $phpBBuid2 = (isset($_COOKIE[W3PHPBBCONFIG["cookie_name"].'_u']) && $_COOKIE[W3PHPBBCONFIG["cookie_name"].'_u'] == 2) ? 2 : 0;
  9. } else { $phpBBuid2 = 0; }
  10. if(defined("WPW3ALL_NOT_ULINKED")) { $phpBBuid2 = 2; } // switch to be like it is uid2, so to avoid the reload of the page loop
  11. // the shortcode homepage push has been excluded more below where: if(w3all_passed_url != '' && inhomepageShort != 'inhomepage-phpbbiframe'){
  12. // exclude also if the passed url_push is set to 'no'
  13.  
  14. global $w3all_iframe_custom_w3fancyurl,$w3all_url_to_cms,$w3all_iframe_custom_top_gap,$w3cookie_domain,$wp_w3all_forum_folder_wp;
  15. $wp_w3all_forum_folder_wp = empty($ltm['wp_page_name']) ? $wp_w3all_forum_folder_wp : $ltm['wp_page_name'];
  16. $w3all_iframe_custom_top_gap = empty($ltm['wp_page_iframe_top_gap']) ? $w3all_iframe_custom_top_gap : $ltm['wp_page_iframe_top_gap'];
  17. $w3allhomeurl = get_home_url();
  18.  
  19. $current_user = wp_get_current_user();
  20. $w3all_url_to_cms_clean = $w3all_url_to_cms;
  21. $w3all_url_to_cms_clean0 = strpos($w3all_url_to_cms_clean, 'https://') !== false ? str_replace('https://', 'http://', $w3all_url_to_cms_clean) : str_replace('http://', 'https://', $w3all_url_to_cms_clean);
  22. // guess to get the domain.com to display into preloader // array order here is !important
  23. if(!empty($w3all_url_to_cms)){
  24. $w3guessdomaindisplay = str_replace(array("http://www.","https://www.","http://","https://"), array("","","",""), $w3all_url_to_cms);
  25. $spos = strpos($w3guessdomaindisplay,'/');
  26. if($spos !== false)
  27. {
  28. $w3guessdomaindisplay = substr($w3guessdomaindisplay, 0, $spos);
  29. }} else { $w3guessdomaindisplay = 'Did you setup the URL that point to phpBB into the integration plugin admin page<br /> and is it correct?'; }
  30.  
  31. if(!empty($w3cookie_domain)){
  32. if(substr($w3cookie_domain, 0, 1) == '.'){
  33. $document_domain = substr($w3cookie_domain, 1);
  34. } else {
  35. $document_domain = $w3cookie_domain;
  36. }
  37. } else {
  38. $document_domain = 'localhost';
  39. }
  40.  
  41. // do not use wp is_ssl() because it fail on some server
  42. $w3all_orig = strpos($w3all_url_to_cms,'https') !== false ? 'https://'. $document_domain : 'http://' . $document_domain;
  43. $w3all_orig_www = strpos($w3all_url_to_cms,'https') !== false ? 'https://www.'. $document_domain : 'http://www.' . $document_domain;
  44.  
  45. // security switch
  46. $w3all_url_to_cms0 = $w3all_url_to_cms_sw = $w3all_url_to_cms;
  47.  
  48. if( isset($_GET["w3"]) ){ // default
  49. $phpbb_url = trim(base64_decode($_GET["w3"]));
  50. $w3all_url_to_cms_sw = $w3all_url_to_cms . '/' . $phpbb_url;
  51. if( preg_match('/[^-0-9A-Za-z\._#\:\?\/=&%]/ui',$phpbb_url) ){
  52. $w3all_url_to_cms_sw = $w3all_url_to_cms0;
  53. }
  54. } elseif ( isset($_GET[$w3all_iframe_custom_w3fancyurl]) ){ //fancy
  55. $phpbb_url = trim(base64_decode($_GET[$w3all_iframe_custom_w3fancyurl]));
  56. $w3all_url_to_cms_sw = $w3all_url_to_cms . '/' . $phpbb_url;
  57. if( preg_match('/[^-0-9A-Za-z\._#\:\?\/=&%]/ui',$phpbb_url) ){
  58. $w3all_url_to_cms_sw = $w3all_url_to_cms0;
  59. }
  60. }
  61.  
  62. // old way - to be removed
  63. // assure that passed url is correctly all decoded // may something else need to added in certain conditions
  64. $w3all_url_to_cms_sw = str_replace(array("%2F", "%23", "%2E"), array("/", "#", "."), $w3all_url_to_cms_sw);
  65.  
  66. // bug -> https://wordpress.org/support/topic/problem-using-iframe-feature-with-https/
  67. if( strlen($w3all_url_to_cms_sw) == strlen(get_option( 'w3all_url_to_cms' )) OR strlen($w3all_url_to_cms_sw) == strlen(get_option( 'w3all_url_to_cms' )) + 1 )
  68. {
  69. // do not rewrite value of the global $w3all_url_to_cms or it will be may appended into widgets avatars urls, so that will make it fail image loads
  70. $w3all_url_to_cms_sw = $w3all_url_to_cms;
  71. $w3all_url_to_cms_sw .= (substr($w3all_url_to_cms, -1) == '/' ? '' : '/index.php');
  72. } else { $w3all_url_to_cms_sw = $w3all_url_to_cms; }
  73.  
  74. $w3all_url_to_cms_switch_phpbb_default_url = (empty($ltm['phpbb_default_url'])) ? $w3all_url_to_cms_sw : $ltm['phpbb_default_url'];
  75.  
  76. echo'<!-- noscript warning and simple preloader -->
  77. <div id="w3idwloader" class="w3_wrap_loader">
  78. <noscript><h3 style="background-color:#333;color:#FFF;padding:15px;font-size:0.8em;pointer-events:auto;">Javascript disabled: can\'t load the forum page at this Url.<br />Enable Javascript on your browser or visit the forum here:<br /><br />'.$w3all_url_to_cms.'<br /><a href="'.$w3all_url_to_cms.'">To be auto-redirected click here<br />(may this link will not work)</a></h3></noscript>
  79. <div class="w3preloadtext">'.$w3guessdomaindisplay.'</div>
  80. <div class="ww3_loader"><div class="w3_loader"></div></div>
  81. </div>
  82. <!-- START iframe div -->
  83. <div style="width:100%;min-width:100%" id="w3all_wrap_phpbb_forum_shortcode_div_id" class="w3all_wrap_phpbb_forum_shortcode_div_class">
  84. <iframe id="w3all_phpbb_iframe" style="width:1px;min-width:100%;*width:100%;border:0;" scrolling="no" src="'.$w3all_url_to_cms_switch_phpbb_default_url.'"></iframe>
  85. ';
  86. echo "<script type=\"text/javascript\">
  87. document.domain = 'knigi-igri.net'; // NOTE: for domains like 'mysite.co.uk' remove this line, if you setup the next to match the correct document.domain
  88. // document.domain = 'mydomain.com'; // NOTE: reset/setup this with domain (like mysite.co.uk) if js error when WP is installed like on mysite.domain.com and phpBB on domain.com: js origin error can come out for example when WordPress is on subdomain install and phpBB on domain. The origin fix is needed: (do this also on phpBB overall_footer.html added code, it need to match)
  89. var wp_u_logged = ".$current_user->ID.";
  90. var phpBBuid2 = ".$phpBBuid2.";
  91. var inhomepageShort = '".$ltm['wp_page_name']."';
  92. var w3urlpush = '".$ltm['url_push']."';
  93. var w3scrolldefault = '".$ltm['scroll_default']."';
  94. var w3allhomeurl = '".$w3allhomeurl."';
  95. var wp_w3all_forum_folder_wp = '".$wp_w3all_forum_folder_wp."';
  96. var w3all_iframe_custom_w3fancyurl = '".$w3all_iframe_custom_w3fancyurl."';
  97.  
  98. function w3all_phpbb_pushUrlToParentOnBackForward(w3ER){
  99. if(w3ER != ''){
  100. var rem = w3ER.slice(-1);
  101. if(rem == '#'){ w3ER = w3ER.substring(0, w3ER.length - 1); }
  102. w3ER = window.btoa(unescape(encodeURIComponent(w3ER)));
  103. var w3all_url_pushER = w3allhomeurl + '/' + wp_w3all_forum_folder_wp + '/?' + w3all_iframe_custom_w3fancyurl + '=' + w3ER;
  104. window.history.replaceState({}, \"\", w3all_url_pushER);
  105. }
  106. }
  107.  
  108. function w3all_ajaxup_from_phpbb(res){
  109. var w3all_phpbb_u_logged = /#w3all_phpbb_u_logged=1/ig.exec(res);
  110.  
  111. if(phpBBuid2 != 2){ // if not phpBB uid 2 or get loop for this user
  112. if( w3all_phpbb_u_logged == null && wp_u_logged > 1 || wp_u_logged == 0 && w3all_phpbb_u_logged != null ){
  113. document.location.replace('".$w3allhomeurl."/index.php/".$wp_w3all_forum_folder_wp."/');
  114. }
  115. }
  116. jQuery('#w3idwloader').css(\"display\",\"none\");
  117. var w3all_phpbbpmcount = /.*(#w3all_phpbbpmcount)=([0-9]+).*/ig.exec(res);
  118. if(w3all_phpbbpmcount !== null){
  119. w3all_ajaxup_from_phpbb_do(w3all_phpbbpmcount[2]);
  120. }
  121.  
  122. if(w3scrolldefault == 'yes'){
  123. var w3all_lochash = /.*(#w3all_lochash)=([0-9]+).*/ig.exec(res);
  124. if(w3all_lochash !== null && w3all_lochash[2] != 0){
  125. jQuery('html, body').animate({ scrollTop: w3all_lochash[2]}, 400);
  126. } else {
  127. jQuery('html, body').animate({ scrollTop: ".$w3all_iframe_custom_top_gap."}, 400);
  128. }
  129. } // if(w3scrolldefault
  130.  
  131. } // END w3all_ajaxup_from_phpbb(res){
  132.  
  133. // array() of allowed domains
  134.  
  135. var w3all_orig_domains = ['".$w3all_orig."','".$w3all_orig_www."','".$w3all_url_to_cms_clean."','".$w3all_url_to_cms_clean0."','https://localhost','http://localhost'];
  136.  
  137. iFrameResize({
  138. log : false,
  139. inPageLinks : true,
  140. targetOrigin: '".$w3all_url_to_cms."',
  141. checkOrigin : w3all_orig_domains,
  142. // heightCalculationMethod: 'taggedElement', // If iframe not resize correctly, un-comment (or change with one of others available resize methods)
  143. // see: https://github.com/davidjbradshaw/iframe-resizer/blob/master/docs/parent_page/options.md
  144.  
  145. onMessage : function(messageData){ // Callback fn when message is received
  146. // w3all simple js check and redirects
  147. var w3all_passed_url = messageData.message.toString();
  148. var w3all_ck = \"".$_SERVER['SERVER_NAME']."\";
  149. var w3all_pass_ext = (w3all_passed_url.indexOf(w3all_ck) > -1);
  150. var w3all_ck_preview = (w3all_passed_url.indexOf('preview') > -1);
  151.  
  152. if (w3all_ck_preview == false) { // or the phpBB passed preview link, will be recognized as external, and preview will redirect to full forum url instead
  153. // so these are maybe, external iframe redirects
  154. if (w3all_pass_ext == true) {
  155. window.location.replace(w3all_passed_url);
  156. }
  157. if (/^(f|ht)tps?:\/\//i.test(w3all_passed_url)) {
  158. window.location.replace(w3all_passed_url);
  159. }
  160. }
  161.  
  162. // do not pass to be encoded an url with sid or if it point to phpBB admin ACP via iframe
  163. if( /[^-0-9A-Za-z\._#\:\?\/=&%]/ig.exec(w3all_passed_url) !== null || /adm\//ig.exec(w3all_passed_url) !== null || /sid=/ig.exec(w3all_passed_url) !== null ){
  164. w3all_passed_url = '';
  165. }
  166. // PUSH phpBB URLs // do not push in home if inhomepage-phpbbiframe set. If not set then page-forum ($wp_w3all_forum_folder_wp value) need to exist
  167. if(w3all_passed_url != '' && inhomepageShort != 'inhomepage-phpbbiframe' && w3urlpush == 'yes'){
  168. w3all_passed_url = window.btoa(unescape(encodeURIComponent(w3all_passed_url)));
  169. var w3all_passed_url_push = '".$w3allhomeurl."/".$wp_w3all_forum_folder_wp."/?".$w3all_iframe_custom_w3fancyurl."=' + w3all_passed_url;
  170. history.replaceState({w3all_passed_url: w3all_passed_url}, \"\", w3all_passed_url_push);
  171. }
  172. } // end // onMessage
  173. ,
  174. onScroll: function(x,y){
  175. //return false;
  176. }
  177. });
  178. </script>";
  179.  
  180. echo'</div><!-- END iframe div -->';
  181.  
Add Comment
Please, Sign In to add comment