elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  [PHP] - Leer las {} de html, creacion de Templates tipo phpbb
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [PHP] - Leer las {} de html, creacion de Templates tipo phpbb  (Leído 2,803 veces)
Overlord

Desconectado Desconectado

Mensajes: 28



Ver Perfil
[PHP] - Leer las {} de html, creacion de Templates tipo phpbb
« en: 24 Septiembre 2006, 20:33 pm »

Amigos:

Estoy tratando de hacer un sistema de plantillas para mi web baso en el codigo de phpbb, pero tengo problemas, aqui les pongo el codigo:

clases.php

Código:
<?
class plantilla{
var $_tpldata = array();

/* Pasamos el nombre de la variables sin su extención */
        function plantilla($template_file){
                $this->jnt_file = 'themes/yellow/' . $template_file . '.jnt';
        }
       
/* Resibe la variable */
        function asigna_variables($vars){
                $this->vars= (empty($this->vars)) ? $_vars : $this->vars . $vars;
echo  $vars[2];
        }
       
/*extraido de phpbb2, funcion para una consulta SQL */
function assign_block_vars($vararray)
{
$blockname = $this->jnt_file;
reset($this);
if (strstr($blockname, '.'))
{
// Nested block.

$blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1;
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']';

}
// Now we add the block that we're actually assigning to.
// We're adding a new iteration to this block with the given
// variable assignments.
$str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;';

// Now we evaluate this assignment we've built up.
eval($str);
}
else
{
// Top-level block.
// Add a new iteration to this block with the variable assignments
// we were given.
$this->_tpldata[$blockname . '.'][] = $vararray;
}

return true;
}


/* Funcion encargada de cargar el archivo para ser mostrado */
function loadfile($handle)
{
$handle = "body.jnt";
// If the file for this handle is already loaded and compiled, do nothing.
if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle]))
{
return true;

}

// Si el archivo no existe.
//echo "<b>$this->files[$handle]</b><br>";
if (!isset($this->files['themes/yellow/body.jnt']))
{
die("Template->loadfile(): No file specified for handle $handle");
}

$filename = $this->files[$handle];

$str = implode("", @file($filename));
if (empty($str))
{
die("Template->loadfile(): File $filename for handle $handle is empty");
}

$this->uncompiled_code[$handle] = $str;

return true;
}

function pparse()
{
$handle=$this->jnt_file;
//echo $handle;
if (!$this->loadfile($handle))
{
die("Template->pparse(): Couldn't load template file for handle $handle");
}

// actually compile the template now.
if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle]))
{
// Actually compile the code now.
$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
}

// Run the compiled code.
eval($this->compiled_code[$handle]);
return true;
}

}
?>

categorias.php

Código:
<?
$jnt_template=new plantilla("body");

//assign_block_vars
$resp = mysql_query("select * FROM categorias ORDER BY c_id") ;
while($datos = mysql_fetch_array($resp))
{
//$jnt_template->assign_block_vars('body',array
$jnt_template->assign_block_vars(array
(
'SECCION_N' => $datos['nombre'],
'DESCRIPCION' => $datos['descripcion']
));

};
//$ContenidoString = $jnt_template->muestra();
//echo $ContenidoString;
$jnt_template->pparse();
mysql_free_result($resp) ;
mysql_close($conectar) ;

?>

El problema es el siguiente:
Tengo el archivo de plantila en themes/yellow/body.xxx, entonces php me arroja el siguiente error:

Código:
Template->loadfile(): No file specified for handle body.jnt

En resumen lo que quiero es hacer una paginas con plantillas y que php me lea las {varibles} en un archivo html.

PD: Tiene que ser usando un bucle para las consultas

¿Alguien me puede ayudar?

Gracias.


En línea

Athagan

Desconectado Desconectado

Mensajes: 75


Ver Perfil
Re: [PHP] - Leer las {} de html, creacion de Templates tipo phpbb
« Respuesta #1 en: 24 Septiembre 2006, 20:58 pm »

No se si te servirá, pero te dejo un tutorial de PHP donde se incluye como hacer webs con "plantillas" -> http://www.luminous.com.ar/wiki/index.php/Reemplazo_de_tags_del_template .
Saludos.


En línea

Overlord

Desconectado Desconectado

Mensajes: 28



Ver Perfil
Re: [PHP] - Leer las {} de html, creacion de Templates tipo phpbb
« Respuesta #2 en: 24 Septiembre 2006, 23:56 pm »

Gracias, igual ahora buscare en googl  :D

Grax
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Leer codigo HTML desde internet api Wininet
Programación C/C++
Riki_89D 2 3,596 Último mensaje 28 Mayo 2011, 22:04 pm
por kiriost
Html leer datos
Desarrollo Web
DameBanda 5 4,830 Último mensaje 16 Noviembre 2011, 16:58 pm
por RyogiShiki
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines