İlave alanları şablonda kullanmak istediğimizde sadece ilave alan boş değilse ve boşsa kontrollerini yapabiliyoruz.
Fakat bu her zaman yeterli olmuyor, daha esnek kontol için bu düzenlemeyi kullanabilirsiniz.
Yeni versiyonda if ile değerin olup olmadığını kontrol edebiliyoruz.Ek olarak if yazımında veya / ya da mantıksal kontrolünü de kullanabiliyoruz.
Mevcut yetenekleri :
İlave alan buna eşitse : ( yap )
İlave alan buna eşitse veya bunlardan biriyse : ( yap )
İlave alan buna eşitse : ( yap ) : eşit değilse : (yap )
İlave alan buna eşitse veya bunlardan biriyse : ( yap ) : eşit değilse : (yap )
İlave alan varsa : ( yap )
Bu ilave alanların hepsi varsa : ( yap )
Bu ilave alanların bir tanesi varsa : ( yap )
template.class.php'de dosyasında öncelik {include} kodunda olduğu için bir düzenleme ile bu işlemi ikinci sıraya alıyoruz.Bu sayede bu yazımların içinde include yapsını kullanabileceğiz.
Aç - engine/classes/templates.class.php
Bul ve Sil :
if( strpos( $this->template, "{include file=" ) !== false ) {
$this->include_mode = 'tpl';
$this->template = preg_replace_callback( "#\\{include file=['\"](.+?)['\"]\\}#i", array( &$this, 'load_file'), $this->template );
} $category_id = $row['category'];
$tpl->compile( 'content' );// MWS Smart Xfield v1.1
if ( strpos( $tpl->copy_template, "{if xfield=" ) ) {
if ( $xfound ) $xfdata = &$xfieldsdata;
else $xfdata = xfieldsdataload( $row['xfields'] );
if ( preg_match_all( "#\{if xfield=['\"]([a-zA-Z0-9-_\|\&]+)['\"]\}[\s\n\t]*(.+?)[\s\n\t]*\{\/if\}#ies", $tpl->copy_template, $matches0 ) ) {
$length = count( $matches0[0] );
for ( $x = 0; $x <= $length; $x++ ) {
if ( strpos( $matches0[1][$x], "|" ) != false ) {
$keys = explode( "|", $matches0[1][$x] );
foreach ( $keys as $key ) {
if ( in_array( $key, array_keys( $xfdata ) ) && ! empty( $xfdata[ $key ] ) ) {
$tpl->copy_template = str_replace( $matches0[0][$x], $matches0[2][$x], $tpl->copy_template );
}
}
} else if ( strpos( $matches0[1][$x], "&" ) != false ) {
$keys = explode( "&", $matches0[1][$x] ); $stop = false;
foreach ( $keys as $key ) {
if ( ! in_array( $key, array_keys( $xfdata ) ) || empty( $xfdata[ $key ] ) ) {
$stop = true;
}
}
if ( $stop ) $tpl->copy_template = str_replace( $matches0[0][$x], "", $tpl->copy_template );
else $tpl->copy_template = str_replace( $matches0[0][$x], $matches0[2][$x], $tpl->copy_template );
} else {
$key = $matches0[1][$x];
if ( in_array( $key, array_keys( $xfdata ) ) && ! empty( $xfdata[ $key ] ) ) {
$matches0[2][$x] = str_replace( "{value}", $xfdata[ $key ], $matches0[2][$x] );
$tpl->copy_template = str_replace( $matches0[0][$x], $matches0[2][$x], $tpl->copy_template );
} else {
$tpl->copy_template = str_replace( $matches0[0][$x], "", $tpl->copy_template );
}
}
}
}
if ( preg_match_all( "#\{if xfield=['\"](.+?)['\"] ([not-]*)eq=['\"](.+?)['\"]\}[\s\n\t]*(.+?)[\s\n\t]*\{\/if\}#ies", $tpl->copy_template, $matches1 ) ) {
$length = count( $matches1[0] );
for ( $x = 0; $x <= $length; $x++ ) {
if ( strpos( $matches1[0][$x], "{else}" ) != false ) break;
if ( in_array( $matches1[1][$x], array_keys( $xfdata ) ) ) {
$matches1[4][$x] = str_replace( "{value}", $xfdata[ $matches1[1][$x] ], $matches1[4][$x] );
if ( ! empty( $matches1[2][$x] ) && $matches1[2][$x] == "not-" ) {
if ( ! in_array( $xfdata[ $matches1[1][$x] ], explode("|", $matches1[3][$x] ) ) ) { $tpl->copy_template = str_replace( $matches1[0][$x], $matches1[4][$x], $tpl->copy_template ); }
else { $tpl->copy_template = str_replace( $matches1[0][$x], "", $tpl->copy_template ); }
} else {
if ( in_array( $xfdata[ $matches1[1][$x] ], explode("|", $matches1[3][$x] ) ) ) { $tpl->copy_template = str_replace( $matches1[0][$x], $matches1[4][$x], $tpl->copy_template ); }
else { $tpl->copy_template = str_replace( $matches1[0][$x], "", $tpl->copy_template ); }
}
} else {
$tpl->copy_template = str_replace( $matches1[0][$x], "", $tpl->copy_template );
}
}
}
if ( preg_match_all( "#\{if xfield=['\"](.+?)['\"] eq=['\"](.+?)['\"]\}[\s\n\t]*(.+?)[\s\n\t]*\{else\}[\s\n\t]*(.+?)[\s\n\t]*\{\/if\}#ies", $tpl->copy_template, $matches2 ) ) {
$length = count( $matches2[0] );
for ( $x = 0; $x <= $length; $x++ ) {
if ( in_array( $matches2[1][$x], array_keys( $xfdata ) ) ) {
$matches2[3][$x] = str_replace( "{value}", $xfdata[ $matches2[1][$x] ], $matches2[3][$x] );
$matches2[4][$x] = str_replace( "{value}", $xfdata[ $matches2[1][$x] ], $matches2[4][$x] );
if ( in_array( $xfdata[ $matches2[1][$x] ], explode("|", $matches2[2][$x] ) ) ) { $tpl->copy_template = str_replace( $matches2[0][$x], $matches2[3][$x], $tpl->copy_template ); }
else { $tpl->copy_template = str_replace( $matches2[0][$x], $matches2[4][$x], $tpl->copy_template ); }
} else {
$tpl->copy_template = str_replace( $matches2[0][$x], "", $tpl->copy_template );
}
}
}
unset( $xfdata, $matches0, $matches1, $matches2 );
}
// MWS Smart Xfield v1.1if (stripos ( $tpl->copy_template, "[not-static=" ) !== false) {if( strpos( $tpl->copy_template, "{include file=" ) !== false ) {
$tpl->include_mode = 'tpl';
$tpl->copy_template = preg_replace_callback( "#\\{include file=['\"](.+?)['\"]\\}#i", array( &$tpl, 'load_file'), $tpl->template );
} {if xfield="year|genre|url"}
Herhangi biri girilmiş
{/if}
{if xfield="year&genre&url"}
Hepsi girilmiş
{/if}
{if xfield="genre"}
Genre <b>{value}</b> olarak girilmiş
{/if}
{if xfield="genre" eq="Drama"}
Genre <b>Drama:{value}</b> olarak girilmiş
{/if}
{if xfield="genre" not-eq="Action"}
Genre <b>Action:{value}</b> olarak girilmemiş
{/if}
{if xfield="genre" eq="Drama"}
Genre <b>{value}</b> olarak girilmiş
{else}
Genre drama olarak girilmemiş
{/if}
{if xfield="genre" eq="Drama"}
Genre <b>{value}</b> olarak girilmiş
{else}
Genre drama olarak girilmemiş
{/if}
{if xfield="genre"}
{include file="{value}.tpl"}
{/if}
{if xfield="genre" eq="Drama|Action"}
{if xfield="year&genre&url"}
Hepsi girilmiş
{/if}
{else}
Genre drama olarak girilmemiş
{/if}