예제 #1
0
function agree_update($touid, $pid, $tid, $fid, $isfirst)
{
    global $conf, $time, $group, $longip, $sid, $uid, $gid, $user;
    //user_login_check($user);
    if (!forum_access_user($fid, $gid, 'allowagree')) {
        return xn_error(10, '您(' . $user['groupname'] . ')无权限在此版块点喜欢');
    }
    if ($uid > 0) {
        // 每日最大喜欢数限制
        if ($time - $user['last_agree_date'] > 86400) {
            user__update($uid, array('last_agree_date' => $time));
            $user['today_agrees'] = 0;
        }
        $user['last_agree_date'] = $time;
        $user['today_agrees']++;
        if ($user['today_agrees'] > $group['maxagrees']) {
            return xn_error(-1, '请您休息会,您所在的用户组每日最大喜欢数为:' . $group['maxagrees']);
        }
        $agree = myagree_read($pid, $uid);
        if ($agree) {
            // 取消喜欢
            $r = myagree_delete($uid, $pid, $isfirst);
            if ($r === FALSE) {
                return xn_error(2, '取消喜欢失败');
            }
            thread_tids_cache_delete_by_order($fid, 'agree');
            return xn_error(1, '取消喜欢成功');
            // 1 表示取喜欢喜欢,前台会根据此项判断减1
        } else {
            // 点击喜欢
            $r = myagree_create($uid, $touid, $pid, $tid, $isfirst);
            if ($r === FALSE) {
                return xn_error(2, '点喜欢失败');
            }
            thread_tids_cache_delete_by_order($fid, 'agree');
            return xn_error(0, '点喜欢成功');
        }
    } else {
        // ip 限制
        $n = guest_agree_count_by_ip($longip);
        if ($n > $group['maxagrees']) {
            return xn_error(-1, '请您休息会,您所在的用户组每日最大喜欢数为:' . $group['maxagrees']);
        }
        // sid 限制
        $agree = guest_agree_read($sid, $pid);
        if ($agree) {
            // 取消喜欢
            $r = guest_agree_delete($sid, $pid, $touid, $isfirst ? $tid : 0);
            if ($r === FALSE) {
                return xn_error(2, '取消喜欢失败');
            }
            thread_tids_cache_delete_by_order($fid, 'agree');
            return xn_error(1, '取消喜欢成功');
            // 1 表示取消喜欢,前台会根据此项判断减1
        } else {
            // 点击喜欢
            $r = guest_agree_create($sid, $longip, $pid, $touid, $isfirst ? $tid : 0);
            if ($r === FALSE) {
                return xn_error(2, '点喜欢失败');
            }
            thread_tids_cache_delete_by_order($fid, 'agree');
            return xn_error(0, '点喜欢成功');
        }
    }
}
예제 #2
0
function post_delete($pid)
{
    global $conf;
    $post = post_read_cache($pid);
    if (empty($post)) {
        return TRUE;
    }
    // 已经不存在了。
    $tid = $post['tid'];
    $uid = $post['uid'];
    $thread = thread_read_cache($tid);
    $fid = $thread['fid'];
    $r = post__delete($pid);
    if ($r === FALSE) {
        return FALSE;
    }
    !$post['isfirst'] and thread__update($tid, array('posts-' => 1));
    !$post['isfirst'] and $uid and user__update($uid, array('posts-' => 1));
    !$post['isfirst'] and runtime_set('posts-', 1);
    // 清理赞同
    $uid and myagree_delete($uid, $pid, $post['isfirst']);
    // 清理缓存
    $post['isfirst'] and post_list_cache_delete($tid);
    $post['images'] || $post['files'] and attach_delete_by_pid($pid);
    return $r;
}