How to handle a variable URL?

Joined: 01/20/2009
User offline. Last seen 1 year 33 weeks ago.

Problem:

I have links within my content with URLs such as:

/bible/book/john/3/16
/bible/book/genesis/1/2/3/4
etc

No actual nodes exist for any of these URLs, so what I need is a "catch all" mechanism that handles a path with the following regular expression:

/bible/book/(w+)/(d+)?/(d+)?/(d+)?/(d+)?

The process would then load the appropriate bible content based on the parameters in the URL.

Does any module exist that can do this, or what would I have to do to make it work?

Thanks,

Steve

Joined: 01/20/2009
User offline. Last seen 1 year 33 weeks ago.
Answered my own question...

After a bit of Googling and other research, I've figured it out :)

function the_bible_menu() {
  $items = array();
  $path = 'bible/book';

  $items["$path/%/%/%/%/%"] = $items["$path/%/%/%/%"] = $items["$path/%/%/%"] = $items["$path/%/%"] = $items["$path/%"] = $items[$path] = array(
    'title' => 'Bible',
    'page callback' => 'the_bible_page',
    'page arguments' => array(2, 3, 4, 5, 6),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );

  return $items;
}

function the_bible_page($book, $ch1, $vs1, $ch2, $vs2) {
  $out = "book=$book; chapter1=$ch1; verse1=$vs1; chapter2=$ch2; verse2=$vs2";

  return $out;
}