Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 156 Pomógł: 15 Dołączył: 13.09.2003 Skąd: London Ostrzeżenie: (0%)
|
Mam taka funkcje:
[php:1:29914852a5]<?php function gettemplate($templatename, $gethtmlcomments = 1) { if(file_exists("templates/$templatename.htm")){ $fd = fopen ("templates/$templatename.htm", "r"); $template_file = fread ($fd, filesize ("templates/$templatename.htm")); $template = preg_replace_callback('/{_([^ ]+)}/U', create_function('$matchs', 'return $GLOBALS["lang_$matchs[1]"];'), $template_file); $template = preg_replace_callback('/{([^ ]+)}/U', create_function('$matches', 'return $GLOBALS[$matches[1]];'), $template); if ($options['addtemplatename'] = 1 AND $gethtmlcomments = 1) { $template = "n<!-- POCZATEK SZABLONU: $templatename -->n$templaten<!-- KONIEC SZABLONU: $templatename -->n"; } fclose($fd); return $template; } else { return "<center><font color="red">Wystapil blad krytyczny - Brak szablonu '$tplfile'. Skontaktuj sie z administratorem.</font></center>"; } } ?>[/php:1:29914852a5] Chce miec mozliwosc dodania do szablonu czegos takiego: Kod <if condition="$show"> tutaj tresc strony </if>
i jesli funkcja natrafi na taki kod zeby sprawdzila czy np. $show == 1, a jesli tak to wyswietlila kod miedzy znacznikiem <if></if>. Ma ktos pomysl jak to zrobic? (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) widze, ze chyba nikt (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) |
|
|
|
![]() |
Post
#2
|
|
|
Grupa: Zarejestrowani Postów: 156 Pomógł: 15 Dołączył: 13.09.2003 Skąd: London Ostrzeżenie: (0%)
|
Dziala mi juz sprawdzanie, ale zrobilem troche inaczej. Znaczniki musza wygladac tak:
[xml:1:0d9ab2f477]<if condition="($cos['cos'] == 1)">COS<else />NIE COS</if condition="($cos['cos'] == 1)">[/xml:1:0d9ab2f477] Ok, ostatnia wersja mojego systemu szablonow wyglada tak: [php:1:0d9ab2f477]<?php // ##################### Start gettemplate ########################### function gettemplate($templatename, $print = 0, $gethtmlcomments = 1) { global $options, $show; if(file_exists("templates/$templatename.htm")) { $fd = fopen ("templates/$templatename.htm", "r"); $template_file = fread ($fd, filesize ("templates/$templatename.htm")); $template = preg_replace_callback('/{_([^ ]+)}/U', create_function('$matchs', 'return $GLOBALS["lang_$matchs[1]"];'), $template_file); $template = str_replace('{script}', SCRIPT.'.php', $template); $template = preg_replace_callback('/{([^ ]+)}/U', create_function('$matches', 'return $GLOBALS[$matches[1]];'), $template); if (substr_count($template,'</if') >= 1) { $template = template_conditionals($template); } if ($options['addtemplatename'] == 1 AND $gethtmlcomments == 1) { $template = "rn<!-- BEGIN TEMPLATE: " . $templatename . " -->n" . $template . "n<!-- END TEMPLATE: " . $templatename . " -->rn"; } if ($options['templatecompressor'] == 1) { //$page_byte = strlen($template); $template = preg_replace ("/(>)(s*)(rn)*(s*)(<)/", '15', $template); //$pagenew_byte=strlen($template); //$page_kilobyte=number_format(($page_byte/1024),2); // echo strpos($vartext,">rn<");exit; //$pagenew_kilobyte=number_format(($pagenew_byte/1024),2); //$pagesaved_byte=$page_byte-$pagenew_byte; //$pagesaved_kilobyte=number_format((($pagesaved_byte)/1024),2); //$pagesaved_perc=number_format(((100*$pagesaved_byte)/$page_byte),2); //$output .= "<br> [Prawdziwa "waga": " . $page_kilobyte . " Kb. skompresowana do <b>" . $pagenew_kilobyte . "</b> Kb. oszczedzajac <b>" . $pagesaved_kilobyte . "</b> Kb. (" . $pagesaved_perc% . ")] "; } fclose($fd); if ($print == 1) { echo $template; } else { return $template; } } else { $errormsg = "<center><font color='red'>Wystapil blad krytyczny - Brak szablonu " . $templatename . ".<br>Skontaktuj sie z administratorem.</font></center>"; if ($print == 1) { echo $errormsg; } else { return $errormsg; } } } // ##################### Start template_conditionals ########################### function template_conditionals($template) { @extract($GLOBALS, EXTR_SKIP); while (preg_match('/<if condition="(.*)">(.*)</if condition="1">/siU',$template,$condition)) { if (substr_count($condition[2],'<else />') >= 1) { preg_match('/<if condition="(.*)">(.*)<else />(.*)</if condition="1">/siU',$condition[0],$condition_else); $condition_true = $condition_else[2]; $condition_false = $condition_else[3]; } else { $condition_true = $condition[2]; $condition_false = ''; } @eval ('if ('.stripslashes($condition[1]).') { $eval_deger= "1"; } else { $eval_deger= "0"; }'); if ($eval_deger==1) { $template=str_replace($condition[0], $condition_true, $template); } else { $template=str_replace($condition[0], $condition_false, $template); } } return $template; } ?>[/php:1:0d9ab2f477] |
|
|
|
gulldarek Sprawdzanie w szablonach (<if></if>) 12.01.2004, 22:51:29
gulldarek Sorry za double posta ale ten temat chyba za duzo ... 13.01.2004, 13:15:57
scanner Musiałbyś sprawdzac tempklate pod względem istanie... 13.01.2004, 13:23:59
gulldarek cos takiego?
<?php
$if_lookfor = '<if cond... 13.01.2004, 13:32:24
scanner nie mam mołżiwości chwilowo sprawdzić, bo mi phpJu... 13.01.2004, 13:39:30
BzikOS Hmm czy ja czegoś nie zrozumiałem, czy Wy cos mies... 13.01.2004, 13:51:44
gulldarek Ale ja chce miec mozliwosc wstawienia do szablonu ... 13.01.2004, 13:54:09
scanner BzikOS - prawie, ale jeszcze zrób eval Kodconditio... 13.01.2004, 13:54:29
gulldarek Mam jeszcze edno pytanie:
Ten kod zwraca mi:
Kod... 13.01.2004, 14:28:40
scanner Napisałem Ci na PW, ale dodam też tutaj:
strpos() ... 13.01.2004, 14:33:43
BzikOS Kontynuując mój pomysł.. coś takiego wykombinowałe... 13.01.2004, 14:51:46
gulldarek W zasadzie to jest dobrze, ale te zmienne trzeba j... 13.01.2004, 15:04:32
BzikOS Z globalizacja to pestka:
<?php
preg_match_all... 13.01.2004, 15:17:11
gulldarek KodParse error: parse error, expecting `T_... 13.01.2004, 15:22:41
BzikOS A w szablonie masz zmienne z $ ?
<if condition... 13.01.2004, 15:27:46
gulldarek Tak mam.
Zrobilem cos takiego:
<?php
functi... 13.01.2004, 15:30:46
BzikOS 1. Coś pokopałeś.. skoro masz zmienne w tablicy su... 13.01.2004, 15:47:11
gulldarek 1. Ok twoje rozwiazanie dziala, ale zmienna musial... 13.01.2004, 16:51:35
gulldarek Jeszcze jedno
<?php
$template = preg_r... 13.01.2004, 19:52:39
BzikOS Powiem szczerze, że nie wiem :/ Męczyłem się z tym... 13.01.2004, 23:24:38
gulldarek Ok zrobiłem
<?php
$template = preg_replace(... 14.01.2004, 09:35:39
BzikOS Hahaha jasne że teraz nie będzie błędów bo nie ma ... 14.01.2004, 09:50:39
gulldarek CytatHahaha jasne że teraz nie będzie błędów bo ni... 14.01.2004, 16:47:19
BzikOS Znalazłem w końcu chwilę czasu i wymyśliłem coś ta... 16.01.2004, 19:36:12
gulldarek Ok twoje dziala dobrze, ale ja w miedzy czasie tez... 18.01.2004, 15:30:00
BzikOS CytatSa dwa ify a skrypt pewnie pomysli ze pierwsz... 18.01.2004, 17:11:35
gulldarek Oplaca, oplaca
Co do wlasnego parsera to probowa... 18.01.2004, 17:15:02
Bora hmm może warto siem tym zainteresowac żeby pozbyć ... 18.01.2004, 18:47:25
gulldarek <?php
function process_template_conditionals($t... 19.01.2004, 13:04:08
Bora Może mój template ciebie zainteresuje.
Posiada obs... 31.01.2004, 20:08:59 ![]() ![]() |
|
Aktualny czas: 25.12.2025 - 16:58 |