| Author |
Message |
montego
Site Admin/Owner


Joined: Feb 12, 2005
Posts: 1294
|
Posted:
Mon Mar 28, 2011 5:18 pm |
|
By the way, I am looking even now at my original tnsl_CleanLinks code and I believe it is incorrect! This is what I have in 1.2.2:
| Code: |
function tnsl_fCleanLinks(&$getNextGen) {
$getNextGen = preg_replace('(&(?!([a-zA-Z]{2,6}|[0-9\#]{1,6})[\;]))', '&', $getNextGen);
$getNextGen = str_replace(array(
'&&',
'·',
' ',
'&#'
), array(
'&&',
'·',
' ',
''
), $getNextGen);
return;
}
|
In my opinion, I believe that it should have been the following instead:
| Code: |
function tnsl_fCleanLinks(&$getNextGen) {
$getNextGen = preg_replace('(&(?!([a-zA-Z]{2,6}|[0-9\#]{1,6})[\;]))', '&', $getNextGen);
$getNextGen = str_replace(array(
'&',
'·',
' ',
'&#'
), array(
'&',
'·',
' ',
''
), $getNextGen);
// montego - following code is required to allow the new RNYA AJAX validations to work properly
$getNextGen = preg_replace('/rnxhr.php\?name=Your_Account&file/', 'rnxhr.php\?name=Your_Account&file', $getNextGen );
return;
}
|
I am curious killing-hours, if this also fixes your issue.
However, I am still reviewing Palbin's revised approach upon MeoToo's original code. I see promise in the approach.
Concerns that I have with the removal of "action" and "src" are:
src
Currently this would affect anything that is actually calling a PHP script as a source of an image, such as the captcha. If we don't clean that too, existing taps may screw these links up? We'll have to review all the code for such usage.
action
While not an issue for RavenNuke(tm) as I made sure at the time that all GET action requests had the right "&", but I'm not convinced other modules (of PHP-Nuke which I still support) are as clean. Should be, but what does it hurt to include?
Another consideration that I have to make is that I was seeing other possible uses for ShortLinks more than just shortening links. I have even presented an idea or two in various forums to handle special situations where an overall replacement approach could be handy.
I do get the issues with more JavaScript usage, especially with Ajax becoming more prevalent, but I also am a firm believer that JS code needs to go into a link ref rather than mixed up amongst the html. Also, with proper usage of jQuery or even use of the rich event model, would we really be seeing these issues?
That is just a slight off-the-cuff response meant to spur more thought and discussion and isn't an end-all position on my part. I would first just like to rule out my one bug, but I am still thinking some form of modified CleanLinks is in order... |
_________________ “To err is human, but when the eraser wears out ahead of the pencil, you’re overdoing it.”
-- Josh Jenkins |
|
|
 |
montego
Site Admin/Owner


Joined: Feb 12, 2005
Posts: 1294
|
Posted:
Mon Mar 28, 2011 5:20 pm |
|
Please note that the second code snippet was mangled slightly. I am reposting the "corrected" code with a space in-between the '&' and its counter-part:
| Code: |
function tnsl_fCleanLinks(&$getNextGen) {
$getNextGen = preg_replace('/(&(?!([a-zA-Z]{2,6}|[0-9\#]{1,6})[\;]))/', '&', $getNextGen);
$getNextGen = str_replace(array(
'&',
'·',
' ',
'&#'
), array(
'& amp;',
'& middot;',
'& nbsp;',
'& #'
), $getNextGen);
// montego - following code is required to allow the new RNYA AJAX validations to work properly
$getNextGen = preg_replace('/rnxhr.php\?name=Your_Account&file/', 'rnxhr.php\?name=Your_Account&file', $getNextGen );
return;
}
|
|
_________________ “To err is human, but when the eraser wears out ahead of the pencil, you’re overdoing it.”
-- Josh Jenkins |
|
|
 |
Killing-Hours
Newbie


Joined: Mar 24, 2011
Posts: 10
|
Posted:
Tue Mar 29, 2011 3:42 pm |
|
Gentlemen, please forgive me if my ignorance shines through... I'm still very new (less than a year) to coding and all that it entails.
As I stated in thread over at RN forums... this issue only affects the "INLINE" javascript.
I'm not sure what you mean when you say that the links should be within the "a href" but for w/e reason... doesn't seem to jive with how I generally code my module applications.
Here is a practical example of the method I use and why I use this method.
(I'm trying to bring myself to y'alls level... please give me time & patience)
-----------------------------------------------------
In my approach to coding my modules using jquery/ajax... I use "INLINE" JS to perform the requests for one simple reason... the "URL" parameter can be updated very easily... module wide... from one central location.
Take for instance:
| Code: |
$script = '<script type="text/javascript">
$(document).ready(function() {
$("#submit").click(function() {
var url = "'.$module_file.'.php?name='.$module_name.'&op=Process";
var input = "input="+$("#input").val();
$.ajax({
type: "POST",
url: url,
dataType: "json",
data: input,
success: function(json) {
alert("Return: " +json.input);
},
failure: function() {
alert("FAIL");
}
});
});
});
</script>';
addJSToHead($script,'inline'); |
Now... I could just as easily change the URL parameter to "modules/json/process.php" and achieve the same result with some drawbacks.
1. Now the process script is being accessed directly which leaves the script unprotected... correct?
2. The url's (module wide) would have to individually be updated if the module changed names.
It would however, allow me to work with shortlinks with no issues other than adding more of a burden to the developer to keep up with all the places things would need to be changed.
I'm not sure If I'm handling this all incorrectly because I'm still learning this stuff as I go along, but it seems to me that this is the correct way I should be structuring modules using jquery/ajax. Any other way seems highly illogical and a waste of precious time. Maybe there are other methods I'm unaware of??
--------------------------------
Montego-
After testing the "Corrected" code you posted... it still presents the same problem. The process of cleansing the code alters the url link by replacing the "&" ------> "&" which breaks the URL parameter. |
| |
|
|
 |
spasticdonkey
Newbie


Joined: Sep 05, 2007
Posts: 68
|
Posted:
Tue Mar 29, 2011 6:28 pm |
|
Just curious if something like this would work.. create:
root/path/yourscript.php
| Code: |
<?php
Header("content-type: application/x-javascript");
global $module_file, $module_name;
echo ' $(document).ready(function() {
$("#submit").click(function() {
var url = "'.$module_file.'.php?name='.$module_name.'&op=Process";
var input = "input="+$("#input").val();
$.ajax({
type: "POST",
url: url,
dataType: "json",
data: input,
success: function(json) {
alert("Return: " +json.input);
},
failure: function() {
alert("FAIL");
}
});
});
});
';
?> |
then in your module
addJSToHead('path/yourscript.php', 'file'); |
| |
|
|
 |
Palbin
Newbie


Joined: Nov 26, 2007
Posts: 22
|
Posted:
Tue Mar 29, 2011 6:51 pm |
|
montego, the edit you made to your original file ('&amp;',) does not fix the issues. All that is doing is fixing an & that has been double encoded. In the JavaScript in question here you do not want it encoded it at all.
I agree the "proper" way would be to put it in external files, but there are a lot of people and examples out there that do not do that. So I find it troublesome requiring that people do that. It is especially a concern when you are writing JavaScript dynamically with PHP as Killing-Hours is doing here.
Can you explain more in-depth what you mean by using this for more than just shortening links. With out a greater understanding of what you mean i am of the opinion that if this kind of functionality is desired it would need to be added or activated by the webmaster seeking it. I think this bridge would need to be crossed once this extended functionality/purpose was needed.
I see no problem adding SRC and ACTION back into the expression.
spasticdonkey, that is going to present the same problem as it is still being echoed to the "screen", and will be encoded when tnsl_fCleanLinks() is run on the buffered output.
Killing-Hours, I personally would not write a module using a link like "modules/json/process.php".
Also you code looks fine to me. It is essentially what I would do, but of course you are going to have differences when two different people write something. |
| |
|
|
 |
Killing-Hours
Newbie


Joined: Mar 24, 2011
Posts: 10
|
Posted:
Tue Mar 29, 2011 7:40 pm |
|
Palbin-
I agree 100% with "I personally would not write a module using a link like etc. etc."
From what I've read on the forums, the correct and safe way to pass the url is via the module file. Thank you for confirming for me!
p.s. Yes, we will defiantly have different styles of coding... I can't understand your spanglish most times Thanks again bud. |
| |
|
|
 |
montego
Site Admin/Owner


Joined: Feb 12, 2005
Posts: 1294
|
Posted:
Wed Mar 30, 2011 9:02 am |
|
Wow, where do you guys find the time! Regarding this:
| Palbin wrote: |
Can you explain more in-depth what you mean by using this for more than just shortening links. With out a greater understanding of what you mean i am of the opinion that if this kind of functionality is desired it would need to be added or activated by the webmaster seeking it. I think this bridge would need to be crossed once this extended functionality/purpose was needed.
|
Don't have time to explain and in reality I don't need to as I agree with your statement about "crossing the bridge". I need to re-write this whole thing anyways and already plan on doing so and basing it more off nukeSEO DH - embedding within it (don't ask me to explain as I am no where close to starting that project).
I am really struggling with the fCleanLinks_Stub code as written. The "cleansing" isn't anything like what I would have imagined and it is not even doing what I previously intended that code to do. So, this is going to take me longer to analyze than previously thought. I already started to re-write the relevant shortlinks.php code... |
| |
|
|
 |
Killing-Hours
Newbie


Joined: Mar 24, 2011
Posts: 10
|
Posted:
Wed Mar 30, 2011 10:32 am |
|
| montego wrote: |
Wow, where do you guys find the time!  |
I'm a hermit & I have no friends.  |
| |
|
|
 |
Guardian
Site Admin


Joined: Jul 18, 2005
Posts: 383
|
Posted:
Thu Mar 31, 2011 5:42 am |
|
Personally I would always use the 'file' method when using addJSToHead() for the simple reason that the function uses an array that loads the files in sequence, so by using something like
| Code: |
addJSToHEAD('jquery.php','file');
addJSToHead('/path/to/jquery-pligin.js','file');
addJSToHead('yourjs.js','file'); |
you know your code is going to be loaded at the correct place.
Using the 'inline' method, the code will only get loaded after the 'file' method so if there is already a 'file' loaded using the same vars as your code, you are pretty much screwed.
Obviously this doesn't fix the issue at hand, I'm just throwing in my 2-cents.
I have played with a few AJAX driven data grids that have edit-in-place, pagination and other nice functions but they never seemed to work right (maybe this issue is why) but I can see what you are trying to achieve, and I like it  |
| |
|
|
 |
Killing-Hours
Newbie


Joined: Mar 24, 2011
Posts: 10
|
Posted:
Thu Mar 31, 2011 9:31 am |
|
| Guardian wrote: |
| Using the 'inline' method, the code will only get loaded after the 'file' method so if there is already a 'file' loaded using the same vars as your code, you are pretty much screwed. |
Very good point Guardian... I had written out a nice response... but upon proof reading... I caught what you meant. Guess I could always use variable names that would be more specific and unique to the module itself to avoid that. Thank you for pointing that out to me! |
| |
|
|
 |
Guardian
Site Admin


Joined: Jul 18, 2005
Posts: 383
|
Posted:
Thu Mar 31, 2011 3:15 pm |
|
* I'm off topic - sorry*
Yes, that's always a good idea
I do the same with php variables, literals and most other things just in case and usually just prefix them with an abbreviation of my sites initials plus an abbreviation of the module name, so for my Code Authors Helpdesk module as an example, I would use something like $cahd_somevar or CAHD_LITERAL.
Whatever code a developer writes will always end up working correctly for the developer. Unfortunately we cannot always guess what another script, written by another developer might be doing and there is always the risk of collision.
Even with java script, think what happens when different scripts are running at the same time that use something like an on.window event. |
| |
|
|
 |
montego
Site Admin/Owner


Joined: Feb 12, 2005
Posts: 1294
|
Posted:
Mon May 23, 2011 8:50 am |
|
Version 1.3.0 is out and has the new method of tapping to hopefully limit the link tapping to a more appropriate href, action and src attributes. |
_________________ “To err is human, but when the eraser wears out ahead of the pencil, you’re overdoing it.”
-- Josh Jenkins |
|
|
 |
|
|