Import.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. ###
  3. # @name Upload Module
  4. # @author Tobias Reich
  5. # @copyright 2014 by Tobias Reich
  6. ###
  7. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  8. class Import extends Module {
  9. static function photo($database, $plugins, $settings, $path, $albumID = 0, $description = '', $tags = '') {
  10. $info = getimagesize($path);
  11. $size = filesize($path);
  12. $photo = new Photo($database, $plugins, $settings, null);
  13. $nameFile = array(array());
  14. $nameFile[0]['name'] = $path;
  15. $nameFile[0]['type'] = $info['mime'];
  16. $nameFile[0]['tmp_name'] = $path;
  17. $nameFile[0]['error'] = 0;
  18. $nameFile[0]['size'] = $size;
  19. if (!$photo->add($nameFile, $albumID, $description, $tags)) return false;
  20. return true;
  21. }
  22. static function url($urls, $albumID = 0) {
  23. $error = false;
  24. # Parse
  25. $urls = str_replace(' ', '%20', $urls);
  26. $urls = explode(',', $urls);
  27. foreach ($urls as &$url) {
  28. if (@exif_imagetype($url)===false) {
  29. $error = true;
  30. continue;
  31. }
  32. $pathinfo = pathinfo($url);
  33. $filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
  34. $tmp_name = LYCHEE_DATA . $filename;
  35. if (@copy($url, $tmp_name)===false) $error = true;
  36. }
  37. $import = Import::server($albumID, LYCHEE_DATA);
  38. if ($error===false&&$import===true) return true;
  39. else return false;
  40. }
  41. static function server($albumID = 0, $path) {
  42. if (!isset($path)) $path = LYCHEE_UPLOADS_IMPORT;
  43. global $database, $plugins, $settings;
  44. $files = glob($path . '*');
  45. $contains['photos'] = false;
  46. $contains['albums'] = false;
  47. foreach ($files as $file) {
  48. if (@exif_imagetype($file)!==false) {
  49. # Photo
  50. if (!Import::photo($database, $plugins, $settings, $file, $albumID)) return false;
  51. $contains['photos'] = true;
  52. } else if (is_dir($file)) {
  53. # Folder
  54. $name = mysqli_real_escape_string($database, basename($file));
  55. $album = new Album($database, null, null, null);
  56. $newAlbumID = $album->add('[Import] ' . $name);
  57. if ($newAlbumID!==false) Import::server($newAlbumID, $file . '/');
  58. $contains['albums'] = true;
  59. }
  60. }
  61. if ($contains['photos']===false&&$contains['albums']===false) return 'Warning: Folder empty!';
  62. if ($contains['photos']===false&&$contains['albums']===true) return 'Notice: Import only contains albums!';
  63. return true;
  64. }
  65. }
  66. ?>