Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> ShortLinks/TegoNuke
Author Message
killing-hours
RavenNuke(tm) Development Team



Joined: Oct 01, 2010
Posts: 438
Location: Houston, Tx

PostPosted: Tue Mar 22, 2011 12:06 pm Reply with quote

Montego (or whomever)-

Working with shortlinks for the first time today and finding what bugs are to be found with how I do things on my site and I noticed something I hadn't counted on.

When doing an ajax request... I set a "url" parameter with the url of my processing script etc. The url is taken with the "&" symbol and not the html code "&".

I.e.
Code:
url: "' . $module_file . '.php?name=' . $module_name . '&op=Processing_Script",


When shortlinks tries to process this request... it converts the "&" ---> "&" which breaks the request.

Is there a better way to handle the "&" in my request or is this something that will need to be addressed within shortlinks itself?

Note*** This happens WITHOUT shortlinks being applied to the said module.

_________________
Money is the measurement of time - Me
"You can all go to hell…I’m going to Texas" -Davy Crockett 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Tue Mar 22, 2011 2:21 pm Reply with quote

I am a little confused. At first you are calling this a shortlinks problem, but in the same post you say that this happens when you are not using shortlinks for the module.

Anyway you should be using the "data" setting in conjunction with the "url" setting. Look the examples at the bottom of the page: [ Only registered users can see links on this board! Get registered or login! ]

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
killing-hours







PostPosted: Tue Mar 22, 2011 2:38 pm Reply with quote

It is very confusing. Not real sure how to explain it other than this.

I use "$.ajax({});" and my "data" is defaulted to "html" since returning a table.

Here is a sample ajax request:

Code:
var dataString = input2 + "&input1=" + input1;

$.ajax({
               type: "POST",
               url: "' . $module_file . '.php?name=' . $module_name . '&op=Process_Script",
               data: dataString,
               success: function(data){
                  $("#loader").css("visibility", "hidden");
                  $(".data").html(data);
                  $(".data").show();
                  $(".tlink").addClass("colorbox");
                  $(".colorbox").colorbox({opacity:0.65, width:"750", heigth:"400"});
                  }
               });


This is "inline" javascript.

Now... the "url" takes the "&" symbol literally (I guess that's the right way to say that) so when you formulate the path to the script.. it looks for the actual "&" and not the html code equivalent.

When shortlinks is activated on the site within RN... somehow shortlinks (regardless of whether it's applied to the particular module or not) takes the link and parses it?? and replaces the "&" ----> "&" which in turn breaks the url path.

With shortlinks activated:
Code:
url: "' . $module_file . '.php?name=' . $module_name . '&op=Process_Script",


becomes:
Code:
url: "' . $module_file . '.php?name=' . $module_name . '&op=Process_Script",


I can see this happening in firebug even though shortlinks is NOT activated on the module.


I hope this makes more sense. I'm not real sure if shortlinks parses "all" links to see if there is a RewriteRule for it and if not.. passes it along.. but that's what it seems like to me.

If I was to guess at how it's happening... it'd be like this.

Shortlinks is activated:
1. Links is parsed via shortlinks to check for RewriteRule. (believe it's converting the symbol here)
2. If there is no RewriteRule... the link is passed on "normally"
3. If there IS a RewriteRule.... shortlink is applied.

Did I confuse you more?
 
killing-hours







PostPosted: Tue Mar 22, 2011 2:54 pm Reply with quote

This may help explain it more.

With shortlinks OFF:
Image

With shortlinks ON:
Image
 
Palbin







PostPosted: Tue Mar 22, 2011 3:35 pm Reply with quote

This is what I meant.

Code:


var dataString = "name=" + ' . $module_name . ' + "&op=Process_Script&" + input2 + "&input1=" + input1;
$.ajax({
               type: "POST",
               url: "' . $module_file . '.php",
               data: dataString,
               success: function(data){
                  $("#loader").css("visibility", "hidden");
                  $(".data").html(data);
                  $(".data").show();
                  $(".tlink").addClass("colorbox");
                  $(".colorbox").colorbox({opacity:0.65, width:"750", heigth:"400"});
                  }
               });
 
killing-hours







PostPosted: Tue Mar 22, 2011 3:45 pm Reply with quote

Wow... that baffles me (the way it's written)... however, it still presents the same problem. it still replaces "&" with "&".

--
Addressing the coding method... why make the code "seem" so complex when their is a more simplified way to write and understand the code? Just curious.
 
killing-hours







PostPosted: Tue Mar 22, 2011 3:54 pm Reply with quote

I don't have the time to try this at the moment (going home) but here is the link to that simple ajax module I made awhile back. It uses the same url style.
[ Only registered users can see links on this board! Get registered or login! ]

This may give you the same effect I'm seeing in firebug so you can see for yourself what is happening or maybe help me narrow down the root cause of this. Just add that (nvm the database n' all that since we are only looking for the "POST" in firebug). Activate shortlinks on a test site and try to send the ajax request.
 
Palbin







PostPosted: Tue Mar 22, 2011 5:18 pm Reply with quote

killing-hours, I did write this wrong
Code:


var dataString = "name=' . $module_name . '&op=Process_Script&" + input2 + "&input1=" + input1;


I found what is causing the problem. I am still looking into what it is even being done.
 
killing-hours







PostPosted: Tue Mar 22, 2011 6:41 pm Reply with quote

Palbin wrote:
killing-hours, I did write this wrong
Code:


var dataString = "name=' . $module_name . '&op=Process_Script&" + input2 + "&input1=" + input1;


I found what is causing the problem. I am still looking into what it is even being done.


Even so... why would you opt to attach it all to the dataString variable instead of keeping it separate in the "data" , "url" parameters? It works either way... but attaching it all to dataString variable creates a bit more of a headache for someone behind you down the line who may have to unravel your coding to update it in the future or what have ya.

Just seems to me that it would be just as effective to keep the "data" and the "url" separate so that one or the other could easily be updated by someone else who might not know all the in's & out's... but hey... To each their own.

Back on track though... the problem?
Code:
/**

 * Function: tnsl_fCleanLinks
 *
 * In order to find the necessary link patterns, ALL URLs must have a consistent usage
 * of the "&", namely "&".
 *
 * $param string &$getNextGen is passed by reference for speed.  This is for the string
 *                 of HTML coming into the function.
 * @return void the return is the variable passed by reference
 */

function tnsl_fCleanLinks(&$getNextGen) {
   $getNextGen = preg_replace('(&(?!([a-zA-Z]{2,6}|[0-9\#]{1,6})[\;]))', '&', $getNextGen);
   $getNextGen = str_replace(array(
      '&&',
      '·',
      ' ',
      '&#'
   ), array(
      '&&',
      '·',
      ' ',
      '&#'
   ), $getNextGen);
 
Palbin







PostPosted: Tue Mar 22, 2011 7:43 pm Reply with quote

[ Only registered users can see links on this board! Get registered or login! ]
 
killing-hours







PostPosted: Tue Mar 22, 2011 8:11 pm Reply with quote

Thank you sir! Appreciate you entertaining my madness. Maybe this will help something down the road.
 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Fri Mar 25, 2011 9:19 pm Reply with quote

Just curious, since this is inline js, have you tried wrapping it in CDATA
Code:


// <![CDATA[
inline script here
// ]]>
</script>
 
View user's profile Send private message Send e-mail
killing-hours







PostPosted: Sat Mar 26, 2011 7:54 am Reply with quote

Guardian-

No... honestly... didn't know I should have been doing that. I'll give it a shot now.

Edit***

Same result. What happens is that function in shortlinks sanitizes ALL links found within the particular file. Since the link is inline JS in the file... shortlinks doesn't recognize that it's actually going to the head vs. being a "normal" link on the page and runs it through the ringer as well.

I've confirmed all works perfectly if I were to move the links outside the file to a .js file... however, that doesn't help in keeping the links easily modified by the variables.

I.e.
Code:
"'.$module_file.'/'.$module_name.'etc etc etc
 
Guardian2003







PostPosted: Sat Mar 26, 2011 8:33 am Reply with quote

I wish I could help more but I'll openly admit that JS/AJAX is not something I have messed with to any real extent.
From what I can see in the function code, it does what it is supposed to do but just doesn't have an exception for the use you require.
It might be possible as a temporary fix to add an exception;
Code:


function tnsl_fCleanLinks(&$getNextGen) {
// do a pregmatch for 'url' and if true;
exit;

   $getNextGen = preg_replace('(&(?!([a-zA-Z]{2,6}|[0-9\#]{1,6})[\;]))', '&amp;', $getNextGen);
   $getNextGen = str_replace(array( ....
 
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Sat Mar 26, 2011 8:37 am Reply with quote

What about storing the module name as a JS variable, and using that when you build the link, so shortlinks won't see it..?

var modname='Your_Module';

<a href="modules.php?name='+modname+'"></a>

just a thought....
 
View user's profile Send private message Visit poster's website
killing-hours







PostPosted: Sat Mar 26, 2011 9:31 am Reply with quote

Really appreciate both inputs...

Just so we understand... I am really in no push for this... It's just a bug I found when I was testing shortlinks on my site. This isn't something mission critical that I can't work around... just something I think really needs to be addressed at some point.

With that said...

@Guardian

That is how RNYA works... it is matched and excluded... however, that would be a pain in the butt for developers to rely on hard coding their links in to be excluded. I understand it's a "just to get ya by" suggestion though.

@Spastic

The purpose of the inline is to define the "$module_name" variable across the entire module so for w/e reason the module directory changes names... it can be changed in one place only and update the entire module with the correct name. It's no issue to have the link in a separate file JS as shortlinks won't mess with it there. This is only an inline issue. Maybe I'm understanding your suggestion wrong??
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Mon Mar 28, 2011 4:16 pm Reply with quote

Yeah, the more I look at this and what you all are suggesting, the more inclined I am to agree with the MeoToo/Palbin approach. For now, if you wouldn't mind vetting out Palbin's approach here, it would be greatly appreciated.

I think preg_replace_callback() is a better way to go so working that up for testing. However, it accomplishes the same as what was posted... only slightly faster and slightly faster. (I also don't like eval() and that is essentially what the 'e' modifier is doing in the MeoToo/Palbin approach.)

Great ideas though from both!

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
killing-hours







PostPosted: Tue Mar 29, 2011 7:14 am Reply with quote

@Montego

I actually replied in that topic (your site) yesterday about 3 hours prior to you posting here. I can't "extensively" test Palbins solution until this evening on my production site where I can really see what breaks. I've tested how it was handling my inline on my test site and all seemed to work flawlessly... but as I mentioned on your site... I'm not advanced enough to understand Palbins coding and not real sure what other problems it may present.

I'm in no real hurry for this and don't mind helping you test any which way I can.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> ShortLinks/TegoNuke

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©