本文整理汇总了PHP中Q::ifset方法的典型用法代码示例。如果您正苦于以下问题:PHP Q::ifset方法的具体用法?PHP Q::ifset怎么用?PHP Q::ifset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q
的用法示例。
在下文中一共展示了Q::ifset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Streams_invitations_response
/**
* Displays an HTML document that can be printed, ideally with line breaks.
* Uses a particular view for the layout.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.invitingUserId Required. The id of the user that generated the invitations with a call to Streams::invite.
* @param {string} $_REQUEST.batch Required. The name of the batch under which invitations were saved during a call to Streams::invite.
* @param {string} [$_REQUEST.limit=100] The maximum number of invitations to show on the page
* @param {string} [$_REQUEST.offset=0] Used for paging
* @param {string} [$_REQUEST.title='Invitations'] Override the title of the document
* @param {string} [$_REQUEST.layout='default'] The name of the layout to use for the HTML document
* @see Users::addLink()
*/
function Streams_invitations_response()
{
Q_Request::requireFields(array('batch', 'invitingUserId'), true);
$invitingUserId = $_REQUEST['invitingUserId'];
$batch = $_REQUEST['batch'];
$title = Q::ifset($_REQUEST, 'layout', 'title');
$layoutKey = Q::ifset($_REQUEST, 'layout', 'default');
$limit = min(1000, Q::ifset($_REQUEST, 'limit', 100));
$offset = Q::ifset($_REQUEST, 'offset', 0);
$layout = Q_Config::expect('Streams', 'invites', 'layout', $layoutKey);
$app = Q_Config::expect('Q', 'app');
$pattern = Streams::invitationsPath($invitingUserId) . DS . $batch . DS . "*.html";
$filenames = glob($pattern);
$parts = array();
foreach ($filenames as $f) {
if (--$offset > 0) {
continue;
}
$parts[] = file_get_contents($f);
if (--$limit == 0) {
break;
}
}
$content = implode("\n\n<div class='Q_pagebreak Streams_invitations_separator'></div>\n\n", $parts);
echo Q::view($layout, compact('content', 'parts'));
return false;
}
示例2: Q_expandable_tool
/**
* This tool implements expandable containers that work on most modern browsers,
* including ones on touchscreens.
* @class Q expandable
* @constructor
* @param {array} $options Options for the tool
* @param {string} $options.title Required. The title for the expandable.
* @param {string} $options.content The content. Required unless you pass "items" instead.
* @param {array} [$options.items] An array of strings to wrap in <span> elements and render in the content
* @param {string} [$options.class] If you use "items", optionally specify the class of the container elements for each item
* @param {integer} [$options.title] A number, if any, to display when collapsed
* @param {boolean} [$options.autoCollapseSiblings] Whether, when expanding an expandable, its siblings should be automatically collapsed.
*/
function Q_expandable_tool($options)
{
if (isset($options['items'])) {
$classString = isset($options['class']) ? "class='{$options['class']}'" : '';
$lines = array();
foreach ($options['items'] as $key => $value) {
$lines[] = "<span {$classString}>{$key}</span>";
}
$between = Q::ifset($options, 'between', '');
$options['content'] = implode($between, $lines);
}
foreach (array('title', 'content') as $field) {
if (!isset($options[$field])) {
throw new Q_Exception_RequiredField(compact('field'));
}
}
Q_Response::addScript('plugins/Q/js/tools/expandable.js');
Q_Response::addStylesheet('plugins/Q/css/expandable.css');
$count = Q::ifset($options, 'count', '');
$style = empty($options['expanded']) ? '' : 'style="display:block"';
$h2 = "<h2>\n\t<span class='Q_expandable_count'>{$count}</span>\n\t{$options['title']}\n</h2>";
$div = "<div class='Q_expandable_container' {$style}><div class='Q_expandable_content'>\n\t{$options['content']}\n</div></div>";
Q_Response::setToolOptions($options);
return $h2 . $div;
}
示例3: Websites_seo_tool
/**
* Tool for admins to edit the url, title, keywords, description of the current page
* @class Websites seo
* @constructor
* @param {Object} [$options] Options for the tool
* @param {String} [$options.skipIfNotAuthorized=true] Whether to skip rendering the contents of the tool if the logged-in user is not authorized to edit the SEO information for this page.
*/
function Websites_seo_tool($options)
{
$skipIfNotAuthorized = Q::ifset($options, 'skipIfNotAuthorized', true);
if ($skipIfNotAuthorized) {
$websitesUserId = Users::communityId();
$sha1 = sha1(Q_Dispatcher::uri());
$seoStreamName = "Websites/seo/{$sha1}";
$stream = Streams::fetchOne(null, $websitesUserId, $seoStreamName);
$user = Users::loggedInUser();
if (!$user or $stream and !$stream->testWriteLevel('suggest')) {
$options['skip'] = true;
}
if (!$stream and !Streams::isAuthorizedToCreate($user->id, $websitesUserId, 'Websites/seo')) {
$options['skip'] = true;
}
}
unset($options['skipIfNotAuthorized']);
Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
Q_Response::addScript("plugins/Websites/js/Websites.js");
Q_Response::setToolOptions($options);
$user = Users::loggedInUser(false, false);
$userId = $user ? $user->id : "";
$communityId = Users::communityId();
$sha1 = sha1(Q_Dispatcher::uri());
$seoStreamName = "Websites/seo/{$sha1}";
$streams = Streams::fetch($userId, $communityId, array("Websites/header", "Websites/title", "Websites/slogan", $seoStreamName));
foreach ($streams as $name => $s) {
if ($s) {
$s->addPreloaded($userId);
}
}
}
示例4: Streams_interests_response
function Streams_interests_response()
{
// serve a javascript file and tell client to cache it
$app = Q_Config::expect('Q', 'app');
$communityId = Q::ifset($_REQUEST, 'communityId', $app);
$tree = new Q_Tree();
$tree->load("files/Streams/interests/{$communityId}.json");
$categories = $tree->getAll();
foreach ($categories as $category => &$v1) {
foreach ($v1 as $k2 => &$v2) {
if (!Q::isAssociative($v2)) {
ksort($v1);
break;
}
ksort($v2);
}
}
header('Content-Type: text/javascript');
header("Pragma: ", true);
// 1 day
header("Cache-Control: public, max-age=86400");
// 1 day
$expires = date("D, d M Y H:i:s T", time() + 86400);
header("Expires: {$expires}");
// 1 day
$json = Q::json_encode($categories, true);
echo "Q.setObject(['Q', 'Streams', 'Interests', 'all', '{$communityId}'], {$json});";
return false;
}
示例5: Streams_message_response_messages
function Streams_message_response_messages()
{
if (isset(Streams::$cache['message'])) {
$message = Streams::$cache['message'];
return Db::exportArray(array($message->ordinal => $message));
}
if (isset(Streams::$cache['messages'])) {
return Db::exportArray(Streams::$cache['messages']);
}
$publisherId = Streams::requestedPublisherId(true);
$streamName = Streams::requestedName(true);
$type = Streams::requestedMessageType();
$stream = Q::ifset(Streams::$cache, 'stream', Streams::fetchOne(null, $publisherId, $streamName, true));
$maxLimit = Streams_Stream::getConfigField($type, 'getMessagesLimit', 100);
$limit = min($maxLimit, Q::ifset($_REQUEST, 'limit', $maxLimit));
if (isset($_REQUEST['ordinal'])) {
$min = $_REQUEST['ordinal'];
$limit = 1;
}
if (isset($_REQUEST['min'])) {
$min = $_REQUEST['min'];
}
$max = isset($_REQUEST['max']) ? $_REQUEST['max'] : -1;
if (isset($_REQUEST['ascending'])) {
$ascending = $_REQUEST['ascending'];
}
if (!$stream->testReadLevel('messages')) {
throw new Users_Exception_NotAuthorized();
}
$messages = $stream->getMessages(compact('type', 'min', 'max', 'limit', 'ascending'));
return Db::exportArray($messages);
}
示例6: 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());
}
示例7: Websites_article_tool
/**
* This tool generates an HTML article viewer that lets authorized users edit the article.
* @class Websites article
* @constructor
* @param {Object} [$options] parameters for the tool
* @param {String} $options.publisherId The article publisher's user id
* @param {String} $options.streamName The article's stream name
* @param {String} $options.stream The article's stream, if it is already fetched
* @param {String} [$options.html=array()] Any additional for the Streams/html editor
* @param {String} [$options.getintouch=array()] Additional options for the Users/getintouch tool, in case it's rendered
*/
function Websites_article_tool($options)
{
$publisherId = $options['publisherId'];
$streamName = $options['streamName'];
$article = Q::ifset($options, 'stream', Streams::fetchOne(null, $publisherId, $streamName));
if (!$article) {
throw new Q_Exception_MissingRow(array('table' => 'article', 'criteria' => $streamName));
}
$getintouch = array_merge(array('user' => $article->userId, 'email' => true, 'sms' => true, 'call' => true, 'between' => "", 'emailSubject' => 'Reaching out from your website', 'class' => 'Q_button Q_clickable'), Q::ifset($options, 'getintouch', array()));
$canView = $article->testReadLevel('content');
$canEdit = $article->testWriteLevel('edit');
if ($article->getintouch) {
if (is_array($git = json_decode($article->getintouch, true))) {
$getintouch = array_merge($getintouch, $git);
}
}
$getintouch['class'] = 'Q_button';
if (!$canView) {
throw new Users_Exception_NotAuthorized();
}
$html = Q::ifset($options, 'html', array());
$article->addPreloaded();
Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
Q_Response::addScript("plugins/Websites/js/Websites.js");
Q_Response::setToolOptions($options);
return Q::view("Websites/tool/article.php", compact('article', 'getintouch', 'canEdit', 'canView', 'html'));
}
示例8: Streams_invite_response_data
function Streams_invite_response_data()
{
if (isset(Streams::$cache['invited'])) {
return Streams::$cache['invited'];
}
$user = Users::loggedInUser(true);
$publisherId = Streams::requestedPublisherId();
$streamType = Streams::requestedType();
$invitingUserId = Streams::requestedField('invitingUserId');
$limit = Q::ifset($_REQUEST, 'limit', Q_Config::get('Streams', 'invites', 'limit', 100));
$invited = Streams_Invited::select('*')->where(array('userId' => $user->id, 'state' => 'pending', 'expireTime <' => new Db_Expression('CURRENT_TIMESTAMP')))->limit($limit)->fetchDbRows(null, null, 'token');
$query = Streams_Invite::select('*')->where(array('token' => array_keys($invited)));
if (isset($publisherId)) {
$query = $query->where(array('publisherId' => $publisherId));
}
if (isset($streamType)) {
$query = $query->where(array('streamName' => new Db_Range($streamType . '/', true, false, true)));
}
if (isset($invitingUserId)) {
$query = $query->where(array('invitingUserId' => $invitingUserId));
}
$invites = $query->fetchDbRows();
$streams = array();
foreach ($invites as $invite) {
$stream = new Streams_Stream();
$stream->publisherId = $invite->publisherId;
$stream->name = $invite->streamName;
if ($stream->retrieve()) {
$streams[$invite->token] = $stream->exportArray();
$streams[$invite->token]['displayName'] = $invite->displayName;
}
}
return compact('streams', 'invites');
}
示例9: Streams_invitations_response
/**
* Displays an HTML document that can be printed, ideally with line breaks.
* Uses a particular view for the layout.
* @param {array} $_REQUEST
* @param {string} $_REQUEST.invitingUserId Required. The id of the user that generated the invitations with a call to Streams::invite.
* @param {string} $_REQUEST.batch Required. The name of the batch under which invitations were saved during a call to Streams::invite.
* @param {string} [$_REQUEST.limit=100] The maximum number of invitations to show on the page
* @param {string} [$_REQUEST.offset=0] Used for paging
* @param {string} [$_REQUEST.title='Invitations'] Override the title of the document
* @param {string} [$_REQUEST.layout='default'] The name of the layout to use for the HTML document
* @see Users::addLink()
*/
function Streams_invitations_response()
{
Q_Request::requireFields(array('batch', 'invitingUserId'), true);
$invitingUserId = $_REQUEST['invitingUserId'];
$batch = $_REQUEST['batch'];
$user = Users::loggedInUser(true);
$stream = Streams::fetchOne(null, $invitingUserId, 'Streams/invitations', true);
if (!$stream->testReadLevel('content')) {
throw new Users_Exception_NotAuthorized();
}
$title = Q::ifset($_REQUEST, 'layout', 'title');
$layoutKey = Q::ifset($_REQUEST, 'layout', 'default');
$limit = min(1000, Q::ifset($_REQUEST, 'limit', 100));
$offset = Q::ifset($_REQUEST, 'offset', 0);
$layout = Q_Config::expect('Streams', 'invites', 'layout', $layoutKey);
$pattern = Streams::invitationsPath($invitingUserId) . DS . $batch . DS . "*.html";
$filenames = glob($pattern);
$parts = array();
foreach ($filenames as $f) {
if (--$offset > 0) {
continue;
}
$parts[] = file_get_contents($f);
if (--$limit == 0) {
break;
}
}
$content = implode("\n\n<div class='Q_pagebreak Streams_invitations_separator'></div>\n\n", $parts);
echo Q::view($layout, compact('title', 'content', 'parts'));
return false;
}
示例10: Users_identifier_post
function Users_identifier_post()
{
$userId = Q::ifset($_REQUEST, 'userId', null);
if (isset($userId)) {
$user = Users_User::fetch($userId, true);
if ($user->emailAddress or $user->mobileNumber) {
throw new Q_Exception("This user is already able to log in and set their own email and mobile number.");
}
} else {
$user = Users::loggedInUser(true);
}
$app = Q_Config::expect('Q', 'app');
$fields = array();
$identifier = Users::requestedIdentifier($type);
if (!$type) {
throw new Q_Exception("a valid email address or mobile number is required", array('identifier', 'mobileNumber', 'emailAddress'));
}
if ($type === 'email') {
$subject = Q_Config::get('Users', 'transactional', 'identifier', 'subject', "Welcome! Verify your email address.");
$view = Q_Config::get('Users', 'transactional', 'identifier', 'body', 'Users/email/addEmail.php');
$user->addEmail($identifier, $subject, $view, array(), array('html' => true));
} else {
if ($type === 'mobile') {
$view = Q_Config::get('Users', 'transactional', 'identifier', 'sms', 'Users/sms/addMobile.php');
$user->addMobile($identifier, $view);
}
}
}
示例11: Streams_stream_response_Q_inplace
function Streams_stream_response_Q_inplace()
{
$stream = isset(Streams::$cache['stream']) ? Streams::$cache['stream'] : null;
if (!$stream) {
throw new Exception("No stream");
}
if (isset($_REQUEST['title'])) {
$result = $stream->title;
} else {
if (isset($_REQUEST['attributes'])) {
if (is_array($_REQUEST['attributes'])) {
reset($_REQUEST['attributes']);
$result = $stream->getAttribute(key($_REQUEST['attributes']));
} else {
$result = $stream->attributes;
}
} else {
$fieldNames = array_diff(Streams::getExtendFieldNames($stream->type), array('insertedTime', 'updatedTime'));
$field = 'content';
foreach ($fieldNames as $f) {
if (isset($_REQUEST[$f])) {
$field = $f;
break;
}
}
$result = $stream->{$field};
}
}
$convert = Q::ifset($_REQUEST, 'convert', '["\\n"]');
return Q_Html::text($result, json_decode($convert, true));
}
示例12: 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());
}
示例13: Assets_subscription_tool
/**
* Standard tool for starting or managing subscriptions.
* @class Assets subscription
* @constructor
* @param {array} $options Override various options for this tool
* @param {string} $options.payments can be "authnet" or "stripe"
* @param {string} $options.planStreamName the name of the subscription plan's stream
* @param {string} [$options.publisherId=Q.Users.communityId] the publisher of the subscription plan's stream
* @param {string} [$options.subscribeButton] Can override the title of the subscribe button
* @param {array} [$options=array()] Any additional options
* @param {string} [$options.token=null] required unless the user is an existing customer
*/
function Assets_subscription_tool($options)
{
if (empty($options['payments'])) {
throw new Q_Exception_RequiredField(array('field' => 'payments'), 'payments');
}
$payments = ucfirst($options['payments']);
$lcpayments = strtolower($payments);
$currency = strtolower(Q::ifset($options, 'currency', 'usd'));
if ($payments === 'Authnet' and $currency !== 'usd') {
throw new Q_Exception("Authnet doesn't support currencies other than USD", 'currency');
}
$className = "Assets_Payments_{$payments}";
switch ($payments) {
case 'Authnet':
$adapter = new $className($options);
$token = $options['token'] = $adapter->authToken();
$testing = $options['testing'] = Q_Config::expect('Assets', 'payments', $lcpayments, 'testing');
$action = $options['action'] = $testing ? "https://test.authorize.net/profile/manage" : "https://secure.authorize.net/profile/manage";
break;
case 'Stripe':
$publishableKey = Q_Config::expect('Assets', 'payments', 'stripe', 'publishableKey');
break;
}
$titles = array('Authnet' => 'Authorize.net', 'Stripe' => 'Stripe');
$subscribeButton = Q::ifset($options, 'subscribeButton', "Subscribe with " . $titles[$payments]);
Q_Response::setToolOptions($options);
return Q::view("Assets/tool/subscription/{$payments}.php", compact('token', 'publishableKey', 'action', 'paymentButton', 'subscribeButton', 'planStreamName'));
}
示例14: Streams_after_Q_objects
function Streams_after_Q_objects()
{
$user = Users::loggedInUser();
if (!$user) {
return;
}
$invite = Streams::$followedInvite;
if (!$invite) {
return;
}
$displayName = $user->displayName();
if ($displayName) {
return;
}
$stream = new Streams_Stream();
$stream->publisherId = $invite->publisherId;
$stream->name = $invite->streamName;
if (!$stream->retrieve()) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with that name'), 'streamName');
}
// Prepare the complete invite dialog
$invitingUser = Users_User::fetch($invite->invitingUserId);
list($relations, $related) = Streams::related($user->id, $stream->publisherId, $stream->name, false);
$params = array('displayName' => null, 'action' => 'Streams/basic', 'icon' => $user->iconUrl(), 'token' => $invite->token, 'user' => array('icon' => $invitingUser->iconUrl(), 'displayName' => $invitingUser->displayName(array('fullAccess' => true))), 'stream' => $stream->exportArray(), 'relations' => Db::exportArray($relations), 'related' => Db::exportArray($related));
$config = Streams_Stream::getConfigField($stream->type, 'invite', array());
$defaults = Q::ifset($config, 'dialog', array());
$tree = new Q_Tree($defaults);
if ($tree->merge($params)) {
$dialogData = $tree->getAll();
if ($dialogData) {
Q_Response::setScriptData('Q.plugins.Streams.invite.dialog', $dialogData);
Q_Response::addTemplate('Streams/invite/complete');
}
}
}
示例15: Users_activate_validate
function Users_activate_validate()
{
$uri = Q_Dispatcher::uri();
$emailAddress = Q::ifset($_REQUEST, 'e', $uri->emailAddress);
$mobileNumber = Q::ifset($_REQUEST, 'm', $uri->mobileNumber);
if ($emailAddress && !Q_Valid::email($emailAddress, $e_normalized, array('no_ip' => 'false'))) {
throw new Q_Exception_WrongValue(array('field' => 'email', 'range' => 'a valid email address'), 'emailAddress');
}
if ($mobileNumber && !Q_Valid::phone($mobileNumber, $m_normalized)) {
throw new Q_Exception_WrongValue(array('field' => 'mobile phone', 'range' => 'a valid phone number'), 'mobileNumber');
}
if ($emailAddress or $mobileNumber) {
if (empty($_REQUEST['code'])) {
throw new Q_Exception("The activation code is missing");
}
} else {
throw new Q_Exception("The contact information is missing");
}
if (!empty($e_normalized)) {
Users::$cache['emailAddress'] = $e_normalized;
}
if (!empty($m_normalized)) {
Users::$cache['mobileNumber'] = $m_normalized;
}
}