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%)
|
[php:1:8770f4a600]<?php
function process_template_conditionals($template, $haltonerror = true) { global $vb script:history.back(1)')); print_cp_footer(); } } } if ($template_cond[$condition_end + 2] != '>') { // the > doesn't come right after the condition must be malformed $if_end_location = $if_location + 1; continue; } // look for recursive case in the if block -- need to do this so the correct </if> is looked at $recursive_if_loc = $if_location; while (1) { $recursive_if_loc = strpos($template_cond, $if_lookfor, $recursive_if_loc + 1); // find an if case if ($recursive_if_loc === false OR $recursive_if_loc >= $if_end_location) { //not found or out of bounds break; } // the bump first level's recursion back one </if> at a time $recursive_if_end_loc = $if_end_location; $if_end_location = strpos($template_cond, $if_end_lookfor, $recursive_if_end_loc + 1); if ($if_end_location === false) { return str_replace("'", "'", $template_cond); // no </if> found -- return the original template } } $else_location = strpos($template_cond, $else_lookfor, $condition_end + 3); // location of false portion // this is needed to correctly identify the <else /> tag associated with the outermost level while (1) { if ($else_location === false OR $else_location >= $if_end_location) { // else isn't found/in a valid area $else_location = -1; break; } $temp = substr($template_cond, $condition_end + 3, $else_location - $condition_end + 3); $opened_if = substr_count($temp, $if_lookfor); // <if> tags opened between the outermost <if> and the <else /> $closed_if = substr_count($temp, $if_end_lookfor); // <if> tags closed under same conditions if ($opened_if == $closed_if) { // if this is true, we're back to the outermost level // and this is the correct else break; } else { // keep looking for correct else case $else_location = strpos($template_cond, $else_lookfor, $else_location + 1); } } if ($else_location == -1) { // no else clause $read_length = $if_end_location - strlen($if_end_lookfor) + 1 - $condition_end + 1; // number of chars to read $true_value = substr($template_cond, $condition_end + 3, $read_length); // the true portion $false_value = ''; } else { $read_length = $else_location - $condition_end - 3; // number of chars to read $true_value = substr($template_cond, $condition_end + 3, $read_length); // the true portion $read_length = $if_end_location - strlen($if_end_lookfor) - $else_location - 3; // number of chars to read $false_value = substr($template_cond, $else_location + strlen($else_lookfor), $read_length); // the false portion } if (strpos($true_value, $if_lookfor) !== false) { $true_value = process_template_conditionals($true_value); } if (strpos($false_value, $if_lookfor) !== false) { $false_value = process_template_conditionals($false_value); } // clean up the extra slashes $str_find = array('"', ''); $str_replace = array('"', ''); if ($delimiter == "'") { $str_find[] = "'"; $str_replace[] = "'"; } $str_find[] = '$delimiter'; $str_replace[] = $delimiter; $condition_value = str_replace($str_find, $str_replace, $condition_value); $conditional = "" . (($condition_value) ? ("$true_value") : ("$false_value")).""; $template_cond = substr_replace($template_cond, $conditional, $if_location, $if_end_location + strlen($if_end_lookfor) - $if_location); $if_end_location = $if_location + strlen($conditional) - 1; // adjust searching position for the replacement above } return str_replace("'", "'", $template_cond); } ?>[/php:1:8770f4a600] |
|
|
|
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 Dziala mi juz sprawdzanie, ale zrobilem troche ina... 31.01.2004, 09:45:46
Bora Może mój template ciebie zainteresuje.
Posiada obs... 31.01.2004, 20:08:59 ![]() ![]() |
|
Aktualny czas: 26.12.2025 - 11:07 |