function Users_after_Q_responseExtras() { if ($preloaded = Users_User::$preloaded) { Q_Response::setScriptData('Q.plugins.Users.User.preloaded', Db::exportArray($preloaded, array('asAvatar' => true))); } Q_Response::setScriptData('Q.plugins.Users.roles', Users::roles()); }
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"); }
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'); } } }
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')); }
function Streams_after_Q_responseExtras() { if ($preloaded = Streams_Stream::$preloaded) { $preloaded = Db::exportArray($preloaded); Q_Response::setScriptData('Q.plugins.Streams.Stream.preloaded', $preloaded); } }
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); } }
function Users_after_Q_responseExtras() { if ($preloaded = Users_User::$preloaded) { Q_Response::setScriptData('Q.plugins.Users.User.preloaded', Db::exportArray($preloaded, array('asAvatar' => true))); } Q_Response::setScriptData('Q.plugins.Users.roles', Users::roles()); $user = Users::loggedInUser(); Q_Response::addHtmlCssClass($user ? 'Users_loggedIn' : 'Users_loggedOut'); }
/** * 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; }
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); }
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); } }
/** * 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); } }
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"); }
function Websites_before_Q_responseExtras() { $user = Users::loggedInUser(false, false); $userId = $user ? $user->id : ""; $websitesUserId = Users::communityId(); $sha1 = sha1(Q_Dispatcher::uri()); $seoStreamName = "Websites/seo/{$sha1}"; $stream = Streams::fetchOne($userId, $websitesUserId, $seoStreamName); if ($stream) { $fields = Q::take($stream->getAllAttributes(), array('keywords', 'description')); foreach ($fields as $k => $v) { Q_Response::setMeta($k, $v); } Q_Response::setSlot('title', $stream->getAttribute('title')); } Q_Response::setScriptData('Q.plugins.Websites.seoStreamName', $seoStreamName); Q_Response::setScriptData('Q.plugins.Websites.userId', Users::communityId()); Q_Response::setScriptData('Q.plugins.Websites.seoReload', Q_Config::expect('Websites', 'seoReload')); }
function Overlay_home_response_content($params) { $countries = array(); $files = glob(APP_WEB_DIR . DS . 'img' . DS . 'squareflags' . DS . '*'); foreach ($files as $file) { $basename = basename($file); $src = Q_Request::baseUrl() . "/img/squareflags/{$basename}"; $src = str_replace(' ', '%20', $src); if (empty($firstCountrySrc)) { $firstCountrySrc = $src; } $parts = explode('.', $basename); $parts2 = explode('_', $parts[0]); foreach ($parts2 as &$v) { $v = strtoupper($v[0]) . substr($v, 1); } $countries[$src] = implode(' ', $parts2); } $counter = Overlay::counter(); $proxyHost = 'http://' . $_SERVER['HTTP_HOST'] . ':' . Q_Config::get('Q', 'node', 'port', '80'); Q_Response::setScriptData('Overlay.proxyHost', $proxyHost); return Q::view('Overlay/content/home.php', compact('countries', 'firstCountrySrc', 'counter')); }
function Websites_before_Q_responseExtras() { $user = Users::loggedInUser(false, false); $userId = $user ? $user->id : ""; $websitesUserId = Q_Config::expect("Websites", "user", "id"); $sha1 = sha1(Q_Dispatcher::uri()); $seoStreamName = "Websites/seo/{$sha1}"; $streams = Streams::fetch($userId, $websitesUserId, array("Websites/header", "Websites/title", "Websites/slogan", $seoStreamName)); if (!empty($streams[$seoStreamName])) { $fields = Q::take($streams[$seoStreamName]->getAllAttributes(), array('keywords', 'description')); foreach ($fields as $k => $v) { Q_Response::setMeta($k, $v); } Q_Response::setSlot('title', $streams[$seoStreamName]->getAttribute('title')); } foreach ($streams as $name => $s) { if ($s) { $s->addPreloaded($userId); } } Q_Response::setScriptData('Q.plugins.Websites.seoStreamName', $seoStreamName); Q_Response::setScriptData('Q.plugins.Websites.userId', Q_Config::expect('Websites', 'user', 'id')); Q_Response::setScriptData('Q.plugins.Websites.seoReload', Q_Config::expect('Websites', 'seoReload')); }
<form action="" method="post"> <?php if ($terms_label) { ?> <div id="Users_authorize_terms"> <input type="checkbox" name="agree" id="Users_agree" value="yes"> <label for="Users_agree"><?php echo $terms_label; ?> </label> </div> <?php } else { ?> <?php echo Q_Response::setScriptData("Q.Users.authorize.noTerms", true); ?> <?php } ?> <div id="Users_authorize_buttons"> <a class="Q_button" name="authorize" id="Users_authorize">Authorize</a> </div> </form> <?php } else { ?> <form action=""> <div id="Users_authorize_buttons"> <a class="Q_button" id="Users_login">Get Started</a> </div>