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;
}

?>
the Joomla! AdsManager component is pretty beautiful, and easy to use and modify to suit your requirement. The only major problem it seems to have is that it has a SEF Plugin that requires a commercial purchase from 3rd Party, and there is no native router as available now in Joomla!
Joomla! now allows a component developer to put a router.php in the component root and then this acts as an override of the URL parser functions of the Joomla! core JRoute Class.

I recently developed a router.php for AdsMananger... so if anybody needs it , copy the code, paste it and save it as router.php inside the component's root folder, and turn on Joomla! SEF and you should be ready to go.

 NOTE:Here is the updated and more complete version of the router.

<?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[] = 'adventures';
				$segments[] = $query['catid'];				
				$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[] = 'tours';
			if(isset($query['catid'])){
				$segments[] = $query['catid'];				
				$category_alias = getCategoryTitle($query['catid']);
				$segments[] = $category_alias;		
				unset($query['catid']);
				
			}
			if(isset($query['adid'])){
				
				$segments[] = $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 'adventures';
		$vars['page'] = "show_category";
			if(isset($segments[1])){
				$vars['catid'] = $segments[1];
				$vars['Itemid'] = $item;
		}
		break;
		case 'tours';
		$vars['page'] = "show_ad";
			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;
}

?>

Leave a CommentTrackback
SOBI2 is fine for sites with moderate database sizes and moderate traffics, but when the number of records in your database exceeds 10s of thousands (and in our case it was 50000), SOBI2 might fail in generating the search results when the search filters are very broad, in fact SOBI2 fails in such cases because the large Queries generated by SOBI2 can not be parsed by mySQL if SQL_BIG_SELECTS option is not set in your mySQL Database.

So, those of you who own dedicated servers or have hosts friendly enough to turn on this mySQL option, go and get it set to 1 and SOBI2 will be back in action again. For the others, let's open the axsearch.class.php and add these few lines before any query is executed, and mySQL will be ready to run large queries.

 

$db2=& JFactory::getDBO();
$db2->setQuery("SET OPTION SQL_BIG_SELECTS=1");
$db2->query();
echo $db2->getErrorMsg();
Leave a CommentTrackback

Continuing from my previous post on how to add your custom formatted data to a SOBI2 Details view template, let's now consider the SOBI2 VCard template, which again has the restrictions of displaying the major field data in a pre processed set defined from inside SOBI2 Classes, so that, from the template itself you are left mostly with tasks like making them look better and doing the CSS for the field labels and values.

But, this is not sufficient in many cases, so let's do it again. let's go through the simple 1,2,3 Step routine of achieving this, the rest you'll understand naturally.

Step 1: Once again, from the From Sobi2 control panel select V-Card Template template under template & css menu. Let's say we need the Item detail URL separately to build a custom More Info link.We'd call our custom function and store the returned URL in our own variable and use it anywhere we like in our vCard HTML template, like this
 

$href=HTML_SOBI::createMoreInfoUrl( $id ); 

Step 2:  open file sobi2.html.php from inside the folder components/com_sobi2 and create the createMoreInfoUrl function to the class HTML_SOBI just where you find the other pre defined function like createWaySearchUrl
function createMoreInfoUrl($id) 	{ 		//REMEMBER TO ADD CATID LATER... 		$href = "index.php?option=com_sobi2&sobi2Task=sobi2Details&&sobi2Id={$id}";//&Itemid={$config->sobi2Itemid} 		$href = sobi2Config::sef($href); 		return $href; 	}

You can easily see how this function is similar to the createWaySearchUrl function and in the vCard template can be used just as the createWaySearchUrl or WaySearchUrl functions are used, as shown in Step1! 

So, once again, you are done! you can have as many custom functions outputting as many custom fields separated from the generic custom field output block that SOBI2 generates.

NOTE:The actual use of this method is not well explained in the given example, since if you want your custom display of individual fields in SOBI2 VCard Template, instead of using the pre defined block of custom fields data, you can comment out the following
<?php echo HTML_SOBI::customFieldsData($fieldsFormatted);?>

and use individual custom formatted field labes and data like
<?php echo $fieldsObjects['field_name']->label; ?>

<?php echo $fieldsObjects['field_name']->data; ?>

Writing a custom function is only important when you need some complex data to be output on your template based on many other fields or want to modify some of the existing functions there.
Leave a CommentTrackback
Recently we were working on a SOBI2 project, where the detail view generated by SOBI2 was not sufficient for us, simply put the formatted data SOBI2 presents us on the detail view was not sufficient for us, since we needed some fields to be displayed so separately from the SOBI2 Generated bunched data, that we needed to do something that presents us with a completely separate data field with no connection with SOBI2 generated detail view. We did the following to achieve this...and hope it's helpful for you too... I'll write in 1,2,3 Steps for ease of implementation, understanding what is happening is actually quite simple! we are simply adding a few more functions to the required classes to achieve the separate output we want.

Step 1:  Let's say we want to display the Item description completely separated from SOBI2 detail view data,what we do first is go to the Joomla Admin of our site and from the Sobi2 control panel select Detail view template under template&css menu.
Step 2:  Now, assume that we'll be writing an appropriate function to render the expected output, and then call it from the position in your layout, where you want this data to be displayed...like this,
<?php HTML_SOBI::getItemDesc($config,$mySobi); ?>

 Where getItemDesc is the function we'll look into next.

Step 3: Now open file sobi2.html.php from inside the folder components/com_sobi2 and add the following function inside the HTML_SOBI class along side the other functions you'll see SOBI2 already uses to generated data.
function getItemDesc($config,$mySobi)
    {
		sobi2Config::import("sobi2.entry");
		return sobiEntry::getItemDesc( $config,$mySobi );
    }

Step 4: Next open sobi2.entry.php from inside the folder components/com_sobi2 and add the follwing function inside the class sobiEntry
function getItemDesc($config, $mySobi)
	{
		$fieldsObjects 	=& $mySobi->myFields;
		//$my =& $config->getUser();
    	        //$cid = intval( sobi2Config::request( $_REQUEST, 'catid', 0 ) );
		foreach( $fieldsObjects as $field ) 
		{
			$field->name = $config->getSobiStr( $field->fieldname );
			$field->label = $config->getSobiStr( $field->label );
			if($field->name=='field_description')
			{
				echo $field->data;
			}
		}
	}


And So! you have your additional field displayed independently on the detail view, it could be any custom field you have added only that you have to know the exact name of the field.


NOTE:One again, The actual use of this method is not well understood from the given example, since if you want your custom display of individual fields in SOBI2 Detail Template, instead of using the pre defined block of custom fields data, you can use the following just like in vCard and use individual custom formatted field labes and data like
<?php echo $fieldsObjects['field_name']->label; ?>

<?php echo $fieldsObjects['field_name']->data; ?>

Writing a custom function is only important when you need some complex data to be output on your template based on many other fields or want to modify some of the existing functions there,and in case of the detail view template, the sobi2.entry.php is the perfect place where you can access the Database from and run your custom queries too
Leave a CommentTrackback

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.