Here is a very tiny program(3 files) has embedded with Smarty template engine.
Anyone knows how to remove Smarty completely?
I konw the procedure to remove Smarty but failed to rewrite the code into pure PHP.
Complete source files as in attachment.

CLICK HERE!!~~~ http://www6.mimima.com/link.php?ref=FGHkNoDtmB

*****************index.php
<?php
require("comm/Smarty.class.php");
require_once("get_data.php");
require_once("books.php");

$book = new bo_books();
$book->apply_discount();

$smarty = new Smarty; 
$smarty->assign("book",$book);
$smarty->display('index.tpl');
?>




****************get_data.php
<?php

class books {

    //public
    public $title = array(); 
    public $image = array(); 
    public $author = array(); 
    public $description = array(); 
    public $year = array ();
    public $price = array(); 

    // private 
    private $filename = "data.txt";

    //class constructor
    function __construct() {

     //get the lines as an array

      $i=-1;
      $lines = file($this->filename);

    // strip "\n" at the end of each array
    // get each variable in an array

      foreach ( $lines as $line) {

        if (strlen($line) > 2) {

        $line = rtrim($line);

        list($what, $content) = explode("=> ", $line."=> => => ");

        if ($what == "Title") {
            $i++;
            $this->title[$i]=$content;
            } elseif ($what == "Image") {
            $this->image[$i]=$content;
            } elseif ($what == "Author") {
            $this->author[$i]=$content;
            } elseif ($what == "Description") {
            $this->description[$i]=$content;
            } elseif ($what == "Year") {
            $this->year[$i]=$content;
            } elseif ($what == "Price") {
            $this->price[$i]=$content;
            };
        };
      };

    } // end constructor

} // end GetData

?>



*************books.php
<?php
class bo_books {

    //public
    public $title = array(); 
    public $image = array(); 
    public $author = array(); 
    public $description = array(); 
    public $year = array ();
    public $price = array(); 
    public $discount = array();
    public $discounted = array();

    //private 
    protected $DataObject;

    function __construct() {
      $this->DataObject = new books();
    }

    public function apply_discount() {

      $this->title = $this->DataObject->title;
      $this->image = $this->DataObject->image;
      $this->author = $this->DataObject->author;
      $this->description = $this->DataObject->description;
      $this->year = $this->DataObject->year; 
      $this->price = $this->DataObject->price;

      $j = 0;  

      foreach($this->year as $year) {

        if ($this->year[$j] == '2004')
            $this->discount[$j] = '20';
          elseif ($this->year[$j] == '2005')
            $this->discount[$j] = '10';

        $this->discounted[$j] = intval($this->price[$j] * (100 - $this->discount[$j])  ) / 100 ; 
        $j++;

      };
    } // end function apply_discount()
} // end class bo_books
?>



**********data.txt

Title=> Building Websites with VB.NET and DotNetNuke 3.0
Image=> 1904811272.jpg
Author=> Daniel N. Egan 
Description=> A practical guide to creating and maintaining your own website with DotNetNuke, the free, open source evolution of Microsoft's IBuySpy Portal 
Year=> 2005
Price=> 39.99

Title=> SSL VPN : Understanding, evaluating and planning secure, web-based remote access
Image=> 1904811078.jpg
Author=> Joseph Steinberg, Tim Speed, Simon Jenner  
Description=> A comprehensive overview of SSL VPN technologies and design strategies 
Year=> 2005
Price=> 49.99

Title=> Windows Server 2003 Active Directory Design and Implementation=> Creating, Migrating, and Merging Networks
Image=> 1904811086.jpg
Author=> John Savill
Description=> A unique, scenario-based approach to selecting and implementing the best Active Directory design for your environment 
Year=> 2005
Price=> 59.99

Title=> Building Websites with the ASP.NET Community Starter Kit
Image=> 1904811000.jpg
Author=> Cristian Darie, K. Scott Allen

Description=> A comprehensive guide to understanding, implementing, and extending the powerful and freely available application from Microsoft
Year=> 2004
Price=> 44.99
Member Avatar for LastMitch

@dansonyun

Anyone knows how to remove Smarty completely?
I konw the procedure to remove Smarty but failed to rewrite the code into pure PHP.

I'm a bit confused with what you are asking. You want to remove Smarty but you know how to do that but don't know how to write pure PHP? Since you know PHP than there's shouldn't be any issue.

There's one more document in the Smarty template "index.tpl" contains html.
The code between " {section} {/section} " must transform to pure PHP. I'm stuck right here. I must made some mistakes but just can't figure it out...... You know~~

Danson

index.tpl
<html>
<head> <title> Site Architecture Example </title> 
</head>
<body>

<table border="0" width="100%">
 <tr>
   <td align="left">
     <a href="http://www.packtpub.com">
      <img src="./images/PacktLogoSmall.png" border="0">
     </a>
     <img src="./images/focused.gif">
   </td>
   <td>
   <h1> Chapter 2 Example </h1>
   </td>
 </tr>
</table> 

<br> 
Here are the books in a two-column table : 
<br> <br>

<table border="1" width="100%">







{section name=tbl loop=$book->title}

 {if %tbl.index% is not odd}

 <tr>
 {/if}

 <td align="left">
  <table>
   <tr>
    <td> 
      <img src="./images/{$book->image[tbl]}" width="220">
    </td>

    <td valign="top">
      <font size=+1><b> {$book->title[tbl]} </b></font><br> 
      <font size=-1 color=blue><b>  {$book->author[tbl]} </b></font><br>
      {$book->description[tbl]} <br>
      Year: {$book->year[tbl]} <br>
      <font size=-1>Cover Price: <s>${$book->price[tbl]}</s></font> <br>
      Our Price: ${$book->discounted[tbl]} 
      <font color=red> save {$book->discount[tbl]} % </font>
    </td>
   </tr>
  </table>
 </td> 

 {if %tbl.index% is odd}

 </tr>
 {/if}

{/section}





</table></body></html>
Member Avatar for LastMitch

@dansonyun

The code between " {section} {/section} " must transform to pure PHP. I'm stuck right here. I must made some mistakes but just can't figure it out...... You know~~

I feel you know how to do this. I used Smarty too. It's just that I'm feeling that you don't want to take time doing this? I know there's more than 1 file needs to change in order for this work. That I know for sure! So I know you know how to do this. Show some effort.

commented: To Rectify what some retard did to LastMitch +0

I'll give you a hint, the classes are making it more difficult, you don't need them. Adapt the loop that reads the data file to output whats in the section in the template file.

In fact, I know nothing about Smarty and I always thought it's something like a clothing. You may just put it on and off.
Never thought it transplants that deep into the source code that seems you need a surgical operation to remove it.

It's not motivated at all if the only reason for you to learn a Language just to remove it, right ?!

I need to do this in a much bigger project. Well~~ ok!! Let's learn some Tasty Smarty.
Thanks for all your reply~

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.