Viewed   165 times

Someone wants me to redesign a site run in PHP (VideoCMS). But when I asked him to send me the source he has given me *.tpl files instead of *.php. There is some code inside them:

{include file='header.tpl' p="article"}

<br />
<table width="886" border="0" cellspacing="0" cellpadding="0">
    <td width="150" valign="top">
    <div id="reg_box">
    <h3 class="captions">{$lang.articles}</h3>
        <div id="list_cats">
    <br />
    <div id="reg_box">
    <h3 class="captions">{$lang.members}</h3>
    {if $logged_in == '1'}
    {include file='loggedin_body.tpl'}
    {include file='login_body.tpl'}


{include file='header.tpl' p="index"}

{php} $_SESSION['isFair'] = "Yes"; {/php}

What's the interpreter of the code? How can I redesign this site?



That looks like Smarty to me. Smarty is a template parser written in PHP.

You can read up on how to use Smarty in the documentation.

If you can't get access to the CMS's source: To view the templates in your browser, just look at what variables Smarty is using and create a PHP file that populates the used variables with dummy data.

If I remember correctly, once Smarty is set up, you can use:

$smarty->assign('nameofvar', 'some data');

to set the variables.

Friday, September 16, 2022

I don't if you want your webservice to upload/download files. Anyway you can use curl( ) to upload/download file from other webserver.

To get some file uploaded to the webservice from the user it's pretty much the same as gettings it from a form, please use the superglobal variable:$_FILES (doc) to get upload files.

for uploading from php to a webservice

$fullflepath = 'C:temptest.jpg';
$upload_url = '';
$params = array(

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);

the webservice to get a file

$uploads_dir = '/uploads';
foreach ($_FILES["photo"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["photo"]["tmp_name"][$key];
        $name = $_FILES["photo"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");

PS: sorry for some reason doesn't like to make a link of $_FILES ... so I have linked the superglobals page instead

Monday, November 14, 2022
  • Corrected your html code so that you have a placeholder for the number of votes.

  • Corrected the Ajax call so that it passes the same parameters as per the hrefs in your initial upvote anchor.

  • Fixed various syntax errors in the ajax call

Html Code

       <span class="votenumbers">{$vote}</span> 
       <a id="upvote_{$qid}" class="q_upvote" href="#"><i class="icon-thumbs-up"></i></a> 
       <a href="vote.php?q_vote=vote_down&question_id={$qid}"><i class="icon-thumbs-down</i</a>

jQuery Code

        var vote = "vote_up",
            question_id ='_')[1], 
            votedata = "q_vote="+vote+"&question_id="+question_id;
                type: 'POST',
                url: 'vote.php',
                data: votedata,
                success: function(vote_msg){
                   if(vote_msg== 'ok')
                       //show the new vote
                        //show notification
Friday, August 19, 2022

declare, before include the template:

{assign var="link_truncate" value="30"}
Friday, October 28, 2022

There are lots of different 'pattern' families out there, but taking your question its broadest terms...

I'd recommend:

  • Jim Coplien's Organisational Patterns
  • The Hillside Group wiki
  • Kevlin Henney's site has plenty of excellent links & papers

Offline (my favourites):

  • Fowler's Patterns of Enterprise Architecture
  • Feather's Working Effectively with Legacy Code

Offline (popular):

  • GoF Design Patterns
  • Fowler's Refactoring: Improving the Design of Existing Code
Wednesday, September 7, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :