chengkun
2025-05-23 0d8e263c22903234efea68fd13a27d8b7b59aac1
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
 
class link_model extends model {
    function get_cache() {
        include(LIB_PATH . "cache.class.php");
        $cacheM = new cache(PLUS_PATH, $this);
        $makecache = $cacheM->link_cache("link.cache.php");
    }
    
    /**
     * @desc   获取友情链接列表
     * @param  $whereData :查询条件
     * @param  $data :自定义处理数组
     */
    public function getList($whereData, $data = array()) {
        
        $select = $data['field'] ? $data['field'] : '*';
        
        $List = $this->select_all('admin_link', $whereData, $select);
        
        if (!empty($List)) {
            foreach ($List as $k => $v) {
                if ($v['pic']) {
                    $List[$k]['pic'] = checkpic($v['pic']);
                }
            }
        }
        
        return $List;
        
    }
    
    /**
     * @desc   获取工具箱详情
     */
    public function getInfo($where = array(), $data = array()) {
        
        $select = $data['field'] ? $data['field'] : '*';
        
        $Info = $this->select_once('admin_link', $where, $select);
        
        if ($Info['pic']) {
            $Info['pic_n'] = checkpic($Info['pic']);
        }
        
        return $Info;
    }
    
    /**
     * @desc   审核友情链接
     */
    function setLinkStatus($id, $data = array()) {
        if ($id) {
            
            $return['id'] = $this->update_once("admin_link", array('link_state' => $data['status']), array('id' => $id));
            
            if ($return['id']) {
                
                $this->get_cache();
                
                $return['msg'] = '友情链接审核成功!';
                $return['errcode'] = 9;
            } else {
                $return['msg'] = '友情链接审核失败!';
                $return['errcode'] = 8;
            }
        } else {
            $return['msg'] = '请选择审核数据!';
            $return['errcode'] = 8;
        }
        return $return;
    }
    
    function addInfo($data = array()) {
        $id = $data['id'];
        $post = $data['post'];
        if ($data['utype'] == 'index') {
            session_start();
            if (md5(strtolower($data['authcode'])) != $_SESSION['authcode'] || empty($_SESSION['authcode'])) {
                unset($_SESSION['authcode']);
                $return['msg'] = '验证码不正确!';
                $return['errcode'] = 8;
                return $return;
            }
            
        }
        if ($data['utype'] == 'admin') {
            if (preg_match("/[^\d-., ]/", $post['link_sorting'])) {
                $return['msg'] = '请正确填写,排序是数字!';
                $return['errcode'] = 8;
            }
        }
        if ($post['sorting'] == "") {
            $post['sorting'] = "0";
        }
        if ($post['phototype'] == "") {
            $post['phototype'] = "0";
        }
        if ($return['msg'] == '') {
            if ($id) {
                $return['id'] = $this->update_once("admin_link", $post, array('id' => $id));
                $msg = '修改';
            } else {
                
                $post['link_time'] = time();
                $return['id'] = $this->insert_into("admin_link", $post);
                $msg = '添加';
            }
            if ($return['id']) {
                $this->get_cache();
                if ($data['utype'] == 'index') {
                    $return['msg'] = '请等待管理员审核!';
                    require_once('admin.model.php');
                    $adminM = new admin_model($this->db, $this->def);
                    $adminM->sendAdminMsg(array('first' => '有新的友情链接《' . $post['link_name'] . '》需要审核', 'type' => 16));
                }
                if ($data['utype'] == 'admin') {
                    
                    $return['msg'] = '友情链接(ID:' . $return['id'] . ')' . $msg . '成功!';
                }
                $return['errcode'] = 9;
            } else {
                $return['msg'] = $msg . '失败!';
                $return['errcode'] = 8;
            }
        }
        
        return $return;
    }
    
    /**
     * @desc   删除友情链接
     */
    public function delInfo($id, $data = array()) {
        
        if (empty($id)) {
            
            return array(
                
                'errcode'   => 8,
                'msg'       => '请选择要删除的数据!',
                'layertype' => 0
            );
            
        } else {
            
            if (is_array($id)) {
                
                $ids = pylode(',', $id);
                $return['layertype'] = 1;
                
            } else {
                $ids = $id;
                $return['layertype'] = 0;
            }
            
            
            $return['id'] = $this->delete_all('admin_link', array('id' => array('in', $ids)), '');
            $this->get_cache();
            $return['msg'] = '友情链接(ID:' . $ids . ')';
            $return['errcode'] = $return['id'] ? '9' : '8';
            $return['msg'] = $return['id'] ? $return['msg'] . '删除成功!' : $return['msg'] . '删除失败!';
        }
        return $return;
    }
    
    public function setLinkSite($data = array()) {
        
        if ($data['uid']) {
            $ids = @explode(',', $data['uid']);
            $id = pylode(',', $ids);
            if ($id) {
                require_once('site.model.php');
                $siteM = new site_model($this->db, $this->def);
                $Table = array('admin_link');
                $siteM->updDid($Table, array('id' => array('in', $id)), array('did' => $data['did']));
                
                $this->get_cache();
                
                $return['msg'] = "友情链接(ID:" . $data['uid'] . ")分配站点成功!";
                $return['errcode'] = 9;
            } else {
                $return['msg'] = '请正确选择需分配用户!';
                $return['errcode'] = 8;
            }
        } else {
            $return['msg'] = '参数不全请重试!';
            $return['errcode'] = 8;
        }
        return $return;
    }
    
    /**
     * @desc 友情链接数目
     */
    function getLinkNum($where = array()) {
        return $this->select_num('admin_link', $where);
    }
}
 
?>