Guest User

page-board

a guest
Sep 28th, 2023
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.19 KB | Photo | 0 0
  1. <?php defined( 'ABSPATH' ) or die( 'forbidden' );
  2. /*
  3. Template Name: Forum
  4. Template Post Type: page
  5. * The default wp_w3all template to display content for the embedded phpBB
  6. * @package WordPress
  7. * @subpackage wp_w3all
  8. * @V5 JS -> https://www.axew3.com/w3/2018/12/phpbb-wordpress-template-integration-iframe-v5/
  9. */
  10. // @2022 axew3.com //
  11.  
  12. // START MAY DO NOT MODIFY
  13.  
  14. if(defined("W3PHPBBCONFIG")){
  15. // detect if it is the uid2 in phpBB and avoid iframe loop
  16. $phpBBuid2 = (isset($_COOKIE[W3PHPBBCONFIG["cookie_name"].'_u']) && $_COOKIE[W3PHPBBCONFIG["cookie_name"].'_u'] == 2) ? 2 : 0;
  17. } else { $phpBBuid2 = 0; }
  18. // detect if running as no linked users mode and avoid iframe loop
  19. if(defined("WPW3ALL_NOT_ULINKED")) { $phpBBuid2 = 0; }
  20.  
  21. global $w3all_iframe_custom_w3fancyurl,$w3all_url_to_cms,$w3all_iframe_custom_top_gap,$w3cookie_domain,$wp_w3all_forum_folder_wp;
  22. $w3allhomeurl = get_home_url();
  23. $current_user = wp_get_current_user();
  24. $w3all_url_to_cms_clean = $w3all_url_to_cms;
  25. $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);
  26. // guess to get the domain.com to display into preloader // array order here is !important
  27. if(!empty($w3all_url_to_cms)){
  28. $w3guessdomaindisplay = str_replace(array("http://www.","https://www.","http://","https://"), array("","","",""), $w3all_url_to_cms);
  29. $spos = strpos($w3guessdomaindisplay,'/');
  30. if($spos !== false)
  31. {
  32. $w3guessdomaindisplay = substr($w3guessdomaindisplay, 0, $spos);
  33. }} else { $w3guessdomaindisplay = 'Did you setup the URL that point to phpBB into the integration plugin admin page<br /> and is it correct?'; }
  34.  
  35. if(!empty($w3cookie_domain)){
  36. if(substr($w3cookie_domain, 0, 1) == '.'){
  37. $document_domain = substr($w3cookie_domain, 1);
  38. } else {
  39. $document_domain = $w3cookie_domain;
  40. }
  41. } else {
  42. $document_domain = 'localhost';
  43. }
  44.  
  45. // do not use wp is_ssl() because it fail on some server
  46. $w3all_orig = strpos($w3all_url_to_cms,'https') !== false ? 'https://'. $document_domain : 'http://' . $document_domain;
  47. $w3all_orig_www = strpos($w3all_url_to_cms,'https') !== false ? 'https://www.'. $document_domain : 'http://www.' . $document_domain;
  48.  
  49. // security switch
  50. $w3all_url_to_cms0 = $w3all_url_to_cms;
  51.  
  52. if( isset($_GET["w3"]) ){ // default
  53. $phpbb_url = trim(base64_decode($_GET["w3"]));
  54. $w3all_url_to_cms = $w3all_url_to_cms . '/' . $phpbb_url;
  55. if( preg_match('/[^-0-9A-Za-z\._#\:\?\/=&%]/ui',$phpbb_url) ){
  56. $w3all_url_to_cms = $w3all_url_to_cms0;
  57. }
  58. } elseif ( isset($_GET[$w3all_iframe_custom_w3fancyurl]) ){ //fancy
  59. $phpbb_url = trim(base64_decode($_GET[$w3all_iframe_custom_w3fancyurl]));
  60. $w3all_url_to_cms = $w3all_url_to_cms . '/' . $phpbb_url;
  61. if( preg_match('/[^-0-9A-Za-z\._#\:\?\/=&%]/ui',$phpbb_url) ){
  62. $w3all_url_to_cms = $w3all_url_to_cms0;
  63. }
  64. }
  65.  
  66. // assure that passed url is correctly all decoded // may something else need to be added in certain conditions
  67. $w3all_url_to_cms = str_replace(array("%2F", "%23", "%2E"), array("/", "#", "."), $w3all_url_to_cms);
  68.  
  69. // bug -> https://wordpress.org/support/topic/problem-using-iframe-feature-with-https/
  70. if( strlen($w3all_url_to_cms) == strlen(get_option( 'w3all_url_to_cms' )) OR strlen($w3all_url_to_cms) == strlen(get_option( 'w3all_url_to_cms' )) + 1 )
  71. {
  72. // do not re-write value of the global $w3all_url_to_cms or index.php will be may appended into widgets avatars urls, so that will make it fail image loads
  73. $w3all_url_to_cms_sw = $w3all_url_to_cms;
  74. $w3all_url_to_cms_sw .= (substr($w3all_url_to_cms, -1) == '/' ? '' : '/index.php');
  75. } else { $w3all_url_to_cms_sw = $w3all_url_to_cms; }
  76.  
  77. function w3all_enqueue_scripts() {
  78. wp_enqueue_script("jquery");
  79. }
  80.  
  81. function wp_w3all_add_ajax() {
  82. global $w3all_url_to_cms,$w3all_url_to_cms_sw,$wp_w3all_forum_folder_wp,$w3allhomeurl;
  83.  
  84. $w3all_url_to_phpbb_ib = $w3all_url_to_cms . "/ucp.php?i=pm&folder=inbox";
  85.  
  86. $s = "
  87. <script type=\"text/javascript\" src=\"".plugins_url()."/wp-w3all-phpbb-integration/addons/resizer/iframeResizer.min.js\"></script>
  88. <script type=\"text/javascript\">
  89. // pre loader js code for iframe content
  90. jQuery( document ).ready(function() {
  91. jQuery('#w3idwloader').attr( \"class\", \"w3_wrap_loader\" );
  92. });
  93. jQuery(window).load(function() {
  94. jQuery('#w3idwloader').css(\"display\",\"none\");
  95. });
  96.  
  97. function w3all_ajaxup_from_phpbb_do(res){
  98. jQuery(document).ready(function() {
  99. if ( parseInt(res,10) > 0 && null == (document.getElementById('wp-admin-bar-w3all_phpbb_pm')) ){
  100. var resp = '".__( 'You have ', 'wp-w3all-phpbb-integration' )."' + parseInt(res,10) + '".__( ' unread forum PM', 'wp-w3all-phpbb-integration' )."';
  101. jQuery('#wp-admin-bar-root-default').append('<li id=\"wp-admin-bar-w3all_phpbb_pm\"><a class=\"ab-item\" href=\"".$w3all_url_to_phpbb_ib."\">' + resp + '</li>');
  102. // window.location.reload(true);// this could be a work around for different themes, but lead to loop in this way
  103. } else if (parseInt(res,10) > 0){
  104. var r = '".__( 'You have ', 'wp-w3all-phpbb-integration' )."' + parseInt(res,10) + '".__( ' unread forum PM', 'wp-w3all-phpbb-integration' )."';
  105. jQuery( 'li.w3all_phpbb_pmn' ).children().text( r );
  106. } else {
  107. if( parseInt(res,10) == 0 && null !== (document.getElementById('wp-admin-bar-w3all_phpbb_pm'))){
  108. jQuery('li[id=wp-admin-bar-w3all_phpbb_pm]').remove();
  109. }
  110. }
  111. });
  112. }
  113. </script>
  114. <style type=\"text/css\" media=\"screen\">
  115. .w3preloadtext{
  116. color:#DDD;
  117. font-size:3.5em;
  118. font-family:impact,arial, sans-serif;
  119. font-style:italic;
  120. text-shadow: rgba(0,0,0,0) -1px 0px;
  121. }
  122. .w3_wrap_loader{
  123. position:fixed;
  124. top:0%;
  125. bottom:0%;
  126. left:0%;
  127. right:0%;
  128. background: rgba(0,0,0,0.95);
  129. z-index:99999;
  130. opacity:90;
  131. -webkit-transition: opacity 400ms ease-in;
  132. -moz-transition: opacity 400ms ease-in;
  133. transition: opacity 400ms ease-in;
  134. width:100%;
  135. text-align:center;
  136. display:flex;
  137. flex-direction:column;
  138. align-items:center;
  139. justify-content:center;
  140. pointer-events:none;
  141. height:100%;
  142. }
  143. .ww3_loader{
  144. width:100%;
  145. text-align:center;
  146. }
  147. .w3_loader {
  148. height: 8px;
  149. width: 30%;
  150. align-items: center;
  151. justify-content: center;
  152. position: relative; left: 50%;
  153. transform: translateX(-50%);
  154. overflow: hidden;
  155. background-color: #DDD;
  156. border-radius: 20px;
  157. margin:0px;padding:0px;
  158. }
  159. .w3_loader:before{
  160. height: 8px;
  161. border-radius: 20px;
  162. display: block;
  163. position: absolute;
  164. content: \"\";
  165. left: -200px;
  166. width: 200px;
  167. background-color: #333;
  168. animation: loading 1s linear infinite;
  169. }
  170. @keyframes loading {
  171. from {left: -200px; width: 30%;}
  172. 50% {width: 30%;}
  173. 70% {width: 70%;}
  174. 80% { left: 50%;}
  175. 95% {left: 120%;}
  176. to {left: 100%;}
  177. }
  178. </style>
  179. ";
  180. echo $s;
  181. }
  182.  
  183. add_action('wp_enqueue_scripts', 'w3all_enqueue_scripts');
  184. add_action('wp_head','wp_w3all_add_ajax');
  185.  
  186. // END MAY DO NOT MODIFY
  187.  
  188. // START a default WordPress page
  189. get_header();
  190. ?>
  191. <!-- noscript warning and simple preloader -->
  192. <div id="w3idwloader" class="w3_wrap_loader">
  193. <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 /><?php echo $w3all_url_to_cms;?><br /><a href="<?php echo $w3all_url_to_cms;?>">To be auto-redirected click here<br />(may this link will not work)</a></h3></noscript>
  194. <div class="w3preloadtext"><?php echo $w3guessdomaindisplay ; ?></div>
  195. <div class="ww3_loader"><div class="w3_loader"></div></div>
  196. </div>
  197. <!-- START iframe div -->
  198. <div style="width:100%;min-width:100%" id="" class="">
  199. <iframe id="w3all_phpbb_iframe" style="width:1px;min-width:100%;*width:100%;border:0;" scrolling="no" src="<?php echo $w3all_url_to_cms; ?>"></iframe>
  200. <?php
  201. echo "<script>
  202. 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
  203. //document.domain = '192.168.1.6'; // 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)
  204. var wp_u_logged = ".$current_user->ID.";
  205. var phpBBuid2 = ".$phpBBuid2.";
  206. var w3allhomeurl = '".$w3allhomeurl."';
  207. var wp_w3all_forum_folder_wp = '".$wp_w3all_forum_folder_wp."';
  208. var w3all_iframe_custom_w3fancyurl = '".$w3all_iframe_custom_w3fancyurl."';
  209.  
  210. function w3all_phpbb_pushUrlToParentOnBackForward(w3ER){
  211. if(w3ER != ''){
  212. var rem = w3ER.slice(-1);
  213. if(rem == '#'){ w3ER = w3ER.substring(0, w3ER.length - 1); }
  214. w3ER = window.btoa(unescape(encodeURIComponent(w3ER)));
  215. var w3all_url_pushER = w3allhomeurl + '/' + wp_w3all_forum_folder_wp + '/?' + w3all_iframe_custom_w3fancyurl + '=' + w3ER;
  216. window.history.replaceState({}, \"\", w3all_url_pushER);
  217. }
  218. }
  219.  
  220. function w3all_ajaxup_from_phpbb(res){
  221. var w3all_phpbb_u_logged = /#w3all_phpbb_u_logged=1/ig.exec(res);
  222.  
  223. if(phpBBuid2 != 2){ // if not phpBB uid 2 or get loop for this user
  224. if( w3all_phpbb_u_logged == null && wp_u_logged > 1 || wp_u_logged == 0 && w3all_phpbb_u_logged != null ){
  225. document.location.replace('".$w3allhomeurl."/index.php/".$wp_w3all_forum_folder_wp."/');
  226. }
  227. }
  228. jQuery('#w3idwloader').css(\"display\",\"none\");
  229. var w3all_phpbbpmcount = /.*(#w3all_phpbbpmcount)=([0-9]+).*/ig.exec(res);
  230. if(w3all_phpbbpmcount !== null){
  231. w3all_ajaxup_from_phpbb_do(w3all_phpbbpmcount[2]);
  232. }
  233.  
  234. var w3all_lochash = /.*(#w3all_lochash)=([0-9]+).*/ig.exec(res);
  235. if(w3all_lochash !== null && w3all_lochash[2] != 0){
  236. jQuery('html, body').animate({ scrollTop: w3all_lochash[2]}, 400);
  237. } else {
  238. jQuery('html, body').animate({ scrollTop: ".$w3all_iframe_custom_top_gap."}, 400);
  239. }
  240.  
  241. } // END w3all_ajaxup_from_phpbb(res){
  242.  
  243. // array() of allowed domains
  244.  
  245. var w3all_orig_domains = ['".$w3all_orig."','".$w3all_orig_www."','".$w3all_url_to_cms_clean."','".$w3all_url_to_cms_clean0."','https://localhost','http://localhost'];
  246.  
  247. iFrameResize({
  248. log : false,
  249. inPageLinks : true,
  250. targetOrigin: '".$w3all_url_to_cms_sw."',
  251. checkOrigin : w3all_orig_domains,
  252. // heightCalculationMethod: 'documentElementOffset', // If iframe not resize correctly, un-comment (or change with one of others available resize methods)
  253. // see: https://github.com/davidjbradshaw/iframe-resizer#heightcalculationmethod
  254.  
  255. onMessage : function(messageData){ // Callback fn when message is received
  256. // w3all simple js check and redirects
  257. var w3all_passed_url = messageData.message.toString();
  258. var w3all_ck = \"".$_SERVER['SERVER_NAME']."\";
  259. var w3all_pass_ext = (w3all_passed_url.indexOf(w3all_ck) > -1);
  260. var w3all_ck_preview = (w3all_passed_url.indexOf('preview') > -1);
  261.  
  262. 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
  263. // so these are maybe, external iframe redirects
  264. if (w3all_pass_ext == true) {
  265. window.location.replace(w3all_passed_url);
  266. }
  267. if (/^(f|ht)tps?:\/\//i.test(w3all_passed_url)) {
  268. window.location.replace(w3all_passed_url);
  269. }
  270. }
  271.  
  272. // do not pass to be encoded an url with sid or if it point to phpBB admin ACP via iframe
  273. 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 ){
  274. w3all_passed_url = '';
  275. }
  276. // PUSH phpBB URLs //
  277. if(w3all_passed_url != ''){
  278. w3all_passed_url = window.btoa(unescape(encodeURIComponent(w3all_passed_url)));
  279. var w3all_passed_url_push = '".$w3allhomeurl."/".$wp_w3all_forum_folder_wp."/?".$w3all_iframe_custom_w3fancyurl."=' + w3all_passed_url;
  280. history.replaceState({}, \"\", w3all_passed_url_push);
  281. }
  282. } // end // onMessage
  283. ,
  284. onScroll: function(x,y){
  285. //return false;
  286. }
  287. });
  288. </script>";
  289. ?>
  290. </div>
  291. <!-- END iframe div -->
  292. <?php get_footer();
Add Comment
Please, Sign In to add comment