Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Converting php-website into a smarty-website

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Mon Jun 16, 2003 9:09 am    Post subject: Converting php-website into a smarty-website Reply with quote

Hello,

i want to use my website "http://www.tmb-clan.net" in with smarty.

So i need a little bit help there because my english is very bad.
Is there anywhere a german help-forum for me ?

I tried so...

[php:1:263f4f8367]<?php
//home.php

define('SMARTY_DIR', 'G:/ORGDV/BLUBB/websites/test/smarty/');
require (SMARTY_DIR.'Smarty.class.php');

$smarty = new Smarty;

$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));

$smarty->display('header.tpl');

$smarty->display('box_menu.tpl');
$smarty->display('box_icq.tpl');
$smarty->display('box_spieler.tpl');
$smarty->display('box_counter.tpl');
$smarty->display('box_info.tpl');

$smarty->display('home.tpl');

$smarty->display('box_termin.tpl');
$smarty->display('box_partner.tpl');
$smarty->display('box_links.tpl');

$smarty->display('werbung_breit.tpl');
$smarty->display('copyright.tpl');
?>[/php:1:263f4f8367]
That works fine... but i want to change somethings on the new website.
So i need a system imlement the right sites...
like this... (http://www.tmb-clan.net/index.php?site=home)
[php:1:263f4f8367]<?php
//file index.php

define('SMARTY_DIR', 'G:/ORGDV/BLUBB/websites/test/smarty/');
require (SMARTY_DIR.'Smarty.class.php');

if (!isset($site))
$site=index;

$smarty = new Smarty;
$smarty->display($site.'.tpl');
?>[/php:1:263f4f8367]
Confused how can i implement it right ?
i want that all sites can use individual boxes left and right.
In the boxes are always the same funktions to display somethings.

So how can i use all right together ?
I need a little script to beginn this converting right.

PS: Sorry for English Errors Smile


Last edited by Doomer on Mon Jun 16, 2003 12:40 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jun 16, 2003 9:48 am    Post subject: Reply with quote

Hello Doomer.

No need to apologize--your English is fine! (better than my German!!) To start, try something like this--

Create a new master template that includes all of the templates you want to be on your main page:

main.tpl
Code:
{include file="header.tpl"}
{include file="box_menu.tpl"}
{include file="box_cq.tpl"}
{include file="box_spieler.tpl"}
{include file="box_counter.tpl"}
{include file="box_info.tpl"}

{include file=$content_template}

{include file="box_termin.tpl"}
{include file="box_partner.tpl"}
{include file="box_links.tpl"}


Your PHP would look like this:
Code:
$smarty = new Smarty;
$smarty->assign('content_template', $site.'.tpl');
$smarty->display('main.tpl');


The template code:
Code:
{include file=$content_template}


dynamically includes (same as $smarty->display) the file that is named in the template variable $content_template, which is set in your PHP code.

Hope that helps!
Back to top
View user's profile Send private message
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Mon Jun 16, 2003 3:44 pm    Post subject: That works fine :) Reply with quote

Very Happy ok, i used the following code
[php:1:617323fb76]<?php
//index.php

define('SMARTY_DIR', 'G:/ORGDV/BLUBB/websites/tmb/smarty/');
require (SMARTY_DIR.'Smarty.class.php');

if (!isset($site))
{ $site=index; }

$smarty = new Smarty;
$smarty->assign('inhalts_template', $site.'.tpl');
$smarty->display('site_'.$site.'.tpl');
?>[/php:1:617323fb76]
Code:
{*site_home.tpl*}
{include file="header.tpl"}

{include file="box_menu.tpl"}
{include file="box_cq.tpl"}
{include file="box_spieler.tpl"}
{include file="box_counter.tpl"}
{include file="box_info.tpl"}

{include file=$inhalts_template}

{include file="box_termin.tpl"}
{include file="box_partner.tpl"}
{include file="box_links.tpl"}

{include file="'werbung_breit.tpl"}
{include file="copyright.tpl"}


Code:
{*home.tpl*}
bla bla bla


now letīs get to the fine tuning Smile
letīs beginn with the "header.tpl"

THE OLD PHP GENERATED HTML CODE
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
   <!--<meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)">-->
   <title>[ T H E   M A D   B O Y S ] - HOME</title>
   <LINK href="http://www.tmb-clan.net/php/cfg/index.css" rel=STYLESHEET type="text/css">
   <LINK REL="SHORTCUT ICON" HREF="http://www.tmb-clan.net/grafik/rest/favicon.ico">

   <script language="JavaScript" src="http://www.tmb-clan.net/java/java.js" type="text/javascript">

   </head>
<body bgcolor="#252645" text="#ffffff" link="red" vlink="0000aa" alink="ff0000" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" ONLOAD="start()">

<script language="JavaScript" src="http://www.tmb-clan.net/java/logo.js" type="text/javascript"></script>

<!-- <script language="JavaScript" src="http://www.tmb-clan.net/java/snow.js" type="text/javascript"></script> -->

<table cellpadding="0" cellspacing="5" width="100%"><tr valign="top" align="center">
<td width="1%">


Bevore i post the new code, i try to explain what must be insert.
In the index.php i includ also the config.inc.php that are also includes
2-3 files (constants.inc.php, functions.inc.php, variablen.inc.php).
In the constats are "website", colors of the website (backround, lines e.g.). website e.g. is www.tmb-clan.net

How must it look in the "header.tpl" ?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
   <!--<meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)">-->
   <title>[ T H E   M A D   B O Y S ] - {$sitename}</title>
   <LINK href="http://{$website}/php/cfg/index.css" rel=STYLESHEET type="text/css">
   <LINK REL="SHORTCUT ICON" HREF="http://{$website}/grafik/rest/favicon.ico">

   <script language="JavaScript" src="http://www.tmb-clan.net/java/java.js" type="text/javascript">

   </head>
<body bgcolor="{$site_bg}" text="#ffffff" link="red" vlink="0000aa" alink="ff0000" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" ONLOAD="start()">


<!-- <script language="JavaScript" src="http://www.tmb-clan.net/java/snow.js" type="text/javascript"></script>

^shoud be loaded from the 01.12.xx - 01.02.xx(+1) Snow like
 -->

<table cellpadding="0" cellspacing="5" width="100%"><tr valign="top" align="center">
<td width="1%"


k, where must i write the "$smarty->assign('website', 'WEBSITE');" text ?
or the "sitename" that differs from site to site (sitename here should be "H O M E").

Puhhh many text to read... thanks for reading...
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jun 16, 2003 11:50 pm    Post subject: Reply with quote

As long as you do your assign prior to calling Smarty, you should be okay.

So as long as your included php files have access to your $smarty variable, you are fine--they can do the includes right within the include file.

You can also use config files (they are described in the manual) so that you can store configuration values (such as site name, colors, etc.)

For example:

my.conf
Code:
website = "WEBSITE"
bgcolor = "Azure"


my.tpl
{config_load file="my.conf"}

Code:
<div style="background-color: {#bgcolor#}">
    This website is {#website#}.
</div>
Back to top
View user's profile Send private message
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Tue Jun 17, 2003 2:30 pm    Post subject: Reply with quote

Ok seems to be good.

There aree many writing and testing jobs...

But it works together...

Thanks, i meet u here when i get bigger problems.

Very Happy Doomer
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Sat Jun 21, 2003 5:19 pm    Post subject: Back from programming Reply with quote

So, iīm back Smile

I insert any Boxes so that the News site is correctly displayed.
Next i want implement a "LOGIN" with Mysql.
But before i can do this i need the function "include_php".
It seems that i need to config any till it works...

ok letīs look @ my files:

[php:1:e2bd4e10e6]<?php
//index.php
require("D:/upload/Jens/websites/tmb-clan/configs/config.inc.php");

$smarty = new Smarty;

if (!isset($site) || $site=="")
{ $site="index"; }

if (siteda($site) == "jub") {
$fehler = '<i id="grun1">SEITE GEFUNDEN</i><br>Keine Fehler auf "'.$site.'".'; }

if (siteda($site) == "nein") {
$fehler = '<i id="rot1">Die Datei "site_'.$site.'.tpl" f&r<br>die Seite "'.$site.'" existiert nicht</i><br>Netter Versuch...<br>';
$site = "index"; }



$smarty->assign('fehlerausgabe', $fehler);

$smarty->assign('inhalts_template', $site.'.tpl');
$smarty->display('site_'.$site.'.tpl');
?>[/php:1:e2bd4e10e6]

site_news.tpl
Code:
{config_load file="smarty.consts.conf" section="news" scope="parent"}   
{include file="header.tpl"}

{include file="box_menu.tpl"}
{include file="box_partner.tpl"}
{include file="box_counter.tpl"}
{include file="box_info.tpl"}
{include file="box_werbung_kurz.tpl"}

{include file=$inhalts_template}

{include file="box_termine.tpl"}
{include file="box_picof.tpl"}
{include file="box_fehler.tpl"}
{include file="box_toplinks.tpl"}
{include file="box_werbung_lang.tpl"}

{include file="box_werbung_breit.tpl"}
{include file="box_member_menu.tpl"}
{include file="copyright.tpl"}


Now lets see in the box_member_menu.tpl
Code:
{*include_php file="D:/upload/Jens/websites/tmb-clan/configs/login.php"*}


<!-- box_member_menu.tpl BREIT ANFANG -->

  <tr>
    <td colspan="3" width="100%">

<a href="http://{#website#}/?site=termine&action=edit" title="Termine editieren !">Termine</a> |
<a href="http://{#website#}/?site=termine&action=edit" title="Termine editieren !">Termine</a> |
<a href="http://{#website#}/?site=termine&action=edit" title="Termine editieren !">Termine</a> |
<a href="http://{#website#}/?site=termine&action=edit" title="Termine editieren !">Termine</a> |
{include_php file="../configs/login.php"}

    </td>
  </tr>

<!-- box_member_menu.tpl ENDE -->


With the Path "../configs/login.php" it seems that the file would be found...
but:
Quote:
Warning: Smarty error: 'file: ../configs/login.php' is not readable in D:\upload\Jens\websites\tmb-clan\smarty\Smarty.class.php on line 999

Warning: _smarty_include_php(): Failed opening '' for inclusion (include_path='.;c:\php4\pear') in D:\upload\Jens\websites\tmb-clan\smarty\Smarty.class.php on line 1777


Ok, thats the Problem... now itīs your turn Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jun 22, 2003 12:00 am    Post subject: Reply with quote

Hi again!

I refer you to the manual: GERMAN ENGLISH

Quote:
In German
include_php-Tags werden verwendet, um PHP-Skripte in Ihre Templates einzubinden. Falls 'Sicherheit' aktiviert ist, muss das einzubindende Skript im '$trusted_dir' Pfad liegen. 'include_php' muss das Attribut 'file' übergeben werden, das den Pfad - entweder relativ zu '$trusted_dir' oder absolut - zum Skript enthält.

now in english for those who are following the thread:
include_php tags are used to include a php script in your template. If security is enabled, then the php script must be located in the $trusted_dir path. The include_php tag must have the attribute "file", which contains the path to the included php file, either relative to $trusted_dir, or an absolute path.


Either you have to set the $trusted_dir (to an absolute path, please) or you must provide an absolute path to your included PHP file. Otherwise, the request fails -- as you have discovered!

HTH
Back to top
View user's profile Send private message
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Sun Jun 22, 2003 10:27 am    Post subject: Reply with quote

Laughing

jub i read this, but i do not understand what it mean ?!
Quote:
If security is enabled, then the php script must be located in the $trusted_dir path.


What for security ?
Where can i finde the $trusted_dir variable ?
how works it together ?

I have downloaded the manual since the beginning... and i read it.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jun 23, 2003 5:08 am    Post subject: Reply with quote

Hi Doomer. This might be my last post before I go on holiday, so good-luck to you!

1) security is used to ensure that only a limited set of functionality is available to the template users.

2) you set the trusted directory like any of the other directories that Smarty needs: ie: $smarty->trusted_dir = '/path/to/trusted';

3) you can avoid having to do #2 by NOT using relative paths in your php_include. If you DO use relative paths for php_include, they are relative to the trusted_dir, NOT your web site (unless you set your trusted_dir to the root of your site, of course)

I hope that is helpful Smile

ps. I wasn't suggesting that you haven't read the manual--I was simply trying to show you were the relevant material was located. I think the manual is excellent but it could probably be expanded a bit more.
Back to top
View user's profile Send private message
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Tue Jun 24, 2003 1:01 pm    Post subject: Reply with quote

I hope u had nice hollidays...


Ok, i will try to set the trusted Dir like #2.

Now i have another Probelem Smile...

I loaded the site up to http://wwww.tmb-clan.net to try it.

My code works, but smarty has a problem to create the template_c files.

Bevore u say chmod.... i set it to 777 on cache and template_c .

Quote:
Warning: Smarty error: problem writing temporary file 'templates_c/%%602/%%602863288/3ef84b8d766bc' in /www/htdocs/wwww/smarty/Smarty.class.php on line 1042

Warning: unable to create file templates_c/%%602/%%602863288/site_index.tpl.php because Datei oder Verzeichnis nicht gefunden in /www/htdocs/wwww/smarty/Smarty.class.php on line 1575

Warning: open_basedir restriction in effect. File is in wrong directory in /www/htdocs/wwww/smarty/Smarty.class.php on line 1158

Warning: Failed opening 'templates_c/%%602/%%602863288/site_index.tpl.php' for inclusion (include_path='.:..') in /www/htdocs/wwww/smarty/Smarty.class.php on line 1158
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Tue Jun 24, 2003 1:07 pm    Post subject: lol little error Reply with quote

forgotten to set

[php:1:995c0800ae]<?php
$smarty->template_dir = '/www/htdocs/wwww/templates/';
$smarty->compile_dir = '/www/htdocs/wwww/templates_c/';
$smarty->config_dir = '/www/htdocs/wwww/configs/';
$smarty->cache_dir = '/www/htdocs/wwww/cache/';
?>[/php:1:995c0800ae]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Doomer
Smarty Rookie


Joined: 16 Jun 2003
Posts: 12
Location: Germany/Bavaria/BT

PostPosted: Sat Jun 28, 2003 1:47 pm    Post subject: next problem Reply with quote

Hi, neverending problems... Confused

to use include_php i added these lines
[php:1:69e7b8db10]<?php
$smarty->template_dir = ABPFAD.'templates/';
$smarty->compile_dir = ABPFAD.'templates_c/';
$smarty->config_dir = ABPFAD.'configs/';
$smarty->cache_dir = ABPFAD.'cache/';
$smarty->trusted_dir = ABPFAD;
?>[/php:1:69e7b8db10]

ande get
Quote:
Warning: Smarty error: 'file: cofigs/login.php' is not readable in D:\upload\Jens\websites\tmb-clan\smarty\Smarty.class.php on line 999

Warning: _smarty_include_php(): Failed opening '' for inclusion (include_path='.;c:\php4\pear') in D:\upload\Jens\websites\tmb-clan\smarty\Smarty.class.php on line 1777

Fatal error: Call to undefined function: logincheck() in D:\upload\Jens\websites\tmb-clan\templates_c\%%-17\%%-1700519665\box_member.tpl.php on line 7


I think that the problem is that the Apache canīt open the file, but i donīt know why ?!

Ok, letīs also look another problem:

The Boxex are convertet and any scripts like the banners working fine.
Now i want to go to integrate the LOGIN-SYSTEM.
I added in the MySQL Database a Table:
Code:
CREATE TABLE `tmb_members` (
  `id` tinyint(2) unsigned NOT NULL auto_increment,
  `nick` varchar(20) NOT NULL default '',
  `pass` varchar(32) NOT NULL default '',
  `rechte` int(10) unsigned NOT NULL default '1',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;

#
# Daten für Tabelle `tmb_members`
#

INSERT INTO `tmb_members` (`id`, `nick`, `pass`, `rechte`) VALUES (1, 'Doomer', 'c8e15dcc73ea5d9c641ccd3ed9aefc55', 16383),
(2, 'Terminator', '9a85db6a0e0003fe1293737c39acc824', 1),
(3, 'Zerocool', 'd947c85f4f06eb2942999f09396f31b9', 1),
(4, 'Tester', '179ad45c6ce2cb97cf1029e212046e81', 1);


i added a template box : box_member.tpl (for the status and look sites like intern news, intern polls, next wars ...) and box_member_menu.tpl
(for edit any, there should be links for edit news, edit wars... if the member has the rights for that.
The RIGHTS i added in the constant.inc.php
[php:1:69e7b8db10]<?php
define ("IS_MEMBER", (int)1);
define ("ACCESS_NEWS_ALL", (int)2);
define ("ACCESS_NEWS_OWN", (int)4);
define ("ACCESS_UPLOAD", (int)Cool;
define ("ACCESS_DOWNLOAD", (int)16);
define ("ACCESS_MEMBERS", (int)32);
define ("ACCESS_POLLS", (int)64);
define ("ACCESS_WARS", (int)128);
define ("ACCESS_LINKS", (int)256);
define ("ACCESS_TERMINE", (int)512);
define ("ACCESS_KASSE", (int)1024);
define ("ACCESS_SCREENSHOTS", (int)2048);

define ("ACCESS_ADMIN", (int)4096);
define ("ACCESS_OPTIONS", (int)8192);
?>[/php:1:69e7b8db10]
it is in the mysql table integratet:
(`id`, `nick`, `pass`, `rechte`)

Which is the best system to show the boxex if the member is logged in.
How can i integratet these check best.

i tried this, but iīm not sure if its the best way:
box_member.tpl
Code:
{include_php file="cofigs/login.php"}

{if logincheck("status") == "ok"}

<table cellpadding=0 cellspacing=1 bgcolor="{#f_rahmen#}" width="160">
  <tr align=center>
    <td bgcolor="{#f_kopf#}" nowrap><i id=s10w>& Login Status &</td></tr>

  <tr align=center><td bgcolor="{#f_body#}"><br><i id=s10w>

Erfolgreich eingelogt
 
    <br /><br /></td>
  </tr>
</table>

<!-- box_member.tpl ENDE -->

{#abstandshalter#}



{elseif logincheck("status") == "ne"}

{else}

ALLGEMEINER FEHLER
IN DER "login.php".

{/if}


The login.php function logincheck($logedin) should be check if the user is logged in. If heīs logged in 'return "OK";' else 'return "ne";'
The rest shoult be make the box_member template.
if it is OK, the templatet shows the box, else no memberbox is displayed.

Thanks for reading this long text.
Doomer

PREVIEW: http://wwww.tmb-clan.net
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP