<?php
/**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
*
* Abstraction for an image file
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Image
- * @package Laconica
- * @author Evan Prodromou <evan@controlyourself.ca>
- * @author Zach Copley <zach@controlyourself.ca>
- * @copyright 2008-2009 Control Yourself, Inc.
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @author Zach Copley <zach@status.net>
+ * @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://laconi.ca/
+ * @link http://status.net/
*/
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
* Makes it slightly easier to accept an image file from upload.
*
* @category Image
- * @package Laconica
- * @author Evan Prodromou <evan@controlyourself.ca>
- * @author Zach Copley <zach@controlyourself.ca>
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://laconi.ca/
+ * @link http://status.net/
*/
class ImageFile
static function fromUpload($param='upload')
{
switch ($_FILES[$param]['error']) {
- case UPLOAD_ERR_OK: // success, jump out
+ case UPLOAD_ERR_OK: // success, jump out
break;
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- throw new Exception(sprintf(_('That file is too big. The maximum file size is %d.'), $this->maxFileSize()));
+ case UPLOAD_ERR_INI_SIZE:
+ case UPLOAD_ERR_FORM_SIZE:
+ throw new Exception(sprintf(_('That file is too big. The maximum file size is %s.'),
+ ImageFile::maxFileSize()));
return;
- case UPLOAD_ERR_PARTIAL:
+ case UPLOAD_ERR_PARTIAL:
@unlink($_FILES[$param]['tmp_name']);
throw new Exception(_('Partial upload.'));
return;
- default:
+ case UPLOAD_ERR_NO_FILE:
+ // No file; probably just a non-AJAX submission.
+ return;
+ default:
+ common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " .
+ $_FILES[$param]['error']);
throw new Exception(_('System error uploading file.'));
return;
}
throw new Exception(_('Lost our file.'));
return;
}
-
+
// Don't crop/scale if it isn't necessary
- if ($size === $this->width
- && $size === $this->height
- && $x === 0
- && $y === 0
+ if ($size === $this->width
+ && $size === $this->height
+ && $x === 0
+ && $y === 0
&& $w === $this->width
&& $h === $this->height) {
-
+
$outname = Avatar::filename($this->id,
- image_type_to_extension($this->type),
- $size,
- common_timestamp());
+ image_type_to_extension($this->type),
+ $size,
+ common_timestamp());
$outpath = Avatar::path($outname);
@copy($this->filepath, $outpath);
return $outname;
imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h);
$outname = Avatar::filename($this->id,
- image_type_to_extension($this->type),
- $size,
- common_timestamp());
+ image_type_to_extension($this->type),
+ $size,
+ common_timestamp());
$outpath = Avatar::path($outname);
throw new Exception(_('Unknown file type'));
return;
}
-
+
imagedestroy($image_src);
imagedestroy($image_dest);
$value = ImageFile::maxFileSizeInt();
if ($value > 1024 * 1024) {
- return ($value/(1024*1024)).'Mb';
+ return ($value/(1024*1024)) . _('MB');
} else if ($value > 1024) {
- return ($value/(1024)).'kB';
+ return ($value/(1024)) . _('kB');
} else {
return $value;
}
$num = substr($str, 0, -1);
switch(strtoupper($unit)){
- case 'G':
- $num *= 1024;
- case 'M':
- $num *= 1024;
- case 'K':
- $num *= 1024;
+ case 'G':
+ $num *= 1024;
+ case 'M':
+ $num *= 1024;
+ case 'K':
+ $num *= 1024;
}
return $num;