/** * Method to parse Route * * @param array $segments * * @return array */ function CrowdfundingParseRoute($segments) { $total = count($segments); $vars = array(); for ($i = 0; $i < $total; $i++) { $segments[$i] = str_replace('-', ':', $segments[$i]); } //Get the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); // Count route segments $count = count($segments); // Standard routing for articles. If we don't pick up an Itemid then we get the view from the segments // the first segment is the view and the last segment is the id of the details, category or payment. if (null === $item) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } // COUNT == 1 // Category or backing layout. if ($count === 1) { // We check to see if an alias is given. If not, we assume it is a project, // because categories have always alias. // If it is a menu item "Details" that could be one of its specific views - backing, embed,... if (false === strpos($segments[0], ':')) { switch ($segments[0]) { case 'backing': case 'friendmail': case 'embed': $id = $item->query['id']; $project = CrowdfundingHelperRoute::getProject($id); $vars['view'] = $segments[0]; $vars['catid'] = (int) $project['catid']; $vars['id'] = (int) $project['id']; break; default: $vars['view'] = 'details'; $vars['id'] = (int) $segments[0]; break; } return $vars; } $vars = CrowdfundingHelperRoute::prepareCategoryOrDetails($segments); if (0 !== count($vars)) { return $vars; } } // COUNT >= 2 if ($count >= 2) { $view = $segments[$count - 1]; switch ($view) { case 'embed': case 'backing': $itemId = (int) $segments[$count - 2]; // Get catid from menu item if (!empty($item->query['id'])) { $catId = (int) $item->query['id']; } else { $catId = (int) $segments[$count - 3]; } $vars['view'] = $view; $vars['id'] = (int) $itemId; $vars['catid'] = (int) $catId; break; case 'updates': // Screens of details - 'updates', 'comments', 'funders' // Screens of details - 'updates', 'comments', 'funders' case 'comments': case 'funders': $itemId = (int) $segments[$count - 2]; // Get catid from menu item if (!empty($item->query['id'])) { $catId = (int) $item->query['id']; } else { $catId = (int) $segments[$count - 3]; } $vars['view'] = 'details'; $vars['id'] = (int) $itemId; $vars['catid'] = (int) $catId; // Get screen $screen = $segments[$count - 1]; $allowedScreens = array('updates', 'comments', 'funders'); if (in_array($screen, $allowedScreens, true)) { $vars['screen'] = $screen; } break; default: // Subcategory or details page. // if there was more than one segment, then we can determine where the URL points to // because the first segment will have the target category id prepended to it. If the // last segment has a number prepended, it is details, otherwise, it is a category. $vars = CrowdfundingHelperRoute::prepareCategoryOrDetails($segments); break; } } return $vars; }