public static function header($page = array()) { $page['js'] = array_merge(array('jquery' => url::common() . '/js/jquery.js', 'plugins' => url::common() . '/js/jquery.plugins.js', 'zotop' => url::common() . '/js/zotop.js'), (array) $page['js']); $page['css'] = array_merge(array('zotop' => url::theme() . '/css/zotop.css', 'global' => url::theme() . '/css/global.css'), (array) $page['css']); $page = self::settings($page); $html[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $html[] = '<html xmlns="http://www.w3.org/1999/xhtml">'; $html[] = '<head>'; $html[] = ' <title>' . $page['title'] . ' Powered by ' . zotop::config("zotop.title") . '</title>'; $html[] = self::meta($page['meta']); $html[] = self::stylesheet($page['css']); $html[] = self::script($page['js']); $html[] = ' ' . html::link(url::theme() . '/image/fav.ico', array('rel' => 'shortcut icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link(url::theme() . '/image/fav.ico', array('rel' => 'icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link(url::theme() . '/image/fav.ico', array('rel' => 'bookmark', 'type' => 'image/x-icon')); $html[] = ' <script type="text/javascript">'; $html[] = ' zotop.url.base = "' . url::base() . '";'; $html[] = ' zotop.url.common = "' . url::common() . '";'; $html[] = ' zotop.page.id = "' . page::id() . '";'; $html[] = ' zotop.user.id =0;'; $html[] = ' zotop.user.username = "";'; $html[] = ' </script>'; $html[] = '</head>'; $html[] = '<body' . html::attributes($page['body']) . '>'; $html[] = '<div id="wrapper">'; $html[] = ''; $str = implode("\n", $html); echo $str; }
public static function header($form = array()) { if (isset($form['template'])) { form::$template = arr::take('template', $form); } $attrs['class'] = isset($form['class']) ? $form['class'] : 'form'; $attrs['method'] = isset($form['method']) ? $form['method'] : 'post'; $attrs['action'] = isset($form['action']) ? $form['action'] : url::current(); //加载表头 $html[] = ''; $html[] = '<form' . html::attributes($attrs) . '>'; $html[] = field::hidden(array('name' => '_REFERER', 'value' => request::referer())); $html[] = field::hidden(array('name' => '_FORMHASH', 'value' => form::hash())); //加载常用js $html[] = html::script(url::common() . '/js/jquery.validate.js'); $html[] = html::script(url::common() . '/js/jquery.validate.additional.js'); $html[] = html::script(url::common() . '/js/jquery.form.js'); //表单头部 if (isset($form['title']) || isset($form['description'])) { $html[] = '<div class="form-header clearfix">'; $html[] = isset($form['icon']) ? ' <div class="form-icon"></div>' : ''; $html[] = isset($form['title']) ? ' <div class="form-title">' . $form['title'] . '</div>' : ''; $html[] = isset($form['description']) ? ' <div class="form-description">' . $form['description'] . '</div>' : ''; $html[] = '</div>'; } //表单body部分开始 $html[] = '<div class="form-body">'; echo implode("\n", $html); }
public function __toString() { $html = '<tr' . html::attributes($this->attributes) . ' >'; foreach ($this->elements as $element) { $html .= $element->toString(); } return $html . '</tr>'; }
public function init($id = false, $attributes = false) { $this->display_glob = false; $this->name_col = false; $this->display_th = false; $this->display_row = false; $this->limit_pager = false; $this->id_table = $id; $this->attribut = is_array($attributes) ? html::attributes($attributes) : ''; return $this; }
public function getPartialsTemplate() { $template = '<thead' . html::attributes($this->attributes) . ' >'; foreach ($this->elements as $element) { if ($element->isTemplate()) { $template .= '{{#head}}{{>head}}{{/head}}'; } else { $template .= $element->toString(); } } return $template . '</thead>'; }
public static function header($header = array()) { $attrs['class'] = isset($header['class']) ? $header['class'] : 'form'; $attrs['method'] = isset($header['method']) ? $header['method'] : 'post'; $attrs['action'] = isset($header['action']) ? $header['action'] : url::current(); $html[] = ''; $html[] = '<form' . html::attributes($attrs) . '>'; $html[] = isset($header['title']) ? '<div class="form-title">' . $header['title'] . '</div>' : ''; $html[] = isset($header['title']) ? '<div class="form-description">' . $header['description'] . '</div>' : ''; $html[] = html::script(url::theme() . '/js/jquery.form.js'); $html[] = html::script(url::theme() . '/js/zotop.form.js'); echo implode("\n", $html); }
public function thumb_img($extra_attrs = array(), $max = null, $center_vertically = false) { list($height, $width) = $this->scale_dimensions($max); if ($center_vertically && $max) { // The constant is divide by 2 to calculate the file and 10 to convert to em $margin_top = (int) (($max - $height) / 20); $extra_attrs["style"] = "margin-top: {$margin_top}em"; $extra_attrs["title"] = $this->title; } $attrs = array_merge($extra_attrs, array("src" => $this->thumb_url(), "alt" => $this->title, "width" => $width, "height" => $height)); // html::image forces an absolute url which we don't want return "<img" . html::attributes($attrs) . "/>"; }
public static function anchor_lang($lang, $uri, $title = NULL, $attributes = NULL, $protocol = NULL) { if ($uri === '') { $site_url = url::base(FALSE); } elseif (strpos($uri, '://') === FALSE and strpos($uri, '#') !== 0) { $site_url = url::site_lang($lang, $uri, $protocol); } else { if (html::$windowed_urls === TRUE and empty($attributes['target'])) { $attributes['target'] = '_blank'; } $site_url = $uri; } return '<a href="' . html::specialchars($site_url, FALSE) . '"' . (is_array($attributes) ? html::attributes($attributes) : '') . '>' . ($title === NULL ? $site_url : $title) . '</a>'; }
public static function header($header = array()) { $header = self::settings($header); $html[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $html[] = '<html xmlns="http://www.w3.org/1999/xhtml">'; $html[] = '<head>'; $html[] = ' <title>' . $header['title'] . ' ' . zotop::config("zotop.title") . '</title>'; $html[] = page::meta($header['meta']); $html[] = page::stylesheet($header['css']); $html[] = page::script($header['js']); $html[] = '</head>'; $html[] = '<body' . html::attributes($header['body']) . '>'; $str = implode("\n", $html); echo $str; }
public static function render($datas = array(), $attrs = array()) { $datas = empty($datas) ? table::$datas : $datas; $attrs = empty($attrs) ? table::$attrs : $attrs; $titles = arr::take('titles', $attrs); $footer = table::$footer; $attrs['class'] = empty($attrs['class']) ? 'table' : 'table ' . $attrs['class']; //渲染表格 $html[] = ''; $html[] = '<table' . html::attributes($attrs) . '>'; if (is_array($titles)) { $html[] = ' <thead>'; $html[] = ' <tr class="title">'; foreach ($titles as $name => $title) { $html[] = ' <th class="' . $name . '"><b>' . $title . '</b></th>'; } $html[] = ' </tr>'; $html[] = ' </thead>'; } $html[] = ' <tbody>'; if (is_array($datas) && !empty($datas)) { $i = 0; foreach ($datas as $row) { $html[] = ''; $html[] = ' <tr class="item ' . ($i % 2 == 0 ? 'odd' : 'even') . ' ' . $row['class'] . '">'; foreach ($row['data'] as $key => $value) { if (is_string($value)) { $html[] = ' <td class="' . $key . '">' . $value . '</td>'; } else { $data = arr::take('value', $value); $html[] = ' <td' . html::attributes($value) . '>' . $data . '</td>'; } } $html[] = ' </tr>'; $i++; } } else { $html[] = ' <tr><td colspan="' . count($titles) . '"><div class="zotop-empty">' . zotop::t('未能找到符合要求的数据') . '</div></td></tr>'; } $html[] = ' </tbody>'; if (!empty($footer)) { $html[] = ' <tr class="footer"><td colspan="' . count($titles) . '">' . $footer . '</td></tr>'; } $html[] = '</table>'; return implode("\n", $html); }
public static function header($header = array()) { if (isset($header['template'])) { form::$template = arr::take('template', $header); } $attrs['class'] = isset($header['class']) ? $header['class'] : 'form'; $attrs['method'] = isset($header['method']) ? $header['method'] : 'post'; $attrs['action'] = isset($header['action']) ? $header['action'] : url::current(); $html[] = ''; $html[] = '<form' . html::attributes($attrs) . '>'; $html[] = isset($header['title']) ? '<div class="form-title">' . $header['title'] . '</div>' : ''; $html[] = isset($header['description']) ? '<div class="form-description">' . $header['description'] . '</div>' : ''; $html[] = field::hidden(array('name' => '_REFERER', 'value' => request::referer())); $html[] = html::script(url::common() . '/js/jquery.validate.js'); $html[] = html::script(url::common() . '/js/jquery.validate.additional.js'); $html[] = html::script(url::common() . '/js/jquery.form.js'); $html[] = html::script(url::common() . '/js/zotop.form.js'); echo implode("\n", $html); }
public static function row($rows, $classname = '') { static $i = 0; if (is_array($rows)) { $html[] = ''; $html[] = ' <tr class="item ' . ($i % 2 == 0 ? 'odd' : 'even') . ' ' . $classname . '">'; foreach ($rows as $key => $value) { if (is_string($value)) { $html[] = ' <td class="' . $key . '">' . $value . '</td>'; } else { $inner = arr::take('inner', $value); $html[] = ' <td class="' . $key . '" ' . html::attributes($value) . '>' . $inner . '</td>'; } } $html[] = ' </tr>'; $i++; } echo implode("\n", $html); }
public function header() { $header = $this->render('header'); if (!$header) { $javascript = (array) $this->js; $css = (array) $this->css; $metas = (array) $this->meta; $html[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $html[] = '<html xmlns="http://www.w3.org/1999/xhtml">'; $html[] = '<head>'; $html[] = ' <title>' . $this->title . ' ' . zotop::config("zotop.title") . '</title>'; $html[] = ' ' . html::meta('keywords', $this->keywords . ' ' . zotop::config("zotop.keywords")); $html[] = ' ' . html::meta('description', $this->description . ' ' . zotop::config("zotop.description")); $html[] = ' ' . html::meta('Content-Type', 'text/html;charset=utf-8'); $html[] = ' ' . html::meta('X-UA-Compatible', 'IE=EmulateIE7'); foreach ($metas as $meta) { $html[] = ' ' . html::meta($meta); } $html[] = ' ' . html::stylesheet('$theme/css/zotop.css', array('id' => 'zotop')); $html[] = ' ' . html::stylesheet('$theme/css/global.css', array('id' => 'global')); foreach ($css as $stylesheet) { $html[] = ' ' . html::stylesheet($stylesheet); } $html[] = ' ' . html::script('$common/js/jquery.js', array('id' => 'jquery')); $html[] = ' ' . html::script('$common/js/jquery.plugins.js', array('id' => 'plugins')); $html[] = ' ' . html::script('$common/js/zotop.js', array('id' => 'zotop')); $html[] = ' ' . html::script('$common/js/global.js', array('id' => 'global')); foreach ($javascript as $js) { $html[] = ' ' . html::script($js); } $html[] = ' ' . html::link('$theme/image/favicon.ico', array('rel' => 'shortcut icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link('$theme/image/favicon.ico', array('rel' => 'icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link('$theme/image/favicon.ico', array('rel' => 'bookmark', 'type' => 'image/x-icon')); $html[] = '</head>'; $html[] = '<body' . html::attributes($this->body) . '>'; $html[] = '<div id="wrapper">'; $html[] = '<div id="page">'; $html[] = ''; $header = implode("\n", $html); } echo $header; }
public function header() { $html[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $html[] = '<html xmlns="http://www.w3.org/1999/xhtml">'; $html[] = '<head>'; $html[] = ' <title>' . $this->title . ' ' . zotop::config("zotop.title") . '</title>'; $html[] = ' ' . html::meta('keywords', $this->keywords); $html[] = ' ' . html::meta('description', $this->description); $html[] = ' ' . html::meta('Content-Type', 'text/html;charset=utf-8'); $html[] = ' ' . html::meta('X-UA-Compatible', 'IE=EmulateIE7'); $html[] = ' ' . html::stylesheet(ZOTOP_APP_URL_CSS . '/zotop.css', array('id' => 'zotop')); $html[] = ' ' . html::stylesheet(ZOTOP_APP_URL_CSS . '/global.css', array('id' => 'global')); $html[] = ' ' . html::link(ZOTOP_APP_URL_IMAGE . '/fav.ico', array('rel' => 'shortcut icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link(ZOTOP_APP_URL_IMAGE . '/fav.ico', array('rel' => 'icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link(ZOTOP_APP_URL_IMAGE . '/fav.ico', array('rel' => 'bookmark', 'type' => 'image/x-icon')); $html[] = '</head>'; $html[] = '<body' . html::attributes($this->body) . '>'; $str = implode("\n", $html); echo $str; }
public static function header($header = array()) { $header = self::settings($header); $html[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; $html[] = '<html xmlns="http://www.w3.org/1999/xhtml">'; $html[] = '<head>'; $html[] = ' <title>' . $header['title'] . ' ' . zotop::config("zotop.title") . '</title>'; $html[] = self::meta($header['meta']); $html[] = self::stylesheet($header['css']); $html[] = self::script($header['js']); $html[] = ' <script type="text/javascript">'; $html[] = ' zotop.user.id =0;'; $html[] = ' zotop.user.username = "";'; $html[] = ' zotop.url.base = "' . url::base() . '";'; $html[] = ' </script>'; $html[] = '</head>'; $html[] = '<body' . html::attributes($header['body']) . '>'; $html[] = '<div id="wrapper">'; $str = implode("\n", $html); echo $str; }
public static function header($form = array()) { if (is_string($form)) { $form['description'] = $form; } form::$template = isset($form['template']) ? $form['template'] : form::$template; form::$globalid = isset($form['globalid']) ? $form['globalid'] : form::$globalid; //form 标签 $attrs['class'] = isset($form['class']) ? $form['class'] : 'form'; $attrs['method'] = isset($form['method']) ? $form['method'] : 'post'; $attrs['target'] = isset($form['target']) ? $form['target'] : ''; $attrs['action'] = isset($form['action']) ? $form['action'] : url::location(); if (isset($form['enctype']) || isset($form['upload'])) { $attrs['enctype'] = 'multipart/form-data'; } //加载表头 $html[] = ''; $html[] = '<form' . html::attributes($attrs) . '>'; $html[] = field::hidden(array('name' => '_REFERER', 'value' => request::referer())); $html[] = field::hidden(array('name' => '_FORMHASH', 'value' => form::hash())); $html[] = field::hidden(array('name' => '_GLOBALID', 'value' => form::globalid())); //加载常用js if ($form['valid'] !== false) { $html[] = html::script(ZOTOP_APP_URL_JS . '/jquery.validate.js'); } if ($form['ajax'] !== false) { $html[] = html::script(ZOTOP_APP_URL_JS . '/jquery.form.js'); } //表单头部 if (isset($form['title']) || isset($form['description'])) { $html[] = '<div class="form-header clearfix">'; $html[] = isset($form['title']) ? ' <div class="form-title">' . $form['title'] . '</div>' : ''; $html[] = isset($form['description']) ? ' <div class="form-description">' . $form['description'] . '</div>' : ''; $html[] = '</div>'; } //表单body部分开始 $html[] = '<div class="form-body">'; echo implode("\n", $html); }
public function header() { $javascript = (array) $this->js; $css = (array) $this->css; $metas = (array) $this->meta; $html[] = '<!DOCTYPE html>'; $html[] = '<html>'; $html[] = '<head>'; $html[] = ' <title>' . $this->title . ' ' . zotop::config("zotop.title") . '</title>'; $html[] = ' ' . html::meta('keywords', $this->keywords . ' ' . zotop::config("zotop.keywords")); $html[] = ' ' . html::meta('description', $this->description . ' ' . zotop::config("zotop.description")); $html[] = ' ' . html::meta('Content-Type', 'text/html;charset=utf-8'); $html[] = ' ' . html::meta('X-UA-Compatible', 'IE=EmulateIE7'); foreach ($metas as $meta) { $html[] = ' ' . html::meta($meta); } $html[] = ' ' . html::stylesheet('$theme/css/zotop.css', array('id' => 'zotop')); $html[] = ' ' . html::stylesheet('$theme/css/global.css', array('id' => 'global')); foreach ($css as $stylesheet) { $html[] = ' ' . html::stylesheet($stylesheet); } $html[] = ' ' . html::script('$common/js/jquery.js', array('id' => 'jquery')); $html[] = ' ' . html::script('$common/js/jquery.plugins.js', array('id' => 'plugins')); $html[] = ' ' . html::script('$common/js/zotop.js', array('id' => 'zotop')); $html[] = ' ' . html::script('$common/js/global.js', array('id' => 'global')); foreach ($javascript as $js) { $html[] = ' ' . html::script($js); } $html[] = ' ' . html::link('$theme/image/favicon.ico', array('rel' => 'shortcut icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link('$theme/image/favicon.ico', array('rel' => 'icon', 'type' => 'image/x-icon')); $html[] = ' ' . html::link('$theme/image/favicon.ico', array('rel' => 'bookmark', 'type' => 'image/x-icon')); $html[] = '</head>'; $html[] = '<body' . html::attributes($this->body) . '>'; $html[] = '<div id="wrapper">'; $html[] = '<div id="container" class="clearfix">'; $html[] = ''; echo implode("\n", $html); }
public static function fieldset($attrs) { $label = arr::take('label', $attrs); $description = arr::take('description', $attrs); $fields = (array) arr::take('fields', $attrs); $attrs['class'] = empty($attrs['class']) ? 'fieldset' : 'fieldset ' . $attrs['class']; $html[] = ''; $html[] = '<div' . html::attributes($attrs) . '>'; $html[] = empty($label) ? '' : '<div class="fieldset-title">' . $label . '</div>'; $html[] = '<div class="fieldset-body">'; foreach ($fields as $field) { $html[] = form::_field($field); } $html[] = '</div>'; $html[] = '</div>'; }
/** * 单选输入框 * * @param $attrs array 控件参数 * @return string 控件代码 */ public static function radio($attrs) { $options = arr::take('options', $attrs); $options = field::_option($options); $value = arr::take('value', $attrs); $attrs['class'] = isset($attrs['class']) ? 'radio ' . $attrs['class'] : 'radio'; //默认样式inline,允许传入block使得checkbox每个元素显示一行 $valid = arr::take('valid', $attrs); $html[] = '<ul' . html::attributes($attrs) . '>'; if (is_array($options)) { $i = 1; foreach ($options as $val => $text) { $checked = $val == $value ? ' checked="checked"' : ''; //这儿代码可能有问题,请检查 $html[] = ' <li>'; $html[] = ' <input type="radio" name="' . $attrs['name'] . '" id="' . $attrs['name'] . '-item' . $i . '" value="' . $val . '"' . $checked . '' . (isset($valid) && $i == 1 ? ' valid = "' . $valid . '"' : '') . '/>'; $html[] = ' <label for="' . $attrs['name'] . '-item' . $i . '">' . html::encode($text) . '</label>'; $html[] = ' </li>'; //这儿代码不完美 $i++; } } $html[] = '</ul>'; if (isset($valid)) { $html[] = '<label for="' . $attrs['name'] . '" class="error">' . $attrs['title'] . '</label>'; } return implode("\n", $html); }
/** * Creates a image link. * * @param string image source, or an array of attributes * @param string|array image alt attribute, or an array of attributes * @param boolean include the index_page in the link * @return string */ public static function image($src = NULL, $alt = NULL, $index = FALSE) { // Create attribute list $attributes = is_array($src) ? $src : array('src' => $src); if (is_array($alt)) { $attributes += $alt; } elseif (!empty($alt)) { // Add alt to attributes $attributes['alt'] = $alt; } if (strpos($attributes['src'], '://') === FALSE) { // Make the src attribute into an absolute URL $attributes['src'] = url::base($index) . $attributes['src']; } return '<img' . html::attributes($attributes) . ' />'; }
/** * Sorts a key/value array of HTML attributes, putting form attributes first, * and returns an attribute string. * * @param array HTML attributes array * @return string */ public static function attributes($attr, $type = NULL) { if (empty($attr)) { return ''; } if (isset($attr['name']) and empty($attr['id']) and strpos($attr['name'], '[') === FALSE) { if ($type === NULL and !empty($attr['type'])) { // Set the type by the attributes $type = $attr['type']; } switch ($type) { case 'text': case 'textarea': case 'password': case 'select': case 'checkbox': case 'file': case 'image': case 'button': case 'submit': // Only specific types of inputs use name to id matching $attr['id'] = $attr['name']; break; } } $order = array('action', 'method', 'type', 'id', 'name', 'value', 'src', 'size', 'maxlength', 'rows', 'cols', 'accept', 'tabindex', 'accesskey', 'align', 'alt', 'title', 'class', 'style', 'selected', 'checked', 'readonly', 'disabled'); $sorted = array(); foreach ($order as $key) { if (isset($attr[$key])) { // Move the attribute to the sorted array $sorted[$key] = $attr[$key]; // Remove the attribute from unsorted array unset($attr[$key]); } } // Combine the sorted and unsorted attributes and create an HTML string return html::attributes(array_merge($sorted, $attr)); }
/** * Creates a link tag. * * @param string|array filename * @param string|array relationship * @param string|array mimetype * @param string specifies suffix of the file * @param string|array specifies on what device the document will be displayed * @param boolean include the index_page in the link * @return string */ public static function link($href, $index = FALSE) { $attr = array('type' => "text/css", 'media' => 'all', 'rel' => "stylesheet", 'href' => $href); return '<link ' . html::attributes($attr) . ' />'; }
/** * Sorts a key/value array of HTML attributes, putting form attributes first, * and returns an attribute string. * * @param array HTML attributes array * @return string */ public static function attributes($attr, $type = NULL) { if (empty($attr)) { return ''; } $order = array('action', 'method', 'type', 'id', 'name', 'value', 'src', 'size', 'maxlength', 'rows', 'cols', 'accept', 'tabindex', 'accesskey', 'align', 'alt', 'title', 'class', 'style', 'selected', 'checked', 'readonly', 'disabled'); $sorted = array(); foreach ($order as $key) { if (isset($attr[$key])) { // Move the attribute to the sorted array $sorted[$key] = $attr[$key]; // Remove the attribute from unsorted array unset($attr[$key]); } } // Combine the sorted and unsorted attributes and create an HTML string return html::attributes(array_merge($sorted, $attr)); }
/** * Creates an embedded flash object. If you use an array of attributes, * define the flash source with the "data" key. * * @param string flash source, or an array of attributes * @param boolean include the index_page in the link * @return string */ public static function flash($data = nil, $index = NO) { // Create attribute list $attributes = is_array($data) ? $data : array('data' => $data); $attributes += array('type' => 'application/x-shockwave-flash', 'alt' => '<a href="http://www.adobe.com/go/getflashplayer">Please download Adobe Flash Player.</a>'); // Remove the alt text from the string $alt = $attributes['alt']; unset($attributes['alt']); if (strpos($attributes['data'], '://') === NO) { // Make the src attribute into an absolute URL $attributes['data'] = url::base($index) . $attributes['data']; } return '<object' . html::attributes($attributes) . '><param name="movie" value="' . $attributes['data'] . '" />' . $alt . '</object>'; }
switch ($info['column']['type']) { case 'textarea': echo form::textarea($ar, $val); break; case 'textbox': echo form::input($ar, $val); break; case 'password': echo form::password($ar); break; case 'dropdown': echo form::dropdown($ar, $info['column']['data'], (string) $val) . ' '; break; case 'date': $date_format = Kohana::config('scaffold.date_format'); echo '<input' . html::attributes(array('type' => 'hidden', 'id' => $name, 'name' => $name, 'value' => $val)) . ' />'; echo form::input(array('id' => $name . '_val'), strftime($date_format, $val), 'readonly'); echo '<script language="javascript">setup_cal("' . $name . '", "' . $date_format . '");</script>'; break; } } } echo '<br />'; } if (is_file(APPPATH . 'scaffold/' . $model_name . '/_edit' . EXT)) { include APPPATH . 'scaffold/' . $model_name . '/_edit' . EXT; } echo form::submit('', 'ok'); echo form::close(); ?> </fieldset>
/** * * This function will create the markup to convert * and array to a UL list * * @param array $array The array to convert * @param array $options The optional parameters to control the convertion * @param array $attributes The HTML params * @param string $keyName The name to use as the key * @param bool $_noUITag Part of the recursion to stop re-creation of UL tags * @return string HTML markup result */ public static function arrayToUL($array, $options = array(), $attributes = NULL, $keyName = NULL, $_noUlTag = false) { // Sanity check, if there is no array or it is empty there is nothing to do.... if (!is_array($array) || empty($array)) { return ''; } // This array will added any unset default options $options += array('recursive' => true, 'intKeys' => false, 'strKeys' => true, 'subKey' => false, 'seperator' => ': '); // Set the options array as vars in this function extract($options); // Create an empty string to append our elements to $list = ''; foreach ($array as $key => $value) { // If the value is a sub array and we are allow to recurse if (is_array($value) && $recursive) { // Determine what the lable for this value should be if ($subKey && $strKeys && is_string($key)) { $subKeyName = $key; } else { if ($subKey && $intKeys && is_int($key)) { $subKeyName = $key; } else { if (!empty($keyName)) { $subKeyName = $keyName; } else { $subKeyName = ''; } } } // Recurse into the element $list .= self::arrayToUL($value, $options, $attributes, $subKeyName, true); // If the value is not empty and not an array } else { if (!empty($value) && !is_array($value)) { // Add the value to the markup using the options to figure out what it should be labeled as if (!empty($keyName)) { $list .= '<li>' . $keyName . $seperator . $value . '</li>'; } else { if ($strKeys && is_string($key)) { $list .= '<li>' . $key . $seperator . $value . '</li>'; } else { if ($intKeys && is_int($key)) { $list .= '<li>' . $key . $seperator . $value . '</li>'; } else { $list .= '<li>' . $value . '</li>'; } } } } } } // If this was the parent wrap the list items in ul tags with any html attributes supplied if (!$_noUlTag) { return '<ul' . (is_array($attributes) ? ' ' . html::attributes($attributes) : '') . '>' . $list . '</ul>'; } else { // If this was the result of recursion just return the list string return $list; } }
public static function iframe($name, $src, $extra = array(), $noframe = '') { $attrs = array('id' => $name, 'name' => $name, 'src' => $src); $attrs += (array) $extra; return '<iframe' . html::attributes($attrs) . '>' . $noframe . '</iframe>'; }
<?php // Make sure attributes follow standard is_array($attributes) or $attributes = array(); $type = $ordered ? 'ol' : 'ul'; printf('<%s%s>', $type, html::attributes($attributes)); foreach ($items as $item) { $item[0] = html::attributes($item[0]); vprintf('<li%s>%s</li>', $item); } printf('</%s>', $type); /* End of file list.php */ /* Location: ./application/views/html/list.php */
/** * Return an <img> tag for the resize. * @param array $extra_attrs Extra attributes to add to the img tag * @return string */ public function resize_img($extra_attrs) { $attrs = array_merge($extra_attrs, array("src" => $this->resize_url(), "alt" => $this->title, "width" => $this->resize_width, "height" => $this->resize_height)); // html::image forces an absolute url which we don't want return "<img" . html::attributes($attrs) . "/>"; }
/** * 多选输入框 * * @param $attrs array 控件参数 * @return string 控件代码 */ public static function checkbox($attrs) { $options = array_take('options', $attrs); //取出options,并unset,这儿用了一个自定义的函数array_take //$options = html::options($options); //格式化数组 $value = array_take('value', $attrs); //即取出了value和options,又把他们从$attrs中去掉了 if (!is_array($value)) { $value = array($value); } $attrs['class'] = isset($attrs['class']) ? 'checkbox ' . $attrs['class'] : 'checkbox'; //默认样式inline,允许传入block使得checkbox每个元素显示一行 $html[] = '<ul' . html::attributes($attrs) . '>'; if (is_array($options)) { $i = 1; foreach ($options as $val => $text) { $checked = in_array($val, $value) ? ' checked="checked"' : ''; //这儿代码可能有问题,请检查 $html[] = '<li><input type="checkbox" name="' . $attrs['name'] . '[]" id="' . $attrs['name'] . '-item' . $i . '" value="' . $val . '"' . $checked . '/><label for="' . $attrs['name'] . '-item' . $i . '">' . html::encode($text) . '</label></li>'; //这儿代码不完美 $i++; } } $html[] = '</ul>'; return implode("\n", $html); }