Pages

Sunday, January 15, 2012

PHP: Webpage Publisher

A webpage publishing class.
<?php

/**
 * @Class: CPublisher.class.php
 * @Author: Abhishek Kumar
**/

require_once("CTemplate.class.php");
require_once("CFile.class.php");

class CPublisher
{
 private static $oTemplate;

 public static function initialize()
 {
  self::$oTemplate = new CTemplate();
  self::$oTemplate->setTemplatePath('asset/template');
 }

 public static function Publish($iContent, $iInclude)
 {
  self::initialize();

  $Output = 
   self::$oTemplate->ModifyAndDump('Container.dt', 
    array(
    'Header'=>self::getHeader($iInclude),
    'Content'=>self::$oTemplate->ModifyAndDump('ContainerBody.dt', 
      array(
      'Header'=>self::$oTemplate->Dump('Header.st'), 
      'Content'=>$iContent,
      'Footer'=>self::$oTemplate->Dump('Footer.st')
      )
     ),
    )
   );

  return $Output;
 }

 private static function getHeader($iInclude)
 {
  $Output = '';
  if($iInclude != null)
  {
   $oFile = new CFile();
   for($i=0; $igetFileExtension($iInclude[$i]))
    {
     case '.js':  $template = 'JavaScript.dt'; break;
     case '.css': $template = 'StyleSheet.dt'; break;
    }
    $Output .= self::$oTemplate->ModifyAndDump($template, array('FileName'=>$iInclude[$i]));
   }
  }
  return $Output;
 }

 public static function PublishWithoutFooter($iContent, $iInclude)
 {
  self::initialize();

  $Output = 
   self::$oTemplate->ModifyAndDump('Container.dt', 
    array(
    'Header'=>self::getHeader($iInclude),
    'Content'=>self::$oTemplate->ModifyAndDump('ContainerBody.dt', 
      array(
      'Header'=>self::$oTemplate->Dump('Header.st'), 
      'Content'=>$iContent,
      'Footer'=>''
      )
     ),
    )
   );

  return $Output;
 }

}

?>
Example 1:
<?php
// Template#1
require_once('_config.php');

require_once('engine/CPublisher.class.php');
require_once('engine/CTemplate.class.php');

$oTemplate = new CTemplate();
$oTemplate->setTemplatePath('asset/template');

$Output = $oTemplate->ModifyAndDump('foExit.dt', 
 array(
  'ProceedAfterLogout'=>'Login.php'
 ));

echo CPublisher::Publish($Output, array('HojaDeEstilo.css'));

?>
Example 2:
<?php
// Template#2
require_once('_config.php');

require_once('engine/CPublisher.class.php');
require_once('engine/CTemplate.class.php');

$oTemplate = new CTemplate();
$oTemplate->setTemplatePath('asset/content');

$Output = $oTemplate->Dump('CertifiedSeller.st');

echo CPublisher::Publish($Output, array('HojaDeEstilo.css'));

?>

No comments:

Post a Comment