mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-17 21:48:00 +00:00
36
inc/core.php
36
inc/core.php
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
spl_autoload_register('autoload');
|
||||
|
||||
function __autoload($className)
|
||||
function autoload($className)
|
||||
{
|
||||
if (file_exists(ROOT . DS . 'models' . DS . strtolower($className) . '.php'))
|
||||
require_once(ROOT . DS . 'models' . DS . strtolower($className) . '.php');
|
||||
@@ -8,6 +9,26 @@ function __autoload($className)
|
||||
require_once(ROOT . DS . 'classes' . DS . strtolower($className) . '.php');
|
||||
}
|
||||
|
||||
function getUserIP()
|
||||
{
|
||||
$client = @$_SERVER['HTTP_CLIENT_IP'];
|
||||
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$remote = $_SERVER['REMOTE_ADDR'];
|
||||
if(filter_var($client, FILTER_VALIDATE_IP))
|
||||
{
|
||||
$ip = $client;
|
||||
}
|
||||
elseif(filter_var($forward, FILTER_VALIDATE_IP))
|
||||
{
|
||||
$ip = $forward;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ip = $remote;
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
function stripSlashesDeep($value)
|
||||
{
|
||||
$value = is_array($value) ? array_map('stripSlashesDeep', $value) : stripslashes($value);
|
||||
@@ -150,22 +171,28 @@ function renderImage($data)
|
||||
imagepng($im);
|
||||
break;
|
||||
case 'gif':
|
||||
if($data['mp4'] || $data['webm']) //user wants mp4 or webm
|
||||
if($data['mp4'] || $data['webm'] || $data['ogg']) //user wants mp4 or webm or ogg
|
||||
{
|
||||
$gifpath = $path;
|
||||
$mp4path = $base_path.'mp4_1.'.$hash; //workaround.. find a better solution!
|
||||
$webmpath = $base_path.'webm_1.'.$hash;
|
||||
$oggpath = $base_path.'ogg_1.'.$hash;
|
||||
|
||||
if(!file_exists($mp4path) && !$data['preview']) //if mp4 does not exist, create it
|
||||
$pm->gifToMP4($gifpath,$mp4path);
|
||||
|
||||
if(!file_exists($webmpath) && $data['webm'] && !$data['preview'])
|
||||
$pm->saveAsWebm($gifpath,$webmpath);
|
||||
|
||||
if(!file_exists($oggpath) && $data['ogg'] && !$data['preview'])
|
||||
$pm->saveAsOGG($gifpath,$oggpath);
|
||||
|
||||
if($data['raw'])
|
||||
{
|
||||
if($data['webm'])
|
||||
serveFile($webmpath, $hash.'.webm','video/webm');
|
||||
if($data['ogg'])
|
||||
serveFile($oggpath, $hash.'.ogg','video/ogg');
|
||||
else
|
||||
serveFile($mp4path, $hash.'.mp4','video/mp4');
|
||||
}
|
||||
@@ -208,6 +235,11 @@ function renderImage($data)
|
||||
{
|
||||
$pm->saveAsWebm(ROOT.DS.'upload'.DS.$hash.DS.$hash,$cachepath);
|
||||
}
|
||||
|
||||
if($data['ogg'])
|
||||
{
|
||||
$pm->saveAsOGG(ROOT.DS.'upload'.DS.$hash.DS.$hash,$cachepath);
|
||||
}
|
||||
|
||||
if($data['raw'])
|
||||
{
|
||||
|
||||
@@ -4,6 +4,20 @@ class PictshareModel extends Model
|
||||
{
|
||||
function backend($params)
|
||||
{
|
||||
switch($params[0])
|
||||
{
|
||||
case 'mp4convert':
|
||||
$hash = $params[1];
|
||||
$path = $params[2];
|
||||
$source = $path.$hash;
|
||||
if(!$this->isImage($hash))
|
||||
exit('[x] Hash not found'."\n");
|
||||
echo "[i] Converting $hash to mp4\n";
|
||||
$this->saveAsMP4($source,$path.'mp4_1.'.$hash);
|
||||
$this->saveAsMP4($source,$path.'ogg_1.'.$hash);
|
||||
break;
|
||||
}
|
||||
|
||||
return array('status'=>'ok');
|
||||
}
|
||||
|
||||
@@ -57,7 +71,7 @@ class PictshareModel extends Model
|
||||
|
||||
if($this->isImage($el))
|
||||
$data['hash']=$el;
|
||||
else if($el=='mp4' || $el=='raw' || $el=='preview' || $el=='webm')
|
||||
else if($el=='mp4' || $el=='raw' || $el=='preview' || $el=='webm' || $el=='ogg')
|
||||
$data[$el] = 1;
|
||||
else if($this->isSize($el))
|
||||
$data['size'] = $el;
|
||||
@@ -705,7 +719,16 @@ class PictshareModel extends Model
|
||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
||||
$source = escapeshellarg($source);
|
||||
$target = escapeshellarg($target);
|
||||
$h265 = "$bin -y -i $source -an -c:v libx264 -f mp4 $target";
|
||||
$h265 = "$bin -y -i $source -an -c:v libx264 -qp 0 -f mp4 $target";
|
||||
system($h265);
|
||||
}
|
||||
|
||||
function saveAsOGG($source,$target)
|
||||
{
|
||||
$bin = escapeshellcmd(ROOT.DS.'bin'.DS.'ffmpeg');
|
||||
$source = escapeshellarg($source);
|
||||
$target = escapeshellarg($target);
|
||||
$h265 = "$bin -y -i $source -an -codec:v libtheora -qp 0 -f ogg $target";
|
||||
system($h265);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
<link rel="canonical" href="<?php echo DOMAINPATH.$hash; ?>" />
|
||||
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
|
||||
<meta property="og:site_name" content="<?php echo (TITLE?TITLE:'PictShare image hosting'); ?>" />
|
||||
<meta property="og:url" content="<?php echo DOMAINPATH.$hash; ?>" />
|
||||
<meta property="og:title" content="<?php echo (TITLE?TITLE:'PictShare image hosting'); ?> MP4" />
|
||||
@@ -35,10 +37,11 @@
|
||||
</head>
|
||||
<body id="body">
|
||||
|
||||
<div id="container img-responsive">
|
||||
<div id="container">
|
||||
<video id="video" poster="<?php echo DOMAINPATH.'preview/'.$hash; ?>" preload="auto" autoplay="autoplay" muted="muted" loop="loop" webkit-playsinline>
|
||||
<source src="<?php echo DOMAINPATH.'raw/mp4/'.$hash; ?>" type="video/mp4">
|
||||
<source src="<?php echo DOMAINPATH.'raw/webm/'.$hash; ?>" type="video/webm">
|
||||
<source src="<?php echo DOMAINPATH.'raw/ogg/'.$hash; ?>" type="video/ogg">
|
||||
</video>
|
||||
</div>
|
||||
<small><?php echo $filesize; ?></small>
|
||||
|
||||
Reference in New Issue
Block a user