![]() |
![]() |
![]()
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] |
|
|
![]() ![]() |
![]() |
Aktualny czas: 3.10.2025 - 06:17 |