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 Websites_seo_post() { if (empty($_REQUEST['streamName'])) { throw new Q_Exception_RequiredField(array('field' => 'streamName')); } $prefix = "Websites/seo/"; if (substr($_REQUEST['streamName'], 0, strlen($prefix)) !== $prefix) { throw new Q_Exception_WrongValue(array('field' => 'streamName', 'range' => "string beginning with {$prefix}")); } $user = Users::loggedInUser(true); $publisherId = Q_Config::expect("Websites", "user", "id"); $type = "Websites/seo"; if (!Streams::isAuthorizedToCreate($user->id, $publisherId, $type)) { throw new Users_Exception_NotAuthorized(); } $stream = new Streams_Stream($publisherId); $stream->publisherId = $publisherId; $stream->name = $_REQUEST['streamName']; $stream->type = $type; if (isset($_REQUEST['uri'])) { $stream->setAttribute('uri', $_REQUEST['uri']); } $stream->save(); $stream->post($user->id, array('type' => 'Streams/created', 'content' => '', 'instructions' => Q::json_encode($stream->toArray())), true); $stream->subscribe(); // autosubscribe to streams you yourself create, using templates Q_Response::setSlot('stream', $stream->exportArray()); }
function Users_0_9_2_Users_mysql() { $app = Q_Config::expect('Q', 'app'); $communityId = Users::communityId(); $rows = Users_Session::select('COUNT(1)')->where($criteria)->fetchAll(PDO::FETCH_NUM); $count = $rows[0][0]; $limit = 100; $offset = 0; $sessions = Users_Session::select('*')->orderBy('id')->limit($limit, $offset)->caching(false)->fetchDbRows(); echo "Adding userId to sessions..."; while ($sessions) { foreach ($sessions as $s) { $parsed = Q::json_decode($s->content, true); if (empty($parsed['Users']['loggedInUser']['id'])) { continue; } $s->userId = $parsed['Users']['loggedInUser']['id']; } Users_Session::insertManyAndExecute($sessions, array('onDuplicateKeyUpdate' => array('userId' => new Db_Expression("VALUES(userId)")))); $min = min($offset + $limit, $count); echo "[100D"; echo "Updated {$min} of {$count} sessions"; $offset += $limit; if ($offset > $count) { break; } $sessions = Users_Session::select('*')->orderBy('id')->limit($limit, $offset)->caching(false)->fetchDbRows(); } echo "\n"; }
function Streams_0_8_8_Streams_mysql() { $app = Q_Config::expect('Q', 'app'); $user = Users_User::fetch($app, true); Streams::create($app, $app, 'Streams/resource', array('name' => 'Streams/invitations', 'readLevel' => 0, 'writeLevel' => 0, 'adminLevel' => 0)); Streams_Access::insert(array('publisherId' => $app, 'streamName' => "Streams/invitations", 'ofUserId' => '', 'grantedByUserId' => null, 'ofContactLabel' => "{$app}/admins", 'readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['close'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']))->execute(); }
/** * Call this function to find the "nearby points" to subscribe to * on a grid of quantized (latitude, longitude) pairs * which are spaced at most $miles apart. * @param {double} $latitude The latitude of the coordinates to search around * @param {double} $longitude The longitude of the coordinates to search around * @param {double} $miles The radius, in miles, around this location. * Should be one of the array values in the Places/nearby/miles config. * @return {Array} Returns an array of up to four ($streamName => $info) pairs * where the $streamName is the name of the stream corresponding to the "nearby point" * and $info includes the keys "latitude", "longitude", and "miles". */ static function forSubscribers($latitude, $longitude, $miles) { list($latQuantized, $longQuantized, $latGrid, $a) = Places::quantize($latitude, $longitude, $miles); $milesArray = Q_Config::expect('Places', 'nearby', 'miles'); if (!in_array($miles, $milesArray)) { throw new Q_Exception("The miles value needs to be in Places/nearby/miles config."); } $result = array(); foreach (array($latQuantized, $latQuantized + $latGrid * 1.1) as $lat) { list($a, $b, $c, $longGrid) = Places::quantize($lat, $longitude, $miles); foreach (array($longQuantized, $longQuantized + $longGrid * 1.1) as $long) { list($latQ, $longQ) = Places::quantize($lat, $long, $miles); if ($longQ > 180) { $longQ = $long % 180 - 180; } if ($longQ < -180) { $longQ = $long % 180 + 180; } if ($latQ > 90) { $latQ = $latQ % 90 - 90; } if ($latQ < -90) { $latQ = $latQ % 90 + 90; } $streamName = self::streamName($latQ, $longQ, $miles); $result[$streamName] = array('latitude' => $lat, 'longitude' => $long, 'geohash' => Places_Geohash::encode($latQ, $longQ, 6), 'miles' => $miles); } } return $result; }
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); } }
function Streams_interests_response() { // serve a javascript file and tell client to cache it $app = Q_Config::expect('Q', 'app'); $communityId = Q::ifset($_REQUEST, 'communityId', $app); $tree = new Q_Tree(); $tree->load("files/Streams/interests/{$communityId}.json"); $categories = $tree->getAll(); foreach ($categories as $category => &$v1) { foreach ($v1 as $k2 => &$v2) { if (!Q::isAssociative($v2)) { ksort($v1); break; } ksort($v2); } } header('Content-Type: text/javascript'); header("Pragma: ", true); // 1 day header("Cache-Control: public, max-age=86400"); // 1 day $expires = date("D, d M Y H:i:s T", time() + 86400); header("Expires: {$expires}"); // 1 day $json = Q::json_encode($categories, true); echo "Q.setObject(['Q', 'Streams', 'Interests', 'all', '{$communityId}'], {$json});"; return false; }
function Streams_0_8_1_Streams_mysql() { $app = Q_Config::expect('Q', 'app'); // template for community stream $stream = new Streams_Stream(); $stream->publisherId = ''; $stream->name = 'Streams/community/'; $stream->type = 'Streams/template'; $stream->title = "Community"; $stream->content = ''; $readLevel = Streams::$READ_LEVEL['content']; $writeLevel = Streams::$WRITE_LEVEL['join']; $adminLevel = Streams::$ADMIN_LEVEL['invite']; $stream->save(); // app community stream, for announcements $stream = new Streams_Stream(); $stream->publisherId = $app; $stream->name = 'Streams/community/main'; $stream->type = 'Streams/community'; $stream->title = "{$app} Community"; $stream->save(); // symlink the labels folder $cwd = getcwd(); chdir(USERS_PLUGIN_FILES_DIR . DS . 'Users' . DS . 'icons'); if (!file_exists('Streams')) { symlink(STREAMS_PLUGIN_FILES_DIR . DS . 'Streams' . DS . 'icons' . DS . 'labels' . DS . 'Streams', 'Streams'); } chdir($cwd); }
/** * Displays an HTML document that can be printed, ideally with line breaks. * Uses a particular view for the layout. * @param {array} $_REQUEST * @param {string} $_REQUEST.invitingUserId Required. The id of the user that generated the invitations with a call to Streams::invite. * @param {string} $_REQUEST.batch Required. The name of the batch under which invitations were saved during a call to Streams::invite. * @param {string} [$_REQUEST.limit=100] The maximum number of invitations to show on the page * @param {string} [$_REQUEST.offset=0] Used for paging * @param {string} [$_REQUEST.title='Invitations'] Override the title of the document * @param {string} [$_REQUEST.layout='default'] The name of the layout to use for the HTML document * @see Users::addLink() */ function Streams_invitations_response() { Q_Request::requireFields(array('batch', 'invitingUserId'), true); $invitingUserId = $_REQUEST['invitingUserId']; $batch = $_REQUEST['batch']; $user = Users::loggedInUser(true); $stream = Streams::fetchOne(null, $invitingUserId, 'Streams/invitations', true); if (!$stream->testReadLevel('content')) { throw new Users_Exception_NotAuthorized(); } $title = Q::ifset($_REQUEST, 'layout', 'title'); $layoutKey = Q::ifset($_REQUEST, 'layout', 'default'); $limit = min(1000, Q::ifset($_REQUEST, 'limit', 100)); $offset = Q::ifset($_REQUEST, 'offset', 0); $layout = Q_Config::expect('Streams', 'invites', 'layout', $layoutKey); $pattern = Streams::invitationsPath($invitingUserId) . DS . $batch . DS . "*.html"; $filenames = glob($pattern); $parts = array(); foreach ($filenames as $f) { if (--$offset > 0) { continue; } $parts[] = file_get_contents($f); if (--$limit == 0) { break; } } $content = implode("\n\n<div class='Q_pagebreak Streams_invitations_separator'></div>\n\n", $parts); echo Q::view($layout, compact('title', 'content', 'parts')); return false; }
function Streams_0_8_6_Streams_mysql() { $app = Q_Config::expect('Q', 'app'); // access for managing communities $access = new Streams_Access(); $access->publisherId = $app; $access->streamName = 'Streams/community*'; $access->ofUserId = ''; $access->ofContactLabel = "{$app}/admins"; $access->readLevel = Streams::$READ_LEVEL['messages']; $access->writeLevel = Streams::$WRITE_LEVEL['edit']; $access->adminLevel = Streams::$ADMIN_LEVEL['manage']; $access->save(); // access for managing categories $access = new Streams_Access(); $access->publisherId = $app; $access->streamName = 'Streams/category/'; $access->ofUserId = ''; $access->ofContactLabel = "{$app}/admins"; $access->readLevel = Streams::$READ_LEVEL['messages']; $access->writeLevel = Streams::$WRITE_LEVEL['close']; $access->adminLevel = Streams::$ADMIN_LEVEL['manage']; $access->save(); // template to help users relate things to Streams/category streams Streams_Stream::insert(array('publisherId' => '', 'name' => 'Streams/category/', 'type' => 'Streams/template', 'title' => 'Untitled Category', 'icon' => 'Streams/category', 'content' => '', 'attributes' => null, 'readLevel' => Streams::$READ_LEVEL['messages'], 'writeLevel' => Streams::$WRITE_LEVEL['relate'], 'adminLevel' => Streams::$ADMIN_LEVEL['invite']))->execute(); // template to help users create subcategories for things Streams_RelatedTo::insert(array('toPublisherId' => '', 'toStreamName' => 'Streams/category/', 'type' => 'subcategories', 'fromPublisherId' => '', 'fromStreamName' => 'Streams/category/'))->execute(); }
/** * Standard tool for starting or managing subscriptions. * @class Assets subscription * @constructor * @param {array} $options Override various options for this tool * @param {string} $options.payments can be "authnet" or "stripe" * @param {string} $options.planStreamName the name of the subscription plan's stream * @param {string} [$options.publisherId=Q.Users.communityId] the publisher of the subscription plan's stream * @param {string} [$options.subscribeButton] Can override the title of the subscribe button * @param {array} [$options=array()] Any additional options * @param {string} [$options.token=null] required unless the user is an existing customer */ function Assets_subscription_tool($options) { if (empty($options['payments'])) { throw new Q_Exception_RequiredField(array('field' => 'payments'), 'payments'); } $payments = ucfirst($options['payments']); $lcpayments = strtolower($payments); $currency = strtolower(Q::ifset($options, 'currency', 'usd')); if ($payments === 'Authnet' and $currency !== 'usd') { throw new Q_Exception("Authnet doesn't support currencies other than USD", 'currency'); } $className = "Assets_Payments_{$payments}"; switch ($payments) { case 'Authnet': $adapter = new $className($options); $token = $options['token'] = $adapter->authToken(); $testing = $options['testing'] = Q_Config::expect('Assets', 'payments', $lcpayments, 'testing'); $action = $options['action'] = $testing ? "https://test.authorize.net/profile/manage" : "https://secure.authorize.net/profile/manage"; break; case 'Stripe': $publishableKey = Q_Config::expect('Assets', 'payments', 'stripe', 'publishableKey'); break; } $titles = array('Authnet' => 'Authorize.net', 'Stripe' => 'Stripe'); $subscribeButton = Q::ifset($options, 'subscribeButton', "Subscribe with " . $titles[$payments]); Q_Response::setToolOptions($options); return Q::view("Assets/tool/subscription/{$payments}.php", compact('token', 'publishableKey', 'action', 'paymentButton', 'subscribeButton', 'planStreamName')); }
/** * Used to create a new stream * * @param {array} $_REQUEST * @param {String} [$_REQUEST.title] Required. The title of the interest. * @param {String} [$_REQUEST.publisherId] Optional. Defaults to the app name. * @return {void} */ function Streams_interest_delete() { $user = Users::loggedInUser(true); $title = Q::ifset($_REQUEST, 'title', null); if (!isset($title)) { throw new Q_Exception_RequiredField(array('field' => 'title')); } $app = Q_Config::expect('Q', 'app'); $publisherId = Q::ifset($_REQUEST, 'publisherId', $app); $name = 'Streams/interest/' . Q_Utils::normalize($title); $stream = Streams::fetchOne(null, $publisherId, $name); if (!$stream) { throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => Q::json_encode(compact('publisherId', 'name')))); } $miPublisherId = $user->id; $miName = 'Streams/user/interests'; $myInterests = Streams::fetchOne($user->id, $miPublisherId, $miName); if (!$myInterests) { throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => Q::json_encode(array('publisherId' => $miPublisherId, 'name' => $miName)))); } $stream->leave(); Streams::unrelate($user->id, $user->id, 'Streams/user/interests', 'Streams/interest', $publisherId, $name, array('adjustWeights' => true)); Q_Response::setSlot('publisherId', $publisherId); Q_Response::setSlot('streamName', $name); /** * Occurs when the logged-in user has successfully removed an interest via HTTP * @event Streams/interest/delete {after} * @param {string} publisherId The publisher of the interest stream * @param {string} title The title of the interest * @param {Users_User} user The logged-in user * @param {Streams_Stream} stream The interest stream * @param {Streams_Stream} myInterests The user's "Streams/user/interests" stream */ Q::event("Streams/interest/remove", compact('publisherId', 'title', 'subscribe', 'user', 'stream', 'myInterests'), 'after'); }
/** * Standard tool for making payments. * @class Assets payment * @constructor * @param {array} $options Override various options for this tool * @param {string} $options.payments can be "authnet" or "stripe" * @param {string} $options.amount the amount to pay. * @param {double} [$options.currency="usd"] the currency to pay in. (authnet supports only "usd") * @param {string} [$options.payButton] Can override the title of the pay button * @param {String} [$options.publisherId=Users::communityId()] The publisherId of the Assets/product or Assets/service stream * @param {String} [$options.streamName] The name of the Assets/product or Assets/service stream * @param {string} [$options.name=Users::communityName()] The name of the organization the user will be paying * @param {string} [$options.image] The url pointing to a square image of your brand or product. The recommended minimum size is 128x128px. * @param {string} [$options.description=null] A short name or description of the product or service being purchased. * @param {string} [$options.panelLabel] The label of the payment button in the Stripe Checkout form (e.g. "Pay {{amount}}", etc.). If you include {{amount}}, it will be replaced by the provided amount. Otherwise, the amount will be appended to the end of your label. * @param {string} [$options.zipCode] Specify whether Stripe Checkout should validate the billing ZIP code (true or false). The default is false. * @param {boolean} [$options.billingAddress] Specify whether Stripe Checkout should collect the user's billing address (true or false). The default is false. * @param {boolean} [$options.shippingAddress] Specify whether Checkout should collect the user's shipping address (true or false). The default is false. * @param {string} [$options.email=Users::loggedInUser(true)->emailAddress] You can use this to override the email address, if any, provided to Stripe Checkout to be pre-filled. * @param {boolean} [$options.allowRememberMe=true] Specify whether to include the option to "Remember Me" for future purchases (true or false). * @param {boolean} [$options.bitcoin=false] Specify whether to accept Bitcoin (true or false). * @param {boolean} [$options.alipay=false] Specify whether to accept Alipay ('auto', true, or false). * @param {boolean} [$options.alipayReusable=false] Specify if you need reusable access to the customer's Alipay account (true or false). */ function Assets_payment_tool($options) { Q_Valid::requireFields(array('payments', 'amount'), $options, true); if (empty($options['name'])) { $options['name'] = Users::communityName(); } if (!empty($options['image'])) { $options['image'] = Q_Html::themedUrl($options['image']); } $options['payments'] = strtolower($options['payments']); if (empty($options['email'])) { $options['email'] = Users::loggedInUser(true)->emailAddress; } $payments = ucfirst($options['payments']); $currency = strtolower(Q::ifset($options, 'currency', 'usd')); if ($payments === 'Authnet' and $currency !== 'usd') { throw new Q_Exception("Authnet doesn't support currencies other than USD", 'currency'); } $className = "Assets_Payments_{$payments}"; switch ($payments) { case 'Authnet': $adapter = new $className($options); $token = $options['token'] = $adapter->authToken(); $testing = $options['testing'] = Q_Config::expect('Assets', 'payments', $lcpayments, 'testing'); $action = $options['action'] = $testing ? "https://test.authorize.net/profile/manage" : "https://secure.authorize.net/profile/manage"; break; case 'Stripe': $publishableKey = Q_Config::expect('Assets', 'payments', 'stripe', 'publishableKey'); break; } $titles = array('Authnet' => 'Authorize.net', 'Stripe' => 'Stripe'); Q_Response::setToolOptions($options); $payButton = Q::ifset($options, 'payButton', "Pay with " . $titles[$payments]); return Q::view("Assets/tool/payment/{$payments}.php", compact('token', 'publishableKey', 'action', 'payButton')); }
/** * Displays an HTML document that can be printed, ideally with line breaks. * Uses a particular view for the layout. * @param {array} $_REQUEST * @param {string} $_REQUEST.invitingUserId Required. The id of the user that generated the invitations with a call to Streams::invite. * @param {string} $_REQUEST.batch Required. The name of the batch under which invitations were saved during a call to Streams::invite. * @param {string} [$_REQUEST.limit=100] The maximum number of invitations to show on the page * @param {string} [$_REQUEST.offset=0] Used for paging * @param {string} [$_REQUEST.title='Invitations'] Override the title of the document * @param {string} [$_REQUEST.layout='default'] The name of the layout to use for the HTML document * @see Users::addLink() */ function Streams_invitations_response() { Q_Request::requireFields(array('batch', 'invitingUserId'), true); $invitingUserId = $_REQUEST['invitingUserId']; $batch = $_REQUEST['batch']; $title = Q::ifset($_REQUEST, 'layout', 'title'); $layoutKey = Q::ifset($_REQUEST, 'layout', 'default'); $limit = min(1000, Q::ifset($_REQUEST, 'limit', 100)); $offset = Q::ifset($_REQUEST, 'offset', 0); $layout = Q_Config::expect('Streams', 'invites', 'layout', $layoutKey); $app = Q_Config::expect('Q', 'app'); $pattern = Streams::invitationsPath($invitingUserId) . DS . $batch . DS . "*.html"; $filenames = glob($pattern); $parts = array(); foreach ($filenames as $f) { if (--$offset > 0) { continue; } $parts[] = file_get_contents($f); if (--$limit == 0) { break; } } $content = implode("\n\n<div class='Q_pagebreak Streams_invitations_separator'></div>\n\n", $parts); echo Q::view($layout, compact('content', 'parts')); return false; }
function Users_identifier_post() { $userId = Q::ifset($_REQUEST, 'userId', null); if (isset($userId)) { $user = Users_User::fetch($userId, true); if ($user->emailAddress or $user->mobileNumber) { throw new Q_Exception("This user is already able to log in and set their own email and mobile number."); } } else { $user = Users::loggedInUser(true); } $app = Q_Config::expect('Q', 'app'); $fields = array(); $identifier = Users::requestedIdentifier($type); if (!$type) { throw new Q_Exception("a valid email address or mobile number is required", array('identifier', 'mobileNumber', 'emailAddress')); } if ($type === 'email') { $subject = Q_Config::get('Users', 'transactional', 'identifier', 'subject', "Welcome! Verify your email address."); $view = Q_Config::get('Users', 'transactional', 'identifier', 'body', 'Users/email/addEmail.php'); $user->addEmail($identifier, $subject, $view, array(), array('html' => true)); } else { if ($type === 'mobile') { $view = Q_Config::get('Users', 'transactional', 'identifier', 'sms', 'Users/sms/addMobile.php'); $user->addMobile($identifier, $view); } } }
function Q_response_dashboard() { $app = Q_Config::expect('Q', 'app'); $slogan = "Powered by Q."; $user = Users::loggedInUser(); return Q::view("{$app}/dashboard.php", compact('slogan', 'user')); }
function Q_errors_native($params) { echo Q::view('Q/errors.php', $params); $app = Q_Config::expect('Q', 'app'); Q::log("{$app}: Errors in " . ceil(Q::milliseconds()) . "ms\n"); Q::log($params); }
/** * @constructor * @param {array} $options=array() Any initial options * @param {string} $options.secret * @param {string} $options.publishableKey * @param {string} $options.token If provided, allows us to create a customer and charge them * @param {Users_User} [$options.user=Users::loggedInUser()] Allows us to set the user to charge */ function __construct($options = array()) { if (!isset($options['user'])) { $options['user'] = Users::loggedInUser(true); } $this->options = array_merge(array('secret' => Q_Config::expect('Assets', 'payments', 'stripe', 'secret'), 'publishableKey' => Q_Config::expect('Assets', 'payments', 'stripe', 'publishableKey')), $options); }
function Users_after_Q_reroute($params, &$stop_dispatch) { $uri = Q_Dispatcher::uri(); $app = Q_Config::expect('Q', 'app'); $ma = $uri->module . '/' . $uri->action; $requireLogin = Q_Config::get('Users', 'requireLogin', array()); if (!isset($requireLogin[$ma])) { return; // We don't have to require login here } $user = Users::loggedInUser(); if ($requireLogin[$ma] === true and !$user) { // require login } else { if ($requireLogin[$ma] === 'facebook' and !Users::facebook($app)) { // require facebook } else { return; // We don't have to require login here } } $redirect_action = Q_Config::get('Users', 'uris', "{$app}/login", "{$app}/welcome"); if ($redirect and $ma != $redirect_action) { Q_Response::redirect($redirect_action); $stop_dispatch = true; return; } }
function Websites_before_Streams_Stream_save_Websites_article($params) { $stream = $params['stream']; $modifiedFields = $params['modifiedFields']; if ($stream->wasRetrieved()) { return; } $user = new Users_User(); if (empty($stream->userId) and empty($modifiedFields['userId'])) { if ($liu = Users::loggedInUser()) { $stream->userId = $liu->id; } else { throw new Q_Exception_RequiredField(array('field' => 'userId')); } } $user->id = $stream->userId; if (!$user->retrieve()) { throw new Users_Exception_NoSuchUser(); } $title = Streams::displayName($user, array('fullAccess' => true)); if (isset($title)) { $stream->title = $title; } $stream->icon = $user->iconUrl(); $s = Streams::fetchOne($user->id, $user->id, "Streams/user/icon"); if (!$s or !($sizes = $s->getAttribute('sizes', null))) { $sizes = Q_Config::expect('Users', 'icon', 'sizes'); sort($sizes); } $stream->setAttribute('sizes', $sizes); }
/** * Override Q/noModule handler. * just goes on to render our app's response, * which will echo a 404 view. */ function Q_noModule($params) { header("HTTP/1.0 404 Not Found"); Q_Dispatcher::uri()->module = Q_Config::expect('Q', 'app'); Q_Dispatcher::uri()->action = 'notFound'; Q::event('Q/response', $params); }
function Users_before_Q_session_save($params) { $row = $params['row']; $row->deviceId = ""; $row->timeout = 0; $row->content = isset($_SESSION) ? Q::json_encode($_SESSION, JSON_FORCE_OBJECT) : "{}"; $row->duration = Q_Config::get('Q', 'session', 'durations', Q_Request::formFactor(), Q_Config::expect('Q', 'session', 'durations', 'session')); }
/** * @method hasAward * @static * @param {string} $awardName * @param {string} $userId * @return {boolean} */ static function hasAward($awardName, $userId) { $exists = new Awards_Earned(); $exists->app = Q_Config::expect('Q', 'app'); $exists->userId = $userId; $exists->badge_name = $awardName; return $exists->retrieve() ? true : false; }
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')); }
function Streams_participating_response() { if (!Q_Request::isAjax()) { return; } $max_limit = Q_Config::expect('Streams', 'db', 'limits', 'participating'); $user = Users::loggedInUser(true); $type = Streams::requestedType(); $limit = Streams::requestedField('limit', false, $max_limit); if ($limit > $max_limit) { throw new Q_Exception("limit is too large, must be <= {$max_limit}"); } $offset = Streams::requestedField('offset', false, 0); $order = Streams::requestedField('order', false, true); $participating = array(); $q = Streams_Participating::select('*')->where(array('userId' => $user->id)); if ($type) { $q = $q->where(array('streamName' => new Db_Range($type . '/', true, false, true))); } if ($limit) { $q = $q->limit($limit, $offset); } if ($order) { $q = $q->orderBy('updatedTime', false); } $res_participating = $q->fetchDbRows(); foreach ($res_participating as $part) { $part_safe = $part->exportArray(); if (isset($part_safe)) { $participating[] = $part_safe; } } Q_Response::setSlot('participating', $participating); if (!Q_Request::slotName('streams')) { return; } $res_streams = array(); $streamNames = array(); foreach ($res_participating as $p) { $streamNames[$p->publisherId][] = $p->streamName; } foreach ($streamNames as $p_id => $names) { $res_streams[$p_id] = Streams::fetch($user->id, $p_id, $names); } $streams = array(); $o = array('asUserId' => $user->id); foreach ($res_streams as $publisherId => $streams_array) { if (!empty($streams_array)) { $streams[$publisherId] = array(); foreach ($streams_array as $streamName => $stream) { $streams[$publisherId][$streamName] = $stream->exportArray($o); } } } Q_Response::setSlot('streams', $streams); }
/** * @constructor * @param {array} [$options=array()] Any initial options * @param {Users_User} [$options.user=Users::loggedInUser()] Allows us to set the user to charge * @param {string} [$options.authname] Optionally override the authname from config * @param {string} [$options.authkey] Optionally override the authkey from config */ function __construct($options = array()) { Q::includeFile(implode(DS, array(Q_PLUGINS_DIR, 'Assets', 'classes', 'Composer', 'vendor', 'autoload.php'))); $testing = Q_Config::expect('Assets', 'payments', 'authnet', 'testing'); $server = $testing ? net\authorize\api\constants\ANetEnvironment::SANDBOX : net\authorize\api\constants\ANetEnvironment::PRODUCTION; if (!isset($options['user'])) { $options['user'] = Users::loggedInUser(true); } $this->options = array_merge(array('authname' => Q_Config::expect('Assets', 'payments', 'authnet', 'name'), 'authkey' => Q_Config::expect('Assets', 'payments', 'authnet', 'transactionKey'), 'server' => $server), $options); }
function Trump_location_response_content() { $apikey = Q_Config::expect('Places', 'google', 'keys', 'web'); return <<<EOT \t\t<iframe frameborder="0" style="border:0" \t\t src="https://www.google.com/maps/embed/v1/place?key={$apikey} \t\t &q=Trump+Village+Section+Three+Brooklyn+NY"> \t\t</iframe> EOT; }
function Streams_before_Q_Utils_canWriteToPath($params, &$result) { extract($params); /** * @var $path * @var $throwIfNotWritable * @var $mkdirIfMissing */ // Assume that Users/before/Q/Utils/canWriteToPath already executed $user = Users::loggedInUser(); $userId = $user ? $user->id : ""; $app = Q_Config::expect('Q', 'app'); $len = strlen(APP_DIR); if (substr($path, 0, $len) === APP_DIR) { $sp = str_replace(DS, '/', substr($path, $len + 1)); if (substr($sp, -1) === '/') { $sp = substr($sp, 0, strlen($sp) - 1); } $prefix = "files/{$app}/uploads/Streams/"; $len = strlen($prefix); if (substr($sp, 0, $len) === $prefix) { $splitId = Q_Utils::splitId($userId); $prefix2 = "files/{$app}/uploads/Streams/invitations/{$splitId}/"; if ($userId and substr($sp, 0, strlen($prefix2)) === $prefix2) { $result = true; // user can write any invitations here return; } $parts = explode('/', substr($sp, $len)); $c = count($parts); if ($c >= 3) { $result = false; for ($j = 0; $j < $c - 3; ++$j) { $publisherId = implode('', array_slice($parts, 0, $j + 1)); $l = $j; for ($i = $c - 1; $i > $j; --$i) { $l = $i; if (in_array($parts[$i], array('icon', 'file'))) { break; } } $name = implode('/', array_slice($parts, $j + 1, $l - $j - 1)); if ($name and $stream = Streams::fetchOne($userId, $publisherId, $name)) { $result = $stream->testWriteLevel('edit'); Streams::$cache['canWriteToStream'] = $stream; break; } } } } } if (!$result and $throwIfNotWritable) { throw new Q_Exception_CantWriteToPath(); } }
function Streams_0_8_4_Streams_mysql() { $app = Q_Config::expect('Q', 'app'); $communityId = Users::communityId(); $user = Users_User::fetch($communityId); // avatar for the App user $avatar = new Streams_Avatar(); $avatar->toUserId = $communityId; $avatar->publisherId = $communityId; $avatar->username = $user->username; $avatar->firstName = Users::communityName(); $avatar->lastName = Users::communitySuffix(); $avatar->icon = $user->icon; $avatar->save(); $avatar2 = new Streams_Avatar(); $avatar2->copyFrom($avatar, null, false, true); $avatar->toUserId = ''; $avatar->save(); // access stream for managing app roles $stream = new Streams_Stream(); $stream->publisherId = Users::communityId(); $stream->name = 'Streams/contacts'; $stream->type = 'Streams/resource'; $stream->title = "Contacts"; $stream->setAttribute('prefixes', array("Users/", "{$app}/")); $stream->save(); // access stream for managing app roles $stream = new Streams_Stream(); $stream->publisherId = $app; $stream->name = 'Streams/labels'; $stream->type = 'Streams/resource'; $stream->title = "Labels"; $stream->setAttribute('prefixes', array("Users/", "{$app}/")); $stream->save(); // access for managing app contacts $access = new Streams_Access(); $access->publisherId = $communityId; $access->streamName = 'Streams/contacts'; $access->ofUserId = ''; $access->ofContactLabel = "{$app}/admins"; $access->readLevel = Streams::$READ_LEVEL['messages']; $access->writeLevel = Streams::$WRITE_LEVEL['edit']; $access->adminLevel = Streams::$ADMIN_LEVEL['manage']; $access->save(); // access for managing app roles $access = new Streams_Access(); $access->publisherId = $communityId; $access->streamName = 'Streams/labels'; $access->ofUserId = ''; $access->ofContactLabel = "{$app}/admins"; $access->readLevel = Streams::$READ_LEVEL['messages']; $access->writeLevel = Streams::$WRITE_LEVEL['edit']; $access->adminLevel = Streams::$ADMIN_LEVEL['manage']; $access->save(); }
function Platform_before_Users_computePassphraseHash($params) { $user = $params['user']; $passphrase = $params['passphrase']; $isHashed = $params['isHashed']; $appRootUrl = Q_Config::get("Platform", "appRootUrl", Q_Config::expect("Q", "web", "appRootUrl")); if (!$isHashed) { $passphrase = sha1($passphrase . "\t" . $appRootUrl . "\t" . $this->id); } return Users::hashPassphrase($passphrase, $user->passphraseHash); }