Closed #37
This commit is contained in:
parent
4ecb3f3b81
commit
2279e5605b
6 changed files with 141 additions and 66 deletions
|
@ -5,9 +5,7 @@
|
|||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
.post-type-flash {
|
||||
border-color: red;
|
||||
}
|
||||
.post-type-youtube:after,
|
||||
.post-type-flash:after {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
|
@ -15,9 +13,21 @@
|
|||
width: 150px;
|
||||
height: 150px;
|
||||
content: ' ';
|
||||
background: url('../img/thumb-overlay-swf.png');
|
||||
pointer-events: none;
|
||||
}
|
||||
.post-type-flash {
|
||||
border-color: red;
|
||||
}
|
||||
.post-type-youtube {
|
||||
border-color: red;
|
||||
}
|
||||
.post-type-flash:after {
|
||||
background: url('../img/thumb-overlay-swf.png');
|
||||
}
|
||||
.post-type-youtube:after {
|
||||
background: url('../img/thumb-overlay-yt.png');
|
||||
}
|
||||
|
||||
|
||||
.post:focus,
|
||||
.post:hover {
|
||||
|
|
BIN
public_html/media/img/thumb-overlay-yt.png
Normal file
BIN
public_html/media/img/thumb-overlay-yt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
|
@ -188,12 +188,27 @@ $(function()
|
|||
handleInputs(urls, function(postDom, url)
|
||||
{
|
||||
postDom.data('url', url);
|
||||
$('.file-name strong', postDom).text(url);
|
||||
$('[name=source]', postDom).val(url);
|
||||
|
||||
var img = postDom.find('img');
|
||||
img.css('background-image', 'none');
|
||||
img.attr('src', url);
|
||||
postDom.find('[name=source]').val(url);
|
||||
if (matches = url.match(/watch.*?=([a-zA-Z0-9_-]+)/))
|
||||
{
|
||||
postDom.find('.file-name strong').text(url);
|
||||
$.getJSON('http://gdata.youtube.com/feeds/api/videos/' + matches[1] + '?v=2&alt=jsonc', function(data)
|
||||
{
|
||||
postDom.find('.file-name strong')
|
||||
.text(data.data.title);
|
||||
postDom.find('img')
|
||||
.css('background-image', 'none')
|
||||
.attr('src', data.data.thumbnail.hqDefault);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
postDom.find('.file-name strong')
|
||||
.text(url);
|
||||
postDom.find('img')
|
||||
.css('background-image', 'none')
|
||||
.attr('src', url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -217,9 +217,18 @@ class PostController
|
|||
elseif (InputHelper::get('url'))
|
||||
{
|
||||
$url = InputHelper::get('url');
|
||||
$origName = $url;
|
||||
if (!preg_match('/^https?:\/\//', $url))
|
||||
throw new SimpleException('Invalid URL "' . $url . '"');
|
||||
$origName = $url;
|
||||
|
||||
if (preg_match('/youtube.com\/watch.*?=([a-zA-Z0-9_-]+)/', $url, $matches))
|
||||
{
|
||||
$origName = $matches[1];
|
||||
$postType = PostType::Youtube;
|
||||
$sourcePath = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sourcePath = tempnam(sys_get_temp_dir(), 'upload') . '.dat';
|
||||
|
||||
//warning: low level sh*t ahead
|
||||
|
@ -253,10 +262,11 @@ class PostController
|
|||
fclose($sourceFP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* file details */
|
||||
$mimeType = mime_content_type($sourcePath);
|
||||
$mimeType = $sourcePath ? mime_content_type($sourcePath) : null;
|
||||
$imageWidth = null;
|
||||
$imageHeight = null;
|
||||
switch ($mimeType)
|
||||
|
@ -272,13 +282,29 @@ class PostController
|
|||
list ($imageWidth, $imageHeight) = getimagesize($sourcePath);
|
||||
break;
|
||||
default:
|
||||
if (!isset($postType))
|
||||
throw new SimpleException('Invalid file type "' . $mimeType . '"');
|
||||
}
|
||||
|
||||
if ($sourcePath)
|
||||
{
|
||||
$fileSize = filesize($sourcePath);
|
||||
$fileHash = md5_file($sourcePath);
|
||||
$duplicatedPost = R::findOne('post', 'file_hash = ?', [$fileHash]);
|
||||
if ($duplicatedPost !== null)
|
||||
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fileSize = 0;
|
||||
$fileHash = null;
|
||||
if ($postType == PostType::Youtube)
|
||||
{
|
||||
$duplicatedPost = R::findOne('post', 'orig_name = ?', [$origName]);
|
||||
if ($duplicatedPost !== null)
|
||||
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -307,7 +333,7 @@ class PostController
|
|||
$dbPost->name = $name;
|
||||
$dbPost->orig_name = $origName;
|
||||
$dbPost->file_hash = $fileHash;
|
||||
$dbPost->file_size = filesize($sourcePath);
|
||||
$dbPost->file_size = $fileSize;
|
||||
$dbPost->mime_type = $mimeType;
|
||||
$dbPost->safety = $suppliedSafety;
|
||||
$dbPost->source = $suppliedSource;
|
||||
|
@ -319,10 +345,13 @@ class PostController
|
|||
$dbPost->ownFavoritee = [];
|
||||
$dbPost->sharedTag = $dbTags;
|
||||
|
||||
if ($sourcePath)
|
||||
{
|
||||
if (is_uploaded_file($sourcePath))
|
||||
move_uploaded_file($sourcePath, $path);
|
||||
else
|
||||
rename($sourcePath, $path);
|
||||
}
|
||||
R::store($dbPost);
|
||||
|
||||
$this->context->transport->success = true;
|
||||
|
@ -623,7 +652,15 @@ class PostController
|
|||
$dstWidth = $this->config->browsing->thumbWidth;
|
||||
$dstHeight = $this->config->browsing->thumbHeight;
|
||||
|
||||
switch ($post->mime_type)
|
||||
if ($post->type == PostType::Youtube)
|
||||
{
|
||||
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
|
||||
$contents = file_get_contents('http://img.youtube.com/vi/' . $post->orig_name . '/mqdefault.jpg');
|
||||
file_put_contents($tmpPath, $contents);
|
||||
if (file_exists($tmpPath))
|
||||
$srcImage = imagecreatefromjpeg($tmpPath);
|
||||
}
|
||||
else switch ($post->mime_type)
|
||||
{
|
||||
case 'image/jpeg':
|
||||
$srcImage = imagecreatefromjpeg($srcPath);
|
||||
|
@ -784,6 +821,10 @@ class PostController
|
|||
case 'img':
|
||||
$type = PostType::Image;
|
||||
break;
|
||||
case 'yt':
|
||||
case 'youtube':
|
||||
$type = PostType::Youtube;
|
||||
break;
|
||||
default:
|
||||
throw new SimpleException('Unknown type "' . $val . '"');
|
||||
}
|
||||
|
|
|
@ -3,4 +3,5 @@ class PostType extends Enum
|
|||
{
|
||||
const Image = 1;
|
||||
const Flash = 2;
|
||||
const Youtube = 3;
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@
|
|||
</span>
|
||||
</div>
|
||||
|
||||
<?php if ($this->context->transport->post->type != PostType::Youtube): ?>
|
||||
<div class="permalink">
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" title="Download">
|
||||
<i class="icon-dl"></i>
|
||||
|
@ -105,6 +106,7 @@
|
|||
</span>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
||||
<div class="unit favorites">
|
||||
|
@ -211,11 +213,17 @@
|
|||
|
||||
<div id="inner-content">
|
||||
<div class="post-wrapper post-type-<?php echo strtolower(PostType::toString($this->context->transport->post->type)) ?>">
|
||||
<?php if ($this->context->transport->post->type == PostType::Image): ?>
|
||||
<?php switch ($this->context->transport->post->type):
|
||||
case PostType::Image: ?>
|
||||
<img src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" alt="<?php echo $this->context->transport->post->name ?>"/>
|
||||
<?php elseif ($this->context->transport->post->type == PostType::Flash): ?>
|
||||
<?php break ?>
|
||||
<?php case PostType::Flash: ?>
|
||||
<embed width="<?php echo $this->context->transport->post->image_width ?>" height="<?php echo $this->context->transport->post->image_height ?>" type="application/x-shockwave-flash" src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>"/>
|
||||
<?php endif ?>
|
||||
<?php break ?>
|
||||
<?php case PostType::Youtube: ?>
|
||||
<iframe width="800" height="600" src="//www.youtube.com/embed/<?php echo $this->context->transport->post->orig_name ?>" frameborder="0" allowfullscreen></iframe>
|
||||
<?php break ?>
|
||||
<?php endswitch ?>
|
||||
</div>
|
||||
|
||||
<?php if ($canEditAnything): ?>
|
||||
|
|
Loading…
Reference in a new issue