如何让每个人都可以在Social Engine上看到活动?

时间:2012-03-06 19:45:26

标签: zend-framework socialengine

我正在努力让管理员发布的活动对网络的每个成员都可见,而不仅仅是他们的朋友。 据我所知,直到现在,表流是阻止我的消息公开,它只是制作个人资料消息。仅在其Feed中可见。 有没有人知道如何强制执行此操作?

[编辑] 我的下面的代码是在我的帐户中挑选推文,我正在使用我创建的一些设置(例如来自twitter的screen_name和在feed上发布推文的用户)。 代码如下: - >检查是否有设置供Twitter用户阅读其消息。 - >将其保存在表格中 - >授权(理论上)每个人阅读此消息,以太是出版商的朋友或不是。 - >添加我也创建的活动。

$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );

if ($TwitterUser != '') {
    // Ultimo tweet postado
    $TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
    $table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
    $query = $table->select ()->order ( 'tweets_id desc')->limit(1);

    $lastTweet = $table->fetchRow ( $query );
    // Set the configuration parameters
    $config = array ('adapter' => 'Zend_Http_Client_Adapter_Socket', 'ssltransport' => 'tls' );

    // Instantiate a client object
    if (is_null ( $lastTweet )) {
        $client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&count=4&include_rts=1", $config );
    } else {
        $client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&include_rts=1&since_id=" . $lastTweet->real_id, $config );
    }
    // The following request will be sent over a TLS secure connection.
    $response = $client->request ();    
    // Pegando a resposta
    $body = json_decode ( $response->getBody () );
    if (! empty ( $body )) {
        $db = Engine_Api::_()->getDbtable('tweets', 'user')->getAdapter();
        $db->beginTransaction();

        try
        {
        $table = Engine_Api::_ ()->getDbtable ( 'users', 'user' );
        $twitter_user = $table->fetchRow ( $table->select ()->where ( 'user_id = ?', Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.user_id' ) ) );
        $table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
        $activityApi = Engine_Api::_ ()->getDbtable ( 'actions', 'activity' );
        foreach ( array_reverse($body) as $tweet ) {
            $data = explode ( ' ', $tweet->created_at );
            $meses = array ('Jan' => '01', 'Fev' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12' );
            $tweet_date = $data ['5'] . "-" . $meses [$data [1]] . '-' . $data [2] . " " . $data [3];
            $tweet_date = (date ( 'Y-m-d H:i:s', strtotime ( $tweet_date ) ));
            $last_tweet = $table->createRow();
            $last_tweet->setFromArray(array(
                    'real_id' => $tweet->id_str,
                    'user_id' => $tweet->user->id_str,
                    'screen_name' => $tweet->user->screen_name,
                    'body' => $tweet->text,
                    'retweeted' => $tweet->retweeted,
                    'created_at' => $tweet_date,
                    'profile_image_url' => $tweet->user->profile_image_url,
                    'coordinates' => $tweet->coordinates
            ));
            $last_tweet->save();
            // Authorizations
            $auth = Engine_Api::_()->authorization()->context;
            $auth->setAllowed($last_tweet, 'everyone', 'view',    true);
            $auth->setAllowed($last_tweet, 'everyone', 'comment', true);
            $auth->setAllowed($last_tweet, 'everyone', 'likes', true);
            $action = $activityApi->addActivity ($twitter_user,$last_tweet, 'post_twitter', $tweet->text);
            if( $action ) {
                $activityApi->attachActivity($action, $last_tweet);
            }
        }
        // Commit
        $db->commit();
        } catch ( Exception $e ) {
                $db->rollBack ();
                throw $e;
            }
        }
}

没有问题发生,但我跟踪的推文只能是我用来发布它的用户的红色。

1 个答案:

答案 0 :(得分:0)

您应该在流表中为此action_id创建条目。