예제 #1
0
/**
 * Output a list of files and any extra attributes according to $template,
 * taking advantage of mod_concat if CONCAT is True.
 */
function _concat($template, $files, $attributes = array())
{
    if (defined('MOD_CONCAT') && MOD_CONCAT === True && count($files) > 1) {
        $files = array('??' . join(',', $files));
    }
    $extra = _attrs($attributes);
    $out = array();
    foreach ($files as $file) {
        $out[] = sprintf($template, $file, $extra);
    }
    return join("\n", $out);
}
예제 #2
0
 public function test_id()
 {
     $this->assertEquals(' id="myid"', _attrs(['id' => 'myid'], ['id']));
     $this->assertEquals(' id="my-id"', _attrs(['id' => 'my-id'], ['id']));
     $this->assertEquals(' id="my_id"', _attrs(['id' => 'my_id'], ['id']));
     $this->assertEquals(' id="my-id"', _attrs(['id' => 'my id'], ['id']));
     $this->assertEquals(' id="my-id"', _attrs(['id' => ' my id '], ['id']));
     $this->assertEquals(' id="my-id"', _attrs(['id' => ' My Id '], ['id']));
     $this->assertEquals(' id="my-id"', _attrs(['id' => ' MY ID '], ['id']));
     $this->assertEquals(' id="my-id"', _attrs(['id' => '   MY' . "\t" . 'ID   '], ['id']));
     $this->assertEquals(' id="voyti"', _attrs(['id' => 'войти'], ['id']));
     $this->assertEquals(' id="voyti"', _attrs(['id' => ' войти '], ['id']));
     $this->assertEquals(' id="voyti"', _attrs(['id' => ' Войти '], ['id']));
     $this->assertEquals(' id="voyti"', _attrs(['id' => ' ВОЙТИ '], ['id']));
     $this->assertEquals(' id="voyti-voyti"', _attrs(['id' => ' ВОЙТИ ВОЙТИ '], ['id']));
     $this->assertEquals(' id="complex-string-with-quotes"', _attrs(['id' => '"complex string \' with quotes"'], ['id']));
     $this->assertEquals(' id="complex_string_with_quotes"', _attrs(['id' => '"_complex_string_\'_with_quotes_"'], ['id']));
 }
예제 #3
0
 /**
  * For use inside table item template
  */
 function tbl_link($name, $link, $extra = [], $replace = [], $form)
 {
     if (is_array($name)) {
         $extra = (array) $extra + $name;
         $name = $extra['name'];
     }
     $extra['name'] = $extra['name'] ?: $name;
     $extra['link'] = $extra['link'] ?: $link;
     $func = function ($extra, $r, $form) {
         $link = $extra['link'];
         if (!$link && $extra['link_variants']) {
             foreach ((array) $extra['link_variants'] as $link_variant) {
                 if (isset($r[$link_variant])) {
                     $link = $link_variant;
                 }
             }
         }
         $link_url = isset($r[$link]) ? $r[$link] : $link;
         if ($link_url) {
             if (MAIN_TYPE_ADMIN && main()->ADMIN_GROUP != 1 && !_class('admin_methods')->_admin_link_is_allowed($link_url)) {
                 return '';
             }
         }
         if ($extra['rewrite']) {
             $link_url = url($link_url);
         }
         $icon = $extra['icon'] ? $extra['icon'] : _class('table2')->CLASS_ICON_BTN;
         $extra['href'] = $link_url;
         $extra['class'] = $extra['class'] ?: $form->CLASS_BTN_MINI . ($extra['class_add'] ? ' ' . $extra['class_add'] : '');
         $attrs_names = ['id', 'name', 'href', 'class', 'style', 'target', 'alt', 'title'];
         return ' <a' . _attrs($extra, $attrs_names) . '><i class="' . $icon . '"></i>' . (!$extra['hide_text'] ? ' ' . t($extra['name']) : '') . '</a> ';
     };
     if ($form->_chained_mode) {
         $form->_body[] = ['func' => $func, 'extra' => $extra, 'replace' => $replace, 'name' => __FUNCTION__];
         return $form;
     }
     return $func((array) $extra + (array) $form->_extra, (array) $replace + (array) $form->_replace, $form);
 }
예제 #4
0
파일: yf_assets.class.php 프로젝트: yfix/yf
 /**
  * Generate html output for desired asset out type and content type
  */
 public function html_out($out_type, $content_type, $str, $params = [])
 {
     if (!$out_type || !$content_type || !strlen($str)) {
         return false;
     }
     $func = __FUNCTION__;
     $out = '';
     $media_path = $this->_get_media_path();
     // try to find web path for file and show it as url
     if ($content_type === 'file') {
         if (substr($str, 0, strlen(PROJECT_PATH)) === PROJECT_PATH) {
             $url = $media_path . substr($str, strlen(PROJECT_PATH));
             return $this->{$func}($out_type, 'url', $url, $params);
         }
     }
     if ($content_type === 'url' && $this->SHORTEN_LOCAL_URL) {
         $slen = strlen($media_path);
         if (substr($str, 0, $slen) === $media_path) {
             $str = '/' . substr($str, $slen);
         }
     }
     if ($this->OUT_ADD_ASSET_NAME && $params['asset_name'] && !isset($params['id']) && in_array($content_type, ['inline', 'file'])) {
         $params['data-asset'] = 'asset_' . $out_type . '_' . $content_type . '_' . $params['asset_name'];
     }
     if ($out_type === 'js') {
         $params['type'] = 'text/javascript';
         if ($content_type === 'file') {
             $str = file_get_contents($str);
         }
         if ($this->INLINE_ASSETS_USE_DATA_URI && $content_type === 'inline') {
             $content_type = 'url';
             $params['src'] = 'data:' . $params['type'] . ';base64,' . base64_encode($this->_strip_js_input($str));
         } elseif ($this->FILE_ASSETS_USE_DATA_URI && strlen($str) <= $this->FILE_ASSETS_DATA_URI_MAX_SIZE) {
             $content_type = 'url';
             $params['src'] = 'data:' . $params['type'] . ';base64,' . base64_encode($str);
         }
         if ($content_type === 'url') {
             if (!isset($params['src'])) {
                 $params['src'] = $str . $this->_cached_url_get_mtime($str);
             }
             $out = '<script' . _attrs($params, ['src', 'type', 'class', 'id']) . '></script>';
         } elseif ($content_type === 'file') {
             $out = '<script' . _attrs($params, ['type', 'class', 'id']) . '>' . PHP_EOL . $str . PHP_EOL . '</script>';
         } elseif ($content_type === 'inline') {
             $str = $this->_strip_js_input($str);
             $out = '<script' . _attrs($params, ['type', 'class', 'id']) . '>' . PHP_EOL . $str . PHP_EOL . '</script>';
         }
     } elseif ($out_type === 'css') {
         $params['type'] = 'text/css';
         if ($content_type === 'file') {
             $str = file_get_contents($str);
         }
         if ($this->INLINE_ASSETS_USE_DATA_URI && $content_type === 'inline') {
             $content_type = 'url';
             $params['href'] = 'data:' . $params['type'] . ';base64,' . base64_encode($this->_strip_css_input($str));
         } elseif ($this->FILE_ASSETS_USE_DATA_URI && strlen($str) <= $this->FILE_ASSETS_DATA_URI_MAX_SIZE) {
             $content_type = 'url';
             $params['href'] = 'data:' . $params['type'] . ';base64,' . base64_encode($str);
         }
         if ($content_type === 'url') {
             $params['rel'] = 'stylesheet';
             if (!isset($params['href'])) {
                 $params['href'] = $str . $this->_cached_url_get_mtime($str);
             }
             $out = '<link' . _attrs($params, ['href', 'rel', 'class', 'id']) . ' />';
         } elseif ($content_type === 'file') {
             $out = '<style' . _attrs($params, ['type', 'class', 'id']) . '>' . PHP_EOL . $str . PHP_EOL . '</style>';
         } elseif ($content_type === 'inline') {
             $str = $this->_strip_css_input($str);
             $out = '<style' . _attrs($params, ['type', 'class', 'id']) . '>' . PHP_EOL . $str . PHP_EOL . '</style>';
         }
     }
     return $out;
 }
예제 #5
0
 /**
  */
 function form_row($content, $extra = [], $replace = [], $form)
 {
     $name = $extra['name'];
     $is_html_array = false !== strpos($name, '[');
     if ($is_html_array) {
         $name_dotted = str_replace(['[', ']'], ['.', ''], trim($name, ']['));
     }
     $no_label = false;
     if (isset($form->_params['no_label'])) {
         $no_label = $form->_params['no_label'];
     }
     if (isset($extra['no_label'])) {
         $no_label = $extra['no_label'];
     }
     $_css_group_map = ['errors' => $this->CLASS_ERROR, 'success' => $this->CLASS_SUCCESS, 'warnings' => $this->CLASS_WARNING, 'infos' => $this->CLASS_INFO];
     foreach ($_css_group_map as $_a => $_css_class) {
         if (isset($extra[$_a][$name]) || $is_html_array && isset($extra[$_a][$name_dotted])) {
             if ($extra['stacked']) {
                 $extra['class_add_stacked'] .= ' ' . $_css_class;
             } else {
                 $extra['class_add_form_group'] .= ' ' . $_css_class;
             }
             break;
         }
     }
     $class_form_group = $extra['class_form_group'] ?: $this->CLASS_FORM_GROUP . ($extra['class_add_form_group'] ? ' ' . $extra['class_add_form_group'] : '');
     if ($extra['class_add_wrapper']) {
         $class_form_group .= ' ' . $extra['class_add_wrapper'];
     }
     $class_label = $extra['class_label'] ?: $this->CLASS_LABEL . ($extra['class_add_label'] ? ' ' . $extra['class_add_label'] : '');
     $def_class_controls = $extra['buttons_controls'] ? $this->CLASS_CONTROLS_BUTTONS : $this->CLASS_CONTROLS;
     $def_class_no_label = $extra['buttons_controls'] ? $this->CLASS_NO_LABEL_BUTTONS : $this->CLASS_NO_LABEL;
     $class_controls = $extra['class_controls'] ?: $def_class_controls . ($extra['desc'] && !$no_label ? ' ' . $this->CLASS_DESC : $def_class_no_label) . ($extra['class_add_controls'] ? ' ' . $extra['class_add_controls'] : '');
     $form_group_extra = $extra['form_group'];
     $form_group_extra['class'] = $class_form_group;
     if ($form->_params['form_group_auto_id'] && !$form_group_extra['id'] && $extra['id']) {
         $form_group_extra['class'] .= ' form-group-id-' . $extra['id'];
     }
     $controls_extra = $extra['controls'];
     $controls_extra['class'] = $class_controls;
     $label_extra = $extra['control_label'];
     $label_extra['class'] = $class_label;
     $label_extra['for'] = $extra['id'];
     $label_tip_html = $extra['label_tip'] ? trim(' ' . tip($extra['label_tip'], $replace)) : '';
     $label = $extra['desc'] && !$no_label ? '<label' . _attrs($label_extra, ['id', 'class', 'style', 'for']) . '>' . t($extra['desc']) . $label_tip_html . '</label>' . PHP_EOL : '';
     $row_start = '<div' . _attrs($form_group_extra, ['id', 'class', 'style']) . '>' . PHP_EOL . $label . (!$extra['wide'] ? '<div' . _attrs($controls_extra, ['id', 'class', 'style']) . '>' . PHP_EOL : '');
     $row_end = (!$extra['wide'] ? '</div>' . PHP_EOL : '') . '</div>';
     $input_group_extra = $extra['input_group'];
     $input_group_extra['class'] = $input_group_extra['class'] ?: $this->CLASS_INPUT_GROUP . ' ' . ($extra['prepend'] ? $this->CLASS_INPUT_PREPEND : '') . ($extra['append'] ? ' ' . $this->CLASS_INPUT_APPEND : '');
     $input_group_extra['class'] .= ' ' . $input_group_extra['class_add'];
     $show_input_group = $extra['append'] || $extra['prepend'];
     $before_content_html = $show_input_group ? '<div' . _attrs($input_group_extra, ['id', 'class', 'style']) . '>' . PHP_EOL : '';
     $before_content_html .= $extra['prepend'] ? '<span class="' . $this->CLASS_ADDON . ($extra['class_prepend'] ? ' ' . $extra['class_prepend'] : '') . '">' . $extra['prepend'] . '</span>' . PHP_EOL : '';
     $after_content_html = $extra['append'] ? '<span class="' . $this->CLASS_ADDON . ($extra['class_append'] ? ' ' . $extra['class_append'] : '') . '">' . $extra['append'] . '</span>' . PHP_EOL : '';
     $after_content_html .= $show_input_group ? '</div>' . PHP_EOL : '';
     #		$after_content_html .= $extra['feedback_icon'] ? '<span class="'.$extra['feedback_icon'].' '.$this->CLASS_FEEDBACK.'" aria-hidden="true"></span>'.PHP_EOL : '';
     if ($extra['edit_link']) {
         if (MAIN_TYPE_ADMIN && main()->ADMIN_GROUP != 1 && !_class('admin_methods')->_admin_link_is_allowed($extra['edit_link'])) {
             $extra['edit_link'] = '';
         }
     }
     $edit_link_html = $extra['edit_link'] ? ' <a href="' . $extra['edit_link'] . '" class="' . $this->CLASS_EDIT_LINK . '"><i class="' . $this->CLASS_EDIT_ICON . '"></i> ' . t('Edit') . '</a>' . PHP_EOL : '';
     $link_name_html = $extra['link_url'] && $extra['link_name'] ? ' <a href="' . $extra['link_url'] . '" class="' . $this->CLASS_LINK_URL . '">' . t($extra['link_name']) . '</a>' . PHP_EOL : '';
     $inline_help_before = $extra['help_before'] ? '<span class="' . $this->CLASS_HELP . '">' . nl2br($extra['help_before']) . '</span>' . PHP_EOL : '';
     $inline_help_after = $extra['inline_help'] ? '<span class="' . $this->CLASS_HELP . '">' . nl2br($extra['inline_help']) . '</span>' . PHP_EOL : '';
     $inline_tip_html = $extra['tip'] ? ' ' . tip($extra['tip'], $replace) : '';
     if ($extra['only_row_start']) {
         return $row_start;
     } elseif ($extra['only_row_end']) {
         return $row_end;
     } elseif ($extra['stacked']) {
         $extra_stacked = is_array($extra['stacked']) ? $extra['stacked'] : [];
         if ($extra['class_stacked'] && !isset($extra_stacked['class'])) {
             $extra_stacked['class'] = $extra['class_stacked'];
         }
         $extra_stacked['class'] = ($extra_stacked['class'] ?: $this->CLASS_STACKED_ITEM) . ' ' . ($extra_stacked['class_add'] ?: $extra['class_add_stacked']);
         return '<span' . _attrs($extra_stacked, ['id', 'class', 'style']) . '>' . ($extra['show_label'] ? $label : '') . $inline_help_before . $before_content_html . $content . PHP_EOL . $after_content_html . $edit_link_html . $link_name_html . $inline_tip_html . $inline_help_after . '</span>';
     } else {
         // Full variant
         return $row_start . $inline_help_before . $before_content_html . $content . PHP_EOL . $after_content_html . $edit_link_html . $link_name_html . $inline_tip_html . $inline_help_after . $this->_add_rich_editor($extra, $replace, $form) . $row_end;
     }
 }
예제 #6
0
파일: yf_html.class.php 프로젝트: yfix/yf
 /**
  * Hyperlink container
  */
 function a()
 {
     $args = func_get_args();
     $a = [];
     // numerics params
     if (isset($args[0]) && is_array($args[0])) {
         $a = $args[0];
     } elseif (isset($args[0])) {
         $a['href'] = $args[0];
         $a['title'] = $args[1];
         $a['icon'] = $args[2];
         $a['text'] = $args[3];
         $a['class_add'] = $args[4];
         $a['target'] = $args[5];
         $a['no_text'] = $args[6];
         // named params
     } elseif (isset($args['link'])) {
         $a = $args;
     }
     if (isset($args['extra']) && is_array($args['extra'])) {
         foreach ($args['extra'] as $k => $v) {
             $a[$k] = $v;
         }
     }
     if (!isset($a['text'])) {
         $a['text'] = $a['title'] ?: $a['href'];
     }
     if ($a['href'] && substr($a['href'], 0, strlen('http')) !== 'http' && substr($a['href'], 0, strlen('//')) !== '//') {
         $a['href'] = url($a['href']);
     }
     if (!isset($a['class'])) {
         $a['class'] = 'btn btn-default btn-mini btn-xs';
     }
     if ($a['class_add']) {
         $a['class'] .= ' ' . $a['class_add'];
     }
     if (!isset($a['target'])) {
         $a['target'] = '_blank';
     }
     $icon = '';
     if (isset($a['icon'])) {
         $icon = [];
         if (!is_array($a['icon'])) {
             $a['icon'] = [$a['icon']];
         }
         foreach ((array) $a['icon'] as $i) {
             $icon[] = '<i class="' . $i . '"></i>';
         }
         $icon = implode('&nbsp;', $icon);
     }
     return '<a' . _attrs($a, ['href', 'title', 'class', 'style', 'id', 'rel', 'target', 'disabled']) . '>' . $icon . ($a['no_text'] ? '' : (strlen($a['text']) ? ($icon ? '&nbsp;' : '') . _prepare_html($a['text']) : '')) . '</a>';
 }
예제 #7
0
 /**
  * Helper to output placeholder image, by default output is data/image
  */
 function placeholder_img($extra = [])
 {
     if (!is_array($extra)) {
         $extra = [];
     }
     $w = (int) $extra['width'];
     $h = (int) $extra['height'];
     if ($extra['as_url']) {
         $extra['src'] = url('/dynamic/placeholder/' . $w . 'x' . $h);
     } else {
         require_once YF_PATH . 'share/functions/yf_placeholder_img.php';
         $img_data = yf_placeholder_img($w, $h, ['no_out' => true] + (array) $extra);
         $extra['src'] = 'data:image/png;base64,' . base64_encode($img_data);
     }
     return '<img' . _attrs($extra, ['src', 'type', 'class', 'id']) . ' />';
 }
예제 #8
0
파일: yf_table2.class.php 프로젝트: yfix/yf
 /**
  */
 function footer_submit($name = '', $extra = [])
 {
     if (is_array($name)) {
         $extra = $name;
         $name = $extra['name'];
     }
     $item = ['type' => __FUNCTION__, 'name' => $name, 'extra' => $extra, 'link' => $link, 'func' => function ($params, $instance_params, $table) {
         $extra = $params['extra'];
         $value = $params['name'] ? $params['name'] : 'Submit';
         if (is_array($value) && empty($extra)) {
             $extra = $value;
             $value = '';
         }
         $value = $extra['value'] ?: $value;
         $desc = $extra['desc'] ?: $value;
         $extra['type'] = 'submit';
         $extra['name'] = trim($extra['name'] ?: $value);
         $icon = $extra['icon'] ? ' ' . $extra['icon'] : $table->CLASS_ICON_SAVE;
         $class = $extra['class'] ?: $extra['a_class'] ?: $table->CLASS_BTN_MINI;
         $extra['class'] = $class;
         return '<button' . _attrs($extra, ['type', 'name', 'class', 'value']) . '><i class="' . trim($icon) . '"></i> ' . t($desc) . '</button>';
     }];
     if (!$extra['display_in']) {
         $extra['display_in'] = 'footer';
     }
     if ($extra['display_in'] == 'header' || $extra['copy_to_header']) {
         $this->_header_links[] = $item;
     }
     if ($extra['display_in'] == 'footer' || $extra['copy_to_footer']) {
         $this->_footer_links[] = $item;
     }
     return $this;
 }
예제 #9
0
파일: yf_form2.class.php 프로젝트: yfix/yf
 /**
  */
 function captcha($name = '', $desc = '', $extra = [], $replace = [])
 {
     if (is_array($desc)) {
         $extra = (array) $extra + $desc;
         $desc = '';
     }
     if (!is_array($extra)) {
         $extra = [];
     }
     $extra['name'] = $extra['name'] ?: ($name ?: 'captcha');
     $extra['desc'] = $this->_prepare_desc($extra, $desc);
     $func = function ($extra, $r, $form) {
         $form->_prepare_inline_error($extra);
         $extra['id'] = $form->_prepare_id($extra);
         $extra['required'] = true;
         $extra['value'] = $r['captcha'];
         $extra['input_attrs'] = _attrs($extra, ['class', 'style', 'placeholder', 'pattern', 'disabled', 'required', 'autocomplete', 'accept', 'value', 'size']);
         $extra = $form->_input_assign_params_from_validate($extra);
         return $form->_row_html(_class('captcha')->show_block(url('/dynamic/captcha_image'), $extra), $extra, $r);
     };
     if ($this->_chained_mode) {
         $this->_body[] = ['func' => $func, 'extra' => $extra, 'replace' => $replace, 'name' => __FUNCTION__];
         return $this;
     }
     return $func((array) $extra + (array) $this->_extra, (array) $replace + (array) $this->_replace, $this);
 }