Jump to content

How do you know if a site is using Smarty?


Recommended Posts

Hi All

 

I have just received the source code for our site from our previous developer who we are no longer in contact with.  How do you know that the site is using Smarty?  My background is in Coldfusion so I am new to PHP.

 

The previous developer told us that the site was created using the SMARTY framework but now works as plain PHP.

 

I would appreciate it if a PHP/Smarty expert can explain the code below on what is is actually doing.  For example it mentions a index.tpl.htm what is a tpl.htm file?

 

Thanks very much in advance

 

-------------this is the index.php page ---------

<?php

 

include_once "local.cfg.php";

include_once INCLUDE_DIR."common.inc.php";

 

$userid = user_getCurrentUserID();

$f_search = g_getVar("f_search",false,"g");

 

$region = false;

 

if($userid > 0)

{

$user = user_get($userid);

$region = $user["Region"];

}

 

if($f_search["region"] && $f_search["region"] > 0 && (($f_search["region"] == 10)||($f_search["region"] == 20)||($f_search["region"] == 30)||($f_search["region"] == 40)||($f_search["region"] == 50)||($f_search["region"] == 60)||($f_search["region"] == 70)||($f_search["region"] == 80)||($f_search["region"] == 90)||($f_search["region"] == 100)||($f_search["region"] == 110)||($f_search["region"] == 120)))

{

$region = $f_search["region"];

$inTwoMonths = 60 * 60 * 24 * 60 + time();

setcookie('region', $region, $inTwoMonths);

 

}

elseif($f_search["region"] == "all")

{

$region = false;

}

 

$smarty->assign("userregion",$region);

 

$cuisine = restaurant_cuisine();

$ambience = restaurant_ambience_list();

$regionOption = restaurant_htmlRegionOptions($region);

$city = restaurant_getCity();

$most = restaurant_mostPopular($region);

 

$latestReviews = restaurant_review_getLatest_region($region);

$latestReviewsCount = restaurant_reviewCountAll($region,true);

$reviewsCount = restaurant_reviewCountAll($region,false);

 

$latest = restaurant_latest($region,10);

 

$featured = restaurant_featured($region,5);

 

// if(!$latest)

// {

// $latest = restaurant_latest(false,10);

// }

$closing = auction_closingAndNewly(true,$region);

$newly = auction_closingAndNewly(false,$region);

 

$smarty->assign("page","home");

$smarty->assign("newly",$newly);

$smarty->assign("closing",$closing);

$smarty->assign("latest",$latest);

$smarty->assign("featured",$featured);

 

$smarty->assign("latestReviews",$latestReviews);

$smarty->assign("latestReviewsCount",$latestReviewsCount);

$smarty->assign("reviewsCount",$reviewsCount);

 

$smarty->assign("most",$most);

$smarty->assign("cuisine",$cuisine);

$smarty->assign("ambience",$ambience);

$smarty->assign("region",$regionOption);

$smarty->assign("city",$city);

$smarty->assign("userid",$userid);

 

$smarty->display("index.tpl.htm");

 

?>

---------------------end snippet-------------------

Smarty is a PHP project that helps separate the PHP code from the HTML. the 'assign' statements at the bottom like this:

   $smarty->assign("most",$most);

assign values to smarty variables. then, the "index.tpl.htm" template file can use those variables. here is the documentation for smarty:

http://www.smarty.net/

Thanks for the reply.

 

So the site is using Smarty? 

 

Also with regard to the index.tpl.htm file where would be the location of this file as it is not in the same directory as the index.php file?

 

So the following line does what, assign a variable city to city? as I would have thought city would contain an actual city name?

 

Finally what was the structure of the code like, is it well coded or are there potential security/performance issues?

 

Thanks

$smarty->assign("city",$city);

So the site is using Smarty?

Yes it does. But Smarty is no longer something to install. It is just some files that need to be included.

 

Also with regard to the index.tpl.htm file where would be the location of this file as it is not in the same directory as the index.php file?

That will depend on where the template directory is. The default is a folder called 'templates' in the same directory as the script being run. You can try putting this at the end of the script and see what it says too:

echo $smarty->template_dir;

 

So the following line does what, assign a variable city to city? as I would have thought city would contain an actual city name?

It assigns the value of the PHP variable $city to the Smarty variable "city". They are two separate scopes of variables.

 

Finally what was the structure of the code like, is it well coded or are there potential security/performance issues?

It would be difficult to draw a complete conclusion on the security of the site, but it does look well formed and that the person most likely knew what they were doing

  • 2 months later...

the strangest thing about that smarty index page is that the smarty function is never called / declared

 

$smarty -> newSmarty();

 

unless it's in one of your two includes

  include_once "local.cfg.php";

  include_once INCLUDE_DIR."common.inc.php";

 

if your site is working then it's fine, but I like to know where things are originating in case something breaks so you don't have to spend hours troubleshooting something.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.