Beispiel #1
0
function Q_post($params)
{
    $uri = Q_Dispatcher::uri();
    $module = $uri->module;
    $action = $uri->action;
    if (!Q::canHandle("{$module}/{$action}/post")) {
        throw new Q_Exception_MethodNotSupported(array('method' => 'POST'));
    }
    if (isset($_SERVER['CONTENT_LENGTH'])) {
        $contentLength = (int) $_SERVER['CONTENT_LENGTH'];
        foreach (array('upload_max_filesize', 'post_max_size') as $name) {
            $value = ini_get($name);
            switch (substr($value, -1)) {
                case 'K':
                    $value *= 1024;
                    break;
                case 'M':
                    $value *= 1024 * 1024;
                    break;
                case 'B':
                    $value *= 1024 * 1024 * 1024;
                    break;
            }
            if ($contentLength > $value) {
                throw new Q_Exception_ContentLength(array('contentLength' => $contentLength, 'exceeds' => $name));
            }
        }
    }
    return Q::event("{$module}/{$action}/post", $params);
}
Beispiel #2
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);
        }
    }
}
Beispiel #3
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);
    }
}
Beispiel #4
0
/**
 * Default Q/notFound handler.
 * Just displays Q/notFound.php view.
 */
function Q_notFound($params)
{
    header("HTTP/1.0 404 Not Found");
    Q_Dispatcher::result("Nothing found");
    $url = Q_Request::url();
    echo Q::view('Q/notFound.php', compact('url'));
}
Beispiel #5
0
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;
    }
}
Beispiel #6
0
function Users_activate_validate()
{
    $uri = Q_Dispatcher::uri();
    $emailAddress = Q::ifset($_REQUEST, 'e', $uri->emailAddress);
    $mobileNumber = Q::ifset($_REQUEST, 'm', $uri->mobileNumber);
    if ($emailAddress && !Q_Valid::email($emailAddress, $e_normalized, array('no_ip' => 'false'))) {
        throw new Q_Exception_WrongValue(array('field' => 'email', 'range' => 'a valid email address'), 'emailAddress');
    }
    if ($mobileNumber && !Q_Valid::phone($mobileNumber, $m_normalized)) {
        throw new Q_Exception_WrongValue(array('field' => 'mobile phone', 'range' => 'a valid phone number'), 'mobileNumber');
    }
    if ($emailAddress or $mobileNumber) {
        if (empty($_REQUEST['code'])) {
            throw new Q_Exception("The activation code is missing");
        }
    } else {
        throw new Q_Exception("The contact information is missing");
    }
    if (!empty($e_normalized)) {
        Users::$cache['emailAddress'] = $e_normalized;
    }
    if (!empty($m_normalized)) {
        Users::$cache['mobileNumber'] = $m_normalized;
    }
}
Beispiel #7
0
function MyApp_home_response_content($params)
{
    // Implement a home page for the user
    $user = Users::loggedInUser();
    // For now we will just internally forward to the welcome page
    Q_Dispatcher::forward("MyApp/welcome");
}
Beispiel #8
0
/**
 * 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);
}
Beispiel #9
0
function Q_validate($params)
{
    $uri = Q_Dispatcher::uri();
    $module = $uri->module;
    $action = $uri->action;
    if (!Q::canHandle("{$module}/{$action}/validate")) {
        return null;
    }
    return Q::event("{$module}/{$action}/validate", $params);
}
Beispiel #10
0
function Q_put($params)
{
    $uri = Q_Dispatcher::uri();
    $module = $uri->module;
    $action = $uri->action;
    if (!Q::canHandle("{$module}/{$action}/put")) {
        throw new Q_Exception_MethodNotSupported(array('method' => 'PUT'));
    }
    return Q::event("{$module}/{$action}/put", $params);
}
Beispiel #11
0
function Q_response_title()
{
    // The default title
    $title = Q_Config::get('Q', 'app', basename(APP_DIR));
    $action = Q_Dispatcher::uri()->action;
    if ($action) {
        $title .= ": {$action}";
    }
    return $title;
}
Beispiel #12
0
/**
 * 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;
}
Beispiel #13
0
function Streams_invited_response()
{
    if (!($token = Q_Dispatcher::uri()->token)) {
        throw new Q_Exception_RequiredField(array('field' => 'token'), 'token');
    }
    if (!($invite = Streams_Invite::fromToken($token))) {
        throw new Q_Exception_MissingRow(array('table' => 'invite', 'criteria' => "token: {$token}"), 'token');
    }
    Users_User::fetch($invite->userId, true)->setVerified();
    Q_Response::redirect($invite->appUrl . "?" . http_build_query(array('Q.Streams.token' => $token), null, '&'));
}
Beispiel #14
0
function Q_delete($params)
{
    $uri = Q_Dispatcher::uri();
    $module = $uri->module;
    $action = $uri->action;
    if (!Q::canHandle("{$module}/{$action}/delete")) {
        throw new Q_Exception_MethodNotSupported(array('method' => 'DELETE'));
    }
    Q_Request::requireValidNonce();
    return Q::event("{$module}/{$action}/delete", $params);
}
/**
 * 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);
    }
}
Beispiel #16
0
function Q_response_content()
{
    $app = Q_Config::expect('Q', 'app');
    $url = Q_Request::url();
    $module = Q_Dispatcher::uri()->module;
    if (empty($module)) {
        return Q::event("{$app}/notFound/response/content");
    }
    $action = Q_Dispatcher::uri()->action;
    $event = "{$module}/{$action}/response/content";
    if (!Q::canHandle($event)) {
        return Q::event("{$app}/notFound/response/content");
    }
    // Go ahead and fire the event, returning the result.
    return Q::event($event);
}
Beispiel #17
0
function Q_response_content()
{
    $app = Q_Config::expect('Q', 'app');
    $url = Q_Request::url();
    $module = Q_Dispatcher::uri()->module;
    if (empty($module)) {
        return Q::event("{$app}/notFound/response/content");
    }
    $action = Q_Dispatcher::uri()->action;
    $event = "{$module}/{$action}/response/content";
    if (!Q::canHandle($event)) {
        return Q::event("{$app}/notFound/response/content");
    }
    Q_Response::setMeta('format-detection', 'telephone=no,date=no,address=no,email=no,url=no');
    // Go ahead and fire the event, returning the result.
    return Q::event($event);
}
Beispiel #18
0
 /**
  * Excecute web request
  * @method execute
  * @static
  */
 static function execute()
 {
     // Fixes for different platforms:
     if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
         // ISAPI 3.0
         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
     }
     // Get the base URL
     $base_url = Q_Request::baseUrl();
     if (Q::$controller === 'Q_ActionController') {
         // we detected action.php in the URL, but
         // a misconfigured web server executed index.php instead
         return Q_ActionController::execute();
     }
     // Set the controller that is being used
     if (!isset(Q::$controller)) {
         Q::$controller = 'Q_WebController';
     }
     try {
         $slots = Q_Request::slotNames(false);
         $slots = $slots ? ' slots: (' . implode(',', $slots) . ') from' : '';
         $method = Q_Request::method();
         Q::log("{$method}{$slots} url: " . Q_Request::url(true), null, null, array('maxLength' => 10000));
         Q_Dispatcher::dispatch();
         $dispatchResult = Q_Dispatcher::result();
         if (!isset($dispatchResult)) {
             $dispatchResult = 'Ran dispatcher';
         }
         $uri = Q_Request::uri();
         $module = $uri->module;
         $action = $uri->action;
         if ($module and $action) {
             $slotNames = Q_Request::slotNames();
             $returned_slots = empty($slotNames) ? '' : implode(',', $slotNames);
             Q::log("~" . ceil(Q::milliseconds()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " {$dispatchResult} for {$module}/{$action}" . " ({$returned_slots})", null, null, array('maxLength' => 10000));
         } else {
             Q::log("~" . ceil(Q::milliseconds()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " {$dispatchResult} No route for " . $_SERVER['REQUEST_URI'], null, null, array('maxLength' => 10000));
         }
     } catch (Exception $exception) {
         /**
          * @event Q/exception
          * @param {Exception} exception
          */
         Q::event('Q/exception', compact('exception'));
     }
 }
Beispiel #19
0
function Users_activate_objects()
{
    $uri = Q_Dispatcher::uri();
    $email = null;
    $mobile = null;
    $user = null;
    $emailAddress = Q::ifset(Users::$cache, 'emailAddress', null);
    $mobileNumber = Q::ifset(Users::$cache, 'mobileNumber', null);
    if ($emailAddress) {
        $user = Users_activate_objects_email(Users::$cache['emailAddress'], $email);
        $type = 'email address';
    }
    if ($mobileNumber) {
        $user = Users_activate_objects_mobile($mobileNumber, $mobile);
        $type = 'mobile number';
    }
    Users::$cache = compact('user', 'email', 'mobile', 'type', 'emailAddress', 'mobileNumber');
}
Beispiel #20
0
/**
 * 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();
    }
    $client_id = $_REQUEST['client_id'];
    $redirect_url = $_REQUEST['redirect_uri'];
    $state = $_REQUEST['state'];
    $client = Users_User::fetch($client_id);
    if (!$client) {
        throw new Q_Exception_MissingRow(array('table' => 'user', 'criteria' => "id = '{$client_id}'"), 'client_id');
    }
    if (empty($client->url)) {
        throw new Q_Exception("Client app needs to register url", 'client_id');
    }
    if (substr($redirect_url, 0, strlen($client->url)) !== $client->url) {
        throw new Q_Exception_WrongValue(array('field' => 'redirect_uri', 'range' => "a url prefixed by client user's 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->retrieve();
        }
    }
    if ($oa and $oa->wasRetrieved()) {
        // User is logged in and already has a token for this client_id and state
        $separator = strpos($redirect_url, '?') === false ? '?' : '&';
        $url = $redirect_url . $separator . http_build_query(array('access_token' => $oa->access_token, 'token_type' => 'bearer', 'expires_in' => $oa->token_expires_seconds, 'scope' => 'user', 'state' => $oa->state));
        Q_Response::redirect(Q_Uri::from($url, false));
        return false;
    }
    $terms_label = Users::termsLabel('authorize');
    $content = Q::view('Users/content/authorize.php', compact('client', 'redirect_url', 'user', 'state', 'terms_label'));
    Q_Response::setSlot('content', $content);
    Q_Response::setSlot('column0', $content);
    return true;
}
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'));
}
Beispiel #22
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 = Q_Config::expect("Websites", "user", "id");
        $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);
}
function Trump_before_Q_responseExtras()
{
    $app = Q_Config::expect('Q', 'app');
    Q_Response::addStylesheet('plugins/Q/css/Q.css');
    Q_Response::addStylesheet('css/html.css', '@end');
    if (Q_Config::get('Q', 'firebug', false)) {
        Q_Response::addScript("https://getfirebug.com/firebug-lite-debug.js");
    }
    Q_Response::addScript('js/Trump.js');
    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);
    }
}
Beispiel #24
0
function Q_response_default($params)
{
    if (!isset($params['slotName'])) {
        throw new Q_Exception_RequiredField(array('field' => '$slotName'));
    }
    $slotName = $params['slotName'];
    $uri = Q_Dispatcher::uri();
    $module = $uri->module;
    $action = $uri->action;
    if (!$module or !$action) {
        return "{$module}/{$action} is not a valid URI";
    }
    $event = "{$module}/{$action}/response/{$slotName}";
    $function_name = $module . '_' . $action . '_response_' . $slotName;
    if (function_exists($function_name)) {
        $result = Q::event($event);
        $result = isset($result) ? $result : "Don't return null from {$function_name}";
    }
    if (Q::canHandle($event)) {
        return Q::event($event);
    }
    throw new Q_Exception_MissingSlot(compact('event'));
}
Beispiel #25
0
function Users_before_Q_objects()
{
    $app = Q_Config::expect('Q', 'app');
    $fb_info = Q_Config::get('Users', 'facebookApps', $app, null);
    // We sometimes pass this in the request, for browsers like Safari
    // that don't allow setting of cookies using javascript inside 3rd party iframes
    if (!empty($fb_info['appId']) and !empty($_REQUEST['Users']['facebook_authResponse'])) {
        $appId = $fb_info['appId'];
        $auth_response = $_REQUEST['Users']['facebook_authResponse'];
        if (is_array($auth_response)) {
            if ($auth_response) {
                $cookie = $auth_response['signedRequest'];
                $expires = 0;
            } else {
                $cookie = "";
                $expires = 1;
            }
            try {
                $facebook = new Facebook(array('appId' => $fb_info['appId'], 'secret' => $fb_info['secret'], 'fileUpload' => true));
                $cookie_name = 'fbsr_' . $facebook->getAppId();
                if (!empty($_SERVER['HTTP_HOST'])) {
                    Q_Response::setCookie($cookie_name, $cookie, $expires);
                }
            } catch (Exception $e) {
                // do nothing
            }
        }
    }
    $uri = Q_Dispatcher::uri();
    $actions = array('activate' => true);
    if ($uri->module === 'Users' and isset($actions[$uri->action])) {
        Q::event("Users/{$uri->action}/objects");
    }
    // Fire an event for hooking into, if necessary
    Q::event('Users/objects', array(), 'after');
}
Beispiel #26
0
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'));
}
Beispiel #27
0
 protected static function handleForwardException($e)
 {
     $slotNames = Q_Request::slotNames(true);
     foreach ($slotNames as $slotName) {
         Q_Response::clearSlot($slotName);
     }
     // Go again, this time with a different URI.
     Q::$toolWasRendered = array();
     self::$uri = Q_Uri::from($e->uri);
     if (is_array($e->skip)) {
         self::$skip = $e->skip;
     } else {
         // Don't process any non-GET methods this time around,
         // Do not collect any analytics
         // And also ignore any accumulated errors
         self::$skip = array('Q/method' => true, 'Q/analytics' => true, 'Q/errors' => true);
     }
     // We'll be handling errors anew
     self::$handling_errors = false;
 }
Beispiel #28
0
 /**
  * Get the stream field from the request, if it can't be deduced throws error
  * @method requestedField
  * @static
  * @param {string} $field
  *	The fiels name
  * @param {boolean} $throwIfMissing=false
  *  Optional. If true, throws an exception if the stream field cannot be deduced
  * @param {mixed} $default=null
  *	Is returned if field is not set
  * @return {string}
  *  The value of the field
  * @throws {Q_Exception_RequiredField}
  *  If the field value can't be deduced, this is thrown
  */
 static function requestedField($field, $throwIfMissing = false, $default = null)
 {
     $uri = Q_Dispatcher::uri();
     if (isset($_REQUEST[$field])) {
         return $_REQUEST[$field];
     } else {
         if (isset($uri->{$field})) {
             if (is_array($uri->{$field})) {
                 return implode('/', $uri->{$field});
             }
             return $uri->{$field};
         } else {
             if ($field = Q_Request::special("Streams.{$field}", $default)) {
                 return $field;
             }
         }
     }
     if ($throwIfMissing) {
         throw new Q_Exception_RequiredField(array('field' => "stream {$field}"), $field);
     }
     return $default;
 }
Beispiel #29
0
 /**
  * The standard action front controller
  * @method execute
  * @static
  * @throws {Q_Exception_BadUrl}
  * @throws {Q_Exception}
  * @throws {Q_Exception_MissingConfig}
  */
 static function execute($url = null)
 {
     // Fixes for different platforms:
     if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
         // ISAPI 3.0
         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
     }
     // Set the controller that is being used
     if (!isset(Q::$controller)) {
         Q::$controller = 'Q_ActionController';
     }
     try {
         $slots = Q_Request::slotNames(false);
         $slots = $slots ? ' slots: (' . implode(',', $slots) . ') from' : '';
         $method = Q_Request::method();
         Q::log("{$method}{$slots} url: " . Q_Request::url(true));
         $tail = Q_Request::tail($url);
         if (!isset($tail)) {
             // Bad url was requested somehow
             $url = Q_Request::url(true);
             $base_url = Q_Request::baseUrl(true);
             throw new Q_Exception_BadUrl(compact('base_url', 'url'));
         }
         $parts = explode('/', $tail);
         $parts_len = count($parts);
         if ($parts_len >= 1) {
             $module = $parts[0];
         }
         if ($parts_len >= 2) {
             $action = $parts[1];
         }
         if (empty($module) or empty($action)) {
             throw new Q_Exception("Not implemented");
         }
         // Make sure the 'Q'/'web' config fields are set,
         // otherwise URLs will be formed pointing to the wrong
         // controller script.
         $ar = Q_Config::get('Q', 'web', 'appRootUrl', null);
         if (!isset($ar)) {
             throw new Q_Exception_MissingConfig(array('fieldpath' => 'Q/web/appRootUrl'));
         }
         // Dispatch the request
         $uri = Q_Uri::from(compact('module', 'action'));
         Q_Dispatcher::dispatch($uri);
         $dispatchResult = Q_Dispatcher::result();
         if (!isset($dispatchResult)) {
             $dispatchResult = 'Ran dispatcher';
         }
         if ($module and $action) {
             $slotNames = Q_Request::slotNames();
             $requestedSlots = empty($slotNames) ? '' : implode(',', $slotNames);
             Q::log("~" . ceil(Q::milliseconds()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " {$dispatchResult} for {$module}/{$action}" . " ({$requestedSlots})");
         } else {
             Q::log("~" . ceil(Q::milliseconds()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " No route for " . $_SERVER['REQUEST_URI']);
         }
     } catch (Exception $exception) {
         /**
          * @event Q/exception
          * @param {Exception} exception
          */
         Q::event('Q/exception', compact('exception'));
     }
 }
Beispiel #30
0
 static function htmlAttributes()
 {
     $touchscreen = Q_Request::isTouchscreen() ? 'Q_touchscreen' : 'Q_notTouchscreen';
     $mobile = Q_Request::isMobile() ? 'Q_mobile' : 'Q_notMobile';
     $cordova = Q_Request::isCordova() ? 'Q_cordova' : 'Q_notCordova';
     $platform = 'Q_' . Q_Request::platform();
     $ie = Q_Request::isIE() ? 'Q_ie' : 'Q_notIE';
     $ie8 = Q_Request::isIE(0, 8) ? 'Q_ie8OrBelow' : 'Q_notIE8OrBelow';
     $uri = Q_Dispatcher::uri();
     $classes = "{$uri->module} {$uri->module}_{$uri->action}";
     $result = 'lang="en" prefix="og: http://ogp.me/ns# object: http://ogp.me/ns/object#" ' . "class='{$touchscreen} {$mobile} {$cordova} {$platform} {$ie} {$ie8} {$classes}'";
     return $result;
 }