FeedModel::put PHP Method

put() public method

添加分享
public put ( integer $uid, string $app = 'public', string $type = '', array $data = [], integer $app_id, string $app_table = 'feed', array $extUid = null, array $lessUids = null, boolean $isAtMe = true, $is_repost ) : mix
$uid integer 操作用户ID
$app string 分享应用类型,默认为public
$type string 分享类型,
$data array 分享相关数据
$app_id integer 应用资源ID,默认为0
$app_table string 应用资源表名,默认为feed
$extUid array 额外用户ID,默认为null
$lessUids array 去除的用户ID,默认为null
$isAtMe boolean 是否为进行发送,默认为true
return mix 添加失败返回false,成功返回新的分享ID
    public function put($uid, $app = 'public', $type = '', $data = array(), $app_id = 0, $app_table = 'feed', $extUid = null, $lessUids = null, $isAtMe = true, $is_repost = 0)
    {
        //检测用户是否被禁言
        if ($isDisabled = model('DisableUser')->isDisableUser($uid, 'post')) {
            $this->error = '您已经被禁言了..';
            return false;
        }
        if (isSubmitLocked()) {
            $this->error = '发布内容过于频繁,请稍后再试';
            return false;
        }
        // 判断数据的正确性
        if (!$uid || $type == '') {
            $this->error = L('PUBLIC_ADMIN_OPRETING_ERROR');
            return false;
        }
        if (strpos($type, 'postvideo') !== false) {
            $type = 'postvideo';
        }
        //分享类型合法性验证 - 临时解决方案
        $checkType = array('post', 'repost', 'postvideo', 'postfile', 'postimage', 'weiba_post', 'weiba_repost', 'long_post', 'photo_post', 'photo_repost', 'vote_post', 'vote_repost', 'event_post', 'event_repost', 'blog_post', 'blog_repost', 'poster_post', 'poster_repost');
        if (!in_array($type, $checkType)) {
            $type = 'post';
        }
        //应用类型验证 用于分享框 - 临时解决方案
        $checkApp = array('w3g', 'public', 'weiba', 'tipoff', 'photo', 'vote', 'event', 'blog', 'poster');
        if (!in_array($app, $checkApp)) {
            $app = 'public';
            $type = 'post';
            $app_table = 'feed';
        }
        $app_table = strtolower($app_table);
        // 添加feed表记录
        $data['uid'] = $uid;
        $data['app'] = $app;
        $data['type'] = $type;
        $data['app_row_id'] = $app_id;
        $data['app_row_table'] = $app_table;
        $data['publish_time'] = time();
        $data['from'] = isset($data['from']) ? intval($data['from']) : getVisitorClient();
        $data['is_del'] = $data['comment_count'] = $data['repost_count'] = 0;
        $data['is_repost'] = $is_repost;
        //判断是否先审后发
        $filterStatus = filter_words($data['body']);
        $weiboSet = model('Xdata')->get('admin_Config:feed');
        $weibo_premission = $weiboSet['weibo_premission'];
        if (in_array('audit', $weibo_premission) || CheckPermission('core_normal', 'feed_audit') || $filterStatus['type'] == 2) {
            $data['is_audit'] = 0;
        } else {
            $data['is_audit'] = 1;
        }
        // 分享内容处理
        if (Addons::requireHooks('weibo_publish_content')) {
            Addons::hook('weibo_publish_content', array(&$data));
        } else {
            // 截取内容信息为分享内容字数 - 长分享
            //$feedConf = model('Xdata')->get('admin_Config:feed');
            //$feedNums = $feedConf['weibo_nums'];
            //if(Addons::requireHooks('show_longtext_button')){
            //	$feedNums = 20000;
            //	$data['body'] = str_replace(SITE_URL, '[SITE_URL]', $data['body']);
            //}else{
            //	$data['body'] = str_replace(SITE_URL, '[SITE_URL]', preg_html($data['body']));
            //}
            $content = $this->formatFeedContent($data['body']);
            $data['body'] = $content['body'];
            $data['content'] = $content['content'];
        }
        //分享到分享的应用资源,加入原资源链接
        $data['body'] .= $data['source_url'];
        $data['content'] .= $data['source_url'];
        // 分享类型插件钩子
        // if($type){
        // 	$addonsData = array();
        // 	Addons::hook("weibo_type",array("typeId"=>$type,"typeData"=>$type_data,"result"=>&$addonsData));
        // 	$data = array_merge($data,$addonsData);
        // }
        if ($type == 'postvideo') {
            if ($_POST['video_id']) {
                $video_info = D('video')->where('video_id=' . $data['video_id'])->find();
                $data['transfer_id'] = $video_info['transfer_id'];
                $data['video_path'] = $video_info['video_path'];
                $data['video_mobile_path'] = $video_info['video_mobile_path'];
                $data['video_part_path'] = $video_info['video_part_path'];
                $data['image_path'] = $video_info['image_path'];
                $data['image_width'] = $video_info['image_width'];
                $data['image_height'] = $video_info['image_height'];
            } else {
                $typedata = model('Video')->_weiboTypePublish($_POST['videourl']);
                if ($typedata && $typedata['flashvar'] && $typedata['flashimg']) {
                    $data = array_merge($data, $typedata);
                } else {
                    $data['type'] = 'post';
                }
            }
        }
        // 添加分享信息
        $feed_id = $this->data($data)->add();
        if (!$feed_id) {
            return false;
        }
        if ($data['video_id']) {
            D('video')->where('video_id=' . $data['video_id'])->setField('feed_id', $feed_id);
            //如果有的话
            if (D('video_transfer')->where('video_id=' . $data['video_id'])->count()) {
                D('video_transfer')->where('video_id=' . $data['video_id'])->setField('feed_id', $feed_id);
            }
        }
        if (!$data['is_audit']) {
            $touid = D('user_group_link')->where('user_group_id=1')->field('uid')->findAll();
            foreach ($touid as $k => $v) {
                model('Notify')->sendNotify($v['uid'], 'feed_audit');
            }
        }
        // 目前处理方案格式化数据
        $data['content'] = str_replace(chr(31), '', $data['content']);
        $data['body'] = str_replace(chr(31), '', $data['body']);
        // 添加关联数据
        // $feed_data = D('FeedData')->data(array('feed_id'=>$feed_id, 'feed_data'=>serialize($data), 'client_ip'=>get_client_ip(), 'client_port'=>get_client_port(), 'feed_content'=>$data['body']))->add();
        // var_dump($feed_data);exit;
        $feed_data = Capsule::table('feed_data')->insert(array('feed_id' => $feed_id, 'feed_data' => serialize($data), 'client_ip' => get_client_ip(), 'client_port' => get_client_port(), 'feed_content' => $data['body']));
        // 添加分享成功后
        if ($feed_id && $feed_data) {
            //锁定发布
            lockSubmit();
            //分享发布成功后的钩子
            //Addons::hook("weibo_publish_after",array('weibo_id'=>$feed_id,'post'=>$data));
            // 发送通知消息 - 重点 - 需要简化把上节点的信息去掉.
            if ($data['is_repost'] == 1) {
                // 转发分享
                $isAtMe && ($content = $data['content']);
                // 内容用户
                $extUid[] = $data['sourceInfo']['transpond_data']['uid'];
                // 资源作者用户
                if ($isAtMe && !empty($data['curid'])) {
                    // 上节点用户
                    $appRowData = $this->get($data['curid']);
                    $extUid[] = $appRowData['uid'];
                }
            } else {
                // 其他分享
                $content = $data['content'];
                //更新最近@的人
                model('Atme')->updateRecentAt($content);
                // 内容用户
            }
            // 发送@消息
            model('Atme')->setAppName('Public')->setAppTable('feed')->addAtme($content, $feed_id, $extUid, $lessUids);
            $data['client_ip'] = get_client_ip();
            $data['feed_id'] = $feed_id;
            $data['feed_data'] = serialize($data);
            // 主动创建渲染后的缓存
            $return = $this->setFeedCache($data);
            $return['user_info'] = model('User')->getUserInfo($uid);
            $return['GroupData'] = model('UserGroupLink')->getUserGroupData($uid);
            //获取用户组信息
            $return['feed_id'] = $feed_id;
            $return['app_row_id'] = $data['app_row_id'];
            $return['is_audit'] = $data['is_audit'];
            // 统计数修改
            model('UserData')->setUid($uid)->updateKey('feed_count', 1);
            // if($app =='public'){ //TODO 分享验证条件
            model('UserData')->setUid($uid)->updateKey('weibo_count', 1);
            // }
            //更新附件信息
            $attach_info['app_name'] = 'public';
            $attach_info['table'] = 'feed';
            $attach_info['row_id'] = $feed_id;
            $attach_map['attach_id'] = array('IN', $data['attach_id']);
            model('Attach')->where($attach_map)->save($attach_info);
            if (!$return) {
                $this->error = L('PUBLIC_CACHE_FAIL');
                // Feed缓存写入失败
            }
            return $return;
        } else {
            $this->error = L('PUBLIC_ADMIN_OPRETING_ERROR');
            // 操作失败
            return false;
        }
    }

Usage Example

<?php

// ....
require_once 'config.php';
require_once 'FeedModel.php';
DatastoreService::setInstance(new DatastoreService($google_api_config));
$feed_url = 'http://www.sciam.com/xml/sciam.xml';
$feed_model = new FeedModel($feed_url);
// save the instance to the datastore
$feed_model->put();
// now, try fetching the saved model from the datastore
$kname = sha1($feed_url);
// fetch the feed with that key, as part of the transaction
$feed_model_fetched = FeedModel::fetch_by_name($kname)[0];
echo "fetched feed model with subscriber url: " . $feed_model_fetched->getSubscriberUrl();