本文整理汇总了PHP中Q_Response::setSlot方法的典型用法代码示例。如果您正苦于以下问题:PHP Q_Response::setSlot方法的具体用法?PHP Q_Response::setSlot怎么用?PHP Q_Response::setSlot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q_Response
的用法示例。
在下文中一共展示了Q_Response::setSlot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Websites_seo_post
function Websites_seo_post()
{
if (empty($_REQUEST['streamName'])) {
throw new Q_Exception_RequiredField(array('field' => 'streamName'));
}
$prefix = "Websites/seo/";
if (substr($_REQUEST['streamName'], 0, strlen($prefix)) !== $prefix) {
throw new Q_Exception_WrongValue(array('field' => 'streamName', 'range' => "string beginning with {$prefix}"));
}
$user = Users::loggedInUser(true);
$publisherId = Users::communityId();
$type = "Websites/seo";
if (!Streams::isAuthorizedToCreate($user->id, $publisherId, $type)) {
throw new Users_Exception_NotAuthorized();
}
$stream = new Streams_Stream($publisherId);
$stream->publisherId = $publisherId;
$stream->name = $_REQUEST['streamName'];
$stream->type = $type;
if (isset($_REQUEST['uri'])) {
$stream->setAttribute('uri', $_REQUEST['uri']);
}
$stream->save();
$stream->post($user->id, array('type' => 'Streams/created', 'content' => '', 'instructions' => Q::json_encode($stream->toArray())), true);
$stream->subscribe();
// autosubscribe to streams you yourself create, using templates
Q_Response::setSlot('stream', $stream->exportArray());
}
示例2: Users_activate_response
function Users_activate_response()
{
$content = Q::event('Users/activate/response/content');
Q_Response::setSlot('content', $content);
Q_Response::setSlot('column0', $content);
// for SmartApp
}
示例3: Users_label_post
/**
* Adds a label to the system. Fills the "label" (and possibly "icon") slot.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.title The title of the label
* @param {string} [$_REQUEST.label] You can override the label to use
* @param {string} [$_REQUEST.icon] Optional path to an icon
* @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this
*/
function Users_label_post($params = array())
{
$req = array_merge($_REQUEST, $params);
Q_Request::requireFields(array('title'), $req, true);
$loggedInUserId = Users::loggedInUser(true)->id;
$userId = Q::ifset($req, 'userId', $loggedInUserId);
$icon = Q::ifset($req, 'icon', null);
$title = $req['title'];
$l = Q::ifset($req, 'label', 'Users/' . Q_Utils::normalize($title));
Users::canManageLabels($loggedInUserId, $userId, $l, true);
$label = new Users_Label();
$label->userId = $userId;
$label->label = $l;
if ($label->retrieve()) {
throw new Users_Exception_LabelExists();
}
$label->title = $title;
if (is_array($icon)) {
// Process any icon that was posted
$icon['path'] = 'uploads/Users';
$icon['subpath'] = "{$userId}/label/{$label}/icon";
$data = Q::event("Q/image/post", $icon);
Q_Response::setSlot('icon', $data);
$label->icon = Q_Request::baseUrl() . '/' . $data[''];
} else {
$label->icon = 'default';
}
$label->save();
Q_Response::setSlot('label', $label->exportArray());
}
示例4: Streams_interest_delete
/**
* Used to create a new stream
*
* @param {array} $_REQUEST
* @param {String} [$_REQUEST.title] Required. The title of the interest.
* @param {String} [$_REQUEST.publisherId] Optional. Defaults to the app name.
* @return {void}
*/
function Streams_interest_delete()
{
$user = Users::loggedInUser(true);
$title = Q::ifset($_REQUEST, 'title', null);
if (!isset($title)) {
throw new Q_Exception_RequiredField(array('field' => 'title'));
}
$app = Q_Config::expect('Q', 'app');
$publisherId = Q::ifset($_REQUEST, 'publisherId', $app);
$name = 'Streams/interest/' . Q_Utils::normalize($title);
$stream = Streams::fetchOne(null, $publisherId, $name);
if (!$stream) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => Q::json_encode(compact('publisherId', 'name'))));
}
$miPublisherId = $user->id;
$miName = 'Streams/user/interests';
$myInterests = Streams::fetchOne($user->id, $miPublisherId, $miName);
if (!$myInterests) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => Q::json_encode(array('publisherId' => $miPublisherId, 'name' => $miName))));
}
$stream->leave();
Streams::unrelate($user->id, $user->id, 'Streams/user/interests', 'Streams/interest', $publisherId, $name, array('adjustWeights' => true));
Q_Response::setSlot('publisherId', $publisherId);
Q_Response::setSlot('streamName', $name);
/**
* Occurs when the logged-in user has successfully removed an interest via HTTP
* @event Streams/interest/delete {after}
* @param {string} publisherId The publisher of the interest stream
* @param {string} title The title of the interest
* @param {Users_User} user The logged-in user
* @param {Streams_Stream} stream The interest stream
* @param {Streams_Stream} myInterests The user's "Streams/user/interests" stream
*/
Q::event("Streams/interest/remove", compact('publisherId', 'title', 'subscribe', 'user', 'stream', 'myInterests'), 'after');
}
示例5: Users_label_put
/**
* Edits a label in the system. Fills the "label" (and possibly "icon") slot.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.label The label
* @param {string} [$_REQUEST.title] The title of the label
* @param {string} [$_REQUEST.icon] Optional path to an icon
* @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this
*/
function Users_label_put($params = array())
{
$req = array_merge($_REQUEST, $params);
Q_Request::requireFields(array('label'), $req, true);
$loggedInUserId = Users::loggedInUser(true)->id;
$userId = Q::ifset($req, 'userId', $loggedInUserId);
$l = $req['label'];
$icon = Q::ifset($req, 'icon', null);
$title = Q::ifset($req, 'title', null);
Users::canManageLabels($loggedInUserId, $userId, $l, true);
$label = new Users_Label();
$label->userId = $userId;
$label->label = $l;
if (!$label->retrieve()) {
throw new Q_Exception_MissingRow(array('table' => 'Label', 'criteria' => json_encode($label->fields)));
}
if (isset($title)) {
$label->title = $title;
}
if (is_array($icon)) {
// Process any icon data
$icon['path'] = 'uploads/Users';
$icon['subpath'] = "{$userId}/label/{$label}/icon";
$data = Q::event("Q/image/post", $icon);
Q_Response::setSlot('icon', $data);
$label->icon = Q_Request::baseUrl() . '/' . $data[''];
}
$label->save();
Q_Response::setSlot('label', $label->exportArray());
}
示例6: Streams_related_post
/**
* Used to create a new relation
*
* @param array $_REQUEST
* toPublisherId, toStreamName, type
* fromPublisherId, fromStreamName, weight
* @return {void}
*/
function Streams_related_post($params)
{
$user = Users::loggedInUser(true);
$asUserId = $user->id;
$toPublisherId = $_REQUEST['toPublisherId'];
$toStreamName = $_REQUEST['toStreamName'];
$type = $_REQUEST['type'];
$fromPublisherId = $_REQUEST['fromPublisherId'];
$fromStreamName = $_REQUEST['fromStreamName'];
// TODO: When we start supporting multiple hosts, this will have to be rewritten
// to make servers communicate with one another when establishing relations between streams
if (!($stream = Streams::fetch($asUserId, $toPublisherId, $toStreamName))) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with those fields'), array('publisherId', 'name'));
}
if (!($stream = Streams::fetch($asUserId, $fromPublisherId, $fromStreamName))) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with those fields'), array('fromPublisherId', 'from_name'));
}
$weight = "+1";
if (isset($_REQUEST['weight'])) {
if (!$stream->testWriteLevel('relations')) {
throw new Users_Exception_NotAuthorized();
}
$weight = $_REQUEST['weight'];
}
$result = Streams::relate($asUserId, $toPublisherId, $toStreamName, $type, $fromPublisherId, $fromStreamName, compact('weight'));
Q_Response::setSlot('result', $result);
}
示例7: Q_file_post
/**
* Used by HTTP clients to upload a new file to the server
* @class Q/file
* @method post
* @param {array} [$params] Parameters that can come from the request
* @param {string} [$params.data] Required if $_FILES is empty. Base64-encoded image data URI - see RFC 2397
* @param {string} [$params.path="uploads"] parent path under web dir (see subpath)
* @param {string} [$params.subpath=""] subpath that should follow the path, to save the image under
* @param {string} [$params.name] override the name of the file, after the subpath
*/
function Q_file_post($params = null)
{
$p = $params ? $params : Q::take($_REQUEST, array('data', 'path', 'subpath'));
if (!empty($_FILES)) {
$file = reset($_FILES);
if ($tmp = $file['tmp_name']) {
if (empty($p['data'])) {
$p['data'] = file_get_contents($tmp);
$p['name'] = $file['name'];
}
unlink($tmp);
}
} else {
if (empty($p['data'])) {
throw new Q_Exception_RequiredField(array('field' => 'data'), 'data');
}
$p['data'] = base64_decode(chunk_split(substr($p['data'], strpos($p['data'], ',') + 1)));
}
$timeLimit = Q_Config::get('Q', 'uploads', 'limits', 'file', 'time', 5 * 60 * 60);
set_time_limit($timeLimit);
// default is 5 min
$data = Q_File::save($p);
if (empty($params)) {
Q_Response::setSlot('data', $data);
}
return $data;
}
示例8: Users_device_post
/**
* Adds a device to the current user id and session.
* See Users_Device::add method for more details.
* @param {string} $deviceId
* @return {void}
*/
function Users_device_post()
{
Q_Request::requireFields(array('deviceId'));
$deviceId = $_REQUEST['deviceId'];
$user = Users::loggedInUser(true);
$device = Users_Device::add(array_merge($_REQUEST, array('userId' => $user->id)));
Q_Response::setSlot('data', $device);
}
示例9: Streams_participating_response
function Streams_participating_response()
{
if (!Q_Request::isAjax()) {
return;
}
$max_limit = Q_Config::expect('Streams', 'db', 'limits', 'participating');
$user = Users::loggedInUser(true);
$type = Streams::requestedType();
$limit = Streams::requestedField('limit', false, $max_limit);
if ($limit > $max_limit) {
throw new Q_Exception("limit is too large, must be <= {$max_limit}");
}
$offset = Streams::requestedField('offset', false, 0);
$order = Streams::requestedField('order', false, true);
$participating = array();
$q = Streams_Participating::select('*')->where(array('userId' => $user->id));
if ($type) {
$q = $q->where(array('streamName' => new Db_Range($type . '/', true, false, true)));
}
if ($limit) {
$q = $q->limit($limit, $offset);
}
if ($order) {
$q = $q->orderBy('updatedTime', false);
}
$res_participating = $q->fetchDbRows();
foreach ($res_participating as $part) {
$part_safe = $part->exportArray();
if (isset($part_safe)) {
$participating[] = $part_safe;
}
}
Q_Response::setSlot('participating', $participating);
if (!Q_Request::slotName('streams')) {
return;
}
$res_streams = array();
$streamNames = array();
foreach ($res_participating as $p) {
$streamNames[$p->publisherId][] = $p->streamName;
}
foreach ($streamNames as $p_id => $names) {
$res_streams[$p_id] = Streams::fetch($user->id, $p_id, $names);
}
$streams = array();
$o = array('asUserId' => $user->id);
foreach ($res_streams as $publisherId => $streams_array) {
if (!empty($streams_array)) {
$streams[$publisherId] = array();
foreach ($streams_array as $streamName => $stream) {
$streams[$publisherId][$streamName] = $stream->exportArray($o);
}
}
}
Q_Response::setSlot('streams', $streams);
}
示例10: Users_authorize_response
/**
* We are going to implement a subset of the OAuth 1.0a functionality for now,
* and later we can expand it to match the full OAuth specification.
*/
function Users_authorize_response()
{
if (Q_Response::getErrors()) {
Q_Dispatcher::showErrors();
}
$response_type = 'token';
$token_type = 'bearer';
$client_id = $_REQUEST['client_id'];
$state = $_REQUEST['state'];
$skip = Q::ifset($_REQUEST, 'skip', false);
$scope = Users_OAuth::requestedScope(true, $scopes);
$client = Users_User::fetch($client_id, true);
if (!$client) {
throw new Q_Exception_MissingRow(array('table' => 'client user', 'criteria' => "id = '{$client_id}'"), 'client_id');
}
if (empty($client->url)) {
throw new Q_Exception("Client app needs to register url", 'client_id');
}
$redirect_uri = Q::ifset($_REQUEST, 'redirect_uri', $client->url);
$user = Users::loggedInUser();
$oa = null;
if (isset(Users::$cache['oAuth'])) {
$oa = Users::$cache['oAuth'];
} else {
if ($user) {
$oa = new Users_OAuth();
$oa->client_id = $client_id;
$oa->userId = $user->id;
$oa->state = $state;
$oa = $oa->retrieve();
}
}
$remaining = $scope;
if ($oa and $oa->wasRetrieved()) {
// User is logged in and already has a token for this client_id and state
$paths = Q_Config::get('Users', 'authorize', 'clients', Q::app(), 'redirectPaths', false);
$path = substr($redirect_uri, strlen($client->url) + 1);
$p = array('response_type' => $response_type, 'token_type' => $token_type, 'access_token' => $oa->access_token, 'expires_in' => $oa->token_expires_seconds, 'scope' => implode(' ', $scope), 'state' => $oa->state);
$p = Q_Utils::sign($p, 'Q.Users.oAuth');
// the redirect uri could be a native app url scheme
$s = strpos($redirect_uri, '#') === false ? '#' : '&';
$redirect_uri = Q_Uri::from($redirect_uri . $s . http_build_query($p), false)->toUrl();
if (!Q::startsWith($redirect_uri, $client->url) or is_array($paths) and !in_array($path, $paths)) {
throw new Users_Exception_Redirect(array('uri' => $redirect_uri));
}
Q_Response::redirect($redirect_uri);
return false;
}
$terms_label = Users::termsLabel('authorize');
Q_Response::setScriptData('Q.Users.authorize', compact('client_id', 'redirect_uri', 'scope', 'scopes', 'remaining', 'state', 'response_type', 'skip'));
$content = Q::view('Users/content/authorize.php', compact('client', 'user', 'redirect_uri', 'scope', 'scopes', 'remaining', 'state', 'terms_label', 'response_type', 'skip'));
Q_Response::setSlot('content', $content);
Q_Response::setSlot('column0', $content);
return true;
}
示例11: Users_contact_post
/**
* Adds contacts to the system. Fills the "contacts" slot.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.label The label of the contact
* @param {string} $_REQUEST.contactUserId The contactUserId of the contact
* @param {string} [$_REQUEST.nickname] The nickname of the contact
* @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this
*/
function Users_contact_post($params = array())
{
$req = array_merge($_REQUEST, $params);
Q_Request::requireFields(array('label', 'contactUserId'), $req, true);
$loggedInUserId = Users::loggedInUser(true)->id;
$userId = Q::ifset($req, 'userId', $loggedInUserId);
$contactUserId = $req['contactUserId'];
$nickname = Q::ifset($req, 'nickname', null);
$contacts = Users_Contact::addContact($userId, $req['label'], $contactUserId, $nickname);
Q_Response::setSlot('contacts', Db::exportArray($contacts));
}
示例12: Users_user_response_users
function Users_user_response_users($params = array())
{
$req = array_merge($_REQUEST, $params);
Q_Valid::requireFields(array('userIds'), $req, true);
$userIds = $req['userIds'];
if (is_string($userIds)) {
$userIds = explode(",", $userIds);
}
$fields = Q_Config::expect('Users', 'avatarFields');
$users = Users_User::select($fields)->where(array('id' => $userIds))->fetchDbRows(null, null, 'id');
return Q_Response::setSlot('users', Db::exportArray($users, array('asAvatar' => true)));
}
示例13: Users_label_post
/**
* Adds a label to the system. Fills the "label" (and possibly "icon") slot.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.title The title of the label
* @param {string} [$_REQUEST.label] You can override the label to use
* @param {string} [$_REQUEST.icon] Optional path to an icon
* @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this
*/
function Users_label_post($params = array())
{
$req = array_merge($_REQUEST, $params);
Q_Request::requireFields(array('title'), $req, true);
$loggedInUserId = Users::loggedInUser(true)->id;
$userId = Q::ifset($req, 'userId', $loggedInUserId);
$icon = Q::ifset($req, 'icon', null);
$title = Q::ifset($req, 'title', null);
$l = Q::ifset($req, 'label', 'Users/' . Q_Utils::normalize($title));
$label = Users_Label::addLabel($l, $userId, $title, $icon);
Q_Response::setSlot('label', $label->exportArray());
}
示例14: Users_label_put
/**
* Edits a label in the system. Fills the "label" (and possibly "icon") slot.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.label The label
* @param {string} [$_REQUEST.title] The title of the label
* @param {string} [$_REQUEST.icon] Optional path to an icon
* @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this
*/
function Users_label_put($params = array())
{
$req = array_merge($_REQUEST, $params);
Q_Request::requireFields(array('label'), $req, true);
$loggedInUserId = Users::loggedInUser(true)->id;
$userId = Q::ifset($req, 'userId', $loggedInUserId);
$l = $req['label'];
$icon = Q::ifset($req, 'icon', null);
$title = Q::ifset($req, 'title', null);
$label = Users_Label::updateLabel($userId, $l, compact('icon', 'title'));
Q_Response::setSlot('label', $label->exportArray());
}
示例15: Users_contact_put
/**
* Edits a contact in the system. Fills the "contact" slot.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.label The label of the contact
* @param {string} $_REQUEST.contactUserId The contactUserId of the contact
* @param {string} [$_REQUEST.nickname] The nickname of the contact
* @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this
*/
function Users_contact_put($params = array())
{
$req = array_merge($_REQUEST, $params);
Q_Request::requireFields(array('label', 'contactUserId'), $req, true);
$loggedInUserId = Users::loggedInUser(true)->id;
$userId = Q::ifset($req, 'userId', $loggedInUserId);
$label = $req['label'];
$contactUserId = $req['contactUserId'];
$nickname = Q::ifset($req, 'nickname', null);
$contact = Users_Contact::updateContact($userId, $label, $contactUserId, compact('nickname'));
Q_Response::setSlot('contact', $contact->exportArray());
}