<?php

/*
    class.secciones.php v0.5b version
    By: Omar G. Soto (OmaR aquí xD)
    PHP5 Compatible version
*/

class secciones {
    var
$type = '';
    var
$secciones = array();
    var
$descripciones = array();
    
    
// function secciones($type, $get = 'sec') { // para PHP 4
    
function __construct($type, $get = 'sec') {
        
$this->type = ($type == 1) ? 1 : $get;
    }
    
    function
addsection($texto, $link) {
        if (!
file_exists($link)) return false;
        if (isset(
$this->secciones[$texto])) return false;
        else {
            
$this->secciones[$texto] = $link;
            return
true;
        }
    }
    
    function
set_description($texto, $desc) {
        if (empty(
$this->secciones[$texto])) return false;
        else {
            
$this->descripciones[$texto] = $desc;
            return
true;
        }
    }
    
    function
get_info() {
        if (isset(
$this->type)) {
            if (
$this->type == 1) {
                
$temp = explode('&', $_SERVER['QUERY_STRING']);
                
$temp = $temp[0];
            } else
$temp = (isset($_GET[$this->type])) ? $_GET[$this->type] : false;
            
            foreach (
$this->secciones as $texto => $link) {
                
$desc = (isset($this->descripciones[$texto])) ? $this->descripciones[$texto] : false;
                if (
$temp == $texto) return array('descripcion' => $desc, 'seccion' => $texto, 'link' => $link);
            }
            
            return
false;
        } else return
false;
    }
}

// Ejemplo de uso

$sec = new secciones(2, 'id');

$sec->addsection(1, 'eje.php'); // ?id=1
$sec->set_description(1, 'Probando descripción');

if (
$info = $sec->get_info()) {

    echo
'»» ' . $info['descripcion'] . '<br />';
    include(
$info['link']);
}

?>

PHP-Hispano.net - Porque al final, todos acabamos aprendiendo.