Page 1 of 1

[HACK] Friendly "Wish-List" URLs

Posted: Thu Sep 17, 2009 3:59 pm
by CharlieFoxtrot
As of ISC 4.07, the wishlist URLs are exceedingly complex... and in my opinion, it's a bit of an overkill as far as 'uniqueness' is concerned.

PROBLEM: Here's what the wishlist URL looks like now:
https://www.yourdomain.com/wishlist.php ... ddfb88102f :(

The wishlist token (everything that appears after the "=" sign) is created by using the PHP command "uniqid()" and then converting it into a longer hash using the "md5()" command.

SIMPLE GOAL: Create something that's shorter, friendlier, easier to read, and still unique. Something like this:
https://www.yourdomain.com/wishlist.php ... sList25869 :)

ADVANCED GOAL: This could be improved a bit more by shortening "publicwishlist=" to "show="... which would look like:
https://www.yourdomain.com/wishlist.php ... sList25869 :D

Here's what I did:

NOTE: These instructions assume that you're modifying ISC 4.07 (but may still work with other versions). Backup your files before making any changes. Test your edits before putting them on a live site.

===========================
PART ONE:
============================

Load the following file into your editor: /includes/classes/class.wishlist.php

FIND: (near line 150)

Code: Select all

$wishlisttoken = md5(uniqid());
REPLACE WITH:

Code: Select all

// CF: Friendly wishlist tokens hack
// $wishlisttoken = md5(uniqid());

// Get first 10 alpha-numeric characters of the wishlist name
$wishStart = substr(ereg_replace("[^A-Za-z0-9]", "", $wishlistname ), 0, 10); 

// Create a less complex unique-ID, and use only digits
$wishEnd = ereg_replace("[^0-9]", "", uniqid()); 

// Get the last 5 digits of the new unique-ID
$wishEnd = substr($wishEnd,-5); 

// Join the two and create a friendlier (and still unique) wishlist token
$wishlisttoken = $wishStart.$wishEnd; 
============================
PART TWO: (Optional)
============================

The edits you made in Part-One will work fine with no further modifications. But if you'd also like to shorten the argument that appears in the URL, here's what to do next.

Continue working with: /includes/classes/class.wishlist.php

FIND (near line 465)

Code: Select all

$GLOBALS['PublicWishListUrl'] = GetConfig('ShopPath').'/wishlist.php?publicwishlist='.$wishlist['wishlisttoken'];
REPLACE WITH:

Code: Select all

//$GLOBALS['PublicWishListUrl'] = GetConfig('ShopPath').'/wishlist.php?publicwishlist='.$wishlist['wishlisttoken'];
$GLOBALS['PublicWishListUrl'] = GetConfig('ShopPath').'/wishlist.php?show='.$wishlist['wishlisttoken'];
In the above steps, you just shortened "publicwishlist" to "show". ~~ However... in this file, the argument "publicwishlist" appears seven times in the following variations:

Code: Select all

$_POST['publicwishlist'] 
$_REQUEST['publicwishlist']
$_GET['publicwishlist']
Therefore, you'll need to change them to 'show' as well. The easiest thing to do is to use your editor's search feature and manually find/replace each one with the appropriate "$_POST", "$_REQUEST" or "$_GET".

Code: Select all

$_POST['show'] 
$_REQUEST['show']
$_GET['show']
Save and test your changes.


CONCLUSION: This has been tested and works with ISC 4.07, it may or may not work with other versions, but it could be used as a roadmap for making similar edits in other versions.

The edits in Part-One will only affect newly created wishlist tokens. Any wishlist tokens that were created before your edits will remain unchanged, and they will continue to work. If the customer has published the url that leads to their wishlist, it will also continue to work

The edits in Part-Two are global, any will work fine with existing wishlist tokens (even if they have the old unfriendly token names).

ONE BIG EXCEPTION: As written, if a customer has previously shared or published their wishlist that used the original argument ("publicwishlist=") then the edits in Part-Two will make previously shared wishlist URL's unusable.

If you wanted to spend some more time with it, then this could be fixed by making seven edits throughout class.wishlist.php (similar to the example below)

Code: Select all

if ( isset($_GET['show'])||isset($_GET['publicwishlist'])) { 
[... rest of code ...]
Good luck! Enjoy!

Charlie

PS: Post any comments or CORRECTIONS or IMPROVEMENTS :)