Underc0de

Programación Web => Back-end => Mensaje iniciado por: fleshworm en Abril 03, 2016, 05:36:45 PM

Título: Php template engine class for PHP 5++
Publicado por: fleshworm en Abril 03, 2016, 05:36:45 PM
Saludos, ya sin mucho que hacer y merodeando bolver al entorno de diseño y desarrollo web queria aportar un objeto o clase para interfaces graficas web bastante comodo y amplio que permite:

- Features
1. Uso de plantillas externas (Templates)
2. Reemplazo de atributos (Llaves, Tags)
3. Output buffering y copuling

PHP Bootstrap Template Engine (Filename=template.class.php)
Código (php) [Seleccionar]


<?php

class template{

 var 
$tpl;

 public function 
__construct($template){
  
$this->tpl = (file_exists($template))? file_get_contents($templateFILE_USE_INCLUDE_PATH): exit("Template not found");
  return(
$this);
 }

 public function 
buffer($data){
  
ob_start();
  include(
$data);
  
$handle ob_get_contents();
  
ob_end_clean();
  return(
$handle);
 }

 public function 
parse(array $data){
  if(
count($data) >= 1){
   foreach(
$data as $key => $value){
    
$handle = (file_exists($value))? $this->buffer($value): $value;
    
$this->tpl preg_replace("~".$key$handle$this->tpl);
   }
  }
  return(
$this);
 }

 public function 
display(){
  echo(
$this->tpl);
 }

}

?>




i. Posible uso (Filename=index.php)
Creamos un archivo index.php que seria donde nuestro navegador pretenderia las primeras entradas de hyper texto de marcado en codigo (ie. HTML) e indicamos las rutinas de sanitizacion convencionales como indicar el uso de sessiones.1, el nivel de reportes de error o error_reporting.2, la zona horaria (Peninzula IBERICA del Caribe Tropical).3 y Cabezeras de contenido como typo y codificacion en este caso (ie. ISO-8859-1). Luego indicamos a nuestro codigo el proceso de un objeto o clase al invocar una instancia con el nombre de nuestra rutina (ie. new Template();). Continuamos a elaborar nuestro procedimiento al entregar valores a los metodos del objeto (ie. parse($tags = array());) donde definimos caracteristicas como nuestro logo, menu o navegacion, contenido y pie de nuestro documento. Luego revisamos nuestro contenido dirigiendonos a nuestro directorio raiz (ie. html_public/) donde deveria reproducir todos nuestros componentes teniendo nuestro lenguage de servidor disponible.

Código (php) [Seleccionar]


<?php
session_start
();
error_reporting(E_ALL);
date_default_timezone_set("America/Los Angeles");
header("Content-type: text/html; charset=ISO-8859-1;");
/* Php Template BST v2 - CC 4 - By Alias */

include_once("template.class.php");

$tpl_file_path "theme/milo_templates.html";
$tpl_tags = array("Hello World" => "<h1>Welcome</h1>");

$obj = new template($tpl_file_path);

$handle $obj->parse($tpl_tags)->display();

?>




ii. Posible uso (Filename=Sample_template.html)
Creamos un archivo o envase para nuestro hyper texto de marcado en codigo en la interface o plantilla donde se organisara todos nuestros componentes como imagenes y contenido para luego reproducir al navegador. En esta incluimos nuestras llaves o tags (ie. ~tagsHere) proximas a ser reemplasadas por nuestra rutina de manipulacion o procedimiento cryptografico.

Código (html5) [Seleccionar]


<!DOCTYPE html Public>
<html lang="En-US">
<head>
<title>~document_title</title>
<meta name="description" content="Briefing" />
<meta name="keywords" content="key, word, tags" />
<meta name="author" content="Alias" />
<meta charset="ISO-8859-1" />
<style type="text/css">
<!--
/* Cascade Style Sheet (CSS) Code ++HERE */
div#info_container{ width: 900px; height: 500px; background: yellow;}
//-->
</style>
</head>
<body>
~header_logo
~site_navigation
~content_info
~footer
</body>
</html>



NOTE: The object has been adapted to the most recent(Stable) version of PHP 5++ having outdated components(artifacts) that didnt match the resource index provided for the PHP Compiler v5 or greater (Motd by BKM).

WARNING: Preprocessor Hypertext Parser, Personal Homepage Preprocessor or !Php for its known acronym is a Industry level Metadata Compiler or Parser (Computer content generator) for developing network centric applications and websites that is known for its popularity among developers of Content Management Systems (CMS) architechture implemented website frameworks like Wordpress, Joomla or Drupal. It comprehend a rigorously diseminated analitics engine for VR ~Zend

Source: http://codewalkers.com/c/a/Display-Tutorials/Writing-a-Template-System-in-PHP/7/