Location: PHPKode > projects > Joomla SEF / SEO - extending OpenSEF > core/sef.onfly.php
<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

// com_poll
class sef_onfly_poll {

	/**
	* Creates the Open SEF URL out of the Joomla! request
	**/
	function create ($string) {
		global $database, $sefConfig;

		$sefstring = "";
        if (eregi("&amp;id=",$string)) {
           	$temp = split("&amp;id=", $string);
            $temp = split("&", $temp[1]);
            if ($temp[0] == "' + this.options[selectedIndex].value + '") {
               	$sefstring .= "' + this.options[selectedIndex].text + '/";
            } else {
                $database->setQuery("SELECT title FROM #__polls WHERE id=".$temp[0]);
                $sefstring .= sefEncode($database->loadResult()).'/';
            }
         }
         if ($sefConfig->encode_page_suffix != "" && $sefstring != "" && !eregi("index.php",$sefstring)) {
			$sefstring = substr($sefstring, 0, strlen($sefstring)-1) . $sefConfig->encode_page_suffix;
		}
		return $sefstring;
	}

	/**
	* Reverts to the Joomla query string out of the Open SEF URL
	**/
 	function revert ($url_array, $pos) {
		// define all variables you pass as globals
		global $database, $sefConfig;

        $option = "com_poll";

        $_GET['option'] = $option;
        $_REQUEST['option'] = $option;
        $database->setQuery("SELECT id "
        ."FROM #__menu "
        ."WHERE link='index.php?option=$option'");
        $Itemid = $database->loadResult();
        $_GET['Itemid'] = $Itemid;
        $_REQUEST['Itemid'] = $Itemid;
        $QUERY_STRING = "option=$option&Itemid=$Itemid";

        if (isset($url_array[$pos+1]) && isset($url_array[$pos+2]) && $url_array[$pos+2]!="") {
        	$task = "results";
            $_GET['task'] = $task;
            $_REQUEST['task'] = $task;
            $title = sefDecode($url_array[$pos+2]);
            $database->setQuery("SELECT id "
            ."FROM #__polls "
            ."WHERE title='$title'");
            $id = $database->loadResult();
            $_GET['id'] = $id;
            $_REQUEST['id'] = $id;
            $QUERY_STRING .= "&task=$task&id=$id";
            return $QUERY_STRING;
		}
	}
}
// com_contact
class sef_onfly_contact {

	/**
	* Creates the Open SEF URL out of the Joomla! request
	**/
	function create ($string) {
		global $database, $sefConfig;

		$sefstring = "";
		if (eregi("&amp;catid=",$string)) {
           $temp = split("&amp;catid=", $string);
           $temp = split("&", $temp[1]);
           $database->setQuery("SELECT name from #__categories WHERE id=".$temp[0]);
           $sefstring .= sefEncode($database->loadResult())."/";
        }
        if (eregi("&amp;contact_id=",$string)) {
        	$temp = split("&amp;contact_id=", $string);
            $temp = split("&", $temp[1]);
            $database->setQuery("SELECT name FROM #__contact_details WHERE id=".$temp[0]);
            $sefstring .= sefEncode($database->loadResult()).$sefConfig->encode_page_suffix;
         }
         return $sefstring;
	}

	/**
	* Reverts to the Joomla query string out of the Open SEF URL
	**/
 	function revert ($url_array, $pos) {
		// define all variables you pass as globals
		global $database, $sefConfig;

        $option = "com_contact";

        $_GET['option'] = $option;
        $_REQUEST['option'] = $option;

        $database->setQuery("SELECT id "
		."FROM #__menu "
		."WHERE link = 'index.php?option=$option' AND published=1 ORDER BY access");
		$Itemid = $database->loadResult();
		$_GET['Itemid'] = $Itemid;
		$_REQUEST['Itemid'] = $Itemid;
		$QUERY_STRING = "option=$option&Itemid=$Itemid";

        $name = sefDecode($url_array[$pos+2]);
		$database->setQuery("SELECT id "
		."FROM #__categories "
		."WHERE name='$name' AND section='com_contact_details'");
		$catid = $database->loadResult();

		if ($catid != "") {
			$_GET['catid'] = $catid;
			$_REQUEST['catid'] = $catid;
			$QUERY_STRING .= "&catid=$catid";
			$database->setQuery("SELECT id "
			."FROM #__menu "
			."WHERE link = 'index.php?option=$option&catid=$catid'");
			$_temp = $database->loadResult();
			if ($_temp != "") {
				$Itemid = $_temp;
				$_GET['Itemid'] = $Itemid;
				$_REQUEST['Itemid'] = $Itemid;
				$QUERY_STRING = "option=$option&Itemid=$Itemid";
			}
		} else {
			$task = "view";
			$_GET['task'] = $task;
			$_REQUEST['task'] = $task;
			$database->setQuery("SELECT id "
			."FROM #__contact_details "
			."WHERE name='$name'");
			$contact_id = $database->loadResult();
			$_GET['contact_id'] = $contact_id;
			$_REQUEST['contact_id'] = $contact_id;
			$QUERY_STRING .= "&task=$task&contact_id=$contact_id";
			$database->setQuery("SELECT id "
			."FROM #__menu "
			."WHERE link = 'index.php?option=$option&task=$task&contact_id=$contact_id'");
			$_temp = $database->loadResult();
			if ($_temp != "") {
				$Itemid = $_temp;
				$_GET['Itemid'] = $Itemid;
				$_REQUEST['Itemid'] = $Itemid;
				$QUERY_STRING = "option=$option&Itemid=$Itemid";
				}
		}
		return $QUERY_STRING;
	}
}
?>
Return current item: Joomla SEF / SEO - extending OpenSEF