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;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
.post-type-flash {
|
.post-type-youtube:after,
|
||||||
border-color: red;
|
|
||||||
}
|
|
||||||
.post-type-flash:after {
|
.post-type-flash:after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
@ -15,9 +13,21 @@
|
||||||
width: 150px;
|
width: 150px;
|
||||||
height: 150px;
|
height: 150px;
|
||||||
content: ' ';
|
content: ' ';
|
||||||
background: url('../img/thumb-overlay-swf.png');
|
|
||||||
pointer-events: none;
|
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:focus,
|
||||||
.post:hover {
|
.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)
|
handleInputs(urls, function(postDom, url)
|
||||||
{
|
{
|
||||||
postDom.data('url', url);
|
postDom.data('url', url);
|
||||||
$('.file-name strong', postDom).text(url);
|
postDom.find('[name=source]').val(url);
|
||||||
$('[name=source]', postDom).val(url);
|
if (matches = url.match(/watch.*?=([a-zA-Z0-9_-]+)/))
|
||||||
|
{
|
||||||
var img = postDom.find('img');
|
postDom.find('.file-name strong').text(url);
|
||||||
img.css('background-image', 'none');
|
$.getJSON('http://gdata.youtube.com/feeds/api/videos/' + matches[1] + '?v=2&alt=jsonc', function(data)
|
||||||
img.attr('src', url);
|
{
|
||||||
|
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,46 +217,56 @@ class PostController
|
||||||
elseif (InputHelper::get('url'))
|
elseif (InputHelper::get('url'))
|
||||||
{
|
{
|
||||||
$url = InputHelper::get('url');
|
$url = InputHelper::get('url');
|
||||||
|
$origName = $url;
|
||||||
if (!preg_match('/^https?:\/\//', $url))
|
if (!preg_match('/^https?:\/\//', $url))
|
||||||
throw new SimpleException('Invalid URL "' . $url . '"');
|
throw new SimpleException('Invalid URL "' . $url . '"');
|
||||||
$origName = $url;
|
|
||||||
$sourcePath = tempnam(sys_get_temp_dir(), 'upload') . '.dat';
|
|
||||||
|
|
||||||
//warning: low level sh*t ahead
|
if (preg_match('/youtube.com\/watch.*?=([a-zA-Z0-9_-]+)/', $url, $matches))
|
||||||
//download the URL $url into $sourcePath
|
|
||||||
$maxBytes = TextHelper::stripBytesUnits(ini_get('upload_max_filesize'));
|
|
||||||
set_time_limit(0);
|
|
||||||
$urlFP = fopen($url, 'rb');
|
|
||||||
if (!$urlFP)
|
|
||||||
throw new SimpleException('Cannot open URL for reading');
|
|
||||||
$sourceFP = fopen($sourcePath, 'w+b');
|
|
||||||
if (!$sourceFP)
|
|
||||||
{
|
{
|
||||||
fclose($urlFP);
|
$origName = $matches[1];
|
||||||
throw new SimpleException('Cannot open file for writing');
|
$postType = PostType::Youtube;
|
||||||
|
$sourcePath = null;
|
||||||
}
|
}
|
||||||
try
|
else
|
||||||
{
|
{
|
||||||
while (!feof($urlFP))
|
$sourcePath = tempnam(sys_get_temp_dir(), 'upload') . '.dat';
|
||||||
|
|
||||||
|
//warning: low level sh*t ahead
|
||||||
|
//download the URL $url into $sourcePath
|
||||||
|
$maxBytes = TextHelper::stripBytesUnits(ini_get('upload_max_filesize'));
|
||||||
|
set_time_limit(0);
|
||||||
|
$urlFP = fopen($url, 'rb');
|
||||||
|
if (!$urlFP)
|
||||||
|
throw new SimpleException('Cannot open URL for reading');
|
||||||
|
$sourceFP = fopen($sourcePath, 'w+b');
|
||||||
|
if (!$sourceFP)
|
||||||
{
|
{
|
||||||
$buffer = fread($urlFP, 4 * 1024);
|
fclose($urlFP);
|
||||||
if (fwrite($sourceFP, $buffer) === false)
|
throw new SimpleException('Cannot open file for writing');
|
||||||
throw new SimpleException('Cannot write into file');
|
}
|
||||||
fflush($sourceFP);
|
try
|
||||||
if (ftell($sourceFP) > $maxBytes)
|
{
|
||||||
throw new SimpleException('File is too big (maximum allowed size: ' . TextHelper::useBytesUnits($maxBytes) . ')');
|
while (!feof($urlFP))
|
||||||
|
{
|
||||||
|
$buffer = fread($urlFP, 4 * 1024);
|
||||||
|
if (fwrite($sourceFP, $buffer) === false)
|
||||||
|
throw new SimpleException('Cannot write into file');
|
||||||
|
fflush($sourceFP);
|
||||||
|
if (ftell($sourceFP) > $maxBytes)
|
||||||
|
throw new SimpleException('File is too big (maximum allowed size: ' . TextHelper::useBytesUnits($maxBytes) . ')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
fclose($urlFP);
|
||||||
|
fclose($sourceFP);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
fclose($urlFP);
|
|
||||||
fclose($sourceFP);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* file details */
|
/* file details */
|
||||||
$mimeType = mime_content_type($sourcePath);
|
$mimeType = $sourcePath ? mime_content_type($sourcePath) : null;
|
||||||
$imageWidth = null;
|
$imageWidth = null;
|
||||||
$imageHeight = null;
|
$imageHeight = null;
|
||||||
switch ($mimeType)
|
switch ($mimeType)
|
||||||
|
@ -272,13 +282,29 @@ class PostController
|
||||||
list ($imageWidth, $imageHeight) = getimagesize($sourcePath);
|
list ($imageWidth, $imageHeight) = getimagesize($sourcePath);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new SimpleException('Invalid file type "' . $mimeType . '"');
|
if (!isset($postType))
|
||||||
|
throw new SimpleException('Invalid file type "' . $mimeType . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileHash = md5_file($sourcePath);
|
if ($sourcePath)
|
||||||
$duplicatedPost = R::findOne('post', 'file_hash = ?', [$fileHash]);
|
{
|
||||||
if ($duplicatedPost !== null)
|
$fileSize = filesize($sourcePath);
|
||||||
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
$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
|
do
|
||||||
{
|
{
|
||||||
|
@ -307,7 +333,7 @@ class PostController
|
||||||
$dbPost->name = $name;
|
$dbPost->name = $name;
|
||||||
$dbPost->orig_name = $origName;
|
$dbPost->orig_name = $origName;
|
||||||
$dbPost->file_hash = $fileHash;
|
$dbPost->file_hash = $fileHash;
|
||||||
$dbPost->file_size = filesize($sourcePath);
|
$dbPost->file_size = $fileSize;
|
||||||
$dbPost->mime_type = $mimeType;
|
$dbPost->mime_type = $mimeType;
|
||||||
$dbPost->safety = $suppliedSafety;
|
$dbPost->safety = $suppliedSafety;
|
||||||
$dbPost->source = $suppliedSource;
|
$dbPost->source = $suppliedSource;
|
||||||
|
@ -319,10 +345,13 @@ class PostController
|
||||||
$dbPost->ownFavoritee = [];
|
$dbPost->ownFavoritee = [];
|
||||||
$dbPost->sharedTag = $dbTags;
|
$dbPost->sharedTag = $dbTags;
|
||||||
|
|
||||||
if (is_uploaded_file($sourcePath))
|
if ($sourcePath)
|
||||||
move_uploaded_file($sourcePath, $path);
|
{
|
||||||
else
|
if (is_uploaded_file($sourcePath))
|
||||||
rename($sourcePath, $path);
|
move_uploaded_file($sourcePath, $path);
|
||||||
|
else
|
||||||
|
rename($sourcePath, $path);
|
||||||
|
}
|
||||||
R::store($dbPost);
|
R::store($dbPost);
|
||||||
|
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
|
@ -623,7 +652,15 @@ class PostController
|
||||||
$dstWidth = $this->config->browsing->thumbWidth;
|
$dstWidth = $this->config->browsing->thumbWidth;
|
||||||
$dstHeight = $this->config->browsing->thumbHeight;
|
$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':
|
case 'image/jpeg':
|
||||||
$srcImage = imagecreatefromjpeg($srcPath);
|
$srcImage = imagecreatefromjpeg($srcPath);
|
||||||
|
@ -784,6 +821,10 @@ class PostController
|
||||||
case 'img':
|
case 'img':
|
||||||
$type = PostType::Image;
|
$type = PostType::Image;
|
||||||
break;
|
break;
|
||||||
|
case 'yt':
|
||||||
|
case 'youtube':
|
||||||
|
$type = PostType::Youtube;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new SimpleException('Unknown type "' . $val . '"');
|
throw new SimpleException('Unknown type "' . $val . '"');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,5 @@ class PostType extends Enum
|
||||||
{
|
{
|
||||||
const Image = 1;
|
const Image = 1;
|
||||||
const Flash = 2;
|
const Flash = 2;
|
||||||
|
const Youtube = 3;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,19 +92,21 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="permalink">
|
<?php if ($this->context->transport->post->type != PostType::Youtube): ?>
|
||||||
<a href="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" title="Download">
|
<div class="permalink">
|
||||||
<i class="icon-dl"></i>
|
<a href="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" title="Download">
|
||||||
<span class="ext">
|
<i class="icon-dl"></i>
|
||||||
<?php $mimes = ['image/jpeg' => 'JPG', 'image/gif' => 'GIF', 'image/png' => 'PNG', 'application/x-shockwave-flash' => 'SWF'] ?>
|
<span class="ext">
|
||||||
<?php $mime = $this->context->transport->post->mimeType ?>
|
<?php $mimes = ['image/jpeg' => 'JPG', 'image/gif' => 'GIF', 'image/png' => 'PNG', 'application/x-shockwave-flash' => 'SWF'] ?>
|
||||||
<?php echo isset($mimes[$mime]) ? $mimes[$mime] : 'unknown' ?>
|
<?php $mime = $this->context->transport->post->mimeType ?>
|
||||||
</span>
|
<?php echo isset($mimes[$mime]) ? $mimes[$mime] : 'unknown' ?>
|
||||||
<span class="size">
|
</span>
|
||||||
<?php echo TextHelper::useBytesUnits($this->context->transport->post->file_size) ?>
|
<span class="size">
|
||||||
</span>
|
<?php echo TextHelper::useBytesUnits($this->context->transport->post->file_size) ?>
|
||||||
</a>
|
</span>
|
||||||
</div>
|
</a>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="unit favorites">
|
<div class="unit favorites">
|
||||||
|
@ -211,11 +213,17 @@
|
||||||
|
|
||||||
<div id="inner-content">
|
<div id="inner-content">
|
||||||
<div class="post-wrapper post-type-<?php echo strtolower(PostType::toString($this->context->transport->post->type)) ?>">
|
<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):
|
||||||
<img src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" alt="<?php echo $this->context->transport->post->name ?>"/>
|
case PostType::Image: ?>
|
||||||
<?php elseif ($this->context->transport->post->type == PostType::Flash): ?>
|
<img src="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" alt="<?php echo $this->context->transport->post->name ?>"/>
|
||||||
<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 break ?>
|
||||||
<?php endif ?>
|
<?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 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>
|
</div>
|
||||||
|
|
||||||
<?php if ($canEditAnything): ?>
|
<?php if ($canEditAnything): ?>
|
||||||
|
|
Loading…
Reference in a new issue