<?
/*
Change log:
[30-04-05]
- corretto un errore nella funzione getPosPar e removePar
[22-04-05]
-corretto un errore nella funzione removePar bisogna verificare che $num non fosse nullo
[08-04-05]
- corretto un errore nella funzione removePar il controllo veniva fatto con
num > 0 e doveva essere >=0
[06-02-05]
- modificata la funzione getNext
[03-02-05]
- aggiunto un parametro alla funzione removeAllPar per potergli dire da dove partire a cancellare
- aggiunto alla funzione buildPars un parametro per eliminare il punto di domanda ?
utile quando si devono concatenare stringhe
[2-11-04]
[v.1]
- agggiunta la funzione retrievCurrUrl prende l'url corrente
// replaceParValue sosituisce un parametro
[17-10-04]
-[v.0.0.0.1] - aggiunta la funzione resetPos e getNext
[10-10-2004]
-[v.0.0.0.1] -aggiunta la funzione setUrlExternal per prendere un url esterno
-corretto un errore nella funzione removePar:se non veniva trovato il valore
cancellava il primo elemento perchè il risultato era ""
[v.0.0.1.1]
[28 gen 2004]
Classe per la gestione dell'url
[testata] [ver 0.0.1.1]
*/
class manUrlv1 {
var $url = array();
function manUrlv1() {
//$this->url = ($_GET) ;
$this->retrievCurrUrl();
}
function retrievCurrUrl() {
$this->url = ($_GET) ;
}
//ritorna l'url costruito
function getUrl() {
return $this->url;
}
//prende un url esterno
function setUrlExternal($p_url){
$this->url = $p_url;
}
//cicla l'array
function loopArray(&$kiave,&$valore) {
list($kiave,$valore)=each($this->url);
return $kiave;
}
//riporta il cursore al primo elemento
function resetPos() {
reset($this->url);
}
//ritorna ad uno a uno tutti gli
//elementi nel vettore
function getNext() {
$this->loopArray($kiave,$valore);
$ret = array();
if ($kiave != "") {
$ret[] = $kiave;
$ret[] = $valore;
}else
$ret = "";
return $ret;
}
//ritorna il valore di una chiave
function getValuePar($par) {
reset($this->url);
while ($this->loopArray($kiave,$valore)) {
if ($kiave == $par) return $valore;
}
}
//ritorna la kiave di una valore
function getKeyPar($par) {
reset($this->url);
while ($this->loopArray($kiave,$value)) {
if ($value == $par) return (string)$kiave;
}
}
//ritorna la posizione di una chiave
function getPosPar($par) {
reset($this->url);
$i=0;
while ($this->loopArray($kiave,$value)) {
//echo $kiave.",".$par.",$i";
if ($kiave == $par) return $i;
$i++;
}
}
//sostituisce un elemento
function replaceParValue($par,$value) {
$this->removePar($par);
$this->addParComplete($par,$valore);
}
//rimuove un elemento
function removePar($par) {
$num = $this->getPosPar($par);
if (($num >=0) && (isset($num) != false)) {
//print_r($this->url);
//echo "trovato e cancellato";
array_splice($this->url,$num,1);
}
//print_r($this->url);
}
//rimuove tutti gli elementi
function removeAllPar($start=1) {
array_splice($this->url,$start,count($this->url));
}
//aggiunge un elemento
function addParComplete($kiave,$valore){
$this->url[$kiave]=$valore;
}
function buildPars($withAsk = true) {
reset($this->url);
if ($withAsk == true) $query ="?";
else $query = "";
while ($this->loopArray($kiave,$value)) {
$query .= $kiave."=".$value."&";
}
$pos = strrpos($query,"&");
if ($pos>0) $query=substr($query,0,$pos);
return $query;
}
};
?>