Если не заполнено дополнительное поле. Новый тег
Категория: Хаки (DLE) | 22 июля 2010 | Просмотров: 12008
Иногда надо пользователю сообщить что дополнительное поле пустое, тоесть незаполненое.
Одним вариантом может быть указывание стандартного значения (по умолчанию), но это не всегда удобно и не всегда возможно.
Именно для отображения сообщения, что поле не указано придуман этот хак (скорее все, что он уже был когда-то и что в последующих версиях будет по умолчанию).
Тестировался на DLE 8.5
Установка!
В файлах папки engine/modules/: show.full.php, show.short.php, show.custom.php
найти:
заменить на:
В шаблон краткой и полной новости куда надо прописать:
ENGLISH
How check if xfieled existe or not?
in files of folder ./engine/modules/: show.full.php, show.short.php, show.custom.php
find:
replace with:
in template (fullstory.tpl, shortstory.tpl) write:
Одним вариантом может быть указывание стандартного значения (по умолчанию), но это не всегда удобно и не всегда возможно.
Именно для отображения сообщения, что поле не указано придуман этот хак (скорее все, что он уже был когда-то и что в последующих версиях будет по умолчанию).
Тестировался на DLE 8.5
Установка!
В файлах папки engine/modules/: show.full.php, show.short.php, show.custom.php
найти:
if( empty( $xfieldsdata[$value[0]] ) ) {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
}
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
}
заменить на:
if( empty( $xfieldsdata[$value[0]] ) ) {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
}
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
}
В шаблон краткой и полной новости куда надо прописать:
[not-xfgiven_xfname] уві, доп.поле не заполнено [/not-xfgiven_xfname]
[xfgiven_xfname] ура, доп.поле заполнено [/xfgiven_xfname]
[xfgiven_xfname] ура, доп.поле заполнено [/xfgiven_xfname]
ГОТОВО!
ENGLISH
How check if xfieled existe or not?
in files of folder ./engine/modules/: show.full.php, show.short.php, show.custom.php
find:
if( empty( $xfieldsdata[$value[0]] ) ) {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
}
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
}
replace with:
if( empty( $xfieldsdata[$value[0]] ) ) {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
}
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
} else {
$tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
$tpl->copy_template = preg_replace( "'\\[not-xfgiven_{$preg_safe_name}\\](.*?)\\[/not-xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
}
in template (fullstory.tpl, shortstory.tpl) write:
[not-xfgiven_xfname] no xfield [/not-xfgiven_xfname]
[xfgiven_xfname] yes xfield [/xfgiven_xfname]
[xfgiven_xfname] yes xfield [/xfgiven_xfname]
ENJOY!
Просмотров: 12008
Комментарии (1)
#1 написал: WildCat (15 августа 2010 18:41)
ICQ: --
цитировать
цитировать





![Validate my RSS feed [Valid RSS]](http://validator.w3.org/feed/images/valid-rss.png)
Гости
----------