当前位置: 首页>>代码示例>>PHP>>正文


PHP Streams::subscribe方法代码示例

本文整理汇总了PHP中Streams::subscribe方法的典型用法代码示例。如果您正苦于以下问题:PHP Streams::subscribe方法的具体用法?PHP Streams::subscribe怎么用?PHP Streams::subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Streams的用法示例。


在下文中一共展示了Streams::subscribe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Places_geolocation_post

/**
 * Used to set the user's location from geolocation data.
 * @class HTTP Places geolocation
 * @method post
 * @param $_REQUEST
 * @param [$_REQUEST.latitude] The new latitude. If set, must also specify longitude.
 * @param [$_REQUEST.longitude] The new longitude. If set, must also specify latitude.
 * @param [$_REQUEST.zipcode] The new zip code. Can be set instead of latitude, longitude.
 * @param [$_REQUEST.miles] The distance around their location around that the user is interested in
 * @param [$_REQUEST.subscribe] Whether to subscribe to all the local interests at the new location.
 * @param [$_REQUEST.unsubscribe] Whether to unsubscribe from all the local interests at the old location.
 * @param [$_REQUEST.accuracy]
 * @param [$_REQUEST.altitude]
 * @param [$_REQUEST.altitudeAccuracy]
 * @param [$_REQUEST.heading]
 * @param [$_REQUEST.speed]
 * @param [$_REQUEST.timezone]
 * @param [$_REQUEST.placeName] optional
 * @param [$_REQUEST.state] optional
 * @param [$_REQUEST.country] optional
 */
function Places_geolocation_post()
{
    $user = Users::loggedInUser(true);
    $stream = Places_Location::userStream();
    $oldLatitude = $stream->getAttribute('latitude');
    $oldLongitude = $stream->getAttribute('longitude');
    $oldMiles = $stream->getAttribute('miles');
    $fields = array('accuracy', 'altitude', 'altitudeAccuracy', 'heading', 'latitude', 'longitude', 'speed', 'miles', 'zipcode', 'timezone', 'placeName', 'state', 'country');
    $attributes = Q::take($_REQUEST, $fields);
    if (isset($attributes['latitude']) xor isset($attributes['longitude'])) {
        throw new Q_Exception("When specifying latitude,longitude you must specify both", array('latitude', 'longitude'));
    }
    if (!empty($attributes['zipcode']) and !isset($attributes['latitude'])) {
        $z = new Places_Zipcode();
        $z->countryCode = 'US';
        $z->zipcode = $attributes['zipcode'];
        if ($z->retrieve()) {
            $attributes['latitude'] = $z->latitude;
            $attributes['longitude'] = $z->longitude;
            $attributes['country'] = $z->countryCode;
        } else {
            throw new Q_Exception_MissingRow(array('table' => 'zipcode', 'criteria' => $attributes['zipcode']), 'zipcode');
        }
    }
    $attributes['miles'] = Q::ifset($attributes, 'miles', $stream->getAttribute('miles', Q_Config::expect('Places', 'nearby', 'defaultMiles')));
    if (empty($attributes['zipcode']) and isset($attributes['latitude'])) {
        $zipcodes = Places_Zipcode::nearby($attributes['latitude'], $attributes['longitude'], $attributes['miles'], 1);
        if ($zipcode = $zipcodes ? reset($zipcodes) : null) {
            $attributes['zipcode'] = $zipcode->zipcode;
            $attributes['placeName'] = $zipcode->placeName;
            $attributes['state'] = $zipcode->state;
            $attributes['country'] = $zipcode->countryCode;
        }
    }
    $stream->setAttribute($attributes);
    $stream->save();
    $stream->post($user->id, array('type' => 'Places/location/updated', 'content' => '', 'instructions' => $stream->getAllAttributes()), true);
    $shouldUnsubscribe = !empty($_REQUEST['unsubscribe']) && isset($oldMiles);
    $shouldSubscribe = !empty($_REQUEST['subscribe']);
    $noChange = false;
    $latitude = $stream->getAttribute('latitude');
    $longitude = $stream->getAttribute('longitude');
    $miles = $stream->getAttribute('miles');
    if ($shouldUnsubscribe and $shouldSubscribe and abs($latitude - $oldLatitude) < 0.0001 and abs($longitude - $oldLongitude) < 0.0001 and abs($miles - $oldMiles) < 0.001) {
        $noChange = true;
    }
    $attributes['stream'] = $stream;
    Q_Response::setSlot('attributes', $attributes);
    if (!$noChange) {
        // Send the response and keep going.
        // WARN: this potentially ties up the PHP thread for a long time
        $timeLimit = Q_Config::get('Places', 'geolocation', 'timeLimit', 100000);
        ignore_user_abort(true);
        set_time_limit($timeLimit);
        Q_Dispatcher::response(true);
        session_write_close();
        if ($shouldUnsubscribe or $shouldSubscribe) {
            $myInterests = Streams_Category::getRelatedTo($user->id, 'Streams/user/interests', 'Streams/interests');
            if (!isset($myInterests)) {
                $myInterests = array();
            }
        }
        if ($shouldUnsubscribe and $oldLatitude and $oldLongitude and $oldMiles) {
            $results = array();
            foreach ($myInterests as $weight => $info) {
                $publisherId = $info[0];
                if (!isset($results[$publisherId])) {
                    $results[$publisherId] = array();
                }
                $results[$publisherId] = array_merge($results[$publisherId], Places_Interest::streams($publisherId, $oldLatitude, $oldLongitude, $info[2], array('miles' => $oldMiles, 'skipAccess' => true, 'forSubscribers' => true)));
            }
            foreach ($results as $publisherId => $streams) {
                Streams::unsubscribe($user->id, $publisherId, $streams, array('skipAccess' => true));
            }
            $attributes['unsubscribed'] = Places_Nearby::unsubscribe($oldLatitude, $oldLongitude, $oldMiles);
        }
        if ($shouldSubscribe) {
            $results = array();
            foreach ($myInterests as $weight => $info) {
//.........这里部分代码省略.........
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:101,代码来源:post.php

示例2: subscribe

 /**
  * Call this function to subscribe to streams on which messages are posted
  * related to things happening the given number of $miles around the given location.
  * @method subscribe
  * @static
  * @param {double} $latitude The latitude of the coordinates to subscribe around
  * @param {double} $longitude The longitude of the coordinates to subscribe around
  * @param {double} $miles The radius, in miles, around this location.
  *  Should be one of the array values in the Places/nearby/miles config.
  * @param {string} $publisherId The id of the publisher publishing these streams.
  *  Defaults to the app name in Q/app config.
  * @param {array} $options The options to pass to the subscribe function
  * @return {Array} Returns an array of up to four arrays of ($publisherId, $streamName)
  *  of streams that were subscribed to.
  */
 static function subscribe($latitude, $longitude, $miles, $publisherId = null, $options = array())
 {
     $user = Users::loggedInUser(true);
     if (!isset($publisherId)) {
         $publisherId = Users::communityId();
     }
     $options['forSubscribers'] = true;
     $options['miles'] = $miles;
     $streams = Places_Nearby::streams($publisherId, $latitude, $longitude, $options);
     return Streams::subscribe($user->id, $publisherId, $streams, $options);
 }
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:26,代码来源:Nearby.php

示例3: subscribe

 /**
  * Subscribe to the stream, to start receiving notifications.
  * Posts a "Streams/subscribe" message to the stream.
  * Also posts a "Streams/subscribed" message to user's "Streams/participating" stream.
  *	If options are not given check the subscription templates:
  *	1. generic publisher id and generic user
  *	2. exact publisher id and generic user
  *	3. generic publisher id and exact user
  *	default is to subscribe to ALL messages.
  *	If options are supplied - skip templates and use options.
  * Using subscribe if subscription is already active will modify existing
  * subscription - change type(s) or modify notifications
  * @param {array} [$options=array()]
  * @param {array} [$options.filter] optional array with two keys
  * @param {array} [$options.filter.types] array of message types, if this is empty then subscribes to all types
  * @param {array} [$options.filter.notifications=0] limit number of notifications, 0 means no limit
  * @param {datetime} [$options.untilTime=null] time limit, if any for subscription
  * @param {array} [$options.rule=array()] optionally override the rule for new subscriptions
  * @param {array} [$options.rule.deliver=array('to'=>'default')] under "to" key,
  *   named the field under Streams/rules/deliver config, which will contain the names of destinations,
  *   which can include "email", "mobile", "email+pending", "mobile+pending"
  * @param {datetime} [$options.rule.readyTime] time from which user is ready to receive notifications again
  * @param {array} [$options.rule.filter] optionally set a filter for the rules to add
  * @param {boolean} [$options.skipRules] if true, do not attempt to create rules for new subscriptions
  * @param {boolean} [$options.skipAccess] if true, skip access check for whether user can join and subscribe
  * @param {string} [$options.userId] the user subscribing to the stream. Defaults to the logged in user.
  * @return {Streams_Participant|null}
  */
 function subscribe($options = array())
 {
     $userId = $this->_verifyUser($options);
     $participants = Streams::subscribe($userId, $this->publisherId, array($this->name), $options);
     return $participants ? reset($participants) : null;
 }
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:34,代码来源:Stream.php


注:本文中的Streams::subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。