Import.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. # Parse
  24. $urls = str_replace(' ', '%20', $urls);
  25. $urls = explode(',', $urls);
  26. foreach ($urls as &$url) {
  27. if (@getimagesize($url)) {
  28. $pathinfo = pathinfo($url);
  29. $filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
  30. $tmp_name = LYCHEE_DATA . $filename;
  31. if (!@copy($url, $tmp_name)) return false;
  32. }
  33. }
  34. return Import::server($albumID, LYCHEE_DATA);
  35. }
  36. static function server($albumID = 0, $path) {
  37. if (!isset($path)) $path = LYCHEE_UPLOADS_IMPORT;
  38. global $database, $plugins, $settings;
  39. $files = glob($path . '*');
  40. $contains['photos'] = false;
  41. $contains['albums'] = false;
  42. foreach ($files as $file) {
  43. if (@getimagesize($file)) {
  44. # Photo
  45. if (!Import::photo($database, $plugins, $settings, $file, $albumID)) return false;
  46. $contains['photos'] = true;
  47. } else if (is_dir($file)) {
  48. # Folder
  49. $name = mysqli_real_escape_string($database, basename($file));
  50. $album = new Album($database, null, null, null);
  51. $newAlbumID = $album->add('[Import] ' . $name);
  52. if ($newAlbumID!==false) Import::server($newAlbumID, $file . '/');
  53. $contains['albums'] = true;
  54. }
  55. }
  56. if ($contains['photos']===false&&$contains['albums']===false) return 'Warning: Folder empty!';
  57. if ($contains['photos']===false&&$contains['albums']===true) return 'Notice: Import only contains albums!';
  58. return true;
  59. }
  60. }
  61. ?>