Your IP : 216.73.216.84


Current Path : /home/helpink/www/components/com_jbusinessdirectory/
Upload File :
Current File : /home/helpink/www/components/com_jbusinessdirectory/router.php

<?php
/**
 * @package    J-BusinessDirectory
 *
 * @author     CMSJunkie http://www.cmsjunkie.com/
 * @copyright  Copyright (C) 2007 - 2022 CMSJunkie. All rights reserved.
 * @license    https://www.gnu.org/licenses/agpl-3.0.en.html
 */

defined('_JEXEC') or die('Restricted access');

/**
 * Routing class of com_jbusinessdirectory
 *
 * @since  3.3
 */
class JBusinessDirectoryRouter extends JComponentRouterView {
	protected $noIDs = false;
	
	/**
	 * Content Component router constructor
	 *
	 * @param   JApplicationCms  $app   The application object
	 * @param   JMenu            $menu  The menu object to work with
	 */
	public function __construct($app = null, $menu = null) {
		$params = JComponentHelper::getParams('com_jbusinessdirectory');
		$this->noIDs = true;
		
		$search = new JComponentRouterViewconfiguration('search');
		$this->registerView($search);
		
		$listing = new JComponentRouterViewconfiguration('companies');
		$listing->setKey('companyId')->setParent($search, 'id');
		$this->registerView($listing);
		
		$offers = new JComponentRouterViewconfiguration('offers');
		$this->registerView($offers);
		
		$offer = new JComponentRouterViewconfiguration('offer');
		$offer->setKey('offerId')->setParent($offers, 'id');
		$this->registerView($offer);
		
		$events = new JComponentRouterViewconfiguration('events');
		$this->registerView($events);
		
		$event = new JComponentRouterViewconfiguration('event');
		$event->setKey('eventId')->setParent($events, 'id');
		$this->registerView($event);
	  
		$this->registerView(new JComponentRouterViewconfiguration('billingdetails'));
		$this->registerView(new JComponentRouterViewconfiguration('businessuser'));
		$this->registerView(new JComponentRouterViewconfiguration('catalog'));
		$this->registerView(new JComponentRouterViewconfiguration('categories'));
		$this->registerView(new JComponentRouterViewconfiguration('invoice'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompany'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanies'));
		$this->registerView(new JComponentRouterViewconfiguration('orders'));
		$this->registerView(new JComponentRouterViewconfiguration('payment'));
		$this->registerView(new JComponentRouterViewconfiguration('packages'));
		$this->registerView(new JComponentRouterViewconfiguration('useroptions'));
		$this->registerView(new JComponentRouterViewconfiguration('conferencesessions'));
		$this->registerView(new JComponentRouterViewconfiguration('conferences'));
		$this->registerView(new JComponentRouterViewconfiguration('speakers'));
		$this->registerView(new JComponentRouterViewconfiguration('cart'));
		$this->registerView(new JComponentRouterViewconfiguration('managebookmarks'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyannouncement'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyannouncements'));
		$this->registerView(new JComponentRouterViewconfiguration('managerequestquotes'));
		$this->registerView(new JComponentRouterViewconfiguration('manageuserreviews'));
		$this->registerView(new JComponentRouterViewconfiguration('manageusermessages'));
		$this->registerView(new JComponentRouterViewconfiguration('manageusereventreservations'));
		$this->registerView(new JComponentRouterViewconfiguration('manageuserservicereservations'));
		$this->registerView(new JComponentRouterViewconfiguration('manageusereventappointments'));
		$this->registerView(new JComponentRouterViewconfiguration('manageuserofferorders'));
		$this->registerView(new JComponentRouterViewconfiguration('userdashboard'));
		$this->registerView(new JComponentRouterViewconfiguration('videos'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyarticles'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyoffer'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyoffers'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyoffercoupons'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyevent'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyevents'));
		$this->registerView(new JComponentRouterViewconfiguration('trips'));
		$this->registerView(new JComponentRouterViewconfiguration('requestquotes'));
		$this->registerView(new JComponentRouterViewconfiguration('listingsmap'));

		$this->registerView(new JComponentRouterViewconfiguration('activityitinerary'));
		$this->registerView(new JComponentRouterViewconfiguration('billingoverview'));
		$this->registerView(new JComponentRouterViewconfiguration('claimlisting'));
		$this->registerView(new JComponentRouterViewconfiguration('companyproducts'));
		$this->registerView(new JComponentRouterViewconfiguration('customers'));
		$this->registerView(new JComponentRouterViewconfiguration('listingconfirmation'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanypricelist'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanypricelists'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyproject'));
		$this->registerView(new JComponentRouterViewconfiguration('managecompanyprojects'));
		$this->registerView(new JComponentRouterViewconfiguration('managelistingregistrations'));
		$this->registerView(new JComponentRouterViewconfiguration('managemessages'));
		$this->registerView(new JComponentRouterViewconfiguration('managepaymentprocessor'));
		$this->registerView(new JComponentRouterViewconfiguration('managepaymentprocessors'));
		$this->registerView(new JComponentRouterViewconfiguration('managereviews'));
		$this->registerView(new JComponentRouterViewconfiguration('managestatistics'));
		$this->registerView(new JComponentRouterViewconfiguration('manageuserpackageorders'));
		$this->registerView(new JComponentRouterViewconfiguration('sharedreview'));
		$this->registerView(new JComponentRouterViewconfiguration('termsconditions'));
		$this->registerView(new JComponentRouterViewconfiguration('manageusertripbookings'));

		parent::__construct($app, $menu);
		
		$this->attachRule(new JComponentRouterRulesMenu($this));
		$this->attachRule(new JComponentRouterRulesStandard($this));
		$this->attachRule(new JComponentRouterRulesNomenu($this));

		//JLoader::register('JBusinessDirectoryRouterRulesLegacy', __DIR__ . '/include/legacyrouter.php');
		//$this->attachRule(new JBusinessDirectoryRouterRulesLegacy($this));
	}
	

	    /**
     * Build method for URLs
     *
     * @param   array  &$query  Array of query elements
     *
     * @return  array  Array of URL segments
     *
     * @since   3.5
     */
    public function build(&$query)
    {
        $segments = [];

		if(isset($query['resetSearch'])){
			unset($query['resetSearch']);
		}

		if(isset($query['list_layout'])){
			unset($query['list_layout']);
		}

		if(isset($query['listing_layout'])){
			unset($query['listing_layout']);
		}

		if(isset($query['featured'])){
			unset($query['featured']);
		}

		if(isset($query['geolocation'])){
			unset($query['geolocation']);
		}

		if(isset($query['radius'])){
			unset($query['radius']);
		}

		if(isset($query['categoryType'])){
			unset($query['categoryType']);
		}

		if(isset($query['view_style'])){
			unset($query['view_style']);
		}

		if(isset($query['view_mode'])){
			unset($query['view_mode']);
		}

		if(isset($query['grid_layout'])){
			unset($query['grid_layout']);
		}

		if(isset($query['menuCategoryId'])){
			unset($query['menuCategoryId']);
		}

		if(isset($query['itemType'])){
			unset($query['itemType']);
		}

		if(isset($query['enforcemetadata'])){
			unset($query['enforcemetadata']);
		}
		
		if(isset($query['enforceURL'])){
			unset($query['enforceURL']);
		}

		if(isset($query['menupackages'])){
			unset($query['menupackages']);
		}
		
	    // Process the parsed variables based on custom defined rules
        foreach ($this->rules as $rule) {
            $rule->build($query, $segments);
        }

		return $segments;
    }

	/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $id     ID of the article to retrieve the segments for
	 * @param   array   $query  The request that is built right now
	 *
	 * @return  array|string  The segments of this item
	 */
	public function getCategorySearchSegment($id, $query) {
		if (!strpos($id, ':')) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('alias'))
			->from($dbquery->qn('#__jbusinessdirectory_categories'))
			->where('id = ' . $dbquery->q($id));
			$db->setQuery($dbquery);
			
			$id .= ':' . $db->loadResult();
		}

		if ($this->noIDs) {
			list($void, $segment) = explode(':', $id, 2);
			return array($void => $segment);
		}
	   
		return array((int) $id => $id);
	}
	
	/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $id     ID of the article to retrieve the segments for
	 * @param   array   $query  The request that is built right now
	 *
	 * @return  array|string  The segments of this item
	 */
	public function getCompaniesSegment($id, $query) {
		if (!strpos($id, ':')) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('alias'))
			->from($dbquery->qn('#__jbusinessdirectory_companies'))
			->where('id = ' . $dbquery->q($id));
			$db->setQuery($dbquery);
			
			$id .= ':' . $db->loadResult();
		}

		if ($this->noIDs) {
			list($void, $segment) = explode(':', $id, 2);
			return array($void => $segment);
		}
	   
		return array((int) $id => $id);
	}
	
	/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $id     ID of the article to retrieve the segments for
	 * @param   array   $query  The request that is built right now
	 *
	 * @return  array|string  The segments of this item
	 */
	public function getOfferSegment($id, $query) {
		if (!strpos($id, ':')) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('alias'))
			->from($dbquery->qn('#__jbusinessdirectory_company_offers'))
			->where('id = ' . $dbquery->q($id));
			$db->setQuery($dbquery);
			
			$id .= ':' . $db->loadResult();
		}
		
		if ($this->noIDs) {
			list($void, $segment) = explode(':', $id, 2);
			return array($void => $segment);
		}
		
		return array((int) $id => $id);
	}
	
	
	/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $id     ID of the article to retrieve the segments for
	 * @param   array   $query  The request that is built right now
	 *
	 * @return  array|string  The segments of this item
	 */
	public function getEventSegment($id, $query) {
		if (!strpos($id, ':')) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('alias'))
			->from($dbquery->qn('#__jbusinessdirectory_company_events'))
			->where('id = ' . $dbquery->q($id));
			$db->setQuery($dbquery);
			
			$id .= ':' . $db->loadResult();
		}
		
		if ($this->noIDs) {
			list($void, $segment) = explode(':', $id, 2);
			return array($void => $segment);
		}
		
		return array((int) $id => $id);
	}
	
	
/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $segment  Segment of the article to retrieve the ID for
	 * @param   array   $query    The request that is parsed right now
	 *
	 * @return  mixed   The id of this item or false
	 */
	public function getCategorySearchId($segment, $query) {
		if ($this->noIDs) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('id'))
			->from($dbquery->qn('#__jbusinessdirectory_categories'))
			->where('alias = ' . $dbquery->q($segment));
			$db->setQuery($dbquery);
			
			return (int) $db->loadResult();
		}
		
		return (int) $segment;
	}

	/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $segment  Segment of the article to retrieve the ID for
	 * @param   array   $query    The request that is parsed right now
	 *
	 * @return  mixed   The id of this item or false
	 */
	public function getCompaniesId($segment, $query) {
		if ($this->noIDs) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('id'))
			->from($dbquery->qn('#__jbusinessdirectory_companies'))
			->where('alias = ' . $dbquery->q($segment));
			$db->setQuery($dbquery);
			
			return (int) $db->loadResult();
		}
		
		return (int) $segment;
	}
	
	/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $segment  Segment of the article to retrieve the ID for
	 * @param   array   $query    The request that is parsed right now
	 *
	 * @return  mixed   The id of this item or false
	 */
	public function getOfferId($segment, $query) {
		if ($this->noIDs) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('id'))
			->from($dbquery->qn('#__jbusinessdirectory_company_offers'))
			->where('alias = ' . $dbquery->q($segment));
			$db->setQuery($dbquery);
			
			return (int) $db->loadResult();
		}
		
		return (int) $segment;
	}
	
	
	/**
	 * Method to get the segment(s) for an article
	 *
	 * @param   string  $segment  Segment of the article to retrieve the ID for
	 * @param   array   $query    The request that is parsed right now
	 *
	 * @return  mixed   The id of this item or false
	 */
	public function getEventId($segment, $query) {
		if ($this->noIDs) {
			$db = JFactory::getDbo();
			$dbquery = $db->getQuery(true);
			$dbquery->select($dbquery->qn('id'))
			->from($dbquery->qn('#__jbusinessdirectory_company_events'))
			->where('alias = ' . $dbquery->q($segment));
			$db->setQuery($dbquery);
			
			return (int) $db->loadResult();
		}
		
		return (int) $segment;
	}
}

/**
 * Content router functions
 *
 * These functions are proxys for the new router interface
 * for old SEF extensions.
 *
 * @param   array  &$query  An array of URL arguments
 *
 * @return  array  The URL arguments to use to assemble the subsequent URL.
 *
 *
 */
function jBusinessDirectoryBuildRoute(&$query) {
	$app = JFactory::getApplication();
	$router = new JBusinessDirectoryRouter($app, $app->getMenu());
	
	return $router->build($query);
}

/**
 * Parse the segments of a URL.
 *
 * This function is a proxy for the new router interface
 * for old SEF extensions.
 *
 * @param   array  $segments  The segments of the URL to parse.
 *
 * @return  array  The URL attributes to be used by the application.
 *
 * @since   3.3
 *
 */
function jBusinessDirectoryParseRoute($segments) {
	$app = JFactory::getApplication();
	$router = new JBusinessDirectoryRouter($app, $app->getMenu());
	
	return $router->parse($segments);
}