2024-07-05 07:26:39 +03:00
< ? php
namespace App\Controllers\Api\Images ;
use App\Services\ { Auth , Router , GenerateRandomStr , DB , Json , EXIF };
use App\Services\Upload as UploadPhoto ;
use \Aws\S3\MultipartUploader ;
use \Aws\Exception\MultipartUploadException ;
class Upload
{
static $continue ;
static $photourl ;
public static function create ( $postbody , $content , $exif )
{
2024-07-17 03:27:03 +03:00
$user = new \App\Models\User ( Auth :: userid ());
if ( NGALLERY [ 'root' ][ 'photo' ][ 'upload' ][ 'premoderation' ] === true ) {
2024-07-20 22:09:13 +03:00
if ( $user -> content ( 'premoderation' ) === " true " || $user -> i ( 'admin' ) > 0 ) {
2024-07-17 03:27:03 +03:00
$moderated = 1 ;
} else {
$moderated = 0 ;
}
} else {
$moderated = 1 ;
}
2024-07-18 19:09:32 +03:00
DB :: query ( 'INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :content)' , array ( ':postbody' => $postbody , ':userid' => Auth :: userid (), ':time' => mktime ( 0 , 0 , 0 , $_POST [ 'month' ], $_POST [ 'day' ], $_POST [ 'year' ]), ':content' => $content , ':photourl' => self :: $photourl , ':exif' => $exif , ':place' => $_POST [ 'place' ], ':timeup' => time (), ':moderated' => $moderated ));
2024-07-20 23:40:47 +03:00
if ( $moderated === 1 ) {
$followers = DB :: query ( 'SELECT * FROM followers WHERE user_id=:uid' , array ( ':uid' => Auth :: userid ()));
foreach ( $followers as $f ) {
DB :: query ( 'INSERT INTO followers_notifications VALUES (\'0\', :uid, :fid, :pid, 0)' , array ( ':uid' => Auth :: userid (), ':fid' => $f [ 'follower_id' ], ':pid' => DB :: query ( 'SELECT * FROM photos ORDER BY id DESC LIMIT 1' )[ 0 ][ 'id' ]));
}
}
2024-07-05 07:26:39 +03:00
echo json_encode (
array (
2024-07-05 12:44:31 +03:00
'id' => DB :: query ( 'SELECT id FROM photos ORDER BY id DESC LIMIT 1' )[ 0 ][ 'id' ],
2024-07-05 07:26:39 +03:00
'errorcode' => 0 ,
'error' => 0
)
);
}
public function __construct ()
{
2024-07-05 09:49:49 +03:00
if ( $_FILES [ 'image' ][ 'error' ] != 4 ) {
2024-07-17 03:58:19 +03:00
$finfo = finfo_open ( FILEINFO_MIME_TYPE );
$type = finfo_file ( $finfo , $_FILES [ 'image' ][ 'tmp_name' ]);
if ( $type === 'image/gif' ) {
if ( NGALLERY [ 'root' ][ 'photo' ][ 'upload' ][ 'allowgif' ] === false ) {
echo json_encode (
array (
'errorcode' => 'FILE_NOTSUPPORTED' ,
'error' => 1
)
);
die ();
}
}
2024-07-05 09:49:49 +03:00
$exif = new EXIF ( $_FILES [ 'image' ][ 'tmp_name' ]);
2024-07-05 12:44:31 +03:00
$exif = $exif -> getData ();
2024-07-13 02:47:11 +03:00
$upload = new UploadPhoto ( $_FILES [ 'image' ], 'cdn/img/' );
2024-07-05 12:44:31 +03:00
if ( $exif === null ) {
$exif = Json :: return (
array (
'type' => 'none' ,
)
);
}
2024-07-06 08:05:10 +03:00
if ( isset ( $_POST [ 'nomap' ])) {
$_POST [ 'lat' ] = null ;
$_POST [ 'lng' ] = null ;
}
2024-07-05 09:49:49 +03:00
if ( $upload -> getType () !== null ) {
2024-07-05 07:26:39 +03:00
$content = Json :: return (
array (
2024-07-05 09:49:49 +03:00
'type' => 'none' ,
'copyright' => $_POST [ 'license' ],
2024-07-05 12:58:12 +03:00
'comment' => $_POST [ 'descr' ],
2024-07-06 08:05:10 +03:00
'lat' => $_POST [ 'lat' ],
'lng' => $_POST [ 'lng' ]
2024-07-05 07:26:39 +03:00
)
);
2024-07-05 09:49:49 +03:00
self :: $photourl = $upload -> getSrc ();
2024-07-05 12:44:31 +03:00
self :: create ( $_POST [ 'descr' ], $content , $exif );
2024-07-05 07:26:39 +03:00
}
} else {
echo json_encode (
array (
'errorcode' => 'FILE_NOTSELECTED' ,
'error' => 1
)
);
}
}
}