I’m working on the new inline Ajaxified comments thing in the next WPGet release (where you click the comments link, and theoretically a little box will pop up and show you the latest comments on that post). I have a question to ask as to how best achieve a solution to a problem I’m facing. If you don’t want to delve into the technical reasons behind this, skip a couple of paragraphs and rejoin. I really do need the users input here as to what the best way of fixing it is, so please please please tell me what I should do.
I’ve run into an interesting problem. In order to do this cool Ajax stuff, I need to pass some special information in the URL so that WPGet springs into action and delivers the Ajax content you requested (pulling out comments out for each and every post would be far too database intensive).
However, WPGet is included by another page, which means that the user doesn’t access the wpget.php file directly, all of that is be handled by the master script. That makes it a pain to get that special information passed in the URL, as I can’t control the master script invoking WPGet and change how it works.
Basically, if I cut the technical drivel, which of these solutions to this problem is better?
- At install time, you have to paste two bits of PHP into your file – one snippet of code at the top to handle Ajax stuff (this is the new bit) and one where you want the posts to appear as normal. This would only affect people wanting the Ajax functionality.
- Only one snippet to copy and paste, but we ask the users at install time which directory wpget.php will be located relative to the script calling it (index.php for example). In most cases, it’s the current directory (index.php and wpget.php in the same folder), so novices will leave it at that and there’s no problem. For people wanting to put it in /includes or whatever, they would have to remember to state this during the setup process.
Technical talk – in this solution, when Ajaxing, we’d request the wpget.php script directly in the URL, along with our arguments, so therefore we need to know where it is relative to $_SERVER[‘PHP_SELF’]
Now, there’s clearly arguments for and against both and I don’t want to complicate the installation process too much. These measures probably won’t affect users not wanting the Ajax comments functionality, but I really want to keep installation simple.
I am relying on you to tell me which solution is best, as I’m not really sure. Particularly Lee, as you suggested this feature, what do you think is best?
Alternatively, I’m if (likely) being incredibly stupid, someone please tell me how to get the current file’s web-accessible filename from within PHP (not the filename of the file that calls wpget.php, but the wpget.php file itself).
I think you should do the second option. The more down and dirty code insertion you make people do, the more likely they are to mess it up (I’m obviously talking from personal experience!)
Sounds like a cool feature!
I agree with Huw, and would say the second option would be best, and in regard to novices installing and needing to know what to put in the path box, here is something (probably needs a but of modifying, and I think is only php5 compatible):
Maybe you could do something along the lines of that so that novices could choose an option to “search” (well, not really search) for wpget, and that returns the directories it has found it in as an array, although only goes one directory deep. It needs a bit of cleaning up, and may be totally the wrong idea, if so, please ignore my babbling. Although you may be able to use it along with $_SERVER[‘DOCUMENT_ROOT’]; to locate the file.
Sorry for suggesting this idea if it’s a bit of a pain to do 🙂
Lee 😀
Just a note: Theres meant to be php code above, note sure how WP handles it, if it for some reason doesn’t show up and you want it just send me an email.
OK, thanks.
Decision made. 🙂
No, it’s not a pain to do – it’s just a case of picking a solution and implementing it and I couldn’t immediately choose which one to do.
For completeness, here’s what I’ll do. If you’re planning to put wpget.php in a different folder to the current one, you’ll be asked to specify this folder (relative to the web-accessible root) at install time. This means that the Ajax features will run directly off the wpget.php script. wpget.php will be required to be web-accessible (not locked down and only include’able by PHP) as the browser calls it directly.
Thanks for the code Lee. I’ll take a look at it when I’m looking at the config tool (it’s the last thing I do, because up until then things change). I’m sure I’ll find some solution.
Very cool, this is so awsome1!!!!