Ejemplo n.º 1
0
 /**
  * @class Q_Exception_Upload
  * @constructor
  * @extends Q_Exception
  * @param {array} [$param=array()]
  * @param {array} [$input_fields=array()]
  */
 function __construct($params = array(), $input_fields = array())
 {
     parent::__construct($params, $input_fields);
     if (!isset($params['code'])) {
         return;
     }
     switch ($params['code']) {
         case UPLOAD_ERR_INI_SIZE:
             $this->message = "the uploaded file exceeds the upload_max_filesize directive in php.ini.";
             break;
         case UPLOAD_ERR_FORM_SIZE:
             $this->message = "value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
             break;
         case UPLOAD_ERR_PARTIAL:
             $this->message = "value: 3; The uploaded file was only partially uploaded.";
             break;
         case UPLOAD_ERR_NO_FILE:
             $this->message = "value: 4; No file was uploaded.";
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $this->message = "value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.";
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $this->message = "value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.";
             break;
         case UPLOAD_ERR_EXTENSION:
             $this->message = "a PHP extension stopped the file upload.";
             break;
     }
 }
Ejemplo n.º 2
0
<?php

/**
 * @module Q
 */
class Q_Exception_AppRequirement extends Q_Exception
{
}
Q_Exception::add('Q_Exception_AppRequirement', 'App \'{{by}}\' requires plugin \'{{plugin}}\' version $version or compatible.');
Ejemplo n.º 3
0
<?php

/**
 * @module Users
 */
class Users_Exception_NoRegister extends Q_Exception
{
}
Q_Exception::add('Users_Exception_NoRegister', 'Cannot directly register a user.');
Ejemplo n.º 4
0
<?php

/**
 * @module Streams
 */
class Streams_Exception_AlreadyForwarded extends Q_Exception
{
}
Q_Exception::add('Streams_Exception_AlreadyForwarded', 'this invite has already been forwarded');
Ejemplo n.º 5
0
<?php

/**
 * @module Q
 */
class Q_Exception_MissingObject extends Q_Exception
{
}
Q_Exception::add('Q_Exception_MissingObject', 'missing object {{name}}');
Ejemplo n.º 6
0
<?php

/**
 * @module Streams
 */
class Streams_Exception_NoSubscriptions extends Q_Exception
{
}
Q_Exception::add('Streams_Exception_NoSubscriptions', 'Stream of type {{type}} does not support subscription');
Ejemplo n.º 7
0
function Q_exception_native($params)
{
    extract($params);
    /**
     * @var Exception $exception 
     */
    if ($is_ajax = Q_Request::isAjax()) {
        $json = @Q::json_encode(array('errors' => Q_Exception::toArray(array($exception))));
        $callback = Q_Request::callback();
        switch (strtolower($is_ajax)) {
            case 'iframe':
                // Render an HTML layout for ajax
                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':
                // Render a JSON layout for ajax
            // Render a JSON layout for ajax
            default:
                header("Content-type: " . ($callback ? "application/javascript" : "application/json"));
                echo $callback ? "{$callback}({$json})" : $json;
        }
    } else {
        if (Q::textMode()) {
            echo Q_Exception::coloredString($exception);
            exit;
        }
        $message = $exception->getMessage();
        $file = $exception->getFile();
        $line = $exception->getLine();
        if (is_callable(array($exception, 'getTraceAsStringEx'))) {
            $trace_string = $exception->getTraceAsStringEx();
        } else {
            $trace_string = $exception->getTraceAsString();
        }
        if ($exception instanceof Q_Exception_PhpError or !empty($exception->messageIsHtml)) {
            // do not sanitize $message
        } else {
            $message = Q_Html::text($message);
        }
        $content = "<h1 class='exception_message'>{$message}</h1>";
        if (Q_Config::get('Q', 'exception', 'showFileAndLine', true)) {
            $content .= "<h3 class='exception_fileAndLine'>in {$file} ({$line})</h3>";
        }
        if (Q_Config::get('Q', 'exception', 'showTrace', true)) {
            $content .= "<pre class='exception_trace'>{$trace_string}</pre>";
        }
        $content .= str_repeat(' ', 512);
        // because of chrome
        $title = "Exception occurred";
        $dashboard = "";
        echo Q::view('Q/layout/html.php', compact('content', 'dashboard', 'title'));
    }
    $app = Q_Config::get('Q', 'app', null);
    $colored = Q_Exception::coloredString($exception);
    Q::log("{$app}: Exception in " . ceil(Q::milliseconds()) . "ms:\n\n{$colored}\n", null, true, array('maxLength' => 10000));
}
Ejemplo n.º 8
0
<?php

/**
 * @module Q
 */
class Q_Exception_Recursion extends Q_Exception
{
}
Q_Exception::add('Q_Exception_Recursion', 'seems we have runaway recursive calls to {{function_name}}');
Ejemplo n.º 9
0
<?php

/**
 * @module Assets
 */
class Assets_Exception_InvalidResponse extends Q_Exception
{
}
Q_Exception::add('Assets_Exception_InvalidResponse', 'invalid response: {{response}}');
Ejemplo n.º 10
0
 /**
  * Error handler
  * @method errorHandler
  * @param {integer} $errno
  * @param {string} $errstr
  * @param {string} $errfile
  * @param {integer} $errline
  * @param {array} $errcontext
  */
 static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
 {
     if (!(error_reporting() & $errno)) {
         // This error code is not included in error_reporting
         // just continue on with execution, if possible.
         // this situation can also happen when
         // someone has used the @ operator.
         return;
     }
     switch ($errno) {
         case E_WARNING:
         case E_NOTICE:
         case E_USER_WARNING:
         case E_USER_NOTICE:
             $context = Q::var_dump($errcontext, 4, '$', 'text');
             $dump = Q_Exception::coloredString($errstr, $errfile, $errline, $context);
             Q::log("PHP Error({$errno}): \n\n{$dump}", null, null, array('maxLength' => 10000));
             $type = 'warning';
             break;
         default:
             $type = 'error';
             break;
     }
     /**
      * @event Q/error
      * @param {integer} errno
      * @param {string} errstr
      * @param {string} errfile
      * @param {integer} errline
      * @param {array} errcontext
      */
     self::event("Q/error", compact('type', 'errno', 'errstr', 'errfile', 'errline', 'errcontext'));
 }
Ejemplo n.º 11
0
<?php

/**
 * @module Q
 */
class Q_Exception_AppRequirementVersion extends Q_Exception
{
}
Q_Exception::add('Q_Exception_AppRequirementVersion', 'App \'{{by}}\' requires plugin \'{{plugin}}\' version {{version}} or compatible. (You have: {{installed}}, compatible with {{compatible}})');
Ejemplo n.º 12
0
function Streams_batch_response_batch()
{
    if (empty($_REQUEST['batch'])) {
        throw new Q_Exception_RequiredField(array('field' => 'batch'));
    }
    try {
        $batch = json_decode($_REQUEST['batch'], true);
    } catch (Exception $e) {
    }
    if (empty($batch)) {
        throw new Q_Exception_WrongValue(array('field' => 'batch', 'range' => 'valid JSON'));
    }
    if (empty($batch['args'])) {
        throw new Q_Exception_RequiredField(array('field' => 'args'));
    }
    // Gather the publisher ids and stream names to fetch
    $to_fetch = array();
    foreach ($batch['args'] as $args) {
        if (count($args) < 4) {
            continue;
        }
        list($action, $slots, $publisherId, $name) = $args;
        if (empty($to_fetch[$publisherId])) {
            $to_fetch[$publisherId] = array();
        }
        $to_fetch[$publisherId][] = $name;
    }
    $user = Users::loggedInUser();
    $userId = $user ? $user->id : "";
    // Fetch the actual streams
    $streams = array();
    foreach ($to_fetch as $publisherId => $names) {
        if (empty($streams[$publisherId])) {
            $streams[$publisherId] = array();
        }
        $streams[$publisherId] = array_merge($streams[$publisherId], Streams::fetch($userId, $publisherId, $names, '*'));
    }
    // Now, build the result
    $result = array();
    foreach ($batch['args'] as $args) {
        try {
            $action = $args[0];
            $prev_request = $_REQUEST;
            $extra = !empty($args[4]) ? $args[4] : null;
            if (is_array($extra)) {
                foreach ($extra as $k => $v) {
                    $_REQUEST[$k] = $v;
                }
            }
            switch ($action) {
                case 'stream':
                    break;
                case 'message':
                    if (!is_array($extra)) {
                        $_REQUEST['ordinal'] = $extra;
                    }
                    break;
                case 'participant':
                    if (!is_array($extra)) {
                        $_REQUEST['userId'] = $extra;
                    }
                    break;
                default:
                    throw new Q_Exception_WrongValue(array('field' => 'action', 'range' => "'stream', 'message' or 'participant'"));
            }
            Q_Request::$slotNames_override = is_array($args[1]) ? $args[1] : explode(',', $args[1]);
            Q_Request::$method_override = 'GET';
            if (count($args) >= 4) {
                Streams::$requestedPublisherId_override = $publisherId = $args[2];
                Streams::$requestedName_override = $name = $args[3];
                if (empty($streams[$publisherId][$name])) {
                    throw new Q_Exception_MissingRow(array('table' => 'Stream', 'criteria' => "{publisherId: '{$publisherId}', name: '{$name}'}"));
                }
                Streams::$cache['stream'] = $streams[$publisherId][$name];
            }
            Q::event("Streams/{$action}/response", compact('streams', 'publisherId', 'name', 'extra', 'user', 'userId'));
            $slots = Q_Response::slots(true);
            unset($slots['batch']);
            $result[] = compact('slots');
        } catch (Exception $e) {
            $result[] = array('errors' => Q_Exception::toArray(array($e)));
        }
        $prev_request = $_REQUEST;
        Q_Request::$slotNames_override = null;
        Q_Request::$method_override = null;
        Streams::$requestedPublisherId_override = null;
        Streams::$requestedName_override = null;
    }
    return $result;
}
Ejemplo n.º 13
0
<?php

/**
 * @module Users
 */
class Users_Exception_NoSuchUser extends Q_Exception
{
}
Q_Exception::add('Users_Exception_NoSuchUser', 'No such user was found in the system');
Ejemplo n.º 14
0
<?php

/**
 * @module Q
 */
class Q_Exception_BadUrl extends Q_Exception
{
}
Q_Exception::add('Q_Exception_BadUrl', 'bad url {{url}} (the base url is {{base_url}})');
Ejemplo n.º 15
0
<?php

/**
 * @module Q
 */
class Q_Exception_DbQuery extends Q_Exception
{
}
Q_Exception::add('Q_Exception_DbQuery', 'DbQuery Exception: {{msg}} ... Query was: {{sql}}');
Ejemplo n.º 16
0
<?php

/**
 * @module Users
 */
class Users_Exception_WrongPassphrase extends Q_Exception
{
}
Q_Exception::add('Users_Exception_WrongPassphrase', 'That is not the right pass phrase');
<?php

/**
 * @module Assets
 */
class Assets_Exception_PaymentMethodRequired extends Q_Exception
{
}
Q_Exception::add('Assets_Exception_PaymentMethodRequired', 'Please add a valid payment method');
Ejemplo n.º 18
0
<?php

/**
 * @module Users
 */
class Users_Exception_LoggedIn extends Q_Exception
{
}
Q_Exception::add('Users_Exception_LoggedIn', 'You are logged in');
Ejemplo n.º 19
0
<?php

/**
 * @module Streams
 */
class Streams_Exception_AlreadyDeclined extends Q_Exception
{
}
Q_Exception::add('Streams_Exception_AlreadyDeclined', 'this invite has already been declined');
Ejemplo n.º 20
0
<?php

/**
 * @module Assets
 */
class Assets_Exception_ChargeFailed extends Q_Exception
{
}
Q_Exception::add('Assets_Exception_ChargeFailed', 'The attempt to charge failed');
Ejemplo n.º 21
0
function Streams_before_Q_objects()
{
    $token = Q_Request::special('Streams.token', null);
    if ($token === null) {
        return;
    }
    $invite = Streams_Invite::fromToken($token);
    if (!$invite) {
        throw new Q_Exception_MissingRow(array('table' => 'invite', 'criteria' => "token = '{$token}"), 'token');
    }
    // did invite expire?
    $ts = Streams_Invite::db()->select("CURRENT_TIMESTAMP")->fetchAll(PDO::FETCH_NUM);
    if (isset($invite->expireTime) and $invite->expireTime < $ts[0][0]) {
        $invite->state = 'expired';
        $invite->save();
    }
    // is invite still pending?
    if ($invite->state !== 'pending') {
        switch ($invite->state) {
            case 'expired':
                $exception = new Streams_Exception_AlreadyExpired(null, 'token');
                break;
            case 'accepted':
                $exception = new Streams_Exception_AlreadyAccepted(null, 'token');
                break;
            case 'declined':
                $exception = new Streams_Exception_AlreadyDeclined(null, 'token');
                break;
            case 'forwarded':
                $exception = new Streams_Exception_AlreadyForwarded(null, 'token');
                break;
            default:
                $exception = new Q_Exception("This invite has already been " . $invite->state, 'token');
                break;
        }
        $shouldThrow = Q::event('Streams/objects/inviteException', compact('invite', 'exception'), 'before');
        if ($shouldThrow === null) {
            Q_Response::setNotice('Streams/objects', $exception->getMessage(), true);
        } else {
            if ($shouldThrow === true) {
                throw $exception;
            }
        }
    }
    // now process the invite
    $invitedUser = Users_User::fetch($invite->userId, true);
    $stream = Streams::fetchOne($invitedUser->id, $invite->publisherId, $invite->streamName);
    if (!$stream) {
        throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => "publisherId = '{$invite->publisherId}', name = '{$invite->streamName}'"));
    }
    $byUser = Users_User::fetch($invite->invitingUserId, true);
    $byStream = Streams::fetchOne($byUser->id, $invite->publisherId, $invite->streamName);
    if (!$byStream) {
        throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => "publisherId = '{$invite->publisherId}', name = '{$invite->streamName}'"));
    }
    $access = new Streams_Access();
    $access->publisherId = $byStream->publisherId;
    $access->streamName = $byStream->name;
    $access->ofUserId = $invite->userId;
    $specified_access = false;
    foreach (array('readLevel', 'writeLevel', 'adminLevel') as $level_type) {
        $access->{$level_type} = -1;
        if (empty($invite->{$level_type})) {
            continue;
        }
        // Give access level from the invite.
        // However, if inviting user has a lower access level now,
        // then give that level instead, unless it is lower than
        // what the invited user would have had otherwise.
        $min = min($invite->{$level_type}, $byStream->get($level_type, 0));
        if ($min > $stream->get($level_type, 0)) {
            $access->{$level_type} = $min;
            $specified_access = true;
        }
    }
    if ($specified_access) {
        $access->save(true);
    }
    // now log invited user in
    $user = Users::loggedInUser();
    if (empty($user) or $user->id !== $invite->userId) {
        $user = new Users_User();
        $user->id = $invite->userId;
        if (!$user->retrieve()) {
            // The user who was invited doesn't exist
            // This shouldn't happen. We just silently log it and return.
            Q::log("Sanity check failed: invite with {$invite->token} pointed to nonexistent user");
            return;
        }
        Users::setLoggedInUser($user);
    }
    // accept invite and autosubscribe if first time
    if ($invite->accept() and !$stream->subscription($user->id)) {
        $stream->subscribe();
    }
    // retain the invite object for further processing
    Streams::$followedInvite = $invite;
}
Ejemplo n.º 22
0
<?php

/**
 * @module Users
 */
class Users_Exception_AlreadyVerified extends Q_Exception
{
}
Q_Exception::add('Users_Exception_AlreadyVerified', 'Another user has verified this {{key}}');
Ejemplo n.º 23
0
<?php

/**
 * @module Streams
 */
class Streams_Exception_AlreadyRelated extends Q_Exception
{
}
Q_Exception::add('Streams_Exception_AlreadyRelated', 'The stream is already {{state}}');
Ejemplo n.º 24
0
 /**
  * @method errors
  * @static
  * @protected
  * @param {Exception} $exception
  * @param {string} $module
  * @param {string} [$partial_response=null]
  */
 protected static function errors($exception, $module, $partial_response = null)
 {
     self::$errors_occurred = true;
     $response_started = self::$response_started;
     $errors = Q_Response::getErrors();
     Q::$toolWasRendered = array();
     try {
         if (self::$handling_errors) {
             // We need to handle errors, but we
             // have already tried to do it.
             // Just show the errors view.
             Q::event('Q/errors/native', compact('errors', 'exception', 'partial_response', 'response_started'));
             return;
         }
         self::$handling_errors = true;
         if (Q::canHandle("{$module}/errors")) {
             /**
              * @event $module/errors
              * @param {Exception} exception
              * @param {string} module
              * @param {string} partial_response
              */
             Q::event("{$module}/errors", compact('errors', 'exception', 'partial_response', 'response_started'));
         } else {
             /**
              * @event Q/errors
              * @param {Exception} exception
              * @param {string} module
              * @param {string} partial_response
              */
             Q::event("Q/errors", compact('errors', 'exception', 'partial_response', 'response_started'));
         }
     } catch (Exception $e) {
         Q_Exception::rethrow($e, '');
         // may be for forwarding
         /**
          * @event Q/exception
          * @param {Exception} exception
          */
         Q::event('Q/exception', compact('exception'));
         // the original exception
     }
 }
Ejemplo n.º 25
0
<?php

/**
 * @module Q
 */
class Q_Exception_SendingToNode extends Q_Exception
{
}
Q_Exception::add('Q_Exception_SendingToNode', 'Error sending {{method}} message to Node. Please try again later.');
Ejemplo n.º 26
0
<?php

/**
 * @module Q
 */
class Q_Exception_TestCaseFailed extends Q_Exception_TestCase
{
}
Q_Exception::add('Q_Exception_TestCaseFailed', 'failed. {{message}}');
Ejemplo n.º 27
0
<?php

/**
 * @module Users
 */
class Users_Exception_DeviceNotification extends Q_Exception
{
}
Q_Exception::add('Users_Exception_DeviceNotification', 'Sending notification failed: $statusMessage');
Ejemplo n.º 28
0
<?php

/**
 * @module Q
 */
class Q_Exception_ContentLength extends Q_Exception
{
}
Q_Exception::add('Q_Exception_ContentLength', 'ContentLength exceeds {{exceeds}}');
Ejemplo n.º 29
0
<?php

/**
 * @module Users
 */
class Users_Exception_NotAuthorized extends Q_Exception
{
}
Q_Exception::add('Users_Exception_NotAuthorized', 'You are not authorized to do this');
Ejemplo n.º 30
0
<?php

/**
 * @module Q
 */
class Q_Exception_TestCaseIncomplete extends Q_Exception_TestCase
{
}
Q_Exception::add('Q_Exception_TestCaseIncomplete', 'incomplete. {{message}}');