htaccess trick for right click /copy/paste/ links

mLgz0rn
User ww
User ww
Posts: 42
Joined: Fri Jan 20, 2017 5:23 pm

htaccess trick for right click /copy/paste/ links

Post by mLgz0rn »

Hey Axe!

Did you remove the "htaccess trick for right click /copy/paste/ links" from the code that needs to be pasted into overall_footer.html?
Because with the new version of w3all wp it does not seem to be there.

Did you add another way to copy links within the iframed forum?

I used to have this code

Code: Select all

///////////////////////////////////////////////////////////////////////////
// htaccess trick for right click /copy/paste/ links
// to apply htaccess rules and rewrite urls for this and email notification, please read this tutorial:
// https://www.axew3.com/w3/2017/04/wp_w3all-htaccess-javascript-rewrite-links-point-iframe-how-to/
 
// remove starting /* and ending */ 
// that wrap the code here below to activate
 
 // remove this line to activate click /copy/paste/ links x htaccess
 
$( "a" ).contextmenu(function() {
  var href = $(this).attr("href");
  var shortlink = /^#p[0-9]+/ig.exec(href);
	var ck  = (href.indexOf('iframe=true') > -1);
	var ckl = /^(http[s]?:\/\/[-a-z0-9\.]+)/ig.exec(href); // check if link point to external resource: a passed phpBB url (attr("href")) is relative, not absolute: so we assume that if http(s) is present, 
	// than it should be a link that point to an external iframe resource. Can be improved further more using this same pattern result.
	// for app.php url type
	var ckApp = (href.indexOf('app.php/') > -1);
	  if ( ckApp == true ){
	  	var hrefApp = href.split('app.php/');
	  	var hA = hrefApp[0] + 'app.php/iframe=true/' + hrefApp[1];
	  	$(this).attr("href", hA); // send out before mouseup ...
	  	//http://rng.clanroyal.dk/forums/app.php/iframe=true/applicationform
	  }  
	  
	else if ( ck == false && ckl == null && shortlink == null ){ // not re-append // not append if short link like #p49 (link of the post on viewtopic) or passed link point to an external resource
	 	  var href0 = href.split('?');
	 	  if(href0[1] == null){ href0[1] = ''; } else { href0[1] = '&' + href0[1]; }
      var href1 = href0[0] + '?iframe=true' + href0[1];
    $(this).attr("href", href1); // send out before mouseup ...
   }
});
$( "a" ).mouseup(function() { // but remove on mouseup, or leaving iframe=true we'll loop with htaccess ...
  var href = $(this).attr("href");
  var ck0  = (href.indexOf('iframe=true/') > -1);
  if ( ck0 == true ){
  $(this).attr("href", href.replace('iframe=true/', ''));
  } else {
  $(this).attr("href", href.replace('iframe=true&', ''));
  }
});
Which seems to have been replaced with this?

Code: Select all

// htaccess isn't needed anymore 
$( "a" ).contextmenu(function() {
  var href = $(this).attr("href");
  var ohref = href;
  var applink = /app\.php[\w\/]+/ig.exec(href);
	var ckext = /^(f|ht)tps?:\/\//i.test(href); // external resource url?
	var ffile = '';
	var shortinp = /^#[a-z][0-9]+$/ig.exec(href);
	var shortfaq = /^#[a-z][a-z0-9]+$/ig.exec(href);
	var hrefu = document.location.href;
if ( href.charAt(0) == '.' && href.charAt(1) == '/' ){
	ffile = ohref;
} else {
  pu = href.split('app.php');
	ffile = './app.php' + pu[1];
}

if( shortinp != null ){
	 ffile = './' + hrefu.split('\\').pop().split('/').pop();
 }
 
 if( shortfaq != null && href.charAt(1) != 'p'){
 	pu = hrefu.split('app.php');
	ffile = './app.php' + pu[1] + shortfaq;
 }
 
var d = ffile;	 
if( href.length < 2 ){ // #
  d = document.location.href;
 }

  hrefEnc = window.btoa(unescape(encodeURIComponent(d)));
  href1 =  wordpress_url_page_forum + '/?w3=' + hrefEnc;
     
 if( ckext != false ){ // external Url
 	href1 = ohref;
 }
      
  $(this).attr("href", href1); // send out encoded
  $(this).mouseout(function() { // reset
  $(this).attr("href", ohref);
});

});
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: htaccess trick for right click /copy/paste/ links

Post by axew3 »

Hi! Yes correct: because the problem was that a particular var, p used on both cms and values to pass (vars) as are them self:
the url to push is now passed to page_forum in overall_footer.html where

Code: Select all

hrefEnc = window.btoa(unescape(encodeURIComponent(d)));
pushed then in page-forum where:

Code: Select all

history.pushState(w3all_passed_url_push, 'Forum page', w3all_passed_url_push);
as base_64 value: if page reloaded by user, another time, where

Code: Select all

if( isset($_GET["w3"]) ){
 $phpbb_url = base64_decode($_GET["w3"]);
 $phpbb_url = trim(utf8_encode($phpbb_url));
	 if( preg_match('/[^-0-9A-Za-z\._#\:\?\/=&%]/i',$phpbb_url) ){
    $w3all_url_to_cms = $w3all_url_to_cms;
   } else {
	   $phpbb_url = substr($phpbb_url, 1);
	   $w3all_url_to_cms = $w3all_url_to_cms . "".$phpbb_url."";
    }
}
decode and pass.
It is a way to bypass all problems, and that never fail, making quite easy the integration complete about right-click and open in new window a forum's link, as well the fact about url to be pushed, that in this way never conflict with anything. It is wrapped encoded into a var named w3.
That work for any link. Try it, never fail in any iframed board link-
htaccess isn't needed anymore also for email notification links! I've not apply this part nor here on this board, but it is very easy. I will complete the documentation and code about this as soon. Since there is no more a var p around, but an encoded string, will be just necessary add a line into overall_header.html: if the url contain let say as is on old example the var iframe=true then redirect to passed url directly: the url not contain any var p because encoded. This the trick. No conflict. no htaccess needed to rewirte var p into post_id.
Shorter code that can be further decreased.
Hope my poor explain here is quite clear to understand something.
I'll return back soon, working for a quite big site actually, migrating and integrating. One task between others was: no iframe, but complex header of main page needed into phpBB. Since the header of this new building site contain several elements, multiple and sub menu, ads etc, i was quite worried on reproduce all these shits you know ... well, i discovered a way to iframe the header of any site, into another on same domain (but also cross domain) showing exactly what needed in a let me say not common way. Result is awesome (the guy working with me to setup the site is amazed by the result, and i'm little proud yes!). Will be a pleasure to make a tutorial about this and working example showed somewhere here around.
mLgz0rn
User ww
User ww
Posts: 42
Joined: Fri Jan 20, 2017 5:23 pm

Re: htaccess trick for right click /copy/paste/ links

Post by mLgz0rn »

Ah okay.

Does this mean I can remove all .htaccess code made for w3all in phppbb and wp?
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: htaccess trick for right click /copy/paste/ links

Post by axew3 »

using the new code yes!
embed phpBB into wordpress page

but you'll leave the two lines added into htaccess, if needed to rewrite for email notification links to point to iframe, that as said, can be achieved also with javascript in a more easy way, but not still added on code documentation.
Applied code fixes resolve all and any iframe issues reported along the time.
Post Reply