Current Path : /var/www/html/clients/kampol.e-nk.ru/OLD/components/com_easyfaq/ |
Current File : /var/www/html/clients/kampol.e-nk.ru/OLD/components/com_easyfaq/sef_ext.php |
<?php /** * @package Easyfaq * @copyright (C) 2006 Joomla-addons.org * @author Websmurf * * -------------------------------------------------------------------------------- * All rights reserved. Easy FAQ Component for Joomla! * * This program is free software; you can redistribute it and/or * modify it under the terms of the Creative Commons - Attribution-NoDerivs 2.5 * license as published by the Creative Commons Organisation * http://creativecommons.org/licenses/by-nd/2.5/. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * -------------------------------------------------------------------------------- **/ defined( '_VALID_MOS' ) or die( 'Restricted access' ); class sef_easyfaq { function create($string){ $_Itemid = $this->getItemidFromUrl($string); $sefstring = ""; if($this->isTask('view', $string)){ //view article $sefstring = "view/"; $id = $this->getIdFromUrl($string); $title = $this->getFaqTitle($id); $category = $this->getFaqCat($id); $sefstring .= $category . "/" . $title . "/"; } else if($this->isTask('new', $string)){ $sefstring = "new/"; } else if($this->isTask('edit', $string)){ $sefstring = "edit/"; $id = $this->getIdFromUrl($string); $sefstring .= $id . "/"; } else if($this->isTask('pdf', $string)){ $sefstring = "pdf/"; $id = $this->getIdFromUrl($string); $sefstring .= $id . "/"; } else if($this->isTask('save', $string)){ $sefstring = "save/"; } else if($this->isTask('cancel', $string)){ $sefstring = "cancel/"; } else if($this->isTask('cat', $string)){ $sefstring = "cat/"; $catid = $this->getCatIdFromUrl($string); $cat = $this->getCatTitle($catid); $sefstring .= $cat . "/"; } else { //no task provided } return $sefstring . $_Itemid . "/"; } function revert($url_array, $pos){ $QUERY_STRING = ""; if(sizeof($url_array) == 4){ //first page $Itemid = $url_array[$pos + 2]; $_GET['Itemid'] = $Itemid; $_REQUEST['Itemid'] = $Itemid; $QUERY_STRING .= "&Itemid=$Itemid"; } else { //arguments have been passed $task = $url_array[$pos + 2]; $_GET['task'] = $task; $_REQUEST['task'] = $task; $QUERY_STRING .= "&task=$task"; switch ($task){ case 'edit': $id = $url_array[$pos + 3]; $_GET['id'] = $id; $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=$id"; $Itemid = $url_array[$pos + 4]; $_GET['Itemid'] = $Itemid; $_REQUEST['Itemid'] = $Itemid; $QUERY_STRING .= "&Itemid=$Itemid"; break; case 'view': $id = $this->getFaqId($url_array[$pos + 4], $url_array[$pos + 3]); $_GET['id'] = $id; $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=$id"; $Itemid = $url_array[$pos + 5]; $_GET['Itemid'] = $Itemid; $_REQUEST['Itemid'] = $Itemid; $QUERY_STRING .= "&Itemid=$Itemid"; break; case 'cancel': case 'new': break; case 'cat': $catid = $this->getCatId($url_array[$pos + 3]); $_GET['catid'] = $catid; $_REQUEST['catid'] = $catid; $QUERY_STRING .= "&catid=$catid"; $Itemid = $url_array[$pos + 4]; $_GET['Itemid'] = $Itemid; $_REQUEST['Itemid'] = $Itemid; $QUERY_STRING .= "&Itemid=$Itemid"; break; } } return $QUERY_STRING; } /** * Retreive from url which task it is * * @param string the needed task * @param string url to look in * @return boolean */ function isTask($task, $string){ return eregi("&task=$task",$string); } /** * Get the id from the url * * @param string url * @return int */ function getIdFromUrl($string){ if (eregi("&id=",$string)) { $temp = split("&id=", $string); $temp = split("&", $temp[1]); return intval($temp[0]); } return null; } /** * Get the catid from the url * * @param string url * @return int */ function getCatIdFromUrl($string){ if (eregi("&catid=",$string)) { $temp = split("&catid=", $string); $temp = split("&", $temp[1]); return intval($temp[0]); } return null; } /** * Get the Itemid from the url * * @param string url * @return id */ function getItemidFromUrl($string){ if (eregi("&Itemid=",$string)) { $temp = split("&Itemid=", $string); $temp = split("&", $temp[1]); return intval($temp[0]); } return null; } /** * Convert category id in sef encoded title * * @param int $id * @return string */ function getCatTitle($id){ global $database; $query = "SELECT title FROM #__categories WHERE id = " . intval($id); $database->setQuery($query); $title = $database->loadResult(); return sefencode($title); } /** * Convert category title in id * * @param string $title * @return int */ function getCatId($title){ global $database; $title = sefdecode($title); $query = "SELECT id FROM #__categories WHERE title = '" . $title . "'"; $database->setQuery($query); $id = $database->loadResult(); return $id; } /** * Convert faq id in sef encoded title * * @param int $id * @return string */ function getFaqTitle($id){ global $database; $query = "SELECT title FROM #__easyfaq WHERE id = " . intval($id); $database->setQuery($query); $title = $database->loadResult(); return sefencode($title); } /** * Convert faq id in sef encoded category * * @param int $id * @return string */ function getFaqCat($id){ global $database; $query = "SELECT name FROM #__categories c LEFT JOIN #__easyfaq f ON c.id = f.catid WHERE f.id = " . intval($id); $database->setQuery($query); $category = $database->loadResult(); echo $database->getErrorMsg(); return sefencode($category); } /** * Convert faq title to id * * @param string $title * @return int */ function getFaqId($title, $category){ global $database; $title = sefdecode($title); $category = sefdecode($category); $query = "SELECT f.id FROM #__easyfaq f LEFT JOIN #__categories c ON f.catid = c.id WHERE f.title = '" . $title . "' AND c.name = '". $category . "'"; $database->setQuery($query); $id = $database->loadResult(); return $id; } }