Пример #1
0
    /**
    * 转发分享
    * @param array $_POST 提交的数据
    * @return array(
    			'share_id'=>分享编号,
    			'pc_id'=>评论编号(如果勾选评论给转发分享),
    			'bc_id'=>原文评论编号(如果勾选评论给原文分享),
    		)
    */
    public function saveRelay($_POST)
    {
        global $_FANWE;
        $share_id = intval($_POST['share_id']);
        $share = ShareService::getShareById($share_id);
        if (empty($share)) {
            return false;
        }
        $data = array();
        $data['share']['uid'] = $_FANWE['uid'];
        $data['share']['parent_id'] = $share_id;
        $content = htmlspecialchars(trim($_POST['content']));
        $data['share']['content'] = $content;
        $type = 'default';
        $base_id = $share['base_id'];
        if ($base_id > 0) {
            $base = ShareService::getShareById($share['base_id']);
            if (!empty($base)) {
                $base_id = $base['share_id'];
            } else {
                $base_id = 0;
            }
        }
        $rec_id = $share['rec_id'];
        if ($share['type'] == 'ask' || $share['type'] == 'ask_post') {
            $type = 'ask_post';
        } elseif ($share['type'] == 'bar' || $share['type'] == 'bar_post') {
            $type = 'bar_post';
        }
        $data['share']['rec_id'] = $share['rec_id'];
        $data['share']['title'] = addslashes($share['title']);
        $data['share']['base_id'] = $base_id > 0 ? $base_id : $share_id;
        $data['share']['type'] = $type;
        $relay_share = ShareService::save($data);
        if (!$relay_share['status']) {
            return false;
        }
        FDB::query('UPDATE ' . FDB::table('share') . '
			SET relay_count = relay_count + 1
			WHERE share_id = ' . $share_id);
        if ($base_id > 0 && $share_id != $base_id) {
            FDB::query('UPDATE ' . FDB::table('share') . '
				SET relay_count = relay_count + 1
				WHERE share_id = ' . $base_id);
        }
        $is_no_post = isset($_POST['is_no_post']) ? intval($_POST['is_no_post']) : 0;
        $share_id = $relay_share['share_id'];
        if ($rec_id > 0 && $is_no_post == 0) {
            if ($type == 'bar_post') {
                FS('Topic')->saveTopicPost($rec_id, $content, $share_id);
            } elseif ($type == 'ask_post') {
                FS('Ask')->saveTopicPost($rec_id, $content, $share_id);
            }
        }
        $is_comment_parent = isset($_POST['is_comment_parent']) ? intval($_POST['is_comment_parent']) : 0;
        $is_comment_base = isset($_POST['is_comment_base']) ? intval($_POST['is_comment_base']) : 0;
        //评论给分享
        $parent_comment_id = 0;
        if ($is_comment_parent == 1) {
            $data = array();
            $data['content'] = $_POST['content'];
            $data['share_id'] = $share['share_id'];
            $parent_comment_id = ShareService::saveComment($data);
        }
        //评论给原创分享
        $base_comment_id = 0;
        if ($is_comment_base == 1 && $base_id > 0) {
            $data = array();
            $data['content'] = $_POST['content'];
            $data['share_id'] = $base_id;
            $base_comment_id = ShareService::saveComment($data);
        }
        return array('share_id' => $share_id, 'pc_id' => $parent_comment_id, 'bc_id' => $base_comment_id);
    }
    /**
    * 转发分享
    * @param array $_POST 提交的数据
    * @return array(
    			'share_id'=>分享编号,
    			'pc_id'=>评论编号(如果勾选评论给转发分享),
    			'bc_id'=>原文评论编号(如果勾选评论给原文分享),
    		)
    */
    public function saveRelay($_POST)
    {
        global $_FANWE;
        $share_id = intval($_POST['share_id']);
        $share = ShareService::getShareById($share_id);
        if (empty($share)) {
            return false;
        }
        $data = array();
        $data['share']['uid'] = $_FANWE['uid'];
        $data['share']['parent_id'] = $share_id;
        $content = htmlspecialchars(trim($_POST['content']));
        $data['share']['content'] = $content;
        $type = 'album_item';
        $base_id = $share['base_id'];
        if ($base_id > 0) {
            $base = ShareService::getShareById($share['base_id']);
            if (!empty($base)) {
                $base_id = $base['share_id'];
            } else {
                $base_id = 0;
            }
        }
        $rec_id = $share['rec_id'];
        if ($share['type'] == 'ask' || $share['type'] == 'ask_post') {
            $type = 'ask_post';
        } elseif ($share['type'] == 'bar' || $share['type'] == 'bar_post') {
            $type = 'bar_post';
        }
        $data['share']['albumid'] = intval($_POST['albumid']);
        $data['share']['rec_id'] = $share['rec_id'];
        $data['share']['is_refer'] = $share['is_refer'];
        $data['share']['refer_url'] = $share['refer_url'];
        $data['share']['title'] = addslashes($share['title']);
        $data['share']['base_id'] = $base_id > 0 ? $base_id : $share_id;
        $data['share']['parent_id'] = $base_id > 0 ? $base_id : $share_id;
        $data['share']['type'] = $type;
        //强制改成杂志社分享数据
        $data['share']['share_data'] = 'photo';
        //强制改成杂志社分享数据
        $relay_share = ShareService::save($data);
        //插入share_photo表中,转发修改成有图数据
        $share_photo_data = array();
        $img_data = FDB::fetchFirst("select img,img_width,img_height,is_animate,video from " . FDB::table("share_photo") . " where share_id = " . $share_id);
        $share_photo_data['uid'] = $_FANWE['uid'];
        $share_photo_data['share_id'] = $relay_share['share_id'];
        $share_photo_data['img'] = $img_data['img'];
        $share_photo_data['img_width'] = $img_data['img_width'];
        $share_photo_data['img_height'] = $img_data['img_height'];
        $share_photo_data['is_animate'] = $img_data['is_animate'];
        $share_photo_data['video'] = $img_data['video'];
        if ($share_photo_data['video']) {
            $share_photo_data['type'] = 'video';
        } else {
            $share_photo_data['type'] = 'default';
        }
        $share_photo_data['sort'] = 10;
        FDB::insert('share_photo', $share_photo_data, true);
        if (!$relay_share['status']) {
            return false;
        }
        FDB::query('UPDATE ' . FDB::table('share') . '
			SET relay_count = relay_count + 1
			WHERE share_id = ' . $share_id);
        if (intval($_POST['albumid']) > 0) {
            $album = FDB::fetchFirst('SELECT cid,id,title FROM ' . FDB::table('album') . ' WHERE id = ' . intval($_POST['albumid']));
            if ($album) {
                $update_share['type'] = 'album_item';
                $share_data_now_type = 'album_item';
                $share_data_rec_id = $album['id'];
                $share_data_rec_cate = $album['cid'];
                $update_share['rec_id'] = $album['id'];
                $update_share['title'] = addslashes($album['title']);
                $update_share['share_data'] = 'photo';
                //更新杂志社
                $album_share = array();
                $album_share['album_id'] = intval($_POST['albumid']);
                $album_share['share_id'] = $relay_share['share_id'];
                $album_share['cid'] = $share_data_rec_cate;
                $album_share['create_day'] = getTodayTime();
                FDB::insert("album_share", $album_share);
                FS('Album')->updateAlbumByShare($share_data_rec_id, $relay_share['share_id']);
                FS('Album')->updateAlbum($share_data_rec_id);
            } else {
                $update_share['rec_id'] = 0;
                $share_data_rec_id = 0;
            }
        } else {
            $share_data_rec_id = 0;
        }
        FDB::update("share", $update_share, "share_id=" . $relay_share['share_id']);
        if ($base_id > 0 && $share_id != $base_id) {
            FDB::query('UPDATE ' . FDB::table('share') . '
				SET relay_count = relay_count + 1
				WHERE share_id = ' . $base_id);
        }
        $is_no_post = isset($_POST['is_no_post']) ? intval($_POST['is_no_post']) : 0;
        $share_id = $relay_share['share_id'];
        if ($rec_id > 0 && $is_no_post == 0) {
            if ($type == 'bar_post') {
                FS('Topic')->saveTopicPost($rec_id, $content, $share_id);
            } elseif ($type == 'ask_post') {
                FS('Ask')->saveTopicPost($rec_id, $content, $share_id);
            }
        }
        $is_comment_parent = isset($_POST['is_comment_parent']) ? intval($_POST['is_comment_parent']) : 0;
        $is_comment_base = isset($_POST['is_comment_base']) ? intval($_POST['is_comment_base']) : 0;
        //评论给分享
        $parent_comment_id = 0;
        if ($is_comment_parent == 1) {
            $data = array();
            $data['content'] = $_POST['content'];
            $data['share_id'] = $share['share_id'];
            $parent_comment_id = ShareService::saveComment($data);
        }
        //评论给原创分享
        $base_comment_id = 0;
        if ($is_comment_base == 1 && $base_id > 0) {
            $data = array();
            $data['content'] = $_POST['content'];
            $data['share_id'] = $base_id;
            $base_comment_id = ShareService::saveComment($data);
        }
        return array('share_id' => $share_id, 'pc_id' => $parent_comment_id, 'bc_id' => $base_comment_id);
    }