示例#1
0
/**
 * 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;
}
示例#2
0
/**
 * Renders a Websites/presentation stream,
 * including an interface to edit the presentation
 * for users who have the permissions to do so.
 * @param {array} $options
 * @param {string} $options.publisherId
 * @param {string} $options.streamName
 */
function Websites_presentation_tool($options)
{
    Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
    Q_Response::addScript('plugins/Websites/js/Websites.js');
    Q_Response::setToolOptions($options);
    return '';
}
function Streams_before_Q_responseExtras()
{
    Q_Response::addScript('plugins/Streams/js/Streams.js');
    $host = Q_Config::get('Streams', 'node', 'host', Q_Config::get('Q', 'node', 'host', null));
    $port = Q_Config::get('Streams', 'node', 'port', Q_Config::get('Q', 'node', 'port', null));
    $user = Users::loggedInUser();
    if ($user) {
        Q_Response::setScriptData('Q.plugins.Users.loggedInUser.displayName', Streams::displayName($user));
    }
    if (!Q_Request::isAjax()) {
        $invite_url = Q_Config::get('Streams', 'invite', 'url', "http://invites.to");
        Q_Response::setScriptData('Q.plugins.Streams.invite.url', $invite_url);
        if (isset($host) && isset($port)) {
            Q_Response::setScriptData('Q.plugins.Streams.node', array("http://{$host}:{$port}"));
        }
        if ($sizes = Q_Config::expect('Streams', 'types', 'Streams/image', 'sizes')) {
            sort($sizes);
            Q_Response::setScriptData('Q.plugins.Streams.image.sizes', $sizes);
        }
        $defaults = array('readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['join'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']);
        Q_Response::setScriptData('Q.plugins.Streams.defaults', $defaults);
        if ($froalaKey = Q_Config::get('Streams', 'froala', 'key', null)) {
            Q_Response::setScriptData('Q.plugins.Streams.froala.key', $froalaKey);
        }
    }
    Q_Response::addStylesheet("plugins/Streams/css/Streams.css");
}
示例#4
0
文件: tool.php 项目: dmitriz/Platform
/**
 * Renders a photo selector tool
 * @param $options
 *   An associative array of parameters, which can include:
 * @param {Object} [$options] this object contains function parameters
 *   @param {Q.Event} $options.onSelect Required string naming the callback to be called when the user selects a photo.
 *   @param {Q.Event} [$options.beforePhotos] Triggered when photos are about to be rendered.
 *   @param {Q.Event} [$options.onPhotos] Triggered when photos have been rendered.
 *   @param {String} [$options.uid='me'] Optional. The uid of the user on the provider whose photos should be shown. Facebook only allows 'me' or a page id as a value.
 *   @param {String} [$options.fetchBy='album'] The tool supports different algoriths for fetching photos. Can be either by 'album' or 'tags'. Maybe more will be added later.
 *   @param {String} [$options.preprocessAlbums] Optional function to process the albums array before presenting it in the select. Receives a reference to the albums array as the first parameter, and a callback to call when it's done as the second.
 *   @param {String} [$options.preprocessPhotos] Optional function to process the photos array before presenting it in the select. Receives a reference to the albums array as the first parameter, and a callback to call when it's done as the second.
 *   @param {Q.Event} [$options.onLoad] Q.Event, callback or callback string name which is called when bunch of photos has been loaded.
 *   @param {Q.Event} [$options.onError] Q.Event, callback or callback string which will be called for each image that is unable to load. Image DOM element will be passed as first argument.
 *   @param {String} [$options.provider='facebook'] Has to be "facebook" for now.
 *   @param {String} [$options.prompt=false]
 *   Specifies type of prompt if user is not logged in or didn't give required permission for the tool.
 *   Can be either 'button', 'dialog' or null|false. 
 *   In first case just shows simple button which opens facebook login popup.
 *   In second case shows Users.facebookDialog prompting user to login.
 *   In third case will not show any prompt and will just hide the tool.
 *   @param {String} [$options.promptTitle]  Used only when 'prompt' equals 'dialog' - will be title of the dialog.
 *   @param {String} [$options.promptText]  Used either for button caption when 'prompt' equals 'button' or dialog text when 'prompt' equals 'dialog'.
 *   @param {Boolean} [$options.oneLine]  If true, all the images are shown in a large horizontally scrolling line.
 * @return {void}
 */
function Streams_photoSelector_tool($options)
{
    Q_Response::addScript('plugins/Streams/js/Streams.js');
    Q_Response::addStylesheet('plugins/Streams/css/Streams.css');
    Q_Response::setToolOptions($options);
    return '';
}
示例#5
0
/**
 * 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'));
}
示例#6
0
文件: tool.php 项目: dmitriz/Platform
/**
 * Ticker that scrolls its contents with various speeds and pauses
 * @class Q ticker
 * @constructor
 * @param {array} $options
 *  An associative array of fields, possibly including:
 *
 * "content" => string
 *  The content of the ticker. The first top-level element
 *  should contain sub-elements, and their sizes determine where
 *  the ticker would pause between automatically scrolling.
 *  The ticker animates by scrolling its inner contents.
 *
 * "vertical" => bool
 *  Defaults to true. If false, the ticker scrolls horizontally.
 *
 * "speed" => integer
 *  The scrolling speed.
 *  This is the number of items that would scroll by in 1 second,
 *  if there were no pauses.
 *  When the speed is positive, vertical tickers scroll down, and
 *  horizontal tickers scroll to the right. New content seems to come in
 *  from the bottom (for vertical tickers) or right (for horizontal tickers)
 *  as the ticker scrolls. The element inside the ticker will start out
 *  aligned with the top side of the ticker (for vertical tickers),
 *  or the left side of the ticker (for horizontal tickers).
 *  When the speed is negative, all this faces the other way.
 *
 * "pause_ms" => int
 *  Defaults to 2000. This is the number of milliseconds to wait
 *  after each second-level element of $content is automatically
 *  scrolled completely into view.
 *
 * "pause_ms_min" => int
 *  If set, then the number of milliseconds to pause is a random
 *  integer between $pause_ms_min and $pause_ms.
 *
 * "scrollbars" => bool
 *  Defaults to true. If true, shows scrollbars, otherwise doesn't.
 *  (Note: this will let the user know how much content is left,
 *   and be able to see it before it would automatically scroll into view.)
 *
 * "scrollbars_pause_ms" => int
 *  Defaults to 500. The ticker pauses its automatic scrolling when the user
 *  starts using the scrollbars. This is the number of milliseconds to wait
 *  until resuming the automatic scrolling.
 *
 * "anim_ms" => int
 *  Defaults to 100. This is the number of milliseconds between calls to
 *  autoScroll.
 *
 * "initial_scroll_mode" => string
 *  Defaults to 'auto'. This is the mode that scrolling starts out in.
 *  Possible values are 'auto' and 'paused'.
 *
 * "ease" => string
 *  Optional. If set, specifies the name of the ease function
 */
function Q_ticker_tool($options = array())
{
    $defaults = array('vertical' => true, 'speed' => 1, 'pause_ms' => 2000, 'scrollbars' => true, 'scrollbars_pause_ms' => 500, 'anim_ms' => 100);
    $fields2 = array_merge($defaults, $options);
    if (!isset($fields2['pause_ms_min'])) {
        $fields2['pause_ms_min'] = $fields2['pause_ms'];
    }
    if (!isset($fields2['content'])) {
        $li_array = array();
        for ($i = 0; $i < 100; ++$i) {
            $li_array[] = '<li><div style="background-color:#' . dechex(rand(0, 16)) . dechex(rand(0, 16)) . dechex(rand(0, 16)) . dechex(rand(0, 16)) . dechex(rand(0, 16)) . dechex(rand(0, 16)) . '">Missing $content parameter. This is just example #' . $i . '</div></li>';
        }
        $default_content = implode("\n", $li_array);
        if ($fields2['vertical']) {
            $fields2['content'] = "<ul class='error'>{$default_content}</ul>";
        } else {
            $fields2['content'] = "<ul class='error'>{$default_content}</ul>";
        }
    }
    Q_Response::addStylesheet('plugins/Q/css/ticker.css');
    Q_Response::addScript('plugins/Q/js/tools/ticker.js');
    Q_Response::setToolOptions($fields2);
    $direction_class = $fields2['vertical'] ? 'vertical' : 'horizontal';
    $scrollbars_class = $fields2['scrollbars'] ? 'scrollbars' : '';
    return Q_Html::tag('div', array('class' => "Q_ticker {$direction_class} {$scrollbars_class}"), $fields2['content']);
}
示例#7
0
function Shipping_shipment_response_content($params)
{
    $user = Users::loggedInUser(true);
    // copy from shipment
    $useTemplate = Q_Request::uri()->template ? "Shipping/shipment/" . Q_Request::uri()->template : false;
    // Check if stream "Shipping/shipments" exists for current user. If no -> create one.
    Shipping::shipments();
    // Check if stream "Shipping/templates" exists for current user. If no -> create one.
    Shipping::createTemplatesStream();
    // Collect streams for shipments. Relations: "describing", "scheduled", "confirmed", "shipping", "canceled", "returned"
    $shipment = Shipping::shipment();
    //$shipment->addPreloaded($userId);
    // test for UPS pickup
    //$stream = Streams::fetchOne("Shipping", "Shipping", "Shipping/shipment/Qdqpcspny");
    //$carrier = new Shipping_Carrier_UPS();
    //$carrier->pickupCreate($stream);
    //-------------------------------
    // add main style
    Q_Response::addStylesheet('css/Shipment.css');
    // set communityId
    Q_Response::setScriptData("Q.info.communityId", Users::communityId());
    Q_Response::setScriptData("Q.info.useTemplate", $useTemplate);
    Q_Response::addScript('js/shipment.js');
    Q_Response::addScript('js/date.js');
    // add jquery UI
    //Q_Response::addStylesheet('//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
    //Q_Response::addScript('//code.jquery.com/ui/1.11.4/jquery-ui.js');
    // add pickadate as date picker
    Q_Response::addStylesheet('js/pickadate/compressed/themes/default.css');
    Q_Response::addStylesheet('js/pickadate/compressed/themes/default.date.css');
    Q_Response::addScript('js/pickadate/compressed/picker.js');
    Q_Response::addScript('js/pickadate/compressed/picker.date.js');
    return Q::view('Shipping/content/shipment.php', compact('user', 'shipment', 'useTemplate'));
}
示例#8
0
function Overlay_before_Q_responseExtras()
{
    $app = Q_Config::expect('Q', 'app');
    Q_Response::addStylesheet('plugins/Q/css/Q.css');
    Q_Response::addStylesheet('css/Overlay.css', '@end');
    Q_Response::addStylesheet('http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,700');
    if (Q_Config::get('Q', 'firebug', false)) {
        Q_Response::addScript("https://getfirebug.com/firebug-lite-debug.js");
    }
    Q_Response::addScript('js/Overlay.js');
    Q_Response::setMeta("title", "Customize My Pic!");
    Q_Response::setMeta("description", "Make a statement on Facebook by customizing your profile picture, even from your smartphone.");
    Q_Response::setMeta("image", Q_Html::themedUrl('img/icon/icon.png'));
    if (Q_Request::isIE()) {
        header("X-UA-Compatible", "IE=edge");
    }
    header('Vary: User-Agent');
    // running an event for loading action-specific extras (if there are any)
    $uri = Q_Dispatcher::uri();
    $module = $uri->module;
    $action = $uri->action;
    $event = "{$module}/{$action}/response/responseExtras";
    if (Q::canHandle($event)) {
        Q::event($event);
    }
}
示例#9
0
function Broadcast_control_response_content($params)
{
    $user = Users::loggedInUser(true);
    $organizations = Broadcast_Agreement::select('a.userId, a.publisherId, u.organization_title, u.organization_domain', 'a')->join(Broadcast_User::table() . ' u', array('a.publisherId' => 'u.userId'))->where(array('a.userId' => $user->id))->fetchAll(PDO::FETCH_ASSOC);
    foreach ($organizations as $k => $org) {
        $messages = Streams_Message::select('content')->where(array('publisherId' => $org['publisherId'], 'streamName' => 'Broadcast/main'))->orderBy('sentTime')->fetchAll(PDO::FETCH_ASSOC);
        $organizations[$k]['messages'] = array();
        foreach ($messages as $msg) {
            $content = json_decode($msg['content'], true);
            if (isset($content['link'])) {
                $ch = curl_init();
                $timeout = 5;
                curl_setopt($ch, CURLOPT_URL, $content['link']);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; cs-CZ; rv:1.7.12) Gecko/20050929");
                $page_contents = curl_exec($ch);
                curl_close($ch);
                preg_match('/<title>([^<]+)<\\/title>/', $page_contents, $matches);
                if (isset($matches[1])) {
                    $content['link_title'] = $matches[1];
                }
            }
            $organizations[$k]['messages'][] = $content;
        }
    }
    Q_Config::set('Q', 'response', 'Broadcast', 'layout_html', 'Broadcast/layout/canvas.php');
    Q_Response::addStylesheet('css/canvas.css');
    Q_Response::addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
    Q_Response::addScript('js/canvas.js');
    return Q::view('Broadcast/content/control.php', compact('organizations'));
}
示例#10
0
/**
 * 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);
        }
    }
}
示例#11
0
function Places_before_Q_responseExtras()
{
    Q_Response::addScript('plugins/Places/js/Places.js');
    Q_Response::addStylesheet("plugins/Places/css/Places.css");
    if ($key = Q_Config::get('Places', 'google', 'keys', 'web', null)) {
        Q_Response::setScriptData("Q.Places.loadGoogleMaps.key", $key);
    }
}
示例#12
0
function MyApp_welcome_response_content($params)
{
    // Do controller stuff here. Prepare variables
    $tabs = array("foo" => "bar");
    $description = "this is a description";
    Q_Response::addScript('js/pages/welcome.js');
    return Q::view('MyApp/content/welcome.php', compact('tabs', 'description'));
}
示例#13
0
function Trump_floor_response_content()
{
    $app = Q_Config::expect('Q', 'app');
    $action = 'about';
    Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
    Q_Response::addScript("plugins/Websites/js/Websites.js");
    return Q::view("Trump/content/floor.php", compact('app', 'action'));
}
示例#14
0
function Shipping_templates_response_content($params)
{
    // Do controller stuff here. Prepare variables
    $env = Shipping::getVars();
    Q_Response::addStylesheet('css/ShipmentTemplates.css');
    Q_Response::addScript('js/date.js', "");
    return Q::view('Shipping/content/templates.php', compact('env'));
}
示例#15
0
/**
 * Makes an infomation block for adding a bookmarklet on the browser's bookmarks bar
 * the way similar to how facebook does: https://www.facebook.com/share_options.php .
 * Main purpose of the tool is to present in cross-browser way how bookmarklet button will look, how bookmarklet will
 * look on browser panel and instructions how to add bookmarklet to that panel.
 * @param {array} $options An associative array of parameters, which can include:
 * @param {array} [$options.scripts] Array of one or more urls of javascript files (will be run through Q_Html::themedUrl) to be executed in order.
 * @param {string} [$options.content] Literal Javascript code to execute. If scripts option is provided, this code is executed after the scripts have been loaded.
 * @param {Object} [$options.skip] Object of {url: path.to.object} pairs to avoid loading script at the url if path.to.object is already defined. Typically names an object which has been defined by the loaded script.
 * @param {string} $options.title Required. Title for the button which will be added to user's browser bar.
 * @param {string} $options.usage Text which is appended to instructions, identifying purpose and usage of this bookmarklet.
 * @param {string} [$options.icon] Icon for the button which will be added to user's browser bar. Can contain placeholders supported by strftime() and also few special placeholders with specific functionality.
 * @return {string}
 */
function Q_bookmarklet_tool($options)
{
    $options = array_merge(array('icon' => null), $options);
    Q_Response::addScript('plugins/Q/js/tools/bookmarklet.js');
    Q_Response::addStylesheet('plugins/Q/css/bookmarklet.css');
    Q_Response::setToolOptions($options);
    return '';
}
示例#16
0
文件: tool.php 项目: dmitriz/Platform
function Streams_basic_tool($options)
{
    $showAccess = false;
    $prompt = 'Fill out your basic information to complete your signup.';
    extract($options);
    Q_Response::addScript('plugins/Streams/js/Streams.js');
    return Q::view('Streams/tool/basic.php', compact('showAccess', 'prompt'));
}
示例#17
0
function Trump_about_response_content()
{
    $publisherId = Users::communityId();
    $streamName = 'Communities/about';
    Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
    Q_Response::addScript("plugins/Websites/js/Websites.js");
    return Q::view("Communities/content/article.php", compact('publisherId', 'streamName'));
}
示例#18
0
文件: tool.php 项目: dmitriz/Platform
/**
 * Renders a search tool which is able to search in streams using query typed by user.
 * @param $options
 *   An associative array of parameters, which can include:
 *   "placeholder" => Optional. Search field placeholder text. Default is "search".
 *   "submit" => Optional. Submit button text (or arbitrary html content). Default is "Submit". If 'false' value is passed, then submit button is not added.
 * @return {string}
 */
function Streams_search_tool($options)
{
    Q_Response::addScript('plugins/Streams/js/Streams.js');
    Q_Response::addStylesheet('plugins/Streams/css/Streams.css');
    $default = array('placeholder' => 'search', 'submit' => 'Submit');
    $options = array_merge($default, $options);
    Q_Response::setToolOptions($options);
    return Q::view('Streams/tool/search.php', $options);
}
示例#19
0
文件: tool.php 项目: dmitriz/Platform
/**
* Renders a comment form and comments feed which is looking like standard Facebook.
* @param $options
*   An associative array of parameters, which can include:
*   "objectId" => Required. A Graph object id which is used to load comments from it and post comments to it.
*   "provider" => Optional. Has to be "facebook" for now.
* @return {string}
*/
function Streams_comments_tool($options)
{
    Q_Response::addScript('plugins/Q/js/phpjs.js');
    Q_Response::addScript('plugins/Streams/js/Streams.js');
    Q_Response::addStylesheet('plugins/Streams/css/Streams.css');
    Q_Response::addStylesheet('plugins/Users/css/Users.css');
    Q_Response::setToolOptions($options);
    return Q::view('Streams/tool/comments.php');
}
示例#20
0
/**
 * This tool contains functionality to show things in columns
 * @class Q columns
 * @constructor
 * @param {array}   [options] Provide options for this tool
 *  @param {array}  [options.animation] For customizing animated transitions
 *  @param {integer}  [options.animation.duration] The duration of the transition in milliseconds, defaults to 500
 *  @param {array}  [options.animation.hide] The css properties in "hide" state of animation
 *  @param {array}  [options.animation.show] The css properties in "show" state of animation
 *  @param {array}  [options.back] For customizing the back button on mobile
 *  @param {string}  [options.back.src] The src of the image to use for the back button
 *  @param {boolean} [options.back.triggerFromTitle] Whether the whole title would be a trigger for the back button. Defaults to true.
 *  @param {boolean} [options.back.hide] Whether to hide the back button. Defaults to false, but you can pass true on android, for example.
 *  @param {array}  [options.close] For customizing the back button on desktop and tablet
 *  @param {string}  [options.close.src] The src of the image to use for the close button
 *  @param {string}  [options.title] You can put a default title for all columns here (which is shown as they are loading)
 *  @param {string}  [options.column] You can put a default content for all columns here (which is shown as they are loading)
 *  @param {array}  [options.clickable] If not null, enables the Q/clickable tool with options from here. Defaults to null.
 *  @param {array}  [options.scrollbarsAutoHide] If not null, enables Q/scrollbarsAutoHide functionality with options from here. Enabled by default.
 *  @param {boolean} [options.fullscreen] Whether to use fullscreen mode on mobile phones, using document to scroll instead of relying on possibly buggy "overflow" CSS implementation. Defaults to true on Android, false everywhere else.
 *  @param {array}   [options.columns] In PHP only, an array of $name => $column pairs, where $column is in the form array('title' => $html, 'content' => $html, 'close' => true)
 * @return {string}
 */
function Q_columns_tool($options)
{
    $jsOptions = array('animation', 'back', 'close', 'title', 'scrollbarsAutoHide', 'fullscreen');
    Q_Response::setToolOptions(Q::take($options, $jsOptions));
    if (!isset($options['columns'])) {
        return '';
    }
    Q_Response::addScript('plugins/Q/js/tools/columns.js');
    Q_Response::addStylesheet('plugins/Q/css/columns.css');
    $result = '<div class="Q_columns_container Q_clearfix">';
    $columns = array();
    $i = 0;
    $closeSrc = Q::ifset($options, 'close', 'src', 'plugins/Q/img/x.png');
    $backSrc = Q::ifset($options, 'back', 'src', 'plugins/Q/img/back-v.png');
    foreach ($options['columns'] as $name => $column) {
        $close = Q::ifset($column, 'close', $i > 0);
        $Q_close = Q_Request::isMobile() ? 'Q_close' : 'Q_close Q_back';
        $closeHtml = !$close ? '' : (Q_Request::isMobile() ? '<div class="Q_close Q_back">' . Q_Html::img($backSrc, 'Back') . '</div>' : '<div class="Q_close">' . Q_Html::img($closeSrc, 'Close') . '</div>');
        $n = Q_Html::text($name);
        $columnClass = 'Q_column_' . Q_Utils::normalize($name) . ' Q_column_' . $i;
        if (isset($column['html'])) {
            $html = $column['html'];
            $columns[] = <<<EOT
\t<div class="Q_columns_column {$columnClass}" data-index="{$i}" data-name="{$n}">
\t\t{$html}
\t</div>
EOT;
        } else {
            $titleHtml = Q::ifset($column, 'title', '[title]');
            $columnHtml = Q::ifset($column, 'column', '[column]');
            $classes = $columnClass . ' ' . Q::ifset($column, 'class', '');
            $attrs = '';
            if (isset($column['data'])) {
                $json = Q::json_encode($column['data']);
                $attrs = 'data-more="' . Q_Html::text($json) . '"';
                foreach ($column['data'] as $k => $v) {
                    $attrs .= 'data-' . Q_Html::text($k) . '="' . Q_Html::text($v) . '" ';
                }
            }
            $data = Q::ifset($column, 'data', '');
            $columns[] = <<<EOT
\t<div class="Q_columns_column {$classes}" data-index="{$i}" data-name="{$n}" {$attrs}>
\t\t<div class="Q_columns_title">
\t\t\t{$closeHtml}
\t\t\t<h2 class="Q_title_slot">{$titleHtml}</h2>
\t\t</div>
\t\t<div class="Q_column_slot">{$columnHtml}</div>
\t</div>
EOT;
        }
        ++$i;
    }
    $result .= "\n" . implode("\n", $columns) . "\n</div>";
    return $result;
}
示例#21
0
function Broadcast_widget_response_widget()
{
    if (!empty($_REQUEST['css'])) {
        Q_Response::addStylesheet($_REQUEST['css']);
    }
    $explanation = Q::ifset($_REQUEST, 'explanation', Q_Config::get('Broadcast', 'text', 'explanation', ''));
    $button = Q::ifset($_REQUEST, 'button', Q_Config::get('Broadcast', 'text', 'button', ''));
    $checkbox = Q::ifset($_REQUEST, 'checkbox', Q_Config::get('Broadcast', 'text', 'checkbox', ''));
    Q_Response::addScript('plugins/Broadcast/js/Broadcast.js');
    return Q::view('Broadcast/widget/widget.php', compact('explanation', 'button', 'checkbox'));
}
示例#22
0
文件: tool.php 项目: dmitriz/Platform
/**
 * Implements an input that filters an associated list (like an autocomplete)
 * @class Q filter
 * @constructor
 * @param {array} [$options] Override various options for this tool
 *  @param {String} [$options.name=filter] The name of the text input
 *  @param {String} [$options.value=''] The initial value of the text input
 *  @param {String} [$options.placeholder] Any placeholder text
 *  @param {array} [$options.placeholders={}] Options for Q/placeholders, or null to omit it
 *  @param {String} [$options.results=''] HTML to display in the results initially. If setting them later, remember to call stateChanged('results')
 *  @param {Q.Event} [$options.onFilter] Name of a JS event handler that is meant to fetch and update results by editing the contents of the element pointed to by the second argument. The first argument is the content of the text input.
 * @return {string}
 */
function Q_filter_tool($options)
{
    Q_Response::setToolOptions($options);
    $name = Q::ifset($options, 'name', 'filter');
    $value = Q::ifset($options, 'value', '');
    $placeholder = Q::ifset($options, 'placeholder', 'filter');
    $class = 'Q_filter_input';
    Q_Response::addScript('plugins/Q/js/tools/filter.js');
    Q_Response::addStylesheet('plugins/Q/css/filter.css');
    return Q_Html::input($name, $value, compact('placeholder', 'class')) . '<div class="Q_filter_results"></div>';
}
示例#23
0
文件: tool.php 项目: dmitriz/Platform
/**
 * userChooser tool
 * @param array $options
 *  "maxResults" => the maximum number of results to show, defaults to 3
 *  "onSuccess" => the name of the function for what to do
 *  "placeholder" => override the default placeholder text,
 *  "exclude" => associative array of userId => true, where userId are the ids of the users
 *    to exclude from the results. Defaults to id of logged-in user, if logged in.
 */
function Streams_userChooser_tool($options)
{
    $maxResults = Q_Config::get('Streams', 'userChooser', 'maxResults', 3);
    $placeholder = "Start typing...";
    extract($options);
    if (!isset($exclude) and $user = Users::loggedInUser()) {
        $exclude = array($user->id => true);
    }
    Q_Response::addScript('plugins/Streams/js/Streams.js');
    Q_Response::setToolOptions(compact('onSuccess', 'maxResults', 'exclude'));
    return Q_Html::input('query', '', array('class' => 'text', 'placeholder' => $placeholder, 'autocomplete' => 'off'));
}
function Places_before_Q_responseExtras()
{
    Q_Response::addScript('plugins/Places/js/Places.js');
    Q_Response::addStylesheet("plugins/Places/css/Places.css");
    if ($key = Q_Config::get('Places', 'google', 'keys', 'web', null)) {
        Q_Response::setScriptData("Q.plugins.Places.loadGoogleMaps.key", $key);
    }
    $miles = Q_Config::expect('Places', 'nearby', 'miles');
    Q_Response::setScriptData("Q.plugins.Places.nearby.miles", $miles);
    $defaultMiles = Q_Config::expect('Places', 'nearby', 'defaultMiles');
    Q_Response::setScriptData("Q.plugins.Places.nearby.defaultMiles", $defaultMiles);
}
示例#25
0
/**
 * Creates an area that behaves like position: fixed in most modern browsers,
 * including ones on touchscreens. Often used for fixed areas that wind up
 * covered by content as it scrolls over the areas.
 * @class Q drawers
 * @constructor
 * @param {array}   [$options] Provide options for this tool
 *  @param {array}   [$options.drawers] Array of strings holding html for drawers
 *  @param {string} [$options.container=null] Optional jQuery selector for handling scrolling
 *  @param {array}   [$options.initial] Information for the initial animation
 *  @param {integer}   [$options.initial.index=1] The index of the drawer to show, either 0 or 1
 *  @param {integer}   [$options.initial.delay=0] Delay before starting initial animation
 *  @param {integer}   [$options.initial.duration=300] The duration of the initial animation
 *  @param {Function} [$options.initial.ease=Q.Animation.linear] The easing function of the initial animation
 *  @param {array}   [$options.transition] Information for the transition animation
 *  @param {integer}   [$options.transition.duration=300] The duration of the transition animation
 *  @param {Function}   [$options.transition.ease=Q.Animation.linear] The easing function of the transition animation
 *  @param {Function}   [$options.width] Override the function that computes the width of the drawers
 *  @param {Function}   [$options.height] Override the function that computes the height drawers tool
 *  @param {array}   [$options.heights=[100,100]] Array of [height0, height1] for drawers that are pinned
 *  @param {array}   [$options.placeholders=['','']] Array of [html0, html1] for drawers that are pinned
 *  @param {array}   [$options.behind=[true,false]] Array of [boolean0, boolean1] to indicate which drawer is behind the others
 *  @param {array}   [$options.bottom=[false,false]] Array of [boolean0, boolean1] to indicate whether to scroll to the bottom of a drawer after switching to it
 *  @param {array}   [$options.triggers=['plugins/Q/img/drawers/up.png', 'plugins/Q/img/drawers/down.png']] Array of [src0, src1] for img elements that act as triggers to swap drawers. Set array elements to false to avoid rendering a trigger.
 *  @param {array}   [$options.trigger]] Options for the trigger elements
 *  @param {integer}   [$options.trigger.rightMargin=10]] How many pixels from the right side of the drawers
 *  @param {integer}   [$options.transition=300]] Number of milliseconds for fading in the trigger images
 *  @param {boolean}   [$options.fullscreen=Q.info.isAndroidStock && Q.info.isAndroid(1000)]] Whether the drawers should take up the whole screen
 *  @param {integer}   [$options.foregroundZIndex=50] The z-index of the drawer in the foreground
 *  @param {integer}   [$options.beforeSwap=new Q.Event()] Occurs right before drawer swap
 *  @param {integer}   [$options.onSwap=new Q.Event()] Occurs right after drawer swap
 */
function Q_drawers_tool($options)
{
    $result = '';
    foreach ($options['drawers'] as $i => $html) {
        $result .= Q_Html::div("drawer_{$i}", "Q_drawers_drawer Q_drawers_drawer_{$i}", $html);
    }
    unset($options['drawers']);
    Q_Response::addScript('plugins/Q/js/tools/drawers.js');
    Q_Response::addStylesheet('plugins/Q/css/drawers.css');
    Q_Response::setToolOptions($options);
    return $result;
}
function Assets_before_Q_responseExtras()
{
    Q_Response::addScript('plugins/Assets/js/Assets.js');
    try {
        $amount = Assets_Credits::amount();
    } catch (Exception $e) {
        $amount = null;
    }
    Q_Response::setScriptData('Q.plugins.Assets.credits', compact('amount'));
    if ($publishableKey = Q_Config::get('Assets', 'payments', 'stripe', 'publishableKey', null)) {
        Q_Response::setScriptData('Q.plugins.Assets.Payments.stripe.publishableKey', $publishableKey);
    }
}
示例#27
0
/**
 * This is the default handler for the Q/responseExtras event.
 * It should not be invoked during AJAX requests, and especially
 * not during JSONP requests. It will output things like the nonce,
 * which prevents CSRF attacks, but is only supposed to be printed
 * on our webpages and not also given to anyone who does a JSONP request.
 */
function Q_before_Q_responseExtras()
{
    $app = Q_Config::expect('Q', 'app');
    $uri = Q_Dispatcher::uri();
    $url = Q_Request::url(true);
    $base_url = Q_Request::baseUrl();
    $ajax = Q_Request::isAjax();
    if (!$uri) {
        return;
    }
    $info = array('url' => $url, 'uriString' => (string) $uri);
    if ($uri) {
        $info['uri'] = $uri->toArray();
    }
    if (!$ajax) {
        $info = array_merge(array('app' => Q_Config::expect('Q', 'app')), $info, array('proxies' => Q_Config::get('Q', 'proxies', array()), 'baseUrl' => $base_url, 'proxyBaseUrl' => Q_Uri::url($base_url), 'proxyUrl' => Q_Uri::url($url), 'sessionName' => Q_Session::name(), 'nodeUrl' => Q_Utils::nodeUrl(), 'slotNames' => Q_Config::get("Q", "response", "slotNames", array('content', 'dashboard', 'title', 'notices'))));
    }
    foreach ($info as $k => $v) {
        Q_Response::setScriptData("Q.info.{$k}", $v);
    }
    if (!$ajax) {
        $uris = Q_Config::get('Q', 'javascript', 'uris', array());
        $urls = array();
        foreach ($uris as $u) {
            $urls["{$u}"] = Q_Uri::url("{$u}");
        }
        Q_Response::setScriptData('Q.urls', $urls);
    }
    // Export more variables to inline js
    $nonce = isset($_SESSION['Q']['nonce']) ? $_SESSION['Q']['nonce'] : null;
    if ($nonce) {
        Q_Response::setScriptData('Q.nonce', $nonce);
    }
    // Attach stylesheets and scripts
    foreach (Q_Config::get('Q', 'javascript', 'responseExtras', array()) as $src => $b) {
        if (!$b) {
            continue;
        }
        Q_Response::addScript($src);
    }
    foreach (Q_Config::get('Q', 'stylesheets', 'responseExtras', array()) as $src => $media) {
        if (!$media) {
            continue;
        }
        if ($media === true) {
            $media = 'screen,print';
        }
        Q_Response::addStylesheet($src, null, $media);
    }
}
示例#28
0
function Awards_after_Q_responseExtras()
{
    Q_Response::addScript('plugins/Awards/js/Awards.js');
    try {
        $amount = Awards_Credits::amount();
    } catch (Exception $e) {
        $amount = null;
    }
    Q_Response::setScriptData('Q.plugins.Awards.credits', compact('amount'));
    $user = Users::loggedInUser();
    if ($user) {
        Q_Response::setScriptData("Q.Users.loggedInUser.displayName", Streams::displayName($user));
    }
}
function Users_before_Q_responseExtras()
{
    Q_Response::addScript('plugins/Users/js/Users.js');
    $app = Q_Config::expect('Q', 'app');
    $requireLogin = Q_Config::get('Users', 'requireLogin', array());
    $rl_array = array();
    foreach ($requireLogin as $rl => $value) {
        $rl_array[Q_Uri::url($rl)] = $value;
    }
    if (!Q_Request::isAjax()) {
        Q_Response::setScriptData('Q.plugins.Users.requireLogin', $rl_array);
        $successUrl = Q_Config::get('Users', 'uris', "{$app}/successUrl", "{$app}/home");
        $afterActivate = Q_Config::get('Users', 'uris', "{$app}/afterActivate", $successUrl);
        $loginOptions = Q_Config::get('Users', 'login', array("identifierType" => 'email,mobile', "userQueryUri" => 'Users/user', "using" => "native,facebook", "noRegister" => false));
        $loginOptions["afterActivate"] = Q_Uri::url($afterActivate);
        $loginOptions["successUrl"] = Q_Uri::url($successUrl);
        Q_Response::setScriptData('Q.plugins.Users.login.serverOptions', $loginOptions);
        $setIdentifierOptions = Q::take($loginOptions, array('identifierType'));
        Q_Response::setScriptData('Q.plugins.Users.setIdentifier.serverOptions', $setIdentifierOptions);
    }
    $fb_app_info = Q_Config::get('Users', 'facebookApps', $app, array());
    if ($fb_app_info) {
        unset($fb_app_info['secret']);
        Q_Response::setScriptData("Q.plugins.Users.facebookApps.{$app}", $fb_app_info);
    }
    if ($node_server_url = Q_Config::get('Users', 'nodeServer', 'url', null)) {
        Q_Response::setScriptData("Q.plugins.Users.nodeServer", parse_url($node_server_url));
    }
    if (Q_Config::get('Users', 'showLoggedInUser', true)) {
        $user = Q_Session::id() ? Users::loggedInUser() : null;
        if ($user) {
            $u = $user->exportArray();
            $u['sessionCount'] = $user->sessionCount;
            Q_Response::setScriptData("Q.plugins.Users.loggedInUser", $u);
            Q_Response::addScriptLine("Q.plugins.Users.loggedInUser = new Q.plugins.Users.User(Q.plugins.Users.loggedInUser);");
        }
    }
    Q_Response::setScriptData('Q.plugins.Users.communityId', Users::communityId());
    Q_Response::setScriptData('Q.plugins.Users.communityName', Users::communityName());
    Q_Response::setScriptData('Q.plugins.Users.communitySuffix', Users::communitySuffix());
    Q_Response::setScriptData('Q.plugins.Users.hinted', Q::ifset($_SESSION, 'Users', 'hinted', array()));
    if ($sizes = Q_Config::expect('Users', 'icon', 'sizes')) {
        sort($sizes);
        Q_Response::setScriptData('Q.plugins.Users.icon.sizes', $sizes);
    }
    $defaultSize = Q_Config::get('Users', 'icon', 'defaultSize', 40);
    Q_Response::setScriptData('Q.plugins.Users.icon.defaultSize', $defaultSize);
    Q_Response::addStylesheet("plugins/Users/css/Users.css");
}
示例#30
0
function Broadcast_main_response_content()
{
    Q_Response::addScript('plugins/Broadcast/js/Broadcast.js');
    $user = Users::loggedInUser(true);
    $stream = new Streams_Stream();
    $stream->publisherId = $user->id;
    $stream->name = 'Broadcast/main';
    if (!$stream->retrieve()) {
        $stream->type = 'Broadcast';
        $stream->title = "Main broadcast stream";
        $stream->content = "Whatever you post to this stream will be syndicated by everyone who has opted in.";
        $stream->save();
    }
    Q_Response::redirect('Broadcast/stream publisherId=' . $stream->publisherId . ' name=Broadcast/main');
}