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 Users_activate_response_content() { $email = $mobile = $type = $user = $emailAddress = $mobileNumber = null; extract(Users::$cache, EXTR_IF_EXISTS); $complete = false; if ($user and !empty($user->passphraseHash)) { if ($emailAddress and $user->emailAddress == $emailAddress) { $complete = true; } else { if ($mobileNumber and $user->mobileNumber = $mobileNumber) { $complete = true; } } } if (!empty(Users::$cache['success'])) { $app = Q_Config::expect('Q', 'app'); $successUrl = Q_Config::get('Users', 'uris', "{$app}/successUrl", "{$app}/home"); if (Q_Request::method() === 'POST') { if ($qs = $_SERVER['QUERY_STRING']) { $qs = "&{$qs}"; } Q_Response::redirect(Q_Config::get('Users', 'uris', "{$app}/afterActivate", $successUrl) . '?Q.fromSuccess=Users/activate' . $qs); return true; } } $view = Q_Config::get('Users', 'activateView', 'Users/content/activate.php'); $t = $email ? 'e' : 'm'; $identifier = $email ? $emailAddress : $mobileNumber; // Generate 10 passphrase suggestions $suggestions = array(); $arr = (include USERS_PLUGIN_FILES_DIR . DS . 'Users' . DS . 'passphrases.php'); for ($i = 0; $i < 10; ++$i) { $pre1 = $arr['pre'][mt_rand(0, count($arr['pre']) - 1)]; $noun1 = $arr['nouns'][mt_rand(0, count($arr['nouns']) - 1)]; $verb = $arr['verbs'][mt_rand(0, count($arr['verbs']) - 1)]; $pre2 = $arr['pre'][mt_rand(0, count($arr['pre']) - 1)]; $adj = $arr['adjectives'][mt_rand(0, count($arr['adjectives']) - 1)]; $noun2 = $arr['nouns'][mt_rand(0, count($arr['nouns']) - 1)]; //$suggestions[] = strtolower("$pre1 $noun1 $verb $pre2 $adj $noun2"); $suggestions[] = strtolower("{$pre1} {$noun1} {$verb} {$pre2} {$noun2}"); } $verb_ue = urlencode($arr['verbs'][mt_rand() % count($arr['verbs'])]); $noun_ue = urlencode($arr['nouns'][mt_rand() % count($arr['nouns'])]); $code = Q::ifset($_REQUEST['code']); Q_Response::addScriptLine("Q.onReady.set(function () {\n\t\tif (Q.Notice) {\n\t\t\tQ.Notice.hide('Users/email');\n\t\t\tQ.Notice.hide('Users/mobile');\n\t\t}\n\t});"); // shh! not while I'm activating! lol return Q::view($view, compact('identifier', 'type', 'user', 'code', 'suggestions', 'verb_ue', 'noun_ue', 't', 'app', 'home', 'complete')); }
function Platform_iframe_response() { if (empty($_POST['html'])) { echo "POST field 'html' is empty"; return false; } if ($stylesheet = Q::ifset($_POST, 'stylesheet', null)) { Q_Response::addStylesheet($stylesheet, '@end'); } $html = $_POST['html']; // use a regular layout, add all the scripts for Users and Streams and whatever // and then call Q.activate() // either that, or change html to a template that is rendered with handlebars in PHP Q_Response::addScriptLine('Q.init();', '@end'); $stylesheets = Q_Response::stylesheets(true, "\n\t"); $scripts = Q_Response::scripts(true, "\n\t"); $templates = Q_Response::templates(true, "\n\t"); $scriptLines = Q_Response::scriptLines(true); echo <<<EOT <!doctype html> <html> <head> <title>Qbix Platform</title> \t\t{$stylesheets} \t\t{$scripts} \t\t<style> \t\thtml { height: 100%; } \t\tbody { height: 100%; } \t\t</style> </head> <body> \t\t<div id="Platform_parsed_html"> \t\t\t{$html} \t\t</div> \t\t{$scriptLines} </body> </html> EOT; return false; }
Q_Response::addScriptLine(<<<EOT \tQ.page('Users/authorize', function () { \t\t\$('#Users_login').click(function () { \t\t\tQ.plugins.Users.login({ \t\t\t\tonSuccess: { 'Users.login': function (user, options, result, used) { \t\t\t\t\tQ.loadUrl(window.location.href, { \t\t\t\t\t\tonActivate: function () { \t\t\t\t\t\t\tif (typeof result === 'string' \t\t\t\t\t\t\t&& Q.Users.authorize.noTerms) { \t\t\t\t\t\t\t\t// We can auto-authorize in this case. \t\t\t\t\t\t\t\t\$('#Users_authorize').click(); \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t}); \t\t\t\t}} \t\t\t}); \t\t\treturn false; \t\t}); \t\t \t\t\$('#Users_authorize').click(function () { \t\t\tvar fields = { \t\t\t\tauthorize: 1 \t\t\t}; \t\t\tif (\$('#Users_agree').length) { \t\t\t\tif (!\$("#Users_agree").attr('checked')) { \t\t\t\t\talert(Q.text.Users.authorize.mustAgree); \t\t\t\t\treturn false; \t\t\t\t} \t\t\t\tfields.agree = 'yes'; \t\t\t} \t\t\tQ.each([ \t\t\t\t'client_id', 'redirect_uri', 'scope', \t\t\t\t'state', 'response_type' \t\t\t], function (i, field) { \t\t\t\tfields[field] = location.search.queryField(field); \t\t\t}); \t\t\tQ.req(Q.info.url, 'url', function (err, response) { \t\t\t\tsetTimeout(function () { \t\t\t\t\tlocation = Q.info.baseUrl; \t\t\t\t}, 1000); \t\t\t}, { \t\t\t\tmethod: 'post', \t\t\t\tfields: fields \t\t\t}); \t\t\treturn false; \t\t}); \t\t \t\treturn function () { \t\t\t\$('#Users_authorize').unbind('click'); \t\t\t\$('#Users_login').unbind('click'); \t\t}; \t}, 'Users/authorize'); EOT );
if ($show_chat) { ?> <div class='social_pane'> <?php echo Q::tool('Streams/participant', compact('stream')); ?> <?php echo Q::tool('Streams/player', compact('stream')); ?> <?php echo Q::tool('Streams/activity', compact('stream')); ?> </div> <?php } ?> </tr> </table> </div> <?php Q_Response::addScriptLine(' $(function() { $("#Q_form_username").focus(); }) Q.addScript( [ "plugins/Q/js/jquery-1.11.1.min.js", "plugins/Q/js/jquery.tools.min.js"], function () { $("*[title]").tooltip(); } ); ');
?> <li class="Users_fromServer"><?php echo Q_Html::text($s); ?> </li> <?php } ?> </ul> </div> <?php } } elseif (Users::loggedInUser()) { ?> <h1 class='Q_big_message'>If you feel something went wrong, <button id='activate_setIdentifier'>try again</button></h1> <?php } else { ?> <h1 class='Q_big_message'>Please try <a href='#' id='activate_login'>logging in</a> to activate your account.</h1> <?php } ?> <?php Q_Response::addScript('plugins/Q/js/Q.js'); ?> <?php Q_Response::addScriptLine("jQuery(function() {\n\t\$('#activate_setIdentifier').click(function() { Q.plugins.Users.setIdentifier(); });\n\t\$('#activate_login').click(function() { Q.plugins.Users.login(); });\n\t\$('#activate_passphrase').val('').focus();\n\t\n\t// Get the suggestions from YAHOO, if possible\n\t\n\t\$('#activate_passphrase').plugin('Q/placeholders').plugin('Q/clickfocus');\n\t\n\t// this used to work:\n\t// var url = 'http://query.yahooapis.com/v1/public/yql?format=json&diagnostics=false&q=select%20abstract%20from%20search.news%20where%20query%3D%22{$verb_ue}%22';\n\t// but YAHOO now deprecated the search.news table.\n\t// later we can pay for BOSS to do this. But for now, here is what we do:\n\tvar url = 'https://query.yahooapis.com/v1/public/yql?format=json&diagnostics=false&q=SELECT+Rating.LastReviewIntro+from+local.search+WHERE+zip+%3D+%2210001%22+AND+%28query%3D%22{$verb_ue}%22+OR+query%3D%22{$noun_ue}%22%29+AND+Rating.LastReviewIntro+MATCHES+%22%5E.%2B%22+LIMIT+10';\n\t\n\tQ.request(url, null, function(err, data) {\n\t\tif (data.query && data.query.results && data.query.results.Result) {\n\t\t\t// var r = data.query.results.result;\n\t\t\tvar r = data.query.results.Result;\n\t\t\tvar ul = \$('#suggestions');\n\t\t\tvar rand, text;\n\t\t\tvar source = '';\n\t\t\tfor (var i=0; i<r.length; ++i) {\n\t\t\t\ttext = r[i].Rating.LastReviewIntro;\n\t\t\t\tif (text) {\n\t\t\t\t\tsource += ' ' + text;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvar source_words = source.toLowerCase().replace(/[^A-Za-z0-9-_\\' ]/g, '').split(' ');\n\t\t\tfor (var i=0; i<7; ++i) { // add seven quotes from here\n\t\t\t\trand = Math.floor(Math.random() * source_words.length);\n\t\t\t\tvar text = source_words.slice(rand, rand+3).join(' ');\n\t\t\t\tif (text) {\n\t\t\t\t\tul.prepend(\$('<li />').addClass('Users_fromYahoo').html(text));\n\t\t\t\t\t\$('li:last', ul).eq(0).remove();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}, {'callbackName': 'callback'});\n}); "); ?> </div>
/** * Default Q/response handler. * 1. Gets some slots, depending on what was requested. * 2. Renders them in a layout * The layout expects "title", "dashboard" and "contents" slots to be filled. */ function Q_response($params) { extract($params); /** * @var Exception $exception * @var array $errors */ if (empty($errors)) { $errors = Q_Response::getErrors(); } if (!empty($_GET['Q_ct'])) { Q_Response::setCookie('Q_ct', $_GET['Q_ct']); } // If output is set, use that $output = Q_Response::output(); if (isset($output)) { if ($output === true) { return; } if (is_string($output)) { echo $output; } return; } // Redirect to success page, if requested. $isAjax = Q_Request::isAjax(); if (empty($errors) and empty($exception)) { if (!$isAjax and null !== Q_Request::special('onSuccess', null)) { $onSuccess = Q_Request::special('onSuccess', null); if (Q_Config::get('Q', 'response', 'onSuccessShowFrom', true)) { $onSuccess = Q_Uri::url($onSuccess . '?Q.fromSuccess=' . Q_Dispatcher::uri()); } Q_Response::redirect($onSuccess); return; } } // Get the requested module $uri = Q_Dispatcher::uri(); if (!isset($module)) { $module = $uri->module; if (!isset($module)) { $module = 'Q'; Q_Dispatcher::uri()->module = 'Q'; } } if (!$isAjax || Q_Request::isLoadExtras()) { Q::event('Q/responseExtras', array(), 'before'); } // Get the main module (the app) $app = Q_Config::expect('Q', 'app'); $action = $uri->action; if (Q::canHandle("{$module}/{$action}/response")) { if (false === Q::event("{$module}/{$action}/response") and !$isAjax) { return; } } $slotNames = Q_Request::slotNames(true); $idPrefixes = array(); if ($temp = Q_Request::special('idPrefixes', null)) { foreach (explode(',', $temp) as $i => $prefix) { if (!isset($slotNames[$i])) { throw new Q_Exception("More id prefixes than slot names", "Q.idPrefixes"); } $idPrefixes[$slotNames[$i]] = $prefix; } } // What to do if this is an AJAX request if ($isAjax) { $to_encode = array(); if (Q_Response::$redirected) { // We already called Q_Response::redirect $to_encode['redirect']['url'] = Q_Uri::url(Q_Response::$redirected); try { $to_encode['redirect']['uri'] = Q_Uri::from(Q_Response::$redirected)->toArray(); } catch (Exception $e) { // couldn't get internal URI } } else { if (is_array($slotNames)) { foreach ($slotNames as $slotName) { Q_Response::fillSlot($slotName, 'default', Q::ifset($idPrefixes, $slotName, null)); } // Go through the slots again, because other handlers may have overwritten // their contents using Q_Response::setSlot() foreach ($slotNames as $sn) { Q_Response::fillSlot($sn, 'default', Q::ifset($idPrefixes, $slotName, null)); } if (Q_Response::$redirected) { // While rendering the slots we called Q_Redirect $to_encode['redirect']['url'] = Q_Uri::url(Q_Response::$redirected); try { $to_encode['redirect']['uri'] = Q_Uri::from(Q_Response::$redirected)->toArray(); } catch (Exception $e) { // couldn't get internal URI } } else { if (Q_Request::isLoadExtras()) { $to_encode['slots'] = Q_Response::slots(true); // add stylesheets, stylesinline, scripts, scriptlines, scriptdata, templates foreach (array_merge(array(''), $slotNames) as $slotName) { $temp = Q_Response::stylesheetsArray($slotName); if ($temp) { $to_encode['stylesheets'][$slotName] = $temp; } $temp = Q_Response::stylesInline($slotName); if ($temp) { $to_encode['stylesInline'][$slotName] = $temp; } $temp = Q_Response::scriptsArray($slotName); if ($temp) { $to_encode['scripts'][$slotName] = $temp; } $temp = Q_Response::scriptLines($slotName, true, "\n", false); if ($temp) { $to_encode['scriptLines'][$slotName] = $temp; } $temp = Q_Response::scriptData($slotName); if ($temp) { $to_encode['scriptData'][$slotName] = $temp; } $temp = Q_Response::templateData($slotName); if ($temp) { $to_encode['templates'][$slotName] = $temp; } } } else { $to_encode['slots'] = Q_Response::slots(true); // add stylesinline, scriptlines, scriptdata, templates foreach (array_merge(array(''), $slotNames) as $slotName) { $temp = Q_Response::stylesInline($slotName); if ($temp) { $to_encode['stylesInline'][$slotName] = $temp; } $temp = Q_Response::scriptData($slotName); if ($temp) { $to_encode['scriptData'][$slotName] = $temp; } $temp = Q_Response::scriptLines($slotName, true, "\n", false); if ($temp) { $to_encode['scriptLines'][$slotName] = $temp; } } } } } } $to_encode['timestamp'] = microtime(true); $echo = Q_Request::contentToEcho(); if (isset($echo)) { $to_encode['echo'] = $echo; } $json = Q::json_encode(Q::cutoff($to_encode)); $callback = Q_Request::callback(); switch (strtolower($isAjax)) { case 'iframe': if (!Q_Response::$batch) { header("Content-type: text/html"); } echo <<<EOT <!doctype html><html lang=en> <head><meta charset=utf-8><title>Q Result</title></head> <body> <script type="text/javascript"> window.result = function () { return {$json} }; </script> </body> </html> EOT; break; case 'json': default: if (!Q_Response::$batch) { header("Content-type: " . ($callback ? "application/javascript" : "application/json")); } echo $callback ? "{$callback}({$json})" : $json; } return; } // If this is a request for a regular webpage, // fill the usual slots and render a layout. if (Q_Response::$redirected) { return; // If already set a redirect header, simply return -- no reason to output all this HTML } static $added_Q_init = false; if (!$added_Q_init) { Q_Response::addScriptLine("\n// Now, initialize Q\nQ.init();\n", null, 'Q'); $added_Q_init = true; } // Get all the usual slots for a webpage $slots = array(); foreach ($slotNames as $sn) { Q_Response::fillSlot($sn, 'default', Q::ifset($idPrefixes, $sn, null)); } // Go through the slots again, because other handlers may have overwritten // their contents using Q_Response::setSlot() foreach ($slotNames as $sn) { Q_Response::fillSlot($sn, 'default', Q::ifset($idPrefixes, $sn, null)); } $output = Q_Response::output(); if (isset($output)) { if ($output === true) { return; } if (is_string($output)) { echo $output; } return; } if (!$isAjax or Q_Request::isLoadExtras()) { Q::event('Q/responseExtras', array(), 'after'); } $slots = Q_Response::slots(false); // Render a full HTML layout $layout_view = Q_Response::layoutView(); echo Q::view($layout_view, $slots); }
Q_Response::addScriptLine(<<<EOT \tQ.page('Users/authorize', function () { \t\t\$('.Q_button').plugin('Q/clickable'); \t\t\$('#Users_login').on(Q.Pointer.click, _login); \t\t\$('#Users_authorize').on(Q.Pointer.click, _authorize); \t\tif (!Q.Users.loggedInUser) { \t\t\t_login(); \t\t} else if (Q.Users.authorize.skip === 'authorize') { \t\t\t_authorize(); \t\t} \t\t \t\treturn function () { \t\t\t\$('#Users_authorize').off(Q.Pointer.click); \t\t\t\$('#Users_login').off(Q.Pointer.click); \t\t}; \t\t \t\tfunction _login() { \t\t\tQ.plugins.Users.login({ \t\t\t\tnoClose: true, \t\t\t\tonSuccess: { 'Users.login': function (user, options, result, used) { \t\t\t\t\tQ.handle(window.location.href); \t\t\t\t}} \t\t\t}); \t\t} \t\t \t\tfunction _authorize() { \t\t\tvar fields = { \t\t\t\tauthorize: 1 \t\t\t}; \t\t\tif (\$('#Users_agree').length) { \t\t\t\tif (!\$("#Users_agree").attr('checked')) { \t\t\t\t\talert(Q.text.Users.authorize.mustAgree); \t\t\t\t\treturn false; \t\t\t\t} \t\t\t\tfields.agree = 'yes'; \t\t\t} \t\t\t\$('#Users_authorize').addClass('Q_working'); \t\t\tQ.each([ \t\t\t\t'client_id', 'redirect_uri', \t\t\t\t'state', 'response_type' \t\t\t], function (i, field) { \t\t\t\tfields[field] = Q.Users.authorize[field]; \t\t\t}); \t\t\tfields.scope = Q.Users.authorize.scope.join(' '); \t\t\tQ.req(Q.info.url, 'url', function (err, response) { \t\t\t}, { \t\t\t\tmethod: 'post', \t\t\t\tfields: fields \t\t\t}); \t\t\treturn false; \t\t} \t}, 'Users/authorize'); EOT );