controller = $controller;
if( $app_specal){
$this->app = $app_specal;
}else{
$this->app = $controller->app;
}
}
function table_begin(){
return '
';
}
function table_head($headers){
return '| '.implode(' | ',$headers).' | ';
}
function table_colset(){
}
function table_panel($html){
return ''.$html.'
';
}
function table_rows($rows){
foreach($rows as $row){
$return[] = '';
foreach($row as $k=>$v){
$return[]=$v;
}
$return[] = '
';
}
return implode('',$return);
}
function table_end(){
return '
';
}
function img($params){
if(is_string($params)){
$params = array('src'=>$params);
}
$app = $params['app'] ? app::get($params['app']) : $this->app;
if(!isset($this->_imgbundle[$app->app_id])){
$bundleinfo = array();
//base_kvstore::instance('imgbundle')->fetch('imgbundle_' . $app->app_id, $bundleinfo);
$this->_imgbundle[$app->app_id] = (array)$bundleinfo;
}
if(is_array($this->_imgbundle[$app->app_id]['info']) && array_key_exists($params['src'], $this->_imgbundle[$app->app_id]['info'])){
$img_info = $this->_imgbundle[$app->app_id]['info'][$params['src']];
$params['lib'] = kernel::base_url(1) . '/' . $this->_imgbundle[$app->app_id]['bundleimg'] . '?' . $this->_imgbundle[$app->app_id]['mtime'];
$params['src'] = app::get('base')->res_url.'/transparent.gif';
$style = "background-image:url({$params['lib']});background-position:0 {$img_info[0]}px;width:{$img_info[1]}px;height:{$img_info[2]}px";
$params['style'] = $params['style']?($params['style'].';'.$style):$style;
$params['class'] = $params['class']?('imgbundle '.$params['class']):'imgbundle';
}else{
$params['src'] = $app->res_url.'/'.$params['src'];
}
unset($params['lib']);
return utils::buildTag($params,'img');
}
function input($params){
if($params['params']){
$p = $params['params'];
unset($params['params']);
$params = array_merge($p,$params);
}
if(is_array($params['type'])){
$params['options'] = $params['type'];
$params['type'] = 'select';
}
if(!array_key_exists('value',$params) && array_key_exists('default',$params)){
$params['value'] = $params['default'];
}
if(!$params['id']){
$params['id'] = $this->new_dom_id();
}
if(substr($params['type'],0,6)=='table:'){
list(,$params['object'],$params['app']) = preg_split('/[:|@]/',$params['type']);
$params['type'] = 'object';
if($params['name'] == 'cat_id' ){
$params['type'] = 'goodscat';
return $this->input_element('goodscat', $params);
}
if($this->input_element('object_'.$params['type'])){
return $this->input_element('object_'.$params['type'], $params);
}else{
return $this->input_element('object', $params);
}
}elseif($this->input_element($params['type'])){
return $this->input_element($params['type'],$params);
}else{
return $this->input_element('default',$params);
}
}
function input_element($type,$params=false){
if(!base_component_ui::$inputer){
if(kernel::is_online()){
base_component_ui::$inputer = kernel::servicelist('html_input');
}else{
base_component_ui::$inputer = array('base_view_input' => new base_view_input);
}
}
if($params===false){
foreach(base_component_ui::$inputer as $inputer){
$inputer->app = $this->app;
if(method_exists($inputer,'input_'.$type)){
return true;
}
}
}else{
foreach(base_component_ui::$inputer as $inputer){
$inputer->app = $this->app;
if(method_exists($inputer,'input_'.$type)){
$html = $inputer->{'input_'.$type}($params);
}
}
return $html;
}
return false;
}
function form_start($params=null){
if(is_string($params)){
$params = array('action'=>$params);
}
if(!$params['action']){
$params['action'] = 'index.php?'.$_SERVER['QUERY_STRING'];
}
array_unshift($this->_form_path,$params);
$return = '';
if($params['title']){
$return.=''.$params['title'].'
';
unset($params['title']);
}
$return .='';
}
$return .='';
$this->form_tab_html = null;
return $return;
}
function button($params){
if($params['class']){
$params['class'] = 'btn '.$params['class'];
}else{
$params['class'] = 'btn';
}
if($params['icon']){
$icon = ''.$this->img(array('src'=>'bundle/'.$params['icon'], 'app'=>$params['app'])).'';
$params['class'] .= ' btn-has-icon';
unset($params['icon']);
}
$app = $params['app']?app::get($params['app']):$this->app;
if($params['label']){
$label = htmlspecialchars($app->_($params['label']));
unset($params['label']);
}
$type = $params['type'];
if($type=='link'){
$element = 'a';
}else{
$element = 'button';
if($params['href']){
$params['onclick'] = 'W.page(\''.$params['href'].'\')';
unset($params['href']);
}
if($type!='submit'){
$params['type'] = 'button';
}
}
if($params['dropmenu']){
if(!$params['id']){
$params['id'] = $this->new_dom_id();
}
if($type!='dropmenu'){
$element = 'span';
$class .= ' btn-drop-menu drop-active';
$drop_handel_id = $params['id'].'-handel';
$dropmenu = '
';
unset($params['dropmenu']);
}else{
$drop_handel_id = $params['id'];
$dropmenu = '
';
}
$scripts = '';
}
return utils::buildTag($params,$element,0).''.$icon.$label.$dropmenu.''.$element.'>'.$script;
}
function script($params){
$app = $params['app']?app::get($params['app']):$this->app; //todo:APP机制了,每个APP自己控制
$pdir = (defined('DEBUG_JS') && constant('DEBUG_JS'));
if( $params['pdir'] && !$pdir ){
$pdir = $params['pdir'];
}else{
$pdir = 'js';
}
$file = $app->res_dir.'/'.$pdir.'/'.$params['src'];
if($params['content']){
return '';
}else{
$time = substr(cachemgr::ask_cache_check_version(), 0, 6);
return '';
}
}
function css($params)
{
$default = array(
'rel' => 'stylesheet',
'type' => 'text/css',
'media' => 'screen, projection',
);
$app = $params['app']?app::get($params['app']):$this->app;
$pdir = (defined('DEBUG_CSS') && constant('DEBUG_CSS'));
if( $params['pdir'] && !$pdir ){
$pdir = $params['pdir'];
}else{
$pdir = 'css';
}
if (is_dir($app->res_dir.'/'.$pdir))
$file = $app->res_url.'/'.$pdir.'/'.$params['src'];
else
$file = $app->res_url.'/'.$params['src'];
if ($params['pdir']) unset($params['pdir']);
if(isset($params['src'])) unset($params['src']);
if(isset($params['app'])) unset($params['app']);
$params = count($params) ? $params+$default : $default;
foreach($params AS $k=>$v){
$ext .= sprintf('%s="%s" ', $k, $v);
}
$time = substr(cachemgr::ask_cache_check_version(), 0, 6);
$file = $file . '?' . $time;
return sprintf('', $file, $ext);
}//End Function
function tree($model,$template='%2$s'){
$pagelimit = 20;
$model = $this->app->model($model);
$pid = intval($_GET['tree']['pid']);
$offset = intval($_GET['tree']['p']);
foreach($model->schema['columns'] as $k=>$col){
if($col['parent_id']){
$pid_col = $k;
}
}
$items = $model->getList($model->idColumn.','.$model->textColumn,array($pid_col=>$pid),$offset,$pagelimit);
foreach($items as $item){
$html.=sprintf('
'
.$template.''
,$item[$model->idColumn],$item[$model->textColumn]);
}
$count = $model->count(array($pid_col=>$pid));
$current = $offset+count($items);
if($count>$current){
$html.=''.($count-$current).app::get('base')->_('个未显示').'…
';
}
if($_GET['act']=='treenode'){
return $html;
}else{
$new_dom_id = $this->new_dom_id();
$params = json_encode(array('args'=>func_get_args()));
return <<{$html}
EOF;
}
}
function pager($params){
if(substr($params['link'],0,11)=='javascript:'){
$tag = 'span';
$this->pager_attr = 'onclick';
$params['link'] = substr($params['link'],11);
}else{
$tag = 'a';
$this->pager_attr = 'href';
}
$this->pager_tag = $tag;
if(!$params['current'])$params['current'] = 1;
if(!$params['total'])$params['total'] = 1;
if($params['total']<2){
return '';
}
if(!$params['nobutton']){
if($params['current']>1){
$prev = '<'.$tag.' '.$this->pager_attr.'="'.sprintf($params['link'],$params['current']-1)
.'" class="prev">«'.$tag.'>';
}else{
$prev = '«';
}
if($params['current']<$params['total']){
$next = '<'.$tag.' '.$this->pager_attr.'="'.sprintf($params['link'],$params['current']+1)
.'" class="next">»'.$tag.'>';
}else{
$next = '»';
}
}
$c = $params['current']; $t=$params['total']; $v = array(); $l=$params['link'];;
if($t<11){
$v[] = $this->pager_link(1,$t,$l,$c);
//123456789
}else{
if($t-$c<8){
$v[] = $this->pager_link(1,3,$l);
$v[] = $this->pager_link($t-8,$t,$l,$c);
//12..50 51 52 53 54 55 56 57
}elseif($c<10){
$v[] = $this->pager_link(1,max($c+3,10),$l,$c);
$v[] = $this->pager_link($t-1,$t,$l);
//1234567..55
}else{
$v[] = $this->pager_link(1,3,$l);
$v[] = $this->pager_link($c-2,$c+3,$l,$c);
$v[] = $this->pager_link($t-1,$t,$l);
//123 456 789
}
}
$links = implode('…',$v);
return <<