/** * 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] = preg_replace('/-/', ':', $segments[$i], 1); } //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 (!isset($item)) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } // COUNT == 1 // Category 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 "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; } list($id, $alias) = explode(':', $segments[0], 2); $alias = str_replace(":", "-", $alias); // first we check if it is a category $category = JCategories::getInstance('Crowdfunding')->get($id); if ($category and strcmp($category->alias, $alias) == 0) { $vars['view'] = 'category'; $vars['id'] = $id; return $vars; } else { $project = CrowdfundingHelperRoute::getProject($id); if (!empty($project)) { if ($project["alias"] == $alias) { $vars['view'] = 'details'; $vars['catid'] = (int) $project["catid"]; $vars['id'] = (int) $id; return $vars; } } } } // COUNT >= 2 if ($count >= 2) { $view = $segments[$count - 1]; switch ($view) { 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'] = 'backing'; $vars['id'] = (int) $itemId; $vars['catid'] = (int) $catId; break; case "embed": // Backing without reward $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'] = 'embed'; $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)) { $vars['screen'] = $screen; } break; default: // 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. $catId = (int) $segments[$count - 2]; $id = (int) $segments[$count - 1]; if ($id > 0 and $catId > 0) { $vars['view'] = 'details'; $vars['catid'] = $catId; $vars['id'] = $id; } else { $vars['view'] = 'category'; $vars['id'] = $id; } break; } } return $vars; }
/** * 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; }