So far I'm re-inventing the wheel here in the most uncomfortable way. I can feel in my gut that this will break one day and cause me a lot of pain. Therefore I'm looking for a better way to take an article alias and build either the menu item url or the article url. Are there no joomla api calls that make this easier/cleaner/more future-proof?
/* Find article by alias */
$db =& JFactory::getDBO();
$sql = 'select id from #__content where alias=' . "'$alias'";
$db->setQuery($sql);
$row = $db->loadAssoc();
$artId = $row['id'];
if ($artId != null) {
$artLink = 'index.php?option=com_content&view=article&id='.$artId;
/* Find menu item by article id */
$sql = 'select parent,alias from #__menu where link=' . "'$artLink'";
$db->setQuery($sql);
$row = $db->loadAssoc();
$menuLink = '';
while ($row != null) {
$menuLink = '/' . $row['alias'] . $menuLink;
$sql = 'select parent,alias from #__menu where id=' . $row['parent'];
$db->setQuery($sql);
$row = $db->loadAssoc();
}
$menuLink = 'index.php' . $menuLink;
}
$articleUrl = ($menuLink != '') ? 'index.php' . $menuLink : JRoute::_($artLink);