本文整理汇总了PHP中Q::tool方法的典型用法代码示例。如果您正苦于以下问题:PHP Q::tool方法的具体用法?PHP Q::tool怎么用?PHP Q::tool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q
的用法示例。
在下文中一共展示了Q::tool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Streams_player_Websites_article
function Streams_player_Websites_article($options)
{
$stream = $options['stream'];
$emailSubject = Q::ifset($options, 'emailSubject', "Reaching out from your website");
$result = Q::tool('Websites/article', array('publisherId' => $stream->publisherId, 'streamName' => $stream->name, 'html' => array('placeholder' => 'Start editing the article here. Select some text to use the HTML editor.', 'froala' => array('key' => Q_Config::get('Streams', 'froala', 'key', null), 'pasteImage' => true)), 'getintouch' => array('email' => true, 'emailSubject' => $emailSubject, 'sms' => 'Text', 'call' => 'Call', 'class' => 'Q_button clickable')));
$result .= Q::tool("Websites/seo", array('skipIfNotAuthorized' => true, 'publisherId' => $stream->publisherId, 'streamName' => $stream->name));
return $result;
}
示例2: Streams_inplace_tool
/**
* This tool generates an inline editor to edit the content or attribute of a stream.
* @class Streams inplace
* @constructor
* @param {array} $options Options for the tool
* An associative array of parameters, containing:
* @param {string} [$options.inplaceType='textarea'] The type of the fieldInput. Can be "textarea" or "text"
* @param {array} [$options.convert] The characters to convert to HTML. Pass an array containing zero or more of "\n", " "
* @param {Streams_Stream} $options.stream A Streams_Stream object
* @param {string} [$options.field] Optional, name of an field to change instead of the content of the stream
* @param {string} [$options.attribute] Optional, name of an attribute to change instead of any field.
* @param {string} [$options.beforeSave] Reference to a callback to call after a successful save. This callback can cancel the save by returning false.
* @param {string} [$options.onSave] Reference to a callback or event to run after a successful save.
* @param {string} [$options.onCancel] Reference to a callback or event to run after cancel.
* @param {array} [$options.inplace=array()] Additional fields to pass to the child Q/inplace tool, if any
* @uses Q inplace
*/
function Streams_inplace_tool($options)
{
if (empty($options['stream'])) {
if (empty($options['publisherId']) or empty($options['streamName'])) {
throw new Q_Exception_RequiredField(array('field' => 'stream'));
}
$publisherId = $options['publisherId'];
$streamName = $options['streamName'];
$stream = Streams::fetchOne(null, $publisherId, $streamName);
if (!$stream) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => "publisherId={$publisherId}, name={$streamName}"));
}
} else {
$stream = $options['stream'];
}
$inplaceType = Q::ifset($options, 'inplaceType', 'textarea');
$inplace = array('action' => $stream->actionUrl(), 'method' => 'PUT', 'type' => $inplaceType);
if (isset($options['inplace'])) {
$inplace = array_merge($options['inplace'], $inplace);
}
$convert = Q::ifset($options, 'convert', array("\n"));
$inplace['hidden']['convert'] = json_encode($convert);
if (!empty($options['attribute'])) {
$field = 'attributes[' . urlencode($options['attribute']) . ']';
$content = $stream->get($options['attribute'], '');
$maxlength = $stream->maxSize_attributes - strlen($stream->maxSize_attributes) - 10;
} else {
$field = !empty($options['field']) ? $options['field'] : 'content';
$content = $stream->{$field};
$maxlength = $stream->maxSizeExtended($field);
}
switch ($inplaceType) {
case 'text':
$inplace['fieldInput'] = Q_Html::input($field, $content, array('placeholder' => Q::ifset($input, 'placeholder', null), 'maxlength' => $maxlength));
$inplace['staticHtml'] = Q_Html::text($content);
break;
case 'textarea':
$inplace['fieldInput'] = Q_Html::textarea($field, 5, 80, array('placeholder' => Q::ifset($inplace, 'placeholder', null), 'maxlength' => $maxlength), $content);
$inplace['staticHtml'] = Q_Html::text($content, $convert);
break;
default:
return "inplaceType must be 'textarea' or 'text'";
}
if (!$stream->testWriteLevel('suggest')) {
if (!isset($options['classes'])) {
$options['classes'] = '';
}
Q_Response::setToolOptions(array('publisherId' => $stream->publisherId, 'streamName' => $stream->name));
$staticClass = $options['inplaceType'] === 'textarea' ? 'Q_inplace_tool_blockstatic' : 'Q_inplace_tool_static';
return "<span class='Q_inplace_tool_container {$options['classes']}' style='position: relative;'>" . "<div class='{$staticClass}'>{$inplace['staticHtml']}</div></span>";
}
$toolOptions = array('publisherId' => $stream->publisherId, 'streamName' => $stream->name, 'inplaceType' => $options['inplaceType']);
Q::take($options, array('attribute', 'field', 'convert'), $toolOptions);
$toolOptions['inplace'] = $inplace;
Q_Response::setToolOptions($toolOptions);
return Q::tool("Q/inplace", $inplace);
}
示例3: Streams_publish_Broadcast_tool
function Streams_publish_Broadcast_tool($options)
{
extract($options);
$publisherId = $stream->publisherId;
$streamName = $stream->name;
$type = 'Broadcast';
$input = Q_Html::input('content', '');
$button = Q_Html::tag('button', array(), 'Post');
return Q_Html::form('Streams/stream', 'post', array(), Q_Html::formInfo(true) . Q_Html::hidden(compact('publisherId', 'streamName', 'type')) . Q::tool('Q/form', array('fields' => array('message' => array('type' => 'text', 'message' => 'this message will appear as if the user typed it before posting'), 'link' => array('type' => 'text', 'message' => 'the address of the webpage to share'), 'picture' => array('type' => 'text', 'message' => 'if you enter a picture url here, it will override the picture that is posted'), 'description' => array('type' => 'textarea', 'message' => 'if you enter something here, it will override the description that facebook would have automatically grabbed from that page'), '' => array('type' => 'button', 'value' => 'Post')), 'onSuccess' => 'Q.plugins.Broadcast.onBroadcastSuccess')));
}
示例4: Streams_player_tool
/**
* This tool generates an interface used for publishing messages to streams
* It basically renders the Streams/player/$type tool, where $type is the stream's type.
*
* @param array $options
* An associative array of parameters, containing:
* "publisherId" => required. The id of the publisher of the stream to which to post the message.
* "streamName" => required. The name of the stream to which to post the message.
*/
function Streams_player_tool($options)
{
extract($options);
if (empty($stream)) {
throw new Q_Exception("Missing stream object");
}
if (!Q::canHandle('Streams/player/' . $stream->type . '/tool')) {
throw new Q_Exception("No player tool has been implemented for streams of type {$stream->type}.");
}
return Q::tool('Streams/player/' . $stream->type, $options);
}
示例5: helperTool
static function helperTool($template, $context, $args, $source)
{
if (empty($args[0])) {
return "{{tool missing name}}";
}
$name = $args[0];
$id = count($args) > 1 && is_string($args[1]) ? $args[1] : null;
$options = Q::ifset($args, 'hash', array());
$fields = $context->fields();
$o = array_merge($options, Q::ifset($fields, $name, array()), Q::ifset($fields, "id:{$id}", array()));
return Q::tool($name, $o, compact('id'));
}
示例6: Streams_message_tool
function Streams_message_tool($options)
{
extract($options);
$user = Users::loggedInUser();
if (!$user) {
throw new Users_Exception_NotLoggedIn();
}
if (empty($publisherId)) {
$publisherId = Streams::requestedPublisherId();
}
if (empty($publisherId)) {
$publisherId = $_REQUEST['publisherId'] = $user->id;
}
if (empty($name)) {
$name = Streams::requestedName(true);
}
$stream = Streams::fetch($user->id, $publisherId, $name);
$stream = !empty($stream) ? reset($stream) : null;
if (!$stream) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with that name'), 'streamName');
}
if (!$stream->testReadLevel('messages') || !$stream->testWriteLevel('post')) {
throw new Users_Exception_NotAuthorized();
}
$hidden = array('publisherId' => $publisherId, 'streamName' => $name);
$fields = array('stream' => array('label' => 'Stream', 'type' => 'static', 'value' => $stream->title));
$type = Streams::requestedType();
// check if stream has messages
$types = Q_Config::get('Streams', 'messages', $stream->type, array());
if (count($types) === 0) {
throw new Q_Exception("Stream of type '{$stream->type}' does not support messages");
}
if (!empty($type) && !in_array($type, $types)) {
throw new Q_Exception("Requested message type '{$type}' is not alowed for streams of type '{$stream->type}'");
}
if (!empty($type)) {
$hidden['type'] = $type;
$fields['type'] = array('label' => 'Message type', 'type' => 'static', 'value' => $type);
} else {
$fields['type'] = array('label' => 'Message type', 'type' => 'select', 'options' => array_merge(array('' => 'Select type'), array_combine($types, $types)), 'value' => '');
}
$fields['content'] = array('label' => 'Content', 'type' => 'textarea');
$fields['submit'] = array('label' => '', 'type' => 'submit_buttons', 'options' => array('submit' => 'Post'));
return Q_Html::tag('h3', array(), 'Post a message') . Q_Html::form(Q_Request::baseUrl() . '/action.php/Streams/message', 'post', array(), Q_Html::hidden($hidden) . Q::tool('Q/form', array('fields' => $fields, 'onSuccess' => 'function (data) {
if (data.errors) alert(data.errors);
else {
alert("Message posted");
var message = Q.getObject(["slots", "form", "fields"], data);
Q.handle(Q.info.baseUrl+"/plugins/Streams/message?publisherId="+message.publisherId+"&name="+message.streamName);
}
}')));
}
示例7: Streams_category_tool
/**
* This tool generates a category selector.
*
* @param {array} $options An associative array of parameters, containing:
* @param {string} [$options.publisherId=Streams::requestedPublisherId()] The publisherId of the stream to present. If "stream" parameter is empty
* @param {string} [$options.streamName=Streams::requestedName()] The streamName of the stream to present. If "stream" parameter is empty
* @param {string} [options.relationType=null] Filter the relation type.
*/
function Streams_category_tool($options)
{
extract($options);
if (!$publisherId) {
$options['publisherId'] = $publisherId = Streams::requestedPublisherId(true);
}
if (!$streamName) {
$options['streamName'] = $streamName = Streams::requestedName(true);
}
Q_Response::setToolOptions($options);
$stream = Streams::fetchOne(null, $publisherId, $streamName, true);
$userId = Users::loggedInUser(true)->id;
return Q::tool('Streams/related', $options);
}
示例8: Users_account_tool
function Users_account_tool($options)
{
$uri = 'Users/account';
$omit = array();
$fields = array();
$title = "Basic Info";
$editing = true;
$complete = true;
$inProcess = false;
$collapsed = false;
$toggle = false;
$omit = array();
$setSlots = null;
extract($options, EXTR_OVERWRITE);
$default_fields = array('username' => array('type' => 'text', 'label' => 'Choose Username'), 'gender' => array('type' => 'select', 'label' => 'I am', 'options' => array('male' => 'a man', 'female' => 'a woman')), 'orientation' => array('type' => 'select', 'label' => 'Orientation', 'options' => array('straight' => 'straight', 'gay' => 'gay', 'bi' => 'bi')), 'relationship_status' => array('type' => 'select', 'label' => 'Status', 'options' => array('single' => "I'm single", 'open' => "I'm in an open relationship", 'relationship' => "I'm in a relationship", 'engaged' => "I'm engaged", 'married' => "I'm married", 'complicated' => "It's complicated", 'widowed' => "I'm widowed")), 'birthday' => array('type' => 'date', 'label' => 'My Birthday', 'options' => array('year_from' => '1920', 'year_to' => date('Y') - 16)), 'zipcode' => array('type' => 'text', 'label' => 'Zipcode', 'attributes' => array('maxlength' => 5)));
$fields = array_merge($default_fields, $fields);
$user = Users::loggedInUser(true);
if (isset($user->gender)) {
$fields['gender']['value'] = $user->gender;
}
if (isset($user->desired_gender)) {
if ($user->desired_gender == 'either') {
$fields['orientation']['value'] = 'bi';
} else {
if (isset($user->gender)) {
$fields['orientation']['value'] = $user->gender != $user->desired_gender ? 'straight' : 'gay';
}
}
}
if (isset($user->relationship_status)) {
$fields['relationship_status']['value'] = $user->relationship_status;
}
if (isset($user->birthday)) {
$fields['birthday']['value'] = date("Y-m-d", Users::db()->fromDate($user->birthday));
}
if (isset($user->zipcode)) {
$fields['zipcode']['value'] = $user->zipcode;
}
if (isset($user->username)) {
$fields['username']['value'] = $user->username;
}
foreach ($omit as $v) {
unset($fields[$v]);
}
$onSuccess = Q_Request::special('onSuccess', Q_Request::url());
$form = $static = compact('fields');
return Q::tool('Q/panel', compact('uri', 'title', 'form', 'static', 'onSuccess', 'complete', 'collapsed', 'toggle', 'editing', 'inProcess', 'static', 'setSlots'));
}
示例9: Streams_player_tool
function Streams_player_tool($options)
{
extract($options);
if (!isset($stream)) {
throw new Q_Exception_MissingObject(array('name' => 'stream'));
}
if (!$stream->testReadLevel('content')) {
$streamName_html = Q_Html::text($stream->name);
return "<a href='#{$streamName_html}'>hidden</a>";
}
$options['streamName'] = $stream->name;
$parts = explode('/', $stream->type);
switch ($parts[0]) {
case 'Streams/text/small':
case 'Streams/text/medium':
case 'Streams/text':
return $stream->content;
case 'Streams/date':
// TODO: localize
if (isset($parts[1]) and $parts[1] === 'birthday') {
return date('M j', strtotime($stream->content));
}
return date('M j, Y', strtotime($stream->content));
case 'Streams/number':
if (isset($parts[1]) and $parts[1] === 'age') {
if (!empty($streams['Streams/user/birthday']->content)) {
return Db::ageFromDateTime($streams['Streams/user/birthday']->content);
}
return null;
}
return $strem->content;
case 'Streams/category':
// TODO: implement
// TODO: implement
case 'Streams/chat':
// TODO: implement
// TODO: implement
case 'Streams/community':
// TODO: implement
// TODO: implement
default:
$event = $stream->type . "/tool";
if (Q::canHandle($event)) {
return Q::tool($stream->type, $options);
}
return Q_Html::tag('div', array('class' => 'Streams_player_stream_content'), Q_Html::text($stream->content));
}
}
示例10: Users_identifier_tool
function Users_identifier_tool($options)
{
$defaults = array('uri' => 'Users/identifier', 'omit' => array(), 'fields' => array(), 'title' => "Contact Info", 'collapsed' => false, 'toggle' => false, 'editing' => true, 'complete' => true, 'inProcess' => false, 'prompt' => "In order for things to work, we must be able to reach you.", 'button_content' => 'OK');
extract(array_merge($defaults, $options));
$default_fields = array('emailAddress' => array('type' => 'text', 'label' => 'Email'));
$fields = array_merge($default_fields, $fields);
$user = Users::loggedInUser(true);
$email = null;
if (isset($user->emailAddress)) {
$fields['emailAddress']['value'] = $user->emailAddress;
} else {
if ($user->emailAddressPending) {
$link = Q_Html::a('#resend', array('class' => 'Users_idenfitier_tool_resend'), "You can re-send the activation email");
$email = new Users_Email();
$email->address = $user->emailAddressPending;
if ($email->retrieve()) {
switch ($email->state) {
case 'active':
if ($email->userId == $user->id) {
$message = "Please confirm this email address.<br>{$link}";
} else {
$message = "This email seems to belong to another user";
}
break;
case 'suspended':
$message = "This address has been suspended.";
break;
case 'unsubscribed':
$message = "The owner of this address has unsubscribed";
break;
case 'unverified':
default:
$message = "Not verified yet.<br>{$link}";
break;
}
$fields['emailAddress']['value'] = $email->address;
$fields['emailAddress']['message'] = $message;
} else {
// something went wrong, so we'll try to correct it
$user->emailAddressPending = "";
$user->save();
}
}
}
$onSuccess = Q_Request::special('onSuccess', Q_Request::url());
$form = $static = compact('fields');
return Q::tool('Q/panel', compact('uri', 'onSuccess', 'form', 'static', 'title', 'collapsed', 'toggle', 'complete', 'editing', 'inProcess', 'setSlots'));
}
示例11: Streams_invite_response_content
function Streams_invite_response_content()
{
$user = Users::loggedInUser(true);
$publisherId = Streams::requestedPublisherId();
if (empty($publisherId)) {
$publisherId = $user->id;
}
$streamName = Streams::requestedName(true);
$stream = new Streams_Stream();
$stream->publisherId = $publisherId;
$stream->name = $streamName;
if (!$stream->retrieve()) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => "{publisherId: '{$publisherId}', name: '{$streamName}'}"));
}
return Q::tool('Streams/invite', compact('stream'));
}
示例12: Streams_access_response_content
function Streams_access_response_content($options)
{
$ajax = true;
$user = Users::loggedInUser(true);
$streamName = Streams::requestedName(true);
$publisherId = Streams::requestedPublisherId();
if (empty($publisherId)) {
$publisherId = $user->id;
}
$stream = new Streams_Stream();
$stream->publisherId = $publisherId;
$stream->name = $streamName;
if (!$stream->retrieve()) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with that name'), 'name');
}
$controls = !empty($options['controls']);
Q_Response::setSlot('title', "Access to: " . $stream->title);
return Q::tool('Streams/access', compact('publisherId', 'streamName', 'ajax', 'controls'), $controls ? array('tag' => null) : array());
}
示例13: helperTool
static function helperTool($template, $context, $args, $source)
{
if (empty($args[0])) {
return "{{tool missing name}}";
}
$name = $args[0];
if (count($args) > 1 && (is_string($args[1]) || is_numeric($args[1]))) {
$id = $args[1];
}
$o = Q::ifset($args, 'hash', array());
$fields = $context->fields();
if (isset($fields[$name])) {
$o = array_merge($o, $fields[$name]);
}
if ($id && isset($fields["id:{$id}"])) {
$o = array_merge($o, $fields["id:{$id}"]);
}
return Q::tool($name, $o, compact('id'));
}
示例14: Streams_message_response_content
function Streams_message_response_content()
{
return Q::tool('Streams/message');
}
示例15: compact
<div id="content">
<?php
echo Q::tool('Shipping/shipment/details', compact("shipment"));
?>
<?php
echo Q::tool('Shipping/packages', array("shipment" => $shipment, "title" => "Packages details", "prefix" => "packages", "descPlaceHolder" => "Describe the package if it is in any way unusual", "requiredFields" => array("width", "length", "height", "weight")), "packages");
?>
<?php
echo Q::tool('Shipping/carriers', compact("shipment"));
?>
<?php
echo Q::tool('Shipping/invoice/options', compact("shipment"));
?>
<?php
echo Q::tool('Shipping/pickup', array("secondsBetween" => 3600, "shipment" => $shipment));
// some carriers need difference 3 hours
?>
<?php
echo Q::tool('Shipping/template', compact("shipment"));
?>
<?php
echo Q::tool('Shipping/shipment/submit', compact("shipment"));
?>
</div>