Here is my new code that generates the entire thing. Has 2 constants at begining to setup the style info. Fixed it so menu will roll over images and long menus can still be selected. Did not figure out how to make long menus shorter and 2 or 3 wide though.
Code:
<?php
define('ITEM_WIDTH',122); //Max width needed for items to show properly
define('CAT_COUNT',6); //Number of main categories
?>
<!-- Magic begin-->
<style type="text/css">
#menu
{
z-index: 1000;
}
#menu, #menu ul
{
font-family : Arial,Helvetica,sans-serif;
font-size : 12px;
position : absolute;
padding : 0; /* no internal margin */
margin : 0; /* no external margin */
list-style-type : none; /* delete any list style */
list-style-image : none;
line-height : 20px;
text-align : left;
}
#menu li
{
padding : 0; /* no internal margin */
margin : 0; /* no external margin */
float : left;
}
#menu li a /* link in menu title */
{
font-weight : bold;
display : block;
padding : 10;
background : #015BBB;
text-decoration : none;
width : <? echo ceil((620-ITEM_WIDTH)/CAT_COUNT); ?>px;
color : #AACCCC;
border-left : 1px solid #015BBB; /*no border but need to avoid a shift when actual border appears */
}
#menu li a:hover /* if mouse over menu title */
{
color : #FFFFFF;
border-left : 1px solid #FFFFFF;
}
#menu li ul /* block of menu items */
{
display: none;
list-style-type : none; /* delete any list style */
list-style-image : none;
background : #FFFFFF;
color : #6699CC;
width: <? echo ITEM_WIDTH; ?>px;
padding : 0; /* no internal margin */
margin : 0; /* no external margin */
border-left : 1px solid #015BBB;
border-right : 1px solid #015BBB;
border-bottom : 1px solid #015BBB;
}
#menu li.over ul /* block of menu items */
{
display: block;
list-style-type : none; /* delete any list style */
list-style-image : none
background : #FFFFFF;
color : #6699CC;
width: <? echo ITEM_WIDTH; ?>px;
padding : 0; /* no internal margin */
margin : 0; /* no external margin */
border-left : 1px solid #015BBB;
border-right : 1px solid #015BBB;
border-bottom : 1px solid #015BBB;
}
#menu li ul li
{
border-top : 1px solid #F0F1F5; /* separation between items*/
}
#menu li ul li a /* link in menu item */
{
font-weight : normal;
display : block;
padding-left : 2;
padding-top : 2;
padding-bottom : 2;
padding-right : 2;
text-decoration : none;
text-align : left;
width : <? echo (ITEM_WIDTH-2); ?>px;/* 162-1 -1 (?) */
color : #6699CC;
background : #FFFFFF;
border-left : 1px solid #FFFFFF; /*no border but need to avoid a shift when actual border appears */
}
#menu li ul li a:hover /* if mouse over menu item */
{
background : #E1F2FA;
color : #6699CC;
border-left : 1px solid #E1F2FA; /*no border but need to avoid a shift when actual border appears */
}
#menu #lastmenu a
{
width : <? echo (ITEM_WIDTH-2); ?>px ;
}
</style>
<script type="text/javascript">
function InitMenu(id)
{
var ParentNode = document.getElementById(id);
var ChildNodesArray = ParentNode.childNodes;
if (ChildNodesArray == null) return;
for (var i = 0; i < ChildNodesArray.length; i++)
{
var ChildNode = ChildNodesArray[i];
if (ChildNode.nodeName.toLowerCase() == "li")
{
ChildNode.onmouseover = function()
{
this.className+=" over";
}
ChildNode.onmouseout = function()
{
this.className=this.className.replace(" over", "");
}
}
}
changeStyle();
}
onload=function()
{InitMenu('menu');}
</script>
<?php
function getBracket($str) {
$start=strpos($str,'[')+1;
$end=strpos($str,']',$start);
return substr($str,$start,$end-$start);
}
//download shop page
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 's2s');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://www.shapeways.com/shops/propmodule');
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$web_data = trim(curl_exec($ch));
curl_close($ch);
$start=strpos($web_data,'<h2>shop sections</h2>');
$start=strpos($web_data,'all models',$start);
//shop sections to look for
$shopsec=array(
'Solid Dice'=>0,
'Hollow Dice'=>0,
'Frame'=>0,
'Metal Dice'=>0,
'Non Dice'=>0,
'Customizable'=>0,
'Dice Set[Prime]'=>0,
'Dice Set[Grid]'=>0,
'Dice Set[Crystal]'=>0,
'Dice Set[Dual]'=>0,
'Dice Set[Frameless]'=>0,
'Dice Set[Points]'=>0,
'Specialty[Lottery]'=>0,
'Specialty[Shell]'=>0,
'Specialty[Loaded]'=>0,
'Specialty[Data]'=>0,
'Specialty[Math]'=>0,
'Specialty[Obfuscation]'=>0,
'Specialty[Ring]'=>0,
'Specialty[4D]'=>0,
'Specialty[Time]'=>0,
);
for ($i=0;$i<1000;$i++) {
$shopsec['Sides['.substr('000' . $i,-3).']']=0;
}
//get quantity of each shop section
foreach ($shopsec as $sec=>&$count) {
$a=strpos($web_data,$sec,$start);
$a=strpos($web_data,'(',$a)+1;
$b=strpos($web_data,')',$a);
$count=substr($web_data,$a,$b-$a);
}
echo '<ul id="menu" >';
//Sides
echo '<li><a href="/shops/propmodule?section=Sides">Sides</a>'."\n";
echo '<ul>'."\n";
foreach ($shopsec as $key=>$count) {
if ((substr($key,0,5)=='Sides') && ($count>0)) {
echo '<li ><a href="/shops/propmodule?section=' . $key . '">' . getBracket($key) . ' (' . $count . ')</a></li>'."\n";
}
}
echo '</ul>'."\n";
echo '</li>'."\n";
//Build Type
echo '<li><a href="/shops/propmodule?section=Build Type">Build Type</a>'."\n";
echo '<ul>'."\n";
/*
foreach ($shopsec as $key=>$count) {
if ((substr($key,0,10)=='Build Type') && ($count>0)) {
echo '<li ><a href="/shops//propmodule?section=' . $key . '">' . getBracket($key) . ' (' . $count . ')</a></li>'."\n";
}
}
*/
echo '<li ><a href="/shops/propmodule?section=Solid Dice">Solid Dice (' . $shopsec['Solid Dice'] . ')</a></li>'."\n";
echo '<li ><a href="/shops/propmodule?section=Hollow Dice">Hollow Dice (' . $shopsec['Hollow Dice'] . ')</a></li>'."\n";
echo '<li ><a href="/shops/propmodule?section=Frame">Frame (' . $shopsec['Frame'] . ')</a></li>'."\n";
echo '</ul>'."\n";
echo '</li>'."\n";
//Dice Sets
echo '<li><a href="/shops/propmodule?section=Specialty">Dice Set</a>'."\n";
echo '<ul>'."\n";
foreach ($shopsec as $key=>$count) {
if ((substr($key,0,8)=='Dice Set') && ($count>0)) {
echo '<li ><a href="/shops/propmodule?section=' . $key . '">' . getBracket($key) . ' (' . $count . ')</a></li>'."\n";
}
}
echo '</ul>'."\n";
echo '</li>'."\n";
//Specialty Dice
echo '<li><a href="/shops/propmodule?section=Specialty">Specialty</a>'."\n";
echo '<ul>'."\n";
foreach ($shopsec as $key=>$count) {
if ((substr($key,0,9)=='Specialty') && ($count>0)) {
echo '<li ><a href="/shops/propmodule?section=' . $key . '">' . getBracket($key) . ' (' . $count . ')</a></li>'."\n";
}
}
echo '</ul>'."\n";
echo '</li>'."\n";
//Meterial
echo '<li><a href="/shops/propmodule?section=Specialty">Material</a>'."\n";
echo '<ul>'."\n";
/*
foreach ($shopsec as $key=>$count) {
if ((substr($key,0,8)=='Material') && ($count>0)) {
echo '<li ><a href="/shops/propmodule?section=' . $key . '">' . getBracket($key) . ' (' . $count . ')</a></li>'."\n";
}
}
*/
echo '<li ><a href="/shops/propmodule?section=Metal+Dice">Metal Dice (' . $shopsec['Metal Dice'] . ')</a></li>'."\n";
echo '</ul>'."\n";
echo '</li>'."\n";
//Other
echo '<li><a href="/shops/propmodule?section=Non Dice">Non Dice (' . $shopsec['Non Dice'] . ')</a></li>'."\n";
echo '<li id="lastmenu"><a href="/shops/propmodule?section=Customizable">Customizable (' . $shopsec['Customizable'] . ')</a></li>'."\n";
echo '</ul>'."\n";
?>