![]() |
![]() |
![]()
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] |
|
|
![]() ![]() |
![]() |
Aktualny czas: 5.10.2025 - 02:48 |