How and where do I use a Smarty Output filter in X-Cart?
I'm building a URL-rewriter for my cart to make it search-engine-friendly. I'm making an outputfilter/plug-in to take care of the actual URL re-writing so I don't have to modify anything other than the templates (hopefully) and then add a small bit of PHP code to all the PHP pages to accept get variables in the format:
name/value/name/value/name/value rather than name=value&name=value&name=value Is there anything anyone can tell me about using Smarty Output Filters? Do I just need to register the output filter once in one of my main templates or do I need to include it just before and explicit Code:
$smarty->display(); |
Hi minorgod,
I hope you'll share your rewriter with the forum when you're done! ATKOgirl |
Minorgod, I'd be interested in the steps you took for such, as I'm intersted the methods taken instead of using apache's mod_rewrite.
Good luck to you! 8) |
preliminary test results
So far I've managed to build a url rewriter plug-in that finds any urls in the pending Smarty output and fills them with a test URL in the format http://someurl. I've run into a snag doing a sub-expression match/string replacement to replace all the special url parameter delimiters with slashes. I'm a regex newbie and this is damn complicated! Any regex gurus out there that can lend a hand fixing this regex? Here's an example of the test code that isn't working right...
Code:
<?php //preg_test Hope someone knows what I'm doing wrong here, cuz I don't! I'll be working on this over the weekend so please post if you know the answer. I'll release a small tutorial once I get everything working right (assuming it doesn't require hand-coding on many php pages in which case I may not write a tutorial). |
Good for testing out regexpr, helped me out on alot of regular expressions in perl:
http://www.savarese.org/oro/demos/OROMatcherDemo.html |
I FOUND it!
After over 8 hours of testing various combinations of regular expression syntax, I have managed to get the following to work for changing the URL parameter syntax in a link to use slashes instead of standard URL parameter syntax.....
Code:
$source = preg_replace("/(a href=)(\")([^?]+)([^\"]+)(\")/e", "'$1$3'.str_replace(array('&','?','+','='),'/','$4')", "$source"); Hope this saves someone 8 hours. It turns out that the main stumbling block was the use of the /e flag at the end of the preg pattern. Without that little "e" after the pattern, PHP wouldn't execute the substring search on the 4th substring that contained the parameters needing slash replacement. Now it does. Now on with the search-engine friendly cart mod! |
disregard that last post
That last post was on the right track, but the final version required much more work. All the bugs still aren't worked out. The module now rewrites all the links on the page using slashes as separators, but now when the page loads, it immediately does a full store search and lists all the items in my store. Not sure why this is happening except that I suspect the search form is being activated by some variable being set when Smarty renders the page the first time, before the output filter has a chance to rewrite the links. Not sure if this is the problem yet. Can anyone think of a reason my customer/home.php would instantly reload with a full store search?
|
Eureka!
Okay, below is a new Smarty Output Filter I wrote to rewrite all the links on a page to be search-engine friendly. HOWEVER, you cannot simply drop this in your Smarty Plug-ins folder and be done. If you rewrite all your page links using this plug-in, then you'll still need to alter your application logic to handle GET varables differently, so you can parse them from the PATH_INFO rather than from the _GET or HTTP_GET_VARS array. Here is the code to make your own Smarty Plug-in....
Code:
<?php Please note, this code is not optimized. A couple of steps here could easily be reduced into a single step, but I needed the extra steps for easier debugging. If you modify this or discover bugs, please post them here. If you need to see the code that is being generated without rendering it in your browser, simply change the last line of this output filter to Code:
return htmlspecialchars($source); Below is a sample PHP script that you might use to grab the variable names and values from the URL on pages where you use this output filter, or target pages you might navigate to from a page using this output filter: Code:
<?php Love me. |
Excellent work :)
|
X-Cart: Static Catalog
Actually, the next version of X-Cart will have a "Static Catalog" feature built-in, which will make it more search engine-friendly.
The cart will be able to generate a HTML version of the catalog automatically. All "dynamic" buttons like "Add to cart", "View cart", "Login", etc. will be linked to the standard X-Cart PHP pages. |
All times are GMT -8. The time now is 07:03 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.