Посетитель
Сообщений: 798
Добрый вечер Парвиз - вот:
Спойлер
/templates/шаблон/content/default_item.tpl.php
Код PHP: <!-- colorbox -->
<?php $this -> addJS ( "templates/{$this->name} /colorbox/jquery.colorbox.js" ) ; ?>
<?php $this -> addJS ( "templates/{$this->name} /colorbox/init_colorbox.js" ) ; ?>
<?php $this -> addCSS ( "templates/{$this->name} /colorbox/colorbox.css" ) ; ?>
<!-- colorbox -->
<?php $user = cmsUser:: getInstance ( ) ; ?>
<?php if ( $fields [ 'title' ] [ 'is_in_item' ] ) { ?>
<h1>
<span class="title_wrap" style="color:black"><?php html( $item [ 'title' ] ) ; ?> </span>
<?php if ( $item [ 'is_private' ] ) { ?>
<span class="is_private" title="<?php html( LANG_PRIVACY_PRIVATE) ; ?> "></span>
<?php } ?>
</h1>
<?php if ( $item [ 'parent_id' ] ) { ?>
<h2 class="parent_title item_<?php echo $item [ 'parent_type' ] ; ?> _title">
<a href="<?php echo rel_to_href( $item [ 'parent_url' ] ) ; ?> "><?php html( $item [ 'parent_title' ] ) ; ?> </a>
</h2>
<?php } ?>
<?php unset ( $fields [ 'title' ] ) ; ?> <?php } ?>
<div class="content_item <?php echo $ctype [ 'name' ] ; ?> _item">
<?php foreach ( $fields as $name => $field ) { ?>
<?php if ( ! $field [ 'is_in_item' ] || $field [ 'is_system' ] ) { continue ; } ?>
<?php if ( ( empty ( $item [ $field [ 'name' ] ] ) || empty ( $field [ 'html' ] ) ) && $item [ $field [ 'name' ] ] !== '0' ) { continue ; } ?> <?php if ( $field [ 'groups_read' ] && ! $user -> isInGroups ( $field [ 'groups_read' ] ) ) { continue ; } ?>
<div class="field ft_<?php echo $field [ 'type' ] ; ?> f_<?php echo $field [ 'name' ] ; ?> <?php echo $field [ 'options' ] [ 'wrap_type' ] ; ?> _field" <?php if ( $field [ 'options' ] [ 'wrap_width' ] ) { ?> style="width: <?php echo $field [ 'options' ] [ 'wrap_width' ] ; ?> ;"<?php } ?> >
<?php if ( $field [ 'options' ] [ 'label_in_item' ] != 'none' ) { ?>
<div class="title_<?php echo $field [ 'options' ] [ 'label_in_item' ] ; ?> "><?php html( $field [ 'title' ] ) ; ?> : </div>
<?php } ?>
<div class="value"><?php echo $field [ 'html' ] ; ?> </div>
</div>
<?php } ?>
<?php
$props_fields = $this -> controller -> getPropsFields ( $props ) ;
$props_fieldsets = cmsForm:: mapFieldsToFieldsets ( $props ) ;
?>
<div class="content_item_props <?php echo $ctype [ 'name' ] ; ?> _item_props">
<table>
<tbody>
<?php foreach ( $props_fieldsets as $fieldset ) { ?>
<?php if ( $fieldset [ 'title' ] ) { ?>
<tr>
<td class="heading" colspan="2"><?php html( $fieldset [ 'title' ] ) ; ?> </td>
</tr>
<?php } ?>
<?php if ( $fieldset [ 'fields' ] ) { ?>
<?php foreach ( $fieldset [ 'fields' ] as $prop ) { ?>
<?php if ( isset ( $props_values [ $prop [ 'id' ] ] ) ) { ?> <?php $prop_field = $props_fields [ $prop [ 'id' ] ] ; ?>
<tr>
<td class="title"><?php html( $prop [ 'title' ] ) ; ?> </td>
<td class="value">
<?php echo $prop_field -> setItem ( $item ) -> parse ( $props_values [ $prop [ 'id' ] ] ) ; ?>
</td>
</tr>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
<?php
$hooks_html = cmsEventsManager:: hookAll ( "content_{$ctype['name']} _item_html" , $item ) ;
if ( $hooks_html ) { echo html_each( $hooks_html ) ; }
?>
<?php
$is_tags = $ctype [ 'is_tags' ] &&
! empty ( $ctype [ 'options' ] [ 'is_tags_in_item' ] ) && $item [ 'tags' ] ;
?>
<?php if ( $is_tags ) { ?>
<div class="tags_bar">
<?php echo html_tags_bar( $item [ 'tags' ] ) ; ?>
</div>
<?php } ?>
<?php
$show_bar = ! empty ( $item [ 'rating_widget' ] ) || $fields [ 'date_pub' ] [ 'is_in_item' ] ||
$fields [ 'user' ] [ 'is_in_item' ] ||
! empty ( $ctype [ 'options' ] [ 'hits_on' ] ) || ! $item [ 'is_pub' ] ||
! $item [ 'is_approved' ] ;
?>
<?php if ( $ctype [ 'item_append_html' ] ) { ?>
<div class="append_html" style="text-align: center;"><?php echo $ctype [ 'item_append_html' ] ; ?> </div>
<?php } ?>
<?php if ( $show_bar ) { ?>
<div class="info_bar">
<?php if ( $fields [ 'date_pub' ] [ 'is_in_item' ] ) { ?>
<div class="bar_item bi_date_pub" title="<?php html( $fields [ 'date_pub' ] [ 'title' ] ) ; ?> ">
<span class="bi_item_title"><?php html( $fields [ 'date_pub' ] [ 'title' ] ) ; ?> :</span>
<?php echo $fields [ 'date_pub' ] [ 'html' ] ; ?>
</div>
<?php } ?>
<?php if ( ! $item [ 'is_pub' ] ) { ?>
<div class="bar_item bi_not_pub">
<?php echo LANG_CONTENT_NOT_IS_PUB; ?>
</div>
<?php } ?>
<?php if ( ! empty ( $ctype [ 'options' ] [ 'hits_on' ] ) ) { ?> <div class="bar_item bi_hits" title="<?php echo LANG_HITS; ?> ">
<span class="bi_item_title"><?php echo LANG_HITS; ?> :</span>
<?php echo $item [ 'hits_count' ] ; ?>
</div>
<?php } ?>
<?php if ( $fields [ 'user' ] [ 'is_in_item' ] ) { ?>
<div class="bar_item bi_user" title="<?php html( $fields [ 'user' ] [ 'title' ] ) ; ?> ">
<span class="bi_item_title"><?php html( $fields [ 'user' ] [ 'title' ] ) ; ?> :</span>
<?php echo $fields [ 'user' ] [ 'html' ] ; ?>
</div>
<?php if ( ! empty ( $item [ 'folder_title' ] ) ) { ?> <div class="bar_item bi_folder">
<a href="
<?php echo href_to
( 'users' , $item [ 'user' ] [ 'id' ] , array ( 'content' , $ctype [ 'name' ] , $item [ 'folder_id' ] ) ) ; ?> ">
<?php echo $item [ 'folder_title' ] ; ?> </a>
</div>
<?php } ?>
<?php } ?>
<div class="r_bar clearfix">
<?php if ( ! empty ( $item [ 'rating_widget' ] ) ) { ?> <div class="bar_item bi_rating">
<?php echo $item [ 'rating_widget' ] ; ?>
</div>
<?php } ?>
<div class="bar_item bi_share">
<div class="share" style="margin:-4px">
<script type="text/javascript">
(function() {
if (window.pluso)if (typeof window.pluso.start == "function") return;
if (window.ifpluso==undefined) { window.ifpluso = 1;
var d = document, s = d.createElement('script'), g = 'getElementsByTagName';
s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true;
s.src = ('https:' == window.location.protocol ? 'https' : 'http') + '://share.pluso.ru/pluso-like.js';
var h=d[g]('body')[0];
h.appendChild(s);
}})();
</script>
<div class="pluso" data-background="transparent" data-options="small,square,line,horizontal,counter,theme=03" data-services="vkontakte,odnoklassniki,facebook,twitter,google,moimir,pinterest"></div>
<div style="display: inline-block;line-height: 24px;vertical-align: bottom;font-size: 16px;color: #888;margin-left: 25px;">Понравилась запись? Поделитесь ею в соцсетях!</div>
</div>
</div>
</div>
<?php if ( ! $item [ 'is_approved' ] ) { ?>
<div class="bar_item bi_not_approved">
<?php echo LANG_CONTENT_NOT_APPROVED; ?>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
/templates/шаблон/assets/helper.php
Код PHP: <?php
/**
* Выводит тег <a>
* @param string $title Название
* @param string $href Ссылка
*/
function html_link( $title , $href ) {
}
/**
* Возвращает панель со страницами
*
* @param int $page Текущая страница
* @param int $perpage Записей на одной странице
* @param int $total Количество записей
* @param str $base_uri Базовый URL, может быть массивом из элементов first и base
* @param str $query Массив параметров запроса
*/
function html_pagebar
( $page , $perpage , $total , $base_uri = false , $query = array ( ) ) {
if ( ! $total ) { return ; }
$pages = ceil ( $total / $perpage ) ; if ( $pages <= 1 ) { return ; }
$core = cmsCore:: getInstance ( ) ;
$anchor = '' ;
}
if ( $anchor ) { $anchor = '#' . $anchor ; }
if ( ! $base_uri ) { $base_uri = $core -> uri_absolute ; }
'first' => $base_uri ,
'base' => $base_uri
) ;
}
}
$html = '' ;
$html .= '<div class="pagebar">' ;
if ( ( $page > 1 ) || ( $page < $pages ) ) {
$html .= '<span class="pagebar_nav">' ;
if ( $page > 1 ) {
$query [ 'page' ] = ( $page - 1 ) ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">← ' . LANG_PAGE_PREV
. '</a> ' ; } else {
$html .= ' <span class="pagebar_page disabled">← ' . LANG_PAGE_PREV. '</span> ' ;
}
if ( $page < $pages ) {
$query [ 'page' ] = ( $page + 1 ) ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . LANG_PAGE_NEXT
. ' →</a> ' ; } else {
$html .= ' <span class="pagebar_page disabled">' . LANG_PAGE_NEXT. ' →</span> ' ;
}
$html .= '</span>' ;
}
$span = 3 ;
if ( $page - $span < 1 ) { $p_start = 1 ; } else { $p_start = $page - $span ; }
if ( $page + $span > $pages ) { $p_end = $pages ; } else { $p_end = $page + $span ; }
$html .= '<span class="pagebar_pages">' ;
if ( $page > $span + 1 ) {
$query [ 'page' ] = 1 ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . LANG_PAGE_FIRST
. '</a> ' ; }
for ( $p = $p_start ; $p <= $p_end ; $p ++ ) {
if ( $p != $page ) {
$query [ 'page' ] = $p ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . $p . '</a> ' ; } else {
$html .= '<span class="pagebar_current">' . $p . '</span>' ;
}
}
if ( $page < $pages - $span ) {
$query [ 'page' ] = $pages ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . LANG_PAGE_LAST
. '</a> ' ; }
$html .= '</span>' ;
$from = $page * $perpage - $perpage + 1 ;
$to = $page * $perpage ; if ( $to > $total ) { $to = $total ; }
$html .= '<div class="pagebar_notice">' . sprintf ( LANG_PAGES_SHOWN
, $from , $to , $total ) . '</div>' ;
$html .= '</div>' ;
return $html ;
}
/**
* Возвращает тег <input>
* @param string $type Тип поля
* @param string $name Имя поля
* @param string $value Значение по-умолчанию
* @param array $attributes Атрибуты тега название=>значение
* @return html
*/
function html_input
( $type = 'text' , $name = '' , $value = '' , $attributes = array ( ) ) { if ( $type == 'password' ) { $attributes [ 'autocomplete' ] = 'off' ; }
$attr_str = html_attr_str( $attributes ) ;
$class = 'input' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="' . $type . '" class="' . $class . '" name="' . $name . '" value="' . htmlspecialchars ( $value ) . '" ' . $attr_str . '/>' ; }
function html_file_input
( $name , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'file-input' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="file" class="' . $class . '" name="' . $name . '" ' . $attr_str . '/>' ;
}
function html_textarea
( $name = '' , $value = '' , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'textarea' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } $html = '<textarea name="' . $name . '" class="' . $class . '" ' . $attr_str . '>' . htmlspecialchars ( $value ) . '</textarea>' ; return $html ;
}
function html_back_button( ) {
return '<div class="back_button"><a href="javascript:window.history.go(-1);">' . LANG_BACK. '</a></div>' ;
}
function html_checkbox
( $name , $checked = false , $value = 1 , $attributes = array ( ) ) { if ( $checked ) { $attributes [ 'checked' ] = 'checked' ; }
$attr_str = html_attr_str( $attributes ) ;
$class = 'input-checkbox' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="checkbox" class="' . $class . '" name="' . $name . '" value="' . $value . '" ' . $attr_str . '/>' ;
}
function html_radio
( $name , $checked = false , $value = 1 , $attributes = array ( ) ) { if ( $checked ) { $attributes [ 'checked' ] = 'checked' ; }
$attr_str = html_attr_str( $attributes ) ;
return '<input type="radio" class="input_radio" name="' . $name . '" value="' . $value . '" ' . $attr_str . '/>' ;
}
function html_date( $date = false , $is_time = false ) {
$date = '<time datetime="' . date ( 'c' , $timestamp ) . '">' . htmlspecialchars ( date ( cmsConfig
:: get ( 'date_format' ) , $timestamp ) ) . '</time>' ; if ( $is_time ) { $date .= ' <span class="time">' . date ( 'H:i' , $timestamp ) . '</span>' ; } return $date ;
}
function html_time( $date = false ) {
return date ( 'H:i' , $timestamp ) ; }
function html_date_time( $date = false ) {
return html_date( $date , true ) ;
}
function html_datepicker
( $name = '' , $value = '' , $attributes = array ( ) , $datepicker = array ( ) ) { if ( isset ( $attributes [ 'id' ] ) ) { $id = $attributes [ 'id' ] ;
unset ( $attributes [ 'id' ] ) ; } else {
$id = $name ;
}
$datepicker_default = array ( 'showStatus' => true ,
'changeYear' => true ,
'showOn' => 'both' ,
'yearRange' => '1940:2050' ,
'dateFormat' => cmsConfig:: get ( 'date_format_js' )
) ;
if ( $datepicker ) {
$datepicker_default = array_merge ( $datepicker_default , $datepicker ) ; }
$attr_str = html_attr_str( $attributes ) ;
$html = '<input type="text" placeholder="' . LANG_SELECT
. '" name="' . $name . '" value="' . htmlspecialchars ( $value ) . '" class="date-input" id="' . $id . '" ' . $attr_str . '/>' ; $html .= '<script type="text/javascript">' ;
$html .= '$(function(){ $("#' . $id . '").datepicker(' . json_encode ( $datepicker_default ) . '); });' ; $html .= '</script>' ;
return $html ;
}
/**
* Возвращает кнопку "Отправить" <input type="submit">
* @param string $caption
* @return html
*/
function html_submit
( $caption = LANG_SUBMIT
, $name = 'submit' , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'button-submit' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input class="' . $class . '" type="submit" name="' . $name . '" value="' . htmlspecialchars ( $caption ) . '" ' . $attr_str . '/>' ; }
/**
* Возвращает html-код кнопки
* @param str $caption Заголовок
* @param str $name Название кнопки
* @param str $onclick Содержимое аттрибута onclick (javascript)
* @return html
*/
function html_button
( $caption , $name , $onclick = '' , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'button' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="button" class="' . $class . '" name="' . $name . '" value="' . htmlspecialchars ( $caption ) . '" onclick="' . $onclick . '" ' . $attr_str . '/>' ; }
/**
* Возвращает тег <img> аватара пользователя
* @param array|yaml $avatars Все изображения аватара
* @param string $size_preset Название пресета
* @param string $alt Замещающий текст изображения
* @param bool $is_html_empty_avatar Вместо дефолтных изображений показывать цветной блок с буквой
* @return string
*/
function html_avatar_image( $avatars , $size_preset = 'small' , $alt = '' , $is_html_empty_avatar = true ) {
$src = html_avatar_image_src( $avatars , $size_preset ) ;
$size = $size_preset == 'micro' ? 'width="32" height="32"' : '' ;
if ( empty ( $avatars ) && ! empty ( $alt ) && $is_html_empty_avatar ) {
$iparams = get_image_block_param_by_title( $alt ) ;
$img = '<div class="default_avatar ' . $iparams [ 'class' ] . '" style="' . $iparams [ 'style' ] . '" data-letter="' . htmlspecialchars ( mb_substr ( $alt , 0 , 1 ) ) . '">' . $img . '</div>' ;
}
return $img ;
}
function get_image_block_param_by_title( $title ) {
static $image_block_params = null ;
if ( isset ( $image_block_params [ $title ] ) ) { return $image_block_params [ $title ] ;
}
// выбираем контрастный цвет для текста
$yiq = ( ( $r * 299 ) + ( $g * 587 ) + ( $b * 114 ) ) / 1000 ;
$txt_color = ( $yiq >= 140 ) ? 'black' : 'white' ;
$image_block_params [ $title ] = array ( 'style' => "background-color: rgba({$r} , {$g} , {$b} , .9); color: {$txt_color} ;" ,
'class' => $txt_color . '_avatar_text'
) ;
return $image_block_params [ $title ] ;
}
/**
* Возвращает тег <img>
* @param array|yaml $image Все размеры заданного изображения
* @param string $size_preset Название пресета
* @param string $alt Замещающий текст изображения
* @param array $attributes Массив аттрибутов тега
* @return string
*/
function html_image
( $image , $size_preset = 'small' , $alt = '' , $attributes = array ( ) ) {
$src = html_image_src( $image , $size_preset , true ) ;
if ( ! $src ) { return '' ; }
$size = $size_preset == 'micro' ? 'width="32" height="32"' : '' ;
$attr_str = html_attr_str( $attributes ) ;
$class = isset ( $attributes [ 'class' ] ) ?
' class="' . $attributes [ 'class' ] . '"' : '' ;
return '<img src="' . $src . '" ' . $size . ' alt="' . htmlspecialchars ( $alt ) . '" ' . $attr_str . $class . ' />' ;
}
/**
* Возвращает тег HTML gif изображения
* @param array|yaml $image Все размеры заданного изображения
* @param string $size_preset Название пресета
* @param string $alt Замещающий текст изображения
* @param array $attributes Массив аттрибутов тега
* @return string
*/
function html_gif_image
( $image , $size_preset = 'small' , $alt = '' , $attributes = array ( ) ) {
$class = isset ( $attributes [ 'class' ] ) ?
$attributes [ 'class' ] : '' ; if ( $size_preset == 'micro' ) {
$class .= ' micro_image' ;
}
$original_src = html_image_src( $image , 'original' , true ) ;
$preview_src = html_image_src( $image , $size_preset , true ) ;
if ( ! $preview_src ) { return '' ; }
return '<a class="ajax-modal gif_image ' . $class . '" href="' . $original_src . '" ' . html_attr_str( $attributes ) . '>
<span class="background_overlay"></span>
<span class="image_label">gif</span>
</a>' ;
}
/**
* Генерирует список опций
* @param string $name Имя списка
* @param array $items Массив элементов списка (значение => заголовок)
* @param string $selected Значение выбранного элемента
* @param array $attributes Массив аттрибутов тега
* @return html
*/
function html_select
( $name , $items , $selected = '' , $attributes = array ( ) ) {
$attr_str = html_attr_str( $attributes ) ;
$class = isset ( $attributes [ 'class' ] ) ?
' class="' . $attributes [ 'class' ] . '"' : '' ; $html = '<select name="' . $name . '" ' . $attr_str . $class . '>' . "\n " ;
$optgroup = false ;
foreach ( $items as $value => $title ) {
if ( $optgroup !== false ) {
$html .= "\t " . '</optgroup>' . "\n " ;
$optgroup = false ;
}
$optgroup = true ;
continue ;
}
$sel = ( ( string) $selected === ( string) $value ) ? 'selected' : '' ;
}
}
if ( $optgroup !== false ) {
$html .= "\t " . '</optgroup>' . "\n " ;
}
$html .= '</select>' . "\n " ;
return $html ;
}
/**
* Генерирует список опций с множественным выбором
* @param string $name Имя списка
* @param array $items Массив элементов списка (значение => заголовок)
* @param string $selected Массив значений выбранных элементов
* @param array $attributes Массив аттрибутов тега
* @return html
*/
function html_select_multiple
( $name , $items , $selected = array ( ) , $attributes = array ( ) , $is_tree = false ) { $attr_str = html_attr_str( $attributes ) ;
$html = '<div class="input_checkbox_list" ' . $attr_str . '>' . "\n " ;
$start_level = false ;
foreach ( $selected as $k => $v ) {
}
}
foreach ( $items as $value => $title ) {
if ( $is_tree ) {
if ( $start_level === false ) { $start_level = $level ; }
$level = $level - $start_level ;
$title = ltrim ( $title , '- ' ) ;
$html .= "\t " . '<label ' . ( $level > 0 ? 'style="margin-left:' . ( $level * 20 ) . 'px"' : '' ) . '>' .
html_checkbox( $name . '[]' , $checked , $value ) . ' ' .
} else {
$html .= "\t " . '<label>' .
html_checkbox( $name . '[]' , $checked , $value ) . ' ' .
}
}
$html .= '</div>' . "\n " ;
return $html ;
}
/**
* Генерирует и возвращает дерево категорий в виде комбо-бокса
* @param array $tree Массив с элементами дерева NS
* @param int $selected_id ID выбранного элемента
* @return html
*/
function html_category_list( $tree , $selected_id = 0 ) {
$html = '<select name="category_id" id="category_id" class="combobox">' . "\n " ;
foreach ( $tree as $cat ) {
$padding = str_repeat ( '---' , $cat [ 'ns_level' ] ) . ' ' ; if ( $selected_id == $cat [ 'id' ] ) { $selected = 'selected' ; } else { $selected = '' ; }
$html .= "\t " . '<option value="' . $cat [ 'id' ] . '" ' . $selected . '>' . $padding . ' ' . htmlspecialchars ( $cat [ 'title' ] ) . '</option>' . "\n " ; }
$html .= '</select>' . "\n " ;
return $html ;
}
/**
* Генерирует две радио-кнопки ВКЛ и ВЫКЛ
* @param string $name
* @param bool $active
* @return html
*/
function html_switch( $name , $active ) {
$html = '' ;
$html .= '<label><input type="radio" name="' . $name . '" value="1" ' . ( $active ? 'checked' : '' ) . '/> ' . LANG_ON . "</label> \n " ;
$html .= '<label><input type="radio" name="' . $name . '" value="0" ' . ( ! $active ? 'checked' : '' ) . '/> ' . LANG_OFF . "</label> \n " ;
return $html ;
}
function html_bool_span( $value , $condition ) {
if ( $condition ) {
return '<span class="positive">' . $value . '</span>' ;
} else {
return '<span class="negative">' . $value . '</span>' ;
}
}
/**
* Строит рекурсивно список UL из массива
* @author acmol
* @param array $array
* @return string
*/
function html_array_to_list( $array ) {
$html = '<ul>' . "\n " ;
foreach ( $array as $key => $elem ) {
$html = $html . '<li>' . $elem . '</li>' . "\n " ;
}
else {
$html = $html . '<li class="folder">' . $key . ' ' . html_array_to_list( $elem ) . '</li>' . "\n " ;
}
}
$html = $html . "</ul>" . "\n " ;
return $html ;
}
function html_tags_bar( $tags ) {
if ( ! $tags ) { return '' ; }
}
foreach ( $tags as $id => $tag ) {
$tags [ $id ] = '<a href="' . href_to
( 'tags' , 'search' ) . '?q=' . urlencode ( $tag ) . '">' . $tag . '</a>' ; }
return $tags_bar ;
}
/system/fields/image.php
Код PHP: <?php
class fieldImage extends cmsFormField {
public $title = LANG_PARSER_IMAGE;
public $sql = 'text' ;
public $allow_index = false ;
public $var_type = 'array' ;
protected $teaser_url = '' ;
public function getOptions( ) {
new fieldList
( 'size_teaser' , array ( 'title' => LANG_PARSER_IMAGE_SIZE_TEASER,
'default' => 'small' ,
'generator' => function ( ) {
$presets = cmsCore:: getModel ( 'images' ) -> getPresetsList ( ) ;
$presets [ 'original' ] = LANG_PARSER_IMAGE_SIZE_ORIGINAL;
return $presets ;
}
) ) ,
new fieldList
( 'size_full' , array ( 'title' => LANG_PARSER_IMAGE_SIZE_FULL,
'default' => 'big' ,
'generator' => function ( ) {
$presets = cmsCore:: getModel ( 'images' ) -> getPresetsList ( ) ;
$presets [ 'original' ] = LANG_PARSER_IMAGE_SIZE_ORIGINAL;
return $presets ;
}
) ) ,
new fieldList
( 'size_modal' , array ( 'title' => LANG_PARSER_IMAGE_SIZE_MODAL,
'default' => '' ,
'generator' => function ( ) {
$presets = cmsCore:: getModel ( 'images' ) -> getPresetsList ( ) ;
$presets [ 'original' ] = LANG_PARSER_IMAGE_SIZE_ORIGINAL;
return array ( '' => '' ) + $presets ; }
) ) ,
new fieldListMultiple
( 'sizes' , array ( 'title' => LANG_PARSER_IMAGE_SIZE_UPLOAD,
'default' => 0 ,
'generator' => function ( ) {
$presets = cmsCore:: getModel ( 'images' ) -> getPresetsList ( ) ;
$presets [ 'original' ] = LANG_PARSER_IMAGE_SIZE_ORIGINAL;
return $presets ;
}
) ) ,
new fieldCheckbox
( 'allow_import_link' , array ( 'title' => LANG_PARSER_IMAGE_ALLOW_IMPORT_LINK
) )
) ;
}
public function setTeaserURL( $url ) {
$this -> teaser_url = $url ;
return $this ;
}
public function parseTeaser( $value ) {
$paths = is_array ( $value ) ?
$value : cmsModel
:: yamlToArray ( $value ) ;
if ( ! $paths && $this -> hasDefaultValue ( ) ) { $paths = $this -> parseDefaultPaths ( ) ; }
if ( ! $paths || ! isset ( $paths [ $this -> getOption ( 'size_teaser' ) ] ) ) { return '' ; }
$url = $this -> teaser_url ?
$this -> teaser_url :
href_to( $this -> item [ 'ctype' ] [ 'name' ] , $this -> item [ 'slug' ] . ".html" ) ;
return '<a href="' . $url . '">' . html_image
( $paths , $this -> getOption ( 'size_teaser' ) , ( empty ( $this -> item [ 'title' ] ) ?
$this -> name : $this -> item [ 'title' ] ) ) . '</a>' ;
}
public function parse( $value ) {
$paths = is_array ( $value ) ?
$value : cmsModel
:: yamlToArray ( $value ) ;
if ( ! $paths && $this -> hasDefaultValue ( ) ) { $paths = $this -> parseDefaultPaths ( ) ; }
$size_full = $this -> getOption ( 'size_full' ) ;
$size_modal = $this -> getOption ( 'size_modal' ) ;
if ( ! $paths || ! isset ( $paths [ $size_full ] ) ) { return '' ; }
$presets = array ( $size_full , false ) ;
$img_func = 'html_gif_image' ;
} else {
$img_func = 'html_image' ;
if ( $size_modal ) { $presets [ 1 ] = $size_modal ; }
}
return $img_func ( $paths , $presets , ( empty ( $this -> item [ 'title' ] ) ?
$this -> name : $this -> item [ 'title' ] ) ) ;
}
public function store( $value , $is_submitted , $old_value = null ) {
$config = cmsConfig:: getInstance ( ) ;
$old_value = cmsModel:: yamlToArray ( $old_value ) ;
if ( $old_value != $value ) {
foreach ( $old_value as $image_url ) {
$image_path = $config -> upload_path . $image_url ;
}
}
}
$sizes = $this -> getOption ( 'sizes' ) ;
if ( empty ( $sizes ) || empty ( $value ) ) { return $value ; }
foreach ( $value as $size => $image_url ) {
$image_path = $config -> upload_path . $image_url ;
}
}
return $value ;
}
public function delete( $value ) {
if ( empty ( $value ) ) { return true ; }
if ( ! is_array ( $value ) ) { $value = cmsModel
:: yamlToArray ( $value ) ; }
$config = cmsConfig:: getInstance ( ) ;
foreach ( $value as $image_url ) {
$image_path = $config -> upload_path . $image_url ;
}
return true ;
}
public function parseDefaultPaths( ) {
$string = $this -> getDefaultValue ( ) ;
if ( ! $string ) { return false ; }
foreach ( $rows as $row ) {
$items [ trim ( $item [ 0 ] ) ] = trim ( $item [ 1 ] ) ; }
}
return $items ;
}
public function getFilterInput( $value = false ) {
return html_checkbox( $this -> name , ( bool) $value ) ;
}
public function applyFilter( $model , $value ) {
return $model -> filterNotNull ( $this -> name ) ;
}
public function getInput( $value ) {
$this -> data [ 'paths' ] = false ;
if ( $value ) {
$this -> data [ 'paths' ] = is_array ( $value ) ?
$value : cmsModel
:: yamlToArray ( $value ) ; }
$this -> data [ 'sizes' ] = $this -> getOption ( 'sizes' ) ;
$this -> data [ 'allow_import_link' ] = $this -> getOption ( 'allow_import_link' ) ;
$this -> data [ 'images_controller' ] = cmsCore:: getController ( 'images' ) ;
return parent:: getInput ( $value ) ;
}
}
/system/lib/template.helper.php
Код PHP: <?php
/**
* Выводит тег <a>
* @param string $title Название
* @param string $href Ссылка
*/
function html_link( $title , $href ) {
}
/**
* Возвращает панель со страницами
*
* @param int $page Текущая страница
* @param int $perpage Записей на одной странице
* @param int $total Количество записей
* @param str $base_uri Базовый URL, может быть массивом из элементов first и base
* @param str $query Массив параметров запроса
*/
function html_pagebar
( $page , $perpage , $total , $base_uri = false , $query = array ( ) ) {
if ( ! $total ) { return ; }
$pages = ceil ( $total / $perpage ) ; if ( $pages <= 1 ) { return ; }
$core = cmsCore:: getInstance ( ) ;
$anchor = '' ;
}
if ( $anchor ) { $anchor = '#' . $anchor ; }
if ( ! $base_uri ) { $base_uri = $core -> uri_absolute ; }
'first' => $base_uri ,
'base' => $base_uri
) ;
}
}
$html = '' ;
$html .= '<div class="pagebar">' ;
if ( ( $page > 1 ) || ( $page < $pages ) ) {
$html .= '<span class="pagebar_nav">' ;
if ( $page > 1 ) {
$query [ 'page' ] = ( $page - 1 ) ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">← ' . LANG_PAGE_PREV
. '</a> ' ; } else {
$html .= ' <span class="pagebar_page disabled">← ' . LANG_PAGE_PREV. '</span> ' ;
}
if ( $page < $pages ) {
$query [ 'page' ] = ( $page + 1 ) ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . LANG_PAGE_NEXT
. ' →</a> ' ; } else {
$html .= ' <span class="pagebar_page disabled">' . LANG_PAGE_NEXT. ' →</span> ' ;
}
$html .= '</span>' ;
}
$span = 3 ;
if ( $page - $span < 1 ) { $p_start = 1 ; } else { $p_start = $page - $span ; }
if ( $page + $span > $pages ) { $p_end = $pages ; } else { $p_end = $page + $span ; }
$html .= '<span class="pagebar_pages">' ;
if ( $page > $span + 1 ) {
$query [ 'page' ] = 1 ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . LANG_PAGE_FIRST
. '</a> ' ; }
for ( $p = $p_start ; $p <= $p_end ; $p ++ ) {
if ( $p != $page ) {
$query [ 'page' ] = $p ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . $p . '</a> ' ; } else {
$html .= '<span class="pagebar_current">' . $p . '</span>' ;
}
}
if ( $page < $pages - $span ) {
$query [ 'page' ] = $pages ;
$uri = ( $query [ 'page' ] == 1 ? $base_uri [ 'first' ] : $base_uri [ 'base' ] ) ;
if ( $query [ 'page' ] == 1 ) { unset ( $query [ 'page' ] ) ; } $html .= ' <a href="' . $uri . ( $query ?
$sep . http_build_query ( $query ) : '' ) . $anchor . '" class="pagebar_page">' . LANG_PAGE_LAST
. '</a> ' ; }
$html .= '</span>' ;
$from = $page * $perpage - $perpage + 1 ;
$to = $page * $perpage ; if ( $to > $total ) { $to = $total ; }
$html .= '<div class="pagebar_notice">' . sprintf ( LANG_PAGES_SHOWN
, $from , $to , $total ) . '</div>' ;
$html .= '</div>' ;
return $html ;
}
/**
* Возвращает тег <input>
* @param string $type Тип поля
* @param string $name Имя поля
* @param string $value Значение по-умолчанию
* @param array $attributes Атрибуты тега название=>значение
* @return html
*/
function html_input
( $type = 'text' , $name = '' , $value = '' , $attributes = array ( ) ) { if ( $type == 'password' ) { $attributes [ 'autocomplete' ] = 'off' ; }
$attr_str = html_attr_str( $attributes ) ;
$class = 'input' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="' . $type . '" class="' . $class . '" name="' . $name . '" value="' . htmlspecialchars ( $value ) . '" ' . $attr_str . '/>' ; }
function html_file_input
( $name , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'file-input' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="file" class="' . $class . '" name="' . $name . '" ' . $attr_str . '/>' ;
}
function html_textarea
( $name = '' , $value = '' , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'textarea' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } $html = '<textarea name="' . $name . '" class="' . $class . '" ' . $attr_str . '>' . htmlspecialchars ( $value ) . '</textarea>' ; return $html ;
}
function html_back_button( ) {
return '<div class="back_button"><a href="javascript:window.history.go(-1);">' . LANG_BACK. '</a></div>' ;
}
function html_checkbox
( $name , $checked = false , $value = 1 , $attributes = array ( ) ) { if ( $checked ) { $attributes [ 'checked' ] = 'checked' ; }
$attr_str = html_attr_str( $attributes ) ;
$class = 'input-checkbox' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="checkbox" class="' . $class . '" name="' . $name . '" value="' . $value . '" ' . $attr_str . '/>' ;
}
function html_radio
( $name , $checked = false , $value = 1 , $attributes = array ( ) ) { if ( $checked ) { $attributes [ 'checked' ] = 'checked' ; }
$attr_str = html_attr_str( $attributes ) ;
return '<input type="radio" class="input_radio" name="' . $name . '" value="' . $value . '" ' . $attr_str . '/>' ;
}
function html_date( $date = false , $is_time = false ) {
$date = '<time datetime="' . date ( 'c' , $timestamp ) . '">' . htmlspecialchars ( date ( cmsConfig
:: get ( 'date_format' ) , $timestamp ) ) . '</time>' ; if ( $is_time ) { $date .= ' <span class="time">' . date ( 'H:i' , $timestamp ) . '</span>' ; } return $date ;
}
function html_time( $date = false ) {
return date ( 'H:i' , $timestamp ) ; }
function html_date_time( $date = false ) {
return html_date( $date , true ) ;
}
function html_datepicker
( $name = '' , $value = '' , $attributes = array ( ) , $datepicker = array ( ) ) { if ( isset ( $attributes [ 'id' ] ) ) { $id = $attributes [ 'id' ] ;
unset ( $attributes [ 'id' ] ) ; } else {
$id = $name ;
}
$datepicker_default = array ( 'showStatus' => true ,
'changeYear' => true ,
'dateFormat' => cmsConfig:: get ( 'date_format_js' )
) ;
if ( $datepicker ) {
$datepicker_default = array_merge ( $datepicker_default , $datepicker ) ; }
$attr_str = html_attr_str( $attributes ) ;
$html = '<input type="text" placeholder="' . LANG_SELECT
. '" name="' . $name . '" value="' . htmlspecialchars ( $value ) . '" class="date-input" id="' . $id . '" ' . $attr_str . '/>' ; $html .= '<script type="text/javascript">' ;
$html .= 'var datepicker_params = ' . json_encode ( $datepicker_default ) . ';datepicker_params.onSelect = datepickerSelected;' ; $html .= '$(function(){ $("#' . $id . '").datepicker(datepicker_params); });function datepickerSelected(dateText,inst){icms.events.run("icms_datepicker_selected_' . $name . '", inst);}' ;
$html .= '</script>' ;
return $html ;
}
/**
* Возвращает кнопку "Отправить" <input type="submit">
* @param string $caption
* @return html
*/
function html_submit
( $caption = LANG_SUBMIT
, $name = 'submit' , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'button-submit' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input class="' . $class . '" type="submit" name="' . $name . '" value="' . htmlspecialchars ( $caption ) . '" ' . $attr_str . '/>' ; }
/**
* Возвращает html-код кнопки
* @param str $caption Заголовок
* @param str $name Название кнопки
* @param str $onclick Содержимое аттрибута onclick (javascript)
* @return html
*/
function html_button
( $caption , $name , $onclick = '' , $attributes = array ( ) ) { $attr_str = html_attr_str( $attributes ) ;
$class = 'button' ;
if ( isset ( $attributes [ 'class' ] ) ) { $class .= ' ' . $attributes [ 'class' ] ; } return '<input type="button" class="' . $class . '" name="' . $name . '" value="' . htmlspecialchars ( $caption ) . '" onclick="' . $onclick . '" ' . $attr_str . '/>' ; }
/**
* Возвращает тег <img> аватара пользователя
* @param array|yaml $avatars Все изображения аватара
* @param string $size_preset Название пресета
* @param string $alt Замещающий текст изображения
* @param bool $is_html_empty_avatar Вместо дефолтных изображений показывать цветной блок с буквой
* @return string
*/
function html_avatar_image( $avatars , $size_preset = 'small' , $alt = '' , $is_html_empty_avatar = false ) {
$src = html_avatar_image_src( $avatars , $size_preset ) ;
$size = $size_preset == 'micro' ? 'width="32" height="32"' : '' ;
if ( empty ( $avatars ) && ! empty ( $alt ) && $is_html_empty_avatar ) {
$iparams = get_image_block_param_by_title( $alt ) ;
$img = '<div class="default_avatar ' . $iparams [ 'class' ] . '" style="' . $iparams [ 'style' ] . '" data-letter="' . htmlspecialchars ( mb_substr ( $alt , 0 , 1 ) ) . '">' . $img . '</div>' ;
}
return $img ;
}
function get_image_block_param_by_title( $title ) {
static $image_block_params = null ;
if ( isset ( $image_block_params [ $title ] ) ) { return $image_block_params [ $title ] ;
}
// выбираем контрастный цвет для текста
$yiq = ( ( $r * 299 ) + ( $g * 587 ) + ( $b * 114 ) ) / 1000 ;
$txt_color = ( $yiq >= 140 ) ? 'black' : 'white' ;
$image_block_params [ $title ] = array ( 'style' => "background-color: rgba({$r} , {$g} , {$b} , .9); color: {$txt_color} ;" ,
'class' => $txt_color . '_avatar_text'
) ;
return $image_block_params [ $title ] ;
}
/**
* Возвращает тег <img>
* @param array|yaml $image Все размеры заданного изображения
* @param string $size_preset Название пресета
* @param string $alt Замещающий текст изображения
* @param array $attributes Массив аттрибутов тега
* @return string
*/
function html_image
( $image , $size_preset = 'small' , $alt = '' , $attributes = array ( ) ) {
list ( $small_preset , $modal_preset ) = $size_preset ; } else {
$small_preset = $size_preset ;
$modal_preset = false ;
}
$src = html_image_src( $image , $small_preset , true ) ;
if ( ! $src ) { return '' ; }
$size = $small_preset == 'micro' ? 'width="32" height="32"' : '' ;
$attr_str = html_attr_str( $attributes ) ;
$class = isset ( $attributes [ 'class' ] ) ?
' class="' . $attributes [ 'class' ] . '"' : '' ;
$image_html = '<img src="' . $src . '" ' . $size . ' title="' . $title . '" alt="' . htmlspecialchars ( $alt ) . '" ' . $attr_str . $class . ' />' ;
if ( $modal_preset ) {
$modal_src = html_image_src( $image , $modal_preset , true ) ;
if ( $modal_src ) {
return '<a title="' . $title . '" class="ajax-modal modal_image hover_image" href="' . $modal_src . '">' . $image_html . '</a>' ;
}
}
return $image_html ;
}
/**
* Возвращает тег HTML gif изображения
* @param array|yaml $image Все размеры заданного изображения
* @param string $size_preset Название пресета
* @param string $alt Замещающий текст изображения
* @param array $attributes Массив аттрибутов тега
* @return string
*/
function html_gif_image
( $image , $size_preset = 'small' , $alt = '' , $attributes = array ( ) ) {
$class = isset ( $attributes [ 'class' ] ) ?
$attributes [ 'class' ] : '' ; if ( $size_preset == 'micro' ) {
$class .= ' micro_image' ;
}
$original_src = html_image_src( $image , 'original' , true ) ;
$preview_src = html_image_src( $image , $size_preset , true ) ;
if ( ! $preview_src ) { return '' ; }
return '<a class="ajax-modal gif_image ' . $class . '" href="' . $original_src . '" ' . html_attr_str( $attributes ) . '>
<span class="background_overlay"></span>
<span class="image_label">gif</span>
</a>' ;
}
/**
* Генерирует список опций
* @param string $name Имя списка
* @param array $items Массив элементов списка (значение => заголовок)
* @param string $selected Значение выбранного элемента
* @param array $attributes Массив аттрибутов тега
* @return html
*/
function html_select
( $name , $items , $selected = '' , $attributes = array ( ) ) {
$attr_str = html_attr_str( $attributes ) ;
$class = isset ( $attributes [ 'class' ] ) ?
' class="' . $attributes [ 'class' ] . '"' : '' ; $html = '<select name="' . $name . '" ' . $attr_str . $class . '>' . "\n " ;
$optgroup = false ;
foreach ( $items as $value => $title ) {
if ( $optgroup !== false ) {
$html .= "\t " . '</optgroup>' . "\n " ;
$optgroup = false ;
}
$optgroup = true ;
continue ;
}
$sel = ( ( string) $selected === ( string) $value ) ? 'selected' : '' ;
}
}
if ( $optgroup !== false ) {
$html .= "\t " . '</optgroup>' . "\n " ;
}
$html .= '</select>' . "\n " ;
return $html ;
}
/**
* Генерирует список опций с множественным выбором
* @param string $name Имя списка
* @param array $items Массив элементов списка (значение => заголовок)
* @param string $selected Массив значений выбранных элементов
* @param array $attributes Массив аттрибутов тега
* @return html
*/
function html_select_multiple
( $name , $items , $selected = array ( ) , $attributes = array ( ) , $is_tree = false ) { $attr_str = html_attr_str( $attributes ) ;
$html = '<div class="input_checkbox_list" ' . $attr_str . '>' . "\n " ;
$start_level = false ;
foreach ( $selected as $k => $v ) {
}
}
foreach ( $items as $value => $title ) {
if ( $is_tree ) {
if ( $start_level === false ) { $start_level = $level ; }
$level = $level - $start_level ;
$title = ltrim ( $title , '- ' ) ;
$html .= "\t " . '<label ' . ( $level > 0 ? 'style="margin-left:' . ( $level * 20 ) . 'px"' : '' ) . '>' .
html_checkbox( $name . '[]' , $checked , $value ) . ' ' .
} else {
$html .= "\t " . '<label>' .
html_checkbox( $name . '[]' , $checked , $value ) . ' ' .
}
}
$html .= '</div>' . "\n " ;
return $html ;
}
/**
* Генерирует и возвращает дерево категорий в виде комбо-бокса
* @param array $tree Массив с элементами дерева NS
* @param int $selected_id ID выбранного элемента
* @return html
*/
function html_category_list( $tree , $selected_id = 0 ) {
$html = '<select name="category_id" id="category_id" class="combobox">' . "\n " ;
foreach ( $tree as $cat ) {
$padding = str_repeat ( '---' , $cat [ 'ns_level' ] ) . ' ' ; if ( $selected_id == $cat [ 'id' ] ) { $selected = 'selected' ; } else { $selected = '' ; }
$html .= "\t " . '<option value="' . $cat [ 'id' ] . '" ' . $selected . '>' . $padding . ' ' . htmlspecialchars ( $cat [ 'title' ] ) . '</option>' . "\n " ; }
$html .= '</select>' . "\n " ;
return $html ;
}
/**
* Генерирует две радио-кнопки ВКЛ и ВЫКЛ
* @param string $name
* @param bool $active
* @return html
*/
function html_switch( $name , $active ) {
$html = '' ;
$html .= '<label><input type="radio" name="' . $name . '" value="1" ' . ( $active ? 'checked' : '' ) . '/> ' . LANG_ON . "</label> \n " ;
$html .= '<label><input type="radio" name="' . $name . '" value="0" ' . ( ! $active ? 'checked' : '' ) . '/> ' . LANG_OFF . "</label> \n " ;
return $html ;
}
function html_bool_span( $value , $condition ) {
if ( $condition ) {
return '<span class="positive">' . $value . '</span>' ;
} else {
return '<span class="negative">' . $value . '</span>' ;
}
}
/**
* Строит рекурсивно список UL из массива
* @author acmol
* @param array $array
* @return string
*/
function html_array_to_list( $array ) {
$html = '<ul>' . "\n " ;
foreach ( $array as $key => $elem ) {
$html = $html . '<li>' . $elem . '</li>' . "\n " ;
}
else {
$html = $html . '<li class="folder">' . $key . ' ' . html_array_to_list( $elem ) . '</li>' . "\n " ;
}
}
$html = $html . "</ul>" . "\n " ;
return $html ;
}
function html_tags_bar( $tags ) {
if ( ! $tags ) { return '' ; }
}
foreach ( $tags as $id => $tag ) {
$tags [ $id ] = '<a href="' . href_to
( 'tags' , 'search' ) . '?q=' . urlencode ( $tag ) . '">' . $tag . '</a>' ; }
return $tags_bar ;
}
Самые дешевые и быстрые
VPS |
Продвижение в соцсетях