chengkun
2025-04-29 a34a90f03cecc7658231547270f8036bb5affe4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
class Smarty_Internal_Compile_Downlist extends Smarty_Internal_CompileBase{
    public $required_attributes = array('item');
    public $optional_attributes = array('name', 'key', 'limit');
    public $shorttag_order = array('from', 'item', 'key', 'name');
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);
 
        $from = $_attr['from'];
        $item = $_attr['item'];
        if (!strncmp("\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) {
            $compiler->trigger_template_error("item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno);
        }
        
        //自定义标签 START
        //数据库操作       
        $OutputStr='global $db,$db_config,$config;
        $where="1";
        if($paramer[\'order\'])
        {
            $where.=" ORDER BY `".$paramer[\'order\']."`";
        }else{
            $where.=" ORDER BY `id`";
        }
        if($paramer[\'sort\'])
        {
            $where.=" ".$paramer[\'sort\'];
        }else{
            $where.=" DESC";
        }
        if($paramer[\'limit\'])
        {
            $limit=" LIMIT ".$paramer[\'limit\'];
        }else{
            $limit=" LIMIT 10";
        }
        $list=$db->select_all("down_resume",$where.$limit);
        if($list&&is_array($list)){
            $uids=$comids=array();
            foreach($list as $val){
                $uids[]=$val[\'uid\'];
                $comids[]=$val[\'comid\'];
            }
            $resume=$db->select_all("resume","`uid` in(".@implode(\',\',$uids).")","`uid`,`name`");
            $company=$db->select_all("company","`uid` in(".@implode(\',\',$comids).")","`uid`,`name`");
            foreach($list as $key=>$val){
                $time=time()-$val[\'downtime\'];
                if($time>86400 && $time<259300){
                    $list[$key][\'time\'] = ceil($time/86400)."天前";
                }elseif($time>3600 && $time<86400){
                    $list[$key][\'time\'] = ceil($time/3600)."小时前";
                }elseif($time>60 && $time<3600){
                    $list[$key][\'time\'] = ceil($time/60)."分钟前";
                }elseif($time<60){
                    $list[$key][\'time\'] = "刚刚";
                }else{
                    $list[$key][\'time\'] = date("Y-m-d",$val[\'downtime\']);
                }
                foreach($resume as $v){
                    if($v[\'uid\']==$val[\'uid\']){
                        $list[$key][\'username\']=$v[\'name\'];
                    }
                }
                foreach($company as $value){
                    if($val[\'comid\']==$value[\'uid\']){
                        $list[$key][\'comname\']=$value[\'name\'];
                    }
                }
                if($paramer[\'user_len\']){
                    $list[$key][\'username\']=mb_substr($list[$key][\'username\'],0,$paramer[\'user_len\'],"utf-8");
                }
                if($paramer[\'com_len\']){
                    $list[$key][\'comname\']=mb_substr($list[$key][\'comname\'],0,$paramer[\'com_len\'],"utf-8");
                }
                $list[$key][\'curl\']=Url("company",array("c"=>"show","id"=>$val[comid]));
                $list[$key][\'url\']=Url("resume",array("c"=>"show","id"=>$val[\'eid\']),"1");
            }
        }';//TODO:Url的生成函数应当统一在模版中生成,或者此类方法放在一个函数文件中统一引用(王成茁)
        //自定义标签 END
 
        return SmartyOutputStr($this,$compiler,$_attr,'downlist','$list',$OutputStr,'$list');
    }
}
class Smarty_Internal_Compile_Downlistelse extends Smarty_Internal_CompileBase{
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);
 
        list($openTag, $nocache, $item, $key) = $this->closeTag($compiler, array('downlist'));
        $this->openTag($compiler, 'downlistelse', array('downlistelse', $nocache, $item, $key));
 
        return "<?php }\nif (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
    }
}
class Smarty_Internal_Compile_Downlistclose extends Smarty_Internal_CompileBase{
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);
        if ($compiler->nocache) {
            $compiler->tag_nocache = true;
        }
 
        list($openTag, $compiler->nocache, $item, $key) = $this->closeTag($compiler, array('downlist', 'downlistelse'));
 
        return "<?php } ?>";
    }
}