bsmither Posted January 10, 2014 Share Posted January 10, 2014 "Brian's code removed my other products as well." In what way? Quote Link to comment Share on other sites More sharing options...
Nik Grey Posted January 10, 2014 Author Share Posted January 10, 2014 The list of categories in the left hand side menu vanished - like this: Quote Link to comment Share on other sites More sharing options...
bsmither Posted January 10, 2014 Share Posted January 10, 2014 It seems the regular expression looking for "Lettering" is way too greedy. Let's try making it ungreedy... Change just this part: '#<li>.*title="Lettering".*</li>#s' to: '#<li>.*title="Lettering".*</li>#sU' Quote Link to comment Share on other sites More sharing options...
Nik Grey Posted January 10, 2014 Author Share Posted January 10, 2014 Brian, I have just noticed something - when I paste this into the Snippet code area: {php} $lettering_tool_branch = array('url' => $GLOBALS['storeURL']."/index.php?_a=letter", 'name' => "Lettering Tool"); $GLOBALS['smarty']->assign('BRANCH', $lettering_tool_branch); $navigation_tree .= $GLOBALS['smarty']->fetch('templates/element.navigation_tree.php'); $navigation_tree = preg_replace('#<li>.*title="Lettering".*</li>#s','',$navigation_tree); $GLOBALS['smarty']->assign('NAVIGATION_TREE', $navigation_tree); {/php} When I save it - clear the cache and go back to check the code I notice it appears as this: {php} $lettering_tool_branch = array('url' => $GLOBALS['storeURL']."/index.php?_a=letter", 'name' => "Lettering Tool"); $GLOBALS['smarty']->assign('BRANCH', $lettering_tool_branch); $navigation_tree .= $GLOBALS['smarty']->fetch('templates/element.navigation_tree.php'); $navigation_tree = preg_replace('#.*title="Lettering".*#s','',$navigation_tree); $GLOBALS['smarty']->assign('NAVIGATION_TREE', $navigation_tree); {/php} The <li> and </li> are missing ? But I added the 'U' regardless and it's now looking like this: Quote Link to comment Share on other sites More sharing options...
bsmither Posted January 10, 2014 Share Posted January 10, 2014 Stupid Sanitation! In the file /classes/sanitize.class.php, line 30, add 'php_code' and a comma to the array: private static $exempt = array('php_code', 'description', .... CubeCart is sending the content through a PHP filter that strips out certain, supposedly dangerous, things. @Al, please add the snippet['php_code'] key to the array of exempt keys in the sanitize class. Quote Link to comment Share on other sites More sharing options...
Nik Grey Posted January 10, 2014 Author Share Posted January 10, 2014 There must have been other characters that I missed as just pasted the original code in again and its much better - that >Lettering menu item that did nothing has gone. So just adding the above 'php_code', worked My Mugs are missing from the menu though..lol. Quote Link to comment Share on other sites More sharing options...
bsmither Posted January 10, 2014 Share Posted January 10, 2014 So! Still need to fine-tune the preg_replace(). Quote Link to comment Share on other sites More sharing options...
Nik Grey Posted January 10, 2014 Author Share Posted January 10, 2014 Let's do it - I'm loving this, learning.. and also it's all here if I need it again Quote Link to comment Share on other sites More sharing options...
bsmither Posted January 11, 2014 Share Posted January 11, 2014 Well, it seems that discovering the regex pattern code to do this properly will take me about a week to learn. So let's try a different approach. We will explode the string at the <li> sequence into an array, look for the array element with Lettering, remove that array element, then implode the array back into a string. {php} $lettering_tool_branch = array('url' => $GLOBALS['storeURL']."/index.php?_a=letter", 'name' => "Lettering Tool"); $GLOBALS['smarty']->assign('BRANCH', $lettering_tool_branch); $navigation_tree .= $GLOBALS['smarty']->fetch('templates/element.navigation_tree.php'); $navigation_tree_array = explode("<li>", $navigation_tree); foreach($navigation_tree_array as $navigation_tree_key => $navigation_tree_val) { if (strpos($navigation_tree_val, 'title="Lettering"') !== false) unset($navigation_tree_array[$navigation_tree_key]); } $navigation_tree = implode("<li>",$navigation_tree_array); //$navigation_tree = preg_replace('#<li>.*title="Lettering".*</li>#sU','',$navigation_tree); $GLOBALS['smarty']->assign('NAVIGATION_TREE', $navigation_tree); {/php} Quote Link to comment Share on other sites More sharing options...
Nik Grey Posted January 11, 2014 Author Share Posted January 11, 2014 Good Lord, it only WORKS ! I want to understand how though, I will re-visit this first thing today. I can add things to the Cart that's what I mean by working as well as the products appearing in the Nav bar most pleased - Thanks Brian. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.