コード例 #1
0
ファイル: Exception.php プロジェクト: dmitriz/Platform
 /**
  * Represents a complex exception thrown in Q. It may contain more details.
  * @class Q_Exception
  * @constructor
  * @extends Exception
  * @param {array} [$params=array()] Array of parameters for the exception. 
  *  Used in the exception message, etc.
  *  To access them later, call $e->params()
  *  You can also provide a string here, which will
  *  then be the exception message.
  * @param {array} [$inputFields=array()] Array of names of input fields to which the exception applies.
  * @param {array} [$code=null] Optionally pass the error code here to override the default
  */
 function __construct($params = array(), $inputFields = array(), $code = null, $file = null, $line = null, $trace = null, $traceAsString = null)
 {
     if (is_string($inputFields)) {
         $inputFields = array($inputFields);
     }
     $this->inputFields = $inputFields;
     if (isset($file)) {
         $this->file = $file;
     }
     if (isset($line)) {
         $this->line = $line;
     }
     if (isset($trace)) {
         $this->trace = $trace;
     }
     if (isset($traceAsString)) {
         $this->traceAsString = $traceAsString;
     }
     if (is_string($params)) {
         parent::__construct($params, isset($code) ? $code : 1);
         return;
     }
     $this->params = is_array($params) ? $params : array();
     $className = get_class($this);
     $message = isset(self::$messages[$className]) ? Q::interpolate(self::$messages[$className], $this->params) : $className;
     $code = isset($code) ? $code : (isset(self::$codes[$className]) ? self::$codes[$className] : 1);
     parent::__construct($message, $code);
 }
コード例 #2
0
ファイル: Users.php プロジェクト: AndreyTepaykin/Platform
 /**
  * Get the url of a user's icon
  * @param {string} [$icon] The contents of a user row's icon field
  * @param {string} [$basename=""] The last part after the slash, such as "50.png"
  * @return {string} The stream's icon url
  */
 static function iconUrl($icon, $basename = null)
 {
     if (empty($icon)) {
         return null;
     }
     $url = Q::interpolate($icon, array('baseUrl' => Q_Request::baseUrl()));
     $url = Q_Valid::url($url) ? $url : "plugins/Users/img/icons/{$url}";
     if ($basename) {
         $url .= "/{$basename}";
     }
     return Q_Html::themedUrl($url);
 }
コード例 #3
0
ファイル: Stream.php プロジェクト: dmitriz/Platform
 /**
  * Get the url of the stream's icon
  * @param {string} [$basename=""] The last part after the slash, such as "50.png"
  * @return {string} The stream's icon url
  */
 function iconUrl($basename = null)
 {
     if (empty($this->icon)) {
         return null;
     }
     $url = Q::interpolate($this->icon, array('baseUrl' => Q_Request::baseUrl()));
     $url = Q_Valid::url($url) ? $url : "plugins/Streams/img/icons/{$url}";
     if ($basename) {
         if (strpos($basename, '.') === false) {
             $basename = "{$basename}.png";
         }
         $url .= "/{$basename}";
     }
     return Q_Html::themedUrl($url);
 }
コード例 #4
0
function Users_before_Q_Utils_canWriteToPath($params, &$result)
{
    extract($params);
    /**
     * @var $path
     * @var $throwIfNotWritable
     * @var $mkdirIfMissing
     */
    // The Users plugin requires that a user be logged in before uploading a file,
    // and only in the proper directories.
    $user = Users::loggedInUser($throwIfNotWritable);
    if (!$user) {
        return false;
    }
    $app = Q_Config::expect('Q', 'app');
    $subpaths = Q_Config::get('Users', 'paths', 'uploads', array('files/{{app}}/uploads/Users/{{userId}}' => true));
    $paths = array();
    $path = str_replace(array("/", "\\"), DS, $path);
    foreach ($subpaths as $subpath => $can_write) {
        if (!$can_write) {
            continue;
        }
        $subpath = Q::interpolate($subpath, array('userId' => Q_Utils::splitId($user->id), 'app' => $app));
        if ($subpath and ($subpath[0] !== '/' or $subpath[0] !== DS)) {
            $subpath = DS . $subpath;
        }
        $last_char = substr($subpath, -1);
        if ($subpath and $last_char !== '/' and $last_char !== DS) {
            $subpath .= DS;
        }
        $paths[] = APP_DIR . $subpath;
        foreach (Q_Config::get('Q', 'plugins', array()) as $plugin) {
            $c = strtoupper($plugin) . '_PLUGIN_DIR';
            if (defined($c)) {
                $paths[] = constant($c) . $subpath;
            }
        }
        $paths[] = Q_DIR . $subpath;
    }
    if (strpos($path, "../") === false and strpos($path, ".." . DS) === false) {
        foreach ($paths as $p) {
            $p = str_replace(array("/", "\\"), DS, $p);
            $len = strlen($p);
            if (strncmp($path, $p, $len) === 0) {
                // we can write to this path
                if ($mkdirIfMissing and !file_exists($path)) {
                    $mode = is_integer($mkdirIfMissing) ? $mkdirIfMissing : 0777;
                    $mask = umask(Q_Config::get('Q', 'internal', 'umask', 00));
                    if (!@mkdir($path, $mode, true)) {
                        throw new Q_Exception_FilePermissions(array('action' => 'create', 'filename' => $path, 'recommendation' => ' Please set your files directory to be writable.'));
                    }
                    umask($mask);
                    $dir3 = $path;
                    do {
                        chmod($dir3, $mode);
                        $dir3 = dirname($dir3);
                    } while ($dir3 and $dir3 != $p and $dir3 . DS != $p);
                }
                $result = true;
                return;
            }
        }
    }
    if ($throwIfNotWritable) {
        throw new Q_Exception_CantWriteToPath();
    }
    $result = false;
}
コード例 #5
0
ファイル: Streams.php プロジェクト: atirjavid/Platform
 static function invitationsPath($invitingUserId)
 {
     $app = Q_Config::expect('Q', 'app');
     $subpath = Q_Config::get('Streams', 'invites', 'subpath', '{{app}}/uploads/Streams/invitations');
     return APP_FILES_DIR . DS . Q::interpolate($subpath, compact('app')) . DS . $invitingUserId;
 }
コード例 #6
0
ファイル: Users.php プロジェクト: atirjavid/Platform
 static function termsLabel($for = 'register')
 {
     $terms_uri = Q_Config::get('Users', $for, 'terms', 'uri', null);
     $terms_label = Q_Config::get('Users', $for, 'terms', 'label', null);
     $terms_title = Q_Config::get('Users', $for, 'terms', 'title', null);
     if (!$terms_uri or !$terms_title or !$terms_label) {
         return null;
     }
     $terms_link = Q_Html::a(Q::interpolate($terms_uri, array('baseUrl' => Q_Request::baseUrl())), array('target' => '_blank'), $terms_title);
     return Q::interpolate($terms_label, array('link' => $terms_link));
 }
コード例 #7
0
ファイル: Utils.php プロジェクト: AndreyTepaykin/Platform
 /**
  * Returns base url for socket.io connection
  * @method nodeUrl
  * @static
  * @throws {Q_Exception_MissingConfig} If node host or port are not defined
  */
 static function nodeUrl()
 {
     $url = Q_Config::get('Q', 'node', 'url', null);
     if (isset($url)) {
         return Q::interpolate($url, array('baseUrl' => Q_Request::baseUrl()));
     }
     $host = Q_Config::get('Q', 'node', 'host', null);
     $port = Q_Config::get('Q', 'node', 'port', null);
     if (!isset($port) || !isset($host)) {
         return null;
     }
     $https = Q_Config::get('Q', 'node', 'https', false);
     $s = $https ? 's' : '';
     return "http{$s}://{$host}:{$port}";
 }
コード例 #8
0
ファイル: Valid.php プロジェクト: AndreyTepaykin/Platform
 /**
  * Use this for validating the nonce
  * @method nonce
  * @static
  * @param {boolean} [$throwIfInvalid=false] If true, throws an exception if the nonce is invalid.
  * @param {boolean} [$missingIsValid=false] If true, returns true if request body is missing nonce.
  * @throws {Q_Exception_FailedValidation}
  */
 static function nonce($throwIfInvalid = false, $missingIsValid = false)
 {
     if (!isset($_SESSION['Q']['nonce'])) {
         return true;
     }
     $snf = Q_Config::get('Q', 'session', 'nonceField', 'nonce');
     $sn = Q_Request::special($snf, null);
     if ($missingIsValid and !isset($sn)) {
         return true;
     }
     $gp = array_merge($_GET, $_POST);
     $rn = Q_Request::special($snf, null, $gp);
     if (!isset($sn) or $_SESSION['Q']['nonce'] != $rn) {
         if (!$throwIfInvalid) {
             return false;
         }
         $sameDomain = true;
         $baseUrl = Q_Request::baseUrl();
         $message = Q_Config::get('Q', 'session', 'nonceMessages', 'sameDomain', null);
         if (!empty($_SERVER['HTTP_REFERER'])) {
             $host1 = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
             $host2 = parse_url($baseUrl, PHP_URL_HOST);
             if ($host1 !== $host2) {
                 $message = Q_Config::get('Q', 'session', 'nonceMessages', 'otherDomain', null);
             }
         }
         $message = Q::interpolate($message, compact('baseUrl'));
         $field = 'nonce';
         throw new Q_Exception_FailedValidation(compact('message', 'field'), 'Q.nonce');
     }
     return true;
 }
コード例 #9
0
ファイル: User.php プロジェクト: AndreyTepaykin/Platform
 /**
  * Get the url of the user's icon
  * @param {string} [$basename=""] The last part after the slash, such as "50.png"
  * @return {string} The stream's icon url
  */
 function iconUrl($basename = null)
 {
     $replacements = array('userId' => Q_Utils::splitId($this->id));
     return Users::iconUrl(isset($this->icon) ? Q::interpolate($this->icon, $replacements) : 'default', $basename);
 }