RSS

Create Custom SEF URL’s in Joomla for custom development using menus SEF URL’s functionality

21 Mar

class CustomRouter {

function getRewriteURL($itemid=null)
{
if(!$itemid)
{
return null;
}else{
$db = JFactory::getDBO();
$query = “SELECT * FROM  `#__menu` WHERE  `id` = $itemid”;
//$query = “SELECT * FROM  `care_caremenu` WHERE  `id` = 1″;
$db->setQuery($query);
$item = $db->loadObject();

$item->flink = $item->link;

// Reverted back for CMS version 2.5.6
switch ($item->type)
{
case ‘separator’:
// No further action needed.
continue;

case ‘url’:
if ((strpos($item->link, ‘index.php?’) === 0) && (strpos($item->link, ‘Itemid=’) === false)) {
// If this is an internal Joomla link, ensure the Itemid is set.
$item->flink = $item->link.’&Itemid=’.$item->id;
}
break;

case ‘alias’:
// If this is an alias use the item id stored in the parameters to make the link.
$item->flink = ‘index.php?Itemid=’.$item->params->get(‘aliasoptions’);
break;

default:
$router = JSite::getRouter();
if ($router->getMode() == JROUTER_MODE_SEF) {
$item->flink = ‘index.php?Itemid=’.$item->id;
}
else {
$item->flink .= ‘&Itemid=’.$item->id;
}
break;
}

if (strcasecmp(substr($item->flink, 0, 4), ‘http’) && (strpos($item->flink, ‘index.php?’) !== false)) {
//$item->flink = JRoute::_($item->flink, true, $item->params->get(‘secure’));
$item->flink = JRoute::_($item->flink, true, ”);
}
else {
$item->flink = JRoute::_($item->flink);
}

if (strpos(strtolower($item->flink), ‘itemid’) === false)
return $item->flink;
else
return $item->link;
}
}

function getAlias($alias)
{
if($alias){
$alias = JApplication::stringURLSafe($alias);
$alias = trim(str_replace(‘ ‘, ‘-‘, $alias));
}else{
$alias=JFactory::getDate()->format(‘Y-m-d-H-i-s’);
}
return $alias;
}
function genMenu($title=null, $link=null, $itemid=null)
{

if($title && $itemid){
$db = JFactory::getDBO();
$alias = CaresubscriptionHelper::getAlias($title);
$query = “UPDATE `#__menu` SET `title` = “.$db->Quote($title).”, `alias`= “.$db->Quote($alias).”, `path`=”.$db->Quote($alias).” WHERE `id` = $itemid;”;
$db->setQuery($query);
if($db->query()) return true;
else return false;
}elseif($title){
$db = JFactory::getDBO();
$alias = CaresubscriptionHelper::getAlias($title);
$query = “INSERT INTO `#__menu` ( `menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `level`, `component_id`, `ordering`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `lft`, `rgt`, `home`, `language`, `client_id`, `joomlamenu`) VALUES ( ‘mainmenu’, “.$db->Quote($title).”, “.$db->Quote($alias).”, ”, “.$db->Quote($alias).”, “.$db->Quote($link).”, ‘component’, ‘1’, ‘1’, ‘1’, ‘10001’, ‘0’, ‘0’, ‘0000-00-00 00:00:00’, ‘0’, ‘1’, ”, ‘0’, ”, ‘0’, ‘0’, ‘0’, ‘*’, ‘0’, ‘1’);”;
$db->setQuery($query);
if($db->query())    return $db->insertid();
else return false;
}else{
return false;
}
}

// This function will conver global currency to PayPal payment currency.
function currencyconerter($amount, $flag=”currencywithamount”)
{
$params = JComponentHelper::getParams(‘com_caresubscription’);
$sitecurrency      = $params->get(‘sitecurrency’, ‘AED’);
$currencyrate      = $params->get(‘currencyrate’, ‘0’);
$paymentcurrency = $params->get(‘paymentcurrency’, ”);
$currencysymbol  = $params->get(‘currencysymbol’, ”);

if($flag==”amount”)
return round( ($amount * $currencyrate), 2);
else if($flag==”currencywithamount”)
return $currencysymbol.”.round( ($amount * $currencyrate), 2);
}
}

$link   = “index.php?option=component_name&view=viewname&id=”.$id;
$itemid = CustomRouter::genMenu($slug, $link);

Here custom menu is created we can access this SEF url by using following code

$link = CustomRouter::getRewriteURL($itemid);

Advertisements
 
Leave a comment

Posted by on March 21, 2013 in Joomla

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: