X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FFile.php;h=9bb22e502b6203297980c2c93769b357954820fa;hb=5e47b1b2a07d8b300c511115ca018ece172a8505;hp=1edc89d5d7be503d30f3a1e03bcacc5453fa58ea;hpb=cbb7ec07a58e44ffa4f98328511869eee2d6cd43;p=quix0rs-gnu-social.git diff --git a/classes/File.php b/classes/File.php index 1edc89d5d7..9bb22e502b 100644 --- a/classes/File.php +++ b/classes/File.php @@ -391,17 +391,20 @@ class File extends Managed_DataObject throw new UnsupportedMediaException('No image geometry available.'); } - if ($width === null) { + if ($width === null || $width < 1) { $width = common_config('thumbnail', 'width'); $height = common_config('thumbnail', 'height'); $crop = common_config('thumbnail', 'crop'); } - if ($height === null) { + if ($height === null || $height < 1) { $height = $width; $crop = true; } + // Debug log (convert crop to int to have TRUE being displayed as 1 and FALSE as 0) + common_debug('[' . __METHOD__ . ':' . __LINE__ . ']: width=' . $width . ',height=' . $height . ',crop=' . intval($crop)); + // Get proper aspect ratio width and height before lookup // We have to do it through an ImageFile object because of orientation etc. // Only other solution would've been to rotate + rewrite uploaded files. @@ -433,7 +436,19 @@ class File extends Managed_DataObject || $box['h'] < 1 || $box['y'] >= $this->height) { // Fail on bad width parameter. If this occurs, it's due to algorithm in ImageFile->scaleToFit common_debug("Boundary box parameters for resize of {$this->filepath} : ".var_export($box,true)); - throw new ServerException('Bad thumbnail size parameters.'); + throw new ServerException('Bad thumbnail size parameters. maxsize=' . + common_config('thumbnail', 'maxsize') . + ',box[width]=' . $box['width'] . + ',box[height]=' . $box['height'] . + ',box[w]=' . $box['w'] . + ',box[h]=' . $box['h'] . + ',box[x]=' . $box['x'] . + ',box[y]=' . $box['y'] . + ',this->width=' . $this->width . + ',this->heigh=' . $this->height . + ',this->filepath=' . $this->filepath . + ',this->filename=' . $this->filename + ); } // Perform resize and store into file @@ -453,11 +468,42 @@ class File extends Managed_DataObject { return self::path($this->filename); } + public function getUrl() { + if (!empty($this->filename)) { + // A locally stored file, so let's generate a URL for our instance. + $url = self::url($this->filename); + if ($url != $this->url) { + // For indexing purposes, in case we do a lookup on the 'url' field. + // also we're fixing possible changes from http to https, or paths + $this->updateUrl($url); + } + return $url; + } + + // No local filename available, return the URL we have stored return $this->url; } + public function updateUrl($url) + { + $file = File::getKV('url', $url); + if ($file instanceof File) { + throw new ServerException('URL already exists in DB'); + } + $sql = 'UPDATE %1$s SET url=%2$s WHERE url=%3$s;'; + $result = $this->query(sprintf($sql, $this->__table, + $this->_quote((string)$url), + $this->_quote((string)$this->url))); + if ($result === false) { + common_log_db_error($this, 'UPDATE', __FILE__); + throw new ServerException("Could not UPDATE {$this->__table}.url"); + } + + return $result; + } + /** * Blow the cache of notices that link to this URL *