Created
April 10, 2015 15:55
-
-
Save croxton/b5f4bc733a8565fc537b to your computer and use it in GitHub Desktop.
routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Routes | |
* | |
* Defines rules for routing requests to templates | |
* | |
*/ | |
$env_config['resource_router'] = array( | |
/* --------------------------------------------------------- | |
global | |
--------------------------------------------------------- */ | |
// any url with at least one segment | |
'([a-zA-Z\-_]+).*' => function($router, $segment_1='') { | |
// set the Taxonomy tree id to use for sub-menus | |
$tree_id = 0; | |
switch($segment_1) { | |
case "about-us" : | |
$tree_id = 1; | |
break; | |
case "careers" : | |
$tree_id = 2; | |
break; | |
case "what-we-do" : | |
$tree_id = 3; | |
break; | |
case "contact" : | |
$tree_id = 4; | |
break; | |
case "help" : | |
$tree_id = 5; | |
break; | |
case "finance" : | |
$tree_id = 6; | |
break; | |
} | |
$router->setGlobal('route_1_tree_id', $tree_id); | |
return; // signify this rule does not match a route | |
}, | |
/* --------------------------------------------------------- | |
about-us | |
--------------------------------------------------------- */ | |
/* about page */ | |
'about-us/:url_title' => function($router, $wildcard) { | |
switch($wildcard) { | |
case "awards" : | |
case "client-stories" : | |
case "history" : | |
case "organisations-we-support" : | |
$router->setTemplate('about-us/' . $wildcard->value); | |
break; | |
default : | |
// valid entry in the About channel (4)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 4) { | |
$router->setTemplate('site/_page'); | |
} | |
break; | |
} | |
}, | |
/* client stories */ | |
'about-us/client-stories/:url_title' => function($router, $wildcard) { | |
/* valid entry in the client stories channel (33)? */ | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 33) { | |
$router->setTemplate('site/_page'); | |
} | |
}, | |
/* about: catch any url not matched by rules above */ | |
'about-us/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
our-people | |
--------------------------------------------------------- */ | |
/* people landing */ | |
'our-people/?' => function($router) { | |
$router->redirect('our-people/lawyers'); | |
}, | |
/* people: lawyers (search) */ | |
'our-people/lawyers(.*)?' => function($router) { | |
/* @TODO: validate the search/filter segments? */ | |
$router->setTemplate('our-people/lawyers'); | |
}, | |
/* people: senior management */ | |
'our-people/senior-management' => function($router) { | |
$router->setTemplate('our-people/senior-management'); | |
}, | |
/* people profile */ | |
'our-people/profile/:url_title' => function($router, $wildcard) { | |
/* valid entry in the people channel (2)? */ | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 2) { | |
$router->setTemplate('our-people/profile'); | |
} | |
}, | |
/* people profile: print */ | |
'our-people/profile/:url_title/print' => function($router, $wildcard) { | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 2) { | |
$router->setTemplate('our-people/_profile-print'); | |
} | |
}, | |
/* people profile: vcard */ | |
'our-people/profile/:url_title/vcard' => function($router, $wildcard) { | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 2) { | |
$router->setTemplate('our-people/_profile-vcard'); | |
} | |
}, | |
/* people: catch any url not matched by rules above */ | |
'our-people/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
careers | |
--------------------------------------------------------- */ | |
/* careers page */ | |
'careers/:any' => function($router, $wildcard) { | |
switch($wildcard) { | |
case "vacancies" : | |
$router->setTemplate('careers/vacancies'); | |
break; | |
default : | |
// valid entry in the Careers channel (6)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 6) { | |
$router->setTemplate('site/_page'); | |
} | |
break; | |
} | |
}, | |
/* vacancies */ | |
'careers/vacancies/:url_title' => function($router, $wildcard) { | |
/* valid entry in the jobs channel (23)? */ | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 23) { | |
$router->setTemplate('careers/_vacancy'); | |
} | |
}, | |
/* careers: any url not matched by rules above */ | |
'careers/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
events | |
--------------------------------------------------------- */ | |
/* events (chronological events for single day) */ | |
'events/\d{4}/\d{2}/\d{2}' => function($router) { | |
$router->setTemplate('events/_day'); | |
}, | |
/* events (chronological events for next 3 months) */ | |
'events/\d{4}/\d{2}' => function($router) { | |
$router->setTemplate('events'); | |
}, | |
/* event detail */ | |
'events/:url_title' => function($router, $wildcard) { | |
// valid entry in the Calendar Events channel (29)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 29) { | |
$router->setTemplate('events/_event'); | |
} | |
}, | |
/* event detail: export */ | |
'events/:url_title/export' => function($router) { | |
$router->setTemplate('events/_event-export'); | |
}, | |
/* event detail: print */ | |
'events/:url_title/print' => function($router) { | |
$router->setTemplate('events/_event-print'); | |
}, | |
/* events: catch any url not matched by rules above */ | |
'events/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
contact | |
--------------------------------------------------------- */ | |
'contact/:any' => function($router, $wildcard) { | |
switch($wildcard) { | |
case "emergency" : | |
case "enquiry" : | |
case "press" : | |
$router->setTemplate('contact/' . $wildcard->value); | |
break; | |
default : | |
// valid entry in the Offices channel (30)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 30) { | |
$router->setTemplate('contact'); | |
} | |
break; | |
} | |
}, | |
/* contact: catch any url not matched by rules above */ | |
'contact/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
finance | |
--------------------------------------------------------- */ | |
'finance/:any' => function($router, $wildcard) { | |
switch($wildcard) { | |
case "pay" : | |
$router->setTemplate('finance/pay'); | |
break; | |
default : | |
// valid entry in the Finance channel (17)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 17) { | |
$router->setTemplate('site/_page'); | |
} | |
break; | |
} | |
}, | |
/* finance: catch any url not matched by rules above */ | |
'finance/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
help | |
--------------------------------------------------------- */ | |
'help/:any' => function($router, $wildcard) { | |
// valid entry in the Help channel (18)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 18) { | |
$router->setTemplate('site/_page'); | |
} | |
}, | |
/* help: catch any url not matched by rules above */ | |
'help/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
insight | |
--------------------------------------------------------- */ | |
/* insight: blog post (single article) */ | |
'insight/blog/(:url_title)' => function($router, $wildcard) { | |
// valid entry in the Blog channel (9)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 9) { | |
$router->setTemplate('insight/_article'); | |
} | |
}, | |
/* insight: podcast (single) */ | |
'insight/podcasts/(:url_title)' => function($router, $wildcard) { | |
// valid entry in the Podcasts channel (10)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 10) { | |
$router->setTemplate('insight/_podcast'); | |
} | |
}, | |
/* insight: update/publication (single article) */ | |
'insight/updates/(:url_title)' => function($router, $wildcard) { | |
// valid entry in the Updates channel (26)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 26) { | |
$router->setTemplate('insight/_article'); | |
} | |
}, | |
/* insight: video (single) */ | |
'insight/videos/(:url_title)' => function($router, $wildcard) { | |
// valid entry in the Video channel (11)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 11) { | |
$router->setTemplate('insight/_video'); | |
} | |
}, | |
/* insight: search results */ | |
'insight/search/(.*)?' => function($router) { | |
$router->setTemplate('insight/search'); | |
}, | |
/* insight: article listing templates */ | |
'insight/(blog|podcasts|updates|videos)' => function($router, $wildcard) { | |
$router->setTemplate('insight/' . $wildcard->value); | |
}, | |
/* insight: register */ | |
'insight/register' => function($router) { | |
$router->setTemplate('insight/register'); | |
}, | |
/* insight: catch any url not matched by rules above */ | |
'insight/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
news | |
--------------------------------------------------------- */ | |
/* news: story (single) */ | |
'news/(:url_title)' => function($router, $wildcard) { | |
// valid entry in the News channel (7)? | |
if ($wildcard->isValidUrlTitle() && $wildcard->getMeta('channel_id') == 7) { | |
$router->setTemplate('news/_story'); | |
} | |
}, | |
/* news: catch any url not matched by rules above */ | |
'news/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
/* --------------------------------------------------------- | |
what-we-do | |
--------------------------------------------------------- */ | |
/* what-we-do */ | |
'what-we-do/(:url_title)/?(experience|team|what-they-say)?' => function($router, $service, $tab="") { | |
// valid entry in the Services channel (1)? | |
if ($service->isValidUrlTitle() && $service->getMeta('channel_id') == 1) { | |
$router->setTemplate('what-we-do/_service'); | |
} | |
}, | |
/* what-we-do: catch any url not matched by rules above */ | |
'what-we-do/(.*)' => function($router) { | |
$router->set404(); | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment