Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:07

dynamically generate site-index from menu_data.js ?

Poster: vtb
Dated: Thursday October 2 2003 - 16:51:57 BST

Sitting here thinking how to get search engines to index the site without me having to manually maintain two things instead of one every time a page is added/changed...

Has anyone out there written a script (e.g., in PHP) that parses a menu_data.js file and generates at least a crude site index for Google (et al) to spider?

If nobody can come up with one, I will roll my own and then share it with the community. Version 0.01 will have to be rudimentary, meant more for spider than human consumption.

Poster: John
Dated: Thursday October 2 2003 - 17:59:01 BST

Not that I'm aware of. Go for it - roll-away. We gladly accept help and 'goodies' from everybody.

Meanwhile, Andy is coming out with a link checker that will include the menu structure. I'm wondering if he could easily add some kind of formatted output that would serve the purpose.


Meanwhile please post your request in the suggestions area.

Poster: vtb
Dated: Thursday October 2 2003 - 19:09:50 BST

Geez, me and my big mouth, I'm just realizing how much work this could be. One minute into it, I'm thinking, ok, we have to ignore comments. So don't process lines beginning with zero or more whitespaces followed by //. OK, what about the multi-line comment syntax? If you encounter /* turn on a flag the means you're in a comment and keep ignoring till you see */ ... and when you do, reset the flag to false. OK, what if someone has a literal '/*' embedded in there for some reason...? And so on. But I'm gonna give it a shot. 8O

Poster: Andy
Dated: Thursday October 2 2003 - 19:17:15 BST

It's on the ToDo list.

What we are really looking for is a PHP Class that will built arrays from menu_data files. That way we can re-use the code for pretty much anything.

Oh and the really great thing is that we can gather data from other people sites using this PHP class so we can have links all over the place :D

And yes, it is a bit of a nightmare.


Poster: Maz
Dated: Thursday October 2 2003 - 20:36:01 BST

I learn by default, usually by falling down holes, so I don't know what I'm talking about.

This notion came to me, to fullfill 3 in one, id=tabindex(url)
thereby creating accessible urls, grabbing the urls and putting them into php.

I have no idea how it works ;)


Poster: Maz
Dated: Friday October 3 2003 - 17:06:35 BST

I would like to know if its even possible to use accesskey or tabindex in javascript, because so far the screenreader can't access submenus?

If it is I'm sure there will be other ways of utilizing them.


rough first draft link generator. (don't laugh)

Poster: vtb
Dated: Friday October 3 2003 - 22:26:17 BST

Hey Andy,

This seems to work with my menu_data.js. However, it really hasn't been tested with any kind of rigor. It certainly hasn't been subjected to real XP style unit testing or anything like that. It's sure to break if it encounters anything odd.

Also, it only parses out bare urls and has no clue what the parent menu is or anything, so you don't get pretty, organized formatting. I'd like to work on that. I guess this is just to show I'm serious about trying to help.

Also, it isn't OO, as you can see. Hopefully some of this might be worth stealing for use in a method. Were you thinking of building a big multidimensional array with the menu names as keys and items/arrays as values? Then I guess you could walk through it recursively, outputting a header tag for each menu -- a sort of vertical, linear representation of the menu structure.

PS the phpbb syntax highlighter doesn't seem to do to well on this, does it.



$PATTERN   = "/[^\/]\s*aI\(\s*\"(.+)\"\s*\)/U";
$filename    = "js/menu_data.js";

$base = '/dev/pub/index.php?page=';      // this only applies to me
$items = 0;                        // running total of menu items
$links = 0;                      // running total of links to output
$is_multiline_comment = false;         // flag that tells us if it's a comment
$lnum = 0;                        // for debugging
$handle = __at__ fopen($filename,'r') or die("Could not open $filename<br />\n");
while (!feof ($handle)) {
    $line = fgets($handle, 1024);
    // ignore comments ///////////////////////////////////////////////////
    // is the line commented out with '//'?
    if (preg_match("/^\s*\/\//",$line)) {    continue; }
    // are we in a comment opened with '/*' ?
    if (strpos($line,'/*') !== false) { //echo "found opening __at__ OFFSET ", strpos($line,'/*'), " line $lnum\n";
       $is_multiline_comment = true;
       // do we close the comment on the same line?
      if ( strpos($line,'*/',strpos($line,'/*'))!==false ) { //echo "comment closed on same line at line $lnum\n";
         $is_multiline_comment = false;
    // is there a closing '*/' from a comment opened on a previous line?
    if ( $is_multiline_comment && strpos($line,'*/') !== false) {    $is_multiline_comment = false; }
    if ($is_multiline_comment) { continue; }
    //////////////// parse arguments to aI() method calls ////////////////
    $matches = array();
    if  (preg_match_all($PATTERN, $line, $matches )) {
      $items += count($matches[1]);
       foreach($matches[1] as $it) {
          $it = html_entity_decode($it);
          $pairs = explode(";",$it);
          $link = array();
          foreach($pairs as $pair) {
             list($key,$val) = explode("=",$pair);
             $link[$key] = $val;
          if (isset($link['url'])) {
             // this preg_replace() is just for me
             $link['url'] = preg_replace("/\"\s*\+\s*base\s*\+\s*\"/",$base,$link['url']);
             if (! isset($link['text'])) {
                $link['text'] = isset($link['imagealt']) ? $link['imagealt'] : $link['url']; }
             printf('<a href="%s">%s</a><br />', $link['url'],$link['text']);
             echo "\n";
fclose ($handle);
echo "$items calls to aI(), $links links generated.";

Poster: Andy
Dated: Friday October 3 2003 - 22:40:49 BST

Excellent stuff :D

Although I can't test it right now as our dev server is down thanks to a hacker gaining root access and executing rm -rf /usr /bin /etc. . . etc. You get the idea :evil:

Although it was kinda provoked by me he should never have been in our dev server in the first place :?

Anyway, OO is the way we want to go with this. This means that we can use the same code for site map, link checker and all the other great stuff soon to be developed.

What i'm looking at doing, once I get the time, is generating a document that everybody can agree on. This will be the template or bible that we work to, to get the PHP classes as efficient as possible. Also something that will port to ASP and Cold Fusion would be nice too but I might be asking too much there ;)

I'll take a look at it once our server is back up.


Poster: vtb
Dated: Friday October 3 2003 - 23:07:12 BST

... OO is the way we want to go with this.

I love OO too so I definitely agree with that. Anyway, I'd be happy (not to mention honored) to contribute if I can. In my abundant spare time :} You can contact dmintz __at__ any time.

Poster: John
Dated: Saturday October 4 2003 - 0:54:40 BST

As Andy mentioned, he's up to his eyeballs (as usual) trying to get the dev server back up, not to mention getting v5 to final. We are happy to have anybody and everybody here help as they are able, from a simple "Yes, you can do that" answer, to the kind of code you have written.

I'm not speaking for him, but I think I can safely say if you continue with what you're doing and in the direction he needs, he would be most happy to seriously consider what you have done.

Your support is most appreciated.