// where should the file go?
- static function filename($profile, $basename, $mimetype)
+ static function filename(Profile $profile, $origname, $mimetype)
{
try {
$ext = common_supported_mime_to_ext($mimetype);
$ext = substr(strrchr($mimetype, '/'), 1);
}
+ // Normalize and make the original filename more URL friendly.
+ $origname = basename($origname);
+ if (class_exists('Normalizer')) {
+ // http://php.net/manual/en/class.normalizer.php
+ // http://www.unicode.org/reports/tr15/
+ $origname = Normalizer::normalize($origname, Normalizer::FORM_KC);
+ }
+ $origname = preg_replace('/[^A-Za-z0-9\.\_]/', '_', $origname);
+
$nickname = $profile->nickname;
- $datestamp = strftime('%Y%m%dT%H%M%S', time());
- $random = strtolower(common_confirmation_code(32));
- return "$nickname-$datestamp-$random.$ext";
+ $datestamp = strftime('%Y%m%d', time());
+ do {
+ // generate new random strings until we don't run into a filename collision.
+ $random = strtolower(common_confirmation_code(16));
+ $filename = "$nickname-$datestamp-$origname-$random.$ext";
+ } while (file_exists(self::path($filename)));
+ return $filename;
}
/**
{
return self::path($this->filename);
}
+ public function getUrl()
+ {
+ return $this->url;
+ }
/**
* Blow the cache of notices that link to this URL
function title() {
if (empty($this->attachment->title)) {
if (empty($this->oembed->title)) {
- $title = $this->attachment->url;
+ $title = $this->attachment->filename;
} else {
$title = $this->oembed->title;
}
return array('class' => 'attachment',
'href' => $this->attachment->url,
'id' => 'attachment-' . $this->attachment->id,
- 'title' => $this->title());
+ 'title' => $this->linkTitle());
}
function showLink() {
function showRepresentation() {
$thumb = $this->getThumbInfo();
- if ($thumb) {
- $this->out->element('img', array('alt' => '', 'src' => $thumb->url, 'width' => $thumb->width, 'height' => $thumb->height));
+ if ($thumb instanceof File_thumbnail) {
+ $this->out->element('img', array('alt' => '', 'src' => $thumb->getUrl(), 'width' => $thumb->width, 'height' => $thumb->height));
}
}
case 'video/quicktime':
case 'video/webm':
$mediatype = common_get_mime_media($this->attachment->mimetype);
+ $thumb = $this->getThumbInfo();
+ $poster = ($thumb instanceof File_thumbnail)
+ ? $thumb->getUrl()
+ : null;
$this->out->elementStart($mediatype,
array('class'=>'attachment_player',
+ 'poster'=>$poster,
'controls'=>'controls'));
$this->out->element('source',
array('src'=>$this->attachment->url,
* @link http://status.net/
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
class MediaFile
{
$this->maybeAddRedir($this->fileRecord->id, $this->short_fileurl);
}
- function attachToNotice($notice)
+ public function attachToNotice(Notice $notice)
{
File_to_post::processNew($this->fileRecord->id, $notice->id);
$this->maybeAddRedir($this->fileRecord->id,