/** * Method to build Route * * @param array $query * * @return array */ function CrowdfundingBuildRoute(&$query) { $segments = array(); // get a menu item based on Itemid or currently active $app = JFactory::getApplication(); $menu = $app->getMenu(); // we need a menu item. Either the one specified in the query, or the current active one if none specified if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); $menuItemGiven = false; } else { $menuItem = $menu->getItem($query['Itemid']); $menuItemGiven = isset($menuItem->query) ? true : false; } // Check again if ($menuItemGiven and isset($menuItem) and strcmp("com_crowdfunding", $menuItem->component) != 0) { $menuItemGiven = false; unset($query['Itemid']); } $mView = empty($menuItem->query['view']) ? null : $menuItem->query['view']; $mId = empty($menuItem->query['id']) ? null : $menuItem->query['id']; // $mOption = (empty($menuItem->query['option'])) ? null : $menuItem->query['option']; // $mCatid = (empty($menuItem->query['catid'])) ? null : $menuItem->query['catid']; // If is set view and Itemid missing, we have to put the view to the segments if (isset($query['view'])) { $view = $query['view']; } else { return $segments; } // Are we dealing with a category that is attached to a menu item? if ($menuItem instanceof stdClass and isset($view) and $mView == $view and isset($query['id']) and $mId == (int) $query['id']) { unset($query['view']); if (isset($query['catid'])) { unset($query['catid']); } if (isset($query['layout'])) { unset($query['layout']); } unset($query['id']); return $segments; } // Views if (isset($view)) { switch ($view) { case "category": if (!$menuItemGiven) { $segments[] = $view; } unset($query['view']); if (isset($query['id'])) { $categoryId = $query['id']; } else { // We should have id set for this view. If we don't, it is an error. return $segments; } $segments = CrowdfundingHelperRoute::prepareCategoriesSegments($categoryId, $segments, $menuItem, $menuItemGiven); unset($query['id']); break; case "backing": case "embed": case "details": if (!$menuItemGiven) { $segments[] = $view; } unset($query['view']); // If a project is assigned to a menu item. if ($menuItemGiven and strcmp("details", $menuItem->query["view"]) == 0 and $menuItem->query["id"] == (int) $query['id']) { } else { // If a project is NOT assigned to a menu item. if (isset($query['id']) and isset($query['catid']) and !empty($query['catid'])) { $categoryId = (int) $query['catid']; if (false === strpos($query['id'], ":")) { $alias = CrowdfundingHelperRoute::getProjectAlias($query['id']); $query['id'] = $query['id'] . ":" . $alias; } } else { // We should have these two set for this view. If we don't, it is an error. return $segments; } $segments = CrowdfundingHelperRoute::prepareCategoriesSegments($categoryId, $segments, $menuItem, $menuItemGiven); $segments[] = $query['id']; } unset($query['id']); unset($query['catid']); if (strcmp("backing", $view) == 0) { $segments[] = "backing"; } if (strcmp("embed", $view) == 0) { $segments[] = "embed"; } break; case "report": if ($menuItemGiven and strcmp("report", $menuItem->query["view"]) == 0 and isset($query['view'])) { unset($query['view']); } break; case "categories": case "discover": case "transactions": case "projects": case "project": // Form for adding projects if (isset($query['view'])) { unset($query['view']); } break; } } // Layout if (isset($query['layout'])) { if ($menuItemGiven and isset($menuItem->query['layout'])) { if ($query['layout'] == $menuItem->query['layout']) { unset($query['layout']); } } else { if ($query['layout'] == 'default') { unset($query['layout']); } } } // Screen if (isset($query["screen"])) { $segments[] = $query["screen"]; unset($query['screen']); } $total = count($segments); for ($i = 0; $i < $total; $i++) { $segments[$i] = str_replace(':', '-', $segments[$i]); } return $segments; }