parent
73e14c7a3a
commit
eccdcf5ead
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
###
|
||||
# @name Upload Module
|
||||
# @author Tobias Reich
|
||||
# @copyright 2014 by Tobias Reich
|
||||
###
|
||||
|
||||
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
|
||||
class Import extends Module {
|
||||
|
||||
static function photo($database, $plugins, $settings, $path, $albumID = 0, $description = '', $tags = '') {
|
||||
|
||||
$info = getimagesize($path);
|
||||
$size = filesize($path);
|
||||
$photo = new Photo($database, $plugins, $settings, null);
|
||||
|
||||
$nameFile = array(array());
|
||||
$nameFile[0]['name'] = $path;
|
||||
$nameFile[0]['type'] = $info['mime'];
|
||||
$nameFile[0]['tmp_name'] = $path;
|
||||
$nameFile[0]['error'] = 0;
|
||||
$nameFile[0]['size'] = $size;
|
||||
|
||||
if (!$photo->add($nameFile, $albumID, $description, $tags)) return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
static function url($urls, $albumID = 0) {
|
||||
|
||||
# Parse
|
||||
$urls = str_replace(' ', '%20', $urls);
|
||||
$urls = explode(',', $urls);
|
||||
|
||||
# Set path
|
||||
$path = __DIR__ . '/../../data/';
|
||||
|
||||
foreach ($urls as &$url) {
|
||||
|
||||
if (@getimagesize($url)) {
|
||||
|
||||
$pathinfo = pathinfo($url);
|
||||
$filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
|
||||
$tmp_name = $path . $filename;
|
||||
|
||||
if (!@copy($url, $tmp_name)) return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Import::server($albumID, $path);
|
||||
|
||||
}
|
||||
|
||||
static function server($albumID = 0, $path) {
|
||||
|
||||
if (!isset($path)) $path = __DIR__ . '/../../uploads/import/';
|
||||
|
||||
global $database, $plugins, $settings;
|
||||
|
||||
$files = glob($path . '*');
|
||||
$contains['photos'] = false;
|
||||
$contains['albums'] = false;
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
if (@getimagesize($file)) {
|
||||
|
||||
# Photo
|
||||
|
||||
if (!Import::photo($database, $plugins, $settings, $file, $albumID)) return false;
|
||||
$contains['photos'] = true;
|
||||
|
||||
} else if (is_dir($file)) {
|
||||
|
||||
# Folder
|
||||
|
||||
$name = mysqli_real_escape_string($database, basename($file));
|
||||
$album = new Album($database, null, null, null);
|
||||
$newAlbumID = $album->add('[Import] ' . $name);
|
||||
|
||||
if ($newAlbumID!==false) Import::server($newAlbumID, $file . '/');
|
||||
$contains['albums'] = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($contains['photos']===false&&$contains['albums']===false) return 'Warning: Folder empty!';
|
||||
if ($contains['photos']===false&&$contains['albums']===true) return 'Notice: Import only contains albums!';
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @name Upload Module
|
||||
* @author Philipp Maurer
|
||||
* @author Tobias Reich
|
||||
* @copyright 2014 by Philipp Maurer, Tobias Reich
|
||||
*/
|
||||
|
||||
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
|
||||
function importPhoto($path, $albumID = 0, $description = '', $tags = '') {
|
||||
|
||||
$info = getimagesize($path);
|
||||
$size = filesize($path);
|
||||
|
||||
$nameFile = array(array());
|
||||
$nameFile[0]['name'] = $path;
|
||||
$nameFile[0]['type'] = $info['mime'];
|
||||
$nameFile[0]['tmp_name'] = $path;
|
||||
$nameFile[0]['error'] = 0;
|
||||
$nameFile[0]['size'] = $size;
|
||||
|
||||
return upload($nameFile, $albumID, $description, $tags);
|
||||
|
||||
}
|
||||
|
||||
function importUrl($url, $albumID = 0) {
|
||||
|
||||
if (strpos($url, ',')!==false) {
|
||||
|
||||
// Multiple photos
|
||||
|
||||
$url = explode(',', $url);
|
||||
|
||||
foreach ($url as &$key) {
|
||||
|
||||
$key = str_replace(' ', '%20', $key);
|
||||
|
||||
if (@getimagesize($key)) {
|
||||
|
||||
$pathinfo = pathinfo($key);
|
||||
$filename = $pathinfo['filename'].".".$pathinfo['extension'];
|
||||
$tmp_name = __DIR__ . '/../../uploads/import/' . $filename;
|
||||
|
||||
copy($key, $tmp_name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return importServer($albumID);
|
||||
|
||||
} else {
|
||||
|
||||
// One photo
|
||||
|
||||
$url = str_replace(' ', '%20', $url);
|
||||
|
||||
if (@getimagesize($url)) {
|
||||
|
||||
$pathinfo = pathinfo($url);
|
||||
$filename = $pathinfo['filename'].".".$pathinfo['extension'];
|
||||
$tmp_name = __DIR__ . "/../../uploads/import/$filename";
|
||||
|
||||
copy($url, $tmp_name);
|
||||
|
||||
return importPhoto($tmp_name, $albumID);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
function importServer($albumID = 0, $path) {
|
||||
|
||||
if (!isset($path)) $path = __DIR__ . '/../../uploads/import/';
|
||||
|
||||
global $database;
|
||||
|
||||
$files = glob($path . '*');
|
||||
$contains['photos'] = false;
|
||||
$contains['albums'] = false;
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
if (@getimagesize($file)) {
|
||||
|
||||
// Photo
|
||||
if (!importPhoto($file, $albumID)) return false;
|
||||
$contains['photos'] = true;
|
||||
|
||||
} else if (is_dir($file)) {
|
||||
|
||||
$name = mysqli_real_escape_string($database, basename($file));
|
||||
$newAlbumID = addAlbum('[Import] ' . $name);
|
||||
|
||||
if ($newAlbumID!==false) importServer($newAlbumID, $file . '/');
|
||||
$contains['albums'] = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($contains['photos']===false&&$contains['albums']===false) return "Warning: Folder empty!";
|
||||
if ($contains['photos']===false&&$contains['albums']===true) return "Notice: Import only contains albums!";
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in new issue