Several people found my Ads Manager router useful. but since it was not built for the front end ad management facility, my version missed handling those specific tasks and views.

One guy "agu" who posted a comment on my previous post on Ads Manager Router took my router and advanced it further, and later mailed me the updated version.

 I'm posting it here,please comment if this is useful,since he also is keen to know how good his code turned out to be.He said he has used it successfully, so this might be the answer to many of your requirement, those who need a more complete router.

BTW, heard that there are several updated versions of Ads Manager coming along, can anybody point me to one of them?
<?php
/**
* Builds route for AdsManager
*
* @access public
* @param array Query associative array
* @return array SEF URI segments
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
function adsmanagerBuildRoute(&$query)
{
   $page = '';
    $segments = array();
    //print_r($query);
    if(isset($query['page'])){
        $page = $query['page'];
        unset($query['page']);
    }

   switch ($page) {
        
        case 'show_category';
                        
            if(isset($query['catid'])){
                $segments[] = 'categories';                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                //unset the rest of useless extra query string parameters passed on by the AdsManager 

Menu...
                //viz. text_search=&order=0&expand=0
                unset($query['text_search']);
                unset($query['order']);
                unset($query['expand']);
            }

        break;
        
        case 'show_ad';
            $segments[] = 'ads';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;

                case 'write_ad';
            $segments[] = 'post';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;

                case 'save_ad';
            $segments[] = 'save';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;

                case 'show_search';
            $segments[] = 'search';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;


        case 'show_all';
            $segments[] = 'allads';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
                break;
        

                case 'show_rules';
            $segments[] = 'rules';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;
        
                case 'delete_ad';
            $segments[] = 'delete';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;

        case 'show_result';
            $segments[] = 'result';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;

        case 'search';
            $segments[] = 'advsearch';
            if(isset($query['catid'])){                
                $category_alias = getCategoryTitle($query['catid']);
                $segments[] = $category_alias;        
                unset($query['catid']);
                
            }
            if(isset($query['adid'])){
                                
                $ad_alias = getAdTitle($query['adid']);
                $segments[] = $ad_alias;        
                unset($query['adid']);
            }
            //unset the rest of useless extra query string parameters passed on by the AdsManager Menu...
            //viz. text_search=&order=0&expand=0
            unset($query['text_search']);
            unset($query['order']);
            unset($query['expand']);
        break;
    } 
   return $segments;
}

/**
* Method to parse Route
* @param array $segments
*/ 
function adsmanagerParseRoute($segments)  
{
    $vars = array();
   
    // Get the active menu item.
    $menu   = &JSite::getMenu();
    $item   = &$menu->getActive();
    
    $firstSegment = $segments[0]; 
    switch($firstSegment){
        case 'categories';
        $vars['page'] = "show_category";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
                $vars['Itemid'] = $item;
        }
        break;
        case 'ads';
        $vars['page'] = "show_ad";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
                case 'post';
        $vars['page'] = "write_ad";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
                case 'save';
        $vars['page'] = "save_ad";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
                case 'search';
        $vars['page'] = "show_search";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
                case 'allads';
        $vars['page'] = "show_all";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;            
        break;
        case 'rules';
        $vars['page'] = "show_rules";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
        case 'delete';
        $vars['page'] = "delete_ad";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
        case 'result';
        $vars['page'] = "show_result";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
        case 'advsearch';
        $vars['page'] = "search";
            if(isset($segments[1])){
                $vars['catid'] = $segments[1];
        }
        if(isset($segments[3])){
                $vars['adid'] = $segments[3];
        }
        $vars['Itemid'] = $item;
        break;
    }
    return $vars;
}

function getCategoryTitle($id){
    $db    = & JFactory::getDBO();
    
    $query = "SELECT `name`,`parent` FROM #__adsmanager_categories WHERE `id`=".$id;
    
    $db->setQuery($query);
    $category_name = $db->loadResult();
    if($category_name=="")
        return;

    //you can add nested categories here

    $category_alias = strtolower($category_name);

    //Remove following characters
    $special_chars = array('!','@','#','$','%','*','(',')');
    foreach($special_chars as $char){
        $category_alias = str_replace($char,'', $category_alias);
    }

    $category_alias = str_replace(' ','-', $category_alias);
    $category_alias = str_replace('  ','-', $category_alias);
    return $category_alias;
}

function getAdTitle($id){
    $db    = & JFactory::getDBO();
    
    $query = "SELECT `ad_headline` FROM #__adsmanager_ads WHERE `id`=".$id;
    
    $db->setQuery($query);
    $ad_name = $db->loadResult();
    if($ad_name=="")
        return;

    //you can add nested categories here

    $ad_alias = strtolower($ad_name);

    //Remove following characters
    $special_chars = array('!','@','#','$','%','*','(',')');
    foreach($special_chars as $char){
        $ad_alias = str_replace($char,'', $ad_alias);
    }

    $ad_alias = str_replace(' ','-', $ad_alias);
    $ad_alias = str_replace('  ','-', $ad_alias);
    return $ad_alias;
}

?>

Add comment


Security code
Refresh

Recent Projects

New Model Agency, Greece

Custom Content Management System built in PHP/MySQL for New Model Agency, Greece.

lawJacked, Share the Law

The largest Law portal in the making,a very large, complicated and technically involved project.

Indy Wellness Guide

Indianapolis area wellness portal, with advanced search features including Zip Code Radius search.

Product Development

S4E Schools Solution


S4E Solution required us to build a complete school administrative software that can handle everything from student registration to results, and daily chores like attendance and everything else, with SMS based monitoring and parent-teacher relationship management.
We have developed a very user friendly and scalable model for this application. The back-end application is like any other CMS back-end but with special focus on school requirements and a no-frills approach for an easier learning experience.
The front end is a template driven complete but simple content management system, with the usual modules and plugin driven scalable design, but since the focus is schools and its administration, the template designing method is very simple and anyone with some HTMl knowledge can design the template or choose from pre-developed templates from the gallery.